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 BSWM_H_ #define BSWM_H_ /* @req BswM0025 */ #include "Std_Types.h" #if defined(USE_RTE) #include "Rte_BswM_Type.h" #endif #define BSWM_VENDOR_ID 60u #define BSWM_MODULE_ID 42u #define BSWM_AR_RELEASE_MAJOR_VERSION 4 #define BSWM_AR_RELEASE_MINOR_VERSION 0 #define BSWM_AR_RELEASE_PATCH_VERSION 3 #define BSWM_AR_MAJOR_VERSION BSWM_AR_RELEASE_MAJOR_VERSION #define BSWM_AR_MINOR_VERSION BSWM_AR_RELEASE_MINOR_VERSION #define BSWM_AR_PATCH_VERSION BSWM_AR_RELEASE_PATCH_VERSION #define BSWM_SW_MAJOR_VERSION 4u #define BSWM_SW_MINOR_VERSION 0u #define BSWM_SW_PATCH_VERSION 1u /* @req BswM0029 */ #define BSWM_E_NO_INIT 0x01u #define BSWM_E_NULL_POINTER 0x02u #define BSWM_E_PARAM_INVALID 0x03u #define BSWM_E_REQ_USER_OUT_OF_RANGE 0x04u #define BSWM_E_REQ_MODE_OUT_OF_RANGE 0x05u #define BSWM_E_PARAM_CONFIG 0x06u #define BSWM_E_PARAM_POINTER 0x07u #define BSWM_SERVICEID_INIT 0x00u #define BSWM_SERVICEID_GETVERSIONINFO 0x01u #define BSWM_SERVICEID_REQUESTMODE 0x02u #define BSWM_SERVICEID_MAINFUNCTION 0x03u #define BSWM_SERVICEID_DEINIT 0x04u #define BSWM_SERVICEID_CANSMCURRENTSTATE 0x05u #define BSWM_SERVICEID_DCMCOMMUNICATIONMODE 0x06u #define BSWM_SERVICEID_LINSMCURRENTSTATE 0x09u #define BSWM_SERVICEID_LINSMCURRENTSCHEDULE 0x0Au #define BSWM_SERVICEID_LINTPREQUESTMODE 0x0Bu #define BSWM_SERVICEID_FRSMCURRENTSTATE 0x0Cu #define BSWM_SERVICEID_ETHSMCURRENTSTATE 0x0Du #define BSWM_SERVICEID_COMMCURRENTMODE 0x0Eu #define BSWM_SERVICEID_ECUMCURRENTSTATE 0x0Fu #define BSWM_SERVICEID_ECUMCURRENTWAKEUP 0x10u #define BSWM_SERVICEID_COMMCURRENTPNCMODE 0x15u #define BSWM_SERVICEID_SDCLIENTSERVICECURRENTSTATE 0x1Fu #define BSWM_SERVICEID_SDEVENTHANDLERCURRENTSTATE 0x20u #define BSWM_SERVICEID_SDCONSUMEDEVENTGROUPCURRENTSTATE 0x21u #include "BswM_Cfg.h" #if defined(BSWM_COMM_ENABLED) #define IS_VALID_COMM_MODE(_x) ((COMM_FULL_COMMUNICATION == (_x)) || (COMM_SILENT_COMMUNICATION == (_x)) || (COMM_NO_COMMUNICATION == (_x))) #endif /* @req BswM0007 */ #if defined(USE_DEM) #define BSWM_REPORT_ERROR_STATUS(eventID, error) Dem_ReportErrorStatus((Dem_EventIdType) eventID, error); #else #define BSWM_REPORT_ERROR_STATUS(eventID, error) #endif #define BSWM_UNDEFINED_REQUEST_VALUE 0xFF /* @req BswM0041 */ typedef uint8 BswM_UserType; typedef uint8 BswM_ModeType; typedef enum { BSWM_FALSE = 0, BSWM_TRUE, BSWM_UNDEFINED, } BswM_RuleStateType; typedef enum { BSWM_CONDITION = 0, BSWM_TRIGGER } BswM_ExecutionType; typedef enum { BSWM_ATOMIC = 0, BSWM_LIST, BSWM_RULE } BswM_ActionType; typedef enum { BSWM_PDUR_DISABLE = 0, BSWM_PDUR_ENABLE } BswM_PduR_ActionType; typedef struct { const uint32 AtomicActionIndex; const sint32 *PduRoutingPathGroupRefId; const sint32 ReferredListIndex; const sint32 ReportFailToDEMRefId; const sint32 *DisabledPduGroupRefId; const sint32 *EnabledPduGroupRefId; const sint16 ReferredRuleIndex; const BswM_ActionType ActionType; const BswM_PduR_ActionType PduRouterAction; const uint8 LinScheduleRef; const boolean AbortOnFail; const boolean PduGroupSwitchReinit; } BswM_ActionListItemType; typedef struct { const BswM_ActionListItemType * const * Items; const uint32 NumberOfItems; const BswM_ExecutionType Execution; } BswM_ActionListType; typedef struct { const uint32 LogicalExpressionIndex; const sint32 ActionListTrueIndex; const sint32 ActionListFalseIndex; const BswM_RuleStateType RuleStateInit; } BswM_RuleType; typedef struct { const sint16 *DeferredRules; const sint16 *const*ImmediateRules; const BswM_RuleType *RuleData; const uint32 NumberOfRules; } BswM_RuleConfigType; typedef struct { const BswM_RuleConfigType *RuleCfg; const BswM_ActionListType *ActionListData; const uint32 *ModeRequestData; } BswM_ConfigType; /*================================ BswM API =================================*/ void BswM_Init( const BswM_ConfigType* ConfigPtr ); void BswM_Deinit( void ); void BswM_MainFunction( void ); #if ( BSWM_GENERIC_REQUEST_ENABLED == STD_ON ) /* @req BswM0046 */ void BswM_RequestMode( BswM_UserType requesting_user, BswM_ModeType requested_mode ); #endif #if ( BSWM_VERSION_INFO_API == STD_ON ) /* @req BswM0003 */ void BswM_GetVersionInfo( Std_VersionInfoType* VersionInfo ); #endif extern const BswM_ConfigType BswM_Config; #endif /* BSWM_H_ */
2301_81045437/classic-platform
system/BswM/inc/BswM.h
C
unknown
5,804
/*-------------------------------- 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 BSWM_CANSM_H_ #define BSWM_CANSM_H_ #include "CanSM_BswM.h" /* @req BswM0049 */ void BswM_CanSM_CurrentState(NetworkHandleType Network, CanSM_BswMCurrentStateType CurrentState); #endif /* BSWM_CANSM_H_ */
2301_81045437/classic-platform
system/BswM/inc/BswM_CanSM.h
C
unknown
975
/*-------------------------------- 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 BSWM_COMM_H_ #define BSWM_COMM_H_ void BswM_ComM_CurrentMode(NetworkHandleType Network, ComM_ModeType RequestedMode); void BswM_ComM_CurrentPNCMode(PNCHandleType PNC, ComM_PncModeType CurrentPncMode); #endif /* BSWM_COMM_H_ */
2301_81045437/classic-platform
system/BswM/inc/BswM_ComM.h
C
unknown
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 -----------------------------*/ #ifndef BSWM_DCM_H_ #define BSWM_DCM_H_ void BswM_Dcm_CommunicationMode_CurrentState(NetworkHandleType Network, Dcm_CommunicationModeType RequestedMode); #endif /* BSWM_DCM_H_ */
2301_81045437/classic-platform
system/BswM/inc/BswM_DCM.h
C
unknown
937
/*-------------------------------- 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 BSWM_ECUM_H_ #define BSWM_ECUM_H_ void BswM_EcuM_CurrentState(EcuM_StateType CurrentState); void BswM_EcuM_CurrentWakeup(EcuM_WakeupSourceType source, EcuM_WakeupStatusType state); #endif /* BSWM_ECUM_H_ */
2301_81045437/classic-platform
system/BswM/inc/BswM_EcuM.h
C
unknown
976
/*-------------------------------- 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 BSWM_ETHSM_H_ #define BSWM_ETHSM_H_ #include "EthSM.h" /* !req SWS_BswM_00050 */ void BswM_EthSM_CurrentState(NetworkHandleType Network, EthSM_NetworkModeStateType CurrentState); #endif /* BSWM_ETHSM_H_ */
2301_81045437/classic-platform
system/BswM/inc/BswM_EthSM.h
C
unknown
974
/*-------------------------------- 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 BSWM_FRSM_H_ #define BSWM_FRSM_H_ #include "FrSM_Types.h" /* @req BswM0051 */ void BswM_FrSM_CurrentState(NetworkHandleType Network, FrSM_BswM_StateType CurrentState); #endif /* BSWM_FRSM_H_ */
2301_81045437/classic-platform
system/BswM/inc/BswM_FrSM.h
C
unknown
966
/*-------------------------------- 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 BSWM_INTERNAL_H_ #define BSWM_INTERNAL_H_ /* @req BswM0037 */ #define BSWM_HIERARCHIC_LIST_LEVELS_MAX (7) typedef enum { BSWM_INIT, BSWM_UNINIT } BswM_InitStatusType; typedef struct { BswM_InitStatusType InitStatus; } BswM_InternalType; typedef struct { uint32 itemIndexBuffer[BSWM_HIERARCHIC_LIST_LEVELS_MAX]; sint32 listIndexBuffer[BSWM_HIERARCHIC_LIST_LEVELS_MAX]; uint8 levelCnt; } BswM_ListStateType; /* Development Error Tracer */ /* @req BswM0031 */ /* @req BswM0033 */ /* @req BswM0030 */ #if (BSWM_DEV_ERROR_DETECT == STD_ON) extern BswM_InternalType BswM_Internal; #define BSWM_DET_REPORTERROR(serviceId, errorId) \ (void)Det_ReportError(BSWM_MODULE_ID, 0, serviceId, errorId) #define BSWM_VALIDATE(expression, serviceId, errorId, ret) \ if (!(expression)) { \ BSWM_DET_REPORTERROR(serviceId, errorId); \ return ret; \ } #define BSWM_VALIDATE_NORV(expression, serviceId, errorId) \ if (!(expression)) { \ BSWM_DET_REPORTERROR(serviceId, errorId); \ return; \ } #else #define BSWM_DET_REPORTERROR(...) #define BSWM_VALIDATE(...) #define BSWM_VALIDATE_NORV(...) #endif /*lint -emacro(904,BSWM_VALIDATE_INIT,BSWM_VALIDATE_INIT_NORV,BSWM_VALIDATE_POINTER_NORV,BSWM_VALIDATE_REQUESTMODE_NORV,BSWM_VALIDATE_REQUESTMODE,BSWM_VALIDATE_CFGPOINTER_NORV,BSWM_VALIDATE_CFGPARAMRANGE_NORV)*/ /*904 PC-Lint exception to MISRA 14.7 (validate DET macros)*/ #define BSWM_VALIDATE_INIT(serviceID) \ BSWM_VALIDATE((BswM_Internal.InitStatus == BSWM_INIT), serviceID, BSWM_E_NO_INIT, 0, E_NOT_OK) #define BSWM_VALIDATE_INIT_NORV(serviceID) \ BSWM_VALIDATE_NORV((BswM_Internal.InitStatus == BSWM_INIT), serviceID, BSWM_E_NO_INIT) #define BSWM_VALIDATE_REQUESTMODE(expression, serviceID) \ BSWM_VALIDATE(expression, serviceID, BSWM_E_REQ_MODE_OUT_OF_RANGE, E_NOT_OK) #define BSWM_VALIDATE_REQUESTMODE_NORV(expression, serviceID) \ BSWM_VALIDATE_NORV(expression, serviceID, BSWM_E_REQ_MODE_OUT_OF_RANGE) #define BSWM_VALIDATE_POINTER_NORV(pointer, serviceID) \ BSWM_VALIDATE_NORV((pointer != NULL), serviceID, BSWM_E_PARAM_POINTER) #define BSWM_VALIDATE_CFGPOINTER_NORV(pointer, serviceID) \ BSWM_VALIDATE_NORV((pointer != NULL), serviceID, BSWM_E_NULL_POINTER) #define BSWM_VALIDATE_CFGPARAMRANGE_NORV(expression, serviceID) \ BSWM_VALIDATE_NORV(expression, serviceID, BSWM_E_PARAM_CONFIG) #define BSWM_VALIDATE_LINTPMODEREQUEST_NORV(modeReq) \ BSWM_VALIDATE_NORV(((LINTP_APPLICATIVE_SCHEDULE == modeReq) || (LINTP_DIAG_REQUEST == modeReq) || (LINTP_DIAG_RESPONSE == modeReq)), BSWM_SERVICEID_LINTPREQUESTMODE, BSWM_E_REQ_MODE_OUT_OF_RANGE) void BswM_Internal_PduGroupSwitchAction( const BswM_ActionListItemType *item ); void BswM_Internal_DMControlAction( const BswM_ActionListItemType *item ); void BswM_Internal_PduRouterControlAction( const BswM_ActionListItemType *item ); void BswM_Internal_ProcessImmediateRequest( const uint32 modeReqIndex ); #endif /* BSWM_INTERNAL_H_ */
2301_81045437/classic-platform
system/BswM/inc/BswM_Internal.h
C
unknown
4,168
/*-------------------------------- 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 BSWM_LINSM_H_ #define BSWM_LINSM_H_ #include "LinSM.h" /* !req BswM0058 */ void BswM_LinSM_CurrentSchedule(NetworkHandleType Network, LinIf_SchHandleType CurrentSchedule); /* !req BswM0052*/ void BswM_LinSM_CurrentState(NetworkHandleType Network, LinSM_ModeType CurrentState); #endif /* BSWM_LINSM_H_ */
2301_81045437/classic-platform
system/BswM/inc/BswM_LinSM.h
C
unknown
1,074
/*-------------------------------- 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 BSWM_LINTP_H_ #define BSWM_LINTP_H_ /* @req BswM0156 */ void BswM_LinTp_RequestMode( NetworkHandleType Network, LinTp_Mode LinTpRequestedMode ); #endif /* BSWM_LINTP_H_ */
2301_81045437/classic-platform
system/BswM/inc/BswM_LinTp.h
C
unknown
941
/*-------------------------------- 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 BSWM_SD_H_ #define BSWM_SD_H_ #include "SD_Types.h" /** @req SWS_BswM_00204 */ void BswM_Sd_ClientServiceCurrentState(uint16 SdClientServiceHandleId, Sd_ClientServiceCurrentStateType CurrentClientState); /** @req SWS_BswM_00207 */ void BswM_Sd_ConsumedEventGroupCurrentState(uint16 SdConsumedEventGroupHandleId, Sd_ConsumedEventGroupCurrentStateType ConsumedEventGroupState); /** @req SWS_BswM_00210 */ void BswM_Sd_EventHandlerCurrentState(uint16 SdEventHandlerHandleId, Sd_EventHandlerCurrentStateType EventHandlerStatus); #endif /* BSWM_SD_H_ */
2301_81045437/classic-platform
system/BswM/inc/BswM_Sd.h
C
unknown
1,453
/*-------------------------------- 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 "BswM.h" #include "BswM_Internal.h" #include "MemMap.h" #if defined(USE_COMM) #include "ComM.h" #include "BswM_ComM.h" #endif #if defined(USE_PDUR) #include "PduR.h" #endif #if defined(USE_NVM) #include "NvM.h" #endif #if defined(USE_CANSM) #include "CanSM.h" #include "BswM_CanSM.h" #endif #if defined(USE_SD) #include "SD.h" #endif #if defined(USE_FRSM) #include "FrSM.h" #include "BswM_FrSM.h" #endif #if defined(USE_LINSM) #include "LinSM.h" #include "BswM_LinSM.h" #endif #if defined(USE_ETHSM) #include "EthSM.h" #include "BswM_EthSM.h" #endif #if defined(USE_COM) #include "Com.h" #endif #if defined(USE_LINIF) #include "LinIf.h" #endif #include "EcuM.h" #include "BswM_EcuM.h" #if defined(USE_DCM) #include "Dcm.h" #endif #if defined(USE_DET) #include "Det.h" #endif #if defined(USE_DEM) #include "Dem.h" #endif #if defined(USE_NM) #include "Nm.h" #endif #if defined(USE_RTE) #include "Rte_BswM.h" #endif #include "SchM_BswM.h" /* General requiremnets */ /* @req BswM0001 */ /* @req BswM0008 */ /* Mode Arbitration */ /* @req BswM0009 */ /* @req BswM0035 */ /* @req BswM0010 */ /* @req BswM0012 */ /* @req BswM0117 */ /* @req BswM0147 */ /* Immediate and Deferred Operation */ /* @req BswM0061 */ /* @req BswM0013 */ /* @req BswM0014 */ /* Arbitration Behavior after Initialization */ /* @req BswM0064 */ /* Mode control */ /* @req BswM0037 */ /* Available Actions */ /* @req BswM0038 */ /* @req BswM0039 */ /* @req BswM0040 */ /* @req BswM0054 */ /* @req BswM0066 */ /* @req BswM0020 */ /* @req BswM0021 */ /* @req BswM9999 */ #if (BSWM_NUMBER_OF_RULES_MAX > 0) #define BSWM_START_SEC_VAR_CLEARED_UNSPECIFIED #include "BswM_BswMemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/ BswM_RuleStateType BswM_RuleStates[BSWM_NUMBER_OF_RULES_MAX]; #define BSWM_STOP_SEC_VAR_CLEARED_UNSPECIFIED #include "BswM_BswMemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/ #endif #if (BSWM_NUMBER_OF_REQUESTS > 0) extern uint32 BswM_ModeReqMirrors[BSWM_NUMBER_OF_REQUESTS]; #endif #define BSWM_START_SEC_VAR_CLEARED_UNSPECIFIED #include "BswM_BswMemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/ static const BswM_RuleConfigType *BswM_RuleConfigPtr; /*lint -e9003 could define variable at block scope */ #define BSWM_STOP_SEC_VAR_CLEARED_UNSPECIFIED #include "BswM_BswMemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/ #define BSWM_START_SEC_VAR_CLEARED_UNSPECIFIED #include "BswM_BswMemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/ static const BswM_ConfigType *BswM_ConfigPtr; #define BSWM_STOP_SEC_VAR_CLEARED_UNSPECIFIED #include "BswM_BswMemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/ #define BSWM_START_SEC_VAR_CLEARED_UNSPECIFIED #include "BswM_BswMemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/ static const BswM_RuleType *BswM_Rules; #define BSWM_STOP_SEC_VAR_CLEARED_UNSPECIFIED #include "BswM_BswMemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/ #define BSWM_START_SEC_VAR_CLEARED_UNSPECIFIED #include "BswM_BswMemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/ static boolean BswM_RequestProcessingOngoing; #define BSWM_STOP_SEC_VAR_CLEARED_UNSPECIFIED #include "BswM_BswMemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/ #if (BSWM_NUMBER_OF_IMMEDIATE_REQUESTS > 0) #define BSWM_START_SEC_VAR_CLEARED_UNSPECIFIED #include "BswM_BswMemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/ static boolean BswM_DelayedRequest[BSWM_NUMBER_OF_IMMEDIATE_REQUESTS]; #define BSWM_STOP_SEC_VAR_CLEARED_UNSPECIFIED #include "BswM_BswMemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/ #endif /* @req BswM0128 */ #if (BSWM_PDUGROUPSWITCH_ACTIONS > 0) #define BSWM_START_SEC_VAR_CLEARED_UNSPECIFIED #include "BswM_BswMemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/ static boolean BswM_PduGroupSwitchActionPerformed; #define BSWM_STOP_SEC_VAR_CLEARED_UNSPECIFIED #include "BswM_BswMemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/ #define BSWM_START_SEC_VAR_CLEARED_UNSPECIFIED #include "BswM_BswMemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/ static Com_IpduGroupVector BswM_ComIpduGroupVector; #define BSWM_STOP_SEC_VAR_CLEARED_UNSPECIFIED #include "BswM_BswMemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/ #define BSWM_START_SEC_VAR_CLEARED_UNSPECIFIED #include "BswM_BswMemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/ static boolean BswM_ComIpduInitialize; #define BSWM_STOP_SEC_VAR_CLEARED_UNSPECIFIED #include "BswM_BswMemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/ #endif #if (BSWM_DEADLINEMONITORING_ACTIONS > 0) #define BSWM_START_SEC_VAR_INIT_UNSPECIFIED #include "BswM_BswMemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/ static boolean BswM_DMControlPerformed; #define BSWM_STOP_SEC_VAR_INIT_UNSPECIFIED #include "BswM_BswMemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/ #define BSWM_START_SEC_VAR_INIT_UNSPECIFIED #include "BswM_BswMemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/ static Com_IpduGroupVector BswM_DMControlGroupVector; #define BSWM_STOP_SEC_VAR_INIT_UNSPECIFIED #include "BswM_BswMemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/ #endif #define BSWM_START_SEC_VAR_INIT_UNSPECIFIED #include "BswM_BswMemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/ BswM_InternalType BswM_Internal = { .InitStatus = BSWM_UNINIT, }; #define BSWM_STOP_SEC_VAR_INIT_UNSPECIFIED #include "BswM_BswMemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/ #ifdef HOST_TEST BswM_InternalType* readinternal_status(void); BswM_InternalType* readinternal_status(void){ return (&BswM_Internal); } #endif #if (BSWM_NUMBER_OF_RULES_MAX > 0) /** * @brief Evaluates a logical expression. * @param logicalExpressionIndex Index (determined pre-compile-time) of the logical expression to be evaluated. * @return BSWM_TRUE or BSWM_FALSE */ static BswM_RuleStateType BswM_Internal_EvaluateLogicalExpression( const uint32 logicalExpressionIndex ) { extern boolean (*BswM_LogicalExpressions[]) (void); /*lint -e9003 */ boolean (*logicalExpressionFcn)(void) = BswM_LogicalExpressions[logicalExpressionIndex]; BswM_RuleStateType retVal; if (TRUE == logicalExpressionFcn()) { retVal = BSWM_TRUE; } else { retVal = BSWM_FALSE; } return retVal; } /* @req BswM0015 */ /* @req BswM0065 */ /** * @brief Evaluates a rule. * @param ruleIndex Index (determined pre-compile-time and/or post-build-time) of the rule to be evaluated. * @return Index to the action list that should be executed as a result of the rule evaluation. Returns -1 if no action should be performed. */ static sint32 BswM_Internal_EvaluateRule( const sint16 ruleIndex ) { BswM_RuleStateType logicalExpression; const BswM_RuleType *rule = &(BswM_Rules[ruleIndex]); const BswM_ActionListType *actionLists = &(BswM_ConfigPtr->ActionListData[0]); sint32 actionListIndex = -1; logicalExpression = BswM_Internal_EvaluateLogicalExpression(rule->LogicalExpressionIndex); if (logicalExpression == BSWM_TRUE) { /* @req BswM0011 */ /* @req BswM0115 */ if (rule->ActionListTrueIndex >= 0) { if ((BSWM_CONDITION == actionLists[rule->ActionListTrueIndex].Execution) || (BSWM_TRUE != BswM_RuleStates[ruleIndex])) { actionListIndex = rule->ActionListTrueIndex; } } BswM_RuleStates[ruleIndex] = BSWM_TRUE; } else if (logicalExpression == BSWM_FALSE) { /* @req BswM0023 */ /* @req BswM0116 */ if (rule->ActionListFalseIndex >= 0) { if ((BSWM_CONDITION == actionLists[rule->ActionListFalseIndex].Execution) || (BSWM_FALSE != BswM_RuleStates[ruleIndex])) { actionListIndex = rule->ActionListFalseIndex; } } BswM_RuleStates[ruleIndex] = BSWM_FALSE; } else { /* Do nothing */ } return actionListIndex; } /** * @brief Executes an action list item that does not refer to another action list or rule. * * Based on the index value stored in the action list item, the function associated with the action is looked up and called. * @param item Pointer to the action list item that should be executed. * @return Forwards E_OK or E_NOT_OK from the action function. */ static Std_ReturnType BswM_Internal_ExecuteAtomicAction( const BswM_ActionListItemType *item ) { extern Std_ReturnType (*BswM_AtomicActions[]) (const BswM_ActionListItemType *item); /*lint -e9003 */ Std_ReturnType (*atomicActionFcn)(const BswM_ActionListItemType *item) = BswM_AtomicActions[item->AtomicActionIndex]; return atomicActionFcn(item); } /** * @brief Saves the list and item index. * * This is a helper function used to keep track of from where an action list or rule is executed within an action list execution. * When the called action list or rule has been executed, the execution of the calling action list need to be resumed. * @param stateBuffer Pointer to context buffer where the indices will be stored. * @param listIndex * @param itemIndex * @return False if there were no empty slots available (i.e. if the nesting level exceeds BSWM_HIERARCHIC_LIST_LEVELS_MAX), otherwise True. */ static boolean BswM_Internal_StoreListState(BswM_ListStateType *stateBuffer, sint32 listIndex, uint32 itemIndex) { boolean didStore = FALSE; if ( stateBuffer->levelCnt < (BSWM_HIERARCHIC_LIST_LEVELS_MAX - 1) ) { stateBuffer->itemIndexBuffer[stateBuffer->levelCnt] = itemIndex; stateBuffer->listIndexBuffer[stateBuffer->levelCnt] = listIndex; stateBuffer->levelCnt++; didStore = TRUE; } return didStore; } /** * @brief Restores the list and item index. * * This is a helper function used to keep track of from where an action list or rule is executed within an action list execution. * When the called action list or rule has been executed, the execution of the calling action list need to be resumed. * @param stateBuffer Pointer to context buffer from where the indices will be restored. * @param listIndex Returns list index. * @param itemIndex Returns item index. * @return False if there were no more state to restore, otherwise True. */ static boolean BswM_Internal_RestoreListState(BswM_ListStateType *stateBuffer, sint32 *listIndex, uint32 *itemIndex) { boolean didRestore = FALSE; if ( stateBuffer->levelCnt > 0 ) { stateBuffer->levelCnt--; *itemIndex = stateBuffer->itemIndexBuffer[stateBuffer->levelCnt]; *listIndex = stateBuffer->listIndexBuffer[stateBuffer->levelCnt]; stateBuffer->listIndexBuffer[stateBuffer->levelCnt] = 0; stateBuffer->itemIndexBuffer[stateBuffer->levelCnt] = 0; didRestore = TRUE; } return didRestore; } /* @req BswM0016 */ /* @req BswM0017 */ /* @req BswM0018 */ /** * @brief Iterates and executes an action list. * * The list items of a given action list @p entryListIndex will be executed. * The action items might refer to another action list or another rule. * @param entryListIndex Index to the action list that should be executed. * @return void */ static void BswM_Internal_IterateActionList(const sint32 entryListIndex) { const BswM_ActionListType *actionLists = &(BswM_ConfigPtr->ActionListData[0]); const BswM_ActionListItemType *item; uint32 itemIndex = 0; sint32 listIndex = entryListIndex; sint32 newListIndex; boolean abortList = FALSE; Std_ReturnType actionResult; BswM_ListStateType listState = { .itemIndexBuffer = {0}, .listIndexBuffer = {0}, .levelCnt = 0 }; /* This loop iterates over an action list. If a list item refers to another list, either explicitly or via a rule evaluation, then that list will be iterated over as well. When arriving at the end of the referred list, then the iteration of the first list is continued. */ do { while ((FALSE==abortList) && (itemIndex < actionLists[listIndex].NumberOfItems)) { item = actionLists[listIndex].Items[itemIndex]; itemIndex++; switch (item->ActionType) { case BSWM_ATOMIC: actionResult = BswM_Internal_ExecuteAtomicAction(item); /* @req BswM0121 */ if (item->ReportFailToDEMRefId >= 0) { if (E_NOT_OK == actionResult) { BSWM_REPORT_ERROR_STATUS(item->ReportFailToDEMRefId, DEM_EVENT_STATUS_FAILED); } else { BSWM_REPORT_ERROR_STATUS(item->ReportFailToDEMRefId, DEM_EVENT_STATUS_PASSED); } } /* @req BswM0055 */ abortList = (TRUE == item->AbortOnFail) && (E_NOT_OK == actionResult); break; case BSWM_LIST: /* Increase list level and start iterating the referred list */ if (TRUE == BswM_Internal_StoreListState(&listState, listIndex, itemIndex)) { listIndex = item->ReferredListIndex; itemIndex = 0; } break; /* @req BswM0019 */ /* @req BswM0067 */ case BSWM_RULE: newListIndex = BswM_Internal_EvaluateRule(item->ReferredRuleIndex); if (newListIndex >= 0) { /* Increase list level and start iterating the referred list */ if (TRUE == BswM_Internal_StoreListState(&listState, listIndex, itemIndex)) { listIndex = newListIndex; itemIndex = 0; } } break; default: break; } } abortList = FALSE; /* No more items in this list or it got aborted, so continue iterating lower level lists if there are any */ } while (TRUE == BswM_Internal_RestoreListState(&listState, &listIndex, &itemIndex)); } #endif #if (BSWM_NUMBER_OF_IMMEDIATE_REQUESTS > 0) /*lint -e528 OTHER*/ static inline boolean BswM_Internal_MirrorNeedsToBeResetToUndefined ( const uint32 modeReqIndex ) { return ( modeReqIndex <= BSWM_IMMEDIATE_REQUEST_NEED_RESET_MIRROR_IDX_MAX ); } /* @req BswM0059 */ /* @req BswM0062 */ /** * @brief Evaluates all the rules referring to an immediate mode request. * * When an immediate request is performed, all the rules that use that request * as a condition in its logical expression needs to be evaluated. * @param modeReqIndex Index to the mode request source. * @return void */ static void BswM_Internal_EvaluateRulesForImmediateRequest( const uint32 modeReqIndex ) { #if (BSWM_NUMBER_OF_RULES_MAX > 0) const sint16 *modeRequestRuleList = BswM_RuleConfigPtr->ImmediateRules[modeReqIndex]; sint16 ruleIndex; sint32 actionListIndex; for ( ; *modeRequestRuleList >= 0; modeRequestRuleList++) { ruleIndex = *modeRequestRuleList; actionListIndex = BswM_Internal_EvaluateRule(ruleIndex); if (0 <= actionListIndex) { BswM_Internal_IterateActionList(actionListIndex); } } #endif #if defined(BSWM_BAC_ADAPTATION) if (TRUE == BswM_Internal_MirrorNeedsToBeResetToUndefined(modeReqIndex)) { BswM_ModeReqMirrors[modeReqIndex] = BSWM_UNDEFINED_REQUEST_VALUE; } #endif } /** * @brief Handle pending requests * * If an immediate request happened during the evaluation of another request (or deferred rules), * they will be processed by this function. * @param void * @return void */ static void BswM_Internal_ProcessDelayedRequests ( void ) { for (uint32 modeReqIndex = 0; modeReqIndex < BSWM_NUMBER_OF_IMMEDIATE_REQUESTS; modeReqIndex++) { if (TRUE == BswM_DelayedRequest[modeReqIndex]) { BswM_Internal_EvaluateRulesForImmediateRequest(modeReqIndex); } } } #endif static inline boolean BswM_Internal_AttemptToProcessRequest ( void ) { boolean okToProcess = FALSE; if (FALSE == BswM_RequestProcessingOngoing) { okToProcess = TRUE; BswM_RequestProcessingOngoing = TRUE; } return okToProcess; } static inline void BswM_Internal_EndRequestProcessing ( void ) { BswM_RequestProcessingOngoing = FALSE; } /* !req BswM0002 */ /* @req BswM0045 */ /* @req BswM0088 */ void BswM_Init(const BswM_ConfigType* ConfigPtr) { /* Validation of parameter: In the failure case when DET is enabled this function will report DET error and return */ BSWM_VALIDATE_CFGPOINTER_NORV(ConfigPtr, BSWM_SERVICEID_INIT); BSWM_VALIDATE_CFGPARAMRANGE_NORV((NULL != ConfigPtr->RuleCfg), BSWM_SERVICEID_INIT); BSWM_VALIDATE_CFGPARAMRANGE_NORV((BSWM_NUMBER_OF_RULES_MAX >= ConfigPtr->RuleCfg->NumberOfRules), BSWM_SERVICEID_INIT); BswM_ConfigPtr = ConfigPtr; BswM_RuleConfigPtr = ConfigPtr->RuleCfg; BswM_Rules = ConfigPtr->RuleCfg->RuleData; uint32 i; #if (BSWM_NUMBER_OF_RULES_MAX > 0) for (i = 0; i < BswM_RuleConfigPtr->NumberOfRules; i++) { BswM_RuleStates[i] = BswM_Rules[i].RuleStateInit; } #endif #if (BSWM_NUMBER_OF_REQUESTS > 0) for (i = 0; i < BSWM_NUMBER_OF_REQUESTS; i++) { BswM_ModeReqMirrors[i] = ConfigPtr->ModeRequestData[i]; } #endif #if (BSWM_NUMBER_OF_IMMEDIATE_REQUESTS > 0) for (i = 0; i < BSWM_NUMBER_OF_IMMEDIATE_REQUESTS; i++) { BswM_DelayedRequest[i] = FALSE; } #endif #if (BSWM_PDUGROUPSWITCH_ACTIONS > 0) BswM_PduGroupSwitchActionPerformed = FALSE; BswM_ComIpduInitialize = FALSE; #endif #if (BSWM_DEADLINEMONITORING_ACTIONS > 0) BswM_DMControlPerformed = FALSE; #endif BswM_RequestProcessingOngoing = FALSE; BswM_Internal.InitStatus = BSWM_INIT; } /* !req BswM0119 */ void BswM_Deinit( void ) { BswM_Internal.InitStatus = BSWM_UNINIT; } /* @req BswM0053 */ void BswM_MainFunction( void ) { BSWM_VALIDATE_INIT_NORV(BSWM_SERVICEID_MAINFUNCTION); /* @req BswM0076 */ #if ((BSWM_PDUGROUPSWITCH_ACTIONS > 0) || (BSWM_DEADLINEMONITORING_ACTIONS > 0)) static boolean firstMainFunctionExecution = TRUE; /* The Com module is initialzed after the BswM so this must be done in the main funciton * and not in BswMInit() */ if (TRUE == firstMainFunctionExecution) { #if (BSWM_PDUGROUPSWITCH_ACTIONS > 0) Com_ClearIpduGroupVector(BswM_ComIpduGroupVector); #endif #if (BSWM_DEADLINEMONITORING_ACTIONS > 0) Com_ClearIpduGroupVector(BswM_DMControlGroupVector); #endif firstMainFunctionExecution = FALSE; } #endif boolean requestCanBeProcessed; SchM_Enter_BswM_EA_0(); requestCanBeProcessed = BswM_Internal_AttemptToProcessRequest(); SchM_Exit_BswM_EA_0(); BswM_Internal_UpdateNotificationMirrors(); /* @req BswM0075 */ /* @req BswM0060 */ #if (BSWM_NUMBER_OF_RULES_MAX > 0) sint16 ruleIndex; sint32 actionListIndex; for (uint32 i = 0; i < BswM_RuleConfigPtr->NumberOfRules; i++) { ruleIndex = BswM_RuleConfigPtr->DeferredRules[i]; if (0 > ruleIndex) { break; } actionListIndex = BswM_Internal_EvaluateRule(ruleIndex); if (0 <= actionListIndex) { BswM_Internal_IterateActionList(actionListIndex); } } #endif /* @req BswM0129 */ #if (BSWM_PDUGROUPSWITCH_ACTIONS > 0) if (TRUE == BswM_PduGroupSwitchActionPerformed) { Com_IpduGroupControl(BswM_ComIpduGroupVector, BswM_ComIpduInitialize); BswM_PduGroupSwitchActionPerformed = FALSE; } #endif #if (BSWM_DEADLINEMONITORING_ACTIONS > 0) if (TRUE == BswM_DMControlPerformed) { Com_ReceptionDMControl(BswM_DMControlGroupVector); BswM_DMControlPerformed = FALSE; } #endif if (TRUE == requestCanBeProcessed) { #if (BSWM_NUMBER_OF_IMMEDIATE_REQUESTS > 0) BswM_Internal_ProcessDelayedRequests(); #endif BswM_Internal_EndRequestProcessing(); } } #if (BSWM_NUMBER_OF_IMMEDIATE_REQUESTS > 0) /** * @brief Try to evaluate all the rules per immediate mode request * * This should be called within the context of an immediate mode request. * All rules referring to the specific mode request will be evaluated. * @param modeReqIndex Index to the mode request source. * @return void */ void BswM_Internal_ProcessImmediateRequest( const uint32 modeReqIndex ) { boolean requestCanBeProcessed; SchM_Enter_BswM_EA_0(); requestCanBeProcessed = BswM_Internal_AttemptToProcessRequest(); SchM_Exit_BswM_EA_0(); if (TRUE == requestCanBeProcessed) { BswM_Internal_EvaluateRulesForImmediateRequest(modeReqIndex); } else { BswM_DelayedRequest[modeReqIndex] = TRUE; } #if (BSWM_PDUGROUPSWITCH_ACTIONS > 0) if (TRUE == BswM_PduGroupSwitchActionPerformed) { Com_IpduGroupControl(BswM_ComIpduGroupVector, BswM_ComIpduInitialize); BswM_PduGroupSwitchActionPerformed = FALSE; } #endif #if (BSWM_DEADLINEMONITORING_ACTIONS > 0) if (TRUE == BswM_DMControlPerformed) { Com_ReceptionDMControl(BswM_DMControlGroupVector); BswM_DMControlPerformed = FALSE; } #endif if (TRUE == requestCanBeProcessed) { BswM_Internal_ProcessDelayedRequests(); BswM_Internal_EndRequestProcessing(); } } #endif #if (BSWM_DEADLINEMONITORING_ACTIONS > 0) /** * @brief Perform a Deadline Monitoring Control action * * Enabling and disabling of deadline monitoring for one or several PDU. * @param item Pointer to the action list item that contains references to the PDUs. * @return void */ void BswM_Internal_DMControlAction( const BswM_ActionListItemType *item ) { const sint32 *pduGroup = item->EnabledPduGroupRefId; if (NULL != pduGroup) { while (*pduGroup >= 0) { Com_SetIpduGroup(BswM_DMControlGroupVector, (Com_IpduGroupIdType) *pduGroup++, TRUE); BswM_DMControlPerformed = TRUE; } } pduGroup = item->DisabledPduGroupRefId; if (NULL != pduGroup) { while (*pduGroup >= 0) { Com_SetIpduGroup(BswM_DMControlGroupVector, (Com_IpduGroupIdType) *pduGroup++, FALSE); BswM_DMControlPerformed = TRUE; } } } #endif #if (BSWM_PDUGROUPSWITCH_ACTIONS > 0) /** * @brief Perform a PDU Group Switch action * * Enabling and disabling of PDU groups. * @param item Pointer to the action list item that contains references to the PDUs. * @return void */ void BswM_Internal_PduGroupSwitchAction( const BswM_ActionListItemType *item ) { const sint32 *pduGroup = item->EnabledPduGroupRefId; if (NULL != pduGroup) { while (*pduGroup >= 0) { Com_SetIpduGroup(BswM_ComIpduGroupVector, (Com_IpduGroupIdType) *pduGroup++, TRUE); BswM_PduGroupSwitchActionPerformed = TRUE; } } pduGroup = item->DisabledPduGroupRefId; if (NULL != pduGroup) { while (*pduGroup >= 0) { Com_SetIpduGroup(BswM_ComIpduGroupVector, (Com_IpduGroupIdType) *pduGroup++, FALSE); BswM_PduGroupSwitchActionPerformed = TRUE; } } BswM_ComIpduInitialize = item->PduGroupSwitchReinit; } #endif #if (BSWM_PDUROUTERCONTROL_ACTIONS > 0) /** * @brief Perform a PDU Routing Path Groups action * * Enabling and disabling of routing of Routing Path Groups in the PDU Router. * @param item Pointer to the action list item that contains references to PDU Routing Path Group. * @return void */ void BswM_Internal_PduRouterControlAction( const BswM_ActionListItemType *item ) { const sint32 *routingPathGroup = item->PduRoutingPathGroupRefId; while (*routingPathGroup >= 0) { if (BSWM_PDUR_ENABLE == item->PduRouterAction) { PduR_EnableRouting((PduR_RoutingPathGroupIdType) *routingPathGroup); } else { PduR_DisableRouting((PduR_RoutingPathGroupIdType) *routingPathGroup); } routingPathGroup++; } } #endif #if (BSWM_VERSION_INFO_API == STD_ON) void BswM_GetVersionInfo( Std_VersionInfoType* VersionInfo ) { BSWM_VALIDATE_POINTER_NORV(VersionInfo, BSWM_SERVICEID_GETVERSIONINFO); /* @req BswM0004 */ /* @req BswM0136 */ STD_GET_VERSION_INFO(VersionInfo,BSWM); } #endif /* BSWM_VERSION_INFO_API */
2301_81045437/classic-platform
system/BswM/src/BswM.c
C
unknown
27,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 */ /*lint -e451 -e9021 AUTOSAR API SWS_MemMap_00003 */ #define BSWM_MEMMAP_ERROR #ifdef BSWM_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 BSWM_MEMMAP_ERROR #undef BSWM_START_SEC_VAR_INIT_UNSPECIFIED #endif #ifdef BSWM_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 BSWM_MEMMAP_ERROR #undef BSWM_STOP_SEC_VAR_INIT_UNSPECIFIED #endif #ifdef BSWM_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 BSWM_MEMMAP_ERROR #undef BSWM_START_SEC_VAR_CLEARED_UNSPECIFIED #endif #ifdef BSWM_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 BSWM_MEMMAP_ERROR #undef BSWM_STOP_SEC_VAR_CLEARED_UNSPECIFIED #endif #ifdef BSWM_MEMMAP_ERROR #error "BswM_BswMemMap.h error, section not mapped" #endif
2301_81045437/classic-platform
system/BswM/src/BswM_BswMemMap.h
C
unknown
2,176
#CAL obj-$(USE_CAL) += Cal_Mac.o obj-$(USE_CAL) += Cal_Cfg.o inc-$(USE_CAL) += $(ROOTDIR)/system/Cal/inc vpath-$(USE_CAL) += $(ROOTDIR)/system/Cal/src
2301_81045437/classic-platform
system/Cal/Cal.mod.mk
Makefile
unknown
156
/*-------------------------------- 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 */ /* @req SWS_Cal_00005 The header file structure shall contain an application interface header file Cal.h */ /* @req SWS_Cal_00016 The CAL shall support reentrant access to all services */ /* @req SWS_Cal_00021 The CAL shall not require initialization phase */ /* @req SWS_Cal_00022 The CAL shall allow parallel access to different services */ /* @req SWS_Cal_00023 CAL shall use a streaming aproach with start, update and finish functions */ /* @req SWS_Cal_00027 The CAL shall not require a shutdown operation phase */ /* @req SWS_Cal_00035 The interface functions shall immediately compute the result */ /* @req SWS_Cal_00067 CAL shall not call the DET in case of error */ /* @req SWS_Cal_00728 CAL services, which do not expect arbitrary amounts of data, only have to provide Cal_<Service>() */ /* @req SWS_Cal_00729 CAL services, which expect arbitrary amounts of data, shall provide Cal_<Service>Start(), Cal_<Service>Update() and Cal_<Service>Finish() */ /* @req SWS_Cal_00731 CAL API can be directly called from BSW modules or SWC. No port definition is required */ /* @req SWS_Cal_00736 A library function shall not call any BSW modules functions */ /* @req SWS_Cal_00015 CAL library and the underlying Crypto Library shall only provide necessary services and algorithms */ #ifndef CAL_H_ #define CAL_H_ #include "Cal_Types.h" /** * Function to initialize the Mac generate service * @param cfgId Identifier of the CAL module configuration to be used for the MAC computation * @param contextBuffer Pointer to the buffer in which the contect of the service is stored * @param keyPtr Pointer to the key to be used for the MAC generation * @return CAL_E_OK if request successful, CAL_E_NOT_OK of request failed */ /* @req SWS_Cal_00108 Cal_MacGenerateStart */ Cal_ReturnType Cal_MacGenerateStart(Cal_ConfigIdType cfgId, Cal_MacGenerateCtxBufType contextBuffer, const Cal_SymKeyType* keyPtr); /** * Function to feed input data to the MAC generate service * @param cfgPtr Identifier of the CAL module configuration to be used for the MAC computation * @param contextBuffer Pointer to the buffer in which the contect of the service is stored * @param dataPtr Pointer to the data for which the MAC shall be computed * @param dataLength Number of bytes for which the MAC shall be computed * @return CAL_E_OK if request successful, CAL_E_NOT_OK of request failed */ /* @req SWS_Cal_00114 Cal_MacGenerateUpdate */ Cal_ReturnType Cal_MacGenerateUpdate(Cal_ConfigIdType cfgId, Cal_MacGenerateCtxBufType contextBuffer, const uint8* dataPtr, uint32 dataLength); /** * Function to finish the MAC generate service * @param cfgPtr Identifier of the CAL module configuration to be used for the MAC computation * @param contextBuffer Pointer to the buffer in which the contect of the service is stored * @param resultPtr Pointer to the memory location to store the generated MAC in. * @param resultLengthPtr On calling this variable contain the size of the resultbuffer, on returning it contains the length of the computed MAC * @param TruncationIsAllowed * @return CAL_E_OK if request successful, CAL_E_NOT_OK of request failed */ /* @req SWS_Cal_00121 Cal_MacGenerateFinish */ Cal_ReturnType Cal_MacGenerateFinish(Cal_ConfigIdType cfgId, Cal_MacGenerateCtxBufType contextBuffer, uint8* resultPtr, uint32* resultLengthPtr, boolean TruncationIsAllowed); /** * Function to initialize the Mac verify service * @param cfgPtr Identifier of the CAL module configuration to be used for the MAC computation * @param contextBuffer Pointer to the buffer in which the contect of the service is stored * @param keyPtr Pointer to the key to be used for the MAC generation * @return CAL_E_OK if request successful, CAL_E_NOT_OK of request failed */ /* @req SWS_Cal_00128 Cal_MacVerifyStart */ Cal_ReturnType Cal_MacVerifyStart(Cal_ConfigIdType cfgId, Cal_MacVerifyCtxBufType contextBuffer, const Cal_SymKeyType* keyPtr); /** * Function to feed input data to the MAC verify service * @param cfgPtr Identifier of the CAL module configuration to be used for the MAC computation * @param contextBuffer Pointer to the buffer in which the contect of the service is stored * @param dataPtr Pointer to the data for which the MAC shall be computed * @param datalength Number of bytes for which the MAC shall be computed * @return CAL_E_OK if request successful, CAL_E_NOT_OK of request failed */ /* @req SWS_Cal_00134 Cal_MacVerifyUpdate */ Cal_ReturnType Cal_MacVerifyUpdate(Cal_ConfigIdType cfgPtr,Cal_MacVerifyCtxBufType contextBuffer, const uint8* dataPtr,uint32 dataLength); /** * Function to finish the MAC verify service * @param cfgPtr Identifier of the CAL module configuration to be used for the MAC computation * @param contextBuffer Pointer to the buffer in which the contect of the service is stored * @param MacPtr Pointer to the MAC to be verified * @param MacLength Length of the MAC to be verified * @param resultPtr Pointer to the result of the MAC verification * @return CAL_E_OK if request successful, CAL_E_NOT_OK of request failed */ /* @req SWS_Cal_00141 Cal_MacVerifyFinish */ Cal_ReturnType Cal_MacVerifyFinish(Cal_ConfigIdType cfgId, Cal_MacVerifyCtxBufType contextBuffer, const uint8* MacPtr, uint32 MacLength, Cal_VerifyResultType* resultPtr); #endif /* CAL_H_ */
2301_81045437/classic-platform
system/Cal/inc/Cal.h
C
unknown
6,255
/*-------------------------------- 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 */ /* @req SWS_Cal_00004 The header file structure shall contain a type header Cal_Types.h */ /* @req SWS_Cal_00068 Only standard AUTOSAR types shall be imported */ /* @req SWS_Cal_00069 Each CPL library shall provide a header file */ /* @req SWS_Cal_00730 All context buffers shall be aligned according to the maximum alignment of all scalar types on the given platform */ #ifndef CAL_TYPES_H_ #define CAL_TYPES_H_ #include "Std_Types.h" #include "Cal_Cfg.h" typedef enum { CAL_E_OK = 0, CAL_E_NOT_OK = 1, CAL_E_SMALL_BUFFER = 3, CAL_E_ENTROPY_EXHAUSTION = 4 } Cal_ReturnType; /* @req SWS_Cal_00075 Cal_VerifyResultType */ typedef enum { CAL_E_VER_OK = 0, CAL_E_VER_NOT_OK = 1 } Cal_VerifyResultType; /* @req SWS_Cal_00073 Cal_ConfigIdType */ typedef uint16 Cal_ConfigIdType; /* @req SWS_Cal_00743 Cal_AlignType */ typedef CalMaxAlignScalarType Cal_AlignType; /* @req SWS_Cal_00742 Cal_MacGenerateCtxBufType */ typedef Cal_AlignType Cal_MacGenerateCtxBufType[CAL_MACGENERATE_CONTEXT_BUFFER_SIZE]; /* @req SWS_Cal_00742 Cal_MacVerifyCtxBufType */ typedef Cal_AlignType Cal_MacVerifyCtxBufType[CAL_MACGENERATE_CONTEXT_BUFFER_SIZE]; /* @req SWS_Cal_00082 Cal_SymKeyType */ typedef struct { uint32 length; Cal_AlignType data[CAL_SYM_KEY_MAX_SIZE]; } Cal_SymKeyType; typedef Cal_ReturnType (*CplMacGenerateStartType)(const void* cfgPtr, Cal_MacGenerateCtxBufType contextBuffer, const Cal_SymKeyType* keyPtr); typedef Cal_ReturnType (*CplMacGenerateUpdateType)(const void* cfgPtr, Cal_MacGenerateCtxBufType contextBuffer, const uint8* dataPtr, uint32 dataLength); typedef Cal_ReturnType (*CplMacGenerateFinishType)(const void* cfgPtr, Cal_MacGenerateCtxBufType contextBuffer, uint8* resultPtr, uint32* resultLengthPtr, boolean TruncationIsAllowed); typedef Cal_ReturnType (*CplMacVerifyStartType)(const void* cfgPtr, Cal_MacVerifyCtxBufType contextBuffer, const Cal_SymKeyType* keyPtr); typedef Cal_ReturnType (*CplMacVerifyUpdateType)(const void* cfgPtr,Cal_MacVerifyCtxBufType contextBuffer, const uint8* dataPtr,uint32 dataLength); typedef Cal_ReturnType (*CplMacVerifyFinishType)(const void* cfgPtr, Cal_MacVerifyCtxBufType contextBuffer, const uint8* MacPtr, uint32 MacLength, Cal_VerifyResultType* resultPtr); /* @req SWS_Cal_00074 Cal_MacGenerateConfigType*/ typedef struct { Cal_ConfigIdType ConfigId; CplMacGenerateStartType MacGenerateStartFunction; CplMacGenerateUpdateType MacGenerateUpdateFunction; CplMacGenerateFinishType MacGenerateFinishFunction; void *MacGenerateConfigPtr; } Cal_MacGenerateConfigType; /* @req SWS_Cal_00074 Cal_MacVerifyConfigType*/ typedef struct { Cal_ConfigIdType ConfigId; CplMacVerifyStartType MacVerifyStartFunction; CplMacVerifyUpdateType MacVerifyUpdateFunction; CplMacVerifyFinishType MacVerifyFinishFunction; void *MacVerifyConfigPtr; } Cal_MacVerifyConfigType; /* @req SWS_Cal_00544 Cpl_MacGenerateConfigType */ typedef struct { Cal_ConfigIdType ConfigId; } Cpl_MacGenerateConfigType; /* @req SWS_Cal_00544 Cpl_MacVerifyConfigType */ typedef struct { Cal_ConfigIdType ConfigId; } Cpl_MacVerifyConfigType; #endif /* CAL_TYPES_H_ */
2301_81045437/classic-platform
system/Cal/inc/Cal_Types.h
C
unknown
4,097
/*-------------------------------- 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 */ /* @req SWS_Cal_00001 The CAL shall be able to incorporate cryptographic library modules specified in chapter 8.4*/ /* @req SWS_Cal_00003 The header file structure shall contain a configuration header Cal_Cfg.h*/ /* @req SWS_Cal_00006 The code file structure shall contain one or more MISRA-C 2004 conform source files Cal_<xxx>.c */ /* @req SWS_Cal_00008 Include file structure for Cal and Cpl*/ /* @req SWS_Cal_00021 The CAL shall not require initialization phase */ /* @req SWS_Cal_00024 Structure of Cal and the states */ /* @req SWS_Cal_00025 Each service shall have a constant structure Cal_<Service>ConfigType (implemented by generator) */ /* @req SWS_Cal_00026 Each configuration shall have a configurable name */ /* @req SWS_Cal_00029 Structure of Cal and the states */ /* @req SWS_Cal_00028 Configure all available and allowed schemes and underlying cryptographic primitives*/ /* @req SWS_Cal_00030 It shall be checked during configuration that only valid service configurations are chosen */ /* @req SWS_Cal_00063 CAL functions should check error when input parameters if there are error cases*/ /* @req SWS_Cal_00064 The API parameters shall be checked in the order in which they are passed*/ /* @req SWS_Cal_00489 Errors should be evaluated for each API call according to the table */ /* @req SWS_Cal_00506 The CAL shall use the interfaces of the incorporated cryptographic library modules to calculate the result of a cryptographic service */ /* @req SWS_Cal_00539 Return API return value if error conditions are met*/ /* @req SWS_Cal_00738 Each .c file should include MemMap.h*/ /* @req SWS_Cal_00739 Each implementation <library>*.c, that uses AUTOSAR integer data types, shall include the header file Std_Types.h */ /* !req SWS_Cal_00740 All the AUTOSAR library Modules should use the AUTOSAR data types insetad of native C data types*/ /* !req SWS_Cal_00741 All the AUTOSAR library Modules should avoid direct use of compiler and platform specific keyword*/ #include "Cal.h" #include "Cpl_Mac.h" #include "MemMap.h" extern const Cal_MacGenerateConfigType CalMacGenerateConfig[ ]; extern const Cal_MacVerifyConfigType CalMacVerifyConfig[ ]; /* * Public functions */ /* @req SWS_Cal_00046 Cal_<Service>Start shall sheck the validity of the configuration it receives */ /* @req SWS_Cal_00047 Cal_<Service>Start shall configure CAL, set the status and store the status in the context buffer */ /* @req SWS_Cal_00488 If an error is detected, return CAL_E_NOT_OK */ Cal_ReturnType Cal_MacGenerateStart(Cal_ConfigIdType cfgId, Cal_MacGenerateCtxBufType contextBuffer, const Cal_SymKeyType* keyPtr) { // Check the cfgId Cal_ReturnType returnVal; returnVal = CAL_E_OK; if ((cfgId >= CalSizeOfGenerateConfig) || (keyPtr == NULL)) { returnVal = CAL_E_NOT_OK; }else { //Set state to active contextBuffer[0] = 1; // Call the Cpl_MacGenerateStart returnVal = CalMacGenerateConfig[cfgId].MacGenerateStartFunction((const void *)CalMacGenerateConfig[cfgId].MacGenerateConfigPtr, contextBuffer, keyPtr); } return returnVal; } /* @req SWS_Cal_00050 Cal_<Service>Update shall check whether the service is initialized */ /* @req SWS_Cal_00051 The CAL shall assume that the data provided to Cal_<Service>Update will not change until it returns */ /* @req SWS_Cal_00052 If the service is initialized, process the data, set the status active, store data in context buffer and return status */ /* @req SWS_Cal_00054 The CAL shall allow the application to call the update function arbitrarily often */ /* @req SWS_Cal_00488 If an error is detected, return CAL_E_NOT_OK */ Cal_ReturnType Cal_MacGenerateUpdate(Cal_ConfigIdType cfgId, Cal_MacGenerateCtxBufType contextBuffer, const uint8* dataPtr, uint32 dataLength) { //check if contextBuffer is "idle" Cal_ReturnType returnVal; returnVal = CAL_E_OK; if ((cfgId >= CalSizeOfGenerateConfig) || (contextBuffer[0] == 0) || (dataPtr == NULL)) { returnVal = CAL_E_NOT_OK; } else { // Call the Cpl_MacGenerateUpdate returnVal = CalMacGenerateConfig[cfgId].MacGenerateUpdateFunction((const void *)CalMacGenerateConfig[cfgId].MacGenerateConfigPtr, contextBuffer, dataPtr, dataLength); } return returnVal; } /* @req SWS_Cal_00056 Cal_<Service>Finish shall check whether the service is initialized */ /* @req SWS_Cal_00057 The CAL shall assume that the data provided to Cal_<Service>Finish will not change until it returns */ /* @req SWS_Cal_00058 If the service is initialized, process the data, set the status to idle, store result in result buffer and return status */ /* @req SWS_Cal_00662 The CAL shall check if the provided buffer is large enough to hold the result of the computation */ /* @req SWS_Cal_00488 If an error is detected, return CAL_E_NOT_OK */ Cal_ReturnType Cal_MacGenerateFinish(Cal_ConfigIdType cfgId, Cal_MacGenerateCtxBufType contextBuffer, uint8* resultPtr, uint32* resultLengthPtr, boolean TruncationIsAllowed) { Cal_ReturnType returnVal; returnVal = CAL_E_OK; if ((cfgId >= CalSizeOfGenerateConfig) || (contextBuffer[0] == 0) || (resultPtr == NULL) || (resultLengthPtr == NULL)) { returnVal = CAL_E_NOT_OK; } else { uint32 tempResultLength = *resultLengthPtr; // Call the Cpl_MacGenerateFinish returnVal = CalMacGenerateConfig[cfgId].MacGenerateFinishFunction((const void *)CalMacGenerateConfig[cfgId].MacGenerateConfigPtr, contextBuffer, resultPtr, resultLengthPtr, TruncationIsAllowed); if (returnVal == CAL_E_OK) { contextBuffer[0] = 0; } if((*resultLengthPtr > tempResultLength) && (FALSE == TruncationIsAllowed)) { returnVal = CAL_E_SMALL_BUFFER; } } return returnVal; } /* @req SWS_Cal_00046 Cal_<Service>Start shall sheck the validity of the configuration it receives */ /* @req SWS_Cal_00047 Cal_<Service>Start shall configure CAL, set the status and store the status in the context buffer */ /* @req SWS_Cal_00488 If an error is detected, return CAL_E_NOT_OK */ Cal_ReturnType Cal_MacVerifyStart(Cal_ConfigIdType cfgId, Cal_MacVerifyCtxBufType contextBuffer, const Cal_SymKeyType* keyPtr) { Cal_ReturnType returnVal; returnVal = CAL_E_OK; if ((cfgId >= CalSizeOfGenerateConfig) || (keyPtr == NULL)) { returnVal = CAL_E_NOT_OK; } else { //Set status to active contextBuffer[0] = 1; // Call the Cpl_MacVerifyStart returnVal = CalMacVerifyConfig[cfgId].MacVerifyStartFunction((const void *)CalMacVerifyConfig[cfgId].MacVerifyConfigPtr, contextBuffer, keyPtr); } return returnVal; } /* @req SWS_Cal_00050 Cal_<Service>Update shall check whether the service is initialized */ /* @req SWS_Cal_00051 The CAL shall assume that the data provided to Cal_<Service>Update will not change until it returns */ /* @req SWS_Cal_00052 If the service is initialized, process the data, set the status active, store data in context buffer and return status */ /* @req SWS_Cal_00054 The CAL shall allow the application to call the update function arbitrarily often */ /* @req SWS_Cal_00478 As the CAL is a library, all functions have to be reentrant */ /* @req SWS_Cal_00488 If an error is detected, return CAL_E_NOT_OK */ Cal_ReturnType Cal_MacVerifyUpdate(Cal_ConfigIdType cfgId, Cal_MacVerifyCtxBufType contextBuffer, const uint8* dataPtr, uint32 dataLength) { Cal_ReturnType returnVal; returnVal = CAL_E_OK; if ((cfgId >= CalSizeOfGenerateConfig) || (contextBuffer[0] == 0) || (dataPtr == NULL)) { returnVal = CAL_E_NOT_OK; } else { // Call the Cpl_MacVerifyUpdate returnVal = CalMacVerifyConfig[cfgId].MacVerifyUpdateFunction((const void *)CalMacVerifyConfig[cfgId].MacVerifyConfigPtr, contextBuffer,dataPtr,dataLength); } return returnVal; } /* @req SWS_Cal_00056 Cal_<Service>Finish shall check whether the service is initialized */ /* @req SWS_Cal_00057 The CAL shall assume that the data provided to Cal_<Service>Finish will not change until it returns */ /* @req SWS_Cal_00058 If the service is initialized, process the data, set the status to idle, store result in result buffer and return status */ /* @req SWS_Cal_00488 If an error is detected, return CAL_E_NOT_OK */ Cal_ReturnType Cal_MacVerifyFinish(Cal_ConfigIdType cfgId, Cal_MacVerifyCtxBufType contextBuffer, const uint8* MacPtr, uint32 MacLength, Cal_VerifyResultType* resultPtr) { Cal_ReturnType returnVal; returnVal = CAL_E_OK; if ((cfgId >= CalSizeOfGenerateConfig)|| (contextBuffer[0] == 0) || (resultPtr == NULL)) { returnVal = CAL_E_NOT_OK; } else { // Call the Cpl_MacVerifyFinish returnVal = CalMacVerifyConfig[cfgId].MacVerifyFinishFunction((const void *)CalMacVerifyConfig[cfgId].MacVerifyConfigPtr, contextBuffer,MacPtr,MacLength,resultPtr); //Set status to "idle" contextBuffer[0] = 0; } return returnVal; }
2301_81045437/classic-platform
system/Cal/src/Cal_Mac.c
C
unknown
9,989
#CPL obj-$(USE_CPL) += Cpl_Mac.o obj-$(USE_CPL) += hmac_sha2.o obj-$(USE_CPL) += sha2.o inc-$(USE_CPL) += $(ROOTDIR)/system/Cpl inc-$(USE_CPL) += $(ROOTDIR)/system/Cpl/src inc-$(USE_CPL) += $(ROOTDIR)/system/Cpl/crypto vpath-$(USE_CPL) += $(ROOTDIR)/system/Cpl/src vpath-$(USE_CPL) += $(ROOTDIR)/system/Cpl/crypto
2301_81045437/classic-platform
system/Cpl/Cpl.mod.mk
Makefile
unknown
327
/* * HMAC-SHA-224/256/384/512 implementation * Last update: 06/15/2005 * Issue date: 06/15/2005 * * Copyright (C) 2005 Olivier Gay <olivier.gay@a3.epfl.ch> * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. 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. * 3. Neither the name of the project 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 PROJECT 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 PROJECT OR 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. */ //lint -w1 #include <string.h> #include "hmac_sha2.h" #if 0 /* HMAC-SHA-224 functions */ void hmac_sha224_init(hmac_sha224_ctx *ctx, const unsigned char *key, unsigned int key_size) { unsigned int fill; unsigned int num; const unsigned char *key_used; unsigned char key_temp[SHA224_DIGEST_SIZE]; int i; if (key_size == SHA224_BLOCK_SIZE) { key_used = key; num = SHA224_BLOCK_SIZE; } else { if (key_size > SHA224_BLOCK_SIZE){ num = SHA224_DIGEST_SIZE; sha224(key, key_size, key_temp); key_used = key_temp; } else { /* key_size > SHA224_BLOCK_SIZE */ key_used = key; num = key_size; } fill = SHA224_BLOCK_SIZE - num; memset(ctx->block_ipad + num, 0x36, fill); memset(ctx->block_opad + num, 0x5c, fill); } for (i = 0; i < (int) num; i++) { ctx->block_ipad[i] = key_used[i] ^ 0x36; ctx->block_opad[i] = key_used[i] ^ 0x5c; } sha224_init(&ctx->ctx_inside); sha224_update(&ctx->ctx_inside, ctx->block_ipad, SHA224_BLOCK_SIZE); sha224_init(&ctx->ctx_outside); sha224_update(&ctx->ctx_outside, ctx->block_opad, SHA224_BLOCK_SIZE); /* for hmac_reinit */ memcpy(&ctx->ctx_inside_reinit, &ctx->ctx_inside, sizeof(sha224_ctx)); memcpy(&ctx->ctx_outside_reinit, &ctx->ctx_outside, sizeof(sha224_ctx)); } void hmac_sha224_reinit(hmac_sha224_ctx *ctx) { memcpy(&ctx->ctx_inside, &ctx->ctx_inside_reinit, sizeof(sha224_ctx)); memcpy(&ctx->ctx_outside, &ctx->ctx_outside_reinit, sizeof(sha224_ctx)); } void hmac_sha224_update(hmac_sha224_ctx *ctx, const unsigned char *message, unsigned int message_len) { sha224_update(&ctx->ctx_inside, message, message_len); } void hmac_sha224_final(hmac_sha224_ctx *ctx, unsigned char *mac, unsigned int mac_size) { unsigned char digest_inside[SHA224_DIGEST_SIZE]; unsigned char mac_temp[SHA224_DIGEST_SIZE]; sha224_final(&ctx->ctx_inside, digest_inside); sha224_update(&ctx->ctx_outside, digest_inside, SHA224_DIGEST_SIZE); sha224_final(&ctx->ctx_outside, mac_temp); memcpy(mac, mac_temp, mac_size); } void hmac_sha224(const unsigned char *key, unsigned int key_size, const unsigned char *message, unsigned int message_len, unsigned char *mac, unsigned mac_size) { hmac_sha224_ctx ctx; hmac_sha224_init(&ctx, key, key_size); hmac_sha224_update(&ctx, message, message_len); hmac_sha224_final(&ctx, mac, mac_size); } #endif /* HMAC-SHA-256 functions */ void hmac_sha256_init(hmac_sha256_ctx *ctx, const Cal_AlignType *key, unsigned int key_size) { unsigned int fill; unsigned int num; const Cal_AlignType *key_used; Cal_AlignType key_temp[SHA256_DIGEST_SIZE]; int i; if (key_size == SHA256_BLOCK_SIZE) { key_used = key; num = SHA256_BLOCK_SIZE; } else { if (key_size > SHA256_BLOCK_SIZE){ num = SHA256_DIGEST_SIZE; sha256(key, key_size, key_temp); key_used = key_temp; } else { /* key_size > SHA256_BLOCK_SIZE */ key_used = key; num = key_size; } fill = SHA256_BLOCK_SIZE - num; memset(ctx->block_ipad + num, 0x36, fill); memset(ctx->block_opad + num, 0x5c, fill); } for (i = 0; i < (int) num; i++) { ctx->block_ipad[i] = key_used[i] ^ 0x36; ctx->block_opad[i] = key_used[i] ^ 0x5c; } sha256_init(&ctx->ctx_inside); sha256_update(&ctx->ctx_inside, ctx->block_ipad, SHA256_BLOCK_SIZE); sha256_init(&ctx->ctx_outside); sha256_update(&ctx->ctx_outside, ctx->block_opad, SHA256_BLOCK_SIZE); /* for hmac_reinit */ memcpy(&ctx->ctx_inside_reinit, &ctx->ctx_inside, sizeof(sha256_ctx)); memcpy(&ctx->ctx_outside_reinit, &ctx->ctx_outside, sizeof(sha256_ctx)); } void hmac_sha256_reinit(hmac_sha256_ctx *ctx) { memcpy(&ctx->ctx_inside, &ctx->ctx_inside_reinit, sizeof(sha256_ctx)); memcpy(&ctx->ctx_outside, &ctx->ctx_outside_reinit, sizeof(sha256_ctx)); } void hmac_sha256_update(hmac_sha256_ctx *ctx, const unsigned char *message, unsigned int message_len) { sha256_update(&ctx->ctx_inside, message, message_len); } void hmac_sha256_final(hmac_sha256_ctx *ctx, unsigned char *mac, unsigned int mac_size) { unsigned char digest_inside[SHA256_DIGEST_SIZE]; unsigned char mac_temp[SHA256_DIGEST_SIZE]; sha256_final(&ctx->ctx_inside, digest_inside); sha256_update(&ctx->ctx_outside, digest_inside, SHA256_DIGEST_SIZE); sha256_final(&ctx->ctx_outside, mac_temp); memcpy(mac, mac_temp, mac_size); } #if 0 void hmac_sha256(const Cal_AlignType *key, unsigned int key_size, const unsigned char *message, unsigned int message_len, unsigned char *mac, unsigned mac_size) { hmac_sha256_ctx ctx; hmac_sha256_init(&ctx, key, key_size); hmac_sha256_update(&ctx, message, message_len); hmac_sha256_final(&ctx, mac, mac_size); } /* HMAC-SHA-384 functions */ void hmac_sha384_init(hmac_sha384_ctx *ctx, const unsigned char *key, unsigned int key_size) { unsigned int fill; unsigned int num; const unsigned char *key_used; unsigned char key_temp[SHA384_DIGEST_SIZE]; int i; if (key_size == SHA384_BLOCK_SIZE) { key_used = key; num = SHA384_BLOCK_SIZE; } else { if (key_size > SHA384_BLOCK_SIZE){ num = SHA384_DIGEST_SIZE; sha384(key, key_size, key_temp); key_used = key_temp; } else { /* key_size > SHA384_BLOCK_SIZE */ key_used = key; num = key_size; } fill = SHA384_BLOCK_SIZE - num; memset(ctx->block_ipad + num, 0x36, fill); memset(ctx->block_opad + num, 0x5c, fill); } for (i = 0; i < (int) num; i++) { ctx->block_ipad[i] = key_used[i] ^ 0x36; ctx->block_opad[i] = key_used[i] ^ 0x5c; } sha384_init(&ctx->ctx_inside); sha384_update(&ctx->ctx_inside, ctx->block_ipad, SHA384_BLOCK_SIZE); sha384_init(&ctx->ctx_outside); sha384_update(&ctx->ctx_outside, ctx->block_opad, SHA384_BLOCK_SIZE); /* for hmac_reinit */ memcpy(&ctx->ctx_inside_reinit, &ctx->ctx_inside, sizeof(sha384_ctx)); memcpy(&ctx->ctx_outside_reinit, &ctx->ctx_outside, sizeof(sha384_ctx)); } void hmac_sha384_reinit(hmac_sha384_ctx *ctx) { memcpy(&ctx->ctx_inside, &ctx->ctx_inside_reinit, sizeof(sha384_ctx)); memcpy(&ctx->ctx_outside, &ctx->ctx_outside_reinit, sizeof(sha384_ctx)); } void hmac_sha384_update(hmac_sha384_ctx *ctx, const unsigned char *message, unsigned int message_len) { sha384_update(&ctx->ctx_inside, message, message_len); } void hmac_sha384_final(hmac_sha384_ctx *ctx, unsigned char *mac, unsigned int mac_size) { unsigned char digest_inside[SHA384_DIGEST_SIZE]; unsigned char mac_temp[SHA384_DIGEST_SIZE]; sha384_final(&ctx->ctx_inside, digest_inside); sha384_update(&ctx->ctx_outside, digest_inside, SHA384_DIGEST_SIZE); sha384_final(&ctx->ctx_outside, mac_temp); memcpy(mac, mac_temp, mac_size); } void hmac_sha384(const unsigned char *key, unsigned int key_size, const unsigned char *message, unsigned int message_len, unsigned char *mac, unsigned mac_size) { hmac_sha384_ctx ctx; hmac_sha384_init(&ctx, key, key_size); hmac_sha384_update(&ctx, message, message_len); hmac_sha384_final(&ctx, mac, mac_size); } /* HMAC-SHA-512 functions */ void hmac_sha512_init(hmac_sha512_ctx *ctx, const unsigned char *key, unsigned int key_size) { unsigned int fill; unsigned int num; const unsigned char *key_used; unsigned char key_temp[SHA512_DIGEST_SIZE]; int i; if (key_size == SHA512_BLOCK_SIZE) { key_used = key; num = SHA512_BLOCK_SIZE; } else { if (key_size > SHA512_BLOCK_SIZE){ num = SHA512_DIGEST_SIZE; sha512(key, key_size, key_temp); key_used = key_temp; } else { /* key_size > SHA512_BLOCK_SIZE */ key_used = key; num = key_size; } fill = SHA512_BLOCK_SIZE - num; memset(ctx->block_ipad + num, 0x36, fill); memset(ctx->block_opad + num, 0x5c, fill); } for (i = 0; i < (int) num; i++) { ctx->block_ipad[i] = key_used[i] ^ 0x36; ctx->block_opad[i] = key_used[i] ^ 0x5c; } sha512_init(&ctx->ctx_inside); sha512_update(&ctx->ctx_inside, ctx->block_ipad, SHA512_BLOCK_SIZE); sha512_init(&ctx->ctx_outside); sha512_update(&ctx->ctx_outside, ctx->block_opad, SHA512_BLOCK_SIZE); /* for hmac_reinit */ memcpy(&ctx->ctx_inside_reinit, &ctx->ctx_inside, sizeof(sha512_ctx)); memcpy(&ctx->ctx_outside_reinit, &ctx->ctx_outside, sizeof(sha512_ctx)); } void hmac_sha512_reinit(hmac_sha512_ctx *ctx) { memcpy(&ctx->ctx_inside, &ctx->ctx_inside_reinit, sizeof(sha512_ctx)); memcpy(&ctx->ctx_outside, &ctx->ctx_outside_reinit, sizeof(sha512_ctx)); } void hmac_sha512_update(hmac_sha512_ctx *ctx, const unsigned char *message, unsigned int message_len) { sha512_update(&ctx->ctx_inside, message, message_len); } void hmac_sha512_final(hmac_sha512_ctx *ctx, unsigned char *mac, unsigned int mac_size) { unsigned char digest_inside[SHA512_DIGEST_SIZE]; unsigned char mac_temp[SHA512_DIGEST_SIZE]; sha512_final(&ctx->ctx_inside, digest_inside); sha512_update(&ctx->ctx_outside, digest_inside, SHA512_DIGEST_SIZE); sha512_final(&ctx->ctx_outside, mac_temp); memcpy(mac, mac_temp, mac_size); } void hmac_sha512(const unsigned char *key, unsigned int key_size, const unsigned char *message, unsigned int message_len, unsigned char *mac, unsigned mac_size) { hmac_sha512_ctx ctx; hmac_sha512_init(&ctx, key, key_size); hmac_sha512_update(&ctx, message, message_len); hmac_sha512_final(&ctx, mac, mac_size); } #endif
2301_81045437/classic-platform
system/Cpl/crypto/hmac_sha2.c
C
unknown
12,559
/* * HMAC-SHA-224/256/384/512 implementation * Last update: 06/15/2005 * Issue date: 06/15/2005 * * Copyright (C) 2005 Olivier Gay <olivier.gay@a3.epfl.ch> * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. 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. * 3. Neither the name of the project 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 PROJECT 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 PROJECT OR 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. */ #ifndef HMAC_SHA2_H #define HMAC_SHA2_H /*lint -save -e970 */ #include "sha2.h" #include "Cal_Types.h" #ifdef __cplusplus extern "C" { #endif #if 0 typedef struct { sha224_ctx ctx_inside; sha224_ctx ctx_outside; /* for hmac_reinit */ sha224_ctx ctx_inside_reinit; sha224_ctx ctx_outside_reinit; unsigned char block_ipad[SHA224_BLOCK_SIZE]; unsigned char block_opad[SHA224_BLOCK_SIZE]; } hmac_sha224_ctx; #endif typedef struct { sha256_ctx ctx_inside; sha256_ctx ctx_outside; /* for hmac_reinit */ sha256_ctx ctx_inside_reinit; sha256_ctx ctx_outside_reinit; unsigned char block_ipad[SHA256_BLOCK_SIZE]; unsigned char block_opad[SHA256_BLOCK_SIZE]; } hmac_sha256_ctx; #if 0 typedef struct { sha384_ctx ctx_inside; sha384_ctx ctx_outside; /* for hmac_reinit */ sha384_ctx ctx_inside_reinit; sha384_ctx ctx_outside_reinit; unsigned char block_ipad[SHA384_BLOCK_SIZE]; unsigned char block_opad[SHA384_BLOCK_SIZE]; } hmac_sha384_ctx; typedef struct { sha512_ctx ctx_inside; sha512_ctx ctx_outside; /* for hmac_reinit */ sha512_ctx ctx_inside_reinit; sha512_ctx ctx_outside_reinit; unsigned char block_ipad[SHA512_BLOCK_SIZE]; unsigned char block_opad[SHA512_BLOCK_SIZE]; } hmac_sha512_ctx; void hmac_sha224_init(hmac_sha224_ctx *ctx, const unsigned char *key, unsigned int key_size); void hmac_sha224_reinit(hmac_sha224_ctx *ctx); void hmac_sha224_update(hmac_sha224_ctx *ctx, const unsigned char *message, unsigned int message_len); void hmac_sha224_final(hmac_sha224_ctx *ctx, unsigned char *mac, unsigned int mac_size); void hmac_sha224(const unsigned char *key, unsigned int key_size, const unsigned char *message, unsigned int message_len, unsigned char *mac, unsigned mac_size); #endif void hmac_sha256_init(hmac_sha256_ctx *ctx, const Cal_AlignType *key, unsigned int key_size); void hmac_sha256_reinit(hmac_sha256_ctx *ctx); void hmac_sha256_update(hmac_sha256_ctx *ctx, const unsigned char *message, unsigned int message_len); void hmac_sha256_final(hmac_sha256_ctx *ctx, unsigned char *mac, unsigned int mac_size); #if 0 void hmac_sha256(const Cal_AlignType *key, unsigned int key_size, const unsigned char *message, unsigned int message_len, unsigned char *mac, unsigned mac_size); void hmac_sha384_init(hmac_sha384_ctx *ctx, const unsigned char *key, unsigned int key_size); void hmac_sha384_reinit(hmac_sha384_ctx *ctx); void hmac_sha384_update(hmac_sha384_ctx *ctx, const unsigned char *message, unsigned int message_len); void hmac_sha384_final(hmac_sha384_ctx *ctx, unsigned char *mac, unsigned int mac_size); void hmac_sha384(const unsigned char *key, unsigned int key_size, const unsigned char *message, unsigned int message_len, unsigned char *mac, unsigned mac_size); void hmac_sha512_init(hmac_sha512_ctx *ctx, const unsigned char *key, unsigned int key_size); void hmac_sha512_reinit(hmac_sha512_ctx *ctx); void hmac_sha512_update(hmac_sha512_ctx *ctx, const unsigned char *message, unsigned int message_len); void hmac_sha512_final(hmac_sha512_ctx *ctx, unsigned char *mac, unsigned int mac_size); void hmac_sha512(const unsigned char *key, unsigned int key_size, const unsigned char *message, unsigned int message_len, unsigned char *mac, unsigned mac_size); #endif #ifdef __cplusplus } #endif //lint -restore #endif /* !HMAC_SHA2_H */
2301_81045437/classic-platform
system/Cpl/crypto/hmac_sha2.h
C
unknown
5,622
/* * FIPS 180-2 SHA-224/256/384/512 implementation * Last update: 02/02/2007 * Issue date: 04/30/2005 * * Copyright (C) 2005, 2007 Olivier Gay <olivier.gay@a3.epfl.ch> * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. 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. * 3. Neither the name of the project 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 PROJECT 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 PROJECT OR 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. */ //lint -w1 #if 0 #define UNROLL_LOOPS /* Enable loops unrolling */ #endif #include <string.h> #include "sha2.h" #define SHFR(x, n) (x >> n) #define ROTR(x, n) ((x >> n) | (x << ((sizeof(x) << 3) - n))) #define ROTL(x, n) ((x << n) | (x >> ((sizeof(x) << 3) - n))) #define CH(x, y, z) ((x & y) ^ (~x & z)) #define MAJ(x, y, z) ((x & y) ^ (x & z) ^ (y & z)) #define SHA256_F1(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22)) #define SHA256_F2(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25)) #define SHA256_F3(x) (ROTR(x, 7) ^ ROTR(x, 18) ^ SHFR(x, 3)) #define SHA256_F4(x) (ROTR(x, 17) ^ ROTR(x, 19) ^ SHFR(x, 10)) #if 0 #define SHA512_F1(x) (ROTR(x, 28) ^ ROTR(x, 34) ^ ROTR(x, 39)) #define SHA512_F2(x) (ROTR(x, 14) ^ ROTR(x, 18) ^ ROTR(x, 41)) #define SHA512_F3(x) (ROTR(x, 1) ^ ROTR(x, 8) ^ SHFR(x, 7)) #define SHA512_F4(x) (ROTR(x, 19) ^ ROTR(x, 61) ^ SHFR(x, 6)) #endif #define UNPACK32(x, str) \ { \ *((str) + 3) = (uint8) ((x) ); \ *((str) + 2) = (uint8) ((x) >> 8); \ *((str) + 1) = (uint8) ((x) >> 16); \ *((str) + 0) = (uint8) ((x) >> 24); \ } #define PACK32(str, x) \ { \ *(x) = ((uint32) *((str) + 3) ) \ | ((uint32) *((str) + 2) << 8) \ | ((uint32) *((str) + 1) << 16) \ | ((uint32) *((str) + 0) << 24); \ } #define UNPACK64(x, str) \ { \ *((str) + 7) = (uint8) ((x) ); \ *((str) + 6) = (uint8) ((x) >> 8); \ *((str) + 5) = (uint8) ((x) >> 16); \ *((str) + 4) = (uint8) ((x) >> 24); \ *((str) + 3) = (uint8) ((x) >> 32); \ *((str) + 2) = (uint8) ((x) >> 40); \ *((str) + 1) = (uint8) ((x) >> 48); \ *((str) + 0) = (uint8) ((x) >> 56); \ } #define PACK64(str, x) \ { \ *(x) = ((uint64) *((str) + 7) ) \ | ((uint64) *((str) + 6) << 8) \ | ((uint64) *((str) + 5) << 16) \ | ((uint64) *((str) + 4) << 24) \ | ((uint64) *((str) + 3) << 32) \ | ((uint64) *((str) + 2) << 40) \ | ((uint64) *((str) + 1) << 48) \ | ((uint64) *((str) + 0) << 56); \ } /* Macros used for loops unrolling */ #define SHA256_SCR(i) \ { \ w[i] = SHA256_F4(w[i - 2]) + w[i - 7] \ + SHA256_F3(w[i - 15]) + w[i - 16]; \ } #define SHA512_SCR(i) \ { \ w[i] = SHA512_F4(w[i - 2]) + w[i - 7] \ + SHA512_F3(w[i - 15]) + w[i - 16]; \ } #define SHA256_EXP(a, b, c, d, e, f, g, h, j) \ { \ t1 = wv[h] + SHA256_F2(wv[e]) + CH(wv[e], wv[f], wv[g]) \ + sha256_k[j] + w[j]; \ t2 = SHA256_F1(wv[a]) + MAJ(wv[a], wv[b], wv[c]); \ wv[d] += t1; \ wv[h] = t1 + t2; \ } #define SHA512_EXP(a, b, c, d, e, f, g ,h, j) \ { \ t1 = wv[h] + SHA512_F2(wv[e]) + CH(wv[e], wv[f], wv[g]) \ + sha512_k[j] + w[j]; \ t2 = SHA512_F1(wv[a]) + MAJ(wv[a], wv[b], wv[c]); \ wv[d] += t1; \ wv[h] = t1 + t2; \ } const uint32 sha224_h0[8] = {0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4}; const uint32 sha256_h0[8] = {0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19}; const uint64 sha384_h0[8] = {0xcbbb9d5dc1059ed8ULL, 0x629a292a367cd507ULL, 0x9159015a3070dd17ULL, 0x152fecd8f70e5939ULL, 0x67332667ffc00b31ULL, 0x8eb44a8768581511ULL, 0xdb0c2e0d64f98fa7ULL, 0x47b5481dbefa4fa4ULL}; const uint64 sha512_h0[8] = {0x6a09e667f3bcc908ULL, 0xbb67ae8584caa73bULL, 0x3c6ef372fe94f82bULL, 0xa54ff53a5f1d36f1ULL, 0x510e527fade682d1ULL, 0x9b05688c2b3e6c1fULL, 0x1f83d9abfb41bd6bULL, 0x5be0cd19137e2179ULL}; const uint32 sha256_k[64] = {0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2}; #if 0 const uint64 sha512_k[80] = {0x428a2f98d728ae22ULL, 0x7137449123ef65cdULL, 0xb5c0fbcfec4d3b2fULL, 0xe9b5dba58189dbbcULL, 0x3956c25bf348b538ULL, 0x59f111f1b605d019ULL, 0x923f82a4af194f9bULL, 0xab1c5ed5da6d8118ULL, 0xd807aa98a3030242ULL, 0x12835b0145706fbeULL, 0x243185be4ee4b28cULL, 0x550c7dc3d5ffb4e2ULL, 0x72be5d74f27b896fULL, 0x80deb1fe3b1696b1ULL, 0x9bdc06a725c71235ULL, 0xc19bf174cf692694ULL, 0xe49b69c19ef14ad2ULL, 0xefbe4786384f25e3ULL, 0x0fc19dc68b8cd5b5ULL, 0x240ca1cc77ac9c65ULL, 0x2de92c6f592b0275ULL, 0x4a7484aa6ea6e483ULL, 0x5cb0a9dcbd41fbd4ULL, 0x76f988da831153b5ULL, 0x983e5152ee66dfabULL, 0xa831c66d2db43210ULL, 0xb00327c898fb213fULL, 0xbf597fc7beef0ee4ULL, 0xc6e00bf33da88fc2ULL, 0xd5a79147930aa725ULL, 0x06ca6351e003826fULL, 0x142929670a0e6e70ULL, 0x27b70a8546d22ffcULL, 0x2e1b21385c26c926ULL, 0x4d2c6dfc5ac42aedULL, 0x53380d139d95b3dfULL, 0x650a73548baf63deULL, 0x766a0abb3c77b2a8ULL, 0x81c2c92e47edaee6ULL, 0x92722c851482353bULL, 0xa2bfe8a14cf10364ULL, 0xa81a664bbc423001ULL, 0xc24b8b70d0f89791ULL, 0xc76c51a30654be30ULL, 0xd192e819d6ef5218ULL, 0xd69906245565a910ULL, 0xf40e35855771202aULL, 0x106aa07032bbd1b8ULL, 0x19a4c116b8d2d0c8ULL, 0x1e376c085141ab53ULL, 0x2748774cdf8eeb99ULL, 0x34b0bcb5e19b48a8ULL, 0x391c0cb3c5c95a63ULL, 0x4ed8aa4ae3418acbULL, 0x5b9cca4f7763e373ULL, 0x682e6ff3d6b2b8a3ULL, 0x748f82ee5defb2fcULL, 0x78a5636f43172f60ULL, 0x84c87814a1f0ab72ULL, 0x8cc702081a6439ecULL, 0x90befffa23631e28ULL, 0xa4506cebde82bde9ULL, 0xbef9a3f7b2c67915ULL, 0xc67178f2e372532bULL, 0xca273eceea26619cULL, 0xd186b8c721c0c207ULL, 0xeada7dd6cde0eb1eULL, 0xf57d4f7fee6ed178ULL, 0x06f067aa72176fbaULL, 0x0a637dc5a2c898a6ULL, 0x113f9804bef90daeULL, 0x1b710b35131c471bULL, 0x28db77f523047d84ULL, 0x32caab7b40c72493ULL, 0x3c9ebe0a15c9bebcULL, 0x431d67c49c100d4cULL, 0x4cc5d4becb3e42b6ULL, 0x597f299cfc657e2aULL, 0x5fcb6fab3ad6faecULL, 0x6c44198c4a475817ULL}; #endif /* SHA-256 functions */ void sha256_transf(sha256_ctx *ctx, const unsigned char *message, unsigned int block_nb) { uint32 w[64]; uint32 wv[8]; uint32 t1, t2; const unsigned char *sub_block; int i; #ifndef UNROLL_LOOPS int j; #endif for (i = 0; i < (int) block_nb; i++) { sub_block = message + (i << 6); #ifndef UNROLL_LOOPS for (j = 0; j < 16; j++) { PACK32(&sub_block[j << 2], &w[j]); } for (j = 16; j < 64; j++) { SHA256_SCR(j); } for (j = 0; j < 8; j++) { wv[j] = ctx->h[j]; } for (j = 0; j < 64; j++) { t1 = wv[7] + SHA256_F2(wv[4]) + CH(wv[4], wv[5], wv[6]) + sha256_k[j] + w[j]; t2 = SHA256_F1(wv[0]) + MAJ(wv[0], wv[1], wv[2]); wv[7] = wv[6]; wv[6] = wv[5]; wv[5] = wv[4]; wv[4] = wv[3] + t1; wv[3] = wv[2]; wv[2] = wv[1]; wv[1] = wv[0]; wv[0] = t1 + t2; } for (j = 0; j < 8; j++) { ctx->h[j] += wv[j]; } #else PACK32(&sub_block[ 0], &w[ 0]); PACK32(&sub_block[ 4], &w[ 1]); PACK32(&sub_block[ 8], &w[ 2]); PACK32(&sub_block[12], &w[ 3]); PACK32(&sub_block[16], &w[ 4]); PACK32(&sub_block[20], &w[ 5]); PACK32(&sub_block[24], &w[ 6]); PACK32(&sub_block[28], &w[ 7]); PACK32(&sub_block[32], &w[ 8]); PACK32(&sub_block[36], &w[ 9]); PACK32(&sub_block[40], &w[10]); PACK32(&sub_block[44], &w[11]); PACK32(&sub_block[48], &w[12]); PACK32(&sub_block[52], &w[13]); PACK32(&sub_block[56], &w[14]); PACK32(&sub_block[60], &w[15]); SHA256_SCR(16); SHA256_SCR(17); SHA256_SCR(18); SHA256_SCR(19); SHA256_SCR(20); SHA256_SCR(21); SHA256_SCR(22); SHA256_SCR(23); SHA256_SCR(24); SHA256_SCR(25); SHA256_SCR(26); SHA256_SCR(27); SHA256_SCR(28); SHA256_SCR(29); SHA256_SCR(30); SHA256_SCR(31); SHA256_SCR(32); SHA256_SCR(33); SHA256_SCR(34); SHA256_SCR(35); SHA256_SCR(36); SHA256_SCR(37); SHA256_SCR(38); SHA256_SCR(39); SHA256_SCR(40); SHA256_SCR(41); SHA256_SCR(42); SHA256_SCR(43); SHA256_SCR(44); SHA256_SCR(45); SHA256_SCR(46); SHA256_SCR(47); SHA256_SCR(48); SHA256_SCR(49); SHA256_SCR(50); SHA256_SCR(51); SHA256_SCR(52); SHA256_SCR(53); SHA256_SCR(54); SHA256_SCR(55); SHA256_SCR(56); SHA256_SCR(57); SHA256_SCR(58); SHA256_SCR(59); SHA256_SCR(60); SHA256_SCR(61); SHA256_SCR(62); SHA256_SCR(63); wv[0] = ctx->h[0]; wv[1] = ctx->h[1]; wv[2] = ctx->h[2]; wv[3] = ctx->h[3]; wv[4] = ctx->h[4]; wv[5] = ctx->h[5]; wv[6] = ctx->h[6]; wv[7] = ctx->h[7]; SHA256_EXP(0,1,2,3,4,5,6,7, 0); SHA256_EXP(7,0,1,2,3,4,5,6, 1); SHA256_EXP(6,7,0,1,2,3,4,5, 2); SHA256_EXP(5,6,7,0,1,2,3,4, 3); SHA256_EXP(4,5,6,7,0,1,2,3, 4); SHA256_EXP(3,4,5,6,7,0,1,2, 5); SHA256_EXP(2,3,4,5,6,7,0,1, 6); SHA256_EXP(1,2,3,4,5,6,7,0, 7); SHA256_EXP(0,1,2,3,4,5,6,7, 8); SHA256_EXP(7,0,1,2,3,4,5,6, 9); SHA256_EXP(6,7,0,1,2,3,4,5,10); SHA256_EXP(5,6,7,0,1,2,3,4,11); SHA256_EXP(4,5,6,7,0,1,2,3,12); SHA256_EXP(3,4,5,6,7,0,1,2,13); SHA256_EXP(2,3,4,5,6,7,0,1,14); SHA256_EXP(1,2,3,4,5,6,7,0,15); SHA256_EXP(0,1,2,3,4,5,6,7,16); SHA256_EXP(7,0,1,2,3,4,5,6,17); SHA256_EXP(6,7,0,1,2,3,4,5,18); SHA256_EXP(5,6,7,0,1,2,3,4,19); SHA256_EXP(4,5,6,7,0,1,2,3,20); SHA256_EXP(3,4,5,6,7,0,1,2,21); SHA256_EXP(2,3,4,5,6,7,0,1,22); SHA256_EXP(1,2,3,4,5,6,7,0,23); SHA256_EXP(0,1,2,3,4,5,6,7,24); SHA256_EXP(7,0,1,2,3,4,5,6,25); SHA256_EXP(6,7,0,1,2,3,4,5,26); SHA256_EXP(5,6,7,0,1,2,3,4,27); SHA256_EXP(4,5,6,7,0,1,2,3,28); SHA256_EXP(3,4,5,6,7,0,1,2,29); SHA256_EXP(2,3,4,5,6,7,0,1,30); SHA256_EXP(1,2,3,4,5,6,7,0,31); SHA256_EXP(0,1,2,3,4,5,6,7,32); SHA256_EXP(7,0,1,2,3,4,5,6,33); SHA256_EXP(6,7,0,1,2,3,4,5,34); SHA256_EXP(5,6,7,0,1,2,3,4,35); SHA256_EXP(4,5,6,7,0,1,2,3,36); SHA256_EXP(3,4,5,6,7,0,1,2,37); SHA256_EXP(2,3,4,5,6,7,0,1,38); SHA256_EXP(1,2,3,4,5,6,7,0,39); SHA256_EXP(0,1,2,3,4,5,6,7,40); SHA256_EXP(7,0,1,2,3,4,5,6,41); SHA256_EXP(6,7,0,1,2,3,4,5,42); SHA256_EXP(5,6,7,0,1,2,3,4,43); SHA256_EXP(4,5,6,7,0,1,2,3,44); SHA256_EXP(3,4,5,6,7,0,1,2,45); SHA256_EXP(2,3,4,5,6,7,0,1,46); SHA256_EXP(1,2,3,4,5,6,7,0,47); SHA256_EXP(0,1,2,3,4,5,6,7,48); SHA256_EXP(7,0,1,2,3,4,5,6,49); SHA256_EXP(6,7,0,1,2,3,4,5,50); SHA256_EXP(5,6,7,0,1,2,3,4,51); SHA256_EXP(4,5,6,7,0,1,2,3,52); SHA256_EXP(3,4,5,6,7,0,1,2,53); SHA256_EXP(2,3,4,5,6,7,0,1,54); SHA256_EXP(1,2,3,4,5,6,7,0,55); SHA256_EXP(0,1,2,3,4,5,6,7,56); SHA256_EXP(7,0,1,2,3,4,5,6,57); SHA256_EXP(6,7,0,1,2,3,4,5,58); SHA256_EXP(5,6,7,0,1,2,3,4,59); SHA256_EXP(4,5,6,7,0,1,2,3,60); SHA256_EXP(3,4,5,6,7,0,1,2,61); SHA256_EXP(2,3,4,5,6,7,0,1,62); SHA256_EXP(1,2,3,4,5,6,7,0,63); ctx->h[0] += wv[0]; ctx->h[1] += wv[1]; ctx->h[2] += wv[2]; ctx->h[3] += wv[3]; ctx->h[4] += wv[4]; ctx->h[5] += wv[5]; ctx->h[6] += wv[6]; ctx->h[7] += wv[7]; #endif /* !UNROLL_LOOPS */ } } void sha256(const unsigned char *message, unsigned int len, unsigned char *digest) { sha256_ctx ctx; sha256_init(&ctx); sha256_update(&ctx, message, len); sha256_final(&ctx, digest); } void sha256_init(sha256_ctx *ctx) { #ifndef UNROLL_LOOPS int i; for (i = 0; i < 8; i++) { ctx->h[i] = sha256_h0[i]; } #else ctx->h[0] = sha256_h0[0]; ctx->h[1] = sha256_h0[1]; ctx->h[2] = sha256_h0[2]; ctx->h[3] = sha256_h0[3]; ctx->h[4] = sha256_h0[4]; ctx->h[5] = sha256_h0[5]; ctx->h[6] = sha256_h0[6]; ctx->h[7] = sha256_h0[7]; #endif /* !UNROLL_LOOPS */ ctx->len = 0; ctx->tot_len = 0; } void sha256_update(sha256_ctx *ctx, const unsigned char *message, unsigned int len) { unsigned int block_nb; unsigned int new_len, rem_len, tmp_len; const unsigned char *shifted_message; tmp_len = SHA256_BLOCK_SIZE - ctx->len; rem_len = len < tmp_len ? len : tmp_len; memcpy(&ctx->block[ctx->len], message, rem_len); if (ctx->len + len < SHA256_BLOCK_SIZE) { ctx->len += len; return; } new_len = len - rem_len; block_nb = new_len / SHA256_BLOCK_SIZE; shifted_message = message + rem_len; sha256_transf(ctx, ctx->block, 1); sha256_transf(ctx, shifted_message, block_nb); rem_len = new_len % SHA256_BLOCK_SIZE; memcpy(ctx->block, &shifted_message[block_nb << 6], rem_len); ctx->len = rem_len; ctx->tot_len += (block_nb + 1) << 6; } void sha256_final(sha256_ctx *ctx, unsigned char *digest) { unsigned int block_nb; unsigned int pm_len; unsigned int len_b; #ifndef UNROLL_LOOPS int i; #endif block_nb = (1 + ((SHA256_BLOCK_SIZE - 9) < (ctx->len % SHA256_BLOCK_SIZE))); /*lint !e514 */ len_b = (ctx->tot_len + ctx->len) << 3; pm_len = block_nb << 6; memset(ctx->block + ctx->len, 0, pm_len - ctx->len); ctx->block[ctx->len] = 0x80; UNPACK32(len_b, ctx->block + pm_len - 4); sha256_transf(ctx, ctx->block, block_nb); #ifndef UNROLL_LOOPS for (i = 0 ; i < 8; i++) { UNPACK32(ctx->h[i], &digest[i << 2]); } #else UNPACK32(ctx->h[0], &digest[ 0]); UNPACK32(ctx->h[1], &digest[ 4]); UNPACK32(ctx->h[2], &digest[ 8]); UNPACK32(ctx->h[3], &digest[12]); UNPACK32(ctx->h[4], &digest[16]); UNPACK32(ctx->h[5], &digest[20]); UNPACK32(ctx->h[6], &digest[24]); UNPACK32(ctx->h[7], &digest[28]); #endif /* !UNROLL_LOOPS */ } #if 0 /* SHA-512 functions */ void sha512_transf(sha512_ctx *ctx, const unsigned char *message, unsigned int block_nb) { uint64 w[80]; uint64 wv[8]; uint64 t1, t2; const unsigned char *sub_block; int i, j; for (i = 0; i < (int) block_nb; i++) { sub_block = message + (i << 7); #ifndef UNROLL_LOOPS for (j = 0; j < 16; j++) { PACK64(&sub_block[j << 3], &w[j]); } for (j = 16; j < 80; j++) { SHA512_SCR(j); } for (j = 0; j < 8; j++) { wv[j] = ctx->h[j]; } for (j = 0; j < 80; j++) { t1 = wv[7] + SHA512_F2(wv[4]) + CH(wv[4], wv[5], wv[6]) + sha512_k[j] + w[j]; t2 = SHA512_F1(wv[0]) + MAJ(wv[0], wv[1], wv[2]); wv[7] = wv[6]; wv[6] = wv[5]; wv[5] = wv[4]; wv[4] = wv[3] + t1; wv[3] = wv[2]; wv[2] = wv[1]; wv[1] = wv[0]; wv[0] = t1 + t2; } for (j = 0; j < 8; j++) { ctx->h[j] += wv[j]; } #else PACK64(&sub_block[ 0], &w[ 0]); PACK64(&sub_block[ 8], &w[ 1]); PACK64(&sub_block[ 16], &w[ 2]); PACK64(&sub_block[ 24], &w[ 3]); PACK64(&sub_block[ 32], &w[ 4]); PACK64(&sub_block[ 40], &w[ 5]); PACK64(&sub_block[ 48], &w[ 6]); PACK64(&sub_block[ 56], &w[ 7]); PACK64(&sub_block[ 64], &w[ 8]); PACK64(&sub_block[ 72], &w[ 9]); PACK64(&sub_block[ 80], &w[10]); PACK64(&sub_block[ 88], &w[11]); PACK64(&sub_block[ 96], &w[12]); PACK64(&sub_block[104], &w[13]); PACK64(&sub_block[112], &w[14]); PACK64(&sub_block[120], &w[15]); SHA512_SCR(16); SHA512_SCR(17); SHA512_SCR(18); SHA512_SCR(19); SHA512_SCR(20); SHA512_SCR(21); SHA512_SCR(22); SHA512_SCR(23); SHA512_SCR(24); SHA512_SCR(25); SHA512_SCR(26); SHA512_SCR(27); SHA512_SCR(28); SHA512_SCR(29); SHA512_SCR(30); SHA512_SCR(31); SHA512_SCR(32); SHA512_SCR(33); SHA512_SCR(34); SHA512_SCR(35); SHA512_SCR(36); SHA512_SCR(37); SHA512_SCR(38); SHA512_SCR(39); SHA512_SCR(40); SHA512_SCR(41); SHA512_SCR(42); SHA512_SCR(43); SHA512_SCR(44); SHA512_SCR(45); SHA512_SCR(46); SHA512_SCR(47); SHA512_SCR(48); SHA512_SCR(49); SHA512_SCR(50); SHA512_SCR(51); SHA512_SCR(52); SHA512_SCR(53); SHA512_SCR(54); SHA512_SCR(55); SHA512_SCR(56); SHA512_SCR(57); SHA512_SCR(58); SHA512_SCR(59); SHA512_SCR(60); SHA512_SCR(61); SHA512_SCR(62); SHA512_SCR(63); SHA512_SCR(64); SHA512_SCR(65); SHA512_SCR(66); SHA512_SCR(67); SHA512_SCR(68); SHA512_SCR(69); SHA512_SCR(70); SHA512_SCR(71); SHA512_SCR(72); SHA512_SCR(73); SHA512_SCR(74); SHA512_SCR(75); SHA512_SCR(76); SHA512_SCR(77); SHA512_SCR(78); SHA512_SCR(79); wv[0] = ctx->h[0]; wv[1] = ctx->h[1]; wv[2] = ctx->h[2]; wv[3] = ctx->h[3]; wv[4] = ctx->h[4]; wv[5] = ctx->h[5]; wv[6] = ctx->h[6]; wv[7] = ctx->h[7]; j = 0; do { SHA512_EXP(0,1,2,3,4,5,6,7,j); j++; SHA512_EXP(7,0,1,2,3,4,5,6,j); j++; SHA512_EXP(6,7,0,1,2,3,4,5,j); j++; SHA512_EXP(5,6,7,0,1,2,3,4,j); j++; SHA512_EXP(4,5,6,7,0,1,2,3,j); j++; SHA512_EXP(3,4,5,6,7,0,1,2,j); j++; SHA512_EXP(2,3,4,5,6,7,0,1,j); j++; SHA512_EXP(1,2,3,4,5,6,7,0,j); j++; } while (j < 80); ctx->h[0] += wv[0]; ctx->h[1] += wv[1]; ctx->h[2] += wv[2]; ctx->h[3] += wv[3]; ctx->h[4] += wv[4]; ctx->h[5] += wv[5]; ctx->h[6] += wv[6]; ctx->h[7] += wv[7]; #endif /* !UNROLL_LOOPS */ } } void sha512(const unsigned char *message, unsigned int len, unsigned char *digest) { sha512_ctx ctx; sha512_init(&ctx); sha512_update(&ctx, message, len); sha512_final(&ctx, digest); } void sha512_init(sha512_ctx *ctx) { #ifndef UNROLL_LOOPS int i; for (i = 0; i < 8; i++) { ctx->h[i] = sha512_h0[i]; } #else ctx->h[0] = sha512_h0[0]; ctx->h[1] = sha512_h0[1]; ctx->h[2] = sha512_h0[2]; ctx->h[3] = sha512_h0[3]; ctx->h[4] = sha512_h0[4]; ctx->h[5] = sha512_h0[5]; ctx->h[6] = sha512_h0[6]; ctx->h[7] = sha512_h0[7]; #endif /* !UNROLL_LOOPS */ ctx->len = 0; ctx->tot_len = 0; } void sha512_update(sha512_ctx *ctx, const unsigned char *message, unsigned int len) { unsigned int block_nb; unsigned int new_len, rem_len, tmp_len; const unsigned char *shifted_message; tmp_len = SHA512_BLOCK_SIZE - ctx->len; rem_len = len < tmp_len ? len : tmp_len; memcpy(&ctx->block[ctx->len], message, rem_len); if (ctx->len + len < SHA512_BLOCK_SIZE) { ctx->len += len; return; } new_len = len - rem_len; block_nb = new_len / SHA512_BLOCK_SIZE; shifted_message = message + rem_len; sha512_transf(ctx, ctx->block, 1); sha512_transf(ctx, shifted_message, block_nb); rem_len = new_len % SHA512_BLOCK_SIZE; memcpy(ctx->block, &shifted_message[block_nb << 7], rem_len); ctx->len = rem_len; ctx->tot_len += (block_nb + 1) << 7; } void sha512_final(sha512_ctx *ctx, unsigned char *digest) { unsigned int block_nb; unsigned int pm_len; unsigned int len_b; #ifndef UNROLL_LOOPS int i; #endif block_nb = 1 + ((SHA512_BLOCK_SIZE - 17) < (ctx->len % SHA512_BLOCK_SIZE)); len_b = (ctx->tot_len + ctx->len) << 3; pm_len = block_nb << 7; memset(ctx->block + ctx->len, 0, pm_len - ctx->len); ctx->block[ctx->len] = 0x80; UNPACK32(len_b, ctx->block + pm_len - 4); sha512_transf(ctx, ctx->block, block_nb); #ifndef UNROLL_LOOPS for (i = 0 ; i < 8; i++) { UNPACK64(ctx->h[i], &digest[i << 3]); } #else UNPACK64(ctx->h[0], &digest[ 0]); UNPACK64(ctx->h[1], &digest[ 8]); UNPACK64(ctx->h[2], &digest[16]); UNPACK64(ctx->h[3], &digest[24]); UNPACK64(ctx->h[4], &digest[32]); UNPACK64(ctx->h[5], &digest[40]); UNPACK64(ctx->h[6], &digest[48]); UNPACK64(ctx->h[7], &digest[56]); #endif /* !UNROLL_LOOPS */ } /* SHA-384 functions */ void sha384(const unsigned char *message, unsigned int len, unsigned char *digest) { sha384_ctx ctx; sha384_init(&ctx); sha384_update(&ctx, message, len); sha384_final(&ctx, digest); } void sha384_init(sha384_ctx *ctx) { #ifndef UNROLL_LOOPS int i; for (i = 0; i < 8; i++) { ctx->h[i] = sha384_h0[i]; } #else ctx->h[0] = sha384_h0[0]; ctx->h[1] = sha384_h0[1]; ctx->h[2] = sha384_h0[2]; ctx->h[3] = sha384_h0[3]; ctx->h[4] = sha384_h0[4]; ctx->h[5] = sha384_h0[5]; ctx->h[6] = sha384_h0[6]; ctx->h[7] = sha384_h0[7]; #endif /* !UNROLL_LOOPS */ ctx->len = 0; ctx->tot_len = 0; } void sha384_update(sha384_ctx *ctx, const unsigned char *message, unsigned int len) { unsigned int block_nb; unsigned int new_len, rem_len, tmp_len; const unsigned char *shifted_message; tmp_len = SHA384_BLOCK_SIZE - ctx->len; rem_len = len < tmp_len ? len : tmp_len; memcpy(&ctx->block[ctx->len], message, rem_len); if (ctx->len + len < SHA384_BLOCK_SIZE) { ctx->len += len; return; } new_len = len - rem_len; block_nb = new_len / SHA384_BLOCK_SIZE; shifted_message = message + rem_len; sha512_transf(ctx, ctx->block, 1); sha512_transf(ctx, shifted_message, block_nb); rem_len = new_len % SHA384_BLOCK_SIZE; memcpy(ctx->block, &shifted_message[block_nb << 7], rem_len); ctx->len = rem_len; ctx->tot_len += (block_nb + 1) << 7; } void sha384_final(sha384_ctx *ctx, unsigned char *digest) { unsigned int block_nb; unsigned int pm_len; unsigned int len_b; #ifndef UNROLL_LOOPS int i; #endif block_nb = (1 + ((SHA384_BLOCK_SIZE - 17) < (ctx->len % SHA384_BLOCK_SIZE))); len_b = (ctx->tot_len + ctx->len) << 3; pm_len = block_nb << 7; memset(ctx->block + ctx->len, 0, pm_len - ctx->len); ctx->block[ctx->len] = 0x80; UNPACK32(len_b, ctx->block + pm_len - 4); sha512_transf(ctx, ctx->block, block_nb); #ifndef UNROLL_LOOPS for (i = 0 ; i < 6; i++) { UNPACK64(ctx->h[i], &digest[i << 3]); } #else UNPACK64(ctx->h[0], &digest[ 0]); UNPACK64(ctx->h[1], &digest[ 8]); UNPACK64(ctx->h[2], &digest[16]); UNPACK64(ctx->h[3], &digest[24]); UNPACK64(ctx->h[4], &digest[32]); UNPACK64(ctx->h[5], &digest[40]); #endif /* !UNROLL_LOOPS */ } /* SHA-224 functions */ void sha224(const unsigned char *message, unsigned int len, unsigned char *digest) { sha224_ctx ctx; sha224_init(&ctx); sha224_update(&ctx, message, len); sha224_final(&ctx, digest); } void sha224_init(sha224_ctx *ctx) { #ifndef UNROLL_LOOPS int i; for (i = 0; i < 8; i++) { ctx->h[i] = sha224_h0[i]; } #else ctx->h[0] = sha224_h0[0]; ctx->h[1] = sha224_h0[1]; ctx->h[2] = sha224_h0[2]; ctx->h[3] = sha224_h0[3]; ctx->h[4] = sha224_h0[4]; ctx->h[5] = sha224_h0[5]; ctx->h[6] = sha224_h0[6]; ctx->h[7] = sha224_h0[7]; #endif /* !UNROLL_LOOPS */ ctx->len = 0; ctx->tot_len = 0; } void sha224_update(sha224_ctx *ctx, const unsigned char *message, unsigned int len) { unsigned int block_nb; unsigned int new_len, rem_len, tmp_len; const unsigned char *shifted_message; tmp_len = SHA224_BLOCK_SIZE - ctx->len; rem_len = len < tmp_len ? len : tmp_len; memcpy(&ctx->block[ctx->len], message, rem_len); if (ctx->len + len < SHA224_BLOCK_SIZE) { ctx->len += len; return; } new_len = len - rem_len; block_nb = new_len / SHA224_BLOCK_SIZE; shifted_message = message + rem_len; sha256_transf(ctx, ctx->block, 1); sha256_transf(ctx, shifted_message, block_nb); rem_len = new_len % SHA224_BLOCK_SIZE; memcpy(ctx->block, &shifted_message[block_nb << 6], rem_len); ctx->len = rem_len; ctx->tot_len += (block_nb + 1) << 6; } void sha224_final(sha224_ctx *ctx, unsigned char *digest) { unsigned int block_nb; unsigned int pm_len; unsigned int len_b; #ifndef UNROLL_LOOPS int i; #endif block_nb = (1 + ((SHA224_BLOCK_SIZE - 9) < (ctx->len % SHA224_BLOCK_SIZE))); len_b = (ctx->tot_len + ctx->len) << 3; pm_len = block_nb << 6; memset(ctx->block + ctx->len, 0, pm_len - ctx->len); ctx->block[ctx->len] = 0x80; UNPACK32(len_b, ctx->block + pm_len - 4); sha256_transf(ctx, ctx->block, block_nb); #ifndef UNROLL_LOOPS for (i = 0 ; i < 7; i++) { UNPACK32(ctx->h[i], &digest[i << 2]); } #else UNPACK32(ctx->h[0], &digest[ 0]); UNPACK32(ctx->h[1], &digest[ 4]); UNPACK32(ctx->h[2], &digest[ 8]); UNPACK32(ctx->h[3], &digest[12]); UNPACK32(ctx->h[4], &digest[16]); UNPACK32(ctx->h[5], &digest[20]); UNPACK32(ctx->h[6], &digest[24]); #endif /* !UNROLL_LOOPS */ } #endif
2301_81045437/classic-platform
system/Cpl/crypto/sha2.c
C
unknown
29,414
/* * FIPS 180-2 SHA-224/256/384/512 implementation * Last update: 02/02/2007 * Issue date: 04/30/2005 * * Copyright (C) 2005, 2007 Olivier Gay <olivier.gay@a3.epfl.ch> * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. 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. * 3. Neither the name of the project 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 PROJECT 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 PROJECT OR 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. */ #ifndef SHA2_H #define SHA2_H #include "../../../include/Std_Types.h" #define SHA224_DIGEST_SIZE ( 224 / 8) #define SHA256_DIGEST_SIZE ( 256 / 8) #define SHA384_DIGEST_SIZE ( 384 / 8) #define SHA512_DIGEST_SIZE ( 512 / 8) #define SHA256_BLOCK_SIZE ( 512 / 8) #define SHA512_BLOCK_SIZE (1024 / 8) #define SHA384_BLOCK_SIZE SHA512_BLOCK_SIZE #define SHA224_BLOCK_SIZE SHA256_BLOCK_SIZE #ifdef __cplusplus extern "C" { #endif typedef struct { unsigned int tot_len; unsigned int len; unsigned char block[2 * SHA256_BLOCK_SIZE]; uint32 h[8]; } sha256_ctx; typedef struct { unsigned int tot_len; unsigned int len; unsigned char block[2 * SHA512_BLOCK_SIZE]; uint64 h[8]; } sha512_ctx; typedef sha512_ctx sha384_ctx; typedef sha256_ctx sha224_ctx; void sha224_init(sha224_ctx *ctx); void sha224_update(sha224_ctx *ctx, const unsigned char *message, unsigned int len); void sha224_final(sha224_ctx *ctx, unsigned char *digest); void sha224(const unsigned char *message, unsigned int len, unsigned char *digest); void sha256_init(sha256_ctx * ctx); void sha256_update(sha256_ctx *ctx, const unsigned char *message, unsigned int len); void sha256_final(sha256_ctx *ctx, unsigned char *digest); void sha256(const unsigned char *message, unsigned int len, unsigned char *digest); void sha384_init(sha384_ctx *ctx); void sha384_update(sha384_ctx *ctx, const unsigned char *message, unsigned int len); void sha384_final(sha384_ctx *ctx, unsigned char *digest); void sha384(const unsigned char *message, unsigned int len, unsigned char *digest); void sha512_init(sha512_ctx *ctx); void sha512_update(sha512_ctx *ctx, const unsigned char *message, unsigned int len); void sha512_final(sha512_ctx *ctx, unsigned char *digest); void sha512(const unsigned char *message, unsigned int len, unsigned char *digest); #ifdef __cplusplus } #endif #endif /* !SHA2_H */
2301_81045437/classic-platform
system/Cpl/crypto/sha2.h
C
unknown
3,809
/*-------------------------------- 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 */ /* @req SWS_Cal_00534 The code file structure shall contain one or more MISRA-C 2004 conform source files Cpl_<xxx>.c */ /* @req SWS_Cal_00505 The implementation shall be syncronous and reentrant */ #include "Cpl_Mac.h" #include <string.h> #include "crypto/hmac_sha2.h" /* * Private functions */ /* * Copy values from ctx values to MacGenerateCtxBuffer */ static void copyToGenerateBuffer(Cal_MacGenerateCtxBufType contextBuffer, hmac_sha256_ctx ctx) { #if CAL_MACGENERATE_CONTEXT_BUFFER_SIZE < 465 return; #else // ctx inside memcpy(&contextBuffer[1], &ctx.ctx_inside.len, sizeof(ctx.ctx_inside.len)); memcpy(&contextBuffer[5], &ctx.ctx_inside.tot_len, sizeof(ctx.ctx_inside.tot_len)); memcpy(&contextBuffer[9], ctx.ctx_inside.block, sizeof(ctx.ctx_inside.block)); memcpy(&contextBuffer[137], ctx.ctx_inside.h, sizeof(ctx.ctx_inside.h)); // ctx outside memcpy(&contextBuffer[169], &ctx.ctx_outside.len, sizeof(ctx.ctx_outside.len)); memcpy(&contextBuffer[173], &ctx.ctx_outside.tot_len, sizeof(ctx.ctx_outside.tot_len)); memcpy(&contextBuffer[177], ctx.ctx_outside.block, sizeof(ctx.ctx_outside.block)); memcpy(&contextBuffer[305], ctx.ctx_outside.h, sizeof(ctx.ctx_outside.h)); // block ipad memcpy(&contextBuffer[337], ctx.block_ipad, sizeof(ctx.block_ipad)); // block opad memcpy(&contextBuffer[401], ctx.block_opad, sizeof(ctx.block_opad)); #endif } /* * Copy values from MacGenerateCtxBuffer to ctx */ static void copyFromGenerateBuffer(Cal_MacGenerateCtxBufType contextBuffer, hmac_sha256_ctx* ctx) { #if CAL_MACGENERATE_CONTEXT_BUFFER_SIZE < 465 return; #else // ctx inside memcpy(&ctx->ctx_inside.len, &contextBuffer[1], sizeof(ctx->ctx_inside.len)); memcpy(&ctx->ctx_inside.tot_len, &contextBuffer[5], sizeof(ctx->ctx_inside.tot_len)); memcpy(ctx->ctx_inside.block, &contextBuffer[9], sizeof(ctx->ctx_inside.block)); memcpy(ctx->ctx_inside.h, &contextBuffer[137], sizeof(ctx->ctx_inside.h)); // ctx outside memcpy(&ctx->ctx_outside.len, &contextBuffer[169], sizeof(ctx->ctx_outside.len)); memcpy(&ctx->ctx_outside.tot_len, &contextBuffer[173], sizeof(ctx->ctx_outside.tot_len)); memcpy(ctx->ctx_outside.block, &contextBuffer[177], sizeof(ctx->ctx_outside.block)); memcpy(ctx->ctx_outside.h, &contextBuffer[305], sizeof(ctx->ctx_outside.h)); // block ipad memcpy(ctx->block_ipad, &contextBuffer[337], sizeof(ctx->block_ipad)); // block opad memcpy(ctx->block_opad, &contextBuffer[401], sizeof(ctx->block_opad)); #endif } /* * Copy values from ctx to MacVerifyCtxBuffer */ static void copyToVerifyBuffer(Cal_MacVerifyCtxBufType contextBuffer, hmac_sha256_ctx ctx) { #if CAL_MACVERIFY_CONTEXT_BUFFER_SIZE < 465 return; #else // ctx inside memcpy(&contextBuffer[1], &ctx.ctx_inside.len, sizeof(ctx.ctx_inside.len)); memcpy(&contextBuffer[5], &ctx.ctx_inside.tot_len, sizeof(ctx.ctx_inside.tot_len)); memcpy(&contextBuffer[9], ctx.ctx_inside.block, sizeof(ctx.ctx_inside.block)); memcpy(&contextBuffer[137], ctx.ctx_inside.h, sizeof(ctx.ctx_inside.h)); // ctx outside memcpy(&contextBuffer[169], &ctx.ctx_outside.len, sizeof(ctx.ctx_outside.len)); memcpy(&contextBuffer[173], &ctx.ctx_outside.tot_len, sizeof(ctx.ctx_outside.tot_len)); memcpy(&contextBuffer[177], ctx.ctx_outside.block, sizeof(ctx.ctx_outside.block)); memcpy(&contextBuffer[305], ctx.ctx_outside.h, sizeof(ctx.ctx_outside.h)); // block ipad memcpy(&contextBuffer[337], ctx.block_ipad, sizeof(ctx.block_ipad)); // block opad memcpy(&contextBuffer[401], ctx.block_opad, sizeof(ctx.block_opad)); #endif } /* * Copy values from MacVerifyCtxBuffer to ctx */ static void copyFromVerifyBuffer(Cal_MacVerifyCtxBufType contextBuffer, hmac_sha256_ctx* ctx) { #if CAL_MACVERIFY_CONTEXT_BUFFER_SIZE < 465 return; #else // ctx inside memcpy(&ctx->ctx_inside.len, &contextBuffer[1], sizeof(ctx->ctx_inside.len)); memcpy(&ctx->ctx_inside.tot_len, &contextBuffer[5], sizeof(ctx->ctx_inside.tot_len)); memcpy(ctx->ctx_inside.block, &contextBuffer[9], sizeof(ctx->ctx_inside.block)); memcpy(ctx->ctx_inside.h, &contextBuffer[137], sizeof(ctx->ctx_inside.h)); // ctx outside memcpy(&ctx->ctx_outside.len, &contextBuffer[169], sizeof(ctx->ctx_outside.len)); memcpy(&ctx->ctx_outside.tot_len, &contextBuffer[173], sizeof(ctx->ctx_outside.tot_len)); memcpy(ctx->ctx_outside.block, &contextBuffer[177], sizeof(ctx->ctx_outside.block)); memcpy(ctx->ctx_outside.h, &contextBuffer[305], sizeof(ctx->ctx_outside.h)); // block ipad memcpy(ctx->block_ipad, &contextBuffer[337], sizeof(ctx->block_ipad)); // block opad memcpy(ctx->block_opad, &contextBuffer[401], sizeof(ctx->block_opad)); #endif } /* * Public functions */ /* @req SWS_Cal_00701 Implementation of Cpl<MAC>Start */ Cal_ReturnType Cpl_MacGenerateStart(const void* cfgPtr, Cal_MacGenerateCtxBufType contextBuffer, const Cal_SymKeyType* keyPtr) { Cal_ReturnType status; status = CAL_E_OK; if ((cfgPtr == NULL) || (keyPtr == NULL)) { status = CAL_E_NOT_OK; } else { //Activate the service state contextBuffer[0] = 1; // Copy key to the buffer hmac_sha256_ctx ctx; hmac_sha256_init(&ctx, keyPtr->data, keyPtr->length); //copy hmac ctx to context buffer copyToGenerateBuffer(contextBuffer,ctx); status = CAL_E_OK; } return status; } /* @req SWS_Cal_00702 Implementation of Cpl<MAC>Update */ Cal_ReturnType Cpl_MacGenerateUpdate(const void* cfgPtr, Cal_MacGenerateCtxBufType contextBuffer, const uint8* dataPtr, uint32 dataLength) { Cal_ReturnType status; status = CAL_E_OK; if ((cfgPtr == NULL) || (dataPtr == NULL)) { status = CAL_E_NOT_OK; } else { // Handle cfg // Read contextBuffer hmac_sha256_ctx ctx; //copy from contextBuffer to ctxBuffer copyFromGenerateBuffer(contextBuffer,&ctx); // Calculate MAC hmac_sha256_update(&ctx, dataPtr, dataLength); //copy hmac ctx to context buffer copyToGenerateBuffer(contextBuffer,ctx); status = CAL_E_OK; } return status; } /* @req SWS_Cal_00703 Implementation of Cpl<MAC>Finish */ Cal_ReturnType Cpl_MacGenerateFinish(const void* cfgPtr, Cal_MacGenerateCtxBufType contextBuffer, uint8* resultPtr, uint32* resultLengthPtr, boolean TruncationIsAllowed) { Cal_ReturnType status; status = CAL_E_OK; if ((cfgPtr == NULL) || (resultPtr == NULL) || (resultLengthPtr == NULL)) { status = CAL_E_NOT_OK; } else { // Handle cfg // Read contextBuffer hmac_sha256_ctx ctx; //copy from buffer to ctx copyFromGenerateBuffer(contextBuffer,&ctx); // Calculate MAC if ((*resultLengthPtr < SHA256_DIGEST_SIZE) && (FALSE == TruncationIsAllowed)) { *resultLengthPtr = SHA256_DIGEST_SIZE; status = CAL_E_NOT_OK; } else { hmac_sha256_final(&ctx, resultPtr, *resultLengthPtr); *resultLengthPtr = SHA256_DIGEST_SIZE; status = CAL_E_OK; } } return status; } /* @req SWS_Cal_00701 Implementation of Cpl_MacVerifyStart */ Cal_ReturnType Cpl_MacVerifyStart(const void* cfgPtr, Cal_MacVerifyCtxBufType contextBuffer, const Cal_SymKeyType* keyPtr) { Cal_ReturnType status; status = CAL_E_OK; if((keyPtr == NULL) || (cfgPtr == NULL)) { status = CAL_E_NOT_OK; } else { hmac_sha256_ctx ctx; // Copy key to the buffer hmac_sha256_init(&ctx, keyPtr->data, keyPtr->length); //copy hmac ctx to context buffer copyToVerifyBuffer(contextBuffer,ctx); } return status; } /* @req SWS_Cal_00702 Implementation of Cpl_MacVerifyStart */ Cal_ReturnType Cpl_MacVerifyUpdate(const void* cfgPtr, Cal_MacVerifyCtxBufType contextBuffer, const uint8* dataPtr, uint32 dataLength) { Cal_ReturnType status; status = CAL_E_OK; if(cfgPtr == NULL) { status = CAL_E_NOT_OK; } else { hmac_sha256_ctx ctx; //copy from contextBuffer to ctxBuffer copyFromVerifyBuffer(contextBuffer,&ctx); // Calculate MAC hmac_sha256_update(&ctx, dataPtr, dataLength); //copy hmac ctx to context buffer copyToVerifyBuffer(contextBuffer,ctx); } return status; } /* @req SWS_Cal_00703 Implementation of Cpl_MacVerifyFinish */ Cal_ReturnType Cpl_MacVerifyFinish(const void* cfgPtr, Cal_MacVerifyCtxBufType contextBuffer, const uint8* MacPtr, uint32 MacLength, Cal_VerifyResultType* resultPtr) { Cal_ReturnType status = CAL_E_OK; if((MacPtr == NULL) || (cfgPtr == NULL)) { *resultPtr = CAL_E_VER_NOT_OK; status = CAL_E_NOT_OK; } else { hmac_sha256_ctx ctx; //result array uint8 result[32]; uint32 resultLength=32; //copy from ctx buffer copyFromVerifyBuffer(contextBuffer,&ctx); hmac_sha256_final(&ctx, result, resultLength); //verify the MAC if(memcmp(result, MacPtr, MacLength) == 0){ *resultPtr = CAL_E_VER_OK; } else { *resultPtr = CAL_E_VER_NOT_OK; } } return status; }
2301_81045437/classic-platform
system/Cpl/src/Cpl_Mac.c
C
unknown
10,470
/*-------------------------------- 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 */ /* @req SWS_Cal_00536 Each CPL library shall provide a header file */ /* @req SWS_Cal_00461 For every API function there should be a coresponding Cpl function */ #ifndef CPL_MAC_H_ #define CPL_MAC_H_ #include "Cal_Types.h" /** * Function to initialize the Mac generate service * @param cfgPtr Identifier of the CAL module configuration to be used for the MAC computation * @param contextBuffer Pointer to the buffer in which the contect of the service is stored * @param keyPtr Pointer to the key to be used for the MAC generation * @return CAL_E_OK if request successful, CAL_E_NOT_OK of request failed */ Cal_ReturnType Cpl_MacGenerateStart(const void* cfgPtr, Cal_MacGenerateCtxBufType contextBuffer, const Cal_SymKeyType* keyPtr); /** * Function to feed input data to the MAC generate service * @param cfgPtr Identifier of the CAL module configuration to be used for the MAC computation * @param contextBuffer Pointer to the buffer in which the contect of the service is stored * @param dataPtr Pointer to the data for which the MAC shall be computed * @param dataLength Number of bytes for which the MAC shall be computed * @return CAL_E_OK if request successful, CAL_E_NOT_OK of request failed */ Cal_ReturnType Cpl_MacGenerateUpdate(const void* cfgPtr, Cal_MacGenerateCtxBufType contextBuffer, const uint8* dataPtr, uint32 dataLength); /** * Function to finish the MAC generate service * @param cfgPtr Identifier of the CAL module configuration to be used for the MAC computation * @param contextBuffer Pointer to the buffer in which the contect of the service is stored * @param resultPtr Pointer to the memory location to store the generated MAC in. * @param resultLengthPtr On calling this variable contain the size of the resultbuffer, on returning it contains the length of the computed MAC * @param TruncationIsAllowed * @return CAL_E_OK if request successful, CAL_E_NOT_OK of request failed */ Cal_ReturnType Cpl_MacGenerateFinish(const void* cfgPtr, Cal_MacGenerateCtxBufType contextBuffer, uint8* resultPtr, uint32* resultLengthPtr, boolean TruncationIsAllowed); /** * Function to initialize the Mac verify service * @param cfgPtr Identifier of the CAL module configuration to be used for the MAC computation * @param contextBuffer Pointer to the buffer in which the contect of the service is stored * @param keyPtr Pointer to the key to be used for the MAC generation * @return CAL_E_OK if request successful, CAL_E_NOT_OK of request failed */ Cal_ReturnType Cpl_MacVerifyStart(const void* cfgPtr, Cal_MacVerifyCtxBufType contextBuffer, const Cal_SymKeyType* keyPtr); /** * Function to feed input data to the MAC verify service * @param cfgPtr Identifier of the CAL module configuration to be used for the MAC computation * @param contextBuffer Pointer to the buffer in which the contect of the service is stored * @param dataPtr Pointer to the data for which the MAC shall be computed * @param datalength Number of bytes for which the MAC shall be computed * @return CAL_E_OK if request successful, CAL_E_NOT_OK of request failed */ Cal_ReturnType Cpl_MacVerifyUpdate(const void* cfgPtr, Cal_MacVerifyCtxBufType contextBuffer, const uint8* dataPtr, uint32 datalength); /** * Function to finish the MAC verify service * @param cfgPtr Identifier of the CAL module configuration to be used for the MAC computation * @param contextBuffer Pointer to the buffer in which the contect of the service is stored * @param MacPtr Pointer to the MAC to be verified * @param MacLength Length of the MAC to be verified * @param resultPtr Pointer to the result of the MAC verification * @return CAL_E_OK if request successful, CAL_E_NOT_OK of request failed */ Cal_ReturnType Cpl_MacVerifyFinish(const void* cfgPtr, Cal_MacVerifyCtxBufType contextBuffer, const uint8* MacPtr, uint32 MacLength, Cal_VerifyResultType* resultPtr); #endif /* CPL_MAC_H_ */
2301_81045437/classic-platform
system/Cpl/src/Cpl_Mac.h
C
unknown
4,838
#EcuMFixed obj-$(USE_ECUM_FIXED) += EcuM.o obj-$(USE_ECUM_FIXED) += EcuM_Fixed.o obj-$(USE_ECUM_FIXED) += EcuM_Main.o obj-$(USE_ECUM_FIXED) += EcuM_PBcfg.o obj-$(USE_ECUM_FIXED) += EcuM_PBHeader.o obj-$(USE_ECUM_FIXED)-$(CFG_SAFETY_PLATFORM) += EcuM_A0.o obj-$(USE_ECUM_FIXED)-$(CFG_SAFETY_PLATFORM) += EcuM_QM.o obj-$(USE_ECUM_FIXED) += EcuM_GeneratedCallouts.o ifeq ($(filter EcuM_Callout_Stubs.o,$(obj-y)),) obj-$(USE_ECUM_FIXED) += EcuM_Callout_Stubs.o endif ifeq ($(filter EcuM_SP_Callout_Stubs.o,$(obj-y)),) obj-$(USE_ECUM_FIXED)-$(CFG_SAFETY_PLATFORM) += EcuM_SP_Callout_Stubs.o endif inc-$(USE_ECUM_FIXED) += $(ROOTDIR)/system/EcuM/inc inc-$(USE_ECUM_FIXED) += $(ROOTDIR)/system/EcuM/src vpath-$(USE_ECUM_FIXED) += $(ROOTDIR)/system/EcuM/src #EcuMFlexible obj-$(USE_ECUM_FLEXIBLE) += EcuM.o obj-$(USE_ECUM_FLEXIBLE) += EcuM_Flexible.o obj-$(USE_ECUM_FLEXIBLE) += EcuM_PBcfg.o obj-$(USE_ECUM_FLEXIBLE) += EcuM_PBHeader.o obj-$(USE_ECUM_FLEXIBLE) += EcuM_GeneratedCallouts.o ifeq ($(filter EcuM_Callout_Stubs.o,$(obj-y)),) obj-$(USE_ECUM_FLEXIBLE) += EcuM_Callout_Stubs.o endif ifeq ($(filter EcuM_SP_Callout_Stubs.o,$(obj-y)),) obj-$(USE_ECUM_FLEXIBLE)-$(CFG_SAFETY_PLATFORM) += EcuM_SP_Callout_Stubs.o endif inc-$(USE_ECUM_FLEXIBLE) += $(ROOTDIR)/system/EcuM/inc inc-$(USE_ECUM_FLEXIBLE) += $(ROOTDIR)/system/EcuM/src vpath-$(USE_ECUM_FLEXIBLE) += $(ROOTDIR)/system/EcuM/src
2301_81045437/classic-platform
system/EcuM/EcuM.mod.mk
Makefile
unknown
1,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 */ /** @fileSafetyClassification ASIL **/ /* Same EcuM.h always used */ /** @addtogroup EcuM ECU State Manager * @{ */ /** @file EcuM.h * API and type definitions for ECU State Manager. */ /* * Include structure: * * * * Rte_Type.h --> Std_Types.h * ^ ^ * | | * Rte_EcuM.h <-- EcuM_Types.h * ^ ^ * | | /-----> EcuM_Cfg.h * | | /------> EcuM_Generated_Types.h * | | / (Holds EcuM_ConfigType and includes all BSW modules ) * | | /-------> EcuM_Cbk.h * | | / (want types EcuM_WakeupSourceType, EcuM_ConfigType *, EcuM_WakeupSourceType , EcuM_WakeupReactionType ) * | |/ * | EcuM.h <----- EcuM_Callout_Stubs.c * | ^ \--- EcuM_PBCfg.c * | | * | | * `---------- EcuM_xxx.c ---> Memmap.h * \-> Det.h, Dem.h * * * * Problems: * - Can_Cfg.h can include just "EcuM_Cbk.h"... * .. it will need at EcuM.h.. problem is that EcuM.h includes EcuM_Cbk.h * - Most BSW modules uses DEM that in Dem_Types.h will include "Rte_Type.h" * (if enabled by CFG_DEM_USE_RTE) * * - EcuM_Generated_Types.h is quite crappy since it includes the * * Changes: * - EcuM_Cfg.h , must not include ANY include files. * - EcuM_Pbcfg.c must include "EcuM_Generated_Types.h" * - EcuM.c, etc must include "EcuM_Generated_Types.h" * --> The GOOD, we keep circular include from EcuM_Generated_Types.h * * * */ /* @req SWS_EcuM_00991 */ /*The implementation of the ECU State Manager Fixed module shall provide one file EcuM.h containing fix type declarations, forward declaration to generated types, and function prototypes.*/ /* @req SWS_EcuM_00676 */ /*It shall only be necessary to include EcuM.h to use all services of the ECU State Manager.*/ /* @req SWS_EcuM_04036 */ /* @req ARC_SWS_ECUM_00011 The ECUM module shall be implemented as a compiler and hardware independent module */ #ifndef ECUM_H_ #define ECUM_H_ /* @req SWS_BSW_00201 */ /*Development errors should be of type uint8 */ #define ECUM_MODULE_ID 10u #define ECUM_VENDOR_ID 60u /* @req SWS_BSW_00059 Published information */ #define ECUM_SW_MAJOR_VERSION 3u #define ECUM_SW_MINOR_VERSION 1u #define ECUM_SW_PATCH_VERSION 0u #define ECUM_AR_MAJOR_VERSION 4u #define ECUM_AR_MINOR_VERSION 3u #define ECUM_AR_PATCH_VERSION 0u #define ECUM_CALLOUT_SW_MAJOR_VERSION 3u #define ECUM_CALLOUT_SW_MINOR_VERSION 0u #define ECUM_CALLOUT_SW_PATCH_VERSION 0u #include "Os.h" // ECUM_ARC_SAFETY_PLATFORM is based on the configuration enabled in makefile #if defined(CFG_SAFETY_PLATFORM) #define ECUM_ARC_SAFETY_PLATFORM STD_ON #else #define ECUM_ARC_SAFETY_PLATFORM STD_OFF #endif /* @req SWS_BSW_00020 */ /* @req SWS_EcuM_02993 *//* @req SWS_EcuM_02993 */ #include "EcuM_Cfg.h" #include "EcuM_Types.h" #include "EcuM_Cbk.h" #if defined(USE_COM) #include "ComStack_Types.h" #endif #if defined(USE_COMM) #include "ComM.h" #endif #if defined(USE_NVM) #include "NvM.h" #endif /** @name Error Codes */ /* @req SWS_BSW_00073 */ /* @req SWS_EcuM_02982 */ /* @req SWS_EcuM_02984 */ /* @req SWS_EcuM_04032 */ #define ECUM_E_UNINIT (0x10u) #define ECUM_E_SERVICE_DISABLED (0x11u) #define ECUM_E_NULL_POINTER (0x12u) #define ECUM_E_INVALID_PAR (0x13u) #define ECUM_E_MULTIPLE_RUN_REQUESTS (0x14u) #define ECUM_E_MISMATCHED_RUN_RELEASE (0x15u) #define ECUM_E_STATE_PAR_OUT_OF_RANGE (0x16u) #define ECUM_E_UNKNOWN_WAKEUP_SOURCE (0x17u) #define ECUM_E_ARC_TIMERERROR (0x18u) #define ECUM_E_ARC_FAULTY_SHUTDOWN_TARGET (0x19u) #define ECUM_E_ARC_FAULTY_CURRENT_STATE (0x1au) #define ECUM_E_ARC_PARTITION_SYNC_TIMEOUT (0x1bu) //@} /** @name Service id's */ //@{ #define ECUM_REQUESTRUN_ID (0x03u) #define ECUM_RELEASERUN_ID (0x04u) #define ECUM_SELECTSHUTDOWNTARGET_ID (0x06u) #define ECUM_GETSTATE_ID (0x07u) #define ECUM_GETSHUTDOWNTARGET_ID (0x09u) #define ECUM_REQUESTPOSTRUN_ID (0x0au) #define ECUM_RELEASEPOSTRUN_ID (0x0bu) #define ECUM_SETWAKEUPEVENT_ID (0x0cu) #define ECUM_SELECTAPPMODE_ID (0x0fu) #define ECUM_COMM_RELEASERUN_ID (0x10u) #define ECUM_GETAPPMODE_ID (0x11u) #define ECUM_SELECT_BOOTARGET_ID (0x12u) #define ECUM_GET_BOOTARGET_ID (0x13u) #define ECUM_VALIDATE_WAKEUP_EVENT_ID (0x14u) #define ECUM_GETSTATUSOFWAKEUPSOURCE_ID (0x17u) #define ECUM_MAINFUNCTION_ID (0x18u) #define ECUM_STARTUPTWO_ID (0x1au) #define ECUM_SELECTSHUTDOWNCAUSE_ID (0x1bu) #define ECUM_COMM_HASREQUESTEDRUN_ID (0x1bu) #define ECUM_GETSHUTDOWNCAUSE_ID (0x1cu) #define ECUM_GODOWN_ID (0x1fu) #define ECUM_GOHALT_ID (0x20u) #define ECUM_GOPOLL_ID (0x21) #define ECUM_ARC_STARTUPTWO_ID (0x22u) #define ECUM_ARC_MAINFUNCTION_A0_ID (0x23u) #define ECUM_ARC_MAINFUNCTION_QM_ID (0x24u) #define ECUM_GETVERSIONINFO_ID (0x00u) #define ECUM_AR_VERSION ((ECUM_AR_MAJOR_VERSION*10000)+(ECUM_AR_MINOR_VERSION*100)+ECUM_AR_PATCH_VERSION) /* @req SWS_EcuM_02813 */ /* @req SWS_EcuM_02935 */ /* @req SWS_EcuM_04034 */ #if ( ECUM_VERSION_INFO_API == STD_ON) void EcuM_GetVersionInfo( Std_VersionInfoType* VersionInfo ); #endif /* @req SWS_EcuM_02811 */ void EcuM_Init( void ); /* @req SWS_EcuM_02838 */ void EcuM_StartupTwo(void); /* @req SWS_EcuM_02812 */ void EcuM_Shutdown(void); #if defined(USE_ECUM_FIXED) /* @req SWS_EcuM_00823 */ Std_ReturnType EcuM_GetState(EcuM_StateType* state); /* @req SWS_EcuM_04124 */ Std_ReturnType EcuM_RequestRUN(EcuM_UserType user); /* @req SWS_EcuM_00815 */ Std_ReturnType EcuM_ReleaseRUN(EcuM_UserType user); /* @req SWS_EcuM_00819 */ Std_ReturnType EcuM_RequestPOST_RUN(EcuM_UserType user); /* @req SWS_EcuM_04129 */ Std_ReturnType EcuM_ReleasePOST_RUN(EcuM_UserType user); /* @req SWS_EcuM_00821 */ void EcuM_KillAllRUNRequests(void); /* @req SWS_EcuMf_00101 */ void EcuM_KillAllPostRUNRequests(void); #endif /*USE_ECUM_FIXED*/ #if defined(USE_COMM) && (ECUM_AR_VERSION < 40300) Std_ReturnType EcuM_ComM_RequestRUN(NetworkHandleType channel); Std_ReturnType EcuM_ComM_ReleaseRUN(NetworkHandleType channel); boolean EcuM_ComM_HasRequestedRUN(NetworkHandleType channel); #endif /* @req SWS_EcuM_02822 */ Std_ReturnType EcuM_SelectShutdownTarget(EcuM_StateType shutdownTarget, uint8 sleepMode); /* @req SWS_EcuM_02824 */ Std_ReturnType EcuM_GetShutdownTarget(EcuM_StateType* shutdownTarget, uint8* sleepMode); Std_ReturnType EcuM_GetLastShutdownTarget(EcuM_StateType* shutdownTarget, uint8* sleepMode); Std_ReturnType EcuM_SelectBootTarget(EcuM_BootTargetType target); Std_ReturnType EcuM_GetBootTarget(EcuM_BootTargetType* target); /* @req SWS_EcuM_02827 */ /* @req SWS_EcuM_02827 */ EcuM_WakeupSourceType EcuM_GetPendingWakeupEvents(void); /* @req SWS_EcuM_02828 */ void EcuM_ClearWakeupEvent(EcuM_WakeupSourceType source ); /* @req SWS_EcuM_02830 */ /* @req SWS_EcuM_02830 */ EcuM_WakeupSourceType EcuM_GetValidatedWakeupEvents(void); /* @req SWS_EcuM_02831 */ EcuM_WakeupSourceType EcuM_GetExpiredWakeupEvents(void); #if defined(USE_ECUM_FIXED) /* @req SWS_EcuM_02832 */ EcuM_WakeupStatusType EcuM_GetStatusOfWakeupSource(EcuM_WakeupSourceType sources); #endif /* @req SWS_EcuM_02826*/ /* @req SWS_EcuM_02826*/ void EcuM_SetWakeupEvent(EcuM_WakeupSourceType sources); /* @req SWS_EcuM_02829 */ /* @req SWS_EcuM_02829 */ void EcuM_ValidateWakeupEvent(EcuM_WakeupSourceType sources); /* @req SWS_EcuM_02837 */ void EcuM_MainFunction(void); #if defined(USE_ECUM_FLEXIBLE) /* @req SWS_EcuM_04046 */ Std_ReturnType EcuM_GoDown(uint16 caller); /* @req SWS_EcuM_04048 */ Std_ReturnType EcuM_GoHalt(void); /* @req SWS_EcuM_04050 */ Std_ReturnType EcuM_SelectShutdownCause(EcuM_ShutdownCauseType target); /* @req SWS_EcuM_04051 */ Std_ReturnType EcuM_GetShutdownCause(EcuM_ShutdownCauseType *shutdownCause); #endif #if (ECUM_ARC_SAFETY_PLATFORM == STD_ON) EcuM_SP_RetStatus EcuM_MainFunction_Partition_A0(EcuM_StateType current_state); EcuM_SP_RetStatus EcuM_MainFunction_Partition_QM(EcuM_StateType current_state); void EcuM_SP_Sync_UpdateStatus(EcuM_SP_PartitionFunCompletion syncSubState); #endif #endif /*ECUM_H_*/ /** @} */
2301_81045437/classic-platform
system/EcuM/inc/EcuM.h
C
unknown
9,245
/*-------------------------------- 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 */ /** @fileSafetyClassification ASIL **/ /* Common for all EcuM variants */ /* * @req SWS_EcuM_02994 @req SWS_EcuMf_02994 Callback/callouts should be in EcuM_Cbk.h * @req SWS_EcuM_02677 @req SWS_EcuMf_02677 Include only this file if you want to use the callbacks/callouts * * - EcuM_WakeupSourceType holds generated types (non-RTE) * - EcuM_WakeupReactionType (non-RTE) */ /* @req SWS_BSW_00172 Callback functions should have void as return type. */ /* @req SWS_BSW_00026 */ /* @req SWS_EcuM_02994 */ /* @req SWS_EcuM_02994 */ #ifndef ECUM_CBK_H_ #define ECUM_CBK_H_ /* @req SWS_EcuM_02677 */ /*It shall only be necessary to include EcuM_Cbk.h to interact with the callbacks and callouts of the ECU State Manager*/ #include "EcuM.h" #if defined(CFG_ARC_ECUM_NVM_READ_INIT) #include "Os.h" #endif struct EcuM_ConfigS; typedef enum { ECUM_WKACT_RUN = 0, /**< Initialization into RUN state */ ECUM_WKACT_TTII = 2, /**< Execute time triggered increased inoperation protocol and shutdown */ ECUM_WKACT_SHUTDOWN = 3 /**< Immediate shutdown */ } EcuM_WakeupReactionType; /* @req SWS_EcuM_02904*/ void EcuM_ErrorHook(uint16 reason); /* @req SWS_EcuM_02905*/ void EcuM_AL_DriverInitZero(void); /* @req SWS_EcuM_02906*/ struct EcuM_ConfigS* EcuM_DeterminePbConfiguration(void); /* @req SWS_EcuM_02907*/ void EcuM_AL_DriverInitOne(const struct EcuM_ConfigS* ConfigPtr); #if defined(USE_ECUM_FIXED) #if (ECUM_ARC_SAFETY_PLATFORM == STD_ON) /* @req SWS_EcuM_00908*/ void EcuM_AL_DriverInitTwo_Partition_A0(const struct EcuM_ConfigS* ConfigPtr); void EcuM_AL_DriverInitTwo_Partition_QM(const struct EcuM_ConfigS* ConfigPtr); /* @req SWS_EcuM_00909*/ void EcuM_AL_DriverInitThree_Partition_A0(const struct EcuM_ConfigS* ConfigPtr); void EcuM_AL_DriverInitThree_Partition_QM(const struct EcuM_ConfigS* ConfigPtr); /* @req SWS_EcuM_00910 */ void EcuM_OnRTEStartup(void); /* @req SWS_EcuM_00911 */ void EcuM_OnEnterRun_Partition_A0(void); void EcuM_OnEnterRun_Partition_QM(void); /* @req SWS_EcuM_00912 */ void EcuM_OnExitRun_Partition_A0(void); void EcuM_OnExitRun_Partition_QM(void); /* @req SWS_EcuM_00913 */ void EcuM_OnExitPostRun_Partition_A0(void); void EcuM_OnExitPostRun_Partition_QM(void); /* @req SWS_EcuM_00914 */ void EcuM_OnPrepShutdown_Partition_A0(void); void EcuM_OnPrepShutdown_Partition_QM(void); #else // ECUM_ARC_SAFETY_PLATFORM /* @req SWS_EcuM_00908*/ void EcuM_AL_DriverInitTwo(const struct EcuM_ConfigS* ConfigPtr); /* @req SWS_EcuM_00909*/ void EcuM_AL_DriverInitThree(const struct EcuM_ConfigS* ConfigPtr); /* @req SWS_EcuM_00910 */ void EcuM_OnRTEStartup(void); /* @req SWS_EcuM_00911 */ void EcuM_OnEnterRun(void); /* @req SWS_EcuM_00912 */ void EcuM_OnExitRun(void); /* @req SWS_EcuM_00913 */ void EcuM_OnExitPostRun(void); /* @req SWS_EcuM_00914 */ void EcuM_OnPrepShutdown(void); #endif // ECUM_ARC_SAFETY_PLATFORM /* @req SWS_EcuM_00915 */ void EcuM_OnGoSleep(void); #endif // USE_ECUM_FIXED #if (ECUM_ARC_SAFETY_PLATFORM == STD_ON) /* @req SWS_EcuM_02916 */ void EcuM_OnGoOffOne_Partition_A0(void); void EcuM_OnGoOffOne_Partition_QM(void); /* @req SWS_EcuM_02917 */ void EcuM_OnGoOffTwo_Partition_A0(void); void EcuM_OnGoOffTwo_Partition_QM(void); #else // ECUM_ARC_SAFETY_PLATFORM /* @req SWS_EcuM_02916 */ void EcuM_OnGoOffOne(void); /* @req SWS_EcuM_02917 */ void EcuM_OnGoOffTwo(void); #endif // ECUM_ARC_SAFETY_PLATFORM /* @req SWS_EcuM_02918 */ void EcuM_EnableWakeupSources(EcuM_WakeupSourceType wakeupSource); /* @req SWS_EcuM_02922 */ void EcuM_DisableWakeupSources(EcuM_WakeupSourceType wakeupSource); /* @req SWS_EcuM_02919 */ void EcuM_GenerateRamHash(void); /* @req SWS_EcuM_02921 */ uint8 EcuM_CheckRamHash(void); /* @req SWS_EcuM_02920 */ void EcuM_AL_SwitchOff(void); /* @req SWS_EcuM_02923 */ void EcuM_AL_DriverRestart(const struct EcuM_ConfigS* ConfigPtr); void EcuM_LoopDetection(void); /* @req SWS_EcuM_02924 */ void EcuM_StartWakeupSources(EcuM_WakeupSourceType wakeupSource); /* @req SWS_EcuM_02925 */ void EcuM_CheckValidation(EcuM_WakeupSourceType wakeupSource); /* @req SWS_EcuM_02926 */ void EcuM_StopWakeupSources(EcuM_WakeupSourceType wakeupSource); #if defined(USE_ECUM_FIXED) /* @req SWS_EcuM_02927 */ EcuM_WakeupReactionType EcuM_OnWakeupReaction(EcuM_WakeupReactionType wact); #endif /* @req SWS_EcuM_02929 */ void EcuM_CheckWakeup(EcuM_WakeupSourceType wakeupSource); /* @req SWS_EcuM_02928 */ void EcuM_SleepActivity(void); /* @req SWS_EcuM_04065 */ void EcuM_AL_Reset(EcuM_ResetType reset); void EcuM_Arc_RememberWakeupEvent(uint32 resetReason); #if defined(CFG_ARC_ECUM_NVM_READ_INIT) void EcuM_Arc_InitFeeReadAdminBlock(TickType tickTimerStart, uint32 EcuMNvramReadAllTimeout); void EcuM_Arc_InitMemReadAllMains(void); #endif #endif /*ECUM_CBK_H_*/
2301_81045437/classic-platform
system/EcuM/inc/EcuM_Cbk.h
C
unknown
5,750
/*-------------------------------- 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 POSTBUILD_TYPES_H_ #define POSTBUILD_TYPES_H_ #include "Std_Types.h" #if defined(USE_BSWM) #include "BswM.h" #endif #if defined(USE_CAN) #include "Can.h" #endif #if defined(USE_CANIF) #include "CanIf.h" #endif #if defined(USE_CANNM) #include "CanNm.h" #endif #if defined(USE_CANTP) #include "CanTp.h" #endif #if defined (USE_CANTRCV) #include "CanTrcv.h" #endif #if defined(USE_COM) #include "Com.h" #endif #if defined(USE_COMM) #include "ComM.h" #endif #if defined(USE_PDUR) #include "PduR.h" #endif #ifdef CFG_POSTBUILD_PARTNUMBER #include "partno.h" #endif #if defined(USE_FIM) #include "FiM.h" #endif typedef struct { const uint32 startPattern; const uint32 postBuildVariant; #ifdef CFG_POSTBUILD_PARTNUMBER const PostBuildPartNoType partNumber; #endif const uint64 preCompileHashLow; /* Lower 8 bytes of the MD5 */ const uint64 preCompileHashHigh; /* Upper 8 bytes of the MD5 */ #if defined(USE_BSWM) const BswM_ConfigType* const BswMConfigPtr; #endif #if defined(USE_CAN) const Can_ConfigType* const CanConfigPtr; #endif #if defined(USE_CANIF) const CanIf_ConfigType* const CanIfConfigPtr; #endif #if defined(USE_CANNM) const CanNm_ConfigType* const CanNmConfigPtr; #endif #if defined(USE_CANTP) const CanTp_ConfigType* const CanTpConfigPtr; #endif #if defined (USE_CANTRCV) const CanTrcv_ConfigType* const CanTrcvConfigPtr; #endif #if defined(USE_COM) const Com_ConfigType* const ComConfigPtr; #endif #if defined(USE_COMM) const ComM_ConfigType* const ComMConfigPtr; #endif #if defined(USE_PDUR) const PduR_PBConfigType* const PduRConfigPtr; #endif #if defined(USE_FIM) const FiM_ConfigType* const FiMConfigPtr; #endif const uint32 * const endPattern; } PostbuildConfigType; #endif
2301_81045437/classic-platform
system/EcuM/inc/EcuM_PBTypes.h
C
unknown
2,699
/*-------------------------------- 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 */ /** @fileSafetyClassification ASIL **/ /* Common types for all EcuM variants */ /** * @addtogroup EcuM ECU State Manager * @{ * * @file EcuM_Types.h * Typedefs needed by EcuM module. Note that types that are generated together with * Ecum Service Ports should be guarded by _DEFINED_TYPEDEF_FOR_<Type>_ to avoid re-definition. */ /* @req SWS_EcuM_04037 */ #ifndef ECUM_TYPES_H_ #define ECUM_TYPES_H_ /* @req SWS_BSW_00024 Include AUTOSAR Standard Types Header in implementation header */ #include "Std_Types.h" #include "Os.h" /* @req SWS_EcuM_03025 */ /* @req SWS_EcuMf_00048 */ /*EcuM_UserType defined in Rte*/ /* @req SWS_EcuMf_00105 */ /*EcuM_StateType defined in Rte*/ /* @req SWS_EcuMf_00036 */ /*EcuM_BootTargetType defined in Rte*/ #include "Rte_EcuM_Type.h" /* To extract main state of both EcuM state and synchronization sate. * e.g. Main state: RUN, Sub state: Post Run */ #ifndef ECUM_MAINSTATE_MASK #define ECUM_MAINSTATE_MASK 0xf0 #endif /* ECUM_SUBSTATE_MASK */ /** Enum literals for EcuM_StateType */ /* @req SWS_EcuM_00507 */ /* @req SWS_EcuM_02664 */ #ifndef ECUM_SUBSTATE_MASK #define ECUM_SUBSTATE_MASK 15U #endif /* ECUM_SUBSTATE_MASK */ #ifndef ECUM_STATE_STARTUP #define ECUM_STATE_STARTUP 16U #endif /* ECUM_STATE_STARTUP */ #ifndef ECUM_STATE_STARTUP_ONE #define ECUM_STATE_STARTUP_ONE 17U #endif /* ECUM_STATE_STARTUP_ONE */ #ifndef ECUM_STATE_STARTUP_TWO #define ECUM_STATE_STARTUP_TWO 18U #endif /* ECUM_STATE_STARTUP_TWO */ #ifndef ECUM_STATE_WAKEUP #define ECUM_STATE_WAKEUP 32U #endif /* ECUM_STATE_WAKEUP */ #ifndef ECUM_STATE_WAKEUP_ONE #define ECUM_STATE_WAKEUP_ONE 33U #endif /* ECUM_STATE_WAKEUP_ONE */ #ifndef ECUM_STATE_WAKEUP_VALIDATION #define ECUM_STATE_WAKEUP_VALIDATION 34U #endif /* ECUM_STATE_WAKEUP_VALIDATION */ #ifndef ECUM_STATE_WAKEUP_REACTION #define ECUM_STATE_WAKEUP_REACTION 35U #endif /* ECUM_STATE_WAKEUP_REACTION */ #ifndef ECUM_STATE_WAKEUP_TWO #define ECUM_STATE_WAKEUP_TWO 36U #endif /* ECUM_STATE_WAKEUP_TWO */ #ifndef ECUM_STATE_WAKEUP_WAKESLEEP #define ECUM_STATE_WAKEUP_WAKESLEEP 37U #endif /* ECUM_STATE_WAKEUP_WAKESLEEP */ #ifndef ECUM_STATE_WAKEUP_TTII #define ECUM_STATE_WAKEUP_TTII 38U #endif /* ECUM_STATE_WAKEUP_TTII */ #ifndef ECUM_STATE_RUN #define ECUM_STATE_RUN 48U #endif /* ECUM_STATE_RUN */ #ifndef ECUM_STATE_APP_RUN #define ECUM_STATE_APP_RUN 50U #endif /* ECUM_STATE_APP_RUN */ #ifndef ECUM_STATE_APP_POST_RUN #define ECUM_STATE_APP_POST_RUN 51U #endif /* ECUM_STATE_APP_POST_RUN */ #ifndef ECUM_STATE_SHUTDOWN #define ECUM_STATE_SHUTDOWN 64U #endif /* ECUM_STATE_SHUTDOWN */ #ifndef ECUM_STATE_PREP_SHUTDOWN #define ECUM_STATE_PREP_SHUTDOWN 68U #endif /* ECUM_STATE_PREP_SHUTDOWN */ #ifndef ECUM_STATE_GO_SLEEP #define ECUM_STATE_GO_SLEEP 73U #endif /* ECUM_STATE_GO_SLEEP */ #ifndef ECUM_STATE_GO_OFF_ONE #define ECUM_STATE_GO_OFF_ONE 77U #endif /* ECUM_STATE_GO_OFF_ONE */ #ifndef ECUM_STATE_GO_OFF_TWO #define ECUM_STATE_GO_OFF_TWO 78U #endif /* ECUM_STATE_GO_OFF_TWO */ #ifndef ECUM_STATE_SLEEP #define ECUM_STATE_SLEEP 80U #endif /* ECUM_STATE_SLEEP */ #if defined(USE_HTMSS) #ifndef ECUM_STATE_HWTEST_RESET #define ECUM_STATE_HWTEST_RESET 96U #endif /* ECUM_STATE_HWTEST_RESET */ #ifndef ECUM_STATE_HWTEST_OFF #define ECUM_STATE_HWTEST_OFF 97U #endif /* ECUM_STATE_HWTEST_RESET */ #endif #ifndef ECUM_STATE_OFF #define ECUM_STATE_OFF 128U #endif /* ECUM_STATE_OFF */ #ifndef ECUM_STATE_RESET #define ECUM_STATE_RESET 144U #endif /* ECUM_STATE_RESET */ /** Enum literals for EcuM_BootTargetType */ #ifndef ECUM_BOOT_TARGET_APP #define ECUM_BOOT_TARGET_APP 0U #endif /* ECUM_BOOT_TARGET_APP */ #ifndef ECUM_BOOT_TARGET_OEM_BOOTLOADER #define ECUM_BOOT_TARGET_OEM_BOOTLOADER 1U #endif /* ECUM_BOOT_TARGET_OEM_BOOTLOADER */ #ifndef ECUM_BOOT_TARGET_SYS_BOOTLOADER #define ECUM_BOOT_TARGET_SYS_BOOTLOADER 2U #endif /* ECUM_BOOT_TARGET_SYS_BOOTLOADER */ /* @req SWS_EcuM_04040 */ /*@req SWS_EcuMf_00049*/ typedef uint32 EcuM_WakeupSourceType; /* @req SWS_EcuM_04041 */ typedef enum { ECUM_WKSTATUS_NONE = 0, /**< No pending wakeup event was detected */ ECUM_WKSTATUS_PENDING = 1, /**< The wakeup event was detected but not yet validated */ ECUM_WKSTATUS_VALIDATED = 2, /**< The wakeup event is valid */ ECUM_WKSTATUS_EXPIRED = 3, /**< The wakeup event has not been validated and has expired therefore */ ECUM_WKSTATUS_DISABLED = 4 /**< The wakeup source is disabled and does not detect wakeup events. */ } EcuM_WakeupStatusType; #if defined(USE_WDGM) #include "WdgM.h" #endif #include "Mcu.h" #if defined(USE_COMM) #include "ComM.h" #endif typedef struct EcuM_WakeupSourceConfig { EcuM_WakeupSourceType EcuMWakeupSourceId; uint32 EcuMValidationTimeout; #if defined(USE_COMM) uint8 EcuMComMChannel; #endif } EcuM_WakeupSourceConfigType; typedef struct EcuM_SleepMode { uint8 EcuMSleepModeId; EcuM_WakeupSourceType EcuMWakeupSourceMask; Mcu_ModeType EcuMSleepModeMcuMode; } EcuM_SleepModeType; #if defined(USE_COMM) typedef struct EcuM_ComMConfig { uint8 EcuMComMNetworkHandle; ComM_BusTypeType EcuMComBusType; } EcuM_ComMConfigType; #endif typedef AppModeType EcuM_AppModeType; /* Defines for illegal modes/channels */ #define ECUM_SLEEP_MODE_WDGM_MODE_ILL 0xff #define ECUM_COMM_CHANNEL_ILL 0xff #define ECUM_VALIDATION_TIMEOUT_ILL 0xffffffffuL /* Data structure for EcuM Safety Platform */ /* * Status for sync */ typedef enum { ECUM_SP_PARTITION_ERR, ECUM_SP_REQ_SYNC, ECUM_SP_RELEASE_SYNC, ECUM_SP_OK } EcuM_SP_RetStatus; /* * Status saying the partition completes its requested functionality */ typedef uint16 EcuM_SP_PartitionFunCompletion; #define ECUM_SP_PARTITION_FUN_COMPLETED_A0 0x01 #define ECUM_SP_PARTITION_FUN_COMPLETED_QM 0x02 /* * EcuM_SP_SyncStatus = 0x<major_state><sync_state> (e.g. 0x30, 3- major state, 0-sync state (no partition completed) * with this 4 bit sync state max 3 partition can be tracked if more partition added then this bits has to be increased */ typedef uint16 EcuM_SP_SyncStatus; #define ECUM_SP_SYNC_NOT_REQUIRED 0x0 #define ECUM_PARTITIONS_IN_SYNC 0x03 #define ECUM_SP_SYNC_STARTUP_TWO_START 0x10 #define ECUM_SP_SYNC_STARTUP_TWO_PARTITION_A0_DONE 0x11 #define ECUM_SP_SYNC_STARTUP_TWO_PARTITION_QM_DONE 0x12 #define ECUM_SP_SYNC_STARTUP_TWO_PARTITION_ALL_DONE 0x13 #define ECUM_SP_SYNC_INIT_RUN_START 0x20 #define ECUM_SP_SYNC_INIT_RUN_PARTITION_A0_DONE 0x21 #define ECUM_SP_SYNC_INIT_RUN_PARTITION_QM_DONE 0x22 #define ECUM_SP_SYNC_INIT_RUN_PARTITION_ALL_DONE 0x23 #define ECUM_SP_SYNC_ENTER_RUN_START 0x30 #define ECUM_SP_SYNC_ENTER_RUN_PARTITION_A0_DONE 0x31 #define ECUM_SP_SYNC_ENTER_RUN_PARTITION_QM_DONE 0x32 #define ECUM_SP_SYNC_ENTER_RUN_PARTITION_ALL_DONE 0x33 #define ECUM_SP_SYNC_EXIT_RUN_START 0x40 #define ECUM_SP_SYNC_EXIT_RUN_PARTITION_A0_DONE 0x41 #define ECUM_SP_SYNC_EXIT_RUN_PARTITION_QM_DONE 0x42 #define ECUM_SP_SYNC_EXIT_RUN_PARTITION_ALL_DONE 0x43 #define ECUM_SP_SYNC_POST_RUN_START 0x50 #define ECUM_SP_SYNC_POST_RUN_PARTITION_A0_DONE 0x51 #define ECUM_SP_SYNC_POST_RUN_PARTITION_QM_DONE 0x52 #define ECUM_SP_SYNC_POST_RUN_PARTITION_ALL_DONE 0x53 #define ECUM_SP_SYNC_PREP_SHUTDOWN_START 0x60 #define ECUM_SP_SYNC_PREP_SHUTDOWN_PARTITION_A0_DONE 0x61 #define ECUM_SP_SYNC_PREP_SHUTDOWN_PARTITION_QM_DONE 0x62 #define ECUM_SP_SYNC_PREP_SHUTDOWN_PARTITION_ALL_DONE 0x63 #define ECUM_SP_SYNC_GO_OFF_ONE_START 0x70 #define ECUM_SP_SYNC_GO_OFF_ONE_PARTITION_A0_DONE 0x71 #define ECUM_SP_SYNC_GO_OFF_ONE_PARTITION_QM_DONE 0x72 #define ECUM_SP_SYNC_GO_OFF_ONE_PARTITION_ALL_DONE 0x73 #define ECUM_SP_SYNC_INIT_GO_OFF_TWO_START 0x80 #define ECUM_SP_SYNC_INIT_GO_OFF_TWO_PARTITION_A0_DONE 0x81 #define ECUM_SP_SYNC_INIT_GO_OFF_TWO_PARTITION_QM_DONE 0x82 #define ECUM_SP_SYNC_INIT_GO_OFF_TWO_PARTITION_ALL_DONE 0x83 #define ECUM_SP_SYNC_GO_OFF_TWO_START 0x90 #define ECUM_SP_SYNC_GO_OFF_TWO_PARTITION_A0_DONE 0x91 #define ECUM_SP_SYNC_GO_OFF_TWO_PARTITION_QM_DONE 0x92 #define ECUM_SP_SYNC_GO_OFF_TWO_PARTITION_ALL_DONE 0x93 /* @req SWS_EcuM_04045 */ typedef uint8 EcuM_ShutdownCauseType; /* @req SWS_EcuM_04044 */ typedef uint8 EcuM_ResetType; #endif /* ECUM_TYPES_H_ */ /** @} */
2301_81045437/classic-platform
system/EcuM/inc/EcuM_Types.h
C
unknown
9,378
/*-------------------------------- 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 */ /** @fileSafetyClassification ASIL **/ /* Common functionality for all EcuM variants (Flexible, Fixed, Safety Platform) */ /* ----------------------------[information]----------------------------------*/ /* * * * Description: * Implements the EcuM (fixed) module * * Support: * General Have Support * ------------------------------------------- * ECUM_TTII_ENABLED N * ECUM_DEV_ERROR_DETECT Y * ECUM_VERSION_INFO_API Y * ECUM_INCLUDE_DEM N (controlled by USE_x macro's instead) * ECUM_INCLUDE_NVRAM_MGR N (controlled by USE_x macro's instead) * ECUM_INLCUDE_DET N (controlled by USE_x macro's instead) * ECUM_MAIN_FUNCTION_PERDIOD Y * ECUM_TTII_WKSOURCE N * * Configuration Have Support * ------------------------------------------- * ECUM_SLEEP_ACTIVITY_PERIOD ? * ECUM_CONFIGCONSISTENCY_HASH N * ECUM_RUN_SELF_REQUEST_PERIOD ? * ECUM_NVRAM_WRITEALL_TIMEOUT Y * ECUM_DEFAULT_APP_MODE ? * * * DefaultShutdownTarget * ------------------------------------------- * ECUM_DEFAULT_SHUTDOWN_TARGET N * */ /* ----------------------------[includes]------------------------------------*/ /* @req SWS_EcuM_02986 */ /* @req SWS_EcuM_02987 */ /* @req SWS_EcuM_03009 */ /* @req SWS_EcuM_03023 */ /* @req SWS_EcuM_02862 */ /* @req SWS_EcuM_02810 */ /* @req SWS_EcuM_02757 The ECU Manager shall treat all errors immediately as errors. */ /* @req SWS_EcuM_02758 The ECU Manager shall not recover from an error */ /* @req SWS_EcuM_02759 The ECU Manager Module shall report all errors as events. */ /* @req SWS_EcuM_02763 Select boot target not supported */ /* @req SWS_EcuM_02858 */ /* @req SWS_EcuM_02859 */ /** These requirements are supported in .swcd file */ /* @req SWS_EcuM_03018 */ /* @req SWS_EcuM_03017 */ /* @req SWS_EcuM_03012 */ /* @req SWS_EcuM_03011 */ /* @req SWS_EcuM_02979 */ /* @req SWS_EcuM_04067 EcuM_UserType is defined by the RTE (RTE_EcuM_Type.h) */ /* @req SWS_EcuM_04042 EcuM_BootTargetType is defined by the RTE (RTE_EcuM_Type.h) */ /* @req SWS_BSW_00005 */ /* @req SWS_BSW_00004 */ #include "Std_Types.h" #include "EcuM.h" #include <string.h> #include <Os.h> #include "EcuM_Generated_Types.h" #if defined(USE_HTMSS) #include "Htmss.h" #endif #include "EcuM_Internals.h" #include "EcuM_Cbk.h" #include "SchM_EcuM.h" #if defined(USE_BSWM) #include "BswM_EcuM.h" #endif /*lint -e451 MISRA:EXTERNAL_FILE:file inclusion:[MISRA 2012 Directive 4.10, required] */ #include "MemMap.h" #include "Mcu.h" #include "ComStack_Types.h" #if defined(USE_DET) #include "Det.h" #endif #if defined(USE_DEM) #include "Dem.h" /* @req SWS_EcuM_02875 */ #endif #include "isr.h" #if defined(USE_NVM) #include "NvM.h" #endif #if defined(USE_RTE) #include "Rte_Main.h" #endif #if defined(USE_SCHM) #include "SchM.h" #endif #if defined(USE_RTM) #include "Smal.h" #endif #if defined(USE_HTMSS) #include "Htmss.h" #endif //#define USE_LDEBUG_PRINTF #include "debug.h" /* ----------------------------[Memory Partition]---------------------------*/ /* @req SWS_EcuM_04035 */ /* @req SWS_BSW_00006 */ #define ECUM_START_SEC_VAR_CLEARED_GLOBALMASTER_UNSPECIFIED /*lint -save -e9019 MISRA:OTHER:suppressed due to EcuM_MemMap.h include is needed:[MISRA 2012 Rule 20.1, advisory] */ #include "EcuM_BswMemMap.h" EcuM_GlobalType EcuM_World; #define ECUM_STOP_SEC_VAR_CLEARED_GLOBALMASTER_UNSPECIFIED #include "EcuM_BswMemMap.h" #define ECUM_START_SEC_VAR_CLEARED_GLOBALMASTER_UNSPECIFIED #include "EcuM_BswMemMap.h" uint32 EcuM_World_run_state_timeout = 0; #define ECUM_STOP_SEC_VAR_CLEARED_GLOBALMASTER_UNSPECIFIED #include "EcuM_BswMemMap.h" #define ECUM_START_SEC_VAR_CLEARED_COMNVM_UNSPECIFIED #include "EcuM_BswMemMap.h" EcuM_GlobalType_Partition_COMMNVM EcuM_World_ComM_NVM; #define ECUM_STOP_SEC_VAR_CLEARED_COMNVM_UNSPECIFIED #include "EcuM_BswMemMap.h" /*lint -restore */ /* ----------------------------[private define]------------------------------*/ /* ----------------------------[private macro]-------------------------------*/ /* ----------------------------[private typedef]-----------------------------*/ /* ----------------------------[private function prototypes]-----------------*/ #if ( ECUM_DEV_ERROR_DETECT == STD_ON ) void CheckWakeupSourceValidity(EcuM_WakeupSourceType sources, uint8 FunctionId); #endif /* ----------------------------[private functions]---------------------------*/ #if !defined(USE_BSWM) #define BswM_EcuM_CurrentWakeup(source, state) #endif #if ( ECUM_DEV_ERROR_DETECT == STD_ON ) void CheckWakeupSourceValidity(EcuM_WakeupSourceType sources, uint8 FunctionId) { EcuM_WakeupSourceType wkSource; const EcuM_SleepModeType *sleepModePtr; sleepModePtr = &EcuM_World.config->EcuMSleepModeConfig[EcuM_World.sleep_mode]; wkSource = sleepModePtr->EcuMWakeupSourceMask; /* @req SWS_EcuM_02625 */ /* Predefined source does not require validation */ if ( ( sources & (ECUM_WKSOURCE_POWER | ECUM_WKSOURCE_RESET | ECUM_WKSOURCE_INTERNAL_RESET | ECUM_WKSOURCE_INTERNAL_WDG | ECUM_WKSOURCE_EXTERNAL_WDG | ECUM_WKSOURCE_HWTEST_RESET) ) != 0 ) { /*Ok*/ } else if( !((sources | wkSource) == wkSource)) { ECUM_DET_REPORT_ERROR(FunctionId, ECUM_E_UNKNOWN_WAKEUP_SOURCE ); /*lint -e{904} MISRA:OTHER:Return statement is necessary in case of reporting a DET error:[MISRA 2012 Rule 15.5, advisory]*/ return; } else { /* do nothing */ } return; } #else #define CheckWakeupSourceValidity(sources, FunctionId) #endif #if defined(CFG_POSTBUILD) static boolean ValidatePostBuildConfiguration(const EcuM_ConfigType* config) { boolean status = TRUE; /* The hash is calculated both when generating the pre compile configuration * and the postbuild configuration. It is based on all pre compile configuration * parameters. * Generator version and vendor id also needs to be a part of the input to the * hash. */ /* Chech that the pointer at least isn't NULL */ if (config->PostBuildConfig == NULL) { status = FALSE; } /* Just a basic check that the it seems to be a valid post build area */ else if (0x5A5A5A5A != config->PostBuildConfig->startPattern) { status = FALSE; } /* Check the variant */ else if (config->EcuMPostBuildVariant != config->PostBuildConfig->postBuildVariant) { status = FALSE; } /* Check the hash */ else if ((config->EcuMConfigConsistencyHashLow != config->PostBuildConfig->preCompileHashLow) || (config->EcuMConfigConsistencyHashHigh != config->PostBuildConfig->preCompileHashHigh)) { status = FALSE; } else { status = TRUE; } return status; } #endif #if defined(USE_HTMSS) /** * @brief Get test results from Htmss * @param group */ static void EcuM_GetHWTestResults( HTMSS_TestGroupType group ) { HTMSS_TestStatusType rv; rv = HTMSS_GetTestStatus(group, NULL_PTR); if(rv != HTMSS_STATUS_OK) { HTMSS_StartupTestErrorHook(); } } #endif /* ----------------------------[public functions]----------------------------*/ #if !defined(USE_DET) && (ECUM_DEV_ERROR_DETECT == STD_ON) #error EcuM configuration error. DET is not enabled when ECUM_DEV_ERROR_DETECT is set #endif /* @req SWS_EcuM_02411 */ /* @req SWS_EcuM_02684 */ /* @req SWS_EcuM_02980 */ /* Init function of all Bsw modules doesn't have return value hence error is ignored implicitly */ /* @req SWS_BSW_00071 */ /** * Initialize EcuM. */ void EcuM_Init(void) { Mcu_ResetType resetReason; /* @req SWS_EcuM_04015 */ boolean ret = TRUE; #if (OS_NUM_CORES > 1) if (OS_CORE_IS_ID_MASTER(GetCoreID())) { #endif Std_ReturnType status; #if defined(USE_ECUM_FIXED) SetCurrentState(ECUM_STATE_STARTUP_ONE); #endif // Initialize drivers that are needed to determine PostBuild configuration EcuM_AL_DriverInitZero(); // Initialize the OS InitOS(); // Setup interrupts Os_IsrInit(); // Determine PostBuild configuration EcuM_World.config = EcuM_DeterminePbConfiguration(); #if defined(USE_RTM) Smal_Init(); #endif #if defined(USE_HTMSS) // Initialize Safety Monitor /* @req ARC_SWS_ECUM_00012 SMAL_Init allowed to run before HTMSS_Init request test configuration */ HTMSS_Init(0u); /*lint !e910 MISRA:ARGUMENT CHECK:HTMSS_Init does not have support for using input arguments so the value sent is not relevant:[MISRA 2012 Rule 11.9, required] */ #endif #if defined(CFG_POSTBUILD) /* @req SWS_EcuM_02796 */ /* @req SWS_EcuM_02798 */ if (FALSE == ValidatePostBuildConfiguration(EcuM_World.config)) { #if defined(USE_DEM) EcuM_ErrorHook(EcuM_World.config->EcuMDemInconsistencyEventId); #endif ret = FALSE; } #endif /*lint -e{774} MISRA:CONFIGURATION:This may be FALSE if CFG_POSTBUILD is enabled: [MISRA 2012 Rule 14.3,required] */ if (ret == TRUE) { // Initialize drivers needed before the OS-starts EcuM_AL_DriverInitOne(EcuM_World.config); resetReason = Mcu_GetResetReason(); // Determine the reset/wakeup reason /* @req SWS_EcuM_02623 */ /* Validated immediately */ switch (resetReason) { case MCU_POWER_ON_RESET: EcuM_ValidateWakeupEvent(ECUM_WKSOURCE_POWER); break; case MCU_SW_RESET: case MCU_RESET_UNDEFINED: EcuM_ValidateWakeupEvent(ECUM_WKSOURCE_RESET); /* @req SWS_EcuM_02601 ECUM_WKSOURCE_RESET shall be reported if no specific wk source detected */ break; case MCU_WATCHDOG_RESET: EcuM_ValidateWakeupEvent(ECUM_WKSOURCE_INTERNAL_WDG); break; #if defined(USE_HTMSS) case MCU_HWTEST_RESET: EcuM_GetHWTestResults(HTMSS_SHUTDOWN); EcuM_ValidateWakeupEvent(ECUM_WKSOURCE_HWTEST_RESET); break; #endif default: EcuM_Arc_RememberWakeupEvent((uint32)resetReason); break; } #if defined(USE_HTMSS) Std_ReturnType testReturn = HTMSS_StartTest(HTMSS_STARTUP); if (testReturn == E_OK) { EcuM_GetHWTestResults(HTMSS_STARTUP); } #endif /* Moved this here because EcuM_SelectShutdownTarget needs us to be initilized.*/ EcuM_World.initiated = TRUE; /* Set default shutdown target */ /* @req SWS_EcuM_02181 */ status = EcuM_SelectShutdownTarget(EcuM_World.config->EcuMDefaultShutdownTarget, EcuM_World.config->EcuMDefaultSleepMode); if (status == E_OK) { EcuM_World.run_requests = 0; EcuM_World.postrun_requests = 0; #if (ECUM_RESET_LOOP_DETECTION == STD_ON) /* NOTE: This returns true if a loop is detected. The spec does not say */ /* what to do if that happens. */ EcuM_LoopDetection(); #endif // Start this baby up /* @req SWS_EcuMf_00010 */ /* @req SWS_EcuM_02603 */ #if (OS_NUM_CORES > 1) StatusType coreStatus; StartCore(GetCoreID() + 1, &coreStatus); #endif StartOS(EcuM_World.config->EcuMDefaultAppMode); /* @req SWS_EcuM_00243 */ } } #if (OS_NUM_CORES > 1) } else { /* @req SWS_EcuM_04017 */ InitOS(); Os_IsrInit(); StatusType coreStatus; StartCore(GetCoreID() + 1, &coreStatus); StartOS(OSDEFAULTAPPMODE); } #endif } /* @req SWS_EcuM_04020 */ // Typically called from OS shutdown hook void EcuM_Shutdown(void) { #if defined(USE_ECUM_FIXED) SetCurrentState(ECUM_STATE_GO_OFF_TWO); #endif #if defined(USE_HTMSS) Std_ReturnType testReturn; if ((EcuM_World.shutdown_target == ECUM_STATE_HWTEST_OFF) || (EcuM_World.shutdown_target == ECUM_STATE_HWTEST_RESET) ) { testReturn = HTMSS_StartTest(HTMSS_SHUTDOWN); if (testReturn == E_NOT_OK) { HTMSS_ShutdownTestErrorHook(); } } #endif // Let the last drivers do a nice shutdown #if (ECUM_ARC_SAFETY_PLATFORM == STD_ON) // As this is running in Supervisor mode (from SYS_CALL_ShutdownOS, both the partition call be called here EcuM_OnGoOffTwo_Partition_A0(); /*@req ARC_SWS_ECUM_00002*/ EcuM_OnGoOffTwo_Partition_QM(); #else EcuM_OnGoOffTwo(); #endif if (EcuM_World.shutdown_target == ECUM_STATE_OFF) { EcuM_AL_SwitchOff(); /* @req SWS_EcuM_04075 */ } else { EcuM_AL_Reset(EcuM_World.sleep_mode); /* @req SWS_EcuM_04074 */ } } Std_ReturnType EcuM_SelectShutdownTarget(EcuM_StateType shutdownTarget, uint8 sleepMode) { /* 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 */ VALIDATE_RV(EcuM_World.initiated, ECUM_SELECTSHUTDOWNTARGET_ID, ECUM_E_UNINIT, E_NOT_OK); #if (ECUM_DEV_ERROR_DETECT == STD_ON) boolean b_shutdownTarget = ((shutdownTarget == ECUM_STATE_OFF) || (shutdownTarget == ECUM_STATE_RESET) || #if defined(USE_HTMSS) (shutdownTarget == ECUM_STATE_HWTEST_OFF) || (shutdownTarget == ECUM_STATE_HWTEST_RESET) || #endif (shutdownTarget == ECUM_STATE_SLEEP)); #endif /* @req SWS_EcuM_00624 */ VALIDATE_RV(b_shutdownTarget, ECUM_SELECTSHUTDOWNTARGET_ID, ECUM_E_STATE_PAR_OUT_OF_RANGE, E_NOT_OK); LDEBUG_PRINTF("EcuM_SelectShutdownTarget(): shutdownTarget=%s, sleepMode=%d\n", GetMainStateAsString(shutdownTarget), sleepMode); /* @req SWS_EcuM_02585 */ /* @req SWS_EcuM_00232 */ /* @req SWS_EcuM_00624 */ EcuM_World.shutdown_target = shutdownTarget; EcuM_World.sleep_mode = sleepMode; return E_OK; } Std_ReturnType EcuM_GetShutdownTarget(EcuM_StateType* shutdownTarget, uint8* sleepMode) { /* @req SWS_EcuM_02788 */ /* 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 */ VALIDATE_RV(EcuM_World.initiated, ECUM_GETSHUTDOWNTARGET_ID, ECUM_E_UNINIT, E_NOT_OK); VALIDATE_RV(shutdownTarget != NULL, ECUM_GETSHUTDOWNTARGET_ID, ECUM_E_NULL_POINTER, E_NOT_OK); VALIDATE_RV(sleepMode != NULL, ECUM_GETSHUTDOWNTARGET_ID, ECUM_E_NULL_POINTER, E_NOT_OK); *shutdownTarget = EcuM_World.shutdown_target; *sleepMode = EcuM_World.sleep_mode; return E_OK; } Std_ReturnType EcuM_SelectBootTarget(EcuM_BootTargetType target) { // Not supported (void)target; return E_NOT_OK; } Std_ReturnType EcuM_GetBootTarget(EcuM_BootTargetType* target) { // Not supported //lint -estring(920,pointer) /* cast to void */ (void) target; //lint +estring(920,pointer) /* cast to void */ return E_NOT_OK; } Std_ReturnType EcuM_GetLastShutdownTarget(EcuM_StateType* shutdownTarget, uint8* sleepMode) { /* NOT SUPPORTED */ /*lint --e{920} MISRA:STANDARDIZED_INTERFACE:cast is being made from the given type to void:[MISRA 2012 Rule 1.3, required] */ (void)shutdownTarget; (void)sleepMode; return E_NOT_OK; } /** * * @param sources */ /* @req SWS_EcuM_02572 */ /* !req SWS_EcuM_04012 */ /* !req [SWS_EcuM_02712] */ void EcuM_SetWakeupEvent(EcuM_WakeupSourceType sources) { EcuM_WakeupSourceType wkSource; DEBUG_ECUM_CALLIN_W_ARG("EcuM_SetWakeupEvent","0x%lx",(uint32)sources); /* @req SWS_EcuM_02826 */ /* @req SWS_EcuM_02171 */ /* @req SWS_EcuM_02976 */ /* @req SWS_EcuM_02565 */ /*Validate at once for pre-defined sources */ wkSource = (ECUM_WKSOURCE_POWER | ECUM_WKSOURCE_RESET | ECUM_WKSOURCE_INTERNAL_RESET | ECUM_WKSOURCE_INTERNAL_WDG | ECUM_WKSOURCE_EXTERNAL_WDG); /* Sources that should be validated at once */ wkSource &= sources; /* @req SWS_EcuM_02975 */ if (wkSource != 0) { /* Validate pre-defined source at once */ EcuM_ValidateWakeupEvent(wkSource); } /* Don't add pre-defined source to PENDING */ sources ^= wkSource; if (sources != 0 ) { /* @req SWS_EcuM_02867 */ #if ( ECUM_DEV_ERROR_DETECT == STD_ON ) /* Get user defined sources */ wkSource = EcuM_World.config->EcuMSleepModeConfig[EcuM_World.sleep_mode].EcuMWakeupSourceMask; /* Add always validated sources */ wkSource |= (ECUM_WKSOURCE_POWER|ECUM_WKSOURCE_RESET | ECUM_WKSOURCE_INTERNAL_RESET | ECUM_WKSOURCE_INTERNAL_WDG | ECUM_WKSOURCE_EXTERNAL_WDG); if( !((sources | wkSource) == wkSource)) { ECUM_DET_REPORT_ERROR(ECUM_SETWAKEUPEVENT_ID, ECUM_E_UNKNOWN_WAKEUP_SOURCE ); /*lint -e{904} MISRA:ARGUMENT_CHECK:Return statement is necessary in case of reporting a DET error:[MISRA 2012 Rule 15.5, advisory] */ return; } #endif /* @req SWS_EcuM_01117 */ EcuM_World.wakeupEvents |= sources; #if defined(USE_BSWM) BswM_EcuM_CurrentWakeup(sources, ECUM_WKSTATUS_PENDING); #endif } /* @req SWS_EcuM_02707 */ /* @req SWS_EcuM_00714 */ /* @req SWS_EcuM_02565 */ /* @req SWS_EcuM_02709 */ /*@req SWS_EcuM_04004 */ EcuM_World.validationTimer = ECUM_VALIDATION_TIMEOUT / ECUM_MAIN_FUNCTION_PERIOD; //lint !e835 PC-lint violation: Allow zero value as left parameter for configuration } /** * Clear wakeup events * * @return */ void EcuM_ClearWakeupEvent(EcuM_WakeupSourceType source) { /* @req SWS_EcuM_02807 */ /* @req SWS_EcuM_02683 */ EcuM_World.wakeupEvents &= ~(uint32)source; /* Clear pending events */ EcuM_World.validEvents &= ~(uint32)source; /* Clear validated events */ } /** * Get the pending wakeup events. * * @return */ EcuM_WakeupSourceType EcuM_GetPendingWakeupEvents(void) { /* @req SWS_EcuM_02827 */ /* @req SWS_EcuM_02172 */ /* @req SWS_EcuM_01156 */ return EcuM_World.wakeupEvents; } /* @req SWS_EcuM_02532 */ EcuM_WakeupSourceType EcuM_GetValidatedWakeupEvents(void) { // is not really an enum. /* @req SWS_EcuM_02496 */ /* @req SWS_EcuM_02533 */ /* @req SWS_EcuM_03003 */ return EcuM_World.validEvents; } /** * * @param sources */ void EcuM_ValidateWakeupEvent(EcuM_WakeupSourceType sources) { /* @req SWS_EcuM_02625 */ /*No validation of any source */ /* @req SWS_EcuM_00344 */ /* @req SWS_EcuM_02868 */ /* @req SWS_EcuM_02345 */ CheckWakeupSourceValidity(sources, ECUM_VALIDATE_WAKEUP_EVENT_ID); /* @req SWS_EcuM_02496 */ /* @req SWS_EcuM_04078 */ EcuM_World.validEvents |= sources; /* @req SWS_EcuM_02645 */ #if defined(USE_COMM) const EcuM_WakeupSourceConfigType *wkupCfgPtr; for (uint32 i = 0; i < ECUM_WKSOURCE_USER_CNT; i++) { wkupCfgPtr = &EcuM_World.config->EcuMWakeupSourceConfig[i]; /** @CODECOV:NOT_SUPPORTED:Sleep not supported in SafetyPlatform */ __CODE_COVERAGE_IGNORE__ if ( ((sources & wkupCfgPtr->EcuMWakeupSourceId) != 0) && (wkupCfgPtr->EcuMComMChannel != ECUM_COMM_CHANNEL_ILL) ) { /*@req SWS_EcuM_00480*/ ComM_EcuM_WakeUpIndication(wkupCfgPtr->EcuMComMChannel); } } #endif /* !req SWS_EcuM_02790 */ /* !req SWS_EcuM_02791 */ /* @req SWS_EcuM_04003 *//* @req SWS_EcuM_04079 */ #if (ECUM_ARC_SAFETY_PLATFORM == STD_OFF) BswM_EcuM_CurrentWakeup(sources, ECUM_WKSTATUS_VALIDATED); #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 ( ECUM_VERSION_INFO_API == STD_ON ) void EcuM_GetVersionInfo( Std_VersionInfoType* VersionInfo ) { /** @req SWS_EcuMf_00034 */ /* 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 */ VALIDATE_NO_RV((VersionInfo != NULL_PTR),ECUM_GETVERSIONINFO_ID,ECUM_E_NULL_POINTER); /*@req SWS_EcuMf_00034*/ VersionInfo->vendorID = ECUM_VENDOR_ID; VersionInfo->moduleID = ECUM_MODULE_ID; VersionInfo->sw_major_version = ECUM_SW_MAJOR_VERSION; VersionInfo->sw_minor_version = ECUM_SW_MINOR_VERSION; VersionInfo->sw_patch_version = ECUM_SW_PATCH_VERSION; } #endif
2301_81045437/classic-platform
system/EcuM/src/EcuM.c
C
unknown
22,391
/*-------------------------------- 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 */ /** @fileSafetyClassification ASIL **/ /* This file handles ASIL partition ECU management */ /* @req SWS_BSW_00005 */ #include "Std_Types.h" #include "EcuM.h" #include <Os.h> #include "EcuM_Generated_Types.h" #include "EcuM_Internals.h" #include "EcuM_SP_common.h" #include "SchM_EcuM.h" #include "Mcu.h" #if defined(USE_RTM) #include "Rtm.h" #endif #if defined(USE_HTMSS) #include "Htmss.h" #endif #if defined(USE_DET) #include "Det.h" #endif #if defined(USE_DEM) #include "Dem.h" /* @req SWS_EcuM_02875 */ #endif #if defined(USE_NVM) #include "NvM.h" #endif #if defined(USE_RTE) #include "Rte_Main.h" #endif #if defined(USE_SCHM) #include "SchM_SP.h" #endif #ifndef SYS_CALL_ShutdownOS #define SYS_CALL_ShutdownOS ShutdownOS #endif /* @req SWS_BSW_00006 */ #define ECUM_START_SEC_VAR_CLEARED_16 #include "EcuM_BswMemMap.h" /*lint !e9019 MISRA:OTHER:suppressed due to EcuM_MemMap.h include is needed:[MISRA 2012 Rule 20.1, advisory] */ uint16 EcuM_World_SP_sync_timeout = 0; #define ECUM_STOP_SEC_VAR_CLEARED_16 #include "EcuM_BswMemMap.h" /*lint !e9019 MISRA:OTHER:suppressed due to EcuM_MemMap.h include is needed:[MISRA 2012 Rule 20.1, advisory] */ /* * Tracking the variable for QM to sync with other partition */ static inline void set_sync_status_master(EcuM_SP_SyncStatus syncStatus){ EcuM_World.syncStatusMaster= syncStatus; } static inline void clear_sync_status_master(){ set_sync_status_master(ECUM_SP_SYNC_NOT_REQUIRED); } /* * get the sync status (written by Asil parition only) */ static inline EcuM_SP_SyncStatus get_sync_status_master(void){ return EcuM_World.syncStatusMaster; } /* * Start Sync status (written by Asil partition only) */ static inline EcuM_SP_RetStatus start_sync_status_master(EcuM_SP_SyncStatus syncStatus){ EcuM_World.syncStatusMaster = syncStatus; return ECUM_SP_REQ_SYNC; } /* * Start Sync status (written by Asil partition only) */ static inline EcuM_SP_SyncStatus update_sync_sub_status_master(EcuM_SP_PartitionFunCompletion syncStatus){ EcuM_World.syncStatusMaster|= (syncStatus & (EcuM_SP_SyncStatus)ECUM_SUBSTATE_MASK); return EcuM_World.syncStatusMaster; } static inline boolean is_exec_required_for_state_master() { return (((get_sync_status_master() & (EcuM_SP_SyncStatus)ECUM_SP_PARTITION_FUN_COMPLETED_A0) == ECUM_SP_PARTITION_FUN_COMPLETED_A0) ? FALSE : TRUE); } static inline boolean is_currentSyncState(EcuM_SP_SyncStatus syncStatus) { return (((get_sync_status_master() & syncStatus) == syncStatus) ? TRUE : FALSE); } /* * startup II for partition A0 (in state ECUM_STATE_STARTUP_TWO) */ static inline EcuM_SP_RetStatus in_state_startup_two_partition_A0(void){ EcuM_SP_RetStatus rv = ECUM_SP_OK; if (is_exec_required_for_state_master() == TRUE) { EcuM_StartupTwo_Partition_A0(); rv = start_sync_status_master (ECUM_SP_SYNC_STARTUP_TWO_START); EcuM_SP_Sync_UpdateStatus(ECUM_SP_PARTITION_FUN_COMPLETED_A0); } else if (is_currentSyncState(ECUM_SP_SYNC_STARTUP_TWO_PARTITION_ALL_DONE) == TRUE) { EcuM_AL_DriverInitThree_Partition_A0(EcuM_World.config); EcuM_OnEnterRun_Partition_A0(); /** @req SWS_EcuM_00308 */ rv = start_sync_status_master (ECUM_SP_SYNC_INIT_RUN_START); EcuM_SP_Sync_UpdateStatus(ECUM_SP_PARTITION_FUN_COMPLETED_A0); } else { // in synchronization } return rv; } /* * RUN II for partition A0 (in state ECUM_STATE_APP_RUN) */ static inline EcuM_SP_RetStatus in_state_appRun_partition_A0(void){ EcuM_SP_RetStatus rv = ECUM_SP_OK; if (EcuM_World_run_state_timeout != 0) { EcuM_World_run_state_timeout--; } if (is_exec_required_for_state_master() == TRUE) { if ((FALSE == hasRunRequests()) && (EcuM_World_run_state_timeout == 0)) { EcuM_OnExitRun_Partition_A0(); /** @req SWS_EcuM_00865 */ rv = start_sync_status_master (ECUM_SP_SYNC_EXIT_RUN_START); EcuM_SP_Sync_UpdateStatus(ECUM_SP_PARTITION_FUN_COMPLETED_A0); } else { // in run state } } return rv; } /* * RUN III states (in state ECUM_STATE_APP_POST_RUN) for partition A0 */ static inline EcuM_SP_RetStatus in_state_appPostRun_partition_A0(void){ EcuM_SP_RetStatus rv = ECUM_SP_OK; if (is_exec_required_for_state_master() == TRUE) { if (TRUE == hasRunRequests()){ /* We have run requests, return to RUN II */ /* @req SWS_EcuM_00866 */ EcuM_OnEnterRun_Partition_A0(); /** @req SWS_EcuM_00308 */ rv = start_sync_status_master (ECUM_SP_SYNC_INIT_RUN_START); EcuM_SP_Sync_UpdateStatus(ECUM_SP_PARTITION_FUN_COMPLETED_A0); } else if (FALSE == hasPostRunRequests()){ EcuM_OnExitPostRun_Partition_A0(); /** @req SWS_EcuM_00761 */ rv = start_sync_status_master (ECUM_SP_SYNC_POST_RUN_START); EcuM_SP_Sync_UpdateStatus(ECUM_SP_PARTITION_FUN_COMPLETED_A0); } else { /* NOTE: We have postrun requests */ } } return rv; } /* * PREP SHUTDOWN state (in state ECUM_STATE_PREP_SHUTDOWN) for A0 */ static inline EcuM_SP_RetStatus in_state_prepShutdown_Partition_A0(void){ EcuM_SP_RetStatus rv = ECUM_SP_OK; if (is_exec_required_for_state_master() == TRUE) { EcuM_OnPrepShutdown_Partition_A0(); // Switch shutdown mode if ((EcuM_World.shutdown_target == ECUM_STATE_OFF) || (EcuM_World.shutdown_target == ECUM_STATE_RESET)) { //If in state Off or Reset go into Go_Off_One: rv = start_sync_status_master (ECUM_SP_SYNC_PREP_SHUTDOWN_START); EcuM_SP_Sync_UpdateStatus(ECUM_SP_PARTITION_FUN_COMPLETED_A0); } else{ rv = ECUM_SP_PARTITION_ERR; } } return rv; } /* * GO OFF ONE state (in state ECUM_STATE_GO_OFF_ONE) for A0 */ static inline EcuM_SP_RetStatus in_go_off_one_mode_partition_A0(void){ EcuM_SP_RetStatus rv = ECUM_SP_OK; if (is_exec_required_for_state_master() == TRUE) { EcuM_OnGoOffOne_Partition_A0(); rv = start_sync_status_master (ECUM_SP_SYNC_GO_OFF_ONE_START); EcuM_SP_Sync_UpdateStatus(ECUM_SP_PARTITION_FUN_COMPLETED_A0); } else if (is_currentSyncState(ECUM_SP_SYNC_GO_OFF_ONE_PARTITION_ALL_DONE) == TRUE) { rv = start_sync_status_master (ECUM_SP_SYNC_INIT_GO_OFF_TWO_START); EcuM_SP_Sync_UpdateStatus(ECUM_SP_PARTITION_FUN_COMPLETED_A0); } else { // in synchronization with other partition } return rv; } /* * Main function A0 */ EcuM_SP_RetStatus EcuM_MainFunction_Partition_A0(EcuM_StateType current_state) { EcuM_SP_RetStatus rv = ECUM_SP_OK; switch (current_state) { case ECUM_STATE_APP_RUN: /* RUN II state */ rv = in_state_appRun_partition_A0(); break; case ECUM_STATE_APP_POST_RUN: /* RUN III state */ rv = in_state_appPostRun_partition_A0(); break; case ECUM_STATE_PREP_SHUTDOWN: rv = in_state_prepShutdown_Partition_A0(); break; case ECUM_STATE_GO_OFF_ONE: rv = in_go_off_one_mode_partition_A0(); break; case ECUM_STATE_STARTUP_ONE: case ECUM_STATE_STARTUP_TWO: rv = in_state_startup_two_partition_A0(); break; default: ECUM_DET_REPORT_ERROR(ECUM_ARC_MAINFUNCTION_A0_ID, ECUM_E_ARC_FAULTY_CURRENT_STATE); break; } EcuM_SP_SyncStatus currentSyncStatus = get_sync_status_master(); if (currentSyncStatus != ECUM_SP_SYNC_NOT_REQUIRED) { //If we reached ALL_DONE, code above shall go to SYNC_NOT_REQUIRED or next main status START. Otherwise there is some internal error (we will be stuck in ALL_DONE). ASSERT((currentSyncStatus & (EcuM_SP_SyncStatus)ECUM_SUBSTATE_MASK) != ECUM_PARTITIONS_IN_SYNC); EcuM_World_SP_sync_timeout++; } else { EcuM_World_SP_sync_timeout = 0; } /* @req ARC_SWS_ECUM_00010 If synchronisation takes more than the ECUM_SYNC_TIMEOUT_LIMIT then EcuM shall log RTM fault. */ if (EcuM_World_SP_sync_timeout > ECUM_SYNC_TIMEOUT_LIMIT) { #if defined(USE_RTM) Rtm_EntryType EntryType; EntryType.errorType = RTM_ERRORTYPE_BSW; EntryType.error.bsw.moduleId = ECUM_MODULE_ID; EntryType.error.bsw.errorId = ECUM_E_ARC_PARTITION_SYNC_TIMEOUT; Rtm_ReportFailure(&EntryType); #endif } return rv; } /* * Update the EcuM status based on the sync status, this is only called from master. */ void EcuM_SP_Sync_UpdateStatus(EcuM_SP_PartitionFunCompletion syncSubState) { EcuM_SP_SyncStatus syncState = update_sync_sub_status_master(syncSubState); switch (syncState) { case ECUM_SP_SYNC_EXIT_RUN_PARTITION_ALL_DONE: clear_sync_status_master(); /* @req SWS_EcuM_00311 */ SetCurrentState(ECUM_STATE_APP_POST_RUN); /** @req SWS_EcuM_00865 */ break; case ECUM_SP_SYNC_POST_RUN_PARTITION_ALL_DONE: clear_sync_status_master(); SetCurrentState(ECUM_STATE_PREP_SHUTDOWN); break; case ECUM_SP_SYNC_PREP_SHUTDOWN_PARTITION_ALL_DONE: clear_sync_status_master(); SetCurrentState(ECUM_STATE_GO_OFF_ONE); break; case ECUM_SP_SYNC_GO_OFF_ONE_PARTITION_ALL_DONE: // change state on ECUM_SP_SYNC_INIT_GO_OFF_TWO_PARTITION_ALL_DONE break; case ECUM_SP_SYNC_INIT_GO_OFF_TWO_PARTITION_ALL_DONE: clear_sync_status_master(); SYS_CALL_ShutdownOS(E_OK); break; case ECUM_SP_SYNC_STARTUP_TWO_PARTITION_ALL_DONE: // change state on ECUM_SP_SYNC_INIT_RUN_PARTITION_ALL_DONE break; case ECUM_SP_SYNC_INIT_RUN_PARTITION_ALL_DONE: clear_sync_status_master(); SetCurrentState(ECUM_STATE_APP_RUN); break; default: /*Partitions not synchronized yet, do nothing until they are*/ break; } } /* * The order defined here is found in SWS_EcuM_02411 */ void EcuM_StartupTwo_Partition_A0(void) { ASSERT(EcuM_World.current_state == ECUM_STATE_STARTUP_ONE); SetCurrentState(ECUM_STATE_STARTUP_TWO); /* Initialize drivers that don't need NVRAM data */ EcuM_AL_DriverInitTwo_Partition_A0(EcuM_World.config); /* Prepare the system to startup RTE */ #if defined(USE_RTE) (void)Rte_Start_partitionA0(); #endif }
2301_81045437/classic-platform
system/EcuM/src/EcuM_A0.c
C
unknown
11,680
/*-------------------------------- 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 -save -e451 MISRA:STANDARDIZED_INTERFACE:AUTOSAR Require Inclusion:[MISRA 2012 Directive 4.10, required]*/ /*lint -save -e9019 MISRA:OTHER:AUTOSAR Require Inclusion:[MISRA 2012 Rule 20.1, advisory] */ /*lint -save -e9021 MISRA:OTHER:AUTOSAR Require Inclusion:[MISRA 2012 Rule 20.5, advisory] */ #ifdef ECUM_START_SEC_VAR_CLEARED_GLOBALMASTER_UNSPECIFIED #include "MemMap.h" #undef ECUM_MEMMAP_ERROR #undef ECUM_START_SEC_VAR_CLEARED_GLOBALMASTER_UNSPECIFIED #endif #ifdef ECUM_STOP_SEC_VAR_CLEARED_GLOBALMASTER_UNSPECIFIED #include "MemMap.h" #undef ECUM_MEMMAP_ERROR #undef ECUM_STOP_SEC_VAR_CLEARED_GLOBALMASTER_UNSPECIFIED #endif #ifdef ECUM_START_SEC_VAR_INIT_UNSPECIFIED #include "MemMap.h" #undef ECUM_MEMMAP_ERROR #undef ECUM_START_SEC_VAR_INIT_UNSPECIFIED #endif #ifdef ECUM_STOP_SEC_VAR_CLEARED_UNSPECIFIED #include "MemMap.h" #undef ECUM_MEMMAP_ERROR #undef ECUM_STOP_SEC_VAR_CLEARED_UNSPECIFIED #endif #ifdef ECUM_START_SEC_VAR_CLEARED_16 #include "MemMap.h" #undef ECUM_MEMMAP_ERROR #undef ECUM_START_SEC_VAR_CLEARED_16 #endif #ifdef ECUM_STOP_SEC_VAR_CLEARED_16 #include "MemMap.h" #undef ECUM_MEMMAP_ERROR #undef ECUM_STOP_SEC_VAR_CLEARED_16 #endif #ifdef ECUM_START_SEC_VAR_NVM_CLEARED_8 #include "MemMap.h" #undef ECUM_MEMMAP_ERROR #undef ECUM_START_SEC_VAR_NVM_CLEARED_8 #endif #ifdef ECUM_STOP_SEC_VAR_NVM_CLEARED_8 #include "MemMap.h" #undef ECUM_MEMMAP_ERROR #undef ECUM_STOP_SEC_VAR_NVM_CLEARED_8 #endif #ifdef ECUM_START_SEC_VAR_NVM_CLEARED_32 #include "MemMap.h" #undef ECUM_MEMMAP_ERROR #undef ECUM_START_SEC_VAR_NVM_CLEARED_32 #endif #ifdef ECUM_STOP_SEC_VAR_NVM_CLEARED_32 #include "MemMap.h" #undef ECUM_MEMMAP_ERROR #undef ECUM_STOP_SEC_VAR_NVM_CLEARED_32 #endif #ifdef ECUM_START_SEC_VAR_NVM_CLEARED_UNSPECIFIED #include "MemMap.h" #undef ECUM_MEMMAP_ERROR #undef ECUM_START_SEC_VAR_NVM_CLEARED_UNSPECIFIED #endif #ifdef ECUM_STOP_SEC_VAR_NVM_CLEARED_UNSPECIFIED #include "MemMap.h" #undef ECUM_MEMMAP_ERROR #undef ECUM_STOP_SEC_VAR_NVM_CLEARED_UNSPECIFIED #endif #ifdef ECUM_START_SEC_VAR_CLEARED_COMNVM_UNSPECIFIED #include "MemMap.h" #undef ECUM_MEMMAP_ERROR #undef ECUM_START_SEC_VAR_CLEARED_COMNVM_UNSPECIFIED #endif #ifdef ECUM_STOP_SEC_VAR_CLEARED_COMNVM_UNSPECIFIED #include "MemMap.h" #undef ECUM_MEMMAP_ERROR #undef ECUM_STOP_SEC_VAR_CLEARED_COMNVM_UNSPECIFIED #endif /*lint -restore */
2301_81045437/classic-platform
system/EcuM/src/EcuM_BswMemMap.h
C
unknown
3,252
/*-------------------------------- 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_EcuM_02990*/ /* @req SWS_EcuMf_00028 Integration functions should be placed in callout functions. */ /* ----------------------------[includes]------------------------------------*/ //lint -emacro(9036,VALIDATE_STATE) #include "EcuM.h" #include "EcuM_Generated_Types.h" #if defined(USE_DET) #include "Det.h" #endif #if defined(USE_DEM) #include "Dem.h" #endif #if defined(USE_MCU) #include "Mcu.h" #endif #if defined(USE_GPT) #include "Gpt.h" #endif #if defined(USE_CAN) #include "Can.h" #endif #if defined(USE_FR) #include "Fr.h" #endif #if defined(USE_DIO) #include "Dio.h" #endif #if defined(USE_CANIF) #include "CanIf.h" #endif #if defined(USE_XCP) #include "Xcp.h" #endif #if defined(USE_PDUR) #include "PduR.h" #endif #if defined(USE_COM) #include "Com.h" #endif #if defined(USE_CANTP) #include "CanTp.h" #endif #if defined(USE_FRTP) #include "FrTp.h" #endif #if defined(USE_J1939TP) #include "J1939Tp.h" #endif #if defined(USE_TCPIP) #include "TcpIp.h" #endif #if defined(USE_SD) #include "SD.h" #endif #if defined(USE_SOAD) #include "SoAd.h" #endif #if defined(USE_DOIP) #include "DoIP.h" #endif #if defined(USE_LDCOM) #include "LdCom.h" #endif #if defined(USE_DCM) #include "Dcm.h" #endif #if defined(USE_PWM) #include "Pwm.h" #endif #if defined (USE_OCU) #include "Ocu.h" #endif #if defined (USE_ICU) #include "Icu.h" #endif #if defined(USE_IOHWAB) #include "IoHwAb.h" #endif #if defined(USE_FLS) #include "Fls.h" #endif #if defined(USE_EEP) #include "Eep.h" #endif #if defined(USE_FEE) #include "Fee.h" #endif #if defined(USE_EA) #include "Ea.h" #endif #if defined(USE_ETHIF) #include "EthIf.h" #endif #if defined(USE_ETH) #include "Eth.h" #endif #if defined(USE_NVM) #include "NvM.h" #endif #if defined(USE_COMM) #include "ComM.h" #endif #if defined(USE_NM) #include "Nm.h" #endif #if defined(USE_CANNM) #include "CanNm.h" #endif #if defined(USE_FRNM) #include "FrNm.h" #endif #if defined(USE_CANSM) #include "CanSM.h" #endif #if defined(USE_FRSM) #include "FrSM.h" #endif #if defined(USE_UDPNM) #include "UdpNm.h" #endif #if defined(USE_LINSM) #include "LinSM.h" #endif #if defined(USE_ETHIF) #include "EthIf.h" #endif #if defined(USE_ETHSM) #include "EthSM.h" #endif #if defined(USE_ETHTSYN) #include "EthTSyn.h" #endif #if defined(USE_STBM) #include "StbM.h" #endif #if defined(USE_SPI) #include "Spi.h" #endif #if defined(USE_WDG) #include "Wdg.h" #endif #if defined(USE_WDGM) #include "WdgM.h" #endif #if defined(USE_BSWM) #include "BswM.h" #endif #if defined(USE_STBM) #include "StbM.h" #endif #if defined(USE_DLT) #include "Dlt.h" #endif #if defined(USE_SOMEIPXF) #include "SomeIpXf.h" #endif #if defined(USE_E2EXF) #include "E2EXf.h" #endif #if defined(USE_SECOC) #include "SecOC.h" #endif #if defined(CFG_SHELL) #include "shell.h" #endif #if defined(CFG_T1_ENABLE) #include "Arc_T1_int.h" #endif #if defined(USE_FIM) #include "FiM.h" #endif #include "isr.h" /* Version check */ #if !(((ECUM_CALLOUT_SW_MAJOR_VERSION == 3) && (ECUM_CALLOUT_SW_MINOR_VERSION == 0)) ) #error EcuM: Configuration file expected EcuM Callout version to be 3.0.X* #endif /* ----------------------------[private define]------------------------------*/ /* Does not run functions that are not drivers. The rationale is to speed up * the initialization when the RAM is kept intact during sleep. This variable * should be updated in EcuM_CheckWakeup() when coming from sleep. */ #define NO_DRIVER(_func) \ if( (EcuM_DriverRestart==FALSE) ) { \ _func; \ } #if defined(USE_ECUM_FIXED) #define VALIDATE_STATE(_state) \ do { \ EcuM_StateType ecuMState; \ if (E_OK != EcuM_GetState(&ecuMState)) { \ ASSERT(0); \ } \ ASSERT(ecuMState == (_state) ); \ } while(0) #else #define VALIDATE_STATE(_state) #endif /* ----------------------------[private macro]-------------------------------*/ /* ----------------------------[private typedef]-----------------------------*/ /* ----------------------------[private function prototypes]-----------------*/ /* ----------------------------[private variables]---------------------------*/ /*lint -esym(9003, EcuM_DriverRestart) MISRA:OTHER:Readability:[MISRA 2012 Rule 8.9, advisory] */ /*lint -e843 MISRA:OTHER:Readability:[MISRA 2004 Info, advisory] */ static boolean EcuM_DriverRestart = FALSE; /* ----------------------------[private functions]---------------------------*/ /* ----------------------------[public functions]----------------------------*/ /** * Called if there is something very wrong. * * Checks for ECUM_E_RAM_CHECK_FAILED (bad hash at wakeup) or * ECUM_E_CONFIGURATION_DATA_INCONSISTENT (bad post-build data) * * This function should NEVER return * * @param reason */ void EcuM_ErrorHook(uint16 reason) { /* @req SWS_EcuM_02904*/ /* Go to defined state Reset, Fail-Safe etc. */ (void)reason; #if (MCU_PERFORM_RESET_API == STD_ON) Mcu_PerformReset(); #else ASSERT(0); #endif } /*lint -esym(9003, EcuMConfig) MISRA:OTHER:modeFunctionSwitchPointer is generated and can therefore not be defined in this static file:[MISRA 2012 Rule 8.9, advisory] */ extern const EcuM_ConfigType EcuMConfig; /*lint -esym(522, _dummy) MISRA:FALSE_POSITIVE:dummy is used to prevent other false positive:[MISRA 2012 Rule 2.2, required]*/ static void _dummy( void ) { } /* @req SWS_EcuM_02730 */ struct EcuM_ConfigS* EcuM_DeterminePbConfiguration(void) { NO_DRIVER(_dummy()); // Keep compiler silent /*lint -e{929} MISRA:STANDARDIZED_INTERFACE:Casting extern and const variable:[MISRA 2012 Rule 11.3, required] */ return (EcuM_ConfigType*)&EcuMConfig; /*lint !e9005 MISRA:STANDARDIZED_INTERFACE:Casting extern and const variable:[MISRA 2012 Rule 11.8, required] */ } #if defined(ECUM_BACKWARD_COMPATIBLE) /** * First callout from EcuM_Init(). May contain * all kind of initialization code. * * Got here by main()->EcuM_Init() * * Part of STARTUP I */ void EcuM_AL_DriverInitZero(void) { // VALIDATE_STATE( ECUM_STATE_STARTUP_ONE ); #if defined(CFG_T1_ENABLE) Arc_T1_Init(); #endif #if defined(USE_DET) Det_Init(); /* @req SWS_EcuM_02783 */ Det_Start(); /* @req SWS_EcuM_02634 */ #endif } /* @req SWS_BSW_00150 */ /** * Part of STARTUP I * * @param ConfigPtr * @req SWS_EcuM_02730 */ void EcuM_AL_DriverInitOne(const EcuM_ConfigType *ConfigPtr) { (void)ConfigPtr; /*lint !e920 MISRA:FALSE_POSITIVE:Allowed to cast pointer to void here:[MISRA 2012 Rule 1.3, required]*/ #if defined(USE_MCU) Mcu_Init(ConfigPtr->McuConfigPtr); /* Set up default clock (Mcu_InitClock requires initRun==1) */ /* Ignoring return value */ (void) Mcu_InitClock(ConfigPtr->McuConfigPtr->McuDefaultClockSettings); // Wait for PLL to sync. while (Mcu_GetPllStatus() != MCU_PLL_LOCKED) { ; } /* Ignoring return value. IMPROVEMENT Handle return value. */ (void) Mcu_DistributePllClock(); #endif #if defined(USE_DEM) // Preinitialize DEM NO_DRIVER(Dem_PreInit(ConfigPtr->DemConfigPtr)); #endif #if defined(USE_PORT) // Setup Port Port_Init(ConfigPtr->PortConfigPtr); #endif #if defined(USE_DIO) #if(DIO_AR_RELEASE_MAJOR_VERSION != 4) || (DIO_AR_RELEASE_MINOR_VERSION != 3) // Setup Dio Dio_Init(ConfigPtr->DioConfigPtr); #endif #endif #if defined(USE_GPT) // Setup the GPT Gpt_Init(ConfigPtr->GptConfigPtr); #endif // Setup watchdog #if defined(USE_WDG) Wdg_Init(ConfigPtr->WdgConfigPtr); #endif #if defined(USE_WDGM) NO_DRIVER(WdgM_Init(ConfigPtr->WdgMConfigPtr)); #endif #if defined(USE_DMA) // Setup DMA Dma_Init(ConfigPtr->DmaConfigPtr); #endif #if defined(USE_ADC) // Setup ADC Adc_Init(ConfigPtr->AdcConfigPtr); #endif #if defined(USE_BSWM) && (ECUM_ARC_SAFETY_PLATFORM == STD_ON) // Setup BSWM /* @req SWS_EcuMf_00016 */ BswM_Init(ConfigPtr->PostBuildConfig->BswMConfigPtr); #endif #if defined(USE_STBM) // Setup STBM StbM_Init(NULL_PTR); #endif // Setup PWM #if defined(USE_PWM) Pwm_Init(ConfigPtr->PwmConfigPtr); #endif // Setup ICU #if defined(USE_ICU) Icu_Init(ConfigPtr->IcuConfigPtr); #endif // Setup OCU #if defined(USE_OCU) Ocu_Init(ConfigPtr->OcuConfigPtr); #endif #if defined(CFG_SHELL) SHELL_Init(); #endif } #endif #if defined(USE_ECUM_FIXED) /** * At this point OS and essential drivers have started. * Start the rest of the drivers * * * Part of STARTUP II * * @param ConfigPtr */ /*lint -esym(522, EcuM_AL_DriverInitTwo) MISRA:FALSE_POSITIVE:Prevent false positive if none of the modules are used:[MISRA 2012 Rule 2.2, required]*/ void EcuM_AL_DriverInitTwo(const EcuM_ConfigType* ConfigPtr) { (void)ConfigPtr; /*lint !e920 MISRA:FALSE_POSITIVE:Allowed to cast pointer to void here:[MISRA 2012 Rule 1.3, required]*/ #if defined(USE_BSWM) && (ECUM_ARC_SAFETY_PLATFORM == STD_OFF) // Setup BSWM /* @req SWS_EcuMf_00016 */ BswM_Init(ConfigPtr->PostBuildConfig->BswMConfigPtr); #endif #if defined(USE_SPI) Spi_Init(ConfigPtr->SpiConfigPtr); // Setup SPI #endif #if defined(USE_EEP) NO_DRIVER(Eep_Init(ConfigPtr->EepConfigPtr)); // Setup EEP #endif #if defined(USE_FLS) NO_DRIVER(Fls_Init(ConfigPtr->FlsConfigPtr)); // Setup Flash #endif #if defined(USE_FEE) NO_DRIVER(Fee_Init()); // Setup FEE #endif #if defined(USE_EA) NO_DRIVER(Ea_Init()); // Setup EA #endif #if defined(USE_NVM) NO_DRIVER(NvM_Init()); // Setup NVRAM Manager and start the read all job NO_DRIVER(NvM_ReadAll()); #endif #if defined(USE_LIN) Lin_Init(ConfigPtr->LinConfigPtr); // Setup Lin driver #endif #if defined(USE_LINIF) NO_DRIVER(LinIf_Init(ConfigPtr->LinIfConfigPtr)); // Setup LinIf #endif #if defined(USE_LINTP) NO_DRIVER(LinTp_Init(ConfigPtr->LinTpConfigPtr)); // Setup LinTp #endif #if defined(USE_LINSM) NO_DRIVER(LinSM_Init(ConfigPtr->LinSMConfigPtr)); // Setup LinSM #endif #if defined(USE_CANTRCV) // Setup Can transceiver driver CanTrcv_Init(ConfigPtr->PostBuildConfig->CanTrcvConfigPtr); #endif #if defined(USE_CAN) Can_Init(ConfigPtr->PostBuildConfig->CanConfigPtr); // Setup Can driver #endif #if defined(USE_FR) NO_DRIVER(Fr_Init(ConfigPtr->FrConfigPtr)); // Setup Flexray CC driver #endif #if defined(USE_CANIF) NO_DRIVER(CanIf_Init(ConfigPtr->PostBuildConfig->CanIfConfigPtr)); // Setup CanIf #endif #if defined(USE_FRIF) NO_DRIVER(FrIf_Init(ConfigPtr->FrIfConfigPtr)); // Setup Flexray Interface #endif #if defined(USE_CANTP) NO_DRIVER(CanTp_Init(ConfigPtr->PostBuildConfig->CanTpConfigPtr)); // Setup CAN TP #endif #if defined(USE_FRTP) NO_DRIVER(FrTp_Init(ConfigPtr->FrTpConfigPtr)); // Setup Flexray TP #endif #if defined(USE_CANSM) NO_DRIVER(CanSM_Init(ConfigPtr->CanSMConfigPtr)); #endif #if defined(USE_FRSM) NO_DRIVER(FrSM_Init(ConfigPtr->FrSMConfigPtr)); // Setup Flexray SM #endif #if defined(USE_ETHIF) // Setup EthIf before Eth & EthTrcv NO_DRIVER(EthIf_Init(ConfigPtr->EthIfConfigPtr)); #endif #if defined(USE_ETHTRCV) NO_DRIVER(EthTrcv_Init(ConfigPtr->EthTrcvConfigPtr)); // Setup EthTrcv #endif #if defined(USE_ETH) Eth_Init(ConfigPtr->EthConfigPtr); // Setup Eth #endif #if defined(USE_ETHSM) NO_DRIVER(EthSM_Init()); // Setup Eth SM #endif #if defined(USE_TCPIP) NO_DRIVER(TcpIp_Init(ConfigPtr->TcpIpConfigPtr)); // Setup Tcp Ip #endif #if defined(USE_J1939TP) NO_DRIVER(J1939Tp_Init(ConfigPtr->J1939TpConfigPtr)); // Setup J1939Tp #endif #if defined(USE_SOAD) NO_DRIVER(SoAd_Init(ConfigPtr->SoAdConfigPtr)); // Setup Socket Adaptor #endif #if defined(USE_DOIP) NO_DRIVER(DoIP_Init(ConfigPtr->DoIPConfigPtr)); // Setup DoIP #endif #if defined(USE_SD) NO_DRIVER(Sd_Init(ConfigPtr->SdConfigPtr)); // Setup Service Discovery #endif #if defined(USE_LDCOM) NO_DRIVER(LdCom_Init(ConfigPtr->LdComConfigPtr)); // Setup Large Data Com #endif #if defined(USE_PDUR) NO_DRIVER(PduR_Init(ConfigPtr->PostBuildConfig->PduRConfigPtr)); // Setup PDU Router #endif #if defined(USE_OSEKNM) NO_DRIVER(OsekNm_Init(ConfigPtr->OsekNmConfigPtr)); // Setup Osek Network Manager #endif #if defined(USE_CANNM) NO_DRIVER(CanNm_Init(ConfigPtr->PostBuildConfig->CanNmConfigPtr)); // Setup Can Network Manager #endif #if defined(USE_FRNM) NO_DRIVER(FrNm_Init(ConfigPtr->FrNmConfigPtr)); // Setup Flexray Network Manager #endif #if defined(USE_UDPNM) NO_DRIVER(UdpNm_Init(ConfigPtr->UdpNmConfigPtr)); // Setup Udp Network Manager #endif #if defined(USE_NM) /* @req SWS_EcuMf_00022 The initialization process has to guarantee that NM is initialized */ /* @req SWS_EcuMf_00023 Initialization of NM is only allowed after the initialization of the respective bus interface. */ NO_DRIVER(Nm_Init()); // Setup Network Management Interface #endif #if defined(USE_COM) NO_DRIVER(Com_Init(ConfigPtr->PostBuildConfig->ComConfigPtr)); // Setup COM layer #endif #if defined(USE_DCM) NO_DRIVER(Dcm_Init(ConfigPtr->DcmConfigPtr)); // Setup DCM #endif #if defined(USE_IOHWAB) NO_DRIVER(IoHwAb_Init()); // Setup IO hardware abstraction layer #endif #if defined(USE_XCP) NO_DRIVER(Xcp_Init(ConfigPtr->XcpConfigPtr)); // Setup XCP #endif #if defined(USE_ETHTSYN) // Setup EthTSyn NO_DRIVER(EthTSyn_Init(ConfigPtr->EthTSynConfigPtr)); #endif #if defined(USE_STBM) // Setup StbM NO_DRIVER(StbM_Init(ConfigPtr->StbMConfigPtr)); #endif } /** * Part of STARTUP II * * @param ConfigPtr */ void EcuM_AL_DriverInitThree(const EcuM_ConfigType* ConfigPtr) { (void)ConfigPtr; /*lint !e920 MISRA:FALSE_POSITIVE:Allowed to cast pointer to void here:[MISRA 2012 Rule 1.3, required]*/ #if defined(USE_FIM) // Setup Function Inhibition Manager #if (FIM_POSTBUILD_MODE == STD_ON) FiM_Init(ConfigPtr->PostBuildConfig->FiMConfigPtr); #else FiM_Init(ConfigPtr->FiMConfigPtr); #endif #endif #if defined(USE_DEM) // Setup DEM NO_DRIVER(Dem_Init()); #endif #if defined(USE_DLT) NO_DRIVER(Dlt_Init(ConfigPtr->DltConfigPtr)); /* Needs to be done after nvram has been initialised */ #endif #if defined(USE_COMM) // Setup Communication Manager NO_DRIVER(ComM_Init(ConfigPtr->PostBuildConfig->ComMConfigPtr)); #endif #if defined(USE_SOMEIPXF) // Setup SomeIp Transformer NO_DRIVER(SomeIpXf_Init(NULL)); #endif #if defined(USE_E2EXF) // Setup E2E Transformer NO_DRIVER(E2EXf_Init(NULL)); #endif #if defined (USE_SECOC) NO_DRIVER(SecOC_Init(ConfigPtr->SecOCConfigPtr)); #endif } void EcuM_OnEnterRun(void) { } void EcuM_OnExitRun(void) { } void EcuM_OnExitPostRun(void) { } void EcuM_OnPrepShutdown(void) { } void EcuM_OnGoSleep(void) { } #endif // ECUM_FIXED void EcuM_OnGoOffOne(void) { } void EcuM_OnGoOffTwo(void) { } void EcuM_LoopDetection(void) { //IMPROVEMENT: How is reset loop detection implemented? } /** * This function should be the last this called before reset. * Normally this manipulates some pin that controls DC to power off * the board (ie it will never get to Mcu_PerformReset()) */ void EcuM_AL_SwitchOff(void) { /* ADD CODE BELOW */ } void EcuM_AL_Reset(EcuM_ResetType reset) { // IMPROVEMENT: Perform reset based on the reset parameter (void)reset; } /** * * Called to check other wakeup sources. Assume for example that * we want to check something else than the actual wakeup pin. * * Can be called from interrupt context. * @param wakeupSource */ void EcuM_CheckWakeup(EcuM_WakeupSourceType source) { (void)source; /* added for lint exception*/ /* ADD CODE BELOW */ } /** * Enable wakeup sources that should wake us. This is when going to sleep. * * This function is called once for each wakeup source.(ie source * can only have one bit set at any time). See ECUM2389 for example. * * @param source */ void EcuM_EnableWakeupSources( EcuM_WakeupSourceType source ) { (void)source; /* Added for lint exception*/ /* ADD CODE BELOW */ } /** * * @param wakeupSource */ void EcuM_DisableWakeupSources(EcuM_WakeupSourceType wakeupSource) { (void)wakeupSource; /* Added for lint exception*/ /* ADD CODE BELOW */ } /** * Start wakeup sources that need validation. * * 1. For wakeup sources that don't need validation nothing needs to be done. * 2. For wakeup sources that may have false wakeup, start then up, e.g. CanIf * * Called once when entering ECUM_STATE_WAKEUP_VALIDATION state * * @param wakeupSource */ void EcuM_StartWakeupSources(EcuM_WakeupSourceType wakeupSource) { VALIDATE_STATE( ECUM_STATE_WAKEUP_VALIDATION ); (void)wakeupSource; /* Added for lint exception*/ /* ADD CODE BELOW */ } /** * Stop not validated events * * @param wakeupSource */ void EcuM_StopWakeupSources(EcuM_WakeupSourceType wakeupSource) { VALIDATE_STATE( ECUM_STATE_WAKEUP_VALIDATION); (void)wakeupSource; } /** * * @param wakeupSource */ void EcuM_CheckValidation(EcuM_WakeupSourceType wakeupSource) { VALIDATE_STATE( ECUM_STATE_WAKEUP_VALIDATION); /* ADD CODE BELOW */ (void) wakeupSource; } /** * Restart drivers. Have no restart list, instead the * drivers restarted are drivers that have had it's hardware * registers reset. If memory is also lost (=all memory is not * powered during sleep), this strategy does not work. * * This calls: * - EcuM_AL_DriverInitOne() * - EcuM_AL_DriverInitTwo() * */ #if (defined(ECUM_BACKWARD_COMPATIBLE) && (ECUM_ARC_SAFETY_PLATFORM == STD_OFF)) void EcuM_AL_DriverRestart(const struct EcuM_ConfigS* ConfigPtr) { const EcuM_ConfigType* config; (void) *ConfigPtr; VALIDATE_STATE( ECUM_STATE_WAKEUP_ONE); config = EcuM_DeterminePbConfiguration(); /* Start all drivers for now */ EcuM_AL_DriverInitOne(config); /* Setup the systick interrupt */ #if defined(USE_MCU) { #if defined(CFG_OS_SYSTICK2) Os_SysTickStart2(OsTickFreq); #else Os_SysTickStart(Mcu_Arc_GetSystemClock() / (uint32_t)OsTickFreq); #endif } #endif #if defined(USE_ECUM_FIXED) EcuM_AL_DriverInitTwo(config); #endif } #endif /** * Called once validation is done and a may change the wakeup at a very * late stage. * * For example if a wakeup event have been verified (=ECUM_WKACT_RUN) but here * a switch or something indicating immediate shutdown the reaction * can be changed here from ECUM_WKACT_RUN to ECUM_WKACT_SHUTDOWN. * This makes would make EcuM to go to * ECUM_STATE_PREP_SHUTDOWN(ECUM_STATE_WAKEUP_WAKESLEEP) instead of * ECUM_STATE_WAKEUP_TWO * * @param wact * @return */ EcuM_WakeupReactionType EcuM_OnWakeupReaction( EcuM_WakeupReactionType wact ) { VALIDATE_STATE( ECUM_STATE_WAKEUP_REACTION ); /* ADD CODE BELOW */ return wact; } /** * Generate RAM hash. * We are in ECUM_STATE_SLEEP here. * */ void EcuM_GenerateRamHash(void) { /* De-init drivers. * There is really no suiteable place to do this but here */ VALIDATE_STATE( ECUM_STATE_SLEEP ); #if defined(USE_GPT) && (GPT_DEINIT_API == STD_ON) Gpt_DeInit(); #endif #if defined(USE_ADC) && (ADC_DEINIT_API == STD_ON) Adc_DeInit(); #endif #if defined(USE_PWM) && (PWM_DE_INIT_API == STD_ON) Pwm_DeInit(); #endif #if defined(USE_SPI) (void)Spi_DeInit(); #endif } /** * Check RAM hash. * We are still in ECUM_STATE_SLEEP here. * * @return */ uint8 EcuM_CheckRamHash( void ) { VALIDATE_STATE( ECUM_STATE_SLEEP ); /* ADD CODE BELOW */ return 0; } /** * This callout is invoked periodically in all reduced clock sleep modes. * It is explicitely allowed to poll wakeup sources from this callout and to call wakeup * notification functions to indicate the end of the sleep state to the ECU State Manager. */ void EcuM_SleepActivity(void) { /* * Note: If called from the Poll sequence the EcuMcalls this callout functions in a * blocking loop at maximum frequency. The callout implementation must ensure by * other means if callout code shall be executed with a lower period. The integrator may * choose any method to control this, e.g. with the help of OS counters, OS alarms, * or Gpt timers */ /* ADD CODE BELOW */ } /** * This ARC definition is called when mcu definition of enum Mcu_ResetType has additional enum values than standard Autosar definition. * Integrator has to map the additional enum value with the appropriate wakeup source and provide code for remembering the reset reason here by calling * EcuM_ValidateWakeupEvent(wakeup source) as per requirement SWS_EcuM_02623 . * * @param resetReason * * */ void EcuM_Arc_RememberWakeupEvent(uint32 resetReason) { switch (resetReason) { /*lint -e764 MISRA:PERFORMANCE:omitting any case:[MISRA 2012 Rule 16.6, required] */ // Handling of additional user defined wakeup sources can be added here default: EcuM_ValidateWakeupEvent(ECUM_WKSOURCE_RESET); /* @req SWS_EcuM_02601 ECUM_WKSOURCE_RESET shall be reported if no specific wk source detected */ break; } } #if defined(CFG_ARC_ECUM_NVM_READ_INIT) /** * Used to quickly let the fee / ea module read the admin block to enter idle state. * * Is enabled by setting "CFG += ARC_ECUM_NVM_READ_INIT" in proj build_config.mk. * @param tickTimerStart * @param EcuMNvramReadAllTimeout */ void EcuM_Arc_InitFeeReadAdminBlock(TickType tickTimerStart, uint32 EcuMNvramReadAllTimeout) { MemIf_StatusType status = MEMIF_IDLE; TickType tickTimerElapsed; TickType curr; /* Let it execute until it's done with reading all admin blocks */ do { curr = GetOsTick(); tickTimerElapsed = OS_TICKS2MS_OS_TICK(curr - tickTimerStart); #if defined(USE_FEE) Fee_MainFunction(); #endif #if defined(USE_FLS) Fls_MainFunction(); #endif #if defined(USE_FEE) status = Fee_GetStatus(); #endif } while ( (MEMIF_BUSY_INTERNAL == status) && (tickTimerElapsed < EcuMNvramReadAllTimeout)); } /** * Calls the memory main functions to quickly finish the NvM_ReadAll job. */ void EcuM_Arc_InitMemReadAllMains(void) { #if defined(USE_NVM) NvM_MainFunction(); #endif #if defined(USE_FEE) Fee_MainFunction(); #endif #if defined(USE_FLS) Fls_MainFunction(); #endif #if defined(USE_EA) Ea_MainFunction(); #endif #if defined(USE_EEP) Eep_MainFunction(); #if defined(USE_SPI) && (SPI_LEVEL_DELIVERED == SPI_LEVEL_2) Spi_MainFunction_Handling(); #endif #endif } #endif
2301_81045437/classic-platform
system/EcuM/src/EcuM_Callout_Stubs.c
C
unknown
24,156
/*-------------------------------- 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 */ /** @fileSafetyClassification ASIL **/ /* Some functions in this file is used by ASIL and QM Ecu managment */ #include "Std_Types.h" #include "EcuM.h" #include <string.h> #include <Os.h> #include "EcuM_Generated_Types.h" #include "EcuM_Internals.h" #include "EcuM_Cbk.h" #include "SchM_EcuM.h" /*lint -e451 MISRA:EXTERNAL_FILE:file inclusion:[MISRA 2012 Directive 4.10, required] */ #include "MemMap.h" #include "Mcu.h" #include "ComStack_Types.h" #if defined(USE_DET) #include "Det.h" #endif #if defined(USE_DEM) #include "Dem.h" /* @req SWS_EcuM_02875 */ #endif #include "isr.h" #if defined(USE_NVM) #include "NvM.h" #endif #if defined(USE_RTE) #include "Rte_Main.h" #endif #if defined(USE_SCHM) #include "SchM.h" #endif /* @req SWS_EcuM_02757 The ECU Manager shall treat all errors immediately as errors. */ //#define USE_LDEBUG_PRINTF #include "debug.h" #if (ECUM_ARC_SAFETY_PLATFORM == STD_OFF) /** @CODECOV:NOT_SUPPORTED:SafetyPlatform has its own partitioned ECUM main functions **/ __CODE_COVERAGE_OFF__ /** EcuM_StartupTwo * NOTE: This is the normal StartupTwo function for EcuM Fixed. It is not used in safety platform. * The order defined here is found in SWS_EcuM_02411 */ void EcuM_StartupTwo(void) { if (EcuM_World.current_state == ECUM_STATE_STARTUP_ONE) { SetCurrentState(ECUM_STATE_STARTUP_TWO); #if defined(USE_SCHM) /* Initialize the BSW scheduler */ SchM_Init(); #endif } if (EcuM_World.current_state == ECUM_STATE_STARTUP_TWO) { EcuM_AL_DriverInitTwo(EcuM_World.config); #if defined(USE_NVM) // Start timer to wait for NVM job to complete TickType tickTimerStart = GetOsTick(); #endif #if defined(USE_RTE) // Prepare the system to startup RTE (void)Rte_Start(); #endif #if defined(USE_NVM) /* Wait for the NVM job (NvM_ReadAll) to terminate. This assumes that: * - A task runs the memory MainFunctions, e.g. Ea_MainFunction(), Eep_MainFunction() * are run in a higher priority task that the task that executes this code. */ #if defined(CFG_ARC_ECUM_NVM_READ_INIT) && defined(USE_FEE) EcuM_Arc_InitFeeReadAdminBlock(tickTimerStart, EcuM_World.config->EcuMNvramReadAllTimeout); #endif TickType tickTimerElapsed; static NvM_RequestResultType readAllResult; Std_ReturnType status; do { /* Read the multiblock status */ status = NvM_GetErrorStatus(0, &readAllResult); tickTimerElapsed = OS_TICKS2MS_OS_TICK(GetOsTick() - tickTimerStart); #if defined(CFG_ARC_ECUM_NVM_READ_INIT) EcuM_Arc_InitMemReadAllMains(); #endif /* The timeout EcuMNvramReadAllTimeout is in ms */ } while( (readAllResult == NVM_REQ_PENDING) && (tickTimerElapsed < EcuM_World.config->EcuMNvramReadAllTimeout) ); if(status!=E_OK) { ECUM_DET_REPORT_ERROR(ECUM_STARTUPTWO_ID, ECUM_E_ARC_TIMERERROR); } #endif /* USE_NVM */ // Initialize drivers that need NVRAM data EcuM_AL_DriverInitThree(EcuM_World.config); } // IMPROVEMENT: Indicate mode change to RTE /* IMPROVEMENT: If one of the wake up sources listed in 7.8.7 Wake up Sources and Reset Reason is set, then * exection shall continue with RUN state. In all other cases, execution shall continue with * WAKEUP VALIDATION state. * */ EcuM_enter_run_mode(); } #endif /*ECUM_ARC_SAFETY_PLATFORM == STD_OFF*/ __CODE_COVERAGE_ON__ /* Note: This is a generic public function for EcuM used both in normal EcuM Fixed and in Safety platform */ /* @req SWS_EcuM_00423 */ Std_ReturnType EcuM_GetState(EcuM_StateType* state) { /* 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 */ VALIDATE_RV(EcuM_World.initiated, ECUM_GETSTATE_ID, ECUM_E_UNINIT, E_NOT_OK);VALIDATE_RV(state != NULL, ECUM_GETSTATE_ID, ECUM_E_NULL_POINTER, E_NOT_OK); *state = EcuM_World.current_state; return E_OK; } /* Note: This is a generic public function for EcuM used both in normal EcuM Fixed and in Safety platform */ Std_ReturnType EcuM_RequestRUN(EcuM_UserType user) { /* 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 */ VALIDATE_RV(EcuM_World.initiated, ECUM_REQUESTRUN_ID, ECUM_E_UNINIT, E_NOT_OK); VALIDATE_RV(user < ECUM_USER_ENDMARK, ECUM_REQUESTRUN_ID, ECUM_E_INVALID_PAR, E_NOT_OK); //lint !e638 !e641 Ok. Data is validated // LDEBUG_PRINTF("EcuM_RequestRUN(): User %d\n",user); if( FALSE == EcuM_World.killAllRequest ) { EcuM_World.run_requests |= (uint32) 1 << user; } /* @req SWS_EcuM_00144 */ return E_OK; } /* Note: This is a generic public function for EcuM used both in normal EcuM Fixed and in Safety platform */ Std_ReturnType EcuM_ReleaseRUN(EcuM_UserType user) { /* 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 */ VALIDATE_RV(EcuM_World.initiated, ECUM_RELEASERUN_ID, ECUM_E_UNINIT, E_NOT_OK); VALIDATE_RV(user < ECUM_USER_ENDMARK, ECUM_RELEASERUN_ID, ECUM_E_INVALID_PAR, E_NOT_OK); //lint !e638 !e641 Ok. Data is validated /* @req SWS_EcuM_00144 */ #if defined(DEBUG_RELEASE_RUN) LDEBUG_PRINTF("EcuM_ReleaseRUN(): User %d\n",user); #endif EcuM_World.run_requests &= ~((uint32) 1 << user); return E_OK; } #if (ECUM_ARC_SAFETY_PLATFORM == STD_OFF) /** * Kill all RUN requests and perform shutdown without waiting for application * to finish * Note: EcuM_KillAllRUNRequest currently not supported in Safety platform. Only used in normal EcuM Fixed. * */ void EcuM_KillAllRUNRequests(void) { /* @req SWS_EcuM_00872 */ /* @req SWS_EcuM_00600 */ /* @req SWS_EcuM_00668 */ EcuM_World.killAllRequest = TRUE; EcuM_World.run_requests = 0; #if defined(USE_COMM) EcuM_World_ComM_NVM.run_comm_requests = 0; #endif #if defined(USE_DEM) Dem_ReportErrorStatus(EcuM_World.config->EcuMDemAllRunRequestsKilledEventId , DEM_EVENT_STATUS_FAILED ); #endif } #endif /* Note: This is a generic public function for EcuM used both in normal EcuM Fixed and in Safety platform */ void EcuM_KillAllPostRUNRequests(void) { EcuM_World.killAllPostrunRequest = TRUE; /* @req SWS_EcuMf_00102 */ /* @req SWS_EcuMf_00103 */ EcuM_World.postrun_requests = 0; } /* Note: This is a generic public function for EcuM used both in normal EcuM Fixed and in Safety platform */ Std_ReturnType EcuM_RequestPOST_RUN(EcuM_UserType user) { /* 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 */ VALIDATE_RV(EcuM_World.initiated, ECUM_REQUESTPOSTRUN_ID, ECUM_E_UNINIT, E_NOT_OK); VALIDATE_RV(user < ECUM_USER_ENDMARK, ECUM_REQUESTPOSTRUN_ID, ECUM_E_INVALID_PAR, E_NOT_OK); //lint !e638 !e641 Ok. Data is validated /* @req SWS_EcuMf_00103 */ if( FALSE == EcuM_World.killAllPostrunRequest ) { EcuM_World.postrun_requests |= (uint32) 1 << user; } return E_OK; } /* Note: This is a generic public function for EcuM used both in normal EcuM Fixed and in Safety platform */ Std_ReturnType EcuM_ReleasePOST_RUN(EcuM_UserType user) { /* 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 */ VALIDATE_RV(EcuM_World.initiated, ECUM_RELEASEPOSTRUN_ID, ECUM_E_UNINIT, E_NOT_OK); VALIDATE_RV(user < ECUM_USER_ENDMARK, ECUM_RELEASEPOSTRUN_ID, ECUM_E_INVALID_PAR, E_NOT_OK); //lint !e638 !e641 Ok. Data is validated EcuM_World.postrun_requests &= ~((uint32) 1 << user); return E_OK; } /* Note: This is a generic public function for EcuM used both in normal EcuM Fixed and in Safety platform */ EcuM_WakeupStatusType EcuM_GetStatusOfWakeupSource( EcuM_WakeupSourceType sources ) { /* @req SWS_EcuM_00754 */ EcuM_WakeupStatusType status = ECUM_WKSTATUS_NONE; if ((EcuM_GetValidatedWakeupEvents() & sources) != 0) { status = ECUM_WKSTATUS_VALIDATED; } else if ((EcuM_GetPendingWakeupEvents() & sources) != 0) { status = ECUM_WKSTATUS_PENDING; } else { status = ECUM_WKSTATUS_NONE; } return status; }
2301_81045437/classic-platform
system/EcuM/src/EcuM_Fixed.c
C
unknown
9,689
/*-------------------------------- 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 */ /** @fileSafetyClassification QM **/ /* EcuM flexible not supported for safety platform */ #include "Std_Types.h" #include "EcuM.h" #include "EcuM_Generated_Types.h" #include "EcuM_Internals.h" #include "EcuM_Cbk.h" #if defined(USE_BSWM) #include "BswM_EcuM.h" #endif /* ----------------------------[private define]------------------------------*/ /* ----------------------------[private macro]-------------------------------*/ #if !defined(USE_BSWM) #define BswM_EcuM_CurrentWakeup(source, state) #endif /* ----------------------------[private typedef]-----------------------------*/ /* ----------------------------[private function prototypes]-----------------*/ /* ----------------------------[private variables]---------------------------*/ /* ----------------------------[private functions]---------------------------*/ /* @req SWS_EcuM_02951 */ /* @req SWS_EcuM_04023 */ /* !req SWS_EcuM_03010 */ static void goSleepSequence(void) { uint32 cMask; uint8 source; const EcuM_SleepModeType *sleepModePtr; /* Get the current sleep mode */ sleepModePtr = &EcuM_World.config->EcuMSleepModeConfig[EcuM_World.sleep_mode]; cMask = sleepModePtr->EcuMWakeupSourceMask; /* Loop over the WKSOURCE for this sleep mode */ for (;(0 != cMask); cMask &= ~(1uL << source)) { /*lint -e{9033} MISRA:STANDARDIZED_INTERFACE:cast of composite expression Reason:[MISRA 2012 Rule 10.8, required] */ source = (uint8)(ilog2(cMask)); /*lint -e{9031} MISRA:STANDARDIZED_INTERFACE:Composite expression assigned to a wider essential type:[MISRA 2012 Rule 10.6, required] */ EcuM_EnableWakeupSources(1u << source); #if defined(USE_BSWM) BswM_EcuM_CurrentWakeup((EcuM_WakeupSourceType)source, ECUM_WKSTATUS_NONE); #endif } (void)GetResource(RES_SCHEDULER); } /* @req SWS_EcuM_02960 */ static void haltSequence(void) { const EcuM_SleepModeType *sleepModePtr; /* @req SWS_EcuM_02961 */ /* !req SWS_EcuM_02799 */ EcuM_GenerateRamHash(); sleepModePtr = &EcuM_World.config->EcuMSleepModeConfig[EcuM_World.sleep_mode]; Mcu_SetMode(sleepModePtr->EcuMSleepModeMcuMode); /* @req SWS_EcuM_04033 */ if (EcuM_CheckRamHash() == 0) { #if defined(USE_DEM) EcuM_ErrorHook(EcuM_World.config->EcuMDemRamCheckFailedEventId); #endif } } /* @req SWS_EcuM_04026 */ static void wakeupRestartSequence(void) { EcuM_WakeupSourceType wMask = 0; Mcu_SetMode(EcuM_World.config->EcuMNormalMcuMode); wMask = EcuM_GetPendingWakeupEvents();/*lint !e838 MISRA:STANDARDIZED_INTERFACE:Assigning 0 as default value for wMask:[MISRA 2004 Info, required]*/ EcuM_DisableWakeupSources(wMask); EcuM_AL_DriverRestart(EcuM_World.config); (void)ReleaseResource(RES_SCHEDULER); } #if (ECUM_DEFENSIVE_BEHAVIOR == STD_ON) static boolean isCallerAllowed(uint16 caller) { boolean status; status = FALSE; for (uint16 i = 0; i < ECUM_GO_DOWN_ALLOWED_USERS_CNT; i++) { if (EcuM_World.config->EcuMGoDownAllowedUsersConfig[i] == caller) { status = TRUE; break; } } return status; } #endif /* ----------------------------[public functions]----------------------------*/ /* @req SWS_EcuM_02932 */ /* @req SWS_EcuM_04016 */ /* This function is always called after init*/ void EcuM_StartupTwo(void) { #if defined(USE_SCHM) SchM_Init(); #endif #if defined(USE_BSWM) BswM_Init(EcuM_World.config->PostBuildConfig->BswMConfigPtr); #endif } /* @req SWS_EcuM_04050 */ Std_ReturnType EcuM_SelectShutdownCause(EcuM_ShutdownCauseType shutdownCause) { /* 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 */ VALIDATE_RV(EcuM_World.initiated, ECUM_SELECTSHUTDOWNCAUSE_ID, ECUM_E_UNINIT, E_NOT_OK); EcuM_World.shutdown_cause = shutdownCause; return E_OK ; } /* @req SWS_EcuM_04051 */ Std_ReturnType EcuM_GetShutdownCause(EcuM_ShutdownCauseType *shutdownCause) { /* 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 */ VALIDATE_RV(EcuM_World.initiated, ECUM_GETSHUTDOWNCAUSE_ID, ECUM_E_UNINIT, E_NOT_OK); *shutdownCause = EcuM_World.shutdown_cause; return E_OK ; } /* @req SWS_EcuM_04046 */ /* @req SWS_EcuM_03022 */ /* @req SWS_EcuM_03021 */ /* !req SWS_EcuM_04008 */ /* @req SWS_EcuM_04019 */ Std_ReturnType EcuM_GoDown(uint16 caller) { /* 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 */ VALIDATE_RV(EcuM_World.initiated, ECUM_GODOWN_ID, ECUM_E_UNINIT, E_NOT_OK); EcuM_WakeupSourceType wakeupEvents; Std_ReturnType rv; rv = E_OK; #if (ECUM_DEFENSIVE_BEHAVIOR == STD_ON) if (FALSE == isCallerAllowed(caller)) { #if defined(USE_DEM) //IMPROVEMENT: Report ECUM_E_IMPROPER_CALLER to DEM when we have the 4.1 config #endif rv = E_NOT_OK; } #else (void)caller; #endif /*lint -e{774} MISRA:FALSE_POSITIVE:if also evaluates to false based on ECUM_DEFENSIVE_BEHAVIOR is STD_OFF:[MISRA 2012 Rule 14.3, required]*/ if (rv == E_OK ) { #if defined(USE_BSWM) /* @req SWS_EcuMf_00017 */ BswM_Deinit(); #endif #if defined(USE_SCHM) SchM_Deinit(); #endif wakeupEvents = EcuM_GetPendingWakeupEvents(); if (wakeupEvents != 0) { rv = EcuM_SelectShutdownTarget(ECUM_STATE_RESET, 0); } /* @req SWS_EcuM_02952 */ ShutdownOS(E_OK); } return rv; } /* @req SWS_EcuM_04048 */ Std_ReturnType EcuM_GoHalt(void) { /* 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 */ VALIDATE_RV(EcuM_World.initiated, ECUM_GOHALT_ID, ECUM_E_UNINIT, E_NOT_OK); goSleepSequence(); /* @req SWS_EcuM_04024 */ haltSequence(); /* @req SWS_EcuM_04001 */ /* @req SWS_EcuM_02963 */ wakeupRestartSequence(); return E_OK ; } /* !req SWS_EcuM_04011 */ void EcuM_MainFunction(void) { static uint32 pendingWkupMask = 0; static boolean validationOngoing = FALSE; static uint32 validationMaxTime = 0; if (FALSE == validationOngoing) { pendingWkupMask = EcuM_GetPendingWakeupEvents(); EcuM_StartWakeupSources(pendingWkupMask); EcuM_World.validationTimer = 0; /* Calculate the validation timing , if any*/ /* @req SWS_EcuM_02479 */ const EcuM_WakeupSourceConfigType *wkupCfgPtr; /* @req SWS_EcuM_02566 */ for (uint32 i = 0; i < ECUM_WKSOURCE_USER_CNT; i++) { wkupCfgPtr = &EcuM_World.config->EcuMWakeupSourceConfig[i]; /* Can't validate something that is not pending */ if (0 != (pendingWkupMask & wkupCfgPtr->EcuMWakeupSourceId)) { /* No validation timeout == ECUM_VALIDATION_TIMEOUT_ILL */ if (wkupCfgPtr->EcuMValidationTimeout != ECUM_VALIDATION_TIMEOUT_ILL) { /* Use one validation timeout, take the longest */ validationMaxTime = MAX( wkupCfgPtr->EcuMValidationTimeout / ECUM_MAIN_FUNCTION_PERIOD, validationMaxTime); EcuM_World.validationTimer = validationMaxTime; } else { /* Validate right away */ /* @req SWS_EcuM_02976 */ /* @req SWS_EcuM_02539*/ EcuM_ValidateWakeupEvent(wkupCfgPtr->EcuMWakeupSourceId); } } } validationOngoing = TRUE; } if (EcuM_World.validationTimer != 0) { /* * Call EcuM_CheckValidation() while all events have not been validated and * timeout have not expired. The call to EcuM_CheckValidation(..) triggers a call * to EcuM_ValidateWakeupEvent(..) from the driver when validated. */ /* Check validation for the events that do not match, ie not yet validated */ EcuM_CheckValidation(EcuM_GetValidatedWakeupEvents() ^ pendingWkupMask); if (0 == (EcuM_GetValidatedWakeupEvents() ^ pendingWkupMask)) { /* All events have been validated */ validationOngoing = FALSE; } } else { uint32 notValidatedMask = EcuM_GetValidatedWakeupEvents() ^ pendingWkupMask; /* Stop wakeupSources that are not validated */ if (0 != notValidatedMask) { EcuM_StopWakeupSources(notValidatedMask); /* @req SWS_EcuM_04081 */ /* @req SWS_EcuM_04082 */ #if defined(USE_BSWM) BswM_EcuM_CurrentWakeup((EcuM_WakeupSourceType)notValidatedMask, ECUM_WKSTATUS_EXPIRED); #endif } validationOngoing = FALSE; } if (0 != EcuM_World.validationTimer) { EcuM_World.validationTimer--; } }
2301_81045437/classic-platform
system/EcuM/src/EcuM_Flexible.c
C
unknown
10,225
/*-------------------------------- 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 _ECUM_GENERATED_TYPES_H_ #define _ECUM_GENERATED_TYPES_H_ #if !(((ECUM_SW_MAJOR_VERSION == 3) && (ECUM_SW_MINOR_VERSION == 1)) ) #error EcuM: Configuration file expected BSW module version to be 3.1.\* #endif #include "PreCompiledDataHash.h" /* @req SWS_EcuM_02992 */ /*The implementation of the ECU State Manager Fixed module shall provide one file EcuM_Generated_Types.h containing generated types and fulfilling the forward declarations from EcuM.h.*/ #include "EcuM_Types.h" #if defined(USE_HTMSS) #include "Htmss.h" #endif #if defined(USE_MCU) #include "Mcu.h" #endif #if defined(USE_PORT) #include "Port.h" #endif #if defined(USE_CAN) #include "Can.h" #endif #if defined(USE_CANTRCV) #include "CanTrcv.h" #endif #if defined(USE_DIO) #include "Dio.h" #endif #if defined(USE_LIN) #include "Lin.h" #endif #if defined(USE_CANIF) #include "CanIf.h" #endif #if defined(USE_LINIF) #include "LinIf.h" #endif #if defined(USE_LINTP) #include "LinTp.h" #endif #if defined(USE_PWM) #include "Pwm.h" #endif #if defined (USE_OCU) #include "Ocu.h" #endif #if defined (USE_ICU) #include "Icu.h" #endif #if defined(USE_COM) #include "Com.h" #endif #if defined(USE_PDUR) #include "PduR.h" #endif #if defined(USE_DMA) #include "Dma.h" #endif #if defined(USE_ADC) #include "Adc.h" #endif #if defined(USE_GPT) #include "Gpt.h" #endif #if defined(USE_COMM) #include "ComM.h" #endif #if defined(USE_SECOC) #include "SecOC.h" #endif #if defined(USE_NM) #include "Nm.h" #endif #if defined(USE_CANNM) #include "CanNm.h" #endif #if defined(USE_CANSM) #include "CanSM.h" #endif #if defined(USE_LINSM) #include "LinSM.h" #endif #if defined(USE_J1939TP) #include "J1939Tp.h" #endif #if defined(USE_TCPIP) #include "TcpIp.h" #endif #if defined(USE_SD) #include "SD.h" #endif #if defined(USE_SOAD) #include "SoAd.h" #endif #if defined(USE_DOIP) #include "DoIP.h" #endif #if defined(USE_LDCOM) #include "LdCom.h" #endif #if defined(USE_UDPNM) #include "UdpNm.h" #endif #if defined(USE_FLS) #include "Fls.h" #endif #if defined(USE_FEE) #include "Fee.h" #endif #if defined(USE_EEP) #include "Eep.h" #endif #if defined(USE_SPI) #include "Spi.h" #endif #if defined(USE_WDG) #include "Wdg.h" #endif #if defined(USE_WDGM) #include "WdgM.h" #endif #if defined(USE_WDGIF) #include "WdgIf.h" #endif #if defined(USE_STBM) #include "StbM.h" #endif #if defined(USE_ETHTSYN) #include "EthTSyn.h" #endif #if defined(USE_ETHSM) #include "EthSM.h" #endif #if defined(USE_ETHTRCV) #include "EthTrcv.h" #endif #if defined(USE_ETHIF) #include "EthIf.h" #endif #if defined(USE_ETH) #include "Eth.h" #endif #if defined(USE_FR) #include "Fr.h" #endif #if defined(USE_BSWM) #include "BswM.h" #endif #if defined(USE_FIM) #include "FiM.h" #endif #if defined(USE_BSWM) || defined(USE_PDUR) || defined(USE_COM) || defined(USE_CANIF) || defined(USE_CANTP) || defined (USE_CANNM) || defined (USE_COMM) || defined (USE_CAN) || (defined(USE_FIM) && (FIM_POSTBUILD_MODE == STD_ON)) #include "EcuM_PBTypes.h" #endif #if defined(USE_DCM) #include "Dcm.h" #endif #if defined(USE_DEM) #include "Dem.h" #endif #if defined(USE_XCP) #include "Xcp.h" #endif #if defined(USE_IPDUM) #include "IpduM.h" #endif #if defined(USE_DLT) #include "Dlt.h" #endif #if defined(USE_FR) #include "Fr.h" #endif #if defined(USE_FRIF) #include "FrIf.h" #endif #if defined(USE_FRNM) #include "FrNm.h" #endif #if defined(USE_FRSM) #include "FrSM.h" #endif #if defined(USE_FRTP) #include "FrTp.h" #endif #if defined(USE_SOMEIPXF) #include "SomeIpXf.h" #endif #if defined(USE_E2EXF) #include "E2EXf.h" #endif #if defined(USE_OSEKNM) #include "OsekNm.h" #endif #if defined(USE_IOHWAB) #include "IoHwAb.h" #endif /* @req SWS_EcuM_02801 */ /* @req SWS_EcuM_04038 */ /* @req SWS_EcuMf_00046 */ typedef struct EcuM_ConfigS { uint32 EcuMPostBuildVariant; /* @req SWS_EcuM_02794 */ uint64 EcuMConfigConsistencyHashLow; /* @req SWS_EcuM_02795 Hash set when compiling the whole software for the */ uint64 EcuMConfigConsistencyHashHigh; /* PB module. It is compared to the PB hash at startup. */ EcuM_StateType EcuMDefaultShutdownTarget; uint8 EcuMDefaultSleepMode; AppModeType EcuMDefaultAppMode; uint32 EcuMRunMinimumDuration; uint32 EcuMNvramReadAllTimeout; uint32 EcuMNvramWriteAllTimeout; Mcu_ModeType EcuMNormalMcuMode; #if defined(USE_DEM) Dem_EventIdType EcuMDemInconsistencyEventId; Dem_EventIdType EcuMDemRamCheckFailedEventId; Dem_EventIdType EcuMDemAllRunRequestsKilledEventId; #endif const EcuM_SleepModeType *EcuMSleepModeConfig; const EcuM_WakeupSourceConfigType *EcuMWakeupSourceConfig; #if defined(USE_ECUM_FLEXIBLE) const EcuM_UserType *EcuMGoDownAllowedUsersConfig; #endif #if defined (USE_COMM) const EcuM_ComMConfigType *EcuMComMConfig; #endif #if defined(USE_MCU) const Mcu_ConfigType* McuConfigPtr; #endif #if defined(USE_PORT) const Port_ConfigType* PortConfigPtr; #endif #if defined(USE_DIO) const Dio_ConfigType* DioConfigPtr; #endif #if defined(USE_CANSM) const CanSM_ConfigType* CanSMConfigPtr; #endif #if defined(USE_LIN) const Lin_ConfigType* LinConfigPtr; #endif #if defined(USE_LINIF) const LinIf_ConfigType* LinIfConfigPtr; #endif #if defined(USE_LINTP) const LinTp_ConfigType* LinTpConfigPtr; #endif #if defined(USE_LINSM) const LinSM_ConfigType* LinSMConfigPtr; #endif #if defined(USE_STBM) const StbM_ConfigType* StbMConfigPtr; #endif #if defined(USE_ETHTSYN) const EthTSyn_ConfigType* EthTSynConfigPtr; #endif #if defined(USE_ETHSM) const EthSM_ConfigType* EthSMConfigPtr; #endif #if defined(USE_ETHTRCV) const EthTrcv_ConfigType* EthTrcvConfigPtr; #endif #if defined(USE_ETHIF) const EthIf_ConfigType* EthIfConfigPtr; #endif #if defined(USE_ETH) const Eth_ConfigType* EthConfigPtr; #endif #if defined(USE_NM) const Nm_ConfigType* NmConfigPtr; #endif #if defined(USE_UDPNM) const UdpNm_ConfigType* UdpNmConfigPtr; #endif #if defined(USE_SECOC) const SecOC_ConfigType* SecOCConfigPtr; #endif #if defined(USE_TCPIP) const TcpIp_ConfigType* TcpIpConfigPtr; #endif #if defined(USE_J1939TP) const J1939Tp_ConfigType* J1939TpConfigPtr; #endif #if defined(USE_SD) const Sd_ConfigType* SdConfigPtr; #endif #if defined(USE_SOAD) const SoAd_ConfigType* SoAdConfigPtr; #endif #if defined(USE_DOIP) const DoIP_ConfigType* DoIPConfigPtr; #endif #if defined(USE_LDCOM) const LdCom_ConfigType* LdComConfigPtr; #endif #if defined(USE_PWM) const Pwm_ConfigType* PwmConfigPtr; #endif #if defined(USE_OCU) const Ocu_ConfigType* OcuConfigPtr; #endif #if defined(USE_ICU) const Icu_ConfigType* IcuConfigPtr; #endif #if defined(USE_DMA) const Dma_ConfigType* DmaConfigPtr; #endif #if defined(USE_ADC) const Adc_ConfigType* AdcConfigPtr; #endif #if defined(USE_GPT) const Gpt_ConfigType* GptConfigPtr; #endif #if defined(USE_FLS) const Fls_ConfigType* FlsConfigPtr; #endif #if defined(USE_EEP) const Eep_ConfigType* EepConfigPtr; #endif #if defined(USE_SPI) const Spi_ConfigType* SpiConfigPtr; #endif #if defined(USE_WDG) const Wdg_ConfigType* WdgConfigPtr; #endif #if defined(USE_WDGIF) const WdgIf_ConfigType* WdgIfConfigPtr; #endif #if defined(USE_WDGM) const WdgM_ConfigType* WdgMConfigPtr; #endif #if defined(USE_DCM) const Dcm_ConfigType* DcmConfigPtr; #endif #if defined(USE_DEM) const Dem_ConfigType* DemConfigPtr; #endif #if defined(USE_XCP) const Xcp_ConfigType* XcpConfigPtr; #endif #if defined(USE_IPDUM) const IpduM_ConfigType* IpduMConfigPtr; #endif #if defined(USE_BSWM) || defined(USE_PDUR) || defined(USE_COM) || defined(USE_CANIF) || defined(USE_CANTP) || defined(USE_CANNM) || defined(USE_BSWM) || defined(USE_CAN) || defined(USE_CANTRCV) || (defined(USE_FIM) && (FIM_POSTBUILD_MODE == STD_ON)) const PostbuildConfigType* PostBuildConfig; #endif #if defined(USE_DLT) const Dlt_ConfigType* DltConfigPtr; #endif #if defined(USE_FR) const Fr_ConfigType * FrConfigPtr; #endif #if defined(USE_FRIF) const FrIf_ConfigType * FrIfConfigPtr; #endif #if defined(USE_FRNM) const FrNm_ConfigType * FrNmConfigPtr; #endif #if defined(USE_FRSM) const FrSM_ConfigType * FrSMConfigPtr; #endif #if defined(USE_FRTP) const FrTp_ConfigType * FrTpConfigPtr; #endif #if defined(USE_OSEKNM) const OsekNm_ConfigType * OsekNmConfigPtr; #endif #if defined(USE_FIM) && (FIM_POSTBUILD_MODE == STD_OFF) const FiM_ConfigType * FiMConfigPtr; #endif } EcuM_ConfigType; #endif /*_ECUM_GENERATED_TYPES_H_*/
2301_81045437/classic-platform
system/EcuM/src/EcuM_Generated_Types.h
C
unknown
9,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 */ /** @fileSafetyClassification ASIL **/ /* Common for whole module */ // Structs and types used internal in the module #ifndef _ECUM_INTERNALS_H_ #define _ECUM_INTERNALS_H_ #include "EcuM_Generated_Types.h" /* @req SWS_BSW_00203 API parameter checking enablement. */ #if defined(USE_DET) /* @req SWS_BSW_00042 Detection of DevErrors should only be performed if configuration parameter for Development errors is set. */ #if ( ECUM_DEV_ERROR_DETECT == STD_ON ) #include "Det.h" /*lint -emacro(904,VALIDATE,VALIDATE_RV,VALIDATE_NO_RV) MISRA:ARGUMENT_CHECK:Macros used for checking arguments before performing any functionality:[MISRA 2012 Rule 15.5, advisory] */ /*lint -emacro(9027,VALIDATE,VALIDATE_RV,VALIDATE_NO_RV) MISRA:ARGUMENT_CHECK:usage of '!' in macros allowed:[MISRA 2012 Rule 10.1, required] */ /* @req SWS_BSW_00045 Development errors should be reported to DET module */ /* @req SWS_BSW_00049 API parameter checking */ #define VALIDATE(_exp,_api,_err ) \ if(!(_exp) ) { \ (void)Det_ReportError(ECUM_MODULE_ID, 0, _api, _err); \ } #define VALIDATE_RV(_exp,_api,_err,_rv ) \ if(!(_exp)) { \ (void)Det_ReportError(ECUM_MODULE_ID, 0, _api, _err); \ return _rv; \ } #define VALIDATE_NO_RV(_exp,_api,_err) \ if(!(_exp)){ \ (void)Det_ReportError(ECUM_MODULE_ID, 0, _api, _err); \ return; \ } // MISRA 2012 14.4 : Inhibit lint error 9036 for macro ended with while(0) condition //lint -emacro(9036,ECUM_DET_REPORT_ERROR) #define ECUM_DET_REPORT_ERROR(_api, _err) \ (void)Det_ReportError(ECUM_MODULE_ID, 0, _api, _err); \ #else #define VALIDATE(_exp,_api,_err ) #define VALIDATE_RV(_exp,_api,_err,_rv ) #define VALIDATE_NO_RV(_exp,_api,_err ) #define ECUM_DET_REPORT_ERROR(_api, _error) #endif #endif #define SchM_Enter_EcuM(_area) SchM_Enter_EcuM_##_area) #define SchM_Exit_EcuM(_area) SchM_Exit_EcuM_##_area) typedef struct { boolean initiated; EcuM_ConfigType *config; EcuM_StateType shutdown_target; AppModeType app_mode; EcuM_StateType current_state; uint32 run_requests; uint32 postrun_requests; boolean killAllRequest; boolean killAllPostrunRequest; #if (defined(USE_ECUM_FLEXIBLE)) EcuM_ShutdownCauseType shutdown_cause; #endif uint8 sleep_mode; /* Events set by EcuM_SetWakeupEvent */ uint32 wakeupEvents; uint32 wakeupTimer; /* Events set by EcuM_ValidateWakeupEvent */ uint32 validEvents; uint32 validationTimer; #if (ECUM_ARC_SAFETY_PLATFORM == STD_ON) EcuM_SP_SyncStatus syncStatusMaster; #endif } EcuM_GlobalType; typedef struct { uint32 nvmReadAllTimer; #if defined(USE_COMM) || (defined(USE_ECUM_COMM) && (ECUM_AR_VERSION < 40000)) uint32 run_comm_requests; #endif #if (ECUM_ARC_SAFETY_PLATFORM == STD_ON) EcuM_SP_SyncStatus syncStatusPartition_QM; EcuM_StateType current_state_partition_QM; #endif } EcuM_GlobalType_Partition_COMMNVM; extern EcuM_GlobalType EcuM_World; extern EcuM_GlobalType_Partition_COMMNVM EcuM_World_ComM_NVM; /*lint -save -e9003 MISRA:OTHER:Blockscope variables definitions warning is neglected:[MISRA 2012 Rule 8.9, advisory] */ typedef enum { ALL, ALL_WO_LIN, ONLY_LIN } EcuM_ComMCommunicationGroupsType; void EcuM_enter_run_mode(void); void SetCurrentState(EcuM_StateType state); // MISRA 2004 6.3, 2012 4.6 : Inhibit lint error 970 for function GetMainStateAsString // to allow usage of type char, as this function uses string constants. char *GetMainStateAsString( EcuM_StateType state ); //lint !e970 // Functions for EcuMFixed and Safety Platform void SetComMCommunicationAllowed(EcuM_ComMCommunicationGroupsType group, boolean Allowed); #if (ECUM_ARC_SAFETY_PLATFORM == STD_ON) void EcuM_StartupTwo_Partition_A0(void); void EcuM_StartupTwo_Partition_QM(void); #endif #define DEBUG_ECUM_STATE(_state) LDEBUG_PRINTF("STATE: %s\n",GetMainStateAsString(_state)) #define DEBUG_ECUM_CALLOUT(_call) LDEBUG_FPUTS( " CALLOUT->: " _call "\n"); #define DEBUG_ECUM_CALLOUT_W_ARG(_call,_farg0,_arg0) LDEBUG_PRINTF(" CALLOUT->: " _call " "_farg0 "\n",_arg0) #define DEBUG_ECUM_CALLIN_W_ARG(_call,_farg0,_arg0) LDEBUG_PRINTF(" <-CALLIN : " _call " "_farg0 "\n",_arg0) #endif /*_ECUM_INTERNALS_H_*/
2301_81045437/classic-platform
system/EcuM/src/EcuM_Internals.h
C
unknown
5,705
/*-------------------------------- 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 */ /** @fileSafetyClassification ASIL **/ /* Some functions in this file is used by ASIL and QM Ecu managment */ /* @req SWS_EcuM_02989 File structure */ /* @req SWS_EcuM_02989 */ #include "Std_Types.h" #include "EcuM.h" #include "EcuM_Generated_Types.h" #include "EcuM_Internals.h" #include "EcuM_SP_common.h" #ifndef ECUM_NOT_SERVICE_COMPONENT #include "Rte_EcuM.h" #endif #include "SchM_EcuM.h" #if defined(USE_BSWM) #include "BswM_EcuM.h" #endif /* @req SWS_EcuM_02875 */ #if defined(USE_DEM) #include "Dem.h" #endif #if defined(USE_NVM) #include "NvM.h" #endif #if defined(USE_COMM) #include "ComM.h" #include "ComM_EcuM.h" #endif //#define USE_LDEBUG_PRINTF #include "debug.h" #define ECUM_STR "ECUM:" /* ----------------------------[Memory Partition]---------------------------*/ /*lint -save -e9019 MISRA:OTHER:suppressed due to EcuM_MemMap.h include is needed:[MISRA 2012 Rule 20.1, advisory] */ #if defined(USE_NVM) #define ECUM_START_SEC_VAR_NVM_CLEARED_32 #include "EcuM_BswMemMap.h" uint32 EcuM_World_go_off_one_state_timeout = 0; #define ECUM_STOP_SEC_VAR_NVM_CLEARED_32 #include "EcuM_BswMemMap.h" #define ECUM_START_SEC_VAR_NVM_CLEARED_UNSPECIFIED #include "EcuM_BswMemMap.h" /*lint -esym(9003,writeAllResult) MISRA:OTHER:Readability:[MISRA 2012 Rule 8.9, advisory] */ NvM_RequestResultType writeAllResult; #define ECUM_STOP_SEC_VAR_NVM_CLEARED_UNSPECIFIED #include "EcuM_BswMemMap.h" #endif /* MISRA 2012 8.9 (Adv) : An object should be defined at block scope * if its identifier only appears in a single function. * * Depending on configuration it might NOT be possible. */ /*lint -esym(9003,EcuM_World_go_sleep_state_timeout) MISRA:OTHER:Readability:[MISRA 2012 Rule 8.9, advisory] */ #define ECUM_START_SEC_VAR_CLEARED_GLOBALMASTER_UNSPECIFIED #include "EcuM_BswMemMap.h" uint32 EcuM_World_go_sleep_state_timeout = 0; #define ECUM_STOP_SEC_VAR_CLEARED_GLOBALMASTER_UNSPECIFIED #include "EcuM_BswMemMap.h" #ifndef ECUM_NOT_SERVICE_COMPONENT #define ECUM_START_SEC_VAR_INIT_UNSPECIFIED #include "EcuM_BswMemMap.h" /** @req SWS_EcuM_00749 */ /** @req SWS_EcuMf_00104 */ static Rte_ModeType_EcuM_Mode currentMode = RTE_MODE_EcuM_Mode_STARTUP; #define ECUM_STOP_SEC_VAR_INIT_UNSPECIFIED #include "EcuM_BswMemMap.h" #endif /*lint -restore */ /* ----------------------------[End Memory Partition]---------------------------*/ #if defined(USE_LDEBUG_PRINTF) /* Note: Not safety relevant. LDEBUG not used in safety context */ char *GetMainStateAsString( EcuM_StateType state ) { char *str = NULL; switch(state) { case ECUM_STATE_APP_RUN: str = "ECUM_STATE_APP_RUN"; break; case ECUM_STATE_SHUTDOWN: str = "ECUM_STATE_SHUTDOWN"; break; case ECUM_STATE_WAKEUP: str = "ECUM_STATE_WAKEUP"; break; // case ECUM_SUBSTATE_MASK: // str = "ECUM_SUBSTATE_MASK"; // break; case ECUM_STATE_WAKEUP_WAKESLEEP: str = "ECUM_STATE_WAKEUP_WAKESLEEP"; break; case ECUM_STATE_WAKEUP_ONE: str = "ECUM_STATE_WAKEUP_ONE"; break; case ECUM_STATE_OFF: str = "ECUM_STATE_OFF"; break; case ECUM_STATE_STARTUP: str = "ECUM_STATE_STARTUP"; break; case ECUM_STATE_PREP_SHUTDOWN: str = "ECUM_STATE_PREP_SHUTDOWN"; break; case ECUM_STATE_RUN: str = "ECUM_STATE_RUN"; break; case ECUM_STATE_STARTUP_TWO: str = "ECUM_STATE_STARTUP_TWO"; break; case ECUM_STATE_WAKEUP_TTII: str = "ECUM_STATE_WAKEUP_TTII"; break; case ECUM_STATE_WAKEUP_VALIDATION: str = "ECUM_STATE_WAKEUP_VALIDATION"; break; case ECUM_STATE_GO_SLEEP: str = "ECUM_STATE_GO_SLEEP"; break; case ECUM_STATE_STARTUP_ONE: str = "ECUM_STATE_STARTUP_ONE"; break; case ECUM_STATE_WAKEUP_TWO: str = "ECUM_STATE_WAKEUP_TWO"; break; case ECUM_STATE_SLEEP: str = "ECUM_STATE_SLEEP"; break; case ECUM_STATE_WAKEUP_REACTION: str = "ECUM_STATE_WAKEUP_REACTION"; break; case ECUM_STATE_APP_POST_RUN: str = "ECUM_STATE_APP_POST_RUN"; break; case ECUM_STATE_GO_OFF_TWO: str = "ECUM_STATE_GO_OFF_TWO"; break; case ECUM_STATE_RESET: str = "ECUM_STATE_RESET"; break; case ECUM_STATE_GO_OFF_ONE: str = "ECUM_STATE_GO_OFF_ONE"; break; default: ASSERT(0); } return str; } /* Note: Not safety relevant. LDEBUG not used in safety context */ const char *GetWakeupReactionAsString( EcuM_WakeupReactionType reaction ) { const char *WakeupReactionAsString[] = { "ECUM_WKACT_RUN", "UNKNONW?", "ECUM_WKACT_TTII", "ECUM_WKACT_SHUTDOWN", }; return WakeupReactionAsString[reaction]; } #endif /*USE_LDEBUG_PRINTF*/ /* Note: This is a generic function to set the EcuM state used by both SP partition and for non-safety platform EcuM */ void SetCurrentState(EcuM_StateType state) { /* Update the state */ EcuM_World.current_state = state; #ifndef ECUM_NOT_SERVICE_COMPONENT Rte_ModeType_EcuM_Mode newMode = currentMode; switch( state ) { case ECUM_STATE_WAKEUP: case ECUM_STATE_WAKEUP_ONE: case ECUM_STATE_WAKEUP_VALIDATION: case ECUM_STATE_WAKEUP_REACTION: case ECUM_STATE_WAKEUP_TWO: case ECUM_STATE_SLEEP: case ECUM_STATE_SHUTDOWN: newMode = RTE_MODE_EcuM_Mode_SLEEP; break; case ECUM_STATE_GO_SLEEP: if( EcuM_World.shutdown_target == ECUM_STATE_SLEEP ) { newMode = RTE_MODE_EcuM_Mode_SLEEP; /** @req SWS_EcuM_00752 */ } break; case ECUM_STATE_GO_OFF_ONE: case ECUM_STATE_GO_OFF_TWO: newMode = RTE_MODE_EcuM_Mode_SHUTDOWN; break; case ECUM_STATE_WAKEUP_TTII: if( EcuM_World.shutdown_target == ECUM_STATE_SLEEP ) { newMode = RTE_MODE_EcuM_Mode_WAKE_SLEEP; /** @req SWS_EcuM_00752 */ } break; case ECUM_STATE_PREP_SHUTDOWN: case ECUM_STATE_APP_POST_RUN: newMode = RTE_MODE_EcuM_Mode_POST_RUN; break; case ECUM_STATE_APP_RUN: SchM_Enter_EcuM_EA_0(); newMode = RTE_MODE_EcuM_Mode_RUN; /* We have a configurable minimum time (EcuMRunMinimumDuration) we have to stay in RUN state */ /* This should not be done in EcuM_enter_run_mode() because RTE_MODE_EcuM_Mode_RUN & EcuM_World_run_state_timeout are * not set at the same time and this might lead to immediate timeout */ EcuM_World_run_state_timeout = EcuM_World.config->EcuMRunMinimumDuration / ECUM_MAIN_FUNCTION_PERIOD; /** @req SWS_EcuM_00310 */ SchM_Exit_EcuM_EA_0(); break; case ECUM_STATE_STARTUP_TWO: newMode = RTE_MODE_EcuM_Mode_STARTUP; break; default: /* Do nothing */ break; } if( newMode != currentMode ) { currentMode = newMode; (void)Rte_Switch_currentMode_currentMode(currentMode); /** @req SWS_EcuM_00750 */ } #else if (ECUM_STATE_APP_RUN == state) { /*lint -e534 MISRA:OTHER:ignoring return value:[MISRA 2004 Info,advisory] */ SchM_Enter_EcuM_EA_0(); /* We have a configurable minimum time (EcuMRunMinimumDuration) we have to stay in RUN state */ EcuM_World_run_state_timeout = EcuM_World.config->EcuMRunMinimumDuration / ECUM_MAIN_FUNCTION_PERIOD; /** @req SWS_EcuM_00310 */ SchM_Exit_EcuM_EA_0(); } #endif /* @req SWS_EcuMf_00014 */ #if (defined(USE_BSWM) && (ECUM_ARC_SAFETY_PLATFORM == STD_OFF)) /* The BswM is not initialized in the ECUM_STATE_STARTUP_ONE state */ if (ECUM_STATE_STARTUP_ONE != state) { BswM_EcuM_CurrentState(state); } #endif } /* Note: QM code - This function is used both by EcuM_Main (non-SP) and EcuM_QM. */ /*lint -esym(522, SetComMCommunicationAllowed) MISRA:STANDARDIZED_INTERFACE:Ok when not using ComM:[MISRA 2012 Rule 2.2, required] */ void SetComMCommunicationAllowed(EcuM_ComMCommunicationGroupsType group, boolean Allowed) { #if defined(USE_COMM) { /* @req SWS_EcuMf_00008 */ uint8 i; for (i=0;i<ECUM_COMM_NETWORKS_CNT;i++) { const EcuM_ComMConfigType* comMConfigPtr = &EcuM_World.config->EcuMComMConfig[i]; if ((EcuM_World.config->EcuMComMConfig != 0) && ((ALL == group) || ((ALL_WO_LIN == group) && (comMConfigPtr->EcuMComBusType != COMM_BUS_TYPE_LIN)) || ((ONLY_LIN == group) && (comMConfigPtr->EcuMComBusType == COMM_BUS_TYPE_LIN)))) { DEBUG_ECUM_CALLOUT_W_ARG("ComM_CommunicationAllowed","%ld",(uint32)comMConfigPtr->EcuMComMNetworkHandle); ComM_CommunicationAllowed(comMConfigPtr->EcuMComMNetworkHandle, Allowed); } } } #else (void)group; /*lint !e920 MISRA:STANDARDIZED_INTERFACE:Casting from a type to void:[MISRA 2012 Rule 1.3, required] */ (void)Allowed; /*lint !e920 MISRA:STANDARDIZED_INTERFACE:Casting from a type to void:[MISRA 2012 Rule 1.3, required] */ #endif } #if (ECUM_ARC_SAFETY_PLATFORM == STD_OFF) /** @CODECOV:NOT_SUPPORTED:SafetyPlatform has its own partitioned ECUM main functions **/ __CODE_COVERAGE_OFF__ /** * RUN II entry * - Called from EcuM_StartupTwo() * - Called from * * Note: Not used for safety platform */ void EcuM_enter_run_mode(void){ EcuM_OnEnterRun(); /** @req SWS_EcuM_00308 */ /* @req SWS_EcuMf_00019 */ /* @req SWS_EcuMf_00008 */ SetComMCommunicationAllowed(ALL, TRUE); /* * time we could leave the state before it has been completed. */ SetCurrentState(ECUM_STATE_APP_RUN); #if defined(USE_COMM) && (ECUM_AR_VERSION < 40000) /* !req SWS_EcuMf_00027 * ECU in RUN state shall also perform wake up validation of sleeping busses */ { uint32 cMask = EcuM_World_ComM_NVM.run_comm_requests; uint8 channel; for (; cMask; cMask &= ~(1ul << channel)) { channel = ilog2(cMask); DEBUG_ECUM_CALLOUT_W_ARG("ComM_EcuM_RunModeIndication","%ld",(uint32)channel); ComM_EcuM_RunModeIndication(channel); } } #endif } //--------- Local functions ------------------------------------------------------------------------------------------------ /** * Enter GO SLEEP state ( soon in state ECUM_STATE_GO_SLEEP) * Note: Not used for safety platform */ static inline void enter_go_sleep_mode(void){ SetCurrentState(ECUM_STATE_GO_SLEEP); DEBUG_ECUM_CALLOUT( ECUM_STR "EcuM_OnGoSleep"); EcuM_OnGoSleep(); #if defined(USE_NVM) NvM_WriteAll(); /* Start timer */ EcuM_World_go_sleep_state_timeout = EcuM_World.config->EcuMNvramWriteAllTimeout / ECUM_MAIN_FUNCTION_PERIOD; #endif } /** * In GO SLEEP state (in state ECUM_STATE_GO_SLEEP) * Note: Not used for safety platform */ static void in_state_goSleep( void ) { /* !req SWS_EcuMf_00026 * The ECU State Manager Fixed module shall put all communication interfaces to standby state and shall arm the * wake up source before the ECU State Manager Fixed module may put the ECU into SLEEP state. */ /* We only wait for NvM_WriteAll() for so long */ if (EcuM_World_go_sleep_state_timeout != 0) { EcuM_World_go_sleep_state_timeout--; #if defined(USE_NVM) { NvM_RequestResultType nvmResult; if((NvM_GetErrorStatus(0, &nvmResult) != E_OK) || (nvmResult != NVM_REQ_PENDING)) { /* Done or something is wrong...continue */ EcuM_World_go_sleep_state_timeout = 0; } } #endif } if( (EcuM_World_go_sleep_state_timeout == 0) ) { /* * We should go to sleep , enable source that should wake us */ uint32 cMask; uint8 source; const EcuM_SleepModeType *sleepModePtr; /* Get the current sleep mode */ /* @req SWS_EcuM_02185 */ sleepModePtr = &EcuM_World.config->EcuMSleepModeConfig[EcuM_World.sleep_mode]; cMask = sleepModePtr->EcuMWakeupSourceMask;/* @req SWS_EcuM_02546 */ /* Loop over the WKSOURCE for this sleep mode */ /* @req SWS_EcuM_02389 */ /* @req SWS_EcuM_02546 */ for (; cMask != 0; cMask &= ~(1UL << source)) { /*lint -e{734} -e{9033} -e{397} -e{834} MISRA:OTHER:return value wont exceed more than 32 so its fine:[MISRA 2004 Info, advisory] */ source = (uint8)(ilog2(cMask)); // DEBUG_ECUM_CALLOUT_W_ARG("EcuM_EnableWakeupSources","0x%lx",(1ul<< source)); EcuM_EnableWakeupSources( 1UL << source ); } /* Let no one else run */ (void)GetResource(RES_SCHEDULER); SetCurrentState(ECUM_STATE_SLEEP); } else if( EcuM_GetPendingWakeupEvents() != 0 ) { /* @req SWS_EcuM_02188 */ /* We have pending wakeup events, need to startup again */ #if defined(USE_NVM) NvM_CancelWriteAll(); SetCurrentState(ECUM_STATE_WAKEUP_ONE); #endif } else { /* No action (terminating else statement required by MISRA) */ } } /** * In "Sleep Sequence I" (in state ECUM_STATE_SLEEP) * Note: Not used for safety platform */ static void in_state_sleep ( void ) { const EcuM_SleepModeType *sleepModePtr = &EcuM_World.config->EcuMSleepModeConfig[EcuM_World.sleep_mode]; /* @req SWS_EcuM_02863 */ DEBUG_ECUM_CALLOUT( ECUM_STR "EcuM_GenerateRamHash"); EcuM_GenerateRamHash(); DEBUG_ECUM_CALLOUT_W_ARG("Mcu_SetMode","%d",sleepModePtr->EcuMSleepModeMcuMode); Mcu_SetMode(sleepModePtr->EcuMSleepModeMcuMode); if( EcuM_CheckRamHash() == 0) { #if defined(USE_DEM) EcuM_ErrorHook(EcuM_World.config->EcuMDemRamCheckFailedEventId); #endif } SetCurrentState(ECUM_STATE_WAKEUP_ONE); } static inline void go_off_one_module_deinit(void){ #if defined(USE_COMM) ComM_DeInit(); #endif #if defined(USE_BSWM) /* @req SWS_EcuMf_00017 */ BswM_Deinit(); #endif #if defined(USE_NVM) // Start NvM_WriteAll and timeout timer NvM_WriteAll(); EcuM_World_go_off_one_state_timeout = EcuM_World.config->EcuMNvramWriteAllTimeout / ECUM_MAIN_FUNCTION_PERIOD; #endif } static inline void enter_go_off_one_mode(void){ SetCurrentState(ECUM_STATE_GO_OFF_ONE); EcuM_OnGoOffOne(); /* @req SWS_EcuMf_00008 Only set LIN to false when not going to sleep. * Kind a strange that COMM is deini on the next line. */ /* @req SWS_EcuMf_00019 */ SetComMCommunicationAllowed(ONLY_LIN, FALSE); go_off_one_module_deinit(); /*lint !e522 MISRA:CONFIGURATION:This function may not have any functionality depending on configuration:[MISRA 2012 Rule 2.2, required] */ } /** * RUN II Loop (in state ECUM_STATE_APP_RUN) * - The entry to RUN II is done in * Note: Not used for safety platform */ static inline void in_state_appRun(void){ if (EcuM_World_run_state_timeout != 0){ EcuM_World_run_state_timeout--; LDEBUG_PRINTF( ECUM_STR "RUN Timeout=%ld\n",EcuM_World_run_state_timeout); } if ((FALSE == hasRunRequests()) && (EcuM_World_run_state_timeout == 0)){ DEBUG_ECUM_CALLOUT( ECUM_STR "EcuM_OnExitRun"); EcuM_OnExitRun(); /** @req SWS_EcuM_00865 */ /* @req SWS_EcuMf_00008 */ /* @req SWS_EcuMf_00020 */ SetComMCommunicationAllowed(ALL_WO_LIN, FALSE); /* @req SWS_EcuM_00311 */ SetCurrentState(ECUM_STATE_APP_POST_RUN); /** @req SWS_EcuM_00865 */ } } /** * RUN III states (in state ECUM_STATE_APP_POST_RUN) * Note: Not used for safety platform */ static inline void in_state_appPostRun(void){ /* @req SWS_EcuMf_00025 Not enter sleep if we have a run request */ if (TRUE == hasRunRequests()){ /* We have run requests, return to RUN II */ /* @req SWS_EcuM_00866 */ DEBUG_ECUM_CALLOUT( ECUM_STR "EcuM_enter_run_mode"); EcuM_enter_run_mode(); } else if (FALSE == hasPostRunRequests()){ DEBUG_ECUM_CALLOUT( ECUM_STR "EcuM_OnExitPostRun"); EcuM_OnExitPostRun(); /** @req SWS_EcuM_00761 */ SetCurrentState(ECUM_STATE_PREP_SHUTDOWN); } else { /* NOTE: We have postrun requests */ } } /** * PREP SHUTDOWN state (in state ECUM_STATE_PREP_SHUTDOWN) * Note: Not used for safety platform */ static inline void in_state_prepShutdown(void){ // The specification does not state what events to clear, // assuming all. EcuM_ClearWakeupEvent((EcuM_WakeupSourceType)0xFFFFFFFFU); DEBUG_ECUM_CALLOUT( ECUM_STR "EcuM_OnPrepShutdown"); EcuM_OnPrepShutdown(); #if defined(USE_DEM) // DEM shutdown Dem_Shutdown(); #endif // Switch shutdown mode switch(EcuM_World.shutdown_target){ //If in state Off or Reset go into Go_Off_One: case ECUM_STATE_OFF: case ECUM_STATE_RESET: /* @req SWS_EcuM_00288 */ enter_go_off_one_mode(); break; case ECUM_STATE_SLEEP: enter_go_sleep_mode(); break; default: ECUM_DET_REPORT_ERROR(ECUM_MAINFUNCTION_ID, ECUM_E_ARC_FAULTY_SHUTDOWN_TARGET); break; } } /* Note: Not used for safety platform */ static inline void in_state_goOffOne(void){ /* @req SWS_EcuM_00328 */ #if defined(USE_NVM) if (0u != EcuM_World_go_off_one_state_timeout){ EcuM_World_go_off_one_state_timeout--; } // Wait for the NVM job (NvmWriteAll) to terminate Std_ReturnType ret = NvM_GetErrorStatus(0, &writeAllResult); if (((ret == E_OK) && (writeAllResult != NVM_REQ_PENDING)) || (EcuM_World_go_off_one_state_timeout == 0)) { ShutdownOS(E_OK); } #else ShutdownOS(E_OK); #endif } //----- MAIN ----------------------------------------------------------------------------------------------------------------- /* Note: This MainFunciton is when not using safety platform. Safety platform partitions have one main function each. */ void EcuM_MainFunction(void) { boolean ret = TRUE; EcuM_WakeupSourceType wMask=0; #if defined(USE_LDEBUG_PRINTF) static uint32 validationMask; #endif static uint32 validationMaxTime; static uint32 pendingWkupMask = 0; /* @req SWS_EcuMf_00029 */ if (FALSE == EcuM_World.initiated) { ret = FALSE; } if (ret == TRUE) { #if defined(USE_LDEBUG_PRINTF) { static EcuM_StateType oldEcuMState = 0xff; if( oldEcuMState != EcuM_World.current_state) { DEBUG_ECUM_STATE(EcuM_World.current_state); oldEcuMState = EcuM_World.current_state; } } #endif switch (EcuM_World.current_state) { case ECUM_STATE_APP_RUN: /* RUN II state */ in_state_appRun(); break; case ECUM_STATE_APP_POST_RUN: /* RUN III state */ in_state_appPostRun(); break; case ECUM_STATE_PREP_SHUTDOWN: in_state_prepShutdown(); break; case ECUM_STATE_GO_OFF_ONE: in_state_goOffOne(); break; case ECUM_STATE_GO_SLEEP: /* 4 cases: * 1. Wait for the NvM_WriteAll() - Stay in state * 2. Timeout on NvM_WriteAll() - go to ECUM_STATE_SLEEP (Scheduler is locked) * 3. NvM_WriteAll() is done - go to ECUM_STATE_SLEEP (Scheduler is locked) * 4. Run request - Call NvM_CancelAll() and go to ECUM_STATE_WAKEUP_ONE. */ in_state_goSleep(); if( EcuM_World.current_state != ECUM_STATE_SLEEP ) { break; } /*lint -e{825} MISRA:STANDARDIZED_INTERFACE:Flow Through, Scheduler is Locked:[MISRA 2012 Rule 16.3, required]*/ case ECUM_STATE_SLEEP: in_state_sleep(); /*lint -e{825} MISRA:STANDARDIZED_INTERFACE:Flow Through, Scheduler is Locked:[MISRA 2012 Rule 16.3, required]*/ case ECUM_STATE_WAKEUP_ONE: { DEBUG_ECUM_STATE(EcuM_World.current_state); /*@req SWS_EcuM_02975 */ Mcu_SetMode(EcuM_World.config->EcuMNormalMcuMode); wMask = EcuM_GetPendingWakeupEvents(); DEBUG_ECUM_CALLOUT_W_ARG("EcuM_DisableWakeupSources", "0x%lx", (uint32) wMask); EcuM_DisableWakeupSources(wMask); /* @req SWS_EcuM_02562 */ EcuM_AL_DriverRestart(EcuM_World.config); EcuM_World.killAllRequest = FALSE; /* Enable run request again */ EcuM_World.killAllPostrunRequest = FALSE; /* Enable run request again */ (void)ReleaseResource(RES_SCHEDULER); #if defined(USE_LDEBUG_PRINTF) validationMask = 0; #endif validationMaxTime = 0; const EcuM_WakeupSourceConfigType *wkupCfgPtr; SetCurrentState(ECUM_STATE_WAKEUP_VALIDATION); /*-------------- ECUM_STATE_WAKEUP_VALIDATION -------------------- */ DEBUG_ECUM_CALLOUT(ECUM_STR "EcuM_GetPendingWakeupEvents"); pendingWkupMask = EcuM_GetPendingWakeupEvents(); DEBUG_ECUM_CALLOUT_W_ARG("EcuM_StartWakeupSources", "0x%lx",(uint32) pendingWkupMask); EcuM_StartWakeupSources(pendingWkupMask); EcuM_World.validationTimer = 0; /* Calculate the validation timing , if any*/ /* @req SWS_EcuM_00494 */ /* @req SWS_EcuM_02479 */ for (uint32 i = 0; i < ECUM_WKSOURCE_USER_CNT; i++) { wkupCfgPtr = &EcuM_World.config->EcuMWakeupSourceConfig[i]; /* Can't validate something that is not pending */ if ((wMask & wkupCfgPtr->EcuMWakeupSourceId) != 0) { /* No validation timeout == ECUM_VALIDATION_TIMEOUT_ILL */ /* @req SWS_EcuM_02566 */ if ((wkupCfgPtr->EcuMValidationTimeout != ECUM_VALIDATION_TIMEOUT_ILL) && ((wMask & wkupCfgPtr->EcuMWakeupSourceId) != 0)) { /* Build a mask with the sources that need validation */ #if defined(USE_LDEBUG_PRINTF) validationMask |= wkupCfgPtr->EcuMWakeupSourceId; #endif /* Use one validation timeout, take the longest */ validationMaxTime = MAX( wkupCfgPtr->EcuMValidationTimeout / ECUM_MAIN_FUNCTION_PERIOD, validationMaxTime); EcuM_World.validationTimer = (validationMaxTime > 0U) ? validationMaxTime : 1U; } else { LDEBUG_PRINTF(ECUM_STR "No Validation for :0x%lx (EcuM_ValidateWakeupEvent() called)\n", (uint32) wkupCfgPtr->EcuMWakeupSourceId); /* Validate right away */ /* @req SWS_EcuM_02976 */ EcuM_ValidateWakeupEvent(wkupCfgPtr->EcuMWakeupSourceId); } } } break; } case ECUM_STATE_WAKEUP_VALIDATION: { if (EcuM_World.validationTimer != 0) { /* * Call EcuM_CheckValidation() while all events have not been validated and * timeout have not expired. The call to EcuM_CheckValidation(..) triggers a call * to EcuM_ValidateWakeupEvent(..) from the driver when validated. */ /* Check validation for the events that do not match, ie not yet validated */ DEBUG_ECUM_CALLOUT_W_ARG( "EcuM_CheckValidation", "0x%lx", (uint32)(EcuM_GetValidatedWakeupEvents() ^ pendingWkupMask)); EcuM_CheckValidation( EcuM_GetValidatedWakeupEvents() ^ pendingWkupMask); /* @req SWS_EcuM_00495*/ if (0 != EcuM_GetValidatedWakeupEvents()) { /* All events have been validated */ EcuM_ValidateWakeupEvent(EcuM_GetValidatedWakeupEvents() ^ pendingWkupMask); SetCurrentState(ECUM_STATE_WAKEUP_REACTION); } else { LDEBUG_PRINTF( ECUM_STR " Awaiting validation for mask: pending=%lx, expected=%lx\n", pendingWkupMask, validationMask); LDEBUG_PRINTF(ECUM_STR " Validation Timer : %lu\n", EcuM_World.validationTimer); } } else { uint32 notValidatedMask = EcuM_GetValidatedWakeupEvents() ^ pendingWkupMask; /* Stop wakeupSources that are not validated */ if (notValidatedMask != 0) { DEBUG_ECUM_CALLOUT_W_ARG("EcuM_StopWakeupSources", "0x%lx", (uint32) notValidatedMask); EcuM_StopWakeupSources(notValidatedMask); #if defined(USE_BSWM) BswM_EcuM_CurrentWakeup(notValidatedMask, ECUM_WKSTATUS_EXPIRED); #endif } SetCurrentState(ECUM_STATE_WAKEUP_REACTION); } if (EcuM_World.validationTimer != 0) { EcuM_World.validationTimer--; } break; } case ECUM_STATE_WAKEUP_REACTION: { /* * At this stage we want to know how to react to the wakeup, e.g. go * back to RUN or SHUTDOWN, etc. */ EcuM_WakeupReactionType wReaction; wMask = EcuM_GetValidatedWakeupEvents(); LDEBUG_PRINTF(ECUM_STR "EcuM_GetValidatedWakeupEvents() : %x\n", wMask); /* NOTE: We have skipped the TTII timer here */ /* If the wakeup mask here is != 0 we have a validated wakeup event -> * go back to RUN */ wReaction = (0 == wMask) ? ECUM_WKACT_SHUTDOWN : ECUM_WKACT_RUN; wReaction = EcuM_OnWakeupReaction(wReaction); LDEBUG_PRINTF(ECUM_STR "Wakeup Reaction: %s\n", GetWakeupReactionAsString(wReaction)); if (wReaction == ECUM_WKACT_RUN) { /* @req SWS_EcuM_00568 */ SetCurrentState(ECUM_STATE_WAKEUP_TWO); } else { /* From figure 28 it seems that we should go to SHUTDOWN/GO SLEEP) again from wakeup * not going up to RUN/RUN II state again. */ /* @req SWS_EcuM_00711 */ /* @req SWS_EcuM_00567 */ SetCurrentState(ECUM_STATE_GO_SLEEP); } break; } case ECUM_STATE_WAKEUP_TWO: #if defined(USE_DEM) Dem_Init(); #endif EcuM_enter_run_mode(); break; default: ECUM_DET_REPORT_ERROR(ECUM_MAINFUNCTION_ID, ECUM_E_ARC_FAULTY_CURRENT_STATE); break; } } } __CODE_COVERAGE_ON__ #endif /*!(defined(ECUM_ARC_SAFETY_PLATFORM))*/
2301_81045437/classic-platform
system/EcuM/src/EcuM_Main.c
C
unknown
28,678
/*-------------------------------- 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 */ /* The post build area has the following structure. * * PostbuildConfig_Type - contains general data about the post * build data and contains pointers to the actual configurations * that are stored afterwards. * * ComM - ComM_Config * Com - ComConfiguration * PduR - PduR_Config * CanIf - CanIf_Config * CanTp Not supported yet * LinIf (N/A) * LinTp (N/A) * FrIf (N/A) * FrTp (N/A) * */ #include "EcuM_PBTypes.h" #include "PreCompiledDataHash.h" #include "MemMap.h" #if defined(USE_CANTP) extern const CanTp_ConfigType CanTpConfig; #endif #if defined(USE_PDUR) extern const PduR_PBConfigType PduR_Config; #endif #if defined(USE_CANIF) extern const CanIf_ConfigType CanIf_Config; #endif #if defined(USE_COM) extern const Com_ConfigType ComConfiguration; #endif #if defined(USE_FIM) #include "FiM.h" #endif /*lint -save -e785 MISRA:FALSE_POSITIVE:Partial array initialization is allowed because this can be rewritten in integration:[MISRA 2012 Rule 9.3, required] */ SECTION_POSTBUILD_HEADER const PostbuildConfigType Postbuild_Config = { .startPattern = 0x5A5A5A5A, .postBuildVariant = 1, .preCompileHashLow = PRE_COMPILED_DATA_HASH_LOW, .preCompileHashHigh = PRE_COMPILED_DATA_HASH_HIGH, #if defined (USE_BSWM) .BswMConfigPtr = &BswM_Config, #endif #if defined (USE_CAN) .CanConfigPtr = &CanConfigData, #endif #if defined(USE_CANIF) .CanIfConfigPtr = &CanIf_Config, #endif #if defined (USE_CANNM) .CanNmConfigPtr = &CanNm_Config, #endif #if defined(USE_CANTP) .CanTpConfigPtr = &CanTpConfig, #endif #if defined(USE_COM) .ComConfigPtr = &ComConfiguration, #endif #if defined (USE_COMM) .ComMConfigPtr = &ComM_Config, #endif #if defined(USE_PDUR) .PduRConfigPtr = &PduR_Config, #endif #if defined(USE_CANTRCV) .CanTrcvConfigPtr = &CanTrcv_Config, #endif #if defined(USE_FIM) && (FIM_POSTBUILD_MODE == STD_ON) .FiMConfigPtr = &FiM_Config, #endif }; /*lint -restore */
2301_81045437/classic-platform
system/EcuM/src/EcuM_PBHeader.c
C
unknown
2,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 -----------------------------*/ /** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.3.0 */ /** @fileSafetyClassification QM **/ /* This file handles QM partition ECU management */ /* @req SWS_BSW_00005 */ #include "Std_Types.h" #include "EcuM.h" #include <Os.h> #include "EcuM_Generated_Types.h" #include "EcuM_Internals.h" #include "EcuM_SP_common.h" #include "SchM_EcuM.h" #include "Mcu.h" #if defined(USE_HTMSS) #include "Htmss.h" #endif #if defined(USE_DET) #include "Det.h" #endif #if defined(USE_DEM) #include "Dem.h" /* @req SWS_EcuM_02875 */ #endif #if defined(USE_NVM) #include "NvM.h" #endif #if defined(USE_RTE) #include "Rte_Main.h" #endif #if defined(USE_SCHM) #include "SchM_SP.h" #endif /* @req SWS_BSW_00006 */ #if defined(USE_NVM) #define ECUM_START_SEC_VAR_NVM_CLEARED_8 #include "EcuM_BswMemMap.h" /*lint !e9019 MISRA:OTHER:suppressed due to EcuM_MemMap.h include is needed:[MISRA 2012 Rule 20.1, advisory] */ static NvM_RequestResultType readAllResult; #define ECUM_STOP_SEC_VAR_NVM_CLEARED_8 #include "EcuM_BswMemMap.h" /*lint !e9019 MISRA:OTHER:suppressed due to EcuM_MemMap.h include is needed:[MISRA 2012 Rule 20.1, advisory] */ #endif #ifndef SYS_CALL_ShutdownOS #define SYS_CALL_ShutdownOS ShutdownOS #endif /* ----------------------------[Extern function]---------------------------*/ #if defined(USE_BSWM) extern void BswM_EcuM_CurrentState ( EcuM_StateType CurrentState ); #endif /* * get the sync status (written by Asil parition only) */ static inline EcuM_SP_SyncStatus get_sync_status_master(void){ return EcuM_World.syncStatusMaster; } /* * Tracking the variable for QM to sync with other partition */ static inline void set_sync_status_partition_QM(EcuM_SP_SyncStatus syncStatus){ EcuM_World_ComM_NVM.syncStatusPartition_QM = syncStatus; } /* * get the QM func status */ static inline EcuM_SP_SyncStatus get_sync_status_partition_QM(void){ return EcuM_World_ComM_NVM.syncStatusPartition_QM; } /* * Update the QM func status */ /* inline function to update QM work done and inform for sync */ static inline EcuM_SP_RetStatus update_function_finish_partition_QM() { set_sync_status_partition_QM(get_sync_status_master() | (EcuM_SP_SyncStatus)ECUM_SP_PARTITION_FUN_COMPLETED_QM); return ECUM_SP_RELEASE_SYNC; } static inline boolean is_currentSyncState(EcuM_SP_SyncStatus syncStatus) { return ((get_sync_status_master() & (EcuM_SP_SyncStatus)ECUM_MAINSTATE_MASK) == (syncStatus & (EcuM_SP_SyncStatus)ECUM_MAINSTATE_MASK)) ? TRUE : FALSE; } /* if the supplied major status is not finished */ static inline boolean is_exec_required_for_state_partition_QM(EcuM_SP_SyncStatus syncStatus) { return ((is_currentSyncState(syncStatus) == TRUE) && !((get_sync_status_partition_QM() & (EcuM_SP_SyncStatus)ECUM_MAINSTATE_MASK) == (syncStatus & (EcuM_SP_SyncStatus)ECUM_MAINSTATE_MASK) /** @CODECOV:PARAMETER_VALIDATION_PRIVATE_FUNCTION:QM status can never not be set as complete when above check is also true*/ __CODE_COVERAGE_IGNORE__ && (get_sync_status_partition_QM() & (EcuM_SP_SyncStatus)ECUM_SP_PARTITION_FUN_COMPLETED_QM) == ECUM_SP_PARTITION_FUN_COMPLETED_QM)); } #if defined(USE_BSWM) static inline boolean is_state_changed_partition_QM(EcuM_StateType current_state) { return (EcuM_World_ComM_NVM.current_state_partition_QM != current_state); } static inline void update_state_changed_partition_QM(EcuM_StateType current_state) { EcuM_World_ComM_NVM.current_state_partition_QM = current_state; set_sync_status_partition_QM(ECUM_SP_SYNC_NOT_REQUIRED); } #endif /* * startup II for partition QM (in state ECUM_STATE_STARTUP_TWO) */ static inline EcuM_SP_RetStatus in_state_startup_two_partition_QM(){ EcuM_SP_RetStatus rv = ECUM_SP_OK; if (is_exec_required_for_state_partition_QM(ECUM_SP_SYNC_STARTUP_TWO_START) == TRUE){ EcuM_StartupTwo_Partition_QM(); rv = update_function_finish_partition_QM(); } else if (is_exec_required_for_state_partition_QM(ECUM_SP_SYNC_INIT_RUN_START) == TRUE) { EcuM_OnEnterRun_Partition_QM(); /** @req SWS_EcuM_00308 */ /* @req SWS_EcuMf_00019 */ /* @req SWS_EcuMf_00008 */ SetComMCommunicationAllowed(ALL, TRUE); rv = update_function_finish_partition_QM(); } else { // in synchronization with other partition } return rv; } /* * RUN II for partition QM (in state ECUM_STATE_APP_RUN) */ static inline EcuM_SP_RetStatus in_state_appRun_partition_QM(){ EcuM_SP_RetStatus rv = ECUM_SP_OK; if (is_exec_required_for_state_partition_QM(ECUM_SP_SYNC_EXIT_RUN_START) == TRUE){ EcuM_OnExitRun_Partition_QM(); /** @req SWS_EcuM_00865 */ /* @req SWS_EcuMf_00008 */ /* @req SWS_EcuMf_00020 */ SetComMCommunicationAllowed(ALL_WO_LIN, FALSE); rv = update_function_finish_partition_QM(); } else { // in synchronization with other partition } return rv; } /* * RUN III states (in state ECUM_STATE_APP_POST_RUN) for partition QM */ static inline EcuM_SP_RetStatus in_state_appPostRun_partition_QM(){ EcuM_SP_RetStatus rv = ECUM_SP_OK; if (is_exec_required_for_state_partition_QM(ECUM_SP_SYNC_INIT_RUN_START) == TRUE){ /* We have run requests, return to RUN II */ /* @req SWS_EcuM_00866 */ EcuM_OnEnterRun_Partition_QM(); /** @req SWS_EcuM_00308 */ /* @req SWS_EcuMf_00019 */ /* @req SWS_EcuMf_00008 */ SetComMCommunicationAllowed(ALL, TRUE); rv = update_function_finish_partition_QM(); } else if (is_exec_required_for_state_partition_QM(ECUM_SP_SYNC_POST_RUN_START) == TRUE) { EcuM_OnExitPostRun_Partition_QM(); /** @req SWS_EcuM_00761 */ rv = update_function_finish_partition_QM(); } else { /* NOTE: We have postrun requests */ } return rv; } /* * PREP SHUTDOWN state (in state ECUM_STATE_PREP_SHUTDOWN) for QM */ static inline EcuM_SP_RetStatus in_state_prepShutdown_Partition_QM(void){ EcuM_SP_RetStatus rv = ECUM_SP_OK; if (is_exec_required_for_state_partition_QM(ECUM_SP_SYNC_PREP_SHUTDOWN_START) == TRUE){ EcuM_OnPrepShutdown_Partition_QM(); #if defined(USE_DEM) // DEM shutdown Dem_Shutdown(); #endif rv = update_function_finish_partition_QM(); } else{ // in synchronization with other partition } return rv; } static inline void go_off_one_module_deinit_QM(void){ #if defined(USE_COMM) ComM_DeInit(); #endif #if defined(USE_BSWM) /* @req SWS_EcuMf_00017 */ BswM_Deinit(); #endif #if defined(USE_NVM) // Start NvM_WriteAll and timeout timer NvM_WriteAll(); EcuM_World_go_off_one_state_timeout = EcuM_World.config->EcuMNvramWriteAllTimeout / ECUM_MAIN_FUNCTION_PERIOD; #endif } /* * GO OFF ONE state (in state ECUM_STATE_GO_OFF_ONE) for QM */ static inline EcuM_SP_RetStatus in_go_off_one_mode_partition_QM(void){ EcuM_SP_RetStatus rv = ECUM_SP_OK; if (is_exec_required_for_state_partition_QM(ECUM_SP_SYNC_GO_OFF_ONE_START) == TRUE){ EcuM_OnGoOffOne_Partition_QM(); /* @req SWS_EcuMf_00008 Only set LIN to false when not going to sleep. * Kind a strange that COMM is deini on the next line. */ /* @req SWS_EcuMf_00019 */ SetComMCommunicationAllowed(ONLY_LIN, FALSE); go_off_one_module_deinit_QM(); /*lint !e522 MISRA:CONFIGURATION: This function may not have any functionality depending on configuration:[MISRA 2012 Rule 2.2, required] */ rv = update_function_finish_partition_QM(); } else if (is_exec_required_for_state_partition_QM(ECUM_SP_SYNC_INIT_GO_OFF_TWO_START) == TRUE) { /* @req SWS_EcuM_00328 */ #if defined(USE_NVM) if (0u != EcuM_World_go_off_one_state_timeout){ EcuM_World_go_off_one_state_timeout--; } // Wait for the NVM job (NvmWriteAll) to terminate Std_ReturnType ret = NvM_GetErrorStatus(0, &writeAllResult); if (((ret == E_OK) && (writeAllResult != NVM_REQ_PENDING)) || (EcuM_World_go_off_one_state_timeout == 0)) { rv = update_function_finish_partition_QM(); } #else rv = update_function_finish_partition_QM(); #endif } else { // in synchronization with other partition } return rv; } /* * Mainfunction for QM */ EcuM_SP_RetStatus EcuM_MainFunction_Partition_QM(EcuM_StateType current_state) { EcuM_SP_RetStatus rv = ECUM_SP_OK; // Check for EcuM state change, in that case QM needs to update BswM #if defined(USE_BSWM) if (is_state_changed_partition_QM(current_state) == TRUE) { update_state_changed_partition_QM(current_state); /* The BswM is not initialized in the ECUM_STATE_STARTUP_ONE state */ /* @req SWS_EcuMf_00014 */ if (ECUM_STATE_STARTUP_ONE != current_state) { BswM_EcuM_CurrentState(current_state); } } #endif switch (current_state) { case ECUM_STATE_APP_RUN: /* RUN II state */ rv = in_state_appRun_partition_QM(); break; case ECUM_STATE_APP_POST_RUN: /* RUN III state */ rv = in_state_appPostRun_partition_QM(); break; case ECUM_STATE_PREP_SHUTDOWN: rv = in_state_prepShutdown_Partition_QM(); break; case ECUM_STATE_GO_OFF_ONE: rv = in_go_off_one_mode_partition_QM(); break; case ECUM_STATE_STARTUP_ONE: // Master partition will change the state to ECUM_STARTUP_TWO break; case ECUM_STATE_STARTUP_TWO: rv = in_state_startup_two_partition_QM(); break; default: ECUM_DET_REPORT_ERROR(ECUM_ARC_MAINFUNCTION_QM_ID, ECUM_E_ARC_FAULTY_CURRENT_STATE); break; } return rv; } /* * The order defined here is found in EcuM2411 */ void EcuM_StartupTwo_Partition_QM(void) { if (EcuM_World.current_state == ECUM_STATE_STARTUP_TWO) { // Initialize drivers that don't need NVRAM data for QM paritition EcuM_AL_DriverInitTwo_Partition_QM(EcuM_World.config); #if defined(USE_NVM) // Start timer to wait for NVM job to complete TickType tickTimerStart = GetOsTick(); #endif /* Prepare the system to startup RTE */ #if defined(USE_RTE) (void)Rte_Start_partitionQM(); #endif /* USE_RTE */ #if defined(USE_NVM) /* Wait for the NVM job (NvM_ReadAll) to terminate. This assumes that: * - A task runs the memory MainFunctions, e.g. Ea_MainFunction(), Eep_MainFunction() * are run in a higher priority task that the task that executes this code. */ #if defined(CFG_ARC_ECUM_NVM_READ_INIT) && defined(USE_FEE) EcuM_Arc_InitFeeReadAdminBlock(tickTimerStart, EcuM_World.config->EcuMNvramReadAllTimeout); #endif TickType tickTimerElapsed; Std_ReturnType status; do { /* Read the multiblock status */ status = NvM_GetErrorStatus(0, &readAllResult); tickTimerElapsed = OS_TICKS2MS_OS_TICK(GetOsTick() - tickTimerStart); #if defined(CFG_ARC_ECUM_NVM_READ_INIT) EcuM_Arc_InitMemReadAllMains(); #endif /* The timeout EcuMNvramReadAllTimeout is in ms */ } while( (readAllResult == NVM_REQ_PENDING) && (tickTimerElapsed < EcuM_World.config->EcuMNvramReadAllTimeout) ); if(status!=E_OK) { ECUM_DET_REPORT_ERROR(ECUM_STARTUPTWO_ID, ECUM_E_ARC_TIMERERROR); } #endif /* USE_NVM */ /* Initialize drivers that need NVRAM data for QM paritition */ EcuM_AL_DriverInitThree_Partition_QM(EcuM_World.config); } }
2301_81045437/classic-platform
system/EcuM/src/EcuM_QM.c
C
unknown
12,827
/*-------------------------------- 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_EcuM_02990*/ /* @req SWS_EcuMf_00028 Integration functions should be placed in callout functions. */ /* ----------------------------[includes]------------------------------------*/ //lint -emacro(9036,VALIDATE_STATE) #include "EcuM.h" #include "EcuM_Generated_Types.h" #include "isr.h" /* @req SWS_BSW_00152 */ /* ----------------------------[private define]------------------------------*/ /* Does not run functions that are not drivers */ #if defined(USE_ECUM_FIXED) #define VALIDATE_STATE(_state) \ do { \ EcuM_StateType ecuMState; \ if (E_OK != EcuM_GetState(&ecuMState)) { \ ASSERT(0); \ } \ ASSERT(ecuMState == (_state) ); \ } while(0) #else #define VALIDATE_STATE(_state) #endif /* ----------------------------[private macro]-------------------------------*/ /* ----------------------------[private typedef]-----------------------------*/ /* ----------------------------[private function prototypes]-----------------*/ /* ----------------------------[private variables]---------------------------*/ /* ----------------------------[private functions]---------------------------*/ /* ----------------------------[public functions]----------------------------*/ #if defined(USE_ECUM_FIXED) #if (ECUM_ARC_SAFETY_PLATFORM == STD_ON) /** * At this point OS and essential drivers have started. * Start the rest of the drivers * * * Part of STARTUP II * * @param ConfigPtr */ void EcuM_AL_DriverInitTwo_Partition_QM(const EcuM_ConfigType* ConfigPtr) { (void)ConfigPtr; /*lint !e920 MISRA:FALSE_POSITIVE:Allowed to cast pointer to void here:[MISRA 2012 Rule 1.3, required]*/ #if defined(USE_SPI) Spi_Init(ConfigPtr->SpiConfigPtr); // Setup SPI #endif #if defined(USE_EEP) Eep_Init(ConfigPtr->EepConfigPtr); // Setup EEP #endif #if defined(USE_FLS) Fls_Init(ConfigPtr->FlsConfigPtr); // Setup Flash #endif #if defined(USE_FEE) Fee_Init(); // Setup FEE #endif #if defined(USE_EA) Ea_Init(); // Setup EA #endif #if defined(USE_NVM) NvM_Init(); // Setup NVRAM Manager and start the read all job NvM_ReadAll(); #endif #if defined(USE_LIN) Lin_Init(ConfigPtr->LinConfigPtr); // Setup Lin driver #endif #if defined(USE_LINIF) LinIf_Init(ConfigPtr->LinIfConfigPtr); // Setup LinIf #endif #if defined(USE_LINSM) LinSM_Init(ConfigPtr->LinSMConfigPtr); // Setup LinSM #endif #if defined(USE_CANTRCV) // Setup Can transceiver driver CanTrcv_Init(ConfigPtr->PostBuildConfig->CanTrcvConfigPtr); #endif #if defined(USE_CAN) Can_Init(ConfigPtr->PostBuildConfig->CanConfigPtr); // Setup Can driver #endif #if defined(USE_FR) Fr_Init(ConfigPtr->FrConfigPtr); // Setup Flexray CC driver #endif #if defined(USE_CANIF) CanIf_Init(ConfigPtr->PostBuildConfig->CanIfConfigPtr); // Setup CanIf #endif #if defined(USE_FRIF) FrIf_Init(ConfigPtr->FrIfConfigPtr); // Setup Flexray Interface #endif #if defined(USE_CANTP) CanTp_Init(ConfigPtr->PostBuildConfig->CanTpConfigPtr); // Setup CAN TP #endif #if defined(USE_FRTP) FrTp_Init(ConfigPtr->FrTpConfigPtr); // Setup Flexray TP #endif #if defined(USE_CANSM) CanSM_Init(ConfigPtr->CanSMConfigPtr); #endif #if defined(USE_FRSM) FrSM_Init(ConfigPtr->FrSMConfigPtr); // Setup Flexray SM #endif #if defined(USE_ETHIF) // Setup EthIf before Eth & EthTrcv EthIf_Init(ConfigPtr->EthIfConfigPtr); #endif #if defined(USE_ETH) Eth_Init(ConfigPtr->EthConfigPtr); // Setup Eth #endif #if defined(USE_ETHIF) EthIf_Init(ConfigPtr->EthIfConfigPtr); // Setup Eth If #endif #if defined(USE_ETHSM) EthSM_Init(); // Setup Eth SM #endif #if defined(USE_TCPIP) TcpIp_Init(ConfigPtr->TcpIpConfigPtr); // Setup Tcp Ip #endif #if defined(USE_J1939TP) J1939Tp_Init(ConfigPtr->J1939TpConfigPtr); // Setup J1939Tp #endif #if defined(USE_SOAD) SoAd_Init(ConfigPtr->SoAdConfigPtr); // Setup Socket Adaptor #endif #if defined(USE_SD) Sd_Init(ConfigPtr->SdConfigPtr); // Setup Service Discovery #endif #if defined(USE_LDCOM) LdCom_Init(ConfigPtr->LdComConfigPtr); // Setup Large Data Com #endif #if defined(USE_PDUR) PduR_Init(ConfigPtr->PostBuildConfig->PduRConfigPtr); // Setup PDU Router #endif #if defined(USE_OSEKNM) OsekNm_Init(ConfigPtr->OsekNmConfigPtr); // Setup Osek Network Manager #endif #if defined(USE_CANNM) CanNm_Init(ConfigPtr->PostBuildConfig->CanNmConfigPtr); // Setup Can Network Manager #endif #if defined(USE_FRNM) FrNm_Init(ConfigPtr->FrNmConfigPtr); // Setup Flexray Network Manager #endif #if defined(USE_UDPNM) UdpNm_Init(ConfigPtr->UdpNmConfigPtr); // Setup Udp Network Manager #endif #if defined(USE_NM) Nm_Init(); // Setup Network Management Interface #endif #if defined(USE_COM) Com_Init(ConfigPtr->PostBuildConfig->ComConfigPtr); // Setup COM layer #endif #if defined(USE_DCM) Dcm_Init(ConfigPtr->DcmConfigPtr); // Setup DCM #endif #if defined(USE_IOHWAB) IoHwAb_Init(); // Setup IO hardware abstraction layer #endif #if defined(USE_XCP) Xcp_Init(ConfigPtr->XcpConfigPtr); // Setup XCP #endif #if defined(USE_ETHTSYN) // Setup EthTSyn EthTSyn_Init(ConfigPtr->EthTSynConfigPtr); #endif #if defined(USE_STBM) // Setup StbM StbM_Init(ConfigPtr->StbMConfigPtr); #endif } /** * Part of STARTUP II * * @param ConfigPtr */ void EcuM_AL_DriverInitThree_Partition_QM(const EcuM_ConfigType* ConfigPtr) { (void)ConfigPtr; /*lint !e920 MISRA:FALSE_POSITIVE:Allowed to cast pointer to void here:[MISRA 2012 Rule 1.3, required]*/ #if defined(USE_FIM) // Setup Function Inhibition Manager #if (FIM_POSTBUILD_MODE == STD_ON) FiM_Init(ConfigPtr->PostBuildConfig->FiMConfigPtr); #else FiM_Init(ConfigPtr->FiMConfigPtr); #endif #endif #if defined(USE_DEM) // Setup DEM Dem_Init(); #endif #if defined(USE_DLT) Dlt_Init(ConfigPtr->DltConfigPtr); /* Needs to be done after nvram has been initialised */ #endif #if defined(USE_COMM) // Setup Communication Manager ComM_Init(ConfigPtr->PostBuildConfig->ComMConfigPtr); #endif #if defined(USE_SOMEIPXF) // Setup SomeIp Transformer SomeIpXf_Init(NULL); #endif #if defined(USE_E2EXF) // Setup E2E Transformer E2EXf_Init(NULL); #endif #if defined (USE_SECOC) SecOC_Init(ConfigPtr->SecOCConfigPtr); #endif } void EcuM_OnEnterRun_Partition_QM(void) { } void EcuM_OnExitRun_Partition_QM(void) { } void EcuM_OnExitPostRun_Partition_QM(void) { } void EcuM_OnPrepShutdown_Partition_QM(void) { } void EcuM_OnGoOffOne_Partition_QM(void) { } void EcuM_OnGoOffTwo_Partition_QM(void) { } /** * At this point OS and essential drivers have started. * Start the rest of the drivers * * * Part of STARTUP II * * @param ConfigPtr */ /*lint -save -e715 MISRA:OTHER:Symbol ConfigPtr not referenced.since this file is only an example which shall be extended by implementer if needed:[MISRA 2012 Rule 2.7, advisory] */ void EcuM_AL_DriverInitTwo_Partition_A0(const EcuM_ConfigType* ConfigPtr) { } /** * Part of STARTUP II * * @param ConfigPtr */ void EcuM_AL_DriverInitThree_Partition_A0(const EcuM_ConfigType* ConfigPtr) { } /*lint -restore -e715 */ void EcuM_OnEnterRun_Partition_A0(void) { } void EcuM_OnExitRun_Partition_A0(void) { } void EcuM_OnExitPostRun_Partition_A0(void) { } void EcuM_OnPrepShutdown_Partition_A0(void) { } void EcuM_OnGoOffOne_Partition_A0(void) { } void EcuM_OnGoOffTwo_Partition_A0(void) { } #endif // ECUM_ARC_SAFETY_PLATFORM #endif // USE_ECUM_FIXED
2301_81045437/classic-platform
system/EcuM/src/EcuM_SP_Callout_Stubs.c
C
unknown
8,692
/*-------------------------------- 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 */ /** @fileSafetyClassification ASIL **/ /* Common file for safety platform */ #ifndef ECUM_SP_COMMON_H_ #define ECUM_SP_COMMON_H_ extern uint32 EcuM_World_run_state_timeout; #if defined (USE_NVM) extern uint32 EcuM_World_go_off_one_state_timeout; extern NvM_RequestResultType writeAllResult; #endif static inline boolean hasRunRequests(void){ uint32 result = EcuM_World.run_requests; #if defined(USE_COMM) result |= EcuM_World_ComM_NVM.run_comm_requests; #endif return ((result != 0) ? TRUE : FALSE); } static inline boolean hasPostRunRequests(void){ return ((EcuM_World.postrun_requests != 0) ? TRUE : FALSE); } #endif /* ECUM_SP_COMMON_H_ */
2301_81045437/classic-platform
system/EcuM/src/EcuM_SP_common.h
C
unknown
1,515
# LinuxOs obj-$(USE_LINUXOS) += Os_Cfg.o sys_tick.o os_linos.o linos_logger.o linos_time.o os_main.o os_stubs.o obj-$(USE_LINUXOS) += pmc_sync_status_common.o pmc_sync_status_reader.o obj-$(USE_LINUXOS) += os_task_linos.o arch.o LinuxOs_StbM.o obj-$(USE_LINUXOS) += os_counter_linos.o os_alarm_linos.o os_init_linos.o os_event_linos.o inc-$(USE_LINUXOS) += $(ROOTDIR)/$(OSAL_ARCH)/gnulinux/gnulinux/kernel vpath-$(USE_LINUXOS) += $(ROOTDIR)/$(OSAL_ARCH)/gnulinux/gnulinux/kernel vpath-$(USE_LINUXOS) += $(ROOTDIR)/mcal/Mcu/src inc-$(USE_LINUXOS) += $(ROOTDIR)/system/LinuxOs/inc inc-$(USE_LINUXOS) += $(ROOTDIR)/system/LinuxOs/src inc-$(USE_LINUXOS) += $(ROOTDIR)/system/LinuxOs/pmc_sync_status_reader inc-$(USE_LINUXOS) += $(ROOTDIR)/system/StbM inc-$(USE_LINUXOS) += $(ROOTDIR)/system/Os/rtos/inc inc-$(USE_LINUXOS) += $(ROOTDIR)/system/Os/rtos/integration inc-$(USE_LINUXOS) += $(ROOTDIR)/system/Os/rtos/src vpath-$(USE_LINUXOS) += $(ROOTDIR)/system/LinuxOs/src vpath-$(USE_LINUXOS) += $(ROOTDIR)/system/LinuxOs/pmc_sync_status_reader CFLAGS += -D__PROGNAME__=\"$(PROJECTNAME)\" # Antons ADPM project doesn't use the MCU module, but needs Mcu.o ifndef USE_MCU obj-$(USE_LINUXOS) += Mcu_gnulinux.o endif # # RedHat 6 and Centos 6 and Ubuntu 12 # needs the RealTime library to be defined. (GCC 4.8) ifneq ($(OS),Windows_NT) ifdef USE_LINUXOS LDFLAGS += -lrt LDFLAGS += -lm endif endif # Ubuntu 12 needs this too. #LDFLAGS += -Wl,--no-as-needed ifneq ($(OS),Windows_NT) # Database module obj-$(USE_LINUXOS_DB) += database.o #Sqlite3 devel library needed for this. ifdef USE_LINUXOS_DB LDFLAGS += -lsqlite3 endif # endif
2301_81045437/classic-platform
system/LinuxOs/LinuxOs.mod.mk
Makefile
unknown
1,719
/*-------------------------------- 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 LINUXOS_STBM_H_ #define LINUXOS_STBM_H_ #include "Rte_Type.h" #include <Rte_StbM_Type.h> /* @req 4.2.2/SWS_StbM_00052 */ void Linos_StbM_Init(); /* Deviation from @req 4.2.2/SWS_StbM_00233: added two parameters. */ Std_ReturnType Linos_StbM_BusSetGlobalTime(StbM_SynchronizedTimeBaseType timeBaseId, const StbM_TimeStampType* timeStampPtr, const StbM_UserDataType* userDataPtr, boolean syncToTimeBase, int ptp_in_sync, float ptp_offset); /* @req 4.2.2/SWS_StbM_00195 */ Std_ReturnType Linos_StbM_GetCurrentTime( StbM_SynchronizedTimeBaseType timeBaseId, StbM_TimeStampType* timeStampPtr, StbM_UserDataType* userDataPtr); #endif /* LINUXOS_STBM_H_ */
2301_81045437/classic-platform
system/LinuxOs/inc/LinuxOs_StbM.h
C
unknown
1,474
/*-------------------------------- 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 "pmc_sync_status_common.h" #ifndef _WIN32 #include <stdio.h> #include <unistd.h> #include <errno.h> #include "linos_logger.h" /* Returns 1 on success and 0 on failure. */ int init_uds_skt_addr( const char *uds_skt_pathname, struct sockaddr_un *uds_skt_addr) { if (uds_skt_pathname == NULL || strlen(uds_skt_pathname) == 0 || uds_skt_addr == NULL) { logger(LOG_ERR, "failed to initialize address for UNIX domain socket, " "invalid parameters."); return 0; } memset(uds_skt_addr, 0, sizeof(*uds_skt_addr)); uds_skt_addr->sun_family = AF_UNIX; strcpy(uds_skt_addr->sun_path, uds_skt_pathname); return 1; } #endif
2301_81045437/classic-platform
system/LinuxOs/pmc_sync_status_reader/pmc_sync_status_common.c
C
unknown
1,491
/*-------------------------------- 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 PMC_SYNC_STATUS_COMMON_H_ #define PMC_SYNC_STATUS_COMMON_H_ #ifndef _WIN32 #include <sys/socket.h> #include <sys/un.h> #endif typedef struct collective_sync_status { int in_sync; float offsetFromMaster; } collective_sync_status; /* sync_status server UNIX domain socket. */ #define SYNC_STATUS_UDS "/tmp/ptp_sync_status.uds" /* Returns 1 on success and 0 on failure. */ int init_uds_skt_addr( const char *uds_skt_pathname, struct sockaddr_un *uds_skt_addr); #endif /* PMC_SYNC_STATUS_COMMON_H_ */
2301_81045437/classic-platform
system/LinuxOs/pmc_sync_status_reader/pmc_sync_status_common.h
C
unknown
1,300
/*-------------------------------- 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 "pmc_sync_status_reader.h" #include "linos_logger.h" #ifndef _WIN32 /* Not POSIX, but needed for debugging using pthread_setname_np */ #define __USE_GNU #include <pthread.h> #endif int init_sync_status_reader() { #ifndef _WIN32 if (!init_uds_skt_addr((const char *) SYNC_STATUS_UDS, &sync_status_uds_skt_addr)) { logger(LOG_ERR, "failed to initialize UNIX domain socket address."); return 0; } #endif return 1; } #ifndef _WIN32 pthread_mutex_t mutex_sync_status_reader_conn; #endif sync_status_reader_conn_state conn_state = SYNC_STATUS_TEMP_DISCONNECTED; sync_status_reader_conn_state connect_sync_status_reader() { sync_status_reader_conn_state ret_state; #ifndef _WIN32 pthread_mutex_lock(&mutex_sync_status_reader_conn); if (conn_state != SYNC_STATUS_PERM_DISCONNECTED) { reader_uds_skt = socket(AF_UNIX, SOCK_STREAM, 0); int conn_rslt = connect(reader_uds_skt, (const struct sockaddr *) &sync_status_uds_skt_addr, (socklen_t) sizeof(sync_status_uds_skt_addr)); if (conn_rslt == -1) { conn_state = SYNC_STATUS_TEMP_DISCONNECTED; close(reader_uds_skt); logger(LOG_ERR, "failed to connect to sync_status UNIX domain socket %s" ", error: %d\n", (const char *) SYNC_STATUS_UDS, errno); } else { conn_state = SYNC_STATUS_CONNECTED; logger(LOG_INFO, "sync_status reader connected\n"); } } ret_state = conn_state; pthread_mutex_unlock(&mutex_sync_status_reader_conn); #endif return ret_state; } void disconnect_sync_status_reader(int close_permanently) { #ifndef _WIN32 pthread_mutex_lock(&mutex_sync_status_reader_conn); /* Design note: * ------------ * To ensure the correctness of the system, disconnect_sync_status_reader * may only set conn_state to SYNC_STATUS_PERM_DISCONNECTED and never * allows setting it to SYNC_STATUS_TEMP_DISCONNECTED. */ if (close_permanently) conn_state = SYNC_STATUS_PERM_DISCONNECTED; /* The socket is closed for both temporary and permanent closure. */ close(reader_uds_skt); pthread_mutex_unlock(&mutex_sync_status_reader_conn); #endif }
2301_81045437/classic-platform
system/LinuxOs/pmc_sync_status_reader/pmc_sync_status_reader.c
C
unknown
3,132
/*-------------------------------- 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 PMC_SYNC_STATUS_READER_H_ #define PMC_SYNC_STATUS_READER_H_ #ifndef _WIN32 #include <stdio.h> #include <unistd.h> #include <errno.h> #include "pmc_sync_status_common.h" #endif typedef enum { SYNC_STATUS_CONNECTED, SYNC_STATUS_TEMP_DISCONNECTED, SYNC_STATUS_PERM_DISCONNECTED } sync_status_reader_conn_state; #ifndef _WIN32 struct sockaddr_un sync_status_uds_skt_addr; int reader_uds_skt; int init_sync_status_reader(); sync_status_reader_conn_state connect_sync_status_reader(); void disconnect_sync_status_reader(int close_permanently); #endif #endif /* PMC_SYNC_STATUS_READER_H_ */
2301_81045437/classic-platform
system/LinuxOs/pmc_sync_status_reader/pmc_sync_status_reader.h
C
unknown
1,389
/*-------------------------------- 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 "LinuxOs_StbM.h" #include "Std_Types.h" #include "linos_logger.h" /* Logger functions */ #include "linos_time.h" #include "Os.h" #ifndef _WIN32 /* Not POSIX, but needed for debugging using pthread_setname_np */ #define __USE_GNU #include <pthread.h> #include <math.h> #endif typedef enum { NEVER_SYNCED, SYNCED } synced_flag; /* Copied from core/system/StbM/StbM.c */ #define StbM_SET_BIT(byte,mask) ((byte) |= (mask)) #define StbM_CLR_BIT(byte,mask) ((byte) &= (~mask)) #define StbM_GET_BIT(byte,mask) (byte & (mask)) /* Copied from core/system/StbM/StbM.c */ #define STBM_TIMEOUT_MASK 0x01u #define STBM_TIMELEAP_MASK 0x02u #define STBM_SYNC_TO_GATEWAY_MASK 0x04u #define STBM_GLOBAL_TIME_BASE_MASK 0x08u /* @req 4.2.2/SWS_StbM_00241 */ #define STMB_MAX_NSECS 0x3B9AC9FF #define STMB_MAX_SECS_HI 0xFFFF /* Synchronization for: */ /* @req 4.2.2/SWS_StbM_00052 */ /* @req 4.2.2/SWS_StbM_00195 */ /* @req 4.2.2/SWS_StbM_00233 */ #ifndef _WIN32 pthread_mutex_t mutex_linos_StbM_Init; #endif /* @req 4.2.2/SWS_StbM_00100 */ static int StbM_Initialized = 0; /* @req 4.2.2/ECUC_StbM_00028 */ typedef float EcucFloatParamDef; /* @req 4.2.2/ECUC_StbM_00028 */ /* Unit: seconds. * Set to a 2 seconds to allow a maximum of one missed update to the slowest * version of the gptp, IEEE 1588-2002, which sends synchronization messages * every 1 second. */ const EcucFloatParamDef StbMSyncLossTimeout = 2; /* Read explanation above. */ /* Synchronization for: */ /* @req 4.2.2/SWS_StbM_00052 */ /* @req 4.2.2/SWS_StbM_00195 */ /* @req 4.2.2/SWS_StbM_00233 */ #ifndef _WIN32 pthread_mutex_t mutex_linos_StbM_Status; #endif typedef struct collective_linos_StbM_Status { #ifndef _WIN32 struct timespec last_StbM_BusSetGlobalTime; #endif int ptp_in_sync; float ptp_offset; synced_flag is_ever_synced; StbM_TimeBaseStatusType timeBaseStatus; } collective_linos_StbM_Status; collective_linos_StbM_Status linos_StbM_Status; #ifndef _WIN32 const int sizeof__time_t = sizeof(__time_t); #endif #define LINOS_STBM_LOG_PREFIX "linos_StbM: " /* Maximum offset from PTP master is based on OsTickFreq */ #define MSEC_TICK 1000/OsTickFreq #define NSEC_TICK MSEC_TICK*1000000 /* deviation from @req 4.2.2/SWS_StbM_00250, no parameter to StbM_Init. Anyway, it is alwyas null an not used. */ /* @req 4.2.2/SWS_StbM_00052 */ void Linos_StbM_Init() { #ifndef _WIN32 /** * Design note: two lock to allow other StbM functions to do tasks between * the check that StbM is initialized and doing status updates. * * However, we use the two lock in order in all functions. */ /* Setting the initialization flag. */ pthread_mutex_lock(&mutex_linos_StbM_Init); /* Those are the only two sizeof(__time_t) that we can handle. */ if (sizeof__time_t == 4 || sizeof__time_t == 8) { /* @req 4.2.2/SWS_StbM_00121 */ StbM_Initialized = 1; } else { logger(LOG_ERR, "%s StbM_Init failed, " "can only handle __time_t of sizes 4 and 8.", LINOS_STBM_LOG_PREFIX); // Do not return, see implemented requirements and Design note above. } pthread_mutex_unlock(&mutex_linos_StbM_Init); /* Anyway, we have to set timeBaseStatus to 0*/ /* @req 4.2.2/SWS_StbM_00170*/ pthread_mutex_lock(&mutex_linos_StbM_Status); linos_StbM_Status.last_StbM_BusSetGlobalTime.tv_nsec = 0; linos_StbM_Status.last_StbM_BusSetGlobalTime.tv_sec = 0; linos_StbM_Status.ptp_in_sync = 0; linos_StbM_Status.ptp_offset = 0xFFFFFFFF; linos_StbM_Status.is_ever_synced = NEVER_SYNCED; linos_StbM_Status.timeBaseStatus = 0; pthread_mutex_unlock(&mutex_linos_StbM_Status); #endif } Std_ReturnType Linos_StbM_BusSetGlobalTime(StbM_SynchronizedTimeBaseType timeBaseId, const StbM_TimeStampType* timeStampPtr, const StbM_UserDataType* userDataPtr, boolean syncToTimeBase, int ptp_in_sync, float ptp_offset) { #ifndef _WIN32 /** * Design note: two lock to allow other StbM functions to do tasks between * the check that StbM is initialized and doing status updates. * * However, we use the two lock in order in all functions. */ Std_ReturnType retValue = E_OK; /* Checking the initialization flag. */ pthread_mutex_lock(&mutex_linos_StbM_Init); retValue = E_OK; if (!StbM_Initialized) { retValue = E_NOT_OK; } pthread_mutex_unlock(&mutex_linos_StbM_Init); if (retValue != E_OK) { logger(LOG_ERR, "%s Linos_StbM_BusSetGlobalTime failed, StbM is not initialized.", LINOS_STBM_LOG_PREFIX); return retValue; } ptp_offset = fabsf(ptp_offset); logger(LOG_DEBUG, "Linos_StbM_BusSetGlobalTime got ptp (in-sync, offset):" " (%d, %f)", ptp_in_sync, ptp_offset); /* For update timeout measurement, get the time from the monotonic clock. */ /* We do this outside the mutex locking block below. */ struct timespec current_time; clock_gettime(CLOCK_MONOTONIC, &current_time); pthread_mutex_lock(&mutex_linos_StbM_Status); linos_StbM_Status.last_StbM_BusSetGlobalTime.tv_nsec = current_time.tv_nsec; linos_StbM_Status.last_StbM_BusSetGlobalTime.tv_sec = current_time.tv_sec; linos_StbM_Status.ptp_in_sync = ptp_in_sync; linos_StbM_Status.ptp_offset = ptp_offset; if (ptp_in_sync && linos_StbM_Status.is_ever_synced == NEVER_SYNCED) { linos_StbM_Status.is_ever_synced = SYNCED; /* @req 4.2.2/SWS_StbM_00185 */ StbM_SET_BIT(linos_StbM_Status.timeBaseStatus, STBM_GLOBAL_TIME_BASE_MASK); } pthread_mutex_unlock(&mutex_linos_StbM_Status); return retValue; #else return E_OK; #endif } /* @req 4.2.2/SWS_StbM_00195 */ Std_ReturnType Linos_StbM_GetCurrentTime(StbM_SynchronizedTimeBaseType timeBaseId, StbM_TimeStampType* timeStampPtr, StbM_UserDataType* userDataPtr ) { #ifndef _WIN32 /** * Design note: two lock to allow other StbM functions to do tasks between * the check that StbM is initialized and doing status updates. * * However, we use the two lock in order in all functions. */ Std_ReturnType retValue = E_OK; /* Checking the initialization flag. */ pthread_mutex_lock(&mutex_linos_StbM_Init); if (!StbM_Initialized) { retValue = E_NOT_OK; /* Avoid to return while locking the mutex. */ } pthread_mutex_unlock(&mutex_linos_StbM_Init); if (retValue != E_OK) { logger(LOG_ERR, "%s Linos_StbM_GetCurrentTime failed, StbM is not initialized.", LINOS_STBM_LOG_PREFIX); return retValue ; } struct timespec tpsys; retValue = Linos_GetCurrentTime(&tpsys); /* @req 4.2.2/SWS_StbM_00199 */ /* On error, return without touching the parameters. */ if (retValue != E_OK) { logger(LOG_ERR, "%s Linos_StbM_GetCurrentTime failed, Error getting system time.", LINOS_STBM_LOG_PREFIX); /*Improvement: review AUTOSAR error handling requirements. */ return retValue; } /* @req 4.2.2/SWS_StbM_00199 */ /* On error, return without touching the parameters. */ if ((tpsys.tv_nsec < 0) || (tpsys.tv_sec < 0)) { logger(LOG_ERR, "%s Linos_StbM_GetCurrentTime failed, Negative system time.", LINOS_STBM_LOG_PREFIX); /* Improvement: review AUTOSAR error handling requirements. */ return E_NOT_OK ; } /* @req 4.2.2/SWS_StbM_00241 */ uint32 tpsys_secondsHi = 0; if (sizeof__time_t == 8) { /* Bit wise shifting must be within variable size. */ tpsys_secondsHi = (tpsys.tv_sec >> 32) & 0xFFFFFFFF; } if (tpsys.tv_nsec <= STMB_MAX_NSECS && tpsys_secondsHi <= STMB_MAX_SECS_HI) { timeStampPtr->nanoseconds = tpsys.tv_nsec & 0xFFFFFFFF; timeStampPtr->seconds = tpsys.tv_sec & 0xFFFFFFFF; timeStampPtr->secondsHi = tpsys_secondsHi & 0xFFFF; } else { /* @req 4.2.2/SWS_StbM_00199 */ /* On error, return without touching the parameters. */ logger(LOG_ERR, "%s Linos_StbM_GetCurrentTime failed, Invalid system time.", LINOS_STBM_LOG_PREFIX); /* Improvement review AUTOSAR error handling requirements. */ return E_NOT_OK ; } /* For update timeout measurement, get the time from the monotonic clock. */ /* We do this outside the mutex locking block below. */ struct timespec current_time; clock_gettime(CLOCK_MONOTONIC, &current_time); /* @req 4.2.2/SWS_StbM_00195 */ pthread_mutex_lock(&mutex_linos_StbM_Status); /* Starting with TIMEOUT bit as set, covering: * 1. StbM_BusSetGlobalTime is never called. * 2. Not in_sync with ptp master. * 3. An overlapping MONTONIC clock. * 4. Timed out since last invocation of StbM_BusSetGlobalTime. */ StbM_SET_BIT(linos_StbM_Status.timeBaseStatus, STBM_TIMEOUT_MASK); struct timespec time_since_last_StbM_BusSetGlobalTime; /* StbMSyncLossTimeout is defined in seconds, so we skip the nsec. */ time_since_last_StbM_BusSetGlobalTime.tv_nsec = 0; time_since_last_StbM_BusSetGlobalTime.tv_sec = current_time.tv_sec - linos_StbM_Status.last_StbM_BusSetGlobalTime.tv_sec; if (linos_StbM_Status.is_ever_synced != NEVER_SYNCED && linos_StbM_Status.ptp_in_sync && time_since_last_StbM_BusSetGlobalTime.tv_sec >= 0 && time_since_last_StbM_BusSetGlobalTime.tv_sec < StbMSyncLossTimeout) { /* Clearing the TIMEOUT bit. */ StbM_CLR_BIT(linos_StbM_Status.timeBaseStatus, STBM_TIMEOUT_MASK); } /* Starting wit the STBM_TIMELEAP_MASK as set. */ StbM_SET_BIT(linos_StbM_Status.timeBaseStatus, STBM_TIMELEAP_MASK); if (linos_StbM_Status.ptp_offset < NSEC_TICK) StbM_CLR_BIT(linos_StbM_Status.timeBaseStatus, STBM_TIMELEAP_MASK); timeStampPtr->timeBaseStatus = linos_StbM_Status.timeBaseStatus; pthread_mutex_unlock(&mutex_linos_StbM_Status); logger(LOG_DEBUG, "%s Linos_StbM_GetCurrentTime (timeBaseStatus, lastUpdate): (0x%x, %lld)", LINOS_STBM_LOG_PREFIX, timeStampPtr->timeBaseStatus, (long long)time_since_last_StbM_BusSetGlobalTime.tv_sec); return retValue; #else return E_OK; #endif }
2301_81045437/classic-platform
system/LinuxOs/src/LinuxOs_StbM.c
C
unknown
11,485
/*-------------------------------- 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 <stdio.h> #include <string.h> #include "database.h" #include "linos_logger.h" // Logger function #ifndef _WIN32 sqlite3 *db = 0; #endif int db_init ( char *filename ) { #ifndef _WIN32 char sql_cmd_create[] = DB_CREATE; char sql_cmd_index[] = DB_CREATE_INDEX; char sql_cmd_trigger[] = DB_CREATE_TRIGGER; char sql_cmd_check[] = DB_CHECK; char *reply = 0; if ( db ) return DB_FAIL_EXISTS; if ( sqlite3_open ( filename, &db ) ) { db = 0; return DB_FAIL_OPEN; } // Busy timeout. Waits a while on DB locked sqlite3_busy_timeout(db, DB_BUSY_TIMEOUT); // mS // // If modbus table missing, then create it. if ( sqlite3_exec ( db, sql_cmd_check, 0, 0, &reply ) != SQLITE_OK ) { logger_mod((LOGGER_MOD_LINOS|LOGGER_SUB_OS_DATABASE), LOG_INFO, "DB Creating arccore_cal DB in file %s\n",filename); if ( sqlite3_exec ( db, sql_cmd_create, 0, 0, &reply ) != SQLITE_OK ) { logger(LOG_ERR, "ERROR: DB CREATE: Sqlite3: %s\n", reply); logger(LOG_ERR, "\n SQL was: %s\n", sql_cmd_create); sqlite3_close ( db ); db = 0; return DB_FAIL_CREATE; } if ( sqlite3_exec ( db, sql_cmd_index, 0, 0, &reply ) != SQLITE_OK ) { logger(LOG_ERR,"ERROR: DB create index Sqlite3: %s\n", reply); logger(LOG_ERR, "\n SQL was: %s\n", sql_cmd_index); sqlite3_close ( db ); db = 0; return DB_FAIL_CREATE; } if ( sqlite3_exec ( db, sql_cmd_trigger, 0, 0, &reply ) != SQLITE_OK ) { logger(LOG_ERR, "ERROR: DB create trigger Sqlite3: %s\n", reply); logger(LOG_ERR, "\n SQL was: %s\n", sql_cmd_trigger); sqlite3_close ( db ); db = 0; return DB_FAIL_CREATE; } } #endif return DB_OK; } // END db_init int callback_print_sql_result(char *NotUsed, int argc, char **argv, char **azColName){ int i; NotUsed=0; logger_mod((LOGGER_MOD_LINOS|LOGGER_SUB_OS_DATABASE), LOG_INFO, "callback_print_sql_result"); for(i=0; i<argc; i++){ printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL"); } printf("\n"); return 0; } int db_get_register ( int register_address, int number_of_registers, int (*callback)(char *, int, char **, char **)) { #ifndef _WIN32 char sql_cmd_get_reg[255]; char tmp_sql_cmd_get_reg[50]; char *reply = NULL; int rc=0; if (!db) return DB_FAIL_EXISTS; tmp_sql_cmd_get_reg[0] = '\0'; snprintf(sql_cmd_get_reg, sizeof(sql_cmd_get_reg), DB_GET_REGISTER, DB_GET_SELECT, register_address, register_address, number_of_registers, tmp_sql_cmd_get_reg); //logger(LOG_DEBUG, "SQL DB_GET_REGISTER [%s]\n", sql_cmd_get_reg); rc = sqlite3_exec(db, sql_cmd_get_reg, (sqlite3_callback) callback, NULL, &reply); if ( rc != SQLITE_OK ) { logger(LOG_ERR, "DB GET REGISTER Sqlite3 error[%d]: %s\n", rc, reply); return DB_FAIL_SELECT; } #endif return DB_OK; } /** * * db_touch_register * * * Updates the timestamp for a register in the database. * * PARAMS: int register_address, int create_missing=0, int force_write=0 * * register_address ECU register address. * * register_value ECU register value. * * create_missing If = 1 then create missing registers, by INSERT (REPLACE) * * force_write IF = 1 then write to register even if writeable = 0 (readonly) * */ int db_touch_register ( int register_address, int create_missing, int force_write, int writeable ) { #ifndef _WIN32 char sql_cmd_touch_reg[255]; char end_sql[25]; char *reply = 0; int rc, num_of_rows; if (!db) return DB_FAIL_EXISTS; if ( force_write == 1 ) { end_sql[0] = '\0'; } else { strcpy( end_sql, DB_UPDATE_NO_FORCE_REGISTER); } snprintf(sql_cmd_touch_reg, 255, DB_TOUCH_REGISTER, register_address, end_sql); logger_mod((LOGGER_MOD_LINOS|LOGGER_SUB_OS_DATABASE), LOG_DEBUG, "SQL DB_TOUCH_REGISTER [%s]\n", sql_cmd_touch_reg); rc = sqlite3_exec(db, sql_cmd_touch_reg, 0, 0, &reply); if ( rc != SQLITE_OK ) { logger(LOG_ERR, "ERROR: DB TOUCH REGISTER Sqlite3 error[%d]: %s\n", rc, reply); return DB_FAIL_INSERT; } else { // Check that there was a row changed // otherwise try SET (REPLACE) num_of_rows = sqlite3_changes(db); if ( num_of_rows != 1 ) { if ( create_missing == 1 ) { // Update didn't work try SET (REPLACE) snprintf(sql_cmd_touch_reg, 255, DB_SET_REGISTER, 0, register_address, writeable); rc = sqlite3_exec(db, sql_cmd_touch_reg, 0, 0, &reply); if ( rc != SQLITE_OK ) { // SET failed logger(LOG_ERR, "ERROR: DB TOUCH REGISTER Sqlite3 error[%d]: %s\n", rc, reply); return DB_FAIL_INSERT; } } } } #endif return DB_OK; } // END db_touch_register /** * * db_inc_register * * Increment an ECU register value in the database. * * PARAMS: int register_address, int register_inc_value, int create_missing=0, int force_write=0 * * register_address ECU register address. * * register_inc_value How much to increment the ECU register value. * * create_missing If = 1 then create missing registers, by INSERT (REPLACE) * * force_write IF = 1 then write to register even if writeable = 0 (readonly) */ int db_inc_register ( int register_address, int register_inc_value, int create_missing, int force_write, int writeable ) { #ifndef _WIN32 char sql_cmd_set_reg[255]; char end_sql[25]; char *reply = 0; int rc, num_of_rows; if (!db) return DB_FAIL_EXISTS; if ( force_write == 1 ) { end_sql[0] = '\0'; } else { strcpy( end_sql, DB_UPDATE_NO_FORCE_REGISTER); } snprintf(sql_cmd_set_reg, 255, DB_INC_REGISTER, register_inc_value, register_address, end_sql); //logger(LOG_DEBUG, "SQL DB_INC_REGISTER [%s]\n", sql_cmd_set_reg); rc = sqlite3_exec(db, sql_cmd_set_reg, 0, 0, &reply); if ( rc != SQLITE_OK ) { logger(LOG_ERR, "ERROR: DB INC REGISTER Sqlite3 error[%d]: %s\n", rc, reply); return DB_FAIL_INSERT; } else { // Check that there was a row changed // otherwise try SET (REPLACE) num_of_rows = sqlite3_changes(db); if ( num_of_rows != 1 ) { if ( create_missing == 1 ) { // Update didn't work try SET (REPLACE) snprintf(sql_cmd_set_reg, 255, DB_SET_REGISTER, register_inc_value, register_address, writeable); rc = sqlite3_exec(db, sql_cmd_set_reg, 0, 0, &reply); if ( rc != SQLITE_OK ) { // SET failed logger(LOG_ERR, "ERROR: DB INC REGISTER Sqlite3 error[%d]: %s\n", rc, reply); return DB_FAIL_INSERT; } } } } #endif return DB_OK; } /** * * db_set_register * * Set an ECU register value in the database. * * PARAMS: int register_address, int register_value, int create_missing=0, int force_write=0 * * register_address ECU register address. * * register_value ECU register value. * * create_missing If = 1 then create missing registers, by INSERT (REPLACE) * * force_write IF = 1 then write to register even if writeable = 0 (readonly) */ int db_set_register ( int register_address, int register_value, int create_missing, int force_write, int writeable ) { #ifndef _WIN32 char sql_cmd_set_reg[255]; char end_sql[25]; char *reply = 0; int rc, num_of_rows; if (!db) return DB_FAIL_EXISTS; if ( force_write == 1 ) { end_sql[0] = '\0'; } else { strcpy( end_sql, DB_UPDATE_NO_FORCE_REGISTER); } snprintf(sql_cmd_set_reg, 255, DB_UPDATE_REGISTER, register_value, register_address, end_sql); logger(LOG_DEBUG, "SQL DB_SET_REGISTER [%s]\n", sql_cmd_set_reg); rc = sqlite3_exec(db, sql_cmd_set_reg, 0, 0, &reply); if ( rc != SQLITE_OK ) { logger(LOG_ERR, "ERROR: DB SET REGISTER Sqlite3 error[%d]: %s\n", rc, reply); return DB_FAIL_INSERT; } else { // Check that there was a row changed // otherwise try SET (REPLACE) num_of_rows = sqlite3_changes(db); if ( num_of_rows != 1 ) { if ( create_missing == 1 ) { // Update didn't work try SET (REPLACE) snprintf(sql_cmd_set_reg, 255, DB_SET_REGISTER, register_value, register_address, writeable); rc = sqlite3_exec(db, sql_cmd_set_reg, 0, 0, &reply); if ( rc != SQLITE_OK ) { // SET failed logger(LOG_ERR, "ERROR: DB SET REGISTER Sqlite3 error[%d]: %s\n", rc, reply); return DB_FAIL_INSERT; } } } } #endif return DB_OK; } int db_close ( void ) { #ifndef _WIN32 if (!db) return DB_FAIL_EXISTS; sqlite3_close ( db ); db = 0; #endif return DB_OK; }
2301_81045437/classic-platform
system/LinuxOs/src/database.c
C
unknown
10,380
/*-------------------------------- 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 _DATABASE_H #define _DATABASE_H #include <sqlite3.h> // Create requested registers not already in the database // // On a register read #define DB_CREATE_MISSING_READ 1 // On a register write #define DB_CREATE_MISSING_WRITE 1 #define DB_OK 0 #define DB_FAIL_EXISTS 1 #define DB_FAIL_OPEN 2 #define DB_FAIL_CREATE 3 #define DB_FAIL_INSERT 4 #define DB_FAIL_SELECT 5 #define DB_DEFAULT_FILE_NAME "/tmp/arccore.sqlite3" // mS Busy timeout. To allow for locked DB #define DB_BUSY_TIMEOUT 250 // #define DB_ECU_RUNTIME_REG_ADDRESS 1 #define DB_CHECK "SELECT * FROM arccore_cal" #define DB_CREATE "CREATE TABLE IF NOT EXISTS 'arccore_cal' ( \ 'registeraddress' INTEGER NOT NULL, \ 'registervalue' INTEGER NOT NULL, \ 'writeable' INTEGER NOT NULL DEFAULT (1), \ 'tagname' TEXT, 'tagdescription' TEXT, \ 'sensortimestamp' DATETIME DEFAULT CURRENT_TIMESTAMP);" #define DB_CREATE_INDEX "CREATE UNIQUE INDEX 'main'.'arccore_cal_index' ON 'arccore_cal' ('registeraddress' ASC);" #define DB_CREATE_TRIGGER "CREATE TRIGGER [UpdateLastTime] AFTER UPDATE ON arccore_cal \ FOR EACH ROW \ BEGIN \ UPDATE arccore_cal SET sensortimestamp = CURRENT_TIMESTAMP WHERE \ registeraddress = old.registeraddress; \ END" #define DB_GET_REGISTER "SELECT %s FROM arccore_cal WHERE \ registeraddress >= %d AND \ registeraddress < ( %d + %d ) \ %s \ ORDER BY registeraddress ASC;" #define DB_GET_SELECT "registeraddress, registervalue" #define DB_SET_REGISTER "REPLACE INTO arccore_cal (registervalue, registeraddress, writeable) \ VALUES (%d, %d, %d)" #define DB_UPDATE_REGISTER "UPDATE arccore_cal SET registervalue = %d WHERE registeraddress = %d %s" #define DB_UPDATE_NO_FORCE_REGISTER " AND writeable = 1" #define DB_INC_REGISTER "UPDATE arccore_cal SET registervalue = registervalue + %d WHERE registeraddress = %d %s" #define DB_TOUCH_REGISTER "UPDATE arccore_cal SET sensortimestamp = time('now') WHERE registeraddress = %d %s" // Log function IMPROVEMENT // CREATE TABLE "mlog" ("registeraddress" INTEGER NOT NULL ,"registervalue" INTEGER NOT NULL ,"tagname" TEXT,"sensortimestamp" DATETIME DEFAULT ((datetime('now','localtime'))) ) // extern int debug; // debug is set in main program. int db_init ( char *filename ); int db_get_register ( int register_address, int number_of_registers, int (*callback)(char *, int, char **, char **)); int callback_print_sql_result(char *NotUsed, int argc, char **argv, char **azColName); int db_set_register ( int register_address, int register_value, int create_missing, int force_write, int writeable ); int db_inc_register ( int register_address, int register_inc_value, int create_missing, int force_write, int writeable ); int db_touch_register ( int register_address, int create_missing, int force_write, int writeable ); int db_close ( void ); #endif
2301_81045437/classic-platform
system/LinuxOs/src/database.h
C
unknown
3,934
/*-------------------------------- 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 _ETHERNETIF_H #define _ETHERNETIF_H /* LINOS stops at the IP layer */ #endif /* _ETHERNETIF_H */
2301_81045437/classic-platform
system/LinuxOs/src/ethernetif.h
C
unknown
863
/*-------------------------------- 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 -----------------------------*/ /* * * Logger functions * * * /etc/rsyslog.conf example config rule ... * * $umask 0000 # make sure nothing interferes with the following definitions * $FileCreateMode 0644 * * $template ArcCoreLogs,"/var/log/modbus-slave.%$DAY%.log" * * if $programname == 'EthernetSimple' then -?ArcCoreLogs * if $programname == 'EthernetSimple' then stop * * AND then in cron.hourly * * # Delete /var/log/modbus-slave.*.log-files not changed in more than 24 hours: * find /var/log/ -type f -mtime +1 -name "modbus-slave*.log" -exec rm -f '{}' \; * * */ #include "linos_logger.h" #include <stdio.h> // vsprintf #include <string.h> // strlen #include <os_i.h> #include <os_sys.h> /* OS_SYS_PTR */ char log_prefix[32] = {'\0'}; // Prefix log messages /* * Regardless of using syslog or not, we define log level strings. * It will be mainly used for printing logs to stdout and stdin. * * We did not use the prioritynames in syslog.h because it appears to require * more than a simple switch statement to use. */ const char * LOG_LEVEL_STR[8] = { "LOG_EMERG", "LOG_ALERT", "LOG_CRIT", "LOG_ERR", "LOG_WARNING", "LOG_NOTICE", "LOG_INFO", "LOG_DEBUG" }; // Bit mask for outputs. bit0 = fprintf, bit 1 = syslog #ifdef USE_SYSLOG int logger_output_mask = 2; #else int logger_output_mask = 1; #endif extern int DebugMask; #ifdef USE_SYSLOG /* * * Open / close syslog * * open_close = 1 = Open * */ void logger_open_close(int open_close, char *progname) { #ifndef _WIN32 if ( open_close == 1 ) { // Open // setlogmask (LOG_UPTO (LOG_DEBUG)); // Only send more important messages than LOG_DEBUG to syslog openlog (progname, LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1); } else { // Close closelog (); } #endif } #endif /* * * Log message suffix * * */ void logger_set_prefix(char *prefix) { strncpy(log_prefix,prefix, (sizeof(log_prefix) - 1)); } /* * * Set logger output * * bit 0 = fprintp * * bit 1 = syslog ( If defined) * * RETURNS 0 on success * */ int logger_set_output(int bitMask) { int rc = 0; int syslog_enabled = 0; #ifdef USE_SYSLOG syslog_enabled = 1; #endif if ( ((bitMask & 1) == 1) && (syslog_enabled == 0) ) { rc = -1; } else { logger_output_mask = bitMask; } return rc; } void logger_mod(uint16_t logmodule, int loglevel, char *format, ... ) { #ifndef _WIN32 va_list listPointer; // Pointer to variable arguments va_start ( listPointer, format); // Set the pointer to the last fixed argument. uint16_t module,submodule; module = (( logmodule >> 8 )& 0xff) ; submodule = (logmodule & 0xff); if ( ((DebugMask >> 8)&0xff) & module) { if ( (DebugMask&0xff) & submodule ) { logger_va(loglevel, format, listPointer); } } va_end( listPointer ); #endif } /* * logger ( loglevel, *format, ...) * * WHERE: * * loglevel = priorities in syslog.h or hard coded if not using syslog * *format = is the main string with formatting. AKA printf format. * ... is an ellipsis. (varying number of args). ie. the varables for the above format. * * */ void logger ( int loglevel, char *format, ... ) { #ifndef _WIN32 va_list listPointer; // Pointer to variable arguments va_start ( listPointer, format); // Set the pointer to the last fixed argument. logger_va (loglevel, format, listPointer); va_end( listPointer ); #endif } #ifndef _WIN32 void logger_va(int loglevel, char *format, va_list listPointer) { char format_buffer[255] = {'\0'}; char print_buffer[255] = {'\0'}; // Temp string buffer char timestamp_buffer[16] = {'\0'}; snprintf(timestamp_buffer, (sizeof(timestamp_buffer) -1), "[%u]:", OS_SYS_PTR->tick); // log_prefix if ( strlen(log_prefix) > 1 ) { strcpy(print_buffer, log_prefix); strcat(print_buffer, " : "); } vsnprintf(format_buffer, (sizeof(format_buffer) -1 ), format,listPointer); // printf -> print_buffer strcat( print_buffer,timestamp_buffer); strcat( print_buffer,format_buffer); #ifdef USE_SYSLOG if ((logger_output_mask & 2) == 2) syslog (loglevel, "%s", print_buffer); #endif if ((logger_output_mask & 1) == 1) { if (loglevel > LOG_WARNING) fprintf(stdout, "%s:%s\n", LOG_LEVEL_STR[loglevel], print_buffer); else fprintf(stderr, "%s:%s\n", LOG_LEVEL_STR[loglevel], print_buffer); } } #endif /* * logger_format_hex( char* s, int slength) * * Format a character array as a hex string. * * s is a pointer to a buffer to log as hex * * slength is the length in bytes * */ char* logger_format_hex( char* s, int slength) { int bytesleft; char *iter = s; unsigned char ch; static char output_buffer[255] = {'\0'}; char* pOutputBuffer = &output_buffer[0]; char* pOutput = pOutputBuffer; if ( slength > 255 ) { slength = 255; } bytesleft = slength; while (bytesleft > 0) { ch = *iter++; if ( slength != bytesleft) { snprintf(pOutputBuffer, 2, " "); pOutputBuffer++; } bytesleft--; if( ',' != ch) { snprintf(pOutputBuffer, 3, "%.2x", ch); pOutputBuffer += 2; } else { snprintf(pOutputBuffer, 2, ","); pOutputBuffer++; } } return pOutput; }
2301_81045437/classic-platform
system/LinuxOs/src/linos_logger.c
C
unknown
6,495
/*-------------------------------- 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 _LINOS_LOGGER_H #define _LINOS_LOGGER_H #include <stdarg.h> // Optional arguments to functions #include <stdint.h> // Use Syslog ? #ifndef _WIN32 #define USE_SYSLOG #endif // // Log priorities // // If NOT using syslog then hard define them here. // Taken from /usr/include/syslog.h #ifdef USE_SYSLOG #include <syslog.h> #else #define LOG_EMERG 0 /* system is unusable */ #define LOG_ALERT 1 /* action must be taken immediately */ #define LOG_CRIT 2 /* critical conditions */ #define LOG_ERR 3 /* error conditions */ #define LOG_WARNING 4 /* warning conditions */ #define LOG_NOTICE 5 /* normal but significant condition */ #define LOG_INFO 6 /* informational */ #define LOG_DEBUG 7 /* debug-level messages */ #endif // // Divide logging in to modules and sub-modules. 16 bits. // Currently used by the DebugMask to filter logging. (-m switch) // Modules (high) 8 bits #define LOGGER_MOD_LINOS 1<<8 // 0x100 #define LOGGER_MOD_TCP 1<<9 // 0x200 // // Sub-modules LINOS 8 bits #define LOGGER_SUB_OS_DATABASE 1 // 0x01 #define LOGGER_SUB_OS_MAIN 1<<1 // 0x02 #define LOGGER_SUB_OS_TASK 1<<2 // 0x04 #define LOGGER_SUB_OS_ALARM 1<<3 // 0x08 #define LOGGER_SUB_OS_EVENT 1<<4 // 0x10 // // Sub-modules TCP 8 bits #define LOGGER_SUB_TCP_MAIN 1 // 0x01 #define LOGGER_SUB_TCP_SEND 1<<1 // 0x02 #define LOGGER_SUB_TCP_RECV 1<<2 // 0x04 #define LOGGER_SUB_TCP_BIND 1<<3 // 0x08 // // Declare functions void logger_open_close(int open_close, char *progname); void logger_set_prefix(char *prefix); int logger_set_output(int bitMask ); void logger_va(int loglevel, char *format, va_list listPointer); void logger(int loglevel, char *format, ... ); void logger_mod(uint16_t logmodule, int loglevel, char *format, ... ); char* logger_format_hex(char* s, int slength); #endif
2301_81045437/classic-platform
system/LinuxOs/src/linos_logger.h
C
unknown
2,717
/*-------------------------------- 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 _WIN32 #include "linos_time.h" #include "linos_logger.h" /* Logger functions */ Std_ReturnType Linos_GetCurrentTime(struct timespec *tp ) { if (clock_gettime(CLOCK_REALTIME, tp)) { logger(LOG_ERR, "Linos_GetCurrentTime. problems getting CLOCK_REALTIME"); return E_NOT_OK; } return E_OK; } #endif /* Not defined _WIN32 */
2301_81045437/classic-platform
system/LinuxOs/src/linos_time.c
C
unknown
1,126
/*-------------------------------- 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 _LINOS_TIME_H_ #define _LINOS_TIME_H_ #ifndef _WIN32 #include "Std_Types.h" #include <time.h> Std_ReturnType Linos_GetCurrentTime(struct timespec *tp); #endif /* Not defined _WIN32 */ #endif /* _LINOS_TIME_H_ */
2301_81045437/classic-platform
system/LinuxOs/src/linos_time.h
C
unknown
990
/*-------------------------------- 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 "linos_logger.h" /* Logger functions */ #include "Os.h" #include <os_sys.h> /* OS_SYS_PTR */ #include <os_i.h> /* GEN_TASK_HEAD */ void Os_AlarmAutostart(void) { AlarmType j; logger_mod((LOGGER_MOD_LINOS|LOGGER_SUB_OS_ALARM), LOG_INFO,"Os_AlarmAutostart"); for (j = 0; j < OS_ALARM_CNT; j++) { if (Os_OnRunningCore(OBJECT_ALARM,j)) { OsAlarmType *alarmPtr; alarmPtr = Os_AlarmGet(j); if (alarmPtr->autostartPtr != NULL) { const OsAlarmAutostartType *autoPtr = alarmPtr->autostartPtr; logger_mod((LOGGER_MOD_LINOS|LOGGER_SUB_OS_ALARM), LOG_INFO, "Setting Alarm %s", alarmPtr->name); if (OS_SYS_PTR->appMode & autoPtr->appModeRef) { if (autoPtr->autostartType == ALARM_AUTOSTART_ABSOLUTE) { logger_mod((LOGGER_MOD_LINOS|LOGGER_SUB_OS_ALARM), LOG_INFO, "Os_AlarmAutostart. Setting ABS Alarm %s alarmTime: %u cycleTime: %u", alarmPtr->name, autoPtr->alarmTime, autoPtr->cycleTime); (void)SetAbsAlarm(j, autoPtr->alarmTime, autoPtr->cycleTime); } else { logger_mod((LOGGER_MOD_LINOS|LOGGER_SUB_OS_ALARM), LOG_INFO, "Os_AlarmAutostart. Setting Rel Alarm %s alarmTime: %u cycleTime: %u", alarmPtr->name, autoPtr->alarmTime, autoPtr->cycleTime); (void)SetRelAlarm(j, autoPtr->alarmTime, autoPtr->cycleTime); } } else { logger(LOG_ERR, "Os_AlarmAutostart OS_SYS_PTR->appMode %u & autoPtr->appModeRef %u FALSE. (sint32)", OS_SYS_PTR->appMode, autoPtr->appModeRef); } } } } } /** * * @param a_obj */ static void AlarmProcess( OsAlarmType *aPtr ) { if( aPtr->cycletime == 0 ) { aPtr->active = 0; } else { // Calc new expire value.. aPtr->expire_val = Os_CounterAdd( Os_CounterGetValue(aPtr->counter), Os_CounterGetMaxValue(aPtr->counter), aPtr->cycletime); } } void Os_AlarmCheck( const OsCounterType *c_p ) { OsAlarmType *a_obj; StatusType rv; SLIST_FOREACH(a_obj,&c_p->alarm_head,alarm_list) { // logger(LOG_INFO,"Os_AlarmCheck a_obj->active %d c_p->val %d a_obj->expire_val %d", a_obj->active, c_p->val, a_obj->expire_val); if( a_obj->active && (c_p->val == a_obj->expire_val) ) { /* Check if the alarms have expired */ logger_mod((LOGGER_MOD_LINOS|LOGGER_SUB_OS_ALARM), LOG_INFO,"Os_AlarmCheck expired %s(%d) cycletime (%d)\n", a_obj->name, a_obj->action.task_id, a_obj->cycletime); switch( a_obj->action.type ) { case ALARM_ACTION_ACTIVATETASK: logger_mod((LOGGER_MOD_LINOS|LOGGER_SUB_OS_ALARM), LOG_INFO, "Os_AlarmCheck ActivateTask (%d)", a_obj->action.task_id); if( ActivateTask(a_obj->action.task_id) != E_OK ) { /* We actually do thing here, See 0S321 */ } AlarmProcess(a_obj); break; case ALARM_ACTION_SETEVENT: rv = SetEvent(a_obj->action.task_id,a_obj->action.event_id); if( rv != E_OK ) { Os_CallErrorHook(rv); } AlarmProcess(a_obj); break; case ALARM_ACTION_ALARMCALLBACK: /* IMPROVEMENT: not done */ break; case ALARM_ACTION_INCREMENTCOUNTER: /** @req OS301 */ logger_mod((LOGGER_MOD_LINOS|LOGGER_SUB_OS_ALARM), LOG_INFO, "Os_AlarmCheck ALARM_ACTION_INCREMENTCOUNTER"); (void)IncrementCounter(a_obj->action.counter_id); AlarmProcess(a_obj); break; default: ASSERT(0); } } } }
2301_81045437/classic-platform
system/LinuxOs/src/os_alarm_linos.c
C
unknown
4,401
/*-------------------------------- 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 "linos_logger.h" /* Logger functions */ #include "Os.h" #include <os_sys.h> /* OS_SYS_PTR */ #include <os_i.h> /* GEN_TASK_HEAD */ extern CounterType Os_Arc_OsTickCounter; /* Stuff here is taken from ./core/system/Os/os_counter.c */ StatusType IncrementCounter( CounterType counter_id ) { StatusType rv = E_OK; //logger(LOG_INFO, " IncrementCounter (%d)", counter_id); OS_SYS_PTR->tick++; // if not used, os_tick_counter < 0 if( Os_Arc_OsTickCounter != -1UL ) { OsCounterType *cPtr = Os_CounterGet(Os_Arc_OsTickCounter); #if defined(CFG_KERNEL_EXTRA) OsTaskVarType *pcbPtr; #endif cPtr->val = Os_CounterAdd( cPtr->val, Os_CounterGetMaxValue(cPtr), 1 ); #if defined(CFG_KERNEL_EXTRA) /* Check tasks in the timer queue (here from Sleep() or WaitSemaphore() ) */ TAILQ_FOREACH(pcbPtr, &OS_SYS_PTR->timerHead, timerEntry ) { --pcbPtr->timerDec; if( pcbPtr->timerDec <= 0 ) { /* Remove from the timer queue */ TAILQ_REMOVE(&OS_SYS_PTR->timerHead, pcbPtr, timerEntry); /* ... and add to the ready queue */ //Os_TaskMakeReady(pcbPtr); logger(LOG_INFO, "gnulinux_timer Task ready"); } } #endif #if OS_ALARM_CNT!=0 Os_AlarmCheck(cPtr); #endif #if OS_SCHTBL_CNT!=0 Os_SchTblCheck(cPtr); #endif } // logger(LOG_INFO, "******************************* Timer test %d", OS_SYS_PTR->tick); return rv; } /** * * Initialize alarms and schedule-tables for the counters * */ void Os_CounterInit( void ) { #if OS_ALARM_CNT!=0 { OsCounterType *cPtr; OsAlarmType *aPtr; /* Add the alarms to counters */ for (AlarmType i = 0; i < OS_ALARM_CNT; i++) { aPtr = Os_AlarmGet(i); cPtr = aPtr->counter; SLIST_INSERT_HEAD(&cPtr->alarm_head, aPtr, alarm_list); logger(LOG_INFO, "Os_CounterInit adding alarm %d (%s)", i, aPtr->name); } } #endif #if OS_SCHTBL_CNT!=0 { OsCounterType *cPtr; OsSchTblType *sPtr; /* Add the schedule tables to counters */ for(ScheduleTableType i = 0; i < OS_SCHTBL_CNT; i++ ) { sPtr = Os_SchTblGet(i); cPtr = sPtr->counter; SLIST_INSERT_HEAD(&cPtr->sched_head, sPtr, sched_list); logger(LOG_INFO, "Os_CounterInit adding Schedule table %d", i); } } #endif }
2301_81045437/classic-platform
system/LinuxOs/src/os_counter_linos.c
C
unknown
3,535
/*-------------------------------- 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 _WIN32 /* Not POSIX, but needed for debugging using pthread_setname_np */ #define __USE_GNU #include <pthread.h> #include <time.h> #include <unistd.h> /* sleep */ #endif #include "linos_logger.h" /* Logger functions */ #include "Os.h" #include <os_sys.h> /* OS_SYS_PTR */ #include <os_i.h> /* GEN_TASK_HEAD */ #include "os_main.h" extern ThreadTaskType ThreadTasks[(OS_TASK_CNT+GNULINUX_TASK_CNT)]; /* Normal tasks and special GNULinux tasks. Declared in os_main.c */ extern int GetTaskId (void); /* Declared in os_task_linos.c */ StatusType WaitEvent ( EventMaskType Mask ) { unsigned int usecs; unsigned int start_ticks, end_ticks, diff_ticks; TaskType CurrentTaskId; #ifndef _WIN32 struct timespec t_start, t_end, t_diff; #endif CurrentTaskId = GetTaskId(); if ( CurrentTaskId > -1) { logger_mod((LOGGER_MOD_LINOS | LOGGER_SUB_OS_EVENT), LOG_INFO, "Started WaitEvent TaskId %s(%d) Mask [0x%.8X] 32bits.", ThreadTasks[CurrentTaskId].name, CurrentTaskId, Mask); #ifndef _WIN32 clock_gettime(CLOCK_REALTIME, &t_start); // Get current time. start_ticks = OS_SYS_PTR->tick; pthread_mutex_lock(&ThreadTasks[CurrentTaskId].mutex_lock); int event_already_existed = 1; while ((ThreadTasks[CurrentTaskId].EventState & Mask) == 0) { event_already_existed = 0; pthread_cond_wait(&ThreadTasks[CurrentTaskId].cond, &ThreadTasks[CurrentTaskId].mutex_lock); } pthread_mutex_unlock(&ThreadTasks[CurrentTaskId].mutex_lock); clock_gettime(CLOCK_REALTIME, &t_end); // Get current time. end_ticks = OS_SYS_PTR->tick; t_diff = timesdiff(&t_start, &t_end); usecs = (t_diff.tv_nsec / 1000) + (t_diff.tv_sec * 1000000); diff_ticks = end_ticks - start_ticks; if (event_already_existed) { logger_mod((LOGGER_MOD_LINOS | LOGGER_SUB_OS_EVENT), LOG_INFO, "Finished WaitEvent TaskId %s(%d). The event already existed.", ThreadTasks[CurrentTaskId].name, CurrentTaskId); } else { logger_mod((LOGGER_MOD_LINOS | LOGGER_SUB_OS_EVENT), LOG_INFO, "Finished WaitEvent TaskId %s(%d). Got event after %d ticks, %d ms.", ThreadTasks[CurrentTaskId].name, CurrentTaskId, diff_ticks, ((usecs) / 1000)); } #endif } else { logger(LOG_ERR, "WaitEvent. ERROR. Couldn't identify calling Task ID %d.", CurrentTaskId); return E_NOT_OK; } return E_OK; } StatusType GetEvent( TaskType TaskId, EventMaskRefType Mask){ logger_mod((LOGGER_MOD_LINOS | LOGGER_SUB_OS_EVENT), LOG_INFO, "Started GetEvent TaskId %s(%d) [0x%.8X] 32bits", ThreadTasks[TaskId].name, TaskId, *Mask); #ifndef _WIN32 pthread_mutex_lock(&ThreadTasks[TaskId].mutex_lock); *Mask = ThreadTasks[TaskId].EventState; pthread_mutex_unlock(&ThreadTasks[TaskId].mutex_lock); #endif logger_mod((LOGGER_MOD_LINOS | LOGGER_SUB_OS_EVENT), LOG_INFO, "Finished GetEvent TaskId %s(%d) [0x%.8X] 32bits", ThreadTasks[TaskId].name, TaskId, *Mask); return E_OK; } StatusType ClearEvent ( EventMaskType Mask ) { TaskType CurrentTaskId; const char same[] = "*** NO CHANGE ***"; const char different[] = ""; char *info; CurrentTaskId = GetTaskId(); if ( CurrentTaskId > -1 ) { logger_mod((LOGGER_MOD_LINOS | LOGGER_SUB_OS_EVENT), LOG_INFO, "Started ClearEvent TaskId %s(%d), Mask [0x%.8X] 32bits.", ThreadTasks[CurrentTaskId].name, CurrentTaskId, Mask); #ifndef _WIN32 pthread_mutex_lock(&ThreadTasks[CurrentTaskId].mutex_lock); EventMaskType OldMask = ThreadTasks[CurrentTaskId].EventState; ThreadTasks[CurrentTaskId].EventState &= ~(Mask); /* Get the newMask to avoid locking the EventState while locking. */ EventMaskType newMask = ThreadTasks[CurrentTaskId].EventState; pthread_mutex_unlock(&ThreadTasks[CurrentTaskId].mutex_lock); if ( OldMask == newMask) info = (char*)&same; else info = (char*)&different; logger_mod((LOGGER_MOD_LINOS | LOGGER_SUB_OS_EVENT), LOG_INFO, "Finished ClearEvent TaskId %s(%d) Mask [0x%.8X]. [0x%.8X] -> [0x%.8X] 32bits. %s", ThreadTasks[CurrentTaskId].name, CurrentTaskId, Mask, OldMask, newMask, info); #endif } else { logger(LOG_ERR, "ClearEvent. ERROR. Couldn't identify calling Task ID."); return E_NOT_OK; } return E_OK; } StatusType SetEvent( TaskType TaskId, EventMaskType Mask ){ #ifndef _WIN32 logger_mod((LOGGER_MOD_LINOS | LOGGER_SUB_OS_EVENT), LOG_INFO, "Started SetEvent TaskId %s(%d), Mask [0x%.8X] 32bits.", ThreadTasks[TaskId].name, TaskId, Mask); pthread_mutex_lock(&ThreadTasks[TaskId].mutex_lock); ThreadTasks[TaskId].EventState |= Mask; /* Notify the waiting thread (WaitEvent) */ pthread_cond_signal(&ThreadTasks[TaskId].cond); pthread_mutex_unlock(&ThreadTasks[TaskId].mutex_lock); logger_mod((LOGGER_MOD_LINOS | LOGGER_SUB_OS_EVENT), LOG_INFO, "Finished SetEvent TaskId %s(%d), Mask [0x%.8X] 32bits.", ThreadTasks[TaskId].name, TaskId, Mask); #endif return E_OK; }
2301_81045437/classic-platform
system/LinuxOs/src/os_event_linos.c
C
unknown
6,357
/*-------------------------------- 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 "linos_logger.h" /* Logger functions */ #include "Os.h" #include <os_sys.h> /* OS_SYS_PTR */ #include <os_i.h> /* GEN_TASK_HEAD */ #include "os_main.h" extern ThreadTaskType ThreadTasks[(OS_TASK_CNT+GNULINUX_TASK_CNT)]; /* Normal tasks and special GNULinux tasks. Declared in os_main.c */ static void copyPcbParts( OsTaskVarType *pcb, const OsTaskConstType *r_pcb ) { pcb->activePriority = r_pcb->prio; pcb->stack= r_pcb->stack; pcb->constPtr = r_pcb; } void InitOS( void ) { uint32_t i; OsTaskVarType *tmpPcbPtr = NULL; logger(LOG_INFO, "InitOS called.\n"); #if OS_COUNTER_CNT!=0 Os_CounterInit(); #endif #if OS_SCHTBL_CNT!=0 Os_SchTblInit(); // IMPROVEMENT SimonG ?? #endif #if (OS_NUM_CORES > 1) IocInit(); // IMPROVEMENT SimonG ?? #endif for( i=0; i < OS_TASK_CNT; i++) { tmpPcbPtr = Os_TaskGet((TaskType)i); #if (OS_NUM_CORES > 1) if (Os_OnRunningCore(OBJECT_TASK,i)) { #endif copyPcbParts(tmpPcbPtr,&Os_TaskConstList[i]); logger(LOG_INFO,"InitOS adding task pid:%d name:%s prio:%d",tmpPcbPtr->constPtr->pid,tmpPcbPtr->constPtr->name,tmpPcbPtr->activePriority); // Fill Simons struct !! ThreadTasks[i].pid = tmpPcbPtr->constPtr->pid; ThreadTasks[i].entry = tmpPcbPtr->constPtr->entry; ThreadTasks[i].name = tmpPcbPtr->constPtr->name; ThreadTasks[i].prio = tmpPcbPtr->activePriority; ThreadTasks[i].autostart = tmpPcbPtr->constPtr->autostart; // #if (OS_NUM_CORES > 1) } #endif #if 0 Os_AddTask(tmpPcbPtr); #endif } /* GNULINUX tasks GNULINUX_TASK_CNT */ i = TASK_ID_GNULINUX_timer; //ThreadTasks[i].pid = TASK_ID_GNULINUX_timer; ThreadTasks[i].entry = gnulinux_timer; ThreadTasks[i].name = "TickDriveTimer"; ThreadTasks[i].prio = 1; ThreadTasks[i].autostart = TRUE; i = TASK_ID_GNULINUX_pmc_sync_status_reader; //ThreadTasks[i].pid = TASK_ID_GNULINUX_pmc_sync_status_reader; ThreadTasks[i].entry = gnulinux_pmc_sync_status_reader; ThreadTasks[i].name = "SyncStatusReader"; ThreadTasks[i].prio = 1; ThreadTasks[i].autostart = TRUE; }
2301_81045437/classic-platform
system/LinuxOs/src/os_init_linos.c
C
unknown
3,185
/*-------------------------------- 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 "os_i.h" #include "linos_logger.h" /* Logger functions */ #include <stdlib.h> #include <stdio.h> /* Stuff here is taken from core/system/Os/os_init.c */ OsErrorType os_error; /* Stuff here is taken from ./core/system/Os/include/os_internal.h */ #define SG_OS_STD_ERR_3(_service_id,_p1,_p2,_p3) \ Os_CallErrorHook(rv); \ return rv // Expecting calling function to provide the ending semicolon /* Stuff here is taken from ./core/system/Os/os_alarm.c */ #define COUNTER_MAX(x) (x)->counter->alarm_base.maxallowedvalue #define COUNTER_MIN_CYCLE(x) (x)->counter->alarm_base.mincycle #define ALARM_CHECK_ID(x) ((x) < OS_ALARM_CNT) StatusType SetAbsAlarm(AlarmType AlarmId, TickType Start, TickType Cycle) { imask_t flags; StatusType rv = E_OK; OsAlarmType *aPtr; OS_VALIDATE( ALARM_CHECK_ID(AlarmId), E_OS_ID); aPtr = Os_AlarmGet(AlarmId); #if (OS_SC3==STD_ON) || (OS_SC4==STD_ON) OsTaskVarType *currPcbPtr = Os_SysTaskGetCurr(); if( currPcbPtr->constPtr->applOwnerId != aPtr->applOwnerId ) { OS_VALIDATE( (Os_ApplCheckState(aPtr->applOwnerId) != E_OS_ACCESS) , E_OS_ACCESS); OS_VALIDATE( (Os_ApplCheckAccess(currPcbPtr->constPtr->applOwnerId, aPtr->accessingApplMask) != E_OS_ACCESS) , E_OS_ACCESS); #if (OS_NUM_CORES > 1) if (Os_ApplGetCore(aPtr->applOwnerId) != GetCoreID()) { StatusType status = Os_NotifyCore(Os_ApplGetCore(aPtr->applOwnerId), OSServiceId_SetAbsAlarm, AlarmId, Start, Cycle); return status; } #endif } #endif OS_VALIDATE( ! (Start > COUNTER_MAX(aPtr)), E_OS_VALUE ); /** @req OS304 */ if( Cycle != 0 && ( (Cycle < COUNTER_MIN_CYCLE(aPtr)) || (Cycle > COUNTER_MAX(aPtr)) ) ) { /** @req OS304 */ rv = E_OS_VALUE; SG_OS_STD_ERR_3(OSServiceId_SetAbsAlarm,AlarmId, Start, Cycle); } Irq_Save(flags); if( aPtr->active == 1 ) { rv = E_OS_STATE; Irq_Restore(flags); SG_OS_STD_ERR_3(OSServiceId_SetAbsAlarm,AlarmId, Start, Cycle); } aPtr->active = 1; aPtr->expire_val = Start; aPtr->cycletime = Cycle; Irq_Restore(flags); OS_DEBUG(D_ALARM," expire:%u cycle:%u\n", (unsigned)aPtr->expire_val, (unsigned)aPtr->cycletime); return rv; } /** * The system service occupies the alarm <AlarmID> element. * After <increment> ticks have elapsed, the task assigned to the * alarm <AlarmID> is activated or the assigned event (only for * extended tasks) is set or the alarm-callback routine is called. * * @param alarm_id Reference to the alarm element * @param increment Relative value in ticks * @param cycle Cycle value in case of cyclic alarm. In case of single alarms, cycle shall be zero. * @return */ StatusType SetRelAlarm(AlarmType AlarmId, TickType Increment, TickType Cycle){ StatusType rv = E_OK; imask_t flags; OsAlarmType *aPtr; OS_VALIDATE( ALARM_CHECK_ID(AlarmId), E_OS_ID); aPtr = Os_AlarmGet(AlarmId); logger(LOG_INFO,"SetRelAlarm id:%d inc:%u cycle:%u", AlarmId, (unsigned)Increment, (unsigned)Cycle); #if (OS_SC3==STD_ON) || (OS_SC4==STD_ON) OsTaskVarType *currPcbPtr = Os_SysTaskGetCurr(); if( currPcbPtr->constPtr->applOwnerId != aPtr->applOwnerId ) { OS_VALIDATE( (Os_ApplCheckState(aPtr->applOwnerId) != E_OS_ACCESS) , E_OS_ACCESS); OS_VALIDATE( (Os_ApplCheckAccess(currPcbPtr->constPtr->applOwnerId, aPtr->accessingApplMask) != E_OS_ACCESS) , E_OS_ACCESS); #if (OS_NUM_CORES > 1) if (Os_ApplGetCore(aPtr->applOwnerId) != GetCoreID()) { StatusType status = Os_NotifyCore(Os_ApplGetCore(aPtr->applOwnerId), OSServiceId_SetRelAlarm, AlarmId, Increment, Cycle); return status; } #endif } #endif if( (Increment == 0) || (Increment > COUNTER_MAX(aPtr)) ) { /** @req OS304 */ rv = E_OS_VALUE; SG_OS_STD_ERR_3(OSServiceId_SetRelAlarm,AlarmId, Increment, Cycle); } else { if( Cycle != 0 && ( (Cycle < COUNTER_MIN_CYCLE(aPtr)) || (Cycle > COUNTER_MAX(aPtr)) ) ) { /** @req OS304 */ rv = E_OS_VALUE; SG_OS_STD_ERR_3(OSServiceId_SetRelAlarm,AlarmId, Increment, Cycle); } } { Irq_Save(flags); if( aPtr->active == 1 ) { Irq_Restore(flags); rv = E_OS_STATE; SG_OS_STD_ERR_3(OSServiceId_SetRelAlarm,AlarmId, Increment, Cycle); } aPtr->active = 1; aPtr->expire_val = Os_CounterAdd( Os_CounterGetValue(aPtr->counter), COUNTER_MAX(aPtr), Increment); aPtr->cycletime = Cycle; Irq_Restore(flags); OS_DEBUG(D_ALARM," expire:%u cycle:%u\n", (unsigned)aPtr->expire_val, (unsigned)aPtr->cycletime); } return rv; } void Os_IsrInit( void ) { } void StartOS( AppModeType Mode ) { OS_SYS_PTR->status.os_started = true; OS_SYS_PTR->appMode = Mode; //os_start(); /* Originally in os_start core/system/Os/os_init.c */ /* Alarm autostart */ #if OS_ALARM_CNT!=0 Os_AlarmAutostart(); #endif /** @req OS424 */ //ASSERT(0); } void ShutdownOS( StatusType Error ) { (void)Error; printf("Shutting down!"); exit(Error); } StatusType GetResource( ResourceType ResID ) { return E_OK; } StatusType ReleaseResource( ResourceType ResID) { return E_OK; }
2301_81045437/classic-platform
system/LinuxOs/src/os_linos.c
C
unknown
7,558
/*-------------------------------- 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 OS_LINOS_H_ #define OS_LINOS_H_ typedef uint16 AlarmType; typedef struct { TickType maxallowedvalue; TickType tickperbase; TickType mincycle; } AlarmBaseType; typedef AlarmBaseType *AlarmBaseRefType; StatusType GetAlarmBase( AlarmType AlarmId, AlarmBaseRefType Info ); StatusType GetAlarm(AlarmType AlarmId, TickRefType Tick); StatusType SetRelAlarm(AlarmType AlarmId, TickType Increment, TickType Cycle); StatusType SetAbsAlarm(AlarmType AlarmId, TickType Start, TickType Cycle); StatusType CancelAlarm(AlarmType AlarmId); void Os_IsrInit( void ); void StartOS( AppModeType Mode ); void ShutdownOS( StatusType ); StatusType GetResource( ResourceType ResID ); StatusType ReleaseResource( ResourceType ResID); #endif /* OS_LINOS_H_ */
2301_81045437/classic-platform
system/LinuxOs/src/os_linos.h
C
unknown
1,546
/*-------------------------------- 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 <stdio.h> #include <setjmp.h> #ifndef _WIN32 #include <unistd.h> /* sleep */ #include <stdlib.h> /* exit */ #include <ctype.h> /* isprint */ #include <errno.h> #include <signal.h> #include <fcntl.h> /* open */ #include <asm/param.h> /* HZ */ #endif #include "linos_logger.h" /* Logger functions */ #include "linos_time.h" #include <time.h> #include <sys/stat.h> // umask #include "version.h" #include "EcuM.h" #include <os_i.h> /* GEN_TASK_HEAD */ #include <os_sys.h> /* OS_SYS_PTR */ #include "LinuxOs_StbM.h" #include "os_main.h" #if defined(USE_LINOS_DB) && !defined(_WIN32) #include "database.h" #endif #include "../pmc_sync_status_reader/pmc_sync_status_reader.h" #include <math.h> #define NSEC_PER_SEC 1000000000 /* Global variables */ int daemonise = 1; extern const OsTaskConstType Os_TaskConstList[OS_TASK_CNT]; #if defined(ANDROID_NDK) #define F_TLOCK LOCK_EX #define F_LOCK LOCK_EX #define FULOCK LOCK_UN int lockf(int fd, int cmd, off_t ignored_len) { return flock(fd, cmd); } #endif #if defined(USE_TCPIP) extern int gnulinuxTcpBindAny; #endif ThreadTaskType ThreadTasks[(OS_TASK_CNT+GNULINUX_TASK_CNT)]; /* Normal tasks and special GNULinux tasks */ int loops = 999; /* Infinate loops */ int DebugMask = 0; /* IMPROVEMENT SimonG Use this mask for debugging */ char *progname = NULL ; // Gets set in main(). Portable implementation of GNUs program_invocation_short_name char pid_file_name[64]; // /var/run/X.pid char bit_event_file_name[64]; // File to store the event bit signal in. #if defined(USE_LINOS_DB) char db_file_name[64]; #endif /* */ int stop_at_runtime = 0; extern void EcuM_Init(void); /* * Normalise timespec * * If tv_nsec >= NSEC_PER_SEC then * add to tv_sec and reduce tv_nsec * until tv_nsec < NSEC_PER_SEC * */ void tsnorm(struct timespec *ts) { #ifndef _WIN32 while (ts->tv_nsec >= NSEC_PER_SEC) { ts->tv_nsec -= NSEC_PER_SEC; ts->tv_sec++; } #endif } #ifndef _WIN32 /* Used by WaitEvent in os_event.c */ struct timespec timesdiff(struct timespec *start, struct timespec *end) { struct timespec temp; if ((end->tv_nsec-start->tv_nsec)<0) { temp.tv_sec = end->tv_sec-start->tv_sec-1; temp.tv_nsec = 1000000000+end->tv_nsec-start->tv_nsec; } else { temp.tv_sec = end->tv_sec-start->tv_sec; temp.tv_nsec = end->tv_nsec-start->tv_nsec; } return temp; } #endif /* * * * gnulinux_timer (Runs in seperate thread) * * Increment the counter OsTickFreq times per second. Max 1000Hz (1ms) ?? * * This sleeps different amounts of time to ensure accuracy. * * */ void gnulinux_timer(void) { #ifndef _WIN32 unsigned int msec = (1000/OsTickFreq); /* How long to wait for every tick */ unsigned int usecs = msec * 1000; /* Wait time in microseconds */ struct timespec t; t.tv_sec = 0; t.tv_nsec = (usecs * 1000); struct timespec r; while(1) { while (clock_nanosleep(CLOCK_MONOTONIC, 0, &t, &r) != 0) { if (errno == EINTR) { t.tv_sec = r.tv_sec; t.tv_nsec = r.tv_nsec; } else { /* Exiting on permanent errors. */ logger(LOG_ERR, "vECU exiting on gnulinux_timer permanent sleep error."); // Improvement: do cleanup exit(1); } } IncrementCounter(0); t.tv_sec = 0; t.tv_nsec = (usecs * 1000); } #endif } void gnulinux_pmc_sync_status_reader(void) { #ifndef _WIN32 if (!init_sync_status_reader()) { logger(LOG_ERR, "failed to initialize pmc_sync_status_reader"); return; } const size_t sync_status_len = (size_t)sizeof(collective_sync_status); collective_sync_status recv_sync_status; sync_status_reader_conn_state conn_state; int recv_len = sync_status_len; while (1) { conn_state = connect_sync_status_reader(); if(conn_state == SYNC_STATUS_PERM_DISCONNECTED) { logger(LOG_DEBUG, "permanently disconnected pmc_sync_status_reader"); return; } else if (conn_state == SYNC_STATUS_CONNECTED) { while (1) { /* Design note: * ------------ * recv will anyway fail if the socket is closed. * Calling disable_gnulinux_pmc_sync_status_reader makes use of * this by calling disconnect_sync_status_reader(1) that * sets conn_state to SYNC_STATUS_PERM_DISCONNECTED and never * allows setting it to SYNC_STATUS_TEMP_DISCONNECTED. */ recv_len = recv(reader_uds_skt, &recv_sync_status, sync_status_len, 0); if (recv_len == sync_status_len) { logger(LOG_DEBUG, "ptp (in-sync, offset): (%d, %f)", recv_sync_status.in_sync, recv_sync_status.offsetFromMaster); Linos_StbM_BusSetGlobalTime(0, NULL, NULL, 0, recv_sync_status.in_sync, recv_sync_status.offsetFromMaster); } else { logger(LOG_ERR, "receiving error or partially sent sync_status"); break; } } disconnect_sync_status_reader(0); } /* Avoid high CPU consumption, sleep before attempting to reconnect. */ sleep(1); } #endif } void disable_gnulinux_pmc_sync_status_reader() { /* Design note: * ------------ * Because gnulinux_pmc_sync_status_reader is implemented as a linos Task * on top of a pthread, we can not directly use pthread_cancel and * associated cleanup handlers. So we attempt closing the connection * whenever there is a possibility for leaving it open. * The possibility here is that gnulinux_pmc_sync_status_reader is blocked * on recv or is sleeping. */ disconnect_sync_status_reader(1); } /* * * * * * MAIN * * * * * */ /* All tasks will get to this function at least once. * * If Alarm type is "ALARM_ACTION_ACTIVATETASK" the thread will spin in this * loop until "pthread_status" get changed to GNULINUX_PTHREAD_FUNCTION_STARTED. * Mutex is required as "gnulinux_timer" thread will change the "pthread_status" to * "GNULINUX_PTHREAD_FUNCTION_STARTED" which means we need to protect the read. * * If Alarm type is "ALARM_ACTION_SETEVENT" the thread will jump to the function pointed to * by "entry()" and it will never return. The generated Rte implements the loop that handles * the WaitEvent, GetEvent and ClearEvent. The SetEvent is handled by gnulinux_timer thread. * * For non Autosar tasks (gnulinux_timer, gnulinux_pmc_sync_status_reader) the behavior is * implementation specific. * */ void TaskWrapper(ThreadTaskType *threadtask) { if ( NULL == threadtask ) { logger(LOG_ERR, "Pointer to thread variable is NULL in TaskWrapper, exiting thread."); pthread_exit(NULL); } while(1) { pthread_mutex_lock(&threadtask->mutex_lock); int thread_is_started = (threadtask->pthread_status == GNULINUX_PTHREAD_FUNCTION_STARTED); pthread_mutex_unlock(&threadtask->mutex_lock); if (thread_is_started) { #ifndef _WIN32 threadtask->entry(); /* Call the function defined in the task entry */ #endif } else { //logger(LOG_INFO, "TaskWrapper waiting to re-activate task"); usleep(1000); /* Sleep 1 ms */ } } } /* All tasks will get to this function at least once. * * This is the first function called when threads are created. This function * checks that the task is meant to be started. If this is the case it will * change the thread status to GNULINUX_PTHREAD_FUNCTION_STARTED and then jump * to TaskWrapper, TaskWrapper will never return. * * We need to have protection on pthread_status because if this thread is delay * and gnulinux_timer thread is started there may be unsynced read/writes to this pthread_status. * */ void* StartTask(void *arg) { #ifndef _WIN32 ThreadTaskType *threadtask; if ( NULL == arg ) { logger(LOG_ERR, "Pointer to thread variable is NULL in StartTask, exiting thread."); pthread_exit(NULL); } threadtask = (ThreadTaskType *)arg; if (&ThreadTasks[TASK_ID_OsIdle] == threadtask) { logger_mod((LOGGER_MOD_LINOS|LOGGER_SUB_OS_MAIN), LOG_INFO, "NOT Calling %s TaskId(%d)", threadtask->name, TASK_ID_OsIdle); } else { pthread_mutex_lock(&threadtask->mutex_lock); int thread_is_starting = (threadtask->pthread_status == GNULINUX_PTHREAD_STARTING); if (thread_is_starting) { threadtask->pthread_status = GNULINUX_PTHREAD_FUNCTION_STARTED; } pthread_mutex_unlock(&threadtask->mutex_lock); if (thread_is_starting) { logger_mod((LOGGER_MOD_LINOS|LOGGER_SUB_OS_MAIN), LOG_INFO, "Calling %s", threadtask->name); TaskWrapper(threadtask); //Will never return } else { logger(LOG_ERR, "Task %s is NOT in state GNULINUX_PTHREAD_STARTING", threadtask->name); pthread_exit(NULL); return NULL; } } #endif return NULL; } void list_all_events() { int i; logger_mod((LOGGER_MOD_LINOS|LOGGER_SUB_OS_MAIN), LOG_INFO, "Listing all task events"); for( i=0; i < OS_TASK_CNT; i++) { logger_mod((LOGGER_MOD_LINOS|LOGGER_SUB_OS_MAIN), LOG_INFO, "IMPROVEMENT %s", ThreadTasks[i].name); } } #if defined(USE_LINOS_DB) && !defined(_WIN32) int callback_print_runtime (char *reg_type, int argc, char **argv, char **azColName) { int i; int address; int value; /* Loop through the columns in the DB record. */ for(i=0; i<argc; i++) { //printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL"); if ( strcmp (azColName[i],"registeraddress") == 0 ) { address = atoi(argv[i]); } else if ( strcmp (azColName[i],"registervalue") == 0 ) { value = atoi(argv[i]); } } if ( address == DB_ECU_RUNTIME_REG_ADDRESS ) { logger(LOG_INFO, "Runtime at start-up is %ld s", value); } return 0; } #endif static void usage() { printf("%s\n",progname); printf("%s\n", ArcticCore_Version.info); printf("USAGE: %s \n", progname); #if defined(USE_TCPIP) printf("-b bind (listen) to INADDR_ANY instead of the configured ip address\n"); #endif #if defined(USE_LINOS_DB) printf("Database file is here %s\n", db_file_name); #endif #ifdef USE_SYSLOG printf("-f stay in foreground. Instead of deamonising.\n"); #endif printf("-l loops (999 = infinite).\n"); printf("-m <BITMASK> to set the debug mask. Only three digit hex, e.g. 0xFFF. See logger.h\n"); printf("-r stop at runtime. For test.\n"); } int settings(int argc, char **argv ) { int index; int c; #ifndef _WIN32 opterr = 0; #endif // See usage() function above while ((c = getopt (argc, argv, "bfhl:m:rt")) != -1) { switch (c) { case 'b': #if defined(USE_TCPIP) gnulinuxTcpBindAny = TRUE; #endif break; case 'l': #ifndef _WIN32 loops = atoi(optarg); #endif break; case 'm': #ifndef _WIN32 //DebugMask = atoi(optarg); DebugMask = strtol(optarg, (char **) NULL, 16); // Accept a digit in decimal or hex printf("DebugMask = 0x%04X\n", DebugMask); #endif break; case 'f': #ifdef USE_SYSLOG logger_set_output(3); /* Syslog + fprintf */ #else logger_set_output(1); /* fprintf */ #endif daemonise = 0; /* Do NOT deamonise */ loops = 10; break; case 'h': usage(); exit(0); break; case 'r': stop_at_runtime = 1; break; case 't': EcuM_Init(); list_all_events(); exit(0); break; case '?': #ifndef _WIN32 if ((optopt == 'l')||(optopt == 'm')||(optopt == 'e')) { fprintf(stderr, "Option -%c requires an argument.\n", optopt); } else if (isprint (optopt)) { fprintf(stderr, "Unknown option `-%c'.\n", optopt); } else { fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt); } #endif return 1; default: abort (); } } #ifndef _WIN32 for (index = optind; index < argc; index++) { fprintf(stderr, "Non-option argument %s", argv[index]); return 0; } #endif return 0; } static void close_sigint(int exit_code) { logger(LOG_INFO, "Shutting down ... "); //logger(LOG_INFO, "Killing threads."); // IMPROVEMENT SimonG // pthread_cancel disable_gnulinux_pmc_sync_status_reader(); // Read Design note inside this method. #if defined(USE_LINOS_DB) && !defined(_WIN32) db_close(); #endif unlink(pid_file_name); logger(LOG_INFO, "Done!"); #ifdef USE_SYSLOG logger_open_close ( 0, progname ); #endif exit(exit_code); } void read_event_file(void) { FILE *rc; char line[80]; TaskType TaskId; EventMaskType Mask; logger(LOG_INFO, "SIG HUP caught. Reading events from file %s", bit_event_file_name); rc = fopen(bit_event_file_name, "r"); if ( rc == NULL ) { logger(LOG_ERR, "Oops problems opening event file %s", bit_event_file_name); } else { while(fgets(line, 80, rc) != NULL) { logger_mod((LOGGER_MOD_LINOS|LOGGER_SUB_OS_MAIN), LOG_INFO, "Line : %s", line); TaskId = atoi(strtok (line,"-")); Mask = strtol(strtok (NULL, "\0"),NULL,0); // 0xabcdef00 logger_mod((LOGGER_MOD_LINOS|LOGGER_SUB_OS_MAIN), LOG_INFO, "SetEvent( TaskType %d, EventMaskType [0x%.8X] )", TaskId, Mask); SetEvent( TaskId, Mask ); } fclose(rc); } } void signal_handler(int sig) { #ifndef _WIN32 switch(sig) { case SIGHUP: read_event_file(); break; case SIGTERM: case SIGINT: close_sigint(0); break; default: logger(LOG_ERR, "Unknown signal (%d) %s ignored.", sig, strsignal(sig)); } #endif } /* Shorten the task name to fit the Linux thread name limits of 15 characters. * See the documentation of pthread_setname_np.*/ #define SHORT_TASK_NAME_MAX 15 char buf_shortTaskName[SHORT_TASK_NAME_MAX]; /* "start_thread( int threadId )" handles the creation of threads and the * reactivation of tasks that have ALARM_ACTION_ACTIVATETASK configured. * * main()->init_threads()->start_thread() * Call occur at system startup and will start all Autostart-tasks. Mutex * is not needed in this case as there is not other task created that want * access to "pthread_status". * * OsStartupTask()->ActivateTask()->start_thread() * OsStartupTask is an Autostart-tasks and will activate the * the Autosar tasks that are not specified as Autostart-tasks. Mutex * is not needed in this case as there is not other task created that want * access to "pthread_status". * * gnulinux_timer()->IncrementCounter()->Os_AlarmCheck()->ActivateTask()->start_thread() * If an Autosar task has the ALARM_ACTION_ACTIVATETASK specified this function * will be called from gnulinux_timer thread to restart the task. Mutex is needed in this * case as the thread being reactivated may read or write to "pthread_status". */ int start_thread( int threadId ) { #ifndef _WIN32 int err; pthread_attr_t attr; /*------------------------------------Restart Terminated Thread------------------------------------*/ /* * This will handle the restart of tasks that have ALARM_ACTION_ACTIVATETASK specified. */ pthread_mutex_lock(&ThreadTasks[threadId].mutex_lock); int thread_is_terminated = (ThreadTasks[threadId].pthread_status == GNULINUX_PTHREAD_FUNCTION_TERMINATED); if (thread_is_terminated) { ThreadTasks[threadId].pthread_status = GNULINUX_PTHREAD_FUNCTION_STARTED; } pthread_mutex_unlock(&ThreadTasks[threadId].mutex_lock); if (thread_is_terminated) { err = E_OK; logger_mod((LOGGER_MOD_LINOS | LOGGER_SUB_OS_TASK), LOG_DEBUG, "Restarting a terminated task (%s).", ThreadTasks[threadId].name); return err; } /*-----------------------------Thread still running and not Terminated-----------------------------*/ /* We can not re-create a task that is not empty and passed the above check. */ pthread_mutex_lock(&ThreadTasks[threadId].mutex_lock); int thread_is_empty = (ThreadTasks[threadId].pthread_status == GNULINUX_PTHREAD_EMPTY); pthread_mutex_unlock(&ThreadTasks[threadId].mutex_lock); if (!thread_is_empty) { err = E_NOT_OK; /* This is a thread that has not terminated OR never started. * We do not log anything here to avoid noise in the logs. */ return err; } /*-----------------------------------------Create Thread-----------------------------------------*/ /* We will only get to this part if the thread was never created. * This means that we don't need mutex as there is no other thread * that will try to read or write pthread_status. */ ThreadTasks[threadId].pthread_status = GNULINUX_PTHREAD_STARTING; /* Initialize thread creation attributes */ err = pthread_attr_init(&attr); if (err != 0) { handle_error_en(err, "pthread_attr_init"); } // IMPROVEMENT Set prio, affinity etc. // if (stack_size > 0) { // err = pthread_attr_setstacksize(&attr, stack_size); // if (err != 0) // handle_error_en(err, "pthread_attr_setstacksize"); // } // // sched_setaffinity( etc. // err = pthread_create((pthread_t * restrict)&(ThreadTasks[threadId].tid), NULL, &StartTask, &ThreadTasks[threadId]); if (err != 0) { logger(LOG_ERR, "\nFailed to create thread for task (%s), error :[%s]", ThreadTasks[threadId].name, strerror(err)); pthread_attr_destroy(&attr); handle_error_en(err, "pthread_create"); } /* Shorten the task name to fit the Linux thread name limits of 15 characters. * See the documentation of pthread_setname_np.*/ int len_shortTaskName = SHORT_TASK_NAME_MAX; if (strlen(ThreadTasks[threadId].name) < SHORT_TASK_NAME_MAX) { len_shortTaskName = strlen(ThreadTasks[threadId].name); } memset(buf_shortTaskName, ' ', SHORT_TASK_NAME_MAX); strncpy(buf_shortTaskName, ThreadTasks[threadId].name, len_shortTaskName); /* Not POSIX, but needed for debugging. */ err = pthread_setname_np(ThreadTasks[threadId].tid, (const char *)buf_shortTaskName); if (err != 0) { logger(LOG_ERR, "\nFailed pthread_setname_np for task (%s), error :[%s]", ThreadTasks[threadId].name, strerror(err)); } /* Destroy the thread attributes object, since it is no longer needed */ err = pthread_attr_destroy(&attr); if (err != 0) { logger(LOG_ERR, "\nFailed pthread_attr_destroy for task (%s), error :[%s]", ThreadTasks[threadId].name, strerror(err)); } return err; #else return 0; #endif } void init_threads() { logger_mod((LOGGER_MOD_LINOS|LOGGER_SUB_OS_MAIN), LOG_INFO, "Initializing threads ..."); int i; /* First, mutexes and locks are initialized before any thread is running. */ for (i=0; i< (OS_TASK_CNT+GNULINUX_TASK_CNT);i++) { /* Initialise the Wait/Set event pthread lock */ #ifndef _WIN32 pthread_mutex_init((pthread_mutex_t *) &ThreadTasks[i].mutex_lock, NULL); pthread_cond_init((pthread_cond_t *) &ThreadTasks[i].cond, NULL); #endif } /* Second, start autostart threads. */ for (i=0; i< (OS_TASK_CNT+GNULINUX_TASK_CNT);i++) { if ( ThreadTasks[i].autostart == TRUE ) { start_thread(i); } } } int demonise(void) { // Daemonise int i; int rc = 0; #ifndef _WIN32 // Our process ID and Session ID pid_t pid, sid; char str[10]; // PID string for /var/run logger_mod((LOGGER_MOD_LINOS|LOGGER_SUB_OS_MAIN), LOG_INFO, "starting the daemonizing process"); // Open the PID file rc = open(pid_file_name,O_RDWR|O_CREAT|O_EXCL,0640); if ( rc < 0 ) { logger(LOG_ERR, "Oops problems opening pid file %s errno: %d (%s)", pid_file_name, errno, strerror(errno)); exit(EXIT_FAILURE); /* Do NOT remove the PID file */ } // Fork off the parent process pid = fork(); if (pid < 0) { logger(LOG_ERR, "Problems forking the parent process."); exit(EXIT_FAILURE); // ERROR } // If we got a good PID, then // we can exit the parent process. if (pid > 0) { exit(EXIT_SUCCESS); } // Change the file mode mask umask(0); // Create a new SID for the child process sid = setsid(); if (sid < 0) { // Log the failure logger(LOG_ERR, "Problems creating SID for the child process."); close_sigint(EXIT_FAILURE); } // Change the current working directory if ((chdir("/")) < 0) { // Log the failure logger(LOG_ERR, "Problems changing the current working directory."); close_sigint(EXIT_FAILURE); } else { logger_mod((LOGGER_MOD_LINOS|LOGGER_SUB_OS_MAIN), LOG_INFO, "Daemonised !!"); } // Close out the standard file descriptors close(STDIN_FILENO); close(STDOUT_FILENO); close(STDERR_FILENO); i=open("/dev/null",O_RDWR); /* open stdin */ dup(i); /* stdout */ dup(i); /* stderr */ // // Save the PID // Lock to prevent multiple processes if (lockf(rc,F_TLOCK,0)<0) { logger(LOG_ERR, "Oops problems locking pid file %s.", pid_file_name); close_sigint(EXIT_FAILURE); } sprintf(str,"%d\n",getpid()); write(rc,str,strlen(str)); // record pid to lockfile logger(LOG_INFO, "PID run file is %s containing the PID %s", pid_file_name, str); // close(rc); // Dont close to hold the lock. #endif return rc; } int main(int argc, char *argv[]) { int rc = 0; int running = 1; #ifndef _WIN32 struct timespec tp; #endif //progname = argv[0]; // Get this programs name. progname = __PROGNAME__; // Get this programs name. Defined in Makefile #ifdef USE_SYSLOG logger_open_close ( 1, progname ); #endif /* Save the PID file here */ //strcat(pid_file_name, "/var/run/"); strcat(pid_file_name, "/tmp/"); strcat(pid_file_name, progname); strcat(bit_event_file_name,pid_file_name); /* Put the event file in the same place as the pid file */ #if defined(USE_LINOS_DB) strcat(db_file_name,pid_file_name); /* Put the database file in the same place as the pid file */ strcat(db_file_name, ".sqlite3"); #endif strcat(pid_file_name, ".pid"); strcat(bit_event_file_name,BIT_EVENT_FILE_NAME_SUFFIX); logger(LOG_INFO, "Bit event file name is %s",bit_event_file_name); if (settings(argc, argv)) { usage(); exit(1); } #ifndef _WIN32 logger(LOG_INFO,"Main. HZ is %ld CLOCKS_PER_SEC is %ld OsTickFreq is %ld", HZ, CLOCKS_PER_SEC, OsTickFreq); #endif logger(LOG_INFO,"%s", ArcticCore_Version.info); //OS_DEBUG(D_ALARM,"SIMONG TEST\n"); #ifndef _WIN32 /* Catch these signals */ signal(SIGHUP, signal_handler); signal(SIGINT, signal_handler); signal(SIGTERM, signal_handler); signal(SIGQUIT, signal_handler); // Ignore these signals (deamonise) signal(SIGCHLD,SIG_IGN); /* child terminate signal */ signal(SIGTSTP,SIG_IGN); /* ignore tty signals */ signal(SIGTTOU,SIG_IGN); signal(SIGTTIN,SIG_IGN); #endif if (daemonise) { demonise(); } else { logger(LOG_INFO, "No daemonising."); } #if defined(USE_LINOS_DB) && !defined(_WIN32) if ( db_init (db_file_name) ) { logger(LOG_ERR,"Failed to initialize ArcCore CAL database '%s'", db_file_name); close_sigint(EXIT_FAILURE); } else { logger(LOG_INFO,"Opened ArcCore CAL database '%s'", db_file_name); } #endif /* *************** START ********************** */ #if defined(USE_LINOS_DB) && !defined(_WIN32) rc = db_get_register ( DB_ECU_RUNTIME_REG_ADDRESS, 1, callback_print_runtime); if ( rc != DB_OK ) { logger(LOG_ERR, "ERROR: process_query DB ERROR: %d", rc); } #endif #ifndef _WIN32 Linos_GetCurrentTime(&tp); logger(LOG_INFO,"Start-up @ clock real time: %ld.%09ld or %s", tp.tv_sec, tp.tv_nsec, ctime(&tp.tv_sec)); #endif if (stop_at_runtime) { close_sigint(rc); return rc; } EcuM_Init(); /* This calls InitOS() */ /* Improvement review if we can configure calling Linos_StbM_Init from EcuM module, * e.g. from EcuM_Init(). * See example sequence diagram in 4.2.2/SWS_StbM. */ Linos_StbM_Init(); /* In addition to Tasks and Scheduler threads, we start a thread to read * PTP synchronization updates from a running pmc_sync_status daemon. */ init_threads(); /* THIS is the Main Thread */ /* All this is just for test */ int sleep_time_s = 1; while (running) { if ( loops != 999 ) { logger(LOG_INFO, "Loops left %d\n", loops); if ( loops > 1 ) { loops--; } else { running=0; } } #ifndef _WIN32 sleep(sleep_time_s); #endif #if defined(USE_LINOS_DB) && !defined(_WIN32) rc = db_inc_register (DB_ECU_RUNTIME_REG_ADDRESS, sleep_time_s, DB_CREATE_MISSING_WRITE, 1,1); // force_write, writeable if ( rc != DB_OK ) { logger(LOG_ERR, "DB_ECU_RUNTIME Problems saving runtime to DB."); } #endif /* Linos_StbM_GetCurrentTime TEST */ if ((DebugMask & (LOGGER_MOD_LINOS|LOGGER_SUB_OS_MAIN)) == (LOGGER_MOD_LINOS|LOGGER_SUB_OS_MAIN)) { StbM_TimeStampType testTime; StbM_UserDataType UserData; Std_ReturnType testReturn; uint8_t flag_timeout = 0, flag_global_time_base = 0; testReturn = Linos_StbM_GetCurrentTime(0, &testTime, &UserData); if ( testReturn != E_OK ) { logger(LOG_ERR, "os_main : testReturn is %d", testReturn); } else { if ( testTime.timeBaseStatus & 0x01 ) { flag_timeout = 1; } if ( testTime.timeBaseStatus & 0x08 ) { flag_global_time_base = 1; } logger(LOG_INFO, "os_main : sys TIME : %d.%d.%09d \tflag_timeout:%d\tflag_global_time_base:%d\n", testTime.secondsHi, testTime.seconds, testTime.nanoseconds, flag_timeout, flag_global_time_base); } } } close_sigint(rc); return rc; }
2301_81045437/classic-platform
system/LinuxOs/src/os_main.c
C
unknown
29,133
/*-------------------------------- 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 _OS_MAIN_H #define _OS_MAIN_H #ifndef _WIN32 /* Not POSIX, but needed for debugging using pthread_setname_np */ #define __USE_GNU #include <pthread.h> #endif #include <setjmp.h> #ifdef _WIN32 #include "os_stubs.h" #endif /* * Main header * */ Os_SysType Os_Sys[OS_NUM_CORES]; Os_IntCounterType Os_IntDisableAllCnt; Os_IntCounterType Os_IntSuspendAllCnt; Os_IntCounterType Os_IntSuspendOsCnt; OsTaskVarType Os_TaskVarList[OS_TASK_CNT]; /* GNULINUX tasks/threads */ /* Trying not to crash with normal tasks. Take the next free task */ #define TASK_ID_GNULINUX_timer ((TaskType)OS_TASK_CNT+0) #define TASK_ID_GNULINUX_pmc_sync_status_reader TASK_ID_GNULINUX_timer+1 #define GNULINUX_TASK_CNT 2 /* Number of GNULINUX tasks. */ /* */ #define BIT_EVENT_FILE_NAME_SUFFIX "_event.txt" /* pthread status */ #define GNULINUX_PTHREAD_EMPTY 0 #define GNULINUX_PTHREAD_STARTING 1 #define GNULINUX_PTHREAD_FUNCTION_STARTED 2 #define GNULINUX_PTHREAD_FUNCTION_TERMINATED 3 /* */ #define PTP_DEVICE "/dev/ptp0" #ifndef CLOCK_INVALID #define CLOCK_INVALID -1 #endif /* Task meta data, the stuff we need anyway. Bits from config/stm32_stm3210c/Os_Cfg.c GEN_TASK_HEAD */ typedef struct { OsTaskidType pid; pthread_t tid; /* Linux pThread id type */ pthread_mutex_t mutex_lock; /* Mutex lock for locking a thread running a WaitEvent */ pthread_cond_t cond; /* Condition variable for notifing changes to EventState */ jmp_buf stack_env; /* pthread stack environment */ uint8 pthread_status; /* Only start new thread if old thread has ended. */ OsPriorityType prio; const char *name; void (*entry)( void ); /* Function pointer */ uint8 autostart; EventMaskType EventState; /* Something to hold Event bits for each task */ } ThreadTaskType; #define handle_error_en(en, msg) \ do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0) #define handle_error(msg) \ do { perror(msg); exit(EXIT_FAILURE); } while (0) /* */ void gnulinux_timer(void); struct timespec timesdiff(struct timespec *start, struct timespec *end); int start_thread( int threadId ); void gnulinux_pmc_sync_status_reader(void); #endif /* _OS_MAIN_H */
2301_81045437/classic-platform
system/LinuxOs/src/os_main.h
C
unknown
3,046
/*-------------------------------- 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 -----------------------------*/ /* * * Stubbed functions to get a working system * */ #include <Os.h> #include <Com_Types.h> #include <Rte_EcuM_Type.h> //#include <os_i.h> /* OS_SYS_PTR */ #include <time.h> #include "linos_logger.h" /* Logger functions */ #include "os_stubs.h" TickType GetOsTick(void) { //return OS_SYS_PTR->tick; //return time(0); return clock(); } void tcpip_task( void ) { logger(LOG_INFO, "tcpip_task called."); } #if defined(USE_RTE) Std_ReturnType Os_GetCounterValue(CounterType counterId, TickType * value) { /*IMPROVEMENT :Currently stubbed */ return E_OK; } Std_ReturnType Os_GetElapsedValue(CounterType counterId, TickType * value, TickType * elapsedValue) { /*IMPROVEMENT :Currently stubbed */ return E_OK; } #endif /* #if defined(USE_RTE) */
2301_81045437/classic-platform
system/LinuxOs/src/os_stubs.c
C
unknown
1,574
/*-------------------------------- 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 _OS_STUBS_H #define _OS_STUBS_H void tcpip_task( void ); #ifdef _WIN32 #include "Platform_types.h" #define INET_ADDRSTRLEN (16) typedef int pthread_t; typedef int pthread_mutex_t; typedef int pthread_cond_t; #endif #endif /* _OS_STUBS_H */
2301_81045437/classic-platform
system/LinuxOs/src/os_stubs.h
C
unknown
1,034
/*-------------------------------- 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 _WIN32 /* Not POSIX, but needed for debugging using pthread_setname_np */ #define __USE_GNU #include <pthread.h> #include <setjmp.h> #include <unistd.h> /* sleep */ #include <stdlib.h> /* exit */ #include <ctype.h> /* isprint */ #include <errno.h> #include <signal.h> #include <fcntl.h> /* open */ #endif #include <stdio.h> #include "linos_logger.h" /* Logger functions */ #ifndef _WIN32 #include <asm/param.h> /* HZ */ #endif #include <time.h> #include "EcuM.h" #include <os_i.h> /* GEN_TASK_HEAD */ #include <os_sys.h> /* OS_SYS_PTR */ #include "os_main.h" extern ThreadTaskType ThreadTasks[(OS_TASK_CNT+GNULINUX_TASK_CNT)]; /* Normal tasks and special GNULinux tasks */ void Os_ResourceReleaseInternal( void ) { } void Os_ResourceGetInternal( void ) { } /* */ int GetTaskId (void) { int TId = -1; // If NOT found this will be returned int i; #ifndef _WIN32 pthread_t id = pthread_self(); for (i=0; i< OS_TASK_CNT;i++){ if(pthread_equal(id,(ThreadTasks[i].tid))){ TId = i; i = OS_TASK_CNT; // Exit for loop } } #endif return TId; } /* Stuff here is taken from core/system/Os/os_task.c */ /* ----------------------------[includes]------------------------------------*/ #include "os_i.h" /* ----------------------------[private define]------------------------------*/ /* ----------------------------[private macro]-------------------------------*/ /* ----------------------------[private typedef]-----------------------------*/ /* ----------------------------[private function prototypes]-----------------*/ /* ----------------------------[private variables]---------------------------*/ #if OS_TASK_CNT!=0 OsTaskVarType Os_TaskVarList[OS_TASK_CNT]; #endif /* ----------------------------[private functions]---------------------------*/ // schedule() static inline void Os_TaskRunningToReady( OsTaskVarType *currPcbPtr ) { ASSERT(currPcbPtr->state == ST_RUNNING ); currPcbPtr->state = ST_READY; } /** * Make a task go the READY state * Used by API: ActivateTask(), SetEvent() * * @param currPcbPtr */ void Os_TaskMakeReady( OsTaskVarType *pcb ) { if( ( pcb->state & ( ST_READY | ST_RUNNING ) ) == 0 ) { pcb->state = ST_READY; TAILQ_INSERT_TAIL(& OS_SYS_PTR->ready_head,pcb,ready_list); OS_DEBUG(D_TASK,"Added %s to ready list\n",pcb->constPtr->name); } } /** * Make a task go the the WAITING state * Used by API: WaitEvent * * * @param pcb Ptr to the task */ void Os_TaskMakeWaiting( OsTaskVarType *pcb ) { ASSERT( pcb->state & (ST_READY|ST_RUNNING) ); pcb->state = ST_WAIT_EVENT; TAILQ_REMOVE(&OS_SYS_PTR->ready_head,pcb,ready_list); OS_DEBUG(D_TASK,"Removed %s from ready list\n",pcb->constPtr->name); } // Sleeping #if defined(CFG_KERNEL_EXTRA) static inline void Os_TaskMakeSleeping( OsTaskVarType *pcb ) { ASSERT( pcb->state & (ST_READY|ST_RUNNING) ); pcb->state = ST_WAITING | ST_SLEEPING; TAILQ_REMOVE(&OS_SYS_PTR->ready_head,pcb,ready_list); OS_DEBUG(D_TASK,"Removed %s from ready list\n",pcb->constPtr->name); } static inline void Os_TaskMakeWaitingOnSem( OsTaskVarType *pcb ) { ASSERT( pcb->state & (ST_READY|ST_RUNNING) ); pcb->state = ST_WAITING_SEM; TAILQ_REMOVE(&OS_SYS_PTR->ready_head,pcb,ready_list); OS_DEBUG(D_TASK,"Removed %s from ready list\n",pcb->constPtr->name); } #endif // Terminate task static inline void Os_TaskMakeSuspended( OsTaskVarType *pcb ) { ASSERT( pcb->state & (ST_READY|ST_RUNNING) ); pcb->state = ST_SUSPENDED; TAILQ_REMOVE(&OS_SYS_PTR->ready_head,pcb,ready_list); OS_DEBUG(D_TASK,"Removed %s from ready list\n",pcb->constPtr->name); } /* ----------------------------[public functions]----------------------------*/ #if defined(CFG_PPC) || defined(CFG_ARMV7_AR) || defined (CFG_ARM_CR4) || defined(CFG_RH850) || defined(CFG_TMS570LC43X) /** * We come here after a task have returned. * */ void Os_TaskPost( void ) { OsTaskVarType *currPcbPtr= OS_SYS_PTR->currTaskPtr; /** @req OS239 */ Irq_Disable(); if( Os_SysIntAnyDisabled() ) { Os_SysIntClearAll(); } /** @req OS070 */ if( Os_TaskOccupiesResources(currPcbPtr) ) { Os_TaskResourceFreeAll(currPcbPtr); } /** @req OS069 */ Os_CallErrorHook(E_OS_MISSINGEND); /** @req OS052 */ (void)TerminateTask(); } #else /** @req OS067 */ /** * Start an extended task. * Tasks done: * - Grab the internal resource for the process * - Set it running state. * - Start to execute the process * */ void Os_TaskStartExtended( void ) { OsTaskVarType *pcb; pcb = Os_SysTaskGetCurr(); #if 0 Os_ResourceGetInternal(); Os_TaskMakeRunning(pcb); #endif // PRETASKHOOK(); Os_ArchFirstCall(); /* We got back without any TerminateTask() or ChainTask() * * OSEK: * Each task shall terminate itself at the end of its code. * Ending the task without a call to TerminateTask or ChainTask * is strictly forbidden and causes undefined behaviour. * * Autosar: * OS052, OS069, OS070 and OS239 * */ /** @req OS239 */ Irq_Disable(); if( Os_SysIntAnyDisabled() ) { Os_SysIntClearAll(); } /** @req OS070 */ if( Os_TaskOccupiesResources(pcb) ) { Os_TaskResourceFreeAll(pcb); } /** @req OS069 */ Os_CallErrorHook(E_OS_MISSINGEND); /** @req OS052 */ TerminateTask(); } /** * Start an basic task. * See extended task. */ void Os_TaskStartBasic( void ) { OsTaskVarType *pcb; pcb = Os_SysTaskGetCurr(); #if 0 Os_ResourceGetInternal(); Os_TaskMakeRunning(pcb); #endif // PRETASKHOOK(); Os_ArchFirstCall(); /** @req OS239 */ Irq_Disable(); if( Os_SysIntAnyDisabled() ) { Os_SysIntClearAll(); } /** @req OS070 */ if( Os_TaskOccupiesResources(pcb) ) { Os_TaskResourceFreeAll(pcb); } /** @req OS069 */ Os_CallErrorHook(E_OS_MISSINGEND); /** @req OS052 */ TerminateTask(); } #endif #if !defined(CFG_GNULINUX) void Os_StackSetup( OsTaskVarType *pcbPtr ) { uint8_t *bottom; /* Find bottom of the stack so that we can place the * context there. * * stack bottom = high address. stack top = low address */ //lint -e{9016} MISRA 2012 18.4 (adv) Allow calculation of address using pointers arithmetic bottom = (uint8_t *)pcbPtr->stack.top + pcbPtr->stack.size; ASSERT( ((uint32_t)bottom & 0x7UL) == 0 ); pcbPtr->stack.curr = bottom; // IMPROVEMENT: alignments here.. // IMPROVEMENT :use function os_arch_get_call_size() ?? // Make some space for back-chain. bottom -= 16; // Set the current stack so that it points to the context pcbPtr->stack.curr = bottom - Os_ArchGetScSize(); Os_StackSetEndmark(pcbPtr); } #endif /* !defined(CFG_GNULINUX) */ /** * Fill the stack with a predefined pattern * * @param pcbPtr Pointer to the pcb to fill with pattern */ #if !defined(CFG_GNULINUX) static void Os_StackFill(OsTaskVarType *pcbPtr) { uint8_t *p = pcbPtr->stack.curr; ASSERT(pcbPtr->stack.curr > pcbPtr->stack.top); //lint -e{946, 947} MISRA False positive. Pointers belong to the same "array" memset(pcbPtr->stack.top,STACK_PATTERN, (size_t)(p - (uint8_t *)pcbPtr->stack.top) ); } #endif /* !defined(CFG_GNULINUX) */ /** * Setup the context for a pcb. The context differs for different arch's * so we call the arch dependent functions also. * The context at setup is always a small context. * * @param pcb Ptr to the pcb to setup context for. */ #if !defined(CFG_GNULINUX) void Os_TaskContextInit( OsTaskVarType *pcb ) { if( pcb->constPtr->autostart ) { Os_TaskMakeReady(pcb); } else { pcb->state = ST_SUSPENDED; } Os_StackSetup(pcb); Os_StackFill(pcb); Os_ArchSetupContext(pcb); } #endif /* !defined(CFG_GNULINUX) */ /** * Find the top priority task. Even the running task is included. * NOTE: There should be a priority queue (using a heap?) here instead. * giving O(log n) for instertions and (1) for getting the top * prio task. The curerent implementation is ehhhh bad. * @return */ OsTaskVarType *Os_TaskGetTop( void ){ OsTaskVarType *i_pcb; OsTaskVarType *top_prio_pcb = NULL; OsPriorityType top_prio = 0; boolean found = FALSE; // OS_DEBUG(D_TASK,"os_find_top_prio_proc\n"); TAILQ_FOREACH(i_pcb,& OS_SYS_PTR->ready_head,ready_list) { // all ready task on the current core are candidates if (Os_OnRunningCore(OBJECT_TASK,i_pcb->constPtr->pid)) { if( i_pcb->state & (ST_READY | ST_RUNNING)) { if( found ) { if( i_pcb->activePriority > top_prio ) { top_prio = i_pcb->activePriority; top_prio_pcb = i_pcb; } } else { found = TRUE; top_prio = i_pcb->activePriority; top_prio_pcb = i_pcb; } } else { ASSERT(0); } } } ASSERT(top_prio_pcb!=NULL); OS_DEBUG(D_TASK,"Found %s\n",top_prio_pcb->constPtr->name); return top_prio_pcb; } void Os_TaskSetupAndSwap( void ) { OsTaskVarType *pcbPtr = Os_SysTaskGetCurr(); Os_ArchSetupContext(pcbPtr); Os_ArchSwapContextTo(NULL, pcbPtr); } //#define USE_LDEBUG_PRINTF #include "debug.h" // we come here from // - WaitEvent() // old_pcb -> WAITING // new_pcb -> READY(RUNNING) // - Schedule(), // old_pcb -> READY // new_pcb -> READY/RUNNING /* * two strategies * 1. When running -> * - remove from ready queue * - set state == ST_RUNNING * * 2. When running -> * * leave in ready queue * * set state == ST_RUNNING * - ready queue and ST_READY not the same * + No need to remove the running process from ready queue */ /** * Tries to Dispatch. * * Used by: * ActivateTask() * WaitEvent() * TerminateTask() * ChainTask() * * @param force Force a re-scheduling * */ #if !defined(CFG_GNULINUX) void Os_Dispatch( OpType op ) { OsTaskVarType *pcbPtr; OsTaskVarType *currPcbPtr = Os_SysTaskGetCurr(); ASSERT(OS_SYS_PTR->intNestCnt == 0); ASSERT(Os_SchedulerResourceIsFree()); /* When calling post hook we must still be in ST_RUNNING */ ASSERT( currPcbPtr->state & ST_RUNNING ); POSTTASKHOOK(); /* Go the correct state for running task */ switch (op) { case OP_SET_EVENT: case OP_SCHEDULE: case OP_RELEASE_RESOURCE: Os_TaskRunningToReady(currPcbPtr); break; case OP_WAIT_EVENT: Os_TaskMakeWaiting(currPcbPtr); break; #if defined(CFG_KERNEL_EXTRA) case OP_WAIT_SEMAPHORE: Os_TaskMakeWaitingOnSem(currPcbPtr); break; case OP_SIGNAL_SEMAPHORE: Os_TaskRunningToReady(currPcbPtr); break; case OP_SLEEP: Os_TaskMakeSleeping(currPcbPtr); break; #endif case OP_ACTIVATE_TASK: Os_TaskMakeReady(currPcbPtr); break; case OP_CHAIN_TASK: ASSERT( OS_SYS_PTR->chainedPcbPtr != NULL ); /* # from chain top * ---------------------------------------------------------- * 1 1 1 1 1->RUNNING * 2 1 1 2 1->READY, 2->RUNNING * 3 1 2 2 1->SUSPENDED/READY*, 2->RUNNING * 4 1 2 3 1->SUSPENDED/READY*, 2->READY , 3-RUNNING * * *) Depends on the number of activations. * * - Chained task is always READY when coming from ChainTask() */ if( currPcbPtr != OS_SYS_PTR->chainedPcbPtr ) { /* #3 and #4 */ if (currPcbPtr->activations > 0) { --currPcbPtr->activations; } if( currPcbPtr->activations == 0 ) { Os_TaskMakeSuspended(currPcbPtr); } else { Os_TaskRunningToReady(currPcbPtr); } /* Chained task is already in READY */ } OS_SYS_PTR->chainedPcbPtr = NULL; break; case OP_TERMINATE_TASK: /*@req OSEK TerminateTask * In case of tasks with multiple activation requests, * terminating the current instance of the task automatically puts the next * instance of the same task into the ready state */ if (currPcbPtr->activations > 0) { --currPcbPtr->activations; } if( currPcbPtr->activations == 0 ) { Os_TaskMakeSuspended(currPcbPtr); } break; default: ASSERT(0); break; } pcbPtr = Os_TaskGetTop(); /* Swap if we found any process or are forced (multiple activations)*/ if( pcbPtr != currPcbPtr ) { if( (OP_CHAIN_TASK == op) && ( currPcbPtr == OS_SYS_PTR->chainedPcbPtr ) ) { /* #2 */ Os_TaskRunningToReady(currPcbPtr); } /* * Swap context */ ASSERT(pcbPtr!=NULL); Os_ResourceReleaseInternal(); #if (OS_STACK_MONITORING == 1) if( !Os_StackIsEndmarkOk(currPcbPtr) ) { #if ( OS_SC1 == STD_ON) || ( OS_SC2 == STD_ON ) /** @req OS068 */ ShutdownOS(E_OS_STACKFAULT); #else /** @req OS396 * If a stack fault is detected by stack monitoring AND the configured scalability * class is 3 or 4, the Operating System module shall call the ProtectionHook() with * the status E_OS_STACKFAULT. * */ PROTECTIONHOOK(E_OS_STACKFAULT); #endif } #endif OS_DEBUG(D_TASK,"Swapping to: %s\n",pcbPtr->constPtr->name); #if defined(CFG_TC2XX) || defined(CFG_TC3XX) if ( (op == OP_TERMINATE_TASK) || (op == OP_CHAIN_TASK) ) { Os_TaskSwapContextTo(NULL,pcbPtr); } else { Os_TaskSwapContext(currPcbPtr,pcbPtr); } #else Os_TaskSwapContext(currPcbPtr,pcbPtr); #endif } else { OS_DEBUG(D_TASK,"Continuing task %s\n",pcbPtr->constPtr->name); #if defined(CFG_PPC) Os_TaskMakeRunning(pcbPtr); PRETASKHOOK(); /* Adjust stack pointer beyond the context area */ Os_StackSetup(pcbPtr); Os_ArchSetStackPointer(pcbPtr->stack.curr); Os_ArchSetupContext(pcbPtr); Os_ArchSwapContextTo(NULL, pcbPtr); #elif defined(CFG_ARMV7_AR) || defined(CFG_ARM_CR4) || defined(CFG_RH850) || defined(CFG_TMS570LC43X) Os_TaskMakeRunning(pcbPtr); PRETASKHOOK(); /* Adjust stack pointer beyond the context area */ Os_StackSetup(pcbPtr); Os_ArchSetSpAndCall(pcbPtr->stack.curr,Os_TaskSetupAndSwap); #else /* Setup the stack again, and just call the basic task */ Os_StackSetup(pcbPtr); /* NOTE: release and get the internal resource ? */ Os_TaskMakeRunning(pcbPtr); PRETASKHOOK(); Os_ArchSetSpAndCall(pcbPtr->stack.curr,Os_TaskStartBasic); ASSERT(0); #endif } } #endif /* !defined(CFG_GNULINUX) */ /* * Thoughts on task switching and memory protection * * If we would have had memory protection: * - Applications have their own MMU settings. * - Swapping between tasks in same Application does NOT involve the MMU. * - When running a non-trusted Application I need will have to: * - Run kernel in supervisor mode. * - Trap the start of each task * - All calls to the kernel will have a trap interface, i.e. Os_ResourceGetInternal(ActivateTask(TASK_ID_foo); * - An ISR2: * - The interupt is taken, the kernel runs in supervisor mode * - If the ISR2 activates * * Stack design: * ALT1: 1 kernel stack... * ALT2: * * Do we need virtual memory?? */ void Os_TaskSwapContext(OsTaskVarType *old_pcb, OsTaskVarType *new_pcb ) { Os_SysTaskSetCurr(new_pcb); #if (OS_USE_APPLICATIONS == STD_ON) OS_SYS_PTR->currApplId = new_pcb->constPtr->applOwnerId; #endif Os_ResourceGetInternal(); Os_TaskMakeRunning(new_pcb); /* NOTE: The pretask hook is not called with the right stack * (it's called on the old task stack, not the new ) */ PRETASKHOOK(); Os_ArchSwapContext(old_pcb,new_pcb); } void Os_TaskSwapContextTo(OsTaskVarType *old_pcb, OsTaskVarType *new_pcb ) { Os_SysTaskSetCurr(new_pcb); #if (OS_USE_APPLICATIONS == STD_ON) OS_SYS_PTR->currApplId = new_pcb->constPtr->applOwnerId; #endif Os_ResourceGetInternal(); Os_TaskMakeRunning(new_pcb); PRETASKHOOK(); Os_ArchSwapContextTo(old_pcb,new_pcb); ASSERT(0); } void Os_Arc_GetStackInfo( TaskType task, StackInfoType *s) { logger(LOG_ERR, "void Os_Arc_GetStackInfo( IMPROVEMENT )"); // OsTaskVarType *pcb = Os_TaskGet(task); // // s->curr = Os_ArchGetStackPtr(); // s->top = pcb->stack.top; // s->at_swap = pcb->stack.curr; // s->size = pcb->stack.size; // s->usage = (void *)Os_StackGetUsage(pcb); } void Os_Arc_GetTaskName(char *str, TaskType taskId) { const char *name = Os_TaskGet(taskId)->constPtr->name; strncpy(str, name , strlen(name)); } /** * Returns the state of a task (running, ready, waiting, suspended) * at the time of calling GetTaskState. * * @param TaskId Task reference * @param State Reference to the state of the task */ #if !defined(CFG_GNULINUX) StatusType GetTaskState(TaskType TaskId, TaskStateRefType State) { state_t curr_state; StatusType rv = E_OK; OsTaskVarType *pcb; OS_VALIDATE_STD_2( TASK_CHECK_ID(TaskId) , E_OS_ID, OSServiceId_GetTaskState,TaskId, State); pcb = Os_TaskGet(TaskId); #if (OS_APPLICATION_CNT > 1) && ( OS_NUM_CORES > 1) if (Os_ApplGetCore(pcb->constPtr->applOwnerId) != GetCoreID()) { StatusType status = Os_NotifyCore(Os_ApplGetCore(pcb->constPtr->applOwnerId), OSServiceId_GetTaskState, TaskId, (uint32_t)State, (uint32_t)0); return status; } #endif curr_state = os_pcb_get_state(pcb); // IMPROVEMENT: Lazy impl. for now */ switch(curr_state) { case ST_RUNNING: *State = TASK_STATE_RUNNING; break; case ST_WAITING: *State = TASK_STATE_WAITING; break; case ST_SUSPENDED: *State = TASK_STATE_SUSPENDED; break; case ST_READY: *State = TASK_STATE_READY; break; } return rv; } #endif /* !defined(CFG_GNULINUX) */ /** * GetTaskID returns the information about the TaskID of the task * which is currently running. * * @param task_id Reference to the task which is currently running * @return */ StatusType GetTaskID( TaskRefType TaskID ) { StatusType rv = E_OK; *TaskID = INVALID_TASK; int i; i = GetTaskId(); /* If valid task then point to data */ if ( i > -1 ) { *TaskID = ThreadTasks[i].pid; } // /* Test specification say return CALLEVEL if in ISR // * but impl. spec says otherwise */ // if( OS_SYS_PTR->intNestCnt == 0 ) { // if( OS_SYS_PTR->currTaskPtr->state & ST_RUNNING ) { // *TaskID = OS_SYS_PTR->currTaskPtr->constPtr->pid; // } else { // /* This is not a real error since this could // * be the case when called from ErrorHook */ // } // } return rv; } /** * This service returns the identifier of the currently executing ISR * * If its caller is not a category 2 ISR (or Hook routines called * inside a category 2 ISR), GetISRID() shall return INVALID_ISR. * * @return */ /** @req OS511 OS provides the service GetISRID() */ /** @req OS515 GetISRID() available in all Scalability Classes. */ ISRType GetISRID( void ) { /** @req OS264 */ if(OS_SYS_PTR->intNestCnt == 0 ) { return INVALID_ISR; } if( Os_SysIsrGetCurr()->constPtr->type == ISR_TYPE_1 ) { return INVALID_ISR; } /** @req OS263 */ return (ISRType)Os_SysIsrGetCurr()->id; } #if !defined(CFG_GNULINUX) static inline void Os_Arc_SetCleanContext( OsTaskVarType *pcb ) { if (pcb->constPtr->proc_type == PROC_EXTENDED) { /** @req OSEK ActivateTask Cleanup events * OSEK,ActivateTask, When an extended task is transferred from suspended * state into ready state all its events are cleared.*/ pcb->ev_set = 0; pcb->ev_wait = 0; } Os_StackSetup(pcb); Os_ArchSetupContext(pcb); } #endif /* !defined(CFG_GNULINUX) */ /** * The task <TaskID> is transferred from the suspended state into * the ready state. The operating system ensures that the task * code is being executed from the first statement. * * The service may be called from interrupt level and from task * level (see Figure 12-1). * Rescheduling after the call to ActivateTask depends on the * place it is called from (ISR, non preemptable task, preemptable * task). * * If E_OS_LIMIT is returned the activation is ignored. * When an extended task is transferred from suspended state * into ready state all its events are cleared. * * Note! * ActivateTask will not immediately change the state of the task * in case of multiple activation requests. If the task is not * suspended, the activation will only be recorded and performed later. * * @param pid * @return */ StatusType ActivateTask( TaskType TaskID ) { StatusType rv = E_OK; #if defined(CFG_GNULINUX) OS_DEBUG(D_TASK,"# ActivateTask %d\n", TaskID); /* ActivateTask on GNU/Linux is to restart a task that ended/exited. */ rv = start_thread(TaskID); return rv; #else imask_t flags; OsTaskVarType *currPcbPtr = Os_SysTaskGetCurr(); OsTaskVarType *destPcbPtr; OS_DEBUG(D_TASK,"# ActivateTask %s\n",currPcbPtr->constPtr->name); TASK_CHECK_ID(TaskID); destPcbPtr = Os_TaskGet(TaskID); #if (OS_SC3==STD_ON) || (OS_SC4==STD_ON) if( destPcbPtr->constPtr->applOwnerId != currPcbPtr->constPtr->applOwnerId ) { ApplicationType appId; OS_VALIDATE_STD_1( (Os_ApplCheckState(destPcbPtr->constPtr->applOwnerId) != E_OS_ACCESS) , E_OS_ACCESS, OSServiceId_ActivateTask,TaskID); /* Do we have access to the task we are activating */ if(OS_SYS_PTR->intNestCnt == 0 ) { appId = currPcbPtr->constPtr->applOwnerId; } else { appId = Os_SysIsrGetCurr()->constPtr->appOwner; } OS_VALIDATE_STD_1( (Os_ApplCheckAccess(appId , destPcbPtr->constPtr->accessingApplMask) != E_OS_ACCESS) , E_OS_ACCESS, OSServiceId_ActivateTask,TaskID); #if (OS_NUM_CORES > 1) if (Os_ApplGetCore(destPcbPtr->constPtr->applOwnerId) != GetCoreID()) { StatusType status = Os_NotifyCore(Os_ApplGetCore(destPcbPtr->constPtr->applOwnerId), OSServiceId_ActivateTask, TaskID, (uint32_t)NULL, (uint32_t)NULL); return status; } #endif } #endif /* @req OS093 ActivateTask */ if( Os_SysIntAnyDisabled() ) { /* Standard */ rv = E_OS_DISABLEDINT; OS_STD_ERR_1(OSServiceId_ActivateTask,TaskID); } Irq_Save(flags); destPcbPtr->activations++; if( os_pcb_get_state(destPcbPtr) != ST_SUSPENDED ) { /** @req OSEK_? Too many task activations */ if( destPcbPtr->activations >= (destPcbPtr->constPtr->activationLimit + 1) ) { /* Standard */ rv=E_OS_LIMIT; /* OSEK Standard Status */ Irq_Restore(flags); --destPcbPtr->activations; OS_STD_ERR_1(OSServiceId_ActivateTask,TaskID); } } else { /* We have a suspended task, make it ready for use */ ASSERT( destPcbPtr->activations == 1 ); Os_Arc_SetCleanContext(destPcbPtr); Os_TaskMakeReady(destPcbPtr); } /* Preempt only if we are preemptable and target has higher prio than us */ //lint -e{9007} MISRA False positive. No side effects of Os_SchedulerResourceIsFree if( (OS_SYS_PTR->intNestCnt == 0) && (currPcbPtr->constPtr->scheduling == FULL) && (destPcbPtr->activePriority > Os_SysTaskGetCurr()->activePriority) && (Os_SchedulerResourceIsFree())) { Os_Dispatch(OP_ACTIVATE_TASK); } Irq_Restore(flags); return rv; #endif /* else of #ifdef CFG_GNULINUX*/ } /** * This service causes the termination of the calling task. The * calling task is transferred from the running state into the * suspended state. * * An internal resource assigned to the calling task is automatically * released. Other resources occupied by the task shall have been * released before the call to TerminateTask. If a resource is still * occupied in standard status the behaviour is undefined. * * If the call was successful, TerminateTask does not return to the * call level and the status can not be evaluated. * * If the version with extended status is used, the service returns * in case of error, and provides a status which can be evaluated * in the application. * * If the service TerminateTask is called successfully, it enforces a * rescheduling. * * [ Ending a task function without call to TerminateTask * or ChainTask is strictly forbidden and may leave the system in an * undefined state. ] * * [] is an OSEK requirement and is overridden by OS052 * * @return */ #if !defined(CFG_GNULINUX) StatusType TerminateTask( void ) { StatusType rv = E_OK; OsTaskVarType *currPcbPtr = Os_SysTaskGetCurr(); OS_DEBUG(D_TASK,"# TerminateTask %s\n",OS_SYS_PTR->currTaskPtr->constPtr->name); OS_VALIDATE_STD( OS_SYS_PTR->intNestCnt == 0, E_OS_CALLEVEL , OSServiceId_TerminateTask); OS_VALIDATE_STD( !Os_TaskOccupiesResources(currPcbPtr), E_OS_RESOURCE , OSServiceId_TerminateTask); #if (OS_NUM_CORES > 1) OS_VALIDATE_STD( !Os_TaskOccupiesSpinlocks(currPcbPtr), E_OS_SPINLOCK , OSServiceId_TerminateTask); /* @req 4.1.2/SWS_Os_00612 */ #endif Irq_Disable(); /* Force the dispatcher to find something, even if its us */ Os_Dispatch(OP_TERMINATE_TASK); ASSERT(0); return rv; } #else /* defined(CFG_GNULINUX) */ StatusType TerminateTask(){ TaskType CurrentTaskId; CurrentTaskId = GetTaskId(); if ( CurrentTaskId > -1 ) { /* TerminateTask is called by the running thread. (self) */ pthread_mutex_lock(&ThreadTasks[CurrentTaskId].mutex_lock); int thread_is_started = ( ThreadTasks[CurrentTaskId].pthread_status == GNULINUX_PTHREAD_FUNCTION_STARTED ); if (thread_is_started) { ThreadTasks[CurrentTaskId].pthread_status = GNULINUX_PTHREAD_FUNCTION_TERMINATED; } pthread_mutex_unlock(&ThreadTasks[CurrentTaskId].mutex_lock); if (!thread_is_started) { logger(LOG_ERR, "TerminateTask PTHREAD_FUNCTION_NOT_STARTED %s Id (%d) %d.", ThreadTasks[CurrentTaskId].name, CurrentTaskId, ThreadTasks[CurrentTaskId].pthread_status); } else { logger_mod((LOGGER_MOD_LINOS|LOGGER_SUB_OS_TASK), LOG_INFO, "TerminateTask called for %s Id (%d).", ThreadTasks[CurrentTaskId].name, CurrentTaskId); } return E_OK; } else { logger(LOG_ERR, "TerminateTask ERROR. Couldn't identify calling Task ID."); return E_NOT_OK; } return E_OK; } #endif #if !defined(CFG_GNULINUX) StatusType ChainTask( TaskType TaskId ) { imask_t flags; StatusType rv = E_OK; OsTaskVarType *currPcbPtr = Os_SysTaskGetCurr(); OsTaskVarType *destPcbPtr; OS_VALIDATE_STD_1( TASK_CHECK_ID(TaskId) , E_OS_ID, OSServiceId_ChainTask,TaskId); destPcbPtr = Os_TaskGet(TaskId); OS_DEBUG(D_TASK,"# ChainTask %s\n",destPcbPtr->constPtr->name); OS_VALIDATE_STD_1( OS_SYS_PTR->intNestCnt == 0, E_OS_CALLEVEL , OSServiceId_ChainTask,TaskId); OS_VALIDATE_STD_1( !Os_TaskOccupiesResources(currPcbPtr), E_OS_RESOURCE , OSServiceId_ChainTask,TaskId); #if (OS_NUM_CORES > 1) OS_VALIDATE_STD_1( !Os_TaskOccupiesSpinlocks(currPcbPtr), E_OS_SPINLOCK , OSServiceId_ChainTask,TaskId); /* @req 4.1.2/SWS_Os_00612 */ #endif Irq_Save(flags); if (currPcbPtr != destPcbPtr) { /** @req OSEK_? Too many task activations */ if( (destPcbPtr->activations + 1) > destPcbPtr->constPtr->activationLimit ) { rv = E_OS_LIMIT; /* OSEK Standard Status */ Irq_Restore(flags); OS_STD_ERR_1(OSServiceId_ChainTask,TaskId); } if( os_pcb_get_state(destPcbPtr) == ST_SUSPENDED ) { ASSERT( destPcbPtr->activations == 0 ); Os_Arc_SetCleanContext(destPcbPtr); Os_TaskMakeReady(destPcbPtr); } destPcbPtr->activations++; } OS_SYS_PTR->chainedPcbPtr = destPcbPtr; #if (OS_APPLICATION_CNT > 1) && (OS_NUM_CORES > 1) if (Os_ApplGetCore(destPcbPtr->constPtr->applOwnerId) != GetCoreID()) { StatusType status = Os_NotifyCore(Os_ApplGetCore(destPcbPtr->constPtr->applOwnerId), OSServiceId_ChainTask, TaskId, 0, 0); OS_SYS_PTR->chainedPcbPtr = destPcbPtr; (void)status; } #endif Os_Dispatch(OP_CHAIN_TASK); ASSERT( 0 ); return rv; } #endif /* !defined(CFG_GNULINUX) */ /** * If a higher-priority task is ready, the internal resource of the task * is released, the current task is put into the ready state, its * context is saved and the higher-priority task is executed. * Otherwise the calling task is continued. * * NOTE: The OSEK spec says a lot of strange things under "particulareties" * that I don't understand * * See OSEK/VDX 13.2.3.4 * */ #if !defined(CFG_GNULINUX) StatusType Schedule( void ) { StatusType rv = E_OK; imask_t flags; OsTaskVarType *currPcbPtr = Os_SysTaskGetCurr(); OS_DEBUG(D_TASK,"# Schedule %s\n",currPcbPtr->constPtr->name); /* Check that we are not calling from interrupt context */ OS_VALIDATE_STD( OS_SYS_PTR->intNestCnt == 0, E_OS_CALLEVEL , OSServiceId_Schedule); /* @req 4.1.2/SWS_Os_00088 */ OS_VALIDATE_STD( !Os_TaskOccupiesResources(currPcbPtr), E_OS_RESOURCE , OSServiceId_Schedule); /* OSEK */ #if (OS_NUM_CORES > 1) OS_VALIDATE_STD( !Os_TaskOccupiesSpinlocks(currPcbPtr), E_OS_SPINLOCK , OSServiceId_Schedule); /* @req 4.1.2/SWS_Os_00624 */ #endif ASSERT( Os_SysTaskGetCurr()->state & ST_RUNNING ); /* We need to figure out if we have an internal resource, * otherwise no re-scheduling. * NON - Have internal resource prio OS_RES_SCHEDULER_PRIO (32+) * FULL - Assigned internal resource OR * No assigned internal resource. * */ if( Os_SysTaskGetCurr()->constPtr->scheduling != NON ) { return E_OK; } { Irq_Save(flags); OsTaskVarType* top_pcb = Os_TaskGetTop(); /* only dispatch if some other ready task has higher prio */ if (top_pcb->activePriority > Os_SysTaskGetCurr()->activePriority) { Os_Dispatch(OP_SCHEDULE); } Irq_Restore(flags); } return rv; } #endif /* !defined(CFG_GNULINUX) */ void Os_Arc_GetTaskInfo( Arc_PcbType *pcbPtr, TaskType taskId, uint32 flags ) { OsTaskVarType *taskPtr = Os_TaskGet(taskId); if( flags & OS_ARC_F_TASK_BASIC) { strncpy(pcbPtr->name,taskPtr->constPtr->name,OS_ARC_PCB_NAME_SIZE); pcbPtr->tasktype = (taskPtr->constPtr->proc_type == PROC_EXTENDED ) ? ARC_TASKTYPE_EXENDED : ARC_TASKTYPE_BASIC; } if( flags & OS_ARC_F_TASK_STACK) { Os_Arc_GetStackInfo(taskId, &pcbPtr->stack ); } }
2301_81045437/classic-platform
system/LinuxOs/src/os_task_linos.c
C
unknown
34,445
SPHINXDIR=../../../../scripts/sphinx doc_module=OSAL doc_type=dd doc_mcu=mpc560x #rstp-y += index.rst #build_mcal_doc can um mpc5xxx #build_mcal_dd_doc MCAL dd include $(SPHINXDIR)/build_doc.mk
2301_81045437/classic-platform
system/Os/doc/dd/makefile
Makefile
unknown
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 -----------------------------*/ #include "Os.h" #include "os_i.h" #include "sys.h" void Os_ArchInit(void) { } void Os_ArchFirstCall( void ) { } uint32 Os_ArchGetScSize( void ) { } void Os_ArchSetupContext( OsTaskVarType *pcb ) { } void Os_ArchSetSpAndCall(void *sp, void (*f)(void) ) { } void Os_ArchSwapContext(void *old,void *new) { } void Os_ArchSwapContextTo(void *old,void *new){ } void *Os_ArchGetStackPtr( void ) { } Std_ReturnType Os_ArchCheckStartStackMarker( void ) { return E_OK; }
2301_81045437/classic-platform
system/Os/osal/generic/linux/kernel/arch.c
C
unknown
1,261
/*-------------------------------- 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 "irq.h" #include "Std_Types.h" void Irq_Init( void ) { } void Irq_EnableVector( sint16 vector, uint8 priority, sint32 core ) { } void Irq_EOI( int16_t vector ) { (void)vector; }
2301_81045437/classic-platform
system/Os/osal/generic/linux/kernel/irq.c
C
unknown
956
/*-------------------------------- 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 IRQ_TYPES_H #define IRQ_TYPES_H /** * End-Of-Interrupt. Called by the OS it wants to clear the interrupt. */ void Irq_EOI( int16_t vector ); typedef enum { PERIPHERAL_CLOCK_LIN_A, PERIPHERAL_CLOCK_LIN_B, PERIPHERAL_CLOCK_LIN_C, PERIPHERAL_CLOCK_FLEXCAN_A, PERIPHERAL_CLOCK_FLEXCAN_B, PERIPHERAL_CLOCK_FLEXCAN_C, } Mcu_Arc_PeriperalClock_t; typedef enum { CPU_CORE0, } Cpu_t; /* Offset from exceptions to interrupts */ #define IRQ_INTERRUPT_OFFSET 0 #endif /* IRQ_H_ */
2301_81045437/classic-platform
system/Os/osal/generic/linux/kernel/irq_types.h
C
unknown
1,301
/*-------------------------------- 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 -----------------------------*/ s #include "Std_Types.h" void Os_SysTickInit( void ) { } void Os_SysTickStart(uint32_t period_ticks) { }
2301_81045437/classic-platform
system/Os/osal/generic/linux/kernel/sys_tick.c
C
unknown
861
cflags-$(OS_32BIT)+= -m32 LDFLAGS-$(OS_32BIT)+= -m32
2301_81045437/classic-platform
system/Os/osal/generic/linux/scripts/gcc.mk
Makefile
unknown
59
/*-------------------------------- 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 "Os.h" #include "os_i.h" void Os_ArchInit(void) { } void Os_ArchFirstCall( void ) { } uint32 Os_ArchGetScSize( void ) { return (unsigned int) 0; } void Os_ArchSetupContext( OsTaskVarType *pcb ) { } void Os_ArchSetSpAndCall(void *sp, void (*f)(void) ) { } void Os_ArchSwapContext(void *old,void *new) { } void Os_ArchSwapContextTo(void *old,void *new){ } void *Os_ArchGetStackPtr( void ) { return NULL; } Std_ReturnType Os_ArchCheckStartStackMarker( void ) { return E_OK; }
2301_81045437/classic-platform
system/Os/osal/gnulinux/gnulinux/kernel/arch.c
C
unknown
1,287
/*-------------------------------- 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 "irq.h" #include "Std_Types.h" void Irq_Init( void ) { } void Irq_EnableVector( sint16 vector, uint8 priority, sint32 core ) { } void Irq_EOI( int16_t vector ) { (void)vector; }
2301_81045437/classic-platform
system/Os/osal/gnulinux/gnulinux/kernel/irq.c
C
unknown
956
/*-------------------------------- 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 IRQ_TYPES_H #define IRQ_TYPES_H #define Irq_SOI() /** * End-Of-Interrupt. Called by the OS it wants to clear the interrupt. */ void Irq_EOI( int16_t vector ); typedef enum { /* Software interrupts. */ INTC_SSCIR0_CLR0, // 0 INTC_SSCIR0_CLR1, // 1 INTC_SSCIR0_CLR2, // 2 INTC_SSCIR0_CLR3, // 3 INTC_SSCIR0_CLR4, // 4 INTC_SSCIR0_CLR5, // 5 INTC_SSCIR0_CLR6, // 6 INTC_SSCIR0_CLR7, // 7 #if defined(CFG_MPC560X) RESERVED0, // 5606-8 ECSM_INT, // 5606-9 DMA_COMBINED_ERROR_INT, // 5606-10 DMA_CH0_INT, // 5606-11 DMA_CH1_INT, // 5606-12 DMA_CH2_INT, // 5606-13 DMA_CH3_INT, // 5606-14 DMA_CH4_INT, // 5606-15 DMA_CH5_INT, // 5606-16 DMA_CH6_INT, // 5606-17 DMA_CH7_INT, // 5606-18 DMA_CH8_INT, // 5606-19 DMA_CH9_INT, // 5606-20 DMA_CH10_INT, // 5606-21 DMA_CH11_INT, // 5606-22 DMA_CH12_INT, // 5606-23 DMA_CH13_INT, // 5606-24 DMA_CH14_INT, // 5606-25 DMA_CH15_INT, // 5606-26 RESERVED1, // 5606-27 SWT_TIMEOUT, // 5606-28 RESERVED2, // 5606-29 STM_CH0_INT, // 5606-30 STM_CH1_INT, // 5606-31 STM_CH2_INT, // 5606-32 STM_CH3_INT, // 5606-33 RESERVED3, // 5606-34 ECC_DBD_INT, // 5606-35 ECC_SBC_INT, // 5606-36 RESERVED4, // 5606-37 RTC_INT, // 5606-38 API_INT, // 5606-39 RESERVED5, // 5606-40 SIU_EXT_IRQ0, // 5606-41 SIU_EXT_IRQ1, // 5606-42 RESERVED6, // 5606-43 RESERVED7, // 5606-44 RESERVED8, // 5606-45 WAKEUP_IRQ0, // 5606-46 WAKEUP_IRQ1, // 5606-47 WAKEUP_IRQ2, // 5606-48 RESERVED9, // 5606-49 RESERVED10, // 5606-50 SAFE_MODE_INT, // 5606-51 MODE_TRAS_INT, // 5606-52 INV_MODE_INT, // 5606-53 INV_MODE_CONF_INT, // 5606-54 RESERVED11, // 5606-55 RESET_ALT_EVENT_INT, // 5606-56 FXOSC_COUNTER_EXPIRED, // 5606-57 RESERVED12, // 5606-58 PIT_INT0, // 5606-59 PIT_INT1, // 5606-60 PIT_INT2, // 5606-61 ADC_EOC_INT, // 5606-62 ADC_ER_INT, // 5606-63 ADC_WD_INT, // 5606-64 FLEXCAN_0_ESR_ERR_INT, // 5606-65 FLEXCAN_0_ESR_BOFF_INT, // 5606-66 RESERVED13, // 5606-67 FLEXCAN_0_BUF_00_03, // 5606-68 FLEXCAN_0_BUF_04_07, // 5606-69 FLEXCAN_0_BUF_08_11, // 5606-70 FLEXCAN_0_BUF_12_15, // 5606-71 FLEXCAN_0_BUF_16_31, // 5606-72 FLEXCAN_0_BUF_32_63, // 5606-73 DSPI_0_ISR_TFUF_RFOF, // 5606-74 DSPI_0_ISR_EOQF, // 5606-75 DSPI_0_ISR_TFFF, // 5606-76 DSPI_0_ISR_TCF, // 5606-77 DSPI_0_ISR_RFDF, // 5606-78 LINFLEX_0_RXI, // 5606-79 LINFLEX_0_TXI, // 5606-80 LINFLEX_0_ERR, // 5606-81 RESERVED14, // 5606-82 RESERVED15, // 5606-83 RESERVED16, // 5606-84 FLEXCAN_1_ESR_ERR_INT, // 5606-85 FLEXCAN_1_ESR_BOFF_INT, // 5606-86 RESERVED17, // 5606-87 FLEXCAN_1_BUF_00_03, // 5606-88 FLEXCAN_1_BUF_04_07, // 5606-89 FLEXCAN_1_BUF_08_11, // 5606-90 FLEXCAN_1_BUF_12_15, // 5606-91 FLEXCAN_1_BUF_16_31, // 5606-92 FLEXCAN_1_BUF_32_63, // 5606-93 DSPI_1_ISR_TFUF_RFOF, // 5606-94 DSPI_1_ISR_EOQF, // 5606-95 DSPI_1_ISR_TFFF, // 5606-96 DSPI_1_ISR_TCF, // 5606-97 DSPI_1_ISR_RFDF, // 5606-98 LINFLEX_1_RXI, // 5606-99 LINFLEX_1_TXI, // 5606-100 LINFLEX_1_ERR, // 5606-101 RESERVED18, // 5606-102 RESERVED19, // 5606-103 RESERVED20, // 5606-104 FLEXCAN_2_ESR_ERR_INT, // 5606-105 FLEXCAN_2_ESR_BOFF_INT, // 5606-106 RESERVED21, // 5606-107 FLEXCAN_2_BUF_00_03, // 5606-108 FLEXCAN_2_BUF_04_07, // 5606-109 FLEXCAN_2_BUF_08_11, // 5606-110 FLEXCAN_2_BUF_12_15, // 5606-111 FLEXCAN_2_BUF_16_31, // 5606-112 FLEXCAN_2_BUF_32_63, // 5606-113 DSPI_2_ISR_TFUF_RFOF, // 5606-114 DSPI_2_ISR_EOQF, // 5606-115 DSPI_2_ISR_TFFF, // 5606-116 DSPI_2_ISR_TCF, // 5606-117 DSPI_2_ISR_RFDF, // 5606-118 LINFLEX_2_RXI, // 5606-119 LINFLEX_2_TXI, // 5606-120 LINFLEX_2_ERR, // 5606-121 LINFLEX_3_RXI, // 5606-122 LINFLEX_3_TXI, // 5606-123 LINFLEX_3_ERR, // 5606-124 I2C_0_INT, // 5606-125 I2C_1_INT, // 5606-126 PIT_INT3, // 5606-127 PIT_INT4, // 5606-128 PIT_INT5, // 5606-129 RESERVED43, // 5606-130 RESERVED44, // 5606-131 RESERVED45, // 5606-132 RESERVED46, // 5606-133 RESERVED47, // 5606-134 RESERVED48, // 5606-135 RESERVED49, // 5606-136 RESERVED50, // 5606-137 RESERVED51, // 5606-138 RESERVED52, // 5606-139 RESERVED53, // 5606-140 #if defined (CFG_MPC5604B) EMIOS_0_GFR_F0_F1, // 5606-141 EMIOS_0_GFR_F2_F3, // 5606-142 EMIOS_0_GFR_F4_F5, // 5606-143 EMIOS_0_GFR_F6_F7, // 5606-144 EMIOS_0_GFR_F8_F9, // 5606-145 EMIOS_0_GFR_F10_F11, // 5606-146 EMIOS_0_GFR_F12_F13, // 5606-147 EMIOS_0_GFR_F14_F15, // 5606-148 EMIOS_0_GFR_F16_F17, // 5606-149 EMIOS_0_GFR_F18_F19, // 5606-150 EMIOS_0_GFR_F20_F21, // 5606-151 EMIOS_0_GFR_F22_F23, // 5606-152 EMIOS_0_GFR_F24_F25, // 5606-153 EMIOS_0_GFR_F26_F27, // 5606-154 RESERVED54, // 5606-155 RESERVED55, // 5606-156 EMIOS_1_GFR_F0_F1, // 5606-157 EMIOS_1_GFR_F2_F3, // 5606-158 EMIOS_1_GFR_F4_F5, // 5606-159 EMIOS_1_GFR_F6_F7, // 5606-160 EMIOS_1_GFR_F8_F9, // 5606-161 EMIOS_1_GFR_F10_F11, // 5606-162 EMIOS_1_GFR_F12_F13, // 5606-163 EMIOS_1_GFR_F14_F15, // 5606-164 EMIOS_1_GFR_F16_F17, // 5606-165 EMIOS_1_GFR_F18_F19, // 5606-166 EMIOS_1_GFR_F20_F21, // 5606-167 EMIOS_1_GFR_F22_F23, // 5606-168 EMIOS_1_GFR_F24_F25, // 5606-169 EMIOS_1_GFR_F26_F27, // 5606-170 RESERVED56, // 5606-171 RESERVED57, // 5606-172 FLEXCAN_3_ESR_ERR_INT, // 5606-173 FLEXCAN_3_ESR_BOFF_INT, // 5606-174 RESERVED58, // 5606-175 FLEXCAN_3_BUF_00_03, // 5606-176 FLEXCAN_3_BUF_04_07, // 5606-177 FLEXCAN_3_BUF_08_11, // 5606-178 FLEXCAN_3_BUF_12_15, // 5606-179 FLEXCAN_3_BUF_16_31, // 5606-180 FLEXCAN_3_BUF_32_63, // 5606-181 RESERVED59, // 5606-182 RESERVED60, // 5606-183 RESERVED61, // 5606-184 RESERVED62, // 5606-185 RESERVED63, // 5606-186 RESERVED64, // 5606-187 RESERVED65, // 5606-188 RESERVED66, // 5606-189 FLEXCAN_4_ESR_ERR_INT, // 5606-190 FLEXCAN_4_ESR_BOFF_INT, // 5606-191 RESERVED67, // 5606-192 FLEXCAN_4_BUF_00_03, // 5606-193 FLEXCAN_4_BUF_04_07, // 5606-194 FLEXCAN_4_BUF_08_11, // 5606-195 FLEXCAN_4_BUF_12_15, // 5606-196 FLEXCAN_4_BUF_16_31, // 5606-197 FLEXCAN_4_BUF_32_63, // 5606-198 RESERVED68, // 5606-199 RESERVED69, // 5606-200 RESERVED70, // 5606-201 FLEXCAN_5_ESR_ERR_INT, // 5606-202 FLEXCAN_5_ESR_BOFF_INT, // 5606-203 RESERVED71, // 5606-204 FLEXCAN_5_BUF_00_03, // 5606-205 FLEXCAN_5_BUF_04_07, // 5606-206 FLEXCAN_5_BUF_08_11, // 5606-207 FLEXCAN_5_BUF_12_15, // 5606-208 FLEXCAN_5_BUF_16_31, // 5606-209 FLEXCAN_5_BUF_32_63, // 5606-210 RESERVED72, // 5606-211 RESERVED73, // 5606-212 RESERVED74, // 5606-213 RESERVED75, // 5606-214 RESERVED76, // 5606-215 RESERVED77, // 5606-216 #elif defined (CFG_MPC5606S) EMIOS_0_GFR_F8_F9, // 5606-141 EMIOS_0_GFR_F10_F11, // 5606-142 EMIOS_0_GFR_F12_F13, // 5606-143 EMIOS_0_GFR_F14_F15, // 5606-144 EMIOS_0_GFR_F16_F17, // 5606-145 EMIOS_0_GFR_F18_F19, // 5606-146 EMIOS_0_GFR_F20_F21, // 5606-147 EMIOS_0_GFR_F22_F23, // 5606-148 RESERVED54, // 5606-149 RESERVED55, // 5606-150 RESERVED56, // 5606-151 RESERVED57, // 5606-152 RESERVED58, // 5606-153 RESERVED59, // 5606-154 RESERVED60, // 5606-155 RESERVED61, // 5606-156 EMIOS_1_GFR_F16_F17, // 5606-157 EMIOS_1_GFR_F18_F19, // 5606-158 EMIOS_1_GFR_F20_F21, // 5606-159 EMIOS_1_GFR_F22_F23, // 5606-160 RESERVED62, // 5606-161 RESERVED63, // 5606-162 RESERVED64, // 5606-163 RESERVED65, // 5606-164 RESERVED66, // 5606-165 RESERVED67, // 5606-166 RESERVED68, // 5606-167 RESERVED69, // 5606-168 RESERVED70, // 5606-169 RESERVED71, // 5606-170 RESERVED72, // 5606-171 RESERVED73, // 5606-172 I2C_2_INT, // 5606-173 I2C_3_INT, // 5606-174 RESERVED74, // 5606-175 RESERVED75, // 5606-176 RESERVED76, // 5606-177 RESERVED77, // 5606-178 RESERVED78, // 5606-179 RESERVED79, // 5606-180 RESERVED80, // 5606-181 RESERVED81, // 5606-182 SDCI_INT, // 5606-183 DCUN0_VSYNC_INT, // 5606-184 DCUN0_UNDRUN, // 5606-185 DCUN0_PARERR, // 5606-186 DCUN0_PDI, // 5606-187 RESERVED82, // 5606-188 RESERVED83, // 5606-189 RESERVED84, // 5606-190 RESERVED85, // 5606-191 SMD0_INT, // 5606-192 SSD0_INT, // 5606-193 SSD1_INT, // 5606-194 SSD2_INT, // 5606-195 SSD3_INT, // 5606-196 SSD4_INT, // 5606-197 SSD5_INT, // 5606-198 LCD0_EOF_INT, // 5606-199 RESERVED86, // 5606-200 QSPI0_TFUF, // 5606-201 QSPI0_EOQF, // 5606-202 QSPI0_TFFF, // 5606-203 QSPI0_TCF, // 5606-204 QSPI0_RFDF, // 5606-205 QSPI0_IPAEF, // 5606-206 #endif INTC_NUMBER_OF_INTERRUPTS, #else /* end CFG_MPC560X */ MCM_MSWTIR_SWTIC, // 8 MCM_ESR_COMB, // 9 /* eDMA */ EDMA_ERRL_ERR31_0, // 10 EDMA_INTL_INT0, // 11 EDMA_INTL_INT1, EDMA_INTL_INT2, EDMA_INTL_INT3, EDMA_INTL_INT4, EDMA_INTL_INT5, EDMA_INTL_INT6, EDMA_INTL_INT7, EDMA_INTL_INT8, EDMA_INTL_INT9, EDMA_INTL_INT10, EDMA_INTL_INT11, EDMA_INTL_INT12, EDMA_INTL_INT13, EDMA_INTL_INT14, EDMA_INTL_INT15, // 26 #if defined(CFG_MPC5554)||defined(CFG_MPC5567) EDMA_INTL_INT16, EDMA_INTL_INT17, EDMA_INTL_INT18, EDMA_INTL_INT19, // 30 EDMA_INTL_INT20, EDMA_INTL_INT21, EDMA_INTL_INT22, EDMA_INTL_INT23, EDMA_INTL_INT24, EDMA_INTL_INT25, EDMA_INTL_INT26, EDMA_INTL_INT27, EDMA_INTL_INT28, EDMA_INTL_INT29, EDMA_INTL_INT30, EDMA_INTL_INT31, // 42 #else RESERVED0, RESERVED1, RESERVED2, RESERVED3, // 30 RESERVED4, RESERVED5, RESERVED6, RESERVED7, RESERVED8, RESERVED9, RESERVED10, RESERVED11, RESERVED12, RESERVED13, RESERVED14, RESERVED15, // 42 #endif #if defined(CFG_MPC5516) /* Semahpore's */ SEMAPHORE_INT0, // 43 SEMAPHORE_INT1, RESERVED16, CRP_INTERRUPT, LVI_INTERRUPT, IIC_A_IBSR_IBIF, RESERVED17, #endif PLL_SYNSR_LOCF, // 54-43, 16-50 PLL_SYNSR_LOLF, // 54-44, 16-51 SIU_OSR_OVER, /* External interrupts */ SIU_EISR_EIF0, // 53 SIU_EISR_EIF1, SIU_EISR_EIF2, SIU_EISR_EIF3, SIU_EISR_EIF15_4, // 54-50, 57 /* eMIOS */ EMISOS200_FLAG_F0, // 58 EMISOS200_FLAG_F1, EMISOS200_FLAG_F2, EMISOS200_FLAG_F3, EMISOS200_FLAG_F4, EMISOS200_FLAG_F5, EMISOS200_FLAG_F6, EMISOS200_FLAG_F7, EMISOS200_FLAG_F8, EMISOS200_FLAG_F9, EMISOS200_FLAG_F10, EMISOS200_FLAG_F11, EMISOS200_FLAG_F12, EMISOS200_FLAG_F13, EMISOS200_FLAG_F14, EMISOS200_FLAG_F15, // 73 #if defined(CFG_MPC5516) EMISOS200_FLAG_F16, EMISOS200_FLAG_F17, EMISOS200_FLAG_F18, EMISOS200_FLAG_F19, EMISOS200_FLAG_F20, EMISOS200_FLAG_F21, EMISOS200_FLAG_F22, EMISOS200_FLAG_F23, // 16-81 #elif defined(CFG_MPC5554)||defined(CFG_MPC5567) ETPU_GLOBAL, // 54-67 ETPU_A_CIS_0, ETPU_A_CIS_1, ETPU_A_CIS_2, // 54-70 ETPU_A_CIS_3, ETPU_A_CIS_4, ETPU_A_CIS_5, ETPU_A_CIS_6, ETPU_A_CIS_7, ETPU_A_CIS_8, ETPU_A_CIS_9, ETPU_A_CIS_10, ETPU_A_CIS_11, ETPU_A_CIS_12, // 54-80 ETPU_A_CIS_13, ETPU_A_CIS_14, ETPU_A_CIS_15, ETPU_A_CIS_16, ETPU_A_CIS_17, ETPU_A_CIS_18, ETPU_A_CIS_19, ETPU_A_CIS_20, ETPU_A_CIS_21, ETPU_A_CIS_22, // 54-90 ETPU_A_CIS_23, ETPU_A_CIS_24, ETPU_A_CIS_25, ETPU_A_CIS_26, ETPU_A_CIS_27, ETPU_A_CIS_28, ETPU_A_CIS_29, ETPU_A_CIS_30, ETPU_A_CIS_31, // 99 #endif /* eQADC */ EQADC_FISR_OVER, // 54-100, 16-82 EQADC_FISR0_NCF0, EQADC_FISR0_PF0, EQADC_FISR0_EOQF0, EQADC_FISR0_CFFF0, EQADC_FISR0_RFDF0, EQADC_FISR1_NCF1, EQADC_FISR1_PF1, EQADC_FISR1_EOQF1, EQADC_FISR1_CFFF1, EQADC_FISR1_RFDF1, // 110, 92 EQADC_FISR2_NCF2, EQADC_FISR2_PF2, EQADC_FISR2_EOQF2, EQADC_FISR2_CFFF2, EQADC_FISR2_RFDF2, EQADC_FISR3_NCF3, EQADC_FISR3_PF3, EQADC_FISR3_EOQF3, EQADC_FISR3_CFFF3, EQADC_FISR3_RFDF3, // 120, 102 EQADC_FISR4_NCF4, EQADC_FISR4_PF4, EQADC_FISR4_EOQF4, EQADC_FISR4_CFFF4, EQADC_FISR4_RFDF4, EQADC_FISR5_NCF5, EQADC_FISR5_PF5, EQADC_FISR5_EOQF5, EQADC_FISR5_CFFF5, EQADC_FISR5_RFDF5, // 130, 112 #if defined(CFG_MPC5516) /* SCI */ SCI_A_COMB, // 16-113 SCI_B_COMB, SCI_C_COMB, SCI_D_COMB, /* DSPI A,B */ DSPI_A_ISR_OVER, DSPI_A_ISR_EOQF, DSPI_A_ISR_TFFF, DSPI_A_ISR_TCF, DSPI_A_ISR_RFDF, DSPI_B_ISR_OVER, // 16-122 DSPI_B_ISR_EOQF, DSPI_B_ISR_TFFF, DSPI_B_ISR_TCF, DSPI_B_ISR_RFDF, #elif defined(CFG_MPC5554)||defined(CFG_MPC5567) DSPI_B_COMB, // 54-131 DSPI_B_ISR_EOQF, DSPI_B_ISR_TFFF, DSPI_B_ISR_TCF, DSPI_B_ISR_RFDF, // 54-135 DSPI_C_COMB, DSPI_C_ISR_EOQF, DSPI_C_ISR_TFFF, DSPI_C_ISR_TCF, DSPI_C_ISR_RFDF, // 54-140 DSPI_D_COMB, DSPI_D_ISR_EOQF, DSPI_D_ISR_TFFF, DSPI_D_ISR_TCF, DSPI_D_ISR_RFDF, // 54-145 ESCI_A_COMB0, RESERVED0, RESERVED1, ESCI_A_COMB1, RESERVED2, RESERVED3, // 54-151 #endif /* FlexCAN A */ #if defined(CFG_MPC5516) || defined(CFG_MPC5554)||defined(CFG_MPC5567) FLEXCAN_A_ESR_BOFF_INT, // 54-152, 16-127 FLEXCAN_A_ESR_ERR_INT, RESERVED18, FLEXCAN_A_IFLAG1_BUF0I, FLEXCAN_A_IFLAG1_BUF1I, FLEXCAN_A_IFLAG1_BUF2I, FLEXCAN_A_IFLAG1_BUF3I, FLEXCAN_A_IFLAG1_BUF4I, FLEXCAN_A_IFLAG1_BUF5I, FLEXCAN_A_IFLAG1_BUF6I, FLEXCAN_A_IFLAG1_BUF7I, FLEXCAN_A_IFLAG1_BUF8I, FLEXCAN_A_IFLAG1_BUF9I, FLEXCAN_A_IFLAG1_BUF10I, FLEXCAN_A_IFLAG1_BUF11I, FLEXCAN_A_IFLAG1_BUF12I, FLEXCAN_A_IFLAG1_BUF13I, FLEXCAN_A_IFLAG1_BUF14I, FLEXCAN_A_IFLAG1_BUF15I, FLEXCAN_A_IFLAG1_BUF31_16I, FLEXCAN_A_IFLAG1_BUF63_32I, #endif #if defined(CFG_MPC5516) /* Periodic interrupt timer */ PIT_PITFLG_RTIF, PIT_PITFLG_PIT1, PIT_PITFLG_PIT2, PIT_PITFLG_PIT3, PIT_PITFLG_PIT4, PIT_PITFLG_PIT5, PIT_PITFLG_PIT6, PIT_PITFLG_PIT7, PIT_PITFLG_PIT8, /* FlexCAN B */ FLEXCAN_B_ESR_BOFF_INT, FLEXCAN_B_ESR_ERR_INT, RESERVED19, FLEXCAN_B_IFLAG1_BUF0I, FLEXCAN_B_IFLAG1_BUF1I, FLEXCAN_B_IFLAG1_BUF2I, FLEXCAN_B_IFLAG1_BUF3I, FLEXCAN_B_IFLAG1_BUF4I, FLEXCAN_B_IFLAG1_BUF5I, FLEXCAN_B_IFLAG1_BUF6I, FLEXCAN_B_IFLAG1_BUF7I, FLEXCAN_B_IFLAG1_BUF8I, FLEXCAN_B_IFLAG1_BUF9I, FLEXCAN_B_IFLAG1_BUF10I, FLEXCAN_B_IFLAG1_BUF11I, FLEXCAN_B_IFLAG1_BUF12I, FLEXCAN_B_IFLAG1_BUF13I, FLEXCAN_B_IFLAG1_BUF14I, FLEXCAN_B_IFLAG1_BUF15I, FLEXCAN_B_IFLAG1_BUF31_16I, FLEXCAN_B_IFLAG1_BUF63_32I, /* FlexCAN C */ FLEXCAN_C_ESR_BOFF_INT, FLEXCAN_C_ESR_ERR_INT, RESERVED20, FLEXCAN_C_IFLAG1_BUF0I, FLEXCAN_C_IFLAG1_BUF1I, FLEXCAN_C_IFLAG1_BUF2I, FLEXCAN_C_IFLAG1_BUF3I, FLEXCAN_C_IFLAG1_BUF4I, FLEXCAN_C_IFLAG1_BUF5I, FLEXCAN_C_IFLAG1_BUF6I, FLEXCAN_C_IFLAG1_BUF7I, FLEXCAN_C_IFLAG1_BUF8I, FLEXCAN_C_IFLAG1_BUF9I, FLEXCAN_C_IFLAG1_BUF10I, FLEXCAN_C_IFLAG1_BUF11I, FLEXCAN_C_IFLAG1_BUF12I, FLEXCAN_C_IFLAG1_BUF13I, FLEXCAN_C_IFLAG1_BUF14I, FLEXCAN_C_IFLAG1_BUF15I, FLEXCAN_C_IFLAG1_BUF31_16I, FLEXCAN_C_IFLAG1_BUF63_32I, /* FlexCAN D */ FLEXCAN_D_ESR_BOFF_INT, FLEXCAN_D_ESR_ERR_INT, RESERVED21, FLEXCAN_D_IFLAG1_BUF0I, FLEXCAN_D_IFLAG1_BUF1I, FLEXCAN_D_IFLAG1_BUF2I, FLEXCAN_D_IFLAG1_BUF3I, FLEXCAN_D_IFLAG1_BUF4I, FLEXCAN_D_IFLAG1_BUF5I, FLEXCAN_D_IFLAG1_BUF6I, FLEXCAN_D_IFLAG1_BUF7I, FLEXCAN_D_IFLAG1_BUF8I, FLEXCAN_D_IFLAG1_BUF9I, FLEXCAN_D_IFLAG1_BUF10I, FLEXCAN_D_IFLAG1_BUF11I, FLEXCAN_D_IFLAG1_BUF12I, FLEXCAN_D_IFLAG1_BUF13I, FLEXCAN_D_IFLAG1_BUF14I, FLEXCAN_D_IFLAG1_BUF15I, FLEXCAN_D_IFLAG1_BUF31_16I, FLEXCAN_D_IFLAG1_BUF63_32I, /* FlexCAN E */ FLEXCAN_E_ESR_BOFF_INT, FLEXCAN_E_ESR_ERR_INT, RESERVED22, FLEXCAN_E_IFLAG1_BUF0I, FLEXCAN_E_IFLAG1_BUF1I, FLEXCAN_E_IFLAG1_BUF2I, FLEXCAN_E_IFLAG1_BUF3I, FLEXCAN_E_IFLAG1_BUF4I, FLEXCAN_E_IFLAG1_BUF5I, FLEXCAN_E_IFLAG1_BUF6I, FLEXCAN_E_IFLAG1_BUF7I, FLEXCAN_E_IFLAG1_BUF8I, FLEXCAN_E_IFLAG1_BUF9I, FLEXCAN_E_IFLAG1_BUF10I, FLEXCAN_E_IFLAG1_BUF11I, FLEXCAN_E_IFLAG1_BUF12I, FLEXCAN_E_IFLAG1_BUF13I, FLEXCAN_E_IFLAG1_BUF14I, FLEXCAN_E_IFLAG1_BUF15I, FLEXCAN_E_IFLAG1_BUF31_16I, FLEXCAN_E_IFLAG1_BUF63_32I, /* FlexCAN F */ FLEXCAN_F_ESR_BOFF_INT, FLEXCAN_F_ESR_ERR_INT, RESERVED23, FLEXCAN_F_IFLAG1_BUF0I, FLEXCAN_F_IFLAG1_BUF1I, FLEXCAN_F_IFLAG1_BUF2I, FLEXCAN_F_IFLAG1_BUF3I, FLEXCAN_F_IFLAG1_BUF4I, FLEXCAN_F_IFLAG1_BUF5I, FLEXCAN_F_IFLAG1_BUF6I, FLEXCAN_F_IFLAG1_BUF7I, FLEXCAN_F_IFLAG1_BUF8I, FLEXCAN_F_IFLAG1_BUF9I, FLEXCAN_F_IFLAG1_BUF10I, FLEXCAN_F_IFLAG1_BUF11I, FLEXCAN_F_IFLAG1_BUF12I, FLEXCAN_F_IFLAG1_BUF13I, FLEXCAN_F_IFLAG1_BUF14I, FLEXCAN_F_IFLAG1_BUF15I, FLEXCAN_F_IFLAG1_BUF31_16I, FLEXCAN_F_IFLAG1_BUF63_32I, RESERVED24, RESERVED25, RESERVED26, RESERVED27, RESERVED28, RESERVED29, RESERVED30, RESERVED31, /* SCI */ SCI_E_COMB, SCI_F_COMB, SCI_G_COMB, SCI_H_COMB, /* DSPI */ DSPI_C_ISR_OVER, DSPI_C_ISR_EOQF, DSPI_C_ISR_TFFF, DSPI_C_ISR_TCF, DSPI_C_ISR_RFDF, DSPI_D_ISR_OVER, DSPI_D_ISR_EOQF, DSPI_D_ISR_TFFF, DSPI_D_ISR_TCF, DSPI_D_ISR_RFDF, /* Flexray */ FLEXRAY_GLOB, FLEXRAY_PRIF, FLEXRAY_CHIF, FLEXRAY_WUP_IF, FLEXRAY_FBNE_F, FLEXRAY_FANE_F, FLEXRAY_RBIF, FLEXRAY_TBIF, RESERVED32, MLB_SERVICE_REQUEST, INTC_NUMBER_OF_INTERRUPTS, /* End of INTC interrupts. The vectors below are used to handle exceptions. */ RESERVED_SPACE_BEFORE_EXCEPTIONS1, RESERVED_SPACE_BEFORE_EXCEPTIONS2, RESERVED_SPACE_BEFORE_EXCEPTIONS3, RESERVED_SPACE_BEFORE_EXCEPTIONS4, RESERVED_SPACE_BEFORE_EXCEPTIONS5, RESERVED_SPACE_BEFORE_EXCEPTIONS6, RESERVED_SPACE_BEFORE_EXCEPTIONS7, RESERVED_SPACE_BEFORE_EXCEPTIONS8, RESERVED_SPACE_BEFORE_EXCEPTIONS9, RESERVED_SPACE_BEFORE_EXCEPTIONS10, RESERVED_SPACE_BEFORE_EXCEPTIONS11, RESERVED_SPACE_BEFORE_EXCEPTIONS12, RESERVED_SPACE_BEFORE_EXCEPTIONS13, RESERVED_SPACE_BEFORE_EXCEPTIONS14, RESERVED_SPACE_BEFORE_EXCEPTIONS15, RESERVED_SPACE_BEFORE_EXCEPTIONS16, RESERVED_SPACE_BEFORE_EXCEPTIONS17, RESERVED_SPACE_BEFORE_EXCEPTIONS18, RESERVED_SPACE_BEFORE_EXCEPTIONS19, RESERVED_SPACE_BEFORE_EXCEPTIONS20, RESERVED_SPACE_BEFORE_EXCEPTIONS21, RESERVED_SPACE_BEFORE_EXCEPTIONS22, RESERVED_SPACE_BEFORE_EXCEPTIONS23, RESERVED_SPACE_BEFORE_EXCEPTIONS24, RESERVED_SPACE_BEFORE_EXCEPTIONS25, #endif #if defined(CFG_MPC5554)||defined(CFG_MPC5567) /* FlexCAN C */ FLEXCAN_C_ESR_BOFF_INT = 173, FLEXCAN_C_ESR_ERR_INT, RESERVED20, FLEXCAN_C_IFLAG1_BUF0I, FLEXCAN_C_IFLAG1_BUF1I, FLEXCAN_C_IFLAG1_BUF2I, FLEXCAN_C_IFLAG1_BUF3I, FLEXCAN_C_IFLAG1_BUF4I, FLEXCAN_C_IFLAG1_BUF5I, FLEXCAN_C_IFLAG1_BUF6I, FLEXCAN_C_IFLAG1_BUF7I, FLEXCAN_C_IFLAG1_BUF8I, FLEXCAN_C_IFLAG1_BUF9I, FLEXCAN_C_IFLAG1_BUF10I, FLEXCAN_C_IFLAG1_BUF11I, FLEXCAN_C_IFLAG1_BUF12I, FLEXCAN_C_IFLAG1_BUF13I, FLEXCAN_C_IFLAG1_BUF14I, FLEXCAN_C_IFLAG1_BUF15I, FLEXCAN_C_IFLAG1_BUF31_16I, FLEXCAN_C_IFLAG1_BUF63_32I, // .... // 275 DSPI_A_COMB = 275, // 54-131 DSPI_A_ISR_EOQF, DSPI_A_ISR_TFFF, DSPI_A_ISR_TCF, DSPI_A_ISR_RFDF, // 54-135 /* FlexCAN B */ FLEXCAN_B_ESR_BOFF_INT = 280, FLEXCAN_B_ESR_ERR_INT, RESERVED21, FLEXCAN_B_IFLAG1_BUF0I, FLEXCAN_B_IFLAG1_BUF1I, FLEXCAN_B_IFLAG1_BUF2I, FLEXCAN_B_IFLAG1_BUF3I, FLEXCAN_B_IFLAG1_BUF4I, FLEXCAN_B_IFLAG1_BUF5I, FLEXCAN_B_IFLAG1_BUF6I, FLEXCAN_B_IFLAG1_BUF7I, FLEXCAN_B_IFLAG1_BUF8I, FLEXCAN_B_IFLAG1_BUF9I, FLEXCAN_B_IFLAG1_BUF10I, FLEXCAN_B_IFLAG1_BUF11I, FLEXCAN_B_IFLAG1_BUF12I, FLEXCAN_B_IFLAG1_BUF13I, FLEXCAN_B_IFLAG1_BUF14I, FLEXCAN_B_IFLAG1_BUF15I, FLEXCAN_B_IFLAG1_BUF31_16I, FLEXCAN_B_IFLAG1_BUF63_32I, /* FlexCAN D */ FLEXCAN_D_ESR_BOFF_INT = 308, FLEXCAN_D_ESR_ERR_INT, RESERVED22, FLEXCAN_D_IFLAG1_BUF0I, FLEXCAN_D_IFLAG1_BUF1I, FLEXCAN_D_IFLAG1_BUF2I, FLEXCAN_D_IFLAG1_BUF3I, FLEXCAN_D_IFLAG1_BUF4I, FLEXCAN_D_IFLAG1_BUF5I, FLEXCAN_D_IFLAG1_BUF6I, FLEXCAN_D_IFLAG1_BUF7I, FLEXCAN_D_IFLAG1_BUF8I, FLEXCAN_D_IFLAG1_BUF9I, FLEXCAN_D_IFLAG1_BUF10I, FLEXCAN_D_IFLAG1_BUF11I, FLEXCAN_D_IFLAG1_BUF12I, FLEXCAN_D_IFLAG1_BUF13I, FLEXCAN_D_IFLAG1_BUF14I, FLEXCAN_D_IFLAG1_BUF15I, FLEXCAN_D_IFLAG1_BUF31_16I, FLEXCAN_D_IFLAG1_BUF63_32I, /* FlexCAN E */ FLEXCAN_E_ESR_BOFF_INT = 329, FLEXCAN_E_ESR_ERR_INT, RESERVED23, FLEXCAN_E_IFLAG1_BUF0I, FLEXCAN_E_IFLAG1_BUF1I, FLEXCAN_E_IFLAG1_BUF2I, FLEXCAN_E_IFLAG1_BUF3I, FLEXCAN_E_IFLAG1_BUF4I, FLEXCAN_E_IFLAG1_BUF5I, FLEXCAN_E_IFLAG1_BUF6I, FLEXCAN_E_IFLAG1_BUF7I, FLEXCAN_E_IFLAG1_BUF8I, FLEXCAN_E_IFLAG1_BUF9I, FLEXCAN_E_IFLAG1_BUF10I, FLEXCAN_E_IFLAG1_BUF11I, FLEXCAN_E_IFLAG1_BUF12I, FLEXCAN_E_IFLAG1_BUF13I, FLEXCAN_E_IFLAG1_BUF14I, FLEXCAN_E_IFLAG1_BUF15I, FLEXCAN_E_IFLAG1_BUF31_16I, FLEXCAN_E_IFLAG1_BUF63_32I, INTC_NUMBER_OF_INTERRUPTS, DUMMY_DUMMY = 319, #endif /* defined(CFG_MPC5554)||defined(CFG_MPC5567) */ #endif CRITICAL_INPUT_EXCEPTION, MACHINE_CHECK_EXCEPTION, DATA_STORAGE_EXCEPTION, INSTRUCTION_STORAGE_EXCEPTION, EXTERNAL_INTERRUPT, /* This is the place where the "normal" interrupts will hit the CPU... */ ALIGNMENT_EXCEPTION, PROGRAM_EXCEPTION, FLOATING_POINT_EXCEPTION, SYSTEM_CALL_EXCEPTION, AUX_EXCEPTION, DECREMENTER_EXCEPTION, FIXED_INTERVAL_TIMER_EXCEPTION, WATCHDOG_TIMER_EXCEPTION, DATA_TLB_EXCEPTION, INSTRUCTION_TLB_EXCEPTION, DEBUG_EXCEPTION, NUMBER_OF_INTERRUPTS_AND_EXCEPTIONS }IrqType; typedef enum { PERIPHERAL_CLOCK_FLEXCAN_A, PERIPHERAL_CLOCK_FLEXCAN_B, PERIPHERAL_CLOCK_FLEXCAN_C, PERIPHERAL_CLOCK_FLEXCAN_D, PERIPHERAL_CLOCK_FLEXCAN_E, PERIPHERAL_CLOCK_FLEXCAN_F, PERIPHERAL_CLOCK_PIT, PERIPHERAL_CLOCK_DSPI_A, PERIPHERAL_CLOCK_DSPI_B, PERIPHERAL_CLOCK_DSPI_C, PERIPHERAL_CLOCK_DSPI_D, #if defined(CFG_MPC560X) PERIPHERAL_CLOCK_EMIOS_0, PERIPHERAL_CLOCK_EMIOS_1, #else PERIPHERAL_CLOCK_EMIOS, #endif PERIPHERAL_CLOCK_ESCI_A, PERIPHERAL_CLOCK_ESCI_B, PERIPHERAL_CLOCK_ESCI_C, PERIPHERAL_CLOCK_ESCI_D, PERIPHERAL_CLOCK_ESCI_E, PERIPHERAL_CLOCK_ESCI_F, PERIPHERAL_CLOCK_ESCI_G, PERIPHERAL_CLOCK_ESCI_H, #if defined(CFG_MPC560X) PERIPHERAL_CLOCK_LIN_A, PERIPHERAL_CLOCK_LIN_B, PERIPHERAL_CLOCK_LIN_C, PERIPHERAL_CLOCK_LIN_D, #endif PERIPHERAL_CLOCK_IIC_A, PERIPHERAL_CLOCK_MLB } Mcu_Arc_PeriperalClock_t; #if defined(CFG_MPC5516) || defined(CFG_MPC5606X) #define CPU_Z1 0 #define CPU_Z0 1 #endif typedef enum { CPU_CORE0, CPU_CORE1 } Cpu_t; /* Offset from exceptions to interrupts */ #define IRQ_INTERRUPT_OFFSET 0 #endif /* IRQ_H_ */
2301_81045437/classic-platform
system/Os/osal/gnulinux/gnulinux/kernel/irq_types.h
C
unknown
28,118
/*-------------------------------- 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 "Std_Types.h" void Os_SysTickInit( void ) { } void Os_SysTickStart(uint32_t period_ticks) { }
2301_81045437/classic-platform
system/Os/osal/gnulinux/gnulinux/kernel/sys_tick.c
C
unknown
862
cflags-$(OS_32BIT)+= -m32 LDFLAGS-$(OS_32BIT)+= -m32 # Nvidia recommended compiler flags for Linux userspace ifneq ($(CROSS_COMPILE),) # DEBUG cflags-y += -march=armv8-a -Wcast-align # RELEASE # -O2 -fomit-frame-pointer -finline-functions -finline-limit=300 fgcse-after-reload endif # Code coverage #cflags-y += -fprofile-arcs -ftest-coverage #LDFLAGS += -lgcov --coverage # ifneq ($(OS),Windows_NT) LDFLAGS += -pthread endif inc-y += $(ROOTDIR)/system/Os/include # SimonG or $(ROOTDIR)/boards/linux/Os.h
2301_81045437/classic-platform
system/Os/osal/gnulinux/gnulinux/scripts/gcc.mk
Makefile
unknown
540
/*-------------------------------- 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_BSW_00020 The header file structure shall contain one or more files * that provide the declaration of functions from the BSW Module API */ #ifndef OS_H_ #define OS_H_ #define OS_AR_RELEASE_MAJOR_VERSION 4u #define OS_AR_RELEASE_MINOR_VERSION 0u #define OS_AR_RELEASE_REVISION_VERSION 3u /* @req SWS_BSW_00059 Published information */ #define OS_SW_MAJOR_VERSION 1u #define OS_SW_MINOR_VERSION 0u #define OS_SW_PATCH_VERSION 1u /* @req SWS_BSW_00024 Include AUTOSAR Standard Types Header in implementation header */ #include "Std_Types.h" #include "arc_assert.h" #if defined(CFG_OS_TEST) #include "os_test.h" #endif #include "Os_Cfg.h" #include "MemMap.h" #include "Cpu.h" #include "limits.h" #include <sys/queue.h> #include "Rte_Os_Type.h" typedef uint8 StatusType; #if (OS_ISR_CNT > OS_ISR_MAX_CNT) #error OS configuration error. OS_ISR_MAX_CNT must be bigger or equal to OS_ISR_CNT #endif #define E_OS_ACCESS (StatusType)1 /**< STD OSEK */ #define E_OS_CALLEVEL (StatusType)2 /**< STD OSEK */ #define E_OS_ID (StatusType)3 /**< STD OSEK */ #define E_OS_LIMIT (StatusType)4 /**< STD OSEK */ #define E_OS_NOFUNC (StatusType)5 /**< STD OSEK */ #define E_OS_RESOURCE (StatusType)6 /**< STD OSEK */ #define E_OS_STATE (StatusType)7 /**< STD OSEK */ #define E_OS_VALUE (StatusType)8 /**< STD OSEK */ #define E_OS_SERVICEID (StatusType)9 /**< AUTOSAR, see 7.10 */ #define E_OS_RATE (StatusType)10 /**< AUTOSAR, see 7.10 */ #define E_OS_ILLEGAL_ADDRESS (StatusType)11 /**< AUTOSAR, see 7.10 */ #define E_OS_MISSINGEND (StatusType)12 /**< AUTOSAR, see 7.10 */ #define E_OS_DISABLEDINT (StatusType)13 /**< AUTOSAR, see 7.10 */ #define E_OS_STACKFAULT (StatusType)14 /**< AUTOSAR, see 7.10 */ #define E_OS_PROTECTION_MEMORY (StatusType)15 /**< AUTOSAR, see 7.10 */ #define E_OS_PROTECTION_TIME (StatusType)16 /**< AUTOSAR, see 7.10 */ #define E_OS_PROTECTION_LOCKED (StatusType)17 /**< AUTOSAR, see 7.10 */ #define E_OS_PROTECTION_EXCEPTION (StatusType)18 /**< AUTOSAR, see 7.10 */ #define E_OS_PROTECTION_RATE (StatusType)19 /**< AUTOSAR, see 7.10 */ #define E_OS_CORE (StatusType)20 /**< AUTOSAR 4.0.3, see 7.13 */ #define E_OS_SPINLOCK (StatusType)21 /**< AUTOSAR 4.0.3, see 7.13 */ #define E_OS_INTERFERENCE_DEADLOCK (StatusType)22 /**< AUTOSAR 4.0.3, see 7.13 */ #define E_OS_NESTING_DEADLOCK (StatusType)23 /**< AUTOSAR 4.0.3, see 7.13 */ #define E_OS_PARAM_POINTER (StatusType)24 /**< AUTOSAR 4.3.0, see 7.1.2.3 */ #define E_OS_EXIT_ABORT (StatusType)30 /* ArcCore */ #define E_OS_PANIC (StatusType)31 /* ArcCore */ #define E_OS_RTE (StatusType)32 /* ArcCore */ #define E_OS_TRUSTED_INDEX (StatusType)33 /* ArcCore, index out of bounds */ #define E_OS_TRUSTED_FUNC (StatusType)34 /* ArcCore, called function is NULL */ #define E_OS_BAD_CONTEXT (StatusType)35 /* ArcCore, called function is NULL */ #define E_OS_TIMEOUT (StatusType)36 /* ArcCore, Semaphore have timeout */ #define E_OS_ASSERT (StatusType)37 /* ArcCore, call to ASSERT() or CONFIG_ASSERT() */ #define E_OS_ISR_RESOURCE (StatusType)38 /* ArcCore, ISR does not support Get/ReleaseResource() */ #define E_OS_FULL (StatusType)39 /* ArcCore, mbox full */ #define E_OS_ILLEGAL (StatusType)255 /* ArcCore*/ #define E_COM_ID 255 // NOTE: The value of E_COM_ID is not known" #if (OS_SC3 == STD_ON) || (OS_SC4 == STD_ON) /* 32bit: Keeping Load/Store and register manipulation simple * during SysCalls when EventMaskType as fun argument */ typedef uint32 EventMaskType; #else typedef uint64 EventMaskType; #endif typedef EventMaskType * EventMaskRefType; typedef uint16 TaskType; typedef TaskType * TaskRefType; typedef uint16 AreaIdType; typedef enum { TASK_STATE_WAITING, TASK_STATE_READY, TASK_STATE_SUSPENDED, TASK_STATE_RUNNING, TASK_STATE_WAITING_SEM } TaskStateType; #define INVALID_TASK 0xdeadU typedef TaskStateType *TaskStateRefType; #define OSMEMORY_IS_READABLE(_access) #define OSMEMORY_IS_WRITEABLE(_access) #define OSMEMORY_IS_EXECUTABLE(_access) #define OSMEMORY_IS_STACKSPACE(_access) #define OSDEFAULTAPPMODE 1 #define INVALID_OSAPPLICATION (0xFFFFFFFFUL) #define TASK(_task) void _task( void ) //lint -esym(123,ISR) Inhibit lint warning for ISR being defined elsewhere without being an error #define ISR(_isr) void _isr( void ) #if (OS_USE_APPLICATIONS == STD_ON) /* @req SWS_Os_00772 Type definition */ typedef uint32 ApplicationType; /* @req SWS_Os_00773 Type definition */ typedef enum { APPLICATION_ACCESSIBLE, APPLICATION_RESTARTING, APPLICATION_TERMINATED } ApplicationStateType; /* @req SWS_Os_00774 Type definition */ typedef ApplicationStateType *ApplicationStateRefType; #endif /* See oil config for defines */ typedef uint32 AppModeType; /* @req SWS_Os_91007 Type definition */ typedef uint16 ScheduleTableType; /* @req SWS_Os_00783 Type definition */ typedef uint16 GlobalTimeTickType; /* @req SWS_Os_00784 Type definition */ typedef enum { SCHEDULETABLE_STOPPED, SCHEDULETABLE_NEXT, SCHEDULETABLE_WAITING, SCHEDULETABLE_RUNNING, SCHEDULETABLE_RUNNING_AND_SYNCHRONOUS } ScheduleTableStatusType; /* @req SWS_Os_00785 Type definition */ typedef ScheduleTableStatusType *ScheduleTableStatusRefType; /* Flags for AccessType */ #define ACCESSTYPE_W 1 #define ACCESSTYPE_R (1<<1) /* @req SWS_Os_00777 Type definition */ typedef uint32 AccessType; /* @req SWS_Os_00778 Type definition */ typedef enum { ACCESS, NO_ACCESS } ObjectAccessType; /* @req SWS_Os_00779 Type definition */ typedef enum { OBJECT_TASK, OBJECT_ISR, OBJECT_ALARM, OBJECT_RESOURCE, OBJECT_COUNTER, OBJECT_SCHEDULETABLE, OBJECT_MESSAGE } ObjectTypeType; /* @req SWS_Os_00787 Type definition */ typedef enum { PRO_IGNORE, PRO_KILLTASKISR, PRO_KILLAPPL, PRO_KILLAPPL_RESTART, PRO_SHUTDOWN } ProtectionReturnType; /* @req SWS_Os_00788 Type definition */ typedef uint8 RestartType; #define RESTART 0 #define NO_RESTART 1 #if (OS_SC2 == STD_ON) || (OS_SC3 == STD_ON) || (OS_SC4 == STD_ON) /** @req SWS_Os_00542 */ /* ProtectionHook( ) available in Scalability Classes 2, 3 and 4. */ /** @req SWS_Os_00538 */ ProtectionReturnType ProtectionHook( StatusType FatalError ); #endif void StartupHook( void ); void ShutdownHook( StatusType Error ); void ErrorHook( StatusType Error ); void PreTaskHook( void ); void PostTaskHook( void ); /* @req SWS_Os_00775 Type definition */ typedef uint16 TrustedFunctionIndexType; /* @req SWS_Os_00776 Type definition */ typedef void * TrustedFunctionParameterRefType; /* See 8.3.9 */ #define INVALID_ISR ((sint16)(-1)) /* @req SWS_Os_00782 Type definition */ typedef sint16 ISRType; #define APP_NO_OWNER (-1UL) /* @req SWS_Os_00780 Type definition */ typedef void * MemoryStartAddressType; /* @req SWS_Os_00781 Type definition */ typedef uint32 MemorySizeType; #include "os_peripheral_i.h" StatusType WaitEvent( EventMaskType Mask ); StatusType SetEvent( TaskType TaskID, EventMaskType Mask ); StatusType ClearEvent( EventMaskType Mask); StatusType GetEvent( TaskType TaskId, EventMaskRefType Mask); void InitOS( void ); void StartOS( AppModeType Mode ); ISRType GetISRID( void ); #if !defined(CFG_SAFETY_PLATFORM) StatusType GetActiveApplicationMode( AppModeType* mode); #endif //CFG_SAFETY_PLATFORM typedef sint8 Os_IntCounterType; /* requirements here: OS368(ISR2), OS092 */ extern Os_IntCounterType Os_IntDisableAllCnt; extern Os_IntCounterType Os_IntSuspendAllCnt; /*lint -esym(9003,Os_Arc_OsTickCounter) MISRA:OTHER:variable defined in generated code so it cannot be defined in block scope:[MISRA 2012 Rule 8.9, advisory]*/ extern CounterType Os_Arc_OsTickCounter; /** @req SWS_Os_00299 */ /* OSEK: States that " service does not support nesting", but says * nothing what to do about it. * * OS092: " If EnableAllInterrupts()/ResumeAllInterrupts()/ResumeOSInterrupts() * are called and no corresponding DisableAllInterupts()/SuspendAllInterrupts()/ * SuspendOSInterrupts() was done before, the Operating System shall not */ /* @req OSEK_SWS_ISR_00002 */ static inline void DisableAllInterrupts( void ) { Irq_Disable(); #if defined(CFG_JAC6_IPC) /* We have to allow disabling interrupts several times from the IPC library */ Os_IntDisableAllCnt=1; #else /* No nesting allowed */ Os_IntDisableAllCnt++; ASSERT(Os_IntDisableAllCnt==1); #endif } /* @req OSEK_SWS_ISR_00001 */ static inline void EnableAllInterrupts( void ) { if(Os_IntDisableAllCnt==0) { /** @req SWS_Os_00092 EnableAllInterrupts */ } else { Os_IntDisableAllCnt--; #if defined(CFG_JAC6_IPC) Os_IntDisableAllCnt=0; __asm volatile ("CPSIE if"); #else Irq_Enable(); #endif } } /* @req OSEK_SWS_ISR_00004 */ static inline void SuspendAllInterrupts( void ) { Irq_SuspendAll(); Os_IntSuspendAllCnt++; } /* @req OSEK_SWS_ISR_00003 */ static inline void ResumeAllInterrupts( void ) { if(Os_IntSuspendAllCnt==0) { /** @req SWS_Os_00092 ResumeAllInterrupts */ } else { Os_IntSuspendAllCnt--; if( Os_IntSuspendAllCnt == 0 ) { Irq_ResumeAll(); } } } /* Only ISR2 interrupts should be suspended but this can NEVER be * done in a more efficient way than to disable all, so let's * do that for all targets. */ /* @req OSEK_SWS_ISR_00006 */ static inline void SuspendOSInterrupts( void ) { Irq_SuspendOs(); Os_IntSuspendAllCnt++; } /* @req OSEK_SWS_ISR_00005 */ static inline void ResumeOSInterrupts( void ) { if(Os_IntSuspendAllCnt==0) { /** @req SWS_Os_00092 ResumeOSInterrupts */ } else { Os_IntSuspendAllCnt--; if(Os_IntSuspendAllCnt==0) { Irq_ResumeOs(); } } } /* * Class 2,3 and 4 API */ #if (OS_SC1 == STD_ON) || (OS_SC2 == STD_ON) #define SYS_CALL_EnterSupervisorMode() #define SYS_CALL_ResumeAllInterrupts() ResumeAllInterrupts() #define SYS_CALL_SuspendAllInterrupts() SuspendAllInterrupts() #define SYS_CALL_EnableAllInterrupts() EnableAllInterrupts() #define SYS_CALL_DisableAllInterrupts() DisableAllInterrupts() #define SYS_CALL_ResumeOSInterrupts() ResumeOSInterrupts() #define SYS_CALL_SuspendOSInterrupts() SuspendOSInterrupts() #define SYS_CALL_ActivateTask ActivateTask #define SYS_CALL_TerminateTask TerminateTask #define SYS_CALL_ChainTask ChainTask #define SYS_CALL_Schedule Schedule #define SYS_CALL_GetTaskID GetTaskID #define SYS_CALL_GetResource GetResource #define SYS_CALL_ReleaseResource ReleaseResource #define SYS_CALL_SetEvent SetEvent #define SYS_CALL_ClearEvent ClearEvent #define SYS_CALL_GetEvent GetEvent #define SYS_CALL_WaitEvent WaitEvent #define SYS_CALL_GetAlarmBase GetAlarmBase #define SYS_CALL_GetAlarm GetAlarm #define SYS_CALL_SetRelAlarm SetRelAlarm #define SYS_CALL_SetAbsAlarm SetAbsAlarm #define SYS_CALL_CancelAlarm CancelAlarm #define SYS_CALL_ShutdownOS ShutdownOS #define SYS_CALL_GetTaskState GetTaskState #define SYS_CALL_GetISRID GetISRID #define SYS_CALL_CheckISRMemoryAccess CheckISRMemoryAccess #define SYS_CALL_CheckTaskMemoryAccess CheckTaskMemoryAccess #define SYS_CALL_CheckObjectOwnership CheckObjectOwnership #define SYS_CALL_StartScheduleTableRel StartScheduleTableRel #define SYS_CALL_StartScheduleTableAbs StartScheduleTableAbs #define SYS_CALL_StopScheduleTable StopScheduleTable #define SYS_CALL_NextScheduleTable NextScheduleTable #define SYS_CALL_GetScheduleTableStatus GetScheduleTableStatus #define SYS_CALL_IncrementCounter IncrementCounter #define SYS_CALL_GetCounterValue GetCounterValue #define SYS_CALL_GetElapsedValue GetElapsedValue StatusType Os_ReadPeripheral8( AreaIdType Area, const uint8 * Address, uint8 * ReadValue); StatusType Os_ReadPeripheral16( AreaIdType Area, const uint16 * Address, uint16 * ReadValue); StatusType Os_ReadPeripheral32( AreaIdType Area, const uint32 * Address, uint32 * ReadValue); StatusType Os_WritePeripheral8 ( AreaIdType Area, uint8 *Address, uint8 WriteValue); StatusType Os_WritePeripheral16( AreaIdType Area, uint16 *Address, uint16 WriteValue); StatusType Os_WritePeripheral32( AreaIdType Area, uint32 *Address, uint32 WriteValue); StatusType Os_ModifyPeripheral8( AreaIdType Area, uint8 *Address, uint8 ClearMask, uint8 SetMask); StatusType Os_ModifyPeripheral16( AreaIdType Area, uint16 *Address, uint16 ClearMask, uint16 SetMask); StatusType Os_ModifyPeripheral32( AreaIdType Area, uint32 *Address, uint32 ClearMask, uint32 SetMask); #define ReadPeripheral8(_a1,_a2,_a3) Os_ReadPeripheral8( _a1, _a2, _a3 ) #define ReadPeripheral16(_a1,_a2,_a3) Os_ReadPeripheral16(_a1, _a2, _a3 ) #define ReadPeripheral32(_a1,_a2,_a3) Os_ReadPeripheral32( _a1, _a2, _a3 ) #define WritePeripheral8(_a1,_a2,_a3) Os_WritePeripheral8( _a1, _a2, _a3 ) #define WritePeripheral16(_a1,_a2,_a3) Os_WritePeripheral16(_a1, _a2, _a3 ) #define WritePeripheral32(_a1,_a2,_a3) Os_WritePeripheral32( _a1, _a2, _a3 ) #define ModifyPeripheral8(_a1,_a2,_a3,_a4) Os_ModifyPeripheral8( _a1, _a2, _a3, _a4 ) #define ModifyPeripheral16(_a1,_a2,_a3,_a4) Os_ModifyPeripheral16(_a1, _a2, _a3, _a4 ) #define ModifyPeripheral32(_a1,_a2,_a3,_a4) Os_ModifyPeripheral32( _a1, _a2, _a3, _a4 ) #elif (OS_SC3 == STD_ON) || (OS_SC4 == STD_ON) /* The RTE uses SYS_CALL_xxx always, so map them to the OS functions */ extern StatusType Os_ArchSysCall(); extern StatusType Os_ArchSysCall_4(uint32 a, uint32 b, uint32 c, uint32 d); extern StatusType Os_ArchSysCall_5(uint32 a, uint32 b, uint32 c, uint32 d, uint32 e); #if defined(CFG_TC2XX) extern StatusType Os_ArchSysCall_4_P1(uint32 * a, uint32 b, uint32 c, uint32 d); extern StatusType Os_ArchSysCall_4_P2(uint32 a, uint32 * b, uint32 c, uint32 d); extern StatusType Os_ArchSysCall_4_P2_3(uint32 a, uint32 * b, uint32 * c, uint32 d); extern StatusType Os_ArchSysCall_4_P2_3(uint32 a, uint32 * b, uint32 * c, uint32 d); extern StatusType Os_ArchSysCall_4_S_P_P(uint32 a, uint32 * b, uint32 *c, uint32 d); extern StatusType Os_ArchSysCall_4_S_P_S(uint32 a, uint32 * b, uint32 c, uint32 d); extern StatusType Os_ArchSysCall_4_S_P_S_S(uint32 a, uint32 * b, uint32 c, uint32 d, uint32 e); extern int Os_ArchSysCall_4_P_S(uint32 *a, uint32 b, uint32 c, uint32 d); #endif extern StatusType Os_ArchSysCall_4_S(uint32 a, uint64, uint32 d); extern StatusType Os_SysCall_0(uint32 index); #if defined(CFG_ARM) extern StatusType Os_ArchSysCall_8(uint32 a1, uint32 a2, uint32 a3, uint32 a4, uint32 a5, uint32 a6,uint32 a7,uint32 a8 ); #endif #define SYS_CALL_0(index) Os_ArchSysCall_4(0,0,0,index) #define SYS_CALL_1(index,_a1) Os_ArchSysCall_4((uint32)(_a1),0,0,index) #define SYS_CALL_2(index,_a1,_a2) Os_ArchSysCall_4((uint32)_a1,(uint32)_a2,0,index) #define SYS_CALL_3(index,_a1,_a2,_a3) Os_ArchSysCall_4((uint32)_a1,(uint32)_a2,(uint32)_a3,index) #define SYS_CALL_4(index,_a1,_a2,_a3,_a4) Os_ArchSysCall_5((uint32)_a1,(uint32)_a2,(uint32)_a3,(uint32)_a4,index) #if defined(CFG_ARM) #define SYS_CALL_8(index,_a1,_a2,_a3,_a4,_a5,_a6,_a7 ) \ Os_ArchSysCall_8((uint32)_a1,(uint32)_a2,(uint32)_a3,(uint32)_a4,(uint32)_a5,(uint32)_a6,(uint32)_a7,index) #endif #if defined(CFG_TC2XX) #define SYS_CALL_1_P1(index,_a1) Os_ArchSysCall_4_P1((uint32 *)_a1,0,0,index) #define SYS_CALL_2_P2(index,_a1,_a2) Os_ArchSysCall_4_P2((uint32)_a1,(uint32 *)_a2,0,index) #define SYS_CALL_3_P2_3(index,_a1,_a2,_a3) Os_ArchSysCall_4_P2_3((uint32)_a1,(uint32 *)_a2,(uint32 *)_a3,index) #define SYS_CALL_3_S_P_S(index,_a1,_a2,_a3) Os_ArchSysCall_4_S_P_S((uint32)_a1,(uint32 *)_a2,(uint32)_a3,index) #define SYS_CALL_3_S_P_P(index,_a1,_a2,_a3) Os_ArchSysCall_4_S_P_P((uint32)_a1,(uint32 *)_a2,(uint32 *)_a3,index) #define SYS_CALL_4_S_P_S_S(index,_a1,_a2,_a3,_a4) Os_ArchSysCall_4_S_P_S_S((uint32)_a1,(uint32 *)_a2,(uint32)_a3,(uint32)_a4, index) #endif #define SYS_CALL_INDEX_EnterSupervisorMode 0 #define SYS_CALL_INDEX_ResumeAllInterrupts 1 #define SYS_CALL_INDEX_SuspendAllInterrupts 2 #define SYS_CALL_INDEX_EnableAllInterrupts 3 #define SYS_CALL_INDEX_DisableAllInterrupts 4 #define SYS_CALL_INDEX_ResumeOSInterrupts 5 #define SYS_CALL_INDEX_SuspendOSInterrupts 6 #define SYS_CALL_INDEX_ActivateTask 7 #define SYS_CALL_INDEX_TerminateTask 8 #define SYS_CALL_INDEX_ChainTask 9 #define SYS_CALL_INDEX_Schedule 10 #define SYS_CALL_INDEX_GetTaskID 11 #define SYS_CALL_INDEX_GetResource 12 #define SYS_CALL_INDEX_ReleaseResource 13 #define SYS_CALL_INDEX_SetEvent 14 #define SYS_CALL_INDEX_ClearEvent 15 #define SYS_CALL_INDEX_GetEvent 16 #define SYS_CALL_INDEX_WaitEvent 17 #define SYS_CALL_INDEX_GetAlarmBase 18 #define SYS_CALL_INDEX_GetAlarm 19 #define SYS_CALL_INDEX_SetRelAlarm 20 #define SYS_CALL_INDEX_SetAbsAlarm 21 #define SYS_CALL_INDEX_CancelAlarm 22 #define SYS_CALL_INDEX_StartOS 23 #define SYS_CALL_INDEX_ShutdownOS 24 #define SYS_CALL_INDEX_GetTaskState 25 #define SYS_CALL_INDEX_GetApplicationID 26 #define SYS_CALL_INDEX_GetISRID 27 #define SYS_CALL_INDEX_CheckISRMemoryAccess 28 #define SYS_CALL_INDEX_CheckTaskMemoryAccess 29 #define SYS_CALL_INDEX_CheckObjectAccess 30 #define SYS_CALL_INDEX_CheckObjectOwnership 31 #define SYS_CALL_INDEX_StartScheduleTableRel 32 #define SYS_CALL_INDEX_StartScheduleTableAbs 33 #define SYS_CALL_INDEX_StopScheduleTable 34 #define SYS_CALL_INDEX_NextScheduleTable 35 #define SYS_CALL_INDEX_StartScheduleTableSynchron 36 #define SYS_CALL_INDEX_SyncScheduleTable 37 #define SYS_CALL_INDEX_GetScheduleTableStatus 38 #define SYS_CALL_INDEX_SetScheduleTableAsync 39 #define SYS_CALL_INDEX_IncrementCounter 40 #define SYS_CALL_INDEX_GetCounterValue 41 #define SYS_CALL_INDEX_GetElapsedValue 42 #define SYS_CALL_INDEX_ReadPeripheral8 43 #define SYS_CALL_INDEX_ReadPeripheral16 44 #define SYS_CALL_INDEX_ReadPeripheral32 45 #define SYS_CALL_INDEX_WritePeripheral8 46 #define SYS_CALL_INDEX_WritePeripheral16 47 #define SYS_CALL_INDEX_WritePeripheral32 48 #define SYS_CALL_INDEX_ModifyPeripheral8 49 #define SYS_CALL_INDEX_ModifyPeripheral16 50 #define SYS_CALL_INDEX_ModifyPeripheral32 51 #define SYS_CALL_INDEX_write 52 #define SYS_CALL_CNT 53 #define SYS_CALL_EnterSupervisorMode() (void)SYS_CALL_0( SYS_CALL_INDEX_EnterSupervisorMode ) #define SYS_CALL_ResumeAllInterrupts() (void)SYS_CALL_0( SYS_CALL_INDEX_ResumeAllInterrupts ) #define SYS_CALL_SuspendAllInterrupts() (void)SYS_CALL_0( SYS_CALL_INDEX_SuspendAllInterrupts ) #define SYS_CALL_EnableAllInterrupts() (void)SYS_CALL_0( SYS_CALL_INDEX_EnableAllInterrupts ) #define SYS_CALL_DisableAllInterrupts() (void)SYS_CALL_0( SYS_CALL_INDEX_DisableAllInterrupts ) #define SYS_CALL_ResumeOSInterrupts() (void)SYS_CALL_0( SYS_CALL_INDEX_ResumeOSInterrupts ) #define SYS_CALL_SuspendOSInterrupts() (void)SYS_CALL_0( SYS_CALL_INDEX_SuspendOSInterrupts ) #define SYS_CALL_ActivateTask(_a1) SYS_CALL_1( SYS_CALL_INDEX_ActivateTask,_a1 ) #define SYS_CALL_TerminateTask() SYS_CALL_0( SYS_CALL_INDEX_TerminateTask) #define SYS_CALL_ChainTask(_a1) SYS_CALL_1( SYS_CALL_INDEX_ChainTask,_a1) #define SYS_CALL_Schedule() SYS_CALL_0( SYS_CALL_INDEX_Schedule) #if defined(CFG_TC2XX) #define SYS_CALL_GetTaskID(_a1) SYS_CALL_1_P1( SYS_CALL_INDEX_GetTaskID,_a1) #else #define SYS_CALL_GetTaskID(_a1) SYS_CALL_1( SYS_CALL_INDEX_GetTaskID,_a1) #endif #define SYS_CALL_GetResource(_a1) SYS_CALL_1( SYS_CALL_INDEX_GetResource,_a1) #define SYS_CALL_ReleaseResource(_a1) SYS_CALL_1( SYS_CALL_INDEX_ReleaseResource,_a1) #define SYS_CALL_SetEvent(_a1,_a2) SYS_CALL_2( SYS_CALL_INDEX_SetEvent,_a1, _a2) #define SYS_CALL_ClearEvent(_a1) SYS_CALL_1( SYS_CALL_INDEX_ClearEvent,_a1) #if defined(CFG_TC2XX) #define SYS_CALL_GetEvent(_a1, _a2) SYS_CALL_2_P2( SYS_CALL_INDEX_GetEvent,_a1,_a2) #else #define SYS_CALL_GetEvent(_a1, _a2) SYS_CALL_2( SYS_CALL_INDEX_GetEvent,_a1,_a2) #endif #define SYS_CALL_WaitEvent(_a1) SYS_CALL_1( SYS_CALL_INDEX_WaitEvent,_a1) #if defined(CFG_TC2XX) #define SYS_CALL_GetAlarmBase(_a1, _a2) SYS_CALL_2_P2( SYS_CALL_INDEX_GetAlarmBase,_a1, _a2) #define SYS_CALL_GetAlarm(_a1, _a2) SYS_CALL_2_P2( SYS_CALL_INDEX_GetAlarm,_a1, _a2) #else #define SYS_CALL_GetAlarmBase(_a1, _a2) SYS_CALL_2( SYS_CALL_INDEX_GetAlarmBase,_a1, _a2) #define SYS_CALL_GetAlarm(_a1, _a2) SYS_CALL_2( SYS_CALL_INDEX_GetAlarm,_a1, _a2) #endif #define SYS_CALL_SetRelAlarm(_a1,_a2,_a3) SYS_CALL_3( SYS_CALL_INDEX_SetRelAlarm,_a1, _a2, _a3) #define SYS_CALL_SetAbsAlarm(_a1,_a2,_a3) SYS_CALL_3( SYS_CALL_INDEX_SetAbsAlarm,_a1, _a2, _a3) #define SYS_CALL_CancelAlarm(_a1) SYS_CALL_1( SYS_CALL_INDEX_CancelAlarm,_a1) #define SYS_CALL_StartOS(_a1) SYS_CALL_1( SYS_CALL_INDEX_StartOS,_a1) #define SYS_CALL_ShutdownOS(_a1) SYS_CALL_1( SYS_CALL_INDEX_ShutdownOS,_a1) #if defined(CFG_TC2XX) #define SYS_CALL_GetTaskState(_a1, _a2) SYS_CALL_2_P2( SYS_CALL_INDEX_GetTaskState,_a1, _a2) #else #define SYS_CALL_GetTaskState(_a1, _a2) SYS_CALL_2( SYS_CALL_INDEX_GetTaskState,_a1, _a2) #endif #if (( OS_SC3 == STD_ON ) || ( OS_SC4 == STD_ON )) #define SYS_CALL_GetApplicationID() SYS_CALL_0( SYS_CALL_INDEX_GetApplicationID) #endif #define SYS_CALL_GetISRID() SYS_CALL_0( SYS_CALL_INDEX_GetISRID) #define SYS_CALL_CheckISRMemoryAccess(_a1,_a2,_a3) SYS_CALL_3( SYS_CALL_INDEX_CheckISRMemoryAccess,_a1, _a2, _a3) #define SYS_CALL_CheckTaskMemoryAccess(_a1,_a2,_a3) SYS_CALL_3( SYS_CALL_INDEX_CheckTaskMemoryAccess,_a1, _a2, _a3) #if (( OS_SC3 == STD_ON ) || ( OS_SC4 == STD_ON )) #define SYS_CALL_CheckObjectAccess(_a1,_a2,_a3) SYS_CALL_3( SYS_CALL_INDEX_CheckObjectAccess,_a1,_a2,_a3) #endif #define SYS_CALL_CheckObjectOwnership(_a1,_a2) SYS_CALL_2( SYS_CALL_INDEX_CheckObjectOwnership,_a1,_a2) #define SYS_CALL_StartScheduleTableRel(_a1,_a2) SYS_CALL_2( SYS_CALL_INDEX_StartScheduleTableRel,_a1,_a2) #define SYS_CALL_StartScheduleTableAbs(_a1,_a2) SYS_CALL_2( SYS_CALL_INDEX_StartScheduleTableAbs,_a1,_a2) #define SYS_CALL_StopScheduleTable(_a1) SYS_CALL_1( SYS_CALL_INDEX_StopScheduleTable,_a1) #define SYS_CALL_NextScheduleTable(_a1,_a2) SYS_CALL_2( SYS_CALL_INDEX_NextScheduleTable,_a1,_a2) #if ( OS_SC2 == STD_ON ) || ( OS_SC4 == STD_ON ) #define SYS_CALL_StartScheduleTableSynchron(_a1) SYS_CALL_1( SYS_CALL_INDEX_StartScheduleTableSynchron,_a1) #define SYS_CALL_SyncScheduleTable(_a1,_a2) SYS_CALL_2( SYS_CALL_INDEX_SyncScheduleTable,_a1,_a2) #define SYS_CALL_SetScheduleTableAsync(_a1) SYS_CALL_1( SYS_CALL_INDEX_SetScheduleTableAsync,_a1) #endif #define SYS_CALL_GetScheduleTableStatus(_a1,_a2) SYS_CALL_2( SYS_CALL_INDEX_GetScheduleTableStatus,_a1,_a2) #define SYS_CALL_IncrementCounter(_a1) SYS_CALL_1( SYS_CALL_INDEX_IncrementCounter,_a1) #if defined(CFG_TC2XX) #define SYS_CALL_GetCounterValue(_a1,_a2) SYS_CALL_2_P2( SYS_CALL_INDEX_GetCounterValue,_a1,_a2) #define SYS_CALL_GetElapsedValue(_a1,_a2,_a3) SYS_CALL_3_P2_3( SYS_CALL_INDEX_GetElapsedValue,_a1,_a2,_a3) #else #define SYS_CALL_GetCounterValue(_a1,_a2) SYS_CALL_2( SYS_CALL_INDEX_GetCounterValue,_a1,_a2) #define SYS_CALL_GetElapsedValue(_a1,_a2,_a3) SYS_CALL_3( SYS_CALL_INDEX_GetElapsedValue,_a1,_a2,_a3) #endif #if defined(CFG_TC2XX) #define ReadPeripheral8(_a1,_a2,_a3) SYS_CALL_3_S_P_P( SYS_CALL_INDEX_ReadPeripheral8, _a1, _a2, _a3 ) #define ReadPeripheral16(_a1,_a2,_a3) SYS_CALL_3_S_P_P( SYS_CALL_INDEX_ReadPeripheral16, _a1, _a2, _a3 ) #define ReadPeripheral32(_a1,_a2,_a3) SYS_CALL_3_S_P_P( SYS_CALL_INDEX_ReadPeripheral32, _a1, _a2, _a3 ) #define WritePeripheral8(_a1,_a2,_a3) SYS_CALL_3_S_P_S( SYS_CALL_INDEX_WritePeripheral8, _a1, _a2, _a3 ) #define WritePeripheral16(_a1,_a2,_a3) SYS_CALL_3_S_P_S( SYS_CALL_INDEX_WritePeripheral16, _a1, _a2, _a3 ) #define WritePeripheral32(_a1,_a2,_a3) SYS_CALL_3_S_P_S( SYS_CALL_INDEX_WritePeripheral32, _a1, _a2, _a3 ) #else #define ReadPeripheral8(_a1,_a2,_a3) SYS_CALL_3( SYS_CALL_INDEX_ReadPeripheral8, _a1, _a2, _a3 ) #define ReadPeripheral16(_a1,_a2,_a3) SYS_CALL_3( SYS_CALL_INDEX_ReadPeripheral16, _a1, _a2, _a3 ) #define ReadPeripheral32(_a1,_a2,_a3) SYS_CALL_3( SYS_CALL_INDEX_ReadPeripheral32, _a1, _a2, _a3 ) #define WritePeripheral8(_a1,_a2,_a3) SYS_CALL_3( SYS_CALL_INDEX_WritePeripheral8, _a1, _a2, _a3 ) #define WritePeripheral16(_a1,_a2,_a3) SYS_CALL_3( SYS_CALL_INDEX_WritePeripheral16, _a1, _a2, _a3 ) #define WritePeripheral32(_a1,_a2,_a3) SYS_CALL_3( SYS_CALL_INDEX_WritePeripheral32, _a1, _a2, _a3 ) #endif #if defined(CFG_ARM) #define ModifyPeripheral8(_a1,_a2,_a3,_a4) SYS_CALL_8( SYS_CALL_INDEX_ModifyPeripheral8, _a1, _a2, _a3, _a4, 0u, 0u, 0u) #define ModifyPeripheral16(_a1,_a2,_a3,_a4) SYS_CALL_8( SYS_CALL_INDEX_ModifyPeripheral16, _a1, _a2, _a3, _a4, 0u, 0u, 0u) #define ModifyPeripheral32(_a1,_a2,_a3,_a4) SYS_CALL_8( SYS_CALL_INDEX_ModifyPeripheral32, _a1, _a2, _a3, _a4, 0u, 0u, 0u) #elif defined(CFG_TC2XX) #define ModifyPeripheral8(_a1,_a2,_a3,_a4) SYS_CALL_4_S_P_S_S( SYS_CALL_INDEX_ModifyPeripheral8, _a1, _a2, _a3, _a4 ) #define ModifyPeripheral16(_a1,_a2,_a3,_a4) SYS_CALL_4_S_P_S_S( SYS_CALL_INDEX_ModifyPeripheral16, _a1, _a2, _a3, _a4 ) #define ModifyPeripheral32(_a1,_a2,_a3,_a4) SYS_CALL_4_S_P_S_S( SYS_CALL_INDEX_ModifyPeripheral32, _a1, _a2, _a3, _a4 ) #else #define ModifyPeripheral8(_a1,_a2,_a3,_a4) SYS_CALL_4( SYS_CALL_INDEX_ModifyPeripheral8, _a1, _a2, _a3, _a4 ) #define ModifyPeripheral16(_a1,_a2,_a3,_a4) SYS_CALL_4( SYS_CALL_INDEX_ModifyPeripheral16, _a1, _a2, _a3, _a4 ) #define ModifyPeripheral32(_a1,_a2,_a3,_a4) SYS_CALL_4( SYS_CALL_INDEX_ModifyPeripheral32, _a1, _a2, _a3, _a4 ) #endif #if defined(CFG_TC2XX) #define SYS_CALL_write(_a1,_a2,_a3) SYS_CALL_3_S_P_S( SYS_CALL_INDEX_write,_a1, _a2, _a3 ) #else #define SYS_CALL_write(_a1,_a2,_a3) SYS_CALL_3( SYS_CALL_INDEX_write,_a1, _a2, _a3 ) #endif #endif /* (OS_SC1 == STD_ON) || (OS_SC2 == STD_ON) */ #define SYS_CALL_AtomicCopy8(to, from) (to) = (from) #define SYS_CALL_AtomicCopy16(to, from) (to) = (from) #define SYS_CALL_AtomicCopy32(to, from) (to) = (from) #define SYS_CALL_AtomicCopy64(to, from) SYS_CALL_SuspendAllInterrupts(); \ (to) = (from); \ SYS_CALL_ResumeAllInterrupts() #define SYS_CALL_AtomicCopyBoolean(to, from) (to) = (from) #if (OS_USE_APPLICATIONS == STD_ON) #if (( OS_SC3 == STD_ON ) || ( OS_SC4 == STD_ON )) ApplicationType GetApplicationID( void ); AccessType CheckISRMemoryAccess( ISRType ISRID, MemoryStartAddressType Address, MemorySizeType Size ); AccessType CheckTaskMemoryAccess( TaskType TaskID, MemoryStartAddressType Address, MemorySizeType Size ); ObjectAccessType CheckObjectAccess( ApplicationType ApplId, ObjectTypeType ObjectType, uint32 objectId ); #endif // #if (( OS_SC3 == STD_ON ) || ( OS_SC4 == STD_ON )) ApplicationType CheckObjectOwnership( ObjectTypeType ObjectType, uint32 objectId ); #endif //#if (OS_USE_APPLICATIONS == STD_ON) StatusType GetTaskID( TaskRefType TaskID ); StatusType GetTaskState( TaskType task_id, TaskStateRefType state); void ShutdownOS( StatusType ); StatusType ActivateTask( TaskType TaskID ); StatusType TerminateTask( void ); StatusType ChainTask( TaskType TaskID ); StatusType Schedule( void ); typedef uint8 ResourceType; StatusType GetResource( ResourceType ResID ); StatusType ReleaseResource( ResourceType ResID); /* * Define scheduler as topmost */ #define RES_SCHEDULER OS_RESOURCE_CNT /* * Priorities of tasks and resources */ #define OS_TASK_PRIORITY_MIN 0 #define OS_TASK_PRIORITY_MAX UINT32_MAX /* Logical priority is higher higher than normal tasks */ #define OS_RES_SCHEDULER_PRIO UINT32_MAX typedef struct OsDriver_s { sint32 OsGptChannelRef; } OsDriver; /*------------------------------------------------------------------- * Counters *-----------------------------------------------------------------*/ #ifdef USE_RTE /* The OS service interface does not match the return type specified in the * OS specification and therefore the following wrap functions are introduced. * Also note there is an argument mismatch in the specification which suggests * the type is TimeInMicrosecondsType while the description describes that * ticks are used. */ /******************************************************************************* * @brief This service reads the current count value of a counter (returning * either the hardware timer ticks if counter is driven by hardware or * the software ticks when user drives counter). * @param[in] counterId Counter id * @param[out] value Contains the current tick value of the counter * @return Status of the execution success of the function * @retval E_OK The function was excuted successfully * @retval E_OS_ID Function error, the input counter value was * invalid * @retval E_OS_PARAM_POINTER Function error, the value argument was NULL_PTR * @retval E_OS_DISABLEDINT Function error, the interrupts were disabled ******************************************************************************/ Std_ReturnType Os_GetCounterValue(CounterType counterId, TickType * value); /******************************************************************************* * @brief This service gets the number of ticks between the current tick value * and a previously read tick value * @param[in] counterId Counter id * @param[inout] value in: the previously read tick value of the counter * out: the current tick value of the counter * @param[out] elapsedTime The difference to the previous read value * @return Status of the execution success of the function * @retval E_OK The function was excuted successfully * @retval E_OS_ID Function error, the input counter value was * invalid * @retval E_OS_PARAM_POINTER Function error, the value argument was NULL_PTR * @retval E_OS_DISABLEDINT Function error, the interrupts were disabled ******************************************************************************/ Std_ReturnType Os_GetElapsedValue(CounterType counterId, TickType * value, TickType * elapsedValue); #endif StatusType IncrementCounter( CounterType ); StatusType GetCounterValue( CounterType, TickRefType ); StatusType GetElapsedCounterValue( CounterType, TickRefType val, TickRefType elapsed_val); StatusType GetElapsedValue( CounterType CounterID, TickRefType Value, TickRefType ElapsedValue ); /*------------------------------------------------------------------- * System timer *-----------------------------------------------------------------*/ typedef const uint32 OsTickType; /*lint -esym(9003,OsTickFreq) MISRA:EXTERNAL_FILE:Inhibit lint error for external object OsTickFreq:[MISRA 2012 Rule 8.9, advisory]*/ extern OsTickType OsTickFreq; void Os_SysTickInit( void ); #if defined(CFG_OS_SYSTICK2) void Os_SysTickStart2( uint32 frequency ); #else void Os_SysTickStart(TickType period_ticks); #endif /* Return a value that is always a free running timer */ TickType GetOsTick( void ); /* Since this is based on SW ticks, no use to have ns resolution */ #define OSTICKDURATION_US (OSTICKDURATION/1000UL) /* Have special macros to always get the OsTick */ #define OS_TICKS2SEC_OS_TICK(_ticks) ( (OSTICKDURATION_US * (_ticks))/1000000UL) #define OS_TICKS2MS_OS_TICK(_ticks) ( (OSTICKDURATION_US * (_ticks))/1000UL ) #define OS_TICKS2US_OS_TICK(_ticks) (OSTICKDURATION_US * (_ticks)) #define OS_TICKS2NS_OS_TICK(_ticks) (OSTICKDURATION * (_ticks)) /*------------------------------------------------------------------- * Kernel extra *-----------------------------------------------------------------*/ #if defined(CFG_KERNEL_EXTRA) #define TMO_MIN 0 #define TMO_INFINITE (0xffffffffUL) #include "os_sem.h" #include "os_mbox.h" #define TICK_MAX UINT_MAX typedef struct OsSemaphore { volatile sint32 count; sint32 maxCount; STAILQ_HEAD(,OsTaskVar) taskHead; } OsSemaphoreType; typedef OsSemaphoreType OsMutexType; StatusType Sleep( TickType ticks ); /* Semaphores */ OsSemaphoreType * Semaphore_Create( sint32 initialCount, sint32 maxCount ); void Semaphore_Destroy( OsSemaphoreType *semPtr ); StatusType Semaphore_Init( OsSemaphoreType *semPtr, sint32 initialCount, sint32 maxCount ); StatusType Semaphore_Wait( OsSemaphoreType *semPtr, TickType tmo ); void Semaphore_Signal(OsSemaphoreType *semPtr); StatusType WaitMutex( OsMutexType *mutexPtr, TickType tmo ); StatusType ReleaseMutex( OsMutexType *mutexPtr ); #endif #if defined(CFG_OS_ISR_HOOKS) void Os_PreIsrHook(ISRType); void Os_PostIsrHook(ISRType); #endif #if defined(CFG_T1_ENABLE) void Os_WaitEventHook(TaskType taskId); void Os_ResumeEventHook(TaskType taskId); void Os_ReleaseEventHook(TaskType taskId); void Os_ActivateTaskHook(TaskType taskId); void Os_StopTaskHook(TaskType taskId); void Os_StartTaskHook(TaskType taskId); void Os_StartStopTaskHook(TaskType taskIdStop, TaskType taskIdStart); #endif /*------------------------------------------------------------------- * Schedule Tables *-----------------------------------------------------------------*/ StatusType StartScheduleTableRel(ScheduleTableType sid, TickType offset); StatusType StartScheduleTableAbs(ScheduleTableType sid, TickType val ); #if ( OS_SC2 == STD_ON ) || ( OS_SC4 == STD_ON ) StatusType StartScheduleTableSynchron(ScheduleTableType sid ); StatusType SyncScheduleTable( ScheduleTableType ScheduleTableID, TickType Value ); StatusType SetScheduleTableAsync( ScheduleTableType sid ); #endif StatusType StopScheduleTable(ScheduleTableType sid); StatusType NextScheduleTable( ScheduleTableType sid_curr, ScheduleTableType sid_next); StatusType GetScheduleTableStatus( ScheduleTableType sid, ScheduleTableStatusRefType status ); /*------------------------------------------------------------------- * Alarms *-----------------------------------------------------------------*/ typedef uint16 AlarmType; typedef struct { TickType maxallowedvalue; TickType tickperbase; TickType mincycle; } AlarmBaseType; /*@req OSEK_SWS_AL_00024*/ typedef AlarmBaseType *AlarmBaseRefType; /*@req OSEK_SWS_AL_00024*/ StatusType GetAlarmBase( AlarmType AlarmId, AlarmBaseRefType Info ); StatusType GetAlarm(AlarmType AlarmId, TickRefType Tick); StatusType SetRelAlarm(AlarmType AlarmId, TickType Increment, TickType Cycle); StatusType SetAbsAlarm(AlarmType AlarmId, TickType Start, TickType Cycle); StatusType CancelAlarm(AlarmType AlarmId); /*------------------------------------------------------------------- * Spinlocks *-----------------------------------------------------------------*/ /* @req SWS_Os_00792 Type definition */ typedef enum { TRYTOGETSPINLOCK_SUCCESS, TRYTOGETSPINLOCK_NOSUCCESS } TryToGetSpinlockType; /* @req SWS_Os_00791 Type definition */ typedef uint16 SpinlockIdType; #if (OS_NUM_CORES > 1) StatusType GetSpinlock( SpinlockIdType SpinlockId ); StatusType ReleaseSpinlock( SpinlockIdType SpinlockId ); StatusType TryToGetSpinlock( SpinlockIdType SpinlockId, TryToGetSpinlockType* Success); #else #define GetSpinlock( x ) #define ReleaseSpinlock( x ) #define TryToGetSpinlock( x,y ) #endif /*------------------------------------------------------------------- * Error's *-----------------------------------------------------------------*/ typedef enum { OSServiceId_ActivateTask, OSServiceId_TerminateTask, OSServiceId_ChainTask, OSServiceId_Schedule, OSServiceId_GetTaskID, OSServiceId_GetResource, OSServiceId_ReleaseResource, OSServiceId_SetEvent, OSServiceId_ClearEvent, OSServiceId_GetEvent, OSServiceId_WaitEvent, OSServiceId_GetAlarmBase, OSServiceId_GetAlarm, OSServiceId_SetRelAlarm, OSServiceId_SetAbsAlarm, OSServiceId_CancelAlarm, OSServiceId_StartOS, OSServiceId_ShutdownOS, OSServiceId_ErrorHook, OSServiceId_PreTaskHook, OSServiceId_PostTaskHook, OSServiceId_StartupHook, OSServiceId_ShutdownHook, OSServiceId_GetTaskState, OSServiceId_GetApplicationID, OSServiceId_GetISRID, OSServiceId_CallTrustedFunction, OSServiceId_CheckISRMemoryAccess, OSServiceId_TaskMemoryAccess, OSServiceId_CheckObjectAccess, OSServiceId_CheckObjectOwnership, OSServiceId_StartScheduleTableRel, OSServiceId_StartScheduleTableAbs, OSServiceId_StopScheduleTable, OSServiceId_NextScheduleTable, OSServiceId_StartScheduleTableSynchron, OSServiceId_SyncScheduleTable, OSServiceId_GetScheduleTableStatus, OSServiceId_SetScheduleTableAsync, OSServiceId_IncrementCounter, OSServiceId_GetCounterValue, OSServiceId_GetElapsedValue, OSServiceId_TerminateApplication, OSServiceId_AllowAccess, OSServiceId_GetApplicationState, OSServiceId_ReadPeripheral8, OSServiceId_ReadPeripheral16, OSServiceId_ReadPeripheral32, OSServiceId_WritePeripheral8, OSServiceId_WritePeripheral16, OSServiceId_WritePeripheral32, OSServiceId_ModifyPeripheral8, OSServiceId_ModifyPeripheral16, OSServiceId_ModifyPeripheral32, #if defined(CFG_KERNEL_EXTRA) OSServiceId_Sleep, OSServiceId_SemWaitChecks, OSServiceId_SemSignal, OSServiceId_BSemSignal, #endif } OsServiceIdType; typedef struct OsError { OsServiceIdType serviceId; uint32 param1; uint32 param2; uint32 param3; } OsErrorType; extern OsErrorType os_error; // IMPROVMENT: Add the service id to all OS service methods. static inline OsServiceIdType OSErrorGetServiceId(void) { return os_error.serviceId; } /* @req SWS_Os_00439 * The Operating System module shall provide the OSEK error macros (OSError…()) * to all configured error hooks AND there shall be two (like in OIL) * global configuration parameters to switch these macros on or off. * * NOTE: As Os has only extended mode, not standard mode, this requirement is considered for extended mode only, * that means no macro is implemented to switch off OSError_...() */ //Task #define OSError_ActivateTask_TaskID ((TaskType) os_error.param1) #define OSError_ChainTask_TaskID ((TaskType) os_error.param1) #define OSError_GetTaskID_TaskID ((TaskRefType) os_error.param1) #define OSError_GetTaskState_TaskId ((TaskType) os_error.param1) #define OSError_GetTaskState_State ((TaskStateRefType) os_error.param2) //Resource #define OSError_GetResource_ResID ((ResourceType) os_error.param1) #define OSError_ReleaseResource_ResID ((ResourceType) os_error.param1) //Event #define OSError_SetEvent_TaskID ((TaskType) os_error.param1) #define OSError_SetEvent_Mask ((EventMaskType) os_error.param2) #define OSError_ClearEvent_Mask ((EventMaskType) os_error.param1) #define OSError_GetEvent_TaskId ((TaskType) os_error.param1) #define OSError_GetEvent_Mask ((EventMaskRefType) os_error.param2) #define OSError_WaitEvent_Mask ((EventMaskType) os_error.param1) //Alarm #define OSError_GetAlarmBase_AlarmId ((AlarmType) os_error.param1) #define OSError_GetAlarmBase_Info ((AlarmBaseRefType) os_error.param2) #define OSError_GetAlarm_AlarmId ((AlarmType) os_error.param1) #define OSError_GetAlarm_Tick ((TickRefType) os_error.param2) #define OSError_SetRelAlarm_AlarmId ((AlarmType) os_error.param1) #define OSError_SetRelAlarm_Increment ((TickType) os_error.param2) #define OSError_SetRelAlarm_Cycle ((TickType) os_error.param3) #define OSError_SetAbsAlarm_AlarmId ((AlarmType) os_error.param1) #define OSError_SetAbsAlarm_Start ((TickType) os_error.param2) #define OSError_SetAbsAlarm_Cycle ((TickType) os_error.param3) #define OSError_CancelAlarm_AlarmId ((AlarmType) os_error.param1) //Application #define OSError_GetApplicationState_ApplId ((ApplicationType) os_error.param1) #define OSError_GetApplicationState_Value ((ApplicationStateRefType) os_error.param2) //Counter #define OSError_IncrementCounter_CounterId ((CounterType) os_error.param1) #define OSError_GetCounterValue_CounterId ((CounterType) os_error.param1) #define OSError_GetCounterValue_RickRef ((TickRefType) os_error.param2) #define OSError_GetElapsedValue_CounterId ((CounterType) os_error.param1) #define OSError_GetElapsedValue_Value ((TickRefType) os_error.param2) #define OSError_GetElapsedValue_ElapsedVal ((TickRefType) os_error.param3) //Schedule Table #define OSError_StartScheduleTableRel_ScheduleTableID ((ScheduleTableType) os_error.param1) #define OSError_StartScheduleTableRel_Offset ((TickType) os_error.param2) #define OSError_StartScheduleTableAbs_ScheduleTableID ((ScheduleTableType) os_error.param1) #define OSError_StartScheduleTableAbs_Start ((TickType) os_error.param2) #define OSError_StartScheduleTableSynchron_ScheduleTableID ((ScheduleTableType) os_error.param1) #define OSError_StopScheduleTable_ScheduleTableID ((ScheduleTableType) os_error.param1) #define OSError_NextScheduleTable_ScheduleTableID_From ((ScheduleTableType) os_error.param1) #define OSError_NextScheduleTable_ScheduleTableID_To ((ScheduleTableType) os_error.param2) #define OSError_SyncScheduleTable_ScheduleTableID ((ScheduleTableType) os_error.param1) #define OSError_SyncScheduleTable_Value ((TickType) os_error.param2) #define OSError_GetScheduleTableStatus_ScheduleTableID ((ScheduleTableType) os_error.param1) #define OSError_GetScheduleTableStatus_Status ((ScheduleTableStatusRefType) os_error.param2) #define OSError_SetScheduleTableAsync_ScheduleTableID ((ScheduleTableType) os_error.param1) //Init #define OSError_StartOS_Mode ((AppModeType) os_error.param1) //Hook #define OSError_ErrorHook_Error ((StatusType) os_error.param1) #define OSError_ShutdownHook_Error ((StatusType) os_error.param1) #if defined(LOCALMESSAGESONLY) #error LOCALMESSAGESONLY shall not be defined #endif /*------------------------------------------------------------------- * COM *-----------------------------------------------------------------*/ typedef void *ApplicationDataRef; /*------------------------------------------------------------------- * Multicore OS *-----------------------------------------------------------------*/ #define OS_CORE_ID_INVALID 65535 #define OS_CORE_ID_MASTER 0 /*lint -emacro(506, OS_CORE_IS_ID_MASTER) MISRA:OTHER:Exception, single core configuration result is always true:[MISRA 2004 Info,advisory]*/ #define OS_CORE_IS_ID_MASTER(_id) (OS_CORE_ID_MASTER == (_id)) typedef uint32 CoreIDType; /* @req SWS_Os_00790 Type definition */ #if defined(CFG_MPC5777M) /* No support for multicore, use core2 */ #define MPC5777M_ACTUAL_CORE_ID_MASTER 2 #define MPC5777M_INTC_REG_EOIR EOIR_PRC2 #define MPC5777M_INTC_REG_IACKR IACKR_PRC2 /* But we say that we use core0 since os assumes this for singlecore */ /*lint -emacro(506, GetCoreID) MISRA:OTHER:Exception, for optimization:[MISRA 2004 Info,advisory]*/ #define GetCoreID() 0 #else #if (OS_NUM_CORES > 1) CoreIDType GetCoreID(void); #else /*lint -emacro(506, GetCoreID) MISRA:OTHER:Exception, for optimization:[MISRA 2004 Info,advisory]*/ #define GetCoreID() 0 #endif #endif void StartCore(CoreIDType coreId, StatusType* status); /* * ArcCore extensions */ void OsTick(void); #define OS_ISR_TYPE2 0 #define OS_ISR_TYPE1 1 union isr_attr { TaskType tid; void (*entry)(void); }; #define TTY_NONE 1 #define TTY_T32 2 #define TTY_WINIDEA 4 #define TTY_SERIAL 8 #define RAMLOG 16 #endif /*OS_H_*/
2301_81045437/classic-platform
system/Os/rtos/inc/Os.h
C
unknown
48,656
/*-------------------------------- 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 ARC_H_ #define ARC_H_ #ifndef ARRAY_SIZE #define ARRAY_SIZE(_x) sizeof(_x)/sizeof((_x)[0]) #endif #define OS_STR__(x) #x #define OS_STRSTR__(x) OS_STR__(x) #if !defined(STR__) #define STR__(x) #x #endif #if !defined(STRSTR__) #define STRSTR__(x) OS_STR__(x) #endif #ifndef MIN #define MIN(_x,_y) (((_x) < (_y)) ? (_x) : (_y)) #endif #ifndef MAX #define MAX(_x,_y) (((_x) > (_y)) ? (_x) : (_y)) #endif #define OS_ARC_PCB_NAME_SIZE 16 #define OS_STACK_USAGE(_x) ((((_x)->size - (uint32_t)((size_t)(_x)->usage - (size_t)(_x)->top))*100)/(_x)->size) #include "Os.h" #include "arc_assert.h" #define ARC_TASKTYPE_BASIC 0 #define ARC_TASKTYPE_EXENDED 1 #define OS_ARC_F_TASK_ALL 0xffffffffUL #define OS_ARC_F_TASK_BASIC (1UL<<0u) #define OS_ARC_F_TASK_STACK (1UL<<1u) /** * Holds information about stack usage */ typedef struct StackInfo_s { /* This task was swapped in with this stack */ void * at_swap; /* Pointer to the top of the stack */ void * top; /* The size of the stack in bytes */ uint32 size; /* Pointer to the current place of the stack */ void * curr; /* Calculated usage in % of total */ void * usage; /* Calculated usage in % of total */ uint8 usageInPercent; } StackInfoType; typedef struct Arc_PcbS { char name[OS_ARC_PCB_NAME_SIZE]; uint32 tasktype; StackInfoType stack; } Arc_PcbType; /** * Converts OSEK StatusType to a string for easy printing * @param status */ const char *Arc_StatusToString(StatusType status); /** * Get task's stack information * @param pid * @param s */ void Os_Arc_GetStackInfo( TaskType pid, StackInfoType *s ); /** * Get task name, type and stack information * @param pcbPtr * @param taskId * @param flags */ void Os_Arc_GetTaskInfo( Arc_PcbType *pcbPtr, TaskType taskId, uint32 flags ); /** * Get ISR name * @param pcbPtr * @param isrId */ void Os_Arc_GetIsrInfo( Arc_PcbType *pcbPtr, ISRType isrId ); /** * Get the number of configured ISRs (category1 and 2) * @return Total number of configured ISRs */ ISRType Os_Arc_GetIsrCount( void ); /** * If the configured trap is not handled by callouts then * this function will be called.and shutdown the system * @param excpetion: excpetion id, pData: pcb data (this argument is not handled in this function) */ void Os_Arc_Panic(uint32 exception, void *pData); #endif /* ARC_H_ */
2301_81045437/classic-platform
system/Os/rtos/inc/arc.h
C
unknown
3,277
/*-------------------------------- 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 -----------------------------*/ /* * Porting interface. Should really be called port.h or something. * The routines below + interrupt handing in Mcu_IntXX.c, should * be all that needs to be implemented for a new port. */ #ifndef ARCH_H_ #define ARCH_H_ #include "Arc_Types.h" /* Default backchain space */ #define ARCH_BACKCHAIN_SIZE (16U) /* Pattern for startup stack */ #define START_STACK_PATTERN 0x42u /** * @brief Set the stack pointer to sp and call function f. * * @param sp Pointer to the stack * @param f Pointer to the function to call. * */ void Os_ArchSetSpAndCall(void *sp, void (*f)(void) ); /** * @brief Return the current stack pointer. * * @param sp */ void Os_ArchSetStackPointer(void *sp); /** * Swap context. * Sets the current pcb * * @param old - old ptr to pcb * @return */ void Os_ArchSwapContext(void *old,void *new); /** * Swap context for the first time for a task * * The only way to call this function right now is to: * Os_TaskSwapContextTo(NULL,<pcb>); */ void Os_ArchSwapContextTo(void *old,void *new); /** * Setup a pcb before use. * * This function should setup: * - context marker( SC_PATTERN, LC_PATTERN ) * - Arch specific register setup * - Check that the stack is suffient for the arch * - More... * * @param pcb Ptr to pcb */ void Os_ArchSetupContext( OsTaskVarType *pcb ); /** * Get current stack pointer * * @return current stack pointer */ void *Os_ArchGetStackPtr( void ); /** * Initialize the hardware. * This could be initialization of: * - interrupt controller * - timers */ void Os_ArchInit( void ); /** * Function that is used when task entry is called for the * first time. For ports that don't support user mode it * should just call entry entry() function of the current task. * * When user mode is supported a switch to user mode must be done * in some way. A trap maybe? */ void Os_ArchFirstCall( void ); #if (OS_SC3==STD_ON) || (OS_SC4==STD_ON) /** * @brief Call the ISR entry. * @details This function should * * Set the MPU entries for ISR application * * Load the application interrupt stack * * Swap to user mode * * Enable interrupts * * Call the ISR entry * * Swap back to privileged mode (trap into the kernel) * * return * * @param aP Pointer to application * @param func Function pointer to the ISR. * @param paP Pointer to preemted application */ void Os_ArchCallIsrEntry( OsAppVarType *aP, void (*func)(void), OsAppVarType *paP); #endif /** * Get the small context size * * @return The small context size in bytes */ uint32 Os_ArchGetScSize( void ); /** * * @param id * @return */ boolean Os_StartCore(CoreIDType id); /** * Function to get map from architecture specific exception * to a protection type * @param exception * * @return */ StatusType Os_ArchGetProtectionType( uint32 exception ); /** * Function to get PCXI. Used only by Tricore * @return PCXI */ uint32 Os_GetCurrentPcxi(void); /** * Function to swap to privileged mode. * * @param pcxi - The value of PCXI */ void Os_ArchToPrivilegedMode( uint32 pcxi); /** * Check if initial stack * @return */ Std_ReturnType Os_ArchCheckStartStackMarker( void ); #endif /*ARCH_H_*/
2301_81045437/classic-platform
system/Os/rtos/inc/arch.h
C
unknown
4,218
/*-------------------------------- 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 OS_I_H_ #define OS_I_H_ #define NO_TASK_OWNER (TaskType)(~0U) #define STACK_PATTERN 0x42u /* Pattern that the stack that unused stack space is filled with */ #include "arc_assert.h" #include <stdlib.h> #include <string.h> #include <sys/queue.h> /* Forward declare most object, so we don't have to care later * Rule: In all files use the name without the "Type" and with "struct" * */ struct OsApplication; struct OsCounter; struct OsAlarm; struct OsResource; struct OsTask; struct OsTaskVar; struct Os_Sys; struct OsIsrVar; #if (OS_STATUS_EXTENDED == STD_ON ) #define OS_VALIDATE(_exp,_err) \ if( !(_exp) ) { \ Os_CallErrorHook(_err); \ return _err; \ } #define OS_VALIDATE_STD(_exp,_err,_id) \ if( !(_exp) ) { \ rv = _err; \ OS_STD_ERR(_id);\ } #define OS_VALIDATE_STD_1(_exp,_err,_id,_p1) \ if( !(_exp) ) { \ rv = _err; \ OS_STD_ERR_1(_id,_p1);\ } #define OS_VALIDATE_STD_2(_exp,_err,_id,_p1,_p2) \ if( !(_exp) ) { \ rv = _err; \ OS_STD_ERR_2(_id,_p1,_p2);\ } #define OS_VALIDATE_STD_3(_exp,_err,_id,_p1,_p2,_p3) \ if( !(_exp) ) { \ rv = _err; \ OS_STD_ERR_3(_id,_p1,_p2,_p3);\ } #else #define OS_VALIDATE(_exp,_err) #define OS_VALIDATE_STD(_exp,_err,_id) #define OS_VALIDATE_STD_1(_exp,_err,_id,_p1) #define OS_VALIDATE_STD_2(_exp,_err,_id,_p1,_p2) #define OS_VALIDATE_STD_3(_exp,_err,_id,_p1,_p2,_p3) #endif // OS_STATUS_EXTENDED #include "Std_Types.h" #include "Os.h" /* @req SWS_BSW_00005 */ #include "os_internal.h" #include "os_sys.h" #include "debug.h" #include "irq_types.h" /* "Normal" includes */ #include "os_config_macros.h" #include "alist_i.h" #include "os_resource_i.h" #include "os_application_i.h" #include "os_task_i.h" #include "os_counter_i.h" #include "os_alarm_i.h" #include "os_sched_table_i.h" #if (OS_NUM_CORES > 1) #include "os_spinlock_i.h" #endif #include "isr.h" #include "arch.h" #include "os_multicore_i.h" #include "arc.h" #include "os_mm.h" #include "os_trap.h" #if (OS_SC3 == STD_ON) || (OS_SC4 == STD_ON) #include "os_peripheral_i.h" #endif /** * Save Os internal mode flags * @return The */ static inline uint32 Os_SystemFlagsSave( uint32 newFlags ) { uint32 old = OS_SYS_PTR->osFlags; OS_SYS_PTR->osFlags = newFlags; return old; } static inline void Os_SystemFlagsRestore( uint32 oldFlags) { OS_SYS_PTR->osFlags = oldFlags; } /* Called for sequence of error hook calls in case a service * does not return with E_OK. Note that in this case the general error hook and the OS- * Application specific error hook are called. */ /** @req SWS_Os_00246 @req SWS_Os_00540 Application error hook to be called after system error hook */ static inline void Os_CallErrorHook(StatusType error) { #if (OS_ERROR_HOOK == STD_ON) uint32 flags = Os_SystemFlagsSave(SYSTEM_FLAGS_IN_OS); ErrorHook(error); Os_SystemFlagsRestore(flags); #endif OS_APP_CALL_ERRORHOOKS(error); } #if (OS_STARTUP_HOOK == STD_ON) static inline void Os_CallStartupHook( void ) { StartupHook(); } #else #define Os_CallStartupHook() #endif #if (OS_SHUTDOWN_HOOK == STD_ON) /* @CODECOV:OTHER_TEST_EXIST: Tested with SIL */ __CODE_COVERAGE_IGNORE__ static inline void Os_CallShutdownHook( StatusType error ) { ShutdownHook( error ); } #else #define Os_CallShutdownHook(_x) #endif #if (OS_PRE_TASK_HOOK == STD_ON) static inline void Os_CallPreTaskHook( void ) { /* @CODECOV:OPERATING_SYSTEM_ASSERT: check for sane values */ __CODE_COVERAGE_OFF__ ASSERT( OS_SYS_PTR->currTaskPtr->state & ST_RUNNING ); ASSERT( OS_SYS_PTR->currTaskPtr->flags == SYS_FLAG_HOOK_STATE_EXPECTING_PRE ); __CODE_COVERAGE_ON__ OS_SYS_PTR->currTaskPtr->flags = SYS_FLAG_HOOK_STATE_EXPECTING_POST; PreTaskHook(); } #else #define Os_CallPreTaskHook() #endif #if (OS_POST_TASK_HOOK == STD_ON) static inline void Os_CallPostTaskHook( void ) { /* @CODECOV:OPERATING_SYSTEM_ASSERT: check for sane values */ __CODE_COVERAGE_OFF__ ASSERT( OS_SYS_PTR->currTaskPtr->state & ST_RUNNING ); ASSERT( OS_SYS_PTR->currTaskPtr->flags == SYS_FLAG_HOOK_STATE_EXPECTING_POST ); __CODE_COVERAGE_ON__ OS_SYS_PTR->currTaskPtr->flags = SYS_FLAG_HOOK_STATE_EXPECTING_PRE; PostTaskHook(); } #else #define Os_CallPostTaskHook() #endif /** !req SWS_Os_00553 !req SWS_Os_00554 !req SWS_Os_00555 !req SWS_Os_00475 !req SWS_Os_00243 !req SWS_Os_00244 !req SWS_Os_00557 * ProtectionHook Return value is not handled */ static inline void Os_CallProtectionHook(StatusType error) { #if (OS_PROTECTION_HOOK == STD_ON) && ((OS_SC3 == STD_ON) || (OS_SC4 == STD_ON)) ProtectionReturnType rv = PRO_SHUTDOWN; uint32 flags = Os_SystemFlagsSave(SYSTEM_FLAGS_IN_OS); rv = ProtectionHook(error); Os_SystemFlagsRestore(flags); /* @CODECOV:OTHER_TEST_EXIST: Tested in SIL. In testing we want "ignore" the errors to continue testing */ __CODE_COVERAGE_IGNORE__ if( rv != PRO_IGNORE ) { /* @req SWS_Os_00556 If the ProtectionHook() returns PRO_SHUTDOWN the Operating System module shall call the ShutdownOS() */ /* @req SWS_Os_00308 If ProtectionHook() returns an invalid value, the Operating System module shall take the same action as * if no protection hook is configured.*/ ShutdownOS(error); } #else /* @req SWS_Os_00107 If no ProtectionHook() is configured and a protection error occurs, the Operating System module shall * call ShutdownOS()*/ /* @req SWS_Os_00068 If a stack fault is detected by stack monitoring AND no ProtectionHook() is configured, the Operating * System module shall call the ShutdownOS() service with the status E_OS_STACKFAULT.*/ ShutdownOS(error); #endif } #if (OS_SC3 == STD_ON) || (OS_SC4 == STD_ON) // to check the address validity of the out parameter supplied to the Os service static inline boolean Os_ValidAddressRange( uint32 addr, uint32 size ) { const OsAppConstType *aConstP = Os_ApplGetConst(GetApplicationID()); boolean rv = FALSE; /* data and bss, check dataAddr */ if( aConstP->trusted == TRUE ) { rv = TRUE; } else { /* @CODECOV:OTHER_TEST_EXIST: This code is generic but the values that come in here are aligned */ __CODE_COVERAGE_OFF__ if( ((addr >= (uint32)aConstP->dataStart ) && ( (addr+size) < (uint32)aConstP->dataEnd )) || ((addr >= (uint32)aConstP->bssStart ) && ( (addr+size) < (uint32)aConstP->bssEnd ) ) ) { rv = TRUE; } __CODE_COVERAGE_ON__ } return rv; } #endif #if (OS_USE_APPLICATIONS == STD_ON) static inline ApplicationType Os_GetCurrTaskISROwnerId (void) { ApplicationType appId; if(OS_SYS_PTR->intNestCnt == 0 ) { appId = Os_SysTaskGetCurr()->constPtr->applOwnerId; } else { appId = Os_SysIsrGetCurr()->constPtr->appOwner; } return appId; } #endif // OS_USE_APPLICATIONS == STD_ON #endif
2301_81045437/classic-platform
system/Os/rtos/inc/os_i.h
C
unknown
8,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 -----------------------------*/ #ifndef OS_MBOX_ #define OS_MBOX_ #include "Std_Types.h" /** * Datatype used by mbox */ typedef uint32 OsMBoxMsg; typedef struct { OsMBoxMsg *msgBuff; /**< @brief Pointer to mbox data */ OsMBoxMsg *putPtr; /**< @brief Put data pointer */ OsMBoxMsg *getPtr; /**< @brief Get data pointer */ OsMBoxMsg *topPtr; /**< @brief Top of the data */ uint32 maxCnt; /**< @brief Maximum number of elements */ uint32 cnt; /**< @brief Current count of the number of elements in the mbox */ OsSemType sem; /**< @brief The semaphore to used to signal/wait on the mbox. */ } OsMBoxType; /** * @breif Initialize a message box. * * @param mbox Pointer to a message box. * @param msgBuff Pointer to a buffer to hold the messages. * @param msgCnt Number of messages that the mailbox holds */ void MBoxInit( OsMBoxType *mbox, OsMBoxMsg *msgBuff, uint32 msgCnt ); /** * @brief Post a message to a message box. * * @param[in] mbox Pointer to message box. * @param[in] msg Message to post to box. * . * @retval E_OS_FULL The message box is full */ StatusType MBoxPost(OsMBoxType *mbox, OsMBoxMsg msg); /** * @brief Fetch a message from a mesasge box. * @details Will fetch a message, msg, from message box, mbox. * The timeout, tmo, set for how long we should * wait for the message. * * @param[in] mbox Pointer to mbox * @param[out] msg The message to fetch * @param[in] tmo Timeout in ticks. * TMO_MIN * . * Just check the box. If no message, * just return E_OS_TIMEOUT * . * TMO_INFINITE * Wait forever. * @retval E_OK OK * @retval E_OS_TIMEOUT Timeout * */ StatusType MBoxFetchTmo(OsMBoxType *mbox, OsMBoxMsg *msg, uint32 tmo); #endif /*OS_MBOX_*/
2301_81045437/classic-platform
system/Os/rtos/inc/os_mbox.h
C
unknown
2,993
/*-------------------------------- 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 -----------------------------*/ /** * @file os_mm.h * @brief Memory management interface for the OS * * @addtogroup os * @{ */ #ifndef OS_MM_H_ #define OS_MM_H_ #if (OS_SC3 == STD_ON) || (OS_SC4 == STD_ON) /** * @brief Initialize the the MPU/MMU. * @details This normally involves setting the MPU entries for * privileged mode. */ void Os_MMInit( void ); /** * @brief Set application MPU settings. * @param aP */ void Os_MMSetApplUserMode( const OsAppVarType *aP ); /** * @brief Set user mode for an ISR * * @param isrPtr Pointer to a task */ void Os_MMSetUserModeIsr( const OsIsrVarType *isrPtr ); /** * @brief Set user mode for a task * @param pcbPtr */ void Os_MMSetUserMode( const OsTaskVarType *pcbPtr ); /** * @brief Check if an address (addr) is in the peripheral address * range of the application * @param pcbPtr */ boolean Os_MMValidPerAddressRange( AreaIdType area, uint32 addr, uint32 size ); #endif /* defined(OS_SC3 == STD_ON) || defined(OS_SC4 == STD_ON) */ #endif /* OS_MM_H_*/ /** @} */
2301_81045437/classic-platform
system/Os/rtos/inc/os_mm.h
C
unknown
1,854
/*-------------------------------- 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 OS_PERIPHERAL_I_H_ #define OS_PERIPHERAL_I_H_ StatusType Os_ReadPeripheral8( AreaIdType Area, const uint8 * Address, uint8 * ReadValue); StatusType Os_ReadPeripheral16( AreaIdType Area, const uint16 * Address, uint16 * ReadValue); StatusType Os_ReadPeripheral32( AreaIdType Area, const uint32 * Address, uint32 * ReadValue); StatusType Os_WritePeripheral8 ( AreaIdType Area, uint8 *Address, uint8 WriteValue); StatusType Os_WritePeripheral16( AreaIdType Area, uint16 *Address, uint16 WriteValue); StatusType Os_WritePeripheral32( AreaIdType Area, uint32 *Address, uint32 WriteValue); StatusType Os_ModifyPeripheral8( AreaIdType Area, uint8 *Address, uint8 ClearMask, uint8 SetMask); StatusType Os_ModifyPeripheral16( AreaIdType Area, uint16 *Address, uint16 ClearMask, uint16 SetMask); StatusType Os_ModifyPeripheral32( AreaIdType Area, uint32 *Address, uint32 ClearMask, uint32 SetMask); #endif /*OS_PERIPHERAL_I_H_*/
2301_81045437/classic-platform
system/Os/rtos/inc/os_peripheral_i.h
C
unknown
1,823
/*-------------------------------- 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 OS_BSEM_ #define OS_BSEM_ #include "Std_Types.h" #include <sys/queue.h> #define TICK_MAX UINT_MAX typedef struct OsSem { sint32 count; STAILQ_HEAD(,OsTaskVar) taskHead; } OsSemType; #define SEM_LOCKED 0 #define SEM_UNLOCKED 1 #define BSEM_LOCKED 0 /* WaitSem() will go into WAITING state.*/ #define BSEM_UNLOCKED 1 StatusType Sleep( TickType ticks ); /** * @brief Function to initialize a semaphore * @details * @param[in] semPtr Pointer to semaphore to initialize * @param[in] initialCount Initial count of the semaohore * @return */ StatusType SemInit( OsSemType *semPtr, sint32 initialCount); /** * @brief Function that waits for a semaphore. * @details The count of the semaphore is decremented. If the count < 0 the * caller is put in WAITING state. If the scheduler is locked * (hold RES_SCHEDULER) the call will fail and returns E_NOT_OK. * * @param[in] semPtr Pointer to the semaphore to wait on. * @param[in] tmo Timeout in OS ticks. * A timeout of 0 can be used for polling the semaphore. * . * @retval E_OS_TIMEOUT */ StatusType SemWaitTmo( OsSemType *semPtr, TickType tmo ); /** * @brief Function that waits for a semaphore. * @details The count of the semaphore is decremented. If the count < 0 the * caller is put in WAITING state. If the scheduler is locked * (hold RES_SCHEDULER) the call will fail and returns E_NOT_OK. * * @param[in] semPtr Pointer to the semaphore to wait on. * . * @retval E_OS_OK */ StatusType SemWait(OsSemType *semPtr); /** * @brief Function to signal a semaphore. * * @param[in] semPtr Pointer to a semaphore. * . * @retval E_OS_VALUE The first task that waits on the semaphore * is in suspended state. * @retval E_OS_VALUE The semPtr passed was NULL_PTR. * */ StatusType SemSignal(OsSemType *semPtr); /** * @brief Function to initialize a binary semaphore. * * @param[in] semPtr Pointer to the semaphore to initialize * @param[in] initialCount BSEM_LOCKED or BSEM_UNLOCKED * @return */ static inline StatusType BSemInit( OsSemType *semPtr, sint32 initialCount) { /* 0 - locked, WaitSem() will go into WAITING state. * 1 - unlocked, WaitSem() will NOT go into WAITING state. */ ASSERT( (initialCount == BSEM_LOCKED) || (initialCount == BSEM_UNLOCKED) ); return SemInit(semPtr, initialCount ); } /** * @brief Function to wait on a binary semaphore. * * @param[in] semPtr Pointer to a semaphore * @param[in] tmo Timeout in OS ticks * . * @retval E_OK OK * @retval E_OS_TIMEOUT Timeout */ static inline StatusType BSemWaitTmo( OsSemType *semPtr, TickType tmo ) { return SemWaitTmo(semPtr,tmo); } /** * @brief Function that waits on a binray semaphore * * @param[in] semPtr Pointer to a semaphore * . * @retval E_OK OK * @retval E_OS_TIMEOUT Timeout */ static inline StatusType BSemWait( OsSemType *semPtr ) { return SemWait(semPtr); } StatusType BSemSignal( OsSemType *semPtr ); #endif /*OS_BSEM_*/
2301_81045437/classic-platform
system/Os/rtos/inc/os_sem.h
C
unknown
4,171
/*-------------------------------- 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 -----------------------------*/ /** * @file os_trap.c * @brief Internal trap interface for the OS used for OS_SC3 and OS_SC4. * * @addtogroup os * @details * @{ */ /* ----------------------------[includes]------------------------------------*/ #include "os_trap.h" #include <stdio.h> #include "os_peripheral_i.h" #include "isr.h" #if (OS_SC3 == STD_ON ) || (OS_SC4 == STD_ON ) #if defined(CFG_PPC) || defined(CFG_TMS570) extern void Os_SetPrivilegedMode( void ); #elif defined(CFG_TC2XX) extern void Os_ArchToPrivilegedMode(uint32 pcxi); #endif /* ----------------------------[private define]------------------------------*/ #ifndef ARRAY_SIZE #define ARRAY_SIZE(_x) (sizeof(_x)/sizeof((_x)[0])) #endif /* ----------------------------[private macro]-------------------------------*/ /* ----------------------------[private typedef]-----------------------------*/ struct ServiceEntry { /*lint -e970 MISRA:OTHER:type int declared outside:[MISRA 2012 Directive 4.6, advisory] */ int* (*entry)[]; uint32 cnt; }; /* ----------------------------[private function prototypes]-----------------*/ /* ----------------------------[private variables]---------------------------*/ /*lint -save -e9054 MISRA:FALSE_POSITIVE:Array dimension:[MISRA 2012 Rule 9.5, required] */ /*lint -e611 MISRA:OTHER:file inclusion:[MISRA 2004 Info, advisory] */ void * Os_ServiceList[] = { /* void and context altering functions */ [SYS_CALL_INDEX_EnterSupervisorMode] = (void *)NULL, [SYS_CALL_INDEX_ResumeAllInterrupts] = (void *)ResumeAllInterrupts , [SYS_CALL_INDEX_SuspendAllInterrupts] = (void *)SuspendAllInterrupts , [SYS_CALL_INDEX_EnableAllInterrupts] = (void *)EnableAllInterrupts , [SYS_CALL_INDEX_DisableAllInterrupts] = (void *)DisableAllInterrupts, [SYS_CALL_INDEX_ResumeOSInterrupts] = (void *)ResumeOSInterrupts , [SYS_CALL_INDEX_SuspendOSInterrupts] = (void *)SuspendOSInterrupts , /* StatusType returning functions */ [SYS_CALL_INDEX_ActivateTask] = (void *)ActivateTask, [SYS_CALL_INDEX_TerminateTask] = (void *)TerminateTask, [SYS_CALL_INDEX_ChainTask] = (void *)ChainTask, [SYS_CALL_INDEX_Schedule] = (void *)Schedule, [SYS_CALL_INDEX_GetTaskID] = (void *)GetTaskID, [SYS_CALL_INDEX_GetResource] = (void *)GetResource, [SYS_CALL_INDEX_ReleaseResource] = (void *)ReleaseResource, [SYS_CALL_INDEX_SetEvent] = (void *)SetEvent, [SYS_CALL_INDEX_ClearEvent] = (void *)ClearEvent, [SYS_CALL_INDEX_GetEvent] = (void *)GetEvent, [SYS_CALL_INDEX_WaitEvent] = (void *)WaitEvent, #if (OS_ALARM_CNT != 0) [SYS_CALL_INDEX_GetAlarmBase] = (void *)GetAlarmBase, [SYS_CALL_INDEX_GetAlarm] = (void *)GetAlarm, [SYS_CALL_INDEX_SetRelAlarm] = (void *)SetRelAlarm, [SYS_CALL_INDEX_SetAbsAlarm] = (void *)SetAbsAlarm, [SYS_CALL_INDEX_CancelAlarm] = (void *)CancelAlarm, #endif [SYS_CALL_INDEX_StartOS] = (void *)StartOS, [SYS_CALL_INDEX_ShutdownOS] = (void *)ShutdownOS, [SYS_CALL_INDEX_GetTaskState] = (void *)GetTaskState, #if ( OS_SC3 == STD_ON ) || ( OS_SC4 == STD_ON ) [SYS_CALL_INDEX_GetApplicationID] = (void *)GetApplicationID, #endif [SYS_CALL_INDEX_GetISRID] = (void *)GetISRID, [SYS_CALL_INDEX_CheckISRMemoryAccess] = (void *)CheckISRMemoryAccess, [SYS_CALL_INDEX_CheckTaskMemoryAccess] = (void *)CheckTaskMemoryAccess, #if ( OS_SC3 == STD_ON ) || ( OS_SC4 == STD_ON ) [SYS_CALL_INDEX_CheckObjectAccess] = (void *)CheckObjectAccess, #endif [SYS_CALL_INDEX_CheckObjectOwnership] = (void *)CheckObjectOwnership, [SYS_CALL_INDEX_StartScheduleTableRel] = (void *)StartScheduleTableRel, [SYS_CALL_INDEX_StartScheduleTableAbs] = (void *)StartScheduleTableAbs, [SYS_CALL_INDEX_StopScheduleTable] = (void *)StopScheduleTable, [SYS_CALL_INDEX_NextScheduleTable] = (void *)NextScheduleTable, #if ( OS_SC2 == STD_ON ) || ( OS_SC4 == STD_ON ) [SYS_CALL_INDEX_StartScheduleTableSynchron] = (void *)StartScheduleTableSynchron, [SYS_CALL_INDEX_SyncScheduleTable] = (void *)SyncScheduleTable, [SYS_CALL_INDEX_SetScheduleTableAsync] = (void *)SetScheduleTableAsync, #endif [SYS_CALL_INDEX_GetScheduleTableStatus] = (void *)GetScheduleTableStatus, [SYS_CALL_INDEX_IncrementCounter] = (void *)IncrementCounter, [SYS_CALL_INDEX_GetCounterValue] = (void *)GetCounterValue, [SYS_CALL_INDEX_GetElapsedValue] = (void *)GetElapsedValue, [SYS_CALL_INDEX_ReadPeripheral8] = (void *)Os_ReadPeripheral8, [SYS_CALL_INDEX_ReadPeripheral16] = (void *)Os_ReadPeripheral16, [SYS_CALL_INDEX_ReadPeripheral32] = (void *)Os_ReadPeripheral32, [SYS_CALL_INDEX_WritePeripheral8] = (void *)Os_WritePeripheral8, [SYS_CALL_INDEX_WritePeripheral16] = (void *)Os_WritePeripheral16, [SYS_CALL_INDEX_WritePeripheral32] = (void *)Os_WritePeripheral32, [SYS_CALL_INDEX_ModifyPeripheral8] = (void *)Os_ModifyPeripheral8, [SYS_CALL_INDEX_ModifyPeripheral16] = (void *)Os_ModifyPeripheral16, [SYS_CALL_INDEX_ModifyPeripheral32] = (void *)Os_ModifyPeripheral32, /* Clib functions */ [SYS_CALL_INDEX_write] = (void *)write , }; /*lint -e611 MISRA:FALSE_POSITIVE:Array dimension:[MISRA 2004 Info, advisory] */ /*lint -e9054 MISRA:FALSE_POSITIVE:Array dimension:[MISRA 2012 Rule 9.5, required] */ const void * Os_TrapList[] = { #if defined(CFG_PPC) || defined(CFG_TMS570) [0] = (void *)Os_SetPrivilegedMode, /* ASM call */ [1] = (void *)NULL, #else [0] = (void *)NULL, /* ASM call */ [1] = (void *)Os_ArchToPrivilegedMode, #endif [2] = (void *)Irq_GenerateSoftInt, #if defined(CFG_TMS570) [3] = (void *)Irq_AckSoftInt, #endif [4] = (void *)Os_IsrAdd, }; /*lint -esym(9003, Os_GblServiceList) MISRA:OTHER:Readability:[MISRA 2012 Rule 8.9, advisory] */ #if defined(CFG_QTST_TRAP) #define QTST_TRAP_IMPL #include "qtst_trap.h" #endif #if defined(CFG_SAFETY_PLATFORM) && defined(CFG_TMS570) && defined(USE_FLS) #define FLS_TMS570_TRAP_IMPL #include "Fls_tms570_trap.h" #endif const struct ServiceEntry Os_GblServiceList[] = { { (void *)Os_ServiceList, SYS_CALL_CNT, }, { (void *)Os_TrapList, ARRAY_SIZE(Os_TrapList), }, #if defined(CFG_QTST_TRAP) [ OS_TRAP_QTST_IDX ] = { (void *)QTst_TrapList, ARRAY_SIZE(QTst_TrapList), }, #endif #if defined(CFG_SAFETY_PLATFORM) && defined(CFG_TMS570) && defined(USE_FLS) [ OS_TRAP_FLS_IDX ] = { (void *)Fls_tms570_TrapList, ARRAY_SIZE(Fls_tms570_TrapList), }, #endif }; /*lint -restore */ /* ----------------------------[private functions]---------------------------*/ /* ----------------------------[public functions]----------------------------*/ #if defined(CFG_TMS570) void * Os_GetService( uint32 idx ) { uint32 tIdx = (idx >> 16u); uint32 sIdx = idx & 0xffffu; const struct ServiceEntry *se = &Os_GblServiceList[tIdx]; ASSERT( (sIdx < se->cnt) && (tIdx < ARRAY_SIZE(Os_GblServiceList)) ); return(*(se->entry))[sIdx]; } #endif #endif /* (OS_SC3 == STD_ON ) || (OS_SC4 == STD_ON ) */ /** @} */
2301_81045437/classic-platform
system/Os/rtos/integration/os_trap.c
C
unknown
8,255
/*-------------------------------- 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 OS_TRAP_H_ #define OS_TRAP_H_ /** * @file os_trap.h * @brief Internal trap interface for the OS used for OS_SC3 and OS_SC4. * The intended use is to give supervisor access to the configured APIs * * @addtogroup os * @details * @{ */ /* ----------------------------[includes]------------------------------------*/ #include "Os.h" #include "irq.h" /* ----------------------------[private define]------------------------------*/ #if (OS_SC3 == STD_ON ) || (OS_SC4 == STD_ON ) /* * In order to separate the different traps from each other the index is * split into two 16-bits fields: * * 3 2 1 * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 * | Trap Index | Service Index | * * * Prefix Trap Index * ------------------------------------------- * SYS_CALL_ 0 * OS_TRAP_ 1 * * */ #define OS_TRAP_QTST_IDX 2 #define OS_TRAP_FLS_IDX 3 #define OS_TRAP_OS_IDX 1u #define OS_TRAP_OS_IDX_SHIFTED (OS_TRAP_OS_IDX << 16u) /* Index to trap functions */ #if defined(CFG_PPC) || defined(CFG_TMS570) #define OS_TRAP_INDEX_Os_SetPrivilegedMode (0u + OS_TRAP_OS_IDX_SHIFTED) #define OS_TRAP_INDEX_Irq_GenerateSoftInt (2u + OS_TRAP_OS_IDX_SHIFTED) #define OS_TRAP_INDEX_Irq_AckSoftInt (3u + OS_TRAP_OS_IDX_SHIFTED) #define OS_TRAP_INDEX_Os_IsrAdd (4u + OS_TRAP_OS_IDX_SHIFTED) #else #define OS_TRAP_INDEX_Reserved (0UL) #define OS_TRAP_INDEX_Os_ArchToPrivilegedMode (-1UL) #define OS_TRAP_INDEX_Irq_GenerateSoftInt (-2UL) #define OS_TRAP_INDEX_Os_IsrAdd (-3UL) #endif /* ----------------------------[public define]------------------------------*/ /* OS trap internal functions */ #define OS_TRAP_Irq_GenerateSoftInt(_a1) SYS_CALL_1( OS_TRAP_INDEX_Irq_GenerateSoftInt,_a1 ) #define OS_TRAP_Irq_AckSoftInt(_a1) SYS_CALL_1( OS_TRAP_INDEX_Irq_AckSoftInt,_a1 ) /* PPC */ #if defined(CFG_PPC) || defined(CFG_TMS570) #define OS_TRAP_Os_SetPrivilegedMode(_a1) SYS_CALL_0( OS_TRAP_INDEX_Os_SetPrivilegedMode ) #elif defined(CFG_TC2XX) #define OS_TRAP_Os_ArchToPrivilegedMode(_a1) SYS_CALL_1( OS_TRAP_INDEX_Os_ArchToPrivilegedMode, _a1) #endif #define OS_TRAP_Os_IsrAdd(_a1) SYS_CALL_1( OS_TRAP_INDEX_Os_IsrAdd, _a1) #else /* for OS_SC1 or OS_SC2 */ #define OS_TRAP_Irq_GenerateSoftInt Irq_GenerateSoftInt #define OS_TRAP_Irq_AckSoftInt Irq_AckSoftInt #define OS_TRAP_Os_IsrAdd Os_IsrAdd #if defined(CFG_PPC) #define OS_TRAP_Os_SetPrivilegedMode(_a1) #endif // CFG_PPC #if defined(CFG_TC2XX) #define OS_TRAP_Os_ArchToPrivilegedMode(_a1) #endif // CFG_TC2XX #if defined(CFG_TMS570) #define OS_TRAP_Os_ArchToPrivilegedMode() #if defined(USE_WDG) #define OS_TRAP_Wdg_Hw_KickWdg Wdg_Hw_KickWdg #define OS_TRAP_Wdg_Hw_SetTriggerCondition Wdg_Hw_SetTriggerCondition #endif // USE_WDG #endif // CFG_TMS570 #define OS_TRAP_Mcu_Hw_PerformReset Mcu_Hw_PerformReset #endif /* (OS_SC3 == STD_ON ) || (OS_SC4 == STD_ON ) */ /* ----------------------------[private macro]-------------------------------*/ /* ----------------------------[private typedef]-----------------------------*/ /* ----------------------------[private function prototypes]-----------------*/ /* ----------------------------[private variables]---------------------------*/ /* ----------------------------[private functions]---------------------------*/ /* ----------------------------[public functions]----------------------------*/ /** @} */ #endif
2301_81045437/classic-platform
system/Os/rtos/integration/os_trap.h
C
unknown
4,599
OS_INC=Os/rtos/inc OS_SRC=Os/rtos/src OS_INTEGRATION=Os/rtos/integration #vpath-y += $(ARCH_KERNEL_PATH-y)/kernel #obj-y += asm_sample.o #CFLAGS_asm_sample.o += -O3 obj-y += arch_krn.o obj-$(CFG_HC1X) += arch_irq.o # object files obj-y += os_event.o obj-y += os_init.o obj-y += arch.o obj-y += os_task.o obj-y += os_resource.o obj-y += os_alarm.o obj-y += os_sched_table.o obj-y += os_counter.o obj-y += $(if $(CFG_TRAVEO_S6J328C),sys_tick_traveo.o,sys_tick.o) obj-y += os_isr.o obj-y += os_application.o obj-y += os_panic.o obj-y += os_trap.o obj-y += os_peripheral.o obj-$(CFG_MULTICORE) += os_spinlock.o obj-$(CFG_MULTICORE) += os_multicore.o obj-$(CFG_KERNEL_EXTRA) += os_sleep.o obj-$(CFG_KERNEL_EXTRA) += os_sem.o obj-$(CFG_KERNEL_EXTRA) += os_mbox.o # These are VERY cpu dependent.. remove #obj-y += int_ctrl.o obj-y += $(if $(CFG_TRAVEO_S6J328C),irq_traveo.o,irq.o) # We are compiling the kernel dep-$(CFG_PPC) += arch_offset.h dep-y += asm_offset.h #dep-y += kernel_offset.h dep-$(CFG_ARM_CM4) += arch_offset.h dep-$(CFG_ARM_CM3) += arch_offset.h dep-$(CFG_ARM_CR4) += arch_offset.h dep-$(CFG_ARM_CR5) += arch_offset.h dep-$(CFG_TC2XX) += arch_offset.h ifeq ($(COMPILER),gcc) # ARM assembler generates "define STACK_APA $12". The extra '$' we want to go. # Assembler offsets %_offset.h: %_offset.c @echo " >> generating $@ from $<" $(Q)$(CC_PRE)$(CC) -S $(CFLAGS) -o $(@:.h=.s) $(addprefix -I,$(inc-y)) $(addprefix -D,$(def-y)) $< $(Q)gawk '/.*define/ { print $$1 " " $$2 " " gensub("#","","g",$$3) }' $(@:.h=.s) > $@ # Assembler offsets asm_offset.h: asm_offset.c @echo " >> asm offset gen $<" $(Q)$(CC_PRE)$(CC) -S $(CFLAGS) -o $(@:.h=.s) $(addprefix -I,$(inc-y)) $(addprefix -D,$(def-y)) $< @$(SED) -e "/#define/!d" -e "s/#//2g" $(@:.h=.s) > $@ @rm $(@:.h=.s) endif ifeq ($(COMPILER),ghs) # ARM assembler generates "define STACK_APA $12". The extra '$' we want to go. # Assembler offsets %_offset.h: %_offset.c @echo " >> generating $@ from $<" $(Q)$(CC) -S $(filter-out -c -dwarf2,$(CFLAGS)) -o $(@:.h=.s) $(addprefix -I,$(inc-y)) $(addprefix -D,$(def-y)) $< $(Q)gawk '/.*define/ { print $$1 " " $$2 " " gensub("#","","g",$$3) }' $(@:.h=.s) > $@ # Assembler offsets asm_offset.h: asm_offset.c @echo " >> asm offset gen $<" $(Q)$(CC) -S $(filter-out -c -dwarf2,$(CFLAGS)) -o $(@:.h=.s) $(addprefix -I,$(inc-y)) $(addprefix -D,$(def-y)) $< @$(SED) -e "/#define/!d" -e "s/#//2g" $(@:.h=.s) > $@ @rm $(@:.h=.s) endif # sed -n '/apa.*/ {h;n;s/q://;x;s/^/#define /;s/$//;x;p}' bepa.c # gawk '/apa/ { var=$0;getline tjo;print "#define " var tjo}' bepa.c # $ gawk '/^arc_dummy/ { va=gensub(/arc_dummy_(.*):.*/,"\\1",$0);getline;printf " #define %-30s %s\n",va,$2 }' asm_offset.h ifeq ($(COMPILER),iar) %_offset.h: %_offset.c @echo " >> generating $@ from $<" $(CC) -lB $@_ $(CFLAGS) $(addprefix -I,$(inc-y)) $(addprefix -D,$(def-y)) $< -o $@__ $(Q)gawk '/^arc_dummy/ { va=gensub(/arc_dummy_(.*):.*/,"\\1",$$0);getline;printf "#define %-30s %s\n",va,$$2 }' $@_ > $@ $(Q)rm $@_ $@__ #$(subst .h,.r12,$@) # $ sed -n "/arc_dummy/ {n;s/q://p}" bepa.c # exit 0 endif #--preprocess=c ifeq ($(COMPILER),diab) # assembler generates this: # arc_dummy_EXC_FRM_SRR1: # .long 16 # # we want the size (16) and the name after arc_dummy # assembler offsets %_offset.h: %_offset.c @echo " >> generating $@ from $<" $(Q)$(CC) -S -Xpreprocess-assembly $(CFLAGS) -o $(@:.h=.s) $(addprefix -I,$(inc-y)) $(addprefix -D,$(def-y)) $< $(Q)gawk 'BEGIN { RS = "arc_dummy_"; FS = ":"} match($$2, /long\t+([0-9]+)/, ary) \ {gsub("\\t", " ",$$1); print ("#define " $$1 " " ary[1]) }' $(@:.h=.s) > $@ endif ifeq ($(COMPILER),cw) # The "\r" in the awk is a little strange...sed and awk if that does not work # sed -e '/.apa/!d' -e '/OBJ/!d' -e 's/\[//' 123.tmp | gawk '{ print "#define " $9 " " $4 }' %_offset.h: %_offset.c @echo " >> generating $@ from $<" # $(Q)$(CC) -dis $(CFLAGS) $(addprefix -I,$(inc-y)) $(addprefix -D,$(def-y)) $< $(Q)$(CC) -dis $(CFLAGS) $(addprefix -I,$(inc-y)) $(addprefix -D,$(def-y)) $< > 123.tmp $(Q)gawk '$$9 ~/.apa/ && $$0 ~/OBJ/ { gsub(/\r/,""); printf("#define %s %d\n",$$10,$$5-100) }' 123.tmp > $@ endif ifeq ($(COMPILER),armcc) # Assembler offsets asm_offset.h: asm_offset.c @echo " >> asm offset gen $<" $(Q)$(CC) -S --preprocess_assembly $(CFLAGS) -o $(@:.h=.s) $(addprefix -I,$(inc-y)) $(addprefix -D,$(def-y)) $< $(Q)gawk 'BEGIN { RS="[\r]*\n" } /^arc_dummy_(.*)/ { var=gensub(/arc_dummy_/,"","g",$$1); getline; offset=$$2; printf "#define %s %s\n", var, offset }' $(@:.h=.s) > $@ @rm $(@:.h=.s) endif VPATH += $(ROOTDIR)/system/$(OS_SRC) inc-y += $(ROOTDIR)/system/$(OS_INC) inc-y += $(ROOTDIR)/system/$(OS_SRC) inc-y += $(ROOTDIR)/system/$(OS_INTEGRATION) VPATH += $(ROOTDIR)/system/Os/rtos/integration VPATH += $(ROOTDIR)/system/Os inc-y += $(ROOTDIR)/system/Os/include VPATH += $(ROOTDIR)/$(OSAL_ARCH)/$(ARCH_FAM)/$(ARCH)/kernel VPATH += $(ROOTDIR)/mcal/arch/$(ARCH)/src/integration VPATH += $(ROOTDIR)/mcal/arch/$(ARCH)/src inc-y += . inc-y += $(ROOTDIR)/$(OSAL_ARCH)/$(ARCH_FAM)/$(ARCH)/kernel inc-y += $(ROOTDIR)/arch/$(ARCH_FAM)/$(ARCH)/drivers inc-y += $(ROOTDIR)/$(OSAL_ARCH)/$(ARCH) inc-y += $(ROOTDIR)/include/$(ARCH_FAM) inc-y += $(ROOTDIR)/mcal/arch/$(ARCH) inc-y += $(ROOTDIR)/mcal/arch/$(ARCH)/src
2301_81045437/classic-platform
system/Os/rtos/makefile
Makefile
unknown
5,490
/*-------------------------------- 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 -----------------------------*/ /* A steal in an idea from * http://blogs.sun.com/nickstephen/entry/some_assembly_required_-_down * According to blog original BSD license.. * * Generate assembler from this file( -S option for GNU ). * extract the "#defines" with some tool e.g. "sed -n '/#define/p' <asm_file>" */ #define restrict #include "os_i.h" #if defined(__GNUC__) || defined(__ghs__) /* For ARM this will generate to #define APA #12 */ #define DECLARE(sym,val) \ __asm("#define\t" #sym "\t%0" : : "n" ((val))) void asm_foo(void) { #elif defined(__CWCC__) #define DECLARE(_var,_offset) \ __declspec(section ".apa") char_t _var[100+ (_offset)] #pragma section ".apa" ".apa" #elif (defined(__DCC__)) || defined(__ARMCC_VERSION) #define DECLARE(_sym,_val) \ const sint32 arc_dummy_ ## _sym = _val #else #define DECLARE(_sym,_val) const sint32 arc_dummy_ ## _sym = _val #endif DECLARE(PCB_STACK_CURR_P, offsetof(OsTaskVarType, stack)); DECLARE(PCB_CONST_P, offsetof(OsTaskVarType, constPtr)); DECLARE(PCB_REGS, offsetof(OsTaskVarType, regs)); DECLARE(SYS_CURR_PCB_P, offsetof(Os_SysType, currTaskPtr)); DECLARE(SYS_INT_NEST_CNT, offsetof(Os_SysType, intNestCnt)); DECLARE(SYS_INT_STACK, offsetof(Os_SysType, intStack)); DECLARE(SYS_SIZE, sizeof(Os_SysType)); #if (OS_SC3 == STD_ON ) || (OS_SC4 == STD_ON ) DECLARE(APP_INT_NEST_CNT, offsetof(OsAppVarType, nestCnt)); DECLARE(APP_INT_STACK, offsetof(OsAppVarType, intStack)); DECLARE(APP_SAVED_INT_STACK, offsetof(OsAppVarType, savedIntStack)); #endif #if defined(__GNUC__) || defined(__ghs__) } #endif
2301_81045437/classic-platform
system/Os/rtos/src/asm_offset.c
C
unknown
2,412
/*-------------------------------- 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 -----------------------------*/ /* * Just a sample file to generate some assembler constructs if you are * really bad at it. * * Add it to makefile and then examin it with objdump. * * Example: * ${CROSS_COMPILE}objdump -S system/kernel/obj_et_stm32_stamp/asm_sample.o * */ #include "Os.h" void apa(void *); void interrupt(void) __attribute__((__interrupt__)); void interrupt( void ) { // apa((void *)0x123); } void func1( int a ) { (void)a; } uint32_t func3( int a ) { if( a == 0) { return 5; } return (*(uint32_t *)0xE000ED04 ) & 0x1f7; } int func2( void ) { int a; a = 3; func1(5); func3(0); return 2; } void func( void ) { func2(); }
2301_81045437/classic-platform
system/Os/rtos/src/asm_sample.c
C
unknown
1,487
/*-------------------------------- 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 "os_i.h" #if defined(__GNUC__) #define DECLARE(sym,val) \ __asm("#define " #sym " %0" : : "i" ((val))) void oil_foo(void) { /* PCB */ #elif defined(__CWCC__) #define DECLARE(_var,_offset) \ __declspec(section ".apa") char _var[100+(_offset)] #pragma section ".apa" ".apa" #endif DECLARE(PCB_T_SIZE, sizeof(OsTaskVarType)); DECLARE(PCB_STACK_CURR_P, offsetof(OsTaskVarType, stack)); DECLARE(PCB_ENTRY_P, offsetof(OsTaskVarType, entry)); DECLARE(SYS_CURR_PCB_P, offsetof(Os_SysType, currTaskPtr)); DECLARE(SYS_INT_NEST_CNT, offsetof(Os_SysType, intNestCnt)); DECLARE(SYS_INT_STACK, offsetof(Os_SysType, intStack)); #if defined(__GNUC__) } #endif
2301_81045437/classic-platform
system/Os/rtos/src/kernel_offset.c
C
unknown
1,488
/*-------------------------------- 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 */ /* ----------------------------[includes]------------------------------------*/ #include "os_i.h" /* ----------------------------[private define]------------------------------*/ #if (OS_ALARM_CNT!=0) /* ----------------------------[private macro]-------------------------------*/ #define COUNTER_MAX(x) (x)->counter->alarm_base.maxallowedvalue #define COUNTER_MIN_CYCLE(x) (x)->counter->alarm_base.mincycle static inline StatusType Os_AlarmCheckCycle(TickType cycle, const OsAlarmType *aPtr) { StatusType status = E_OK; if( (cycle != 0) && ( (cycle < COUNTER_MIN_CYCLE(aPtr)) || (cycle > COUNTER_MAX(aPtr)) ) ) { status = E_OS_VALUE; } return status; } #define ALARM_CHECK_ID(x) ((x) < OS_ALARM_CNT) /* ----------------------------[private typedef]-----------------------------*/ /* ----------------------------[private function prototypes]-----------------*/ /* ----------------------------[private variables]---------------------------*/ /* ----------------------------[private functions]---------------------------*/ /* * Checks if the given alarm has expired, if so sets it to inactive. * Otherwise calculate a new expiration time */ static void AlarmProcess( OsAlarmType *aPtr ) { if( aPtr->cycletime == 0 ) { aPtr->active = 0; } else { // Calc new expire value.. aPtr->expire_val = Os_CounterAdd( Os_CounterGetValue(aPtr->counter), Os_CounterGetMaxValue(aPtr->counter), aPtr->cycletime); } } /** * Os_internalSetRelAlarm: Handles setting of relative alarm both for API and at startup * Difference between SetRelAlarm API and SetRelAlarm at startup; no * interrupt check is available (i.e. SWS_Os_00093) * * @param AlarmId Reference to alarm * @param Increment Relative value in ticks * @param Cycle Referenced alarm's cycle time in ticks * @param isStartup is FALSE when called from API, TRUE at startup * @return Error code */ static StatusType Os_internalSetRelAlarm(AlarmType AlarmId, TickType Increment, TickType Cycle, boolean isStartup){ StatusType rv = E_OK; imask_t flags; OsAlarmType *aPtr; /* Validation of parameters, if it fails, function will return */ /* This is not inline with Table 8, ISO26262-6:2011, Req 1a and 1h */ if ((boolean)FALSE == isStartup) { OS_VALIDATE_STD_3( (Os_SysIntAnyDisabled() == FALSE) , E_OS_DISABLEDINT, OSServiceId_SetRelAlarm,AlarmId, Increment, Cycle); /* @req SWS_Os_00093 */ } OS_VALIDATE_STD_3( ALARM_CHECK_ID(AlarmId), E_OS_ID, OSServiceId_SetRelAlarm,AlarmId, Increment, Cycle); /* @req OSEK_SWS_AL_00009 */ aPtr = Os_AlarmGet(AlarmId); /* @req OSEK_SWS_AL_00013 */ OS_DEBUG(D_ALARM,"SetRelAlarm id:%d inc:%u cycle:%u\n", AlarmId, (unsigned)Increment, (unsigned)Cycle); #if (OS_SC3==STD_ON) || (OS_SC4==STD_ON) const OsTaskVarType *currPcbPtr = Os_SysTaskGetCurr(); // Checking state and access of alarm only done when called from API, not startup. if( ((boolean)FALSE == isStartup) && (currPcbPtr->constPtr->applOwnerId != aPtr->applOwnerId) ) { ApplicationType appId; OS_VALIDATE_STD_3( (Os_ApplCheckState(aPtr->applOwnerId) != E_OS_ACCESS) , E_OS_ACCESS, OSServiceId_SetRelAlarm,AlarmId, Increment, Cycle); appId = Os_GetCurrTaskISROwnerId(); OS_VALIDATE_STD_3( (Os_ApplCheckAccess(appId, aPtr->accessingApplMask) != E_OS_ACCESS) , E_OS_ACCESS, OSServiceId_SetRelAlarm,AlarmId, Increment, Cycle); #if (OS_NUM_CORES > 1) if (Os_ApplGetCore(aPtr->applOwnerId) != GetCoreID()) { StatusType status = Os_NotifyCore(Os_ApplGetCore(aPtr->applOwnerId), OSServiceId_SetRelAlarm, AlarmId, Increment, Cycle); return status; } #endif } #endif /** @req SWS_Os_00304 */ OS_VALIDATE_STD_3( !((Increment == 0) || (Increment > COUNTER_MAX(aPtr))), E_OS_VALUE, OSServiceId_SetRelAlarm,AlarmId, Increment, Cycle); /* @req OSEK_SWS_AL_00011 */ OS_VALIDATE_STD_3( (Os_AlarmCheckCycle(Cycle, aPtr) != E_OS_VALUE) , E_OS_VALUE, OSServiceId_SetRelAlarm,AlarmId, Increment, Cycle); /* @req OSEK_SWS_AL_00012 */ Irq_Save(flags); if( aPtr->active == 1 ) { Irq_Restore(flags); rv = E_OS_STATE; /* @req OSEK_SWS_AL_00010 */ /* OS_STD_ERR_3: Function will return after calling ErrorHook */ /* This is not inline with Table 8, ISO26262-6:2011, Req 1a and 1h */ OS_STD_ERR_3(OSServiceId_SetRelAlarm,AlarmId, Increment, Cycle); } aPtr->active = 1; aPtr->expire_val = Os_CounterAdd( Os_CounterGetValue(aPtr->counter), COUNTER_MAX(aPtr), Increment); aPtr->cycletime = Cycle; Irq_Restore(flags); OS_DEBUG(D_ALARM," expire:%u cycle:%u\n", (unsigned)aPtr->expire_val, (unsigned)aPtr->cycletime); return rv; } /** * Os_internalSetAbsAlarm: Handles setting of absolute alarm both for API and at startup * Difference between SetAbsAlarm API and SetAbsAlarm at startup; no * interrupt check is available (i.e. SWS_Os_00093) * * @param AlarmId Reference to alarm * @param Start Tick value when the alarm expires for the first time * @param Cycle Referenced alarm's cycle time in ticks * @param isStartup is FALSE when called from API, TRUE at startup * @return Error code */ static StatusType Os_internalSetAbsAlarm(AlarmType AlarmId, TickType Start, TickType Cycle, boolean isStartup) { imask_t flags; StatusType rv = E_OK; OsAlarmType *aPtr; /* Validation of parameters, if it fails, function will return */ /* This is not inline with Table 8, ISO26262-6:2011, Req 1a and 1h */ if ((boolean)FALSE == isStartup) { OS_VALIDATE_STD_3( (Os_SysIntAnyDisabled() == FALSE) , E_OS_DISABLEDINT, OSServiceId_SetAbsAlarm,AlarmId, Start, Cycle); /* @req SWS_Os_00093 */ } OS_VALIDATE_STD_3( ALARM_CHECK_ID(AlarmId), E_OS_ID, OSServiceId_SetAbsAlarm,AlarmId, Start, Cycle); /* @req OSEK_SWS_AL_00015 */ aPtr = Os_AlarmGet(AlarmId); /* @req OSEK_SWS_AL_00019 */ #if (OS_SC3==STD_ON) || (OS_SC4==STD_ON) const OsTaskVarType *currPcbPtr = Os_SysTaskGetCurr(); // Checking state and access of alarm only done when called from API, not startup. if( (((boolean)FALSE == isStartup)) && (currPcbPtr->constPtr->applOwnerId != aPtr->applOwnerId)) { ApplicationType appId; OS_VALIDATE_STD_3( (Os_ApplCheckState(aPtr->applOwnerId) != E_OS_ACCESS) , E_OS_ACCESS, OSServiceId_SetAbsAlarm,AlarmId, Start, Cycle); appId = Os_GetCurrTaskISROwnerId(); OS_VALIDATE_STD_3( (Os_ApplCheckAccess(appId, aPtr->accessingApplMask) != E_OS_ACCESS) , E_OS_ACCESS, OSServiceId_SetAbsAlarm,AlarmId, Start, Cycle); #if (OS_NUM_CORES > 1) if (Os_ApplGetCore(aPtr->applOwnerId) != GetCoreID()) { StatusType status = Os_NotifyCore(Os_ApplGetCore(aPtr->applOwnerId), OSServiceId_SetAbsAlarm, AlarmId, Start, Cycle); return status; } #endif } #endif /** @req SWS_Os_00304 */ OS_VALIDATE_STD_3( !(Start > COUNTER_MAX(aPtr)), E_OS_VALUE, OSServiceId_SetAbsAlarm,AlarmId, Start, Cycle); /* @req OSEK_SWS_AL_00017 */ OS_VALIDATE_STD_3( (Os_AlarmCheckCycle(Cycle, aPtr) != E_OS_VALUE) , E_OS_VALUE, OSServiceId_SetAbsAlarm,AlarmId, Start, Cycle); /* @req OSEK_SWS_AL_00018 */ Irq_Save(flags); if( aPtr->active == 1 ) { rv = E_OS_STATE; /* @req OSEK_SWS_AL_00016 */ Irq_Restore(flags); /* OS_STD_ERR_3: Function will return after calling ErrorHook */ /* This is not inline with Table 8, ISO26262-6:2011, Req 1a and 1h */ OS_STD_ERR_3(OSServiceId_SetAbsAlarm,AlarmId, Start, Cycle); } aPtr->active = 1; aPtr->expire_val = Start; aPtr->cycletime = Cycle; Irq_Restore(flags); OS_DEBUG(D_ALARM," expire:%u cycle:%u\n", (unsigned)aPtr->expire_val, (unsigned)aPtr->cycletime); return rv; } /* ----------------------------[public functions]----------------------------*/ /** * The system service GetAlarmBase reads the alarm base * characteristics. The return value <Info> is a structure in which * the information of data type AlarmBaseType is stored. * * @param alarm_id Reference to alarm * @param info Reference to structure with constants of the alarm base. * @return */ /*@req OSEK_SWS_AL_00001*/ StatusType GetAlarmBase( AlarmType AlarmId, AlarmBaseRefType Info ) { StatusType rv = E_OK; /* Validation of parameters, if it fails, function will return */ /* This is not inline with Table 8, ISO26262-6:2011, Req 1a and 1h */ OS_VALIDATE_STD_2( (Info != NULL_PTR), E_OS_PARAM_POINTER, OSServiceId_GetAlarmBase,AlarmId, Info); /* @req SWS_Os_00566 */ #if (OS_SC3==STD_ON) || (OS_SC4==STD_ON) OS_VALIDATE_STD_2( (OS_VALIDATE_ADDRESS_RANGE(Info,sizeof(AlarmBaseType)) == TRUE ) , E_OS_ILLEGAL_ADDRESS , OSServiceId_GetAlarmBase,AlarmId, Info); /*@req SWS_Os_00051 */ #endif OS_VALIDATE_STD_2( (Os_SysIntAnyDisabled() == FALSE) , E_OS_DISABLEDINT, OSServiceId_GetAlarmBase,AlarmId, Info); /* @req SWS_Os_00093 */ OS_VALIDATE_STD_2( ALARM_CHECK_ID(AlarmId), E_OS_ID, OSServiceId_GetAlarmBase,AlarmId, Info); /* @req OSEK_SWS_AL_00002 */ #if (OS_SC3==STD_ON) || (OS_SC4==STD_ON) const OsTaskVarType *currPcbPtr = Os_SysTaskGetCurr(); const OsAlarmType *aPtr = Os_AlarmGet(AlarmId); if( currPcbPtr->constPtr->applOwnerId != aPtr->applOwnerId ) { ApplicationType appId; OS_VALIDATE_STD_2( (Os_ApplCheckState(aPtr->applOwnerId) != E_OS_ACCESS) , E_OS_ACCESS, OSServiceId_GetAlarmBase,AlarmId, Info); appId = Os_GetCurrTaskISROwnerId(); OS_VALIDATE_STD_2( (Os_ApplCheckAccess(appId, aPtr->accessingApplMask) != E_OS_ACCESS) , E_OS_ACCESS, OSServiceId_GetAlarmBase,AlarmId, Info); #if (OS_NUM_CORES > 1) if (Os_ApplGetCore(aPtr->applOwnerId) != GetCoreID()) { StatusType status = Os_NotifyCore(Os_ApplGetCore(aPtr->applOwnerId), OSServiceId_GetAlarmBase, AlarmId, (uint32)Info, 0); return status; } #endif } #endif /* @req OSEK_SWS_AL_00003 */ *Info = alarm_list[AlarmId].counter->alarm_base; return rv; } /** * The system service GetAlarm returns the relative value in ticks * before the alarm <AlarmID> expires. * @param AlarmId Reference to an alarm * @param Tick[out] Relative value in ticks before the alarm <AlarmID> expires. * @return */ /* @req OSEK_SWS_AL_00004 */ StatusType GetAlarm(AlarmType AlarmId, TickRefType Tick) { StatusType rv = E_OK; imask_t flags; const OsAlarmType *aPtr; /* Validation of parameters, if it fails, function will return */ /* This is not inline with Table 8, ISO26262-6:2011, Req 1a and 1h */ OS_VALIDATE_STD_2( (Tick != NULL_PTR), E_OS_PARAM_POINTER, OSServiceId_GetAlarm,AlarmId, Tick); /* @req SWS_Os_00566 */ #if (OS_SC3==STD_ON) || (OS_SC4==STD_ON) OS_VALIDATE_STD_2( (OS_VALIDATE_ADDRESS_RANGE(Tick, sizeof(TickType) ) == TRUE ) , E_OS_ILLEGAL_ADDRESS , OSServiceId_GetAlarm,AlarmId, Tick);/*@req SWS_Os_00051 */ #endif OS_VALIDATE_STD_2( (Os_SysIntAnyDisabled() == FALSE) , E_OS_DISABLEDINT, OSServiceId_GetAlarm,AlarmId, Tick); /* @req SWS_Os_00093 */ OS_VALIDATE_STD_2( ALARM_CHECK_ID(AlarmId), E_OS_ID, OSServiceId_GetAlarm,AlarmId, Tick); /* @req OSEK_SWS_AL_00005 */ aPtr = Os_AlarmGet(AlarmId); /* @req OSEK_SWS_AL_00007 */ #if (OS_SC3==STD_ON) || (OS_SC4==STD_ON) const OsTaskVarType *currPcbPtr = Os_SysTaskGetCurr(); if( currPcbPtr->constPtr->applOwnerId != aPtr->applOwnerId ) { ApplicationType appId; OS_VALIDATE_STD_2( (Os_ApplCheckState(aPtr->applOwnerId) != E_OS_ACCESS) , E_OS_ACCESS, OSServiceId_GetAlarm,AlarmId, Tick); appId = Os_GetCurrTaskISROwnerId(); OS_VALIDATE_STD_2( (Os_ApplCheckAccess(appId, aPtr->accessingApplMask) != E_OS_ACCESS) , E_OS_ACCESS, OSServiceId_GetAlarm,AlarmId, Tick); #if (OS_NUM_CORES > 1) if (Os_ApplGetCore(aPtr->applOwnerId) != GetCoreID()) { StatusType status = Os_NotifyCore(Os_ApplGetCore(aPtr->applOwnerId), OSServiceId_GetAlarm, AlarmId, (uint32)Tick, 0); return status; } #endif } #endif Irq_Save(flags); if( aPtr->active == 0 ) { rv = E_OS_NOFUNC; /* @req OSEK_SWS_AL_00006 */ Irq_Restore(flags); /* OS_STD_ERR_2: Function will return after calling ErrorHook */ /* This is not inline with Table 8, ISO26262-6:2011, Req 1a and 1h */ OS_STD_ERR_2(OSServiceId_GetAlarm,AlarmId, Tick); } *Tick = Os_CounterDiff( aPtr->expire_val, Os_CounterGetValue(aPtr->counter), Os_CounterGetMaxValue(aPtr->counter) ); Irq_Restore(flags); return rv; } /** * The system service occupies the alarm <AlarmID> element. * After <increment> ticks have elapsed, the task assigned to the * alarm <AlarmID> is activated or the assigned event (only for * extended tasks) is set or the alarm-callback routine is called. * * @param AlarmId Reference to the alarm element * @param increment Relative value in ticks * @param cycle Cycle value in case of cyclic alarm. In case of single alarms, cycle shall be zero. * @return */ /* @req OSEK_SWS_AL_00008 */ StatusType SetRelAlarm(AlarmType AlarmId, TickType Increment, TickType Cycle) { return Os_internalSetRelAlarm(AlarmId, Increment, Cycle, FALSE); } /** * The system service occupies the alarm <AlarmID> element. * When <start> ticks are reached, the task assigned to the alarm * * If the absolute value <start> is very close to the current counter * value, the alarm may expire, and the task may become ready or * the alarm-callback may be called before the system service * returns to the user. * If the absolute value <start> already was reached before the * system call, the alarm shall only expire when the absolute value * <start> is reached again, i.e. after the next overrun of the * counter. * * If <cycle> is unequal zero, the alarm element is logged on again * immediately after expiry with the relative value <cycle>. * * The alarm <AlarmID> shall not already be in use. * To change values of alarms already in use the alarm shall be * cancelled first. * * If the alarm is already in use, this call will be ignored and the * error E_OS_STATE is returned. * * Allowed on task level and in ISR, but not in hook routines. * * @param AlarmId * @param Start * @param Cycle * @return */ /* @req OSEK_SWS_AL_00014 */ StatusType SetAbsAlarm(AlarmType AlarmId, TickType Start, TickType Cycle) { return Os_internalSetAbsAlarm(AlarmId, Start, Cycle, FALSE); } /* * The system service CancelAlarm cancels the alarm <AlarmID>. */ /* @req OSEK_SWS_AL_00020 */ StatusType CancelAlarm(AlarmType AlarmId) { StatusType rv = E_OK; OsAlarmType *aPtr; imask_t flags; /* Validation of parameters, if it fails, function will return */ /* This is not inline with Table 8, ISO26262-6:2011, Req 1a and 1h */ OS_VALIDATE_STD_1( (Os_SysIntAnyDisabled() == FALSE) , E_OS_DISABLEDINT, OSServiceId_CancelAlarm,AlarmId); /* @req SWS_Os_00093 */ OS_VALIDATE_STD_1( ALARM_CHECK_ID(AlarmId), E_OS_ID, OSServiceId_CancelAlarm,AlarmId); /* @req OSEK_SWS_AL_00021 */ aPtr = Os_AlarmGet(AlarmId); /* @req OSEK_SWS_AL_00023 */ #if (OS_SC3==STD_ON) || (OS_SC4==STD_ON) const OsTaskVarType *currPcbPtr = Os_SysTaskGetCurr(); if( currPcbPtr->constPtr->applOwnerId != aPtr->applOwnerId ) { ApplicationType appId; OS_VALIDATE_STD_1( (Os_ApplCheckState(aPtr->applOwnerId) != E_OS_ACCESS) , E_OS_ACCESS, OSServiceId_CancelAlarm,AlarmId); appId = Os_GetCurrTaskISROwnerId(); OS_VALIDATE_STD_1( (Os_ApplCheckAccess(appId, aPtr->accessingApplMask) != E_OS_ACCESS) , E_OS_ACCESS, OSServiceId_CancelAlarm,AlarmId); } #if (OS_NUM_CORES > 1) if (Os_ApplGetCore(aPtr->applOwnerId) != GetCoreID()) { StatusType status = Os_NotifyCore(Os_ApplGetCore(aPtr->applOwnerId), OSServiceId_CancelAlarm, AlarmId, 0, 0); return status; } #endif #endif Irq_Save(flags); if( aPtr->active == 0 ) { rv = E_OS_NOFUNC; /* @req OSEK_SWS_AL_00022 */ Irq_Restore(flags); /* OS_STD_ERR_1: Function will return after calling ErrorHook */ /* This is not inline with Table 8, ISO26262-6:2011, Req 1a and 1h */ OS_STD_ERR_1(OSServiceId_CancelAlarm,AlarmId); } aPtr->active = 0; Irq_Restore(flags); return rv; } /* * Check the action of the alarm and progress accordingly; * either activate a task, set an event or increment the counter * */ void Os_AlarmCheck( const OsCounterType *c_p ) { OsAlarmType *aPtr; StatusType rv; /*lint -e{9036} MISRA:EXTERNAL_FILE::[MISRA 2012 Rule 14.4, required] */ SLIST_FOREACH(aPtr,&c_p->alarm_head,alarm_list) { if( aPtr->active && (c_p->val == aPtr->expire_val) ) { /* Check if the alarms have expired */ OS_DEBUG(D_ALARM,"expired %s id:%u val:%u\n", aPtr->name, (unsigned)aPtr->counter_id, (unsigned)aPtr->expire_val); switch( aPtr->action.type ) { case ALARM_ACTION_ACTIVATETASK: /* @req SWS_Os_00321 */ if( ActivateTask(aPtr->action.task_id) != E_OK ) { /* We ignore return value since handling of error occurs in ActivateTask */ } AlarmProcess(aPtr); break; case ALARM_ACTION_SETEVENT: rv = SetEvent(aPtr->action.task_id,aPtr->action.event_id); if( rv != E_OK ) { Os_CallErrorHook(rv); } AlarmProcess(aPtr); break; #if (OS_SC1 == STD_ON) case ALARM_ACTION_ALARMCALLBACK: break; #endif case ALARM_ACTION_INCREMENTCOUNTER: /** @req SWS_Os_00301 */ (void)IncrementCounter(aPtr->action.counter_id); AlarmProcess(aPtr); break; __CODE_COVERAGE_IGNORE__ default: /* @CODECOV:DEFAULT_CASE:Default statement is required for defensive programming. */ ASSERT(0); } } } } /* @req SWS_Os_00476 * The Operating System module shall allow to automatically start * preconfigured absolute alarms during the start of the Operating System. */ void Os_AlarmAutostart(void) { AlarmType j; for (j = 0; j < OS_ALARM_CNT; j++) { #if (OS_NUM_CORES > 1) if (Os_OnRunningCore(OBJECT_ALARM,j)) { #endif const OsAlarmType *aPtr; aPtr = Os_AlarmGet(j); if (aPtr->autostartPtr != NULL_PTR) { const OsAlarmAutostartType *autoPtr = aPtr->autostartPtr; /*lint -e{9036} MISRA:STANDARDIZED_INTERFACE:Type defined by AUTOSAR:[MISRA 2012 Rule 14.4, required] */ /* @CODECOV:OTHER_TEST_EXIST: We support only one appmode */ __CODE_COVERAGE_IGNORE__ if (OS_SYS_PTR->appMode & autoPtr->appModeRef) { if (autoPtr->autostartType == ALARM_AUTOSTART_ABSOLUTE) { (void)Os_internalSetAbsAlarm(j, autoPtr->alarmTime, autoPtr->cycleTime, TRUE); } else { (void)Os_internalSetRelAlarm(j, autoPtr->alarmTime, autoPtr->cycleTime, TRUE); } } } #if (OS_NUM_CORES > 1) } #endif } } #endif
2301_81045437/classic-platform
system/Os/rtos/src/os_alarm.c
C
unknown
22,800
/*-------------------------------- 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 ALARM_I_H_ #define ALARM_I_H_ /* STD container : OsAlarmSetEvent * OsAlarmSetEventRef: 1 * OsAlarmSetEventTaskRef: 1 * */ /* STD container : OsAlarmActivateTask * OsAlarmActivateTaskRef: 1 * */ /* STD container : OsAlarmCallback * OsAlarmCallbackName: 1 Function Ptr * */ /* STD container : OsAlarmIncrementCounter * OsAlarmIncrementCounterRef: 1 Ref to counter * */ struct OsCounter; typedef enum alarm_action_type_e { ALARM_ACTION_ACTIVATETASK=0, ALARM_ACTION_SETEVENT, ALARM_ACTION_ALARMCALLBACK, /* Only class 1 */ ALARM_ACTION_INCREMENTCOUNTER/* SWS OS302 */ } alarm_action_type_t; /* STD container : OsAlarmAction * OsAlarmActivateTask: 0..1 * OsAlarmCallback: 0..1 * OsAlarmIncrementCounter: 0..1 * OsAlarmSetEvent: 0..1 * */ typedef struct OsAlarmAction { alarm_action_type_t type; TaskType task_id; EventMaskType event_id; CounterType counter_id; } OsAlarmActionType; enum OsAlarmAutostartTypeType { // Start with SetAbsAlarm() ALARM_AUTOSTART_ABSOLUTE, // Start with SetRelAlarm() ALARM_AUTOSTART_RELATIVE }; /* STD container : OsAlarmAutostart * OsAlarmAlarmTime: 1 Int * OsAlarmAutoStartType: 1 Int, ABSOLUTE, RELATIVE * OsAlarmCycleTime: 1 Int * OsAlarmAppModeRef: 1..* */ typedef struct OsAlarmAutostart { uint32 alarmTime; enum OsAlarmAutostartTypeType autostartType; uint32 cycleTime; AppModeType appModeRef; } OsAlarmAutostartType; /* STD container : OsAlarm * OsAlarmAccessingApplication: 0..* Ref to OS application * OsAlamCounterRef: 1 Ref to counter * OsAlarmAction[C] 1 Action when alarm expires * OsAlarmAutostart[C] 0..1 Autostart */ typedef struct OsAlarm { char *name; struct OsCounter *counter; /* Reference to counter */ #if (OS_USE_APPLICATIONS == STD_ON) ApplicationType applOwnerId; uint32 accessingApplMask; #endif CounterType counter_id; uint32 alarmtime; /* cycle, 0 = no cycle */ uint32 cycletime; uint32 app_mask; uint32 expire_val; _Bool active; /* if the alarm is active or not */ OsAlarmActionType action; /* Action attributes when alarm expires. */ const struct OsAlarmAutostart *autostartPtr; SLIST_ENTRY(OsAlarm) alarm_list; /* List of alarms connected to the same counter */ #if (OS_SC1 == STD_ON) /* IMPROVEMENT: OS242, callback in scalability class 1 only..*/ /** Missing req OS242 */ #endif } OsAlarmType; #if OS_ALARM_CNT!=0 extern GEN_ALARM_HEAD; #endif void Os_AlarmCheck(const OsCounterType *c_p); void Os_AlarmAutostart(void); static inline OsAlarmType *Os_AlarmGet( AlarmType alarm_id ) { #if (OS_ALARM_CNT!=0) return &alarm_list[alarm_id]; #else (void)alarm_id; return NULL_PTR; #endif } static inline ApplicationType Os_AlarmGetApplicationOwner( AlarmType id ) { ApplicationType rv; /** @req SWS_Os_00274 */ #if (OS_ALARM_CNT!=0) rv = (id < OS_ALARM_CNT) ? Os_AlarmGet(id)->applOwnerId : INVALID_OSAPPLICATION; #else (void)id; rv = INVALID_OSAPPLICATION; #endif return rv; } #endif /*ALARM_I_H_*/
2301_81045437/classic-platform
system/Os/rtos/src/os_alarm_i.h
C
unknown
4,125
/*-------------------------------- 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 */ /* ----------------------------[includes]------------------------------------*/ #include "os_i.h" /* ----------------------------[private define]------------------------------*/ #define BACKCHAIN_SIZE (16uL) /* ----------------------------[private macro]-------------------------------*/ /* ----------------------------[private typedef]-----------------------------*/ /* ----------------------------[private function prototypes]-----------------*/ /* ----------------------------[private variables]---------------------------*/ #if OS_APPLICATION_CNT!=0 OsAppVarType Os_AppVar[OS_APPLICATION_CNT]; #endif /* ----------------------------[private functions]---------------------------*/ /* ----------------------------[public functions]----------------------------*/ /* ----------------------------[General requirements handled in this functions]----------------------------*/ /* @req SWS_Os_00547 * Availability of AllowAccess(): Available in Scalability Classes 3 and 4. * OS536 * Availability of TerminateApplication(): Available in Scalability Classes 3 and 4. * OS520 * Availability of CheckObjectOwnership():Available in Scalability Classes 3 and 4. * @req SWS_Os_00514 * Availability of GetApplicationID():Available in Scalability Classes 3 and 4. * @req SWS_Os_00519 * Availability of CheckObjectAccess():Available in Scalability Classes 3 and 4. * @req SWS_Os_00537 * Availability of GetApplicationState(): Available in Scalability Classes 3 and 4. * */ #if (OS_APPLICATION_CNT > 1) && ((OS_SC1 == STD_ON )||(OS_SC2 == STD_ON )) && (OS_NUM_CORES==1) #error Cant configure more than one application on SC1 and SC1 if on single-core #endif #if (OS_USE_APPLICATIONS == STD_ON) #if ((OS_SC3 == STD_ON) || (OS_SC4 == STD_ON)) /** * This service determines the currently running OS-Application (a unique * identifier has to be allocated to each application). * * @return <identifier of running OS-Application> or INVALID_OSAPPLICATION */ /** @req SWS_Os_00016 OS provides the service GetApplicationID() */ ApplicationType GetApplicationID( void ) { /** @req SWS_Os_00261 *//** !req SWS_Os_00262 */ return OS_SYS_PTR->currApplId; } /** * This service checks if a memory region is write/read/execute accessible * and also returns information if the memory region is part of the stack * space. * * @param ISRID ISR reference * @param Address Start of memory area * @param Size Size of memory area * @return */ AccessType CheckISRMemoryAccess( ISRType isrId, MemoryStartAddressType address, MemorySizeType size ) { /*lint -e{923} MISRA:OTHER:Allow pointer to ptrdiff_t cast:[MISRA 2012 Rule 11.4, advisory]*/ ptrdiff_t addr = (ptrdiff_t)address; (void)addr; (void)size; if( isrId > (ISRType)OS_ISR_CNT ) { /*lint -e{904} MISRA:OTHER:Return statement is necessary to avoid multiple if loops and hence increase readability in case of argument check:[MISRA 2012 Rule 15.5, advisory]*/ return 0; } /** !req SWS_Os_00449 */ return 0; } /** * This service checks if a memory region is write/read/execute accessible * and also returns information if the memory region is part of the stack * space. * * Check returned accesstype with: * OSMEMORY_IS_READABLE(<AccessType>) * OSMEMORY_IS_WRITEABLE(<AccessType>) * OSMEMORY_IS_EXECUTABLE(<AccessType>) * OSMEMORY_IS_STACKSPACE(<AccessType>) * * NOTE: Not really sure what this function is actually good for? Add a use-case! * * @param TaskID Task reference * @param Address Start of memory area * @param Size Size of memory area * @return */ AccessType CheckTaskMemoryAccess( TaskType taskId, MemoryStartAddressType address, MemorySizeType size ) { /*lint -e{923} MISRA:STANDARDIZED_INTERFACE:Allow pointer to ptrdiff_t cast:[MISRA 2012 Rule 11.6, required]*/ ptrdiff_t addr = (ptrdiff_t)address; (void)addr; (void)size; if( taskId > OS_TASK_CNT ) { /*lint -e{904} MISRA:OTHER:Return statement is necessary to avoid multiple if loops and hence increase readability in case of argument check:[MISRA 2012 Rule 15.5, advisory]*/ return 0; } /* IMPROVEMENT: Add body */ return 0; } /** * This service determines if the OS-Applications, given by ApplID, * is allowed to use the IDs of a Task, ISR, Resource, Counter, * Alarm or Schedule Table in API calls. * * @param ApplID OS-Application identifier * @param ObjectType Type of the following parameter * @param object The object to be examined * @return ACCESS if the ApplID has access to the object * NO_ACCESS otherwise */ /** @req SWS_Os_00256 OS provides the service CheckObjectAccess() */ /** @req SWS_Os_00450 CheckObjectAccess checks access rights for Operating System objects. */ ObjectAccessType CheckObjectAccess( ApplicationType ApplId, ObjectTypeType ObjectType, uint32 objectId ) { uint32 appMask = APPL_ID_TO_MASK(ApplId); ObjectAccessType rv = NO_ACCESS; uint32 rvMask = 0U; /* @req SWS_Os_00423 * If in a call of CheckObjectAccess() the object to be examined * is not avalid object OR <ApplID> is invalid OR <ObjectType> is * invalid THEN CheckObjectAccess() shall return NO_ACCESS. */ /* @req SWS_Os_00272 * If the OS-Application <ApplID> in a call of CheckObjectAccess() has no * access to the queried object, CheckObjectAccess() shall return NO_ACCESS. */ if (( ApplId < (ApplicationType)OS_APPLICATION_CNT )) { /*lint -e{685} MISRA:CONFIGURATION:Allow MISRA violations depending on configuration:[MISRA 2012 Rule 14.3, required]*/ /*lint -e{568} MISRA:CONFIGURATION:Allow MISRA violations depending on configuration:[MISRA 2004 Info, advisory]*/ switch( ObjectType ) { case OBJECT_ALARM: #if (OS_ALARM_CNT != 0) if (objectId < OS_ALARM_CNT) { const OsAlarmType *lPtr = Os_AlarmGet((AlarmType)objectId); rvMask = lPtr->accessingApplMask & (appMask); } #endif break; case OBJECT_COUNTER: #if (OS_COUNTER_CNT != 0) if (objectId < OS_COUNTER_CNT) { const OsCounterType *lPtr = Os_CounterGet((CounterType)objectId); rvMask = lPtr->accessingApplMask & (appMask); } #endif break; case OBJECT_ISR: { /* An ISR do not have accessingApplicationMask, just check if owner */ const OsIsrVarType *lPtr = Os_IsrGet((ISRType)objectId); rvMask = (lPtr->constPtr->appOwner == ApplId); } break; case OBJECT_RESOURCE: #if (OS_RESOURCE_CNT != 0) if (objectId < OS_RESOURCE_CNT) { const OsResourceType *lPtr = Os_ResourceGet((ResourceType)objectId); rvMask = lPtr->accessingApplMask & (appMask); } #endif break; case OBJECT_SCHEDULETABLE: #if (OS_SCHTBL_CNT != 0) if (objectId < OS_SCHTBL_CNT) { const OsSchTblType *lPtr = Os_SchTblGet((ScheduleTableType)objectId); rvMask = lPtr->accessingApplMask & (appMask); } #endif break; case OBJECT_TASK: if (objectId < OS_TASK_CNT) { const OsTaskVarType *lPtr = Os_TaskGet((TaskType)objectId); rvMask = lPtr->constPtr->accessingApplMask & (appMask); } break; default: /* @req SWS_Os_00423 */ break; } } else { /** @req SWS_Os_00423 *//** @req SWS_Os_00272 */ } /** @req SWS_Os_00271 *//** @req SWS_Os_00272 */ if (rvMask != 0U) { rv = ACCESS; } /* @req SWS_Os_00367 * Operating System module’s services which do not return a * StatusType shall not raise the error hook(s). */ return rv; } #if !(defined(CFG_SAFETY_PLATFORM) || defined(BUILD_OS_SAFETY_PLATFORM)) /** * This service sets the own state of an OS-Application from * APPLICATION_RESTARTING to APPLICATION_ACCESSIBLE. * * @return E_OK : No errors * E_OS_STATE : The OS-Application of the caller is in the wrong state */ /** @req SWS_Os_00501 OS provides the service AllowAccess() */ StatusType AllowAccess( void ) { StatusType rv = E_OK; ApplicationType applId = OS_SYS_PTR->currApplId; /* @req SWS_Os_00497 * If the state of the OS-Application of the caller of AllowAccess() is not APPLICATION_RESTARTING * AllowAccess() shall return E_OS_STATE. */ /* Validation of parameters, if it fails, function will return */ /* This is not inline with Table 8, ISO26262-6:2011, Req 1a and 1h */ OS_VALIDATE_STD( !(Os_ApplGetState(applId) != APPLICATION_RESTARTING), E_OS_STATE, OSServiceId_AllowAccess); /* @req SWS_Os_00498 * If the state of the OS-Application of the caller of AllowAccess() is APPLICATION_RESTARTING, * AllowAccess() shall set the state to APPLICATION_ACCESSIBLE and * allow other OS-Applications to access the configured objects of the callers OS-Application. */ Os_ApplSetState(applId, APPLICATION_ACCESSIBLE); return rv; } #endif //CFG_SAFETY_PLATFORM #endif // #if ((OS_SC3 == STD_ON) || (OS_SC4 == STD_ON)) /** * This service determines to which OS-Application a given Task, ISR, Resource, * Counter, Alarm or Schedule Table belongs * * @param ObjectType Type of the following parameter * @param object The object to be examined * @return The OS-Application to which the object ObjectType belongs or * INVALID_OSAPPLICATION if the object does not exists */ /** @req SWS_Os_00017 OS provides the service CheckObjectOwnership() */ ApplicationType CheckObjectOwnership( ObjectTypeType ObjectType, uint32 objectId ) { ApplicationType rv = (uint32)INVALID_OSAPPLICATION; switch( ObjectType ) { case OBJECT_ALARM: rv = Os_AlarmGetApplicationOwner((AlarmType)objectId); break; case OBJECT_COUNTER: rv = Os_CounterGetApplicationOwner((CounterType)objectId); break; case OBJECT_ISR: rv = Os_IsrGetApplicationOwner((ISRType)objectId); break; case OBJECT_RESOURCE: rv = Os_ResourceGetApplicationOwner((ResourceType)objectId); break; case OBJECT_SCHEDULETABLE: rv = Os_SchTblGetApplicationOwner((ScheduleTableType)objectId); break; case OBJECT_TASK: rv = Os_TaskGetApplicationOwner((TaskType)objectId); break; default: /** @req SWS_Os_00274 */ rv = (uint32)INVALID_OSAPPLICATION; break; } /** @req SWS_Os_00273 */ /** @req SWS_Os_00367 */ return rv; } #if !(defined(CFG_SAFETY_PLATFORM) || defined(BUILD_OS_SAFETY_PLATFORM)) /** * IMPROVEMENT: Move somewhere else * @param mode * @return */ /* @req OSEK_SWS_SS_00001 */ StatusType GetActiveApplicationMode( AppModeType* mode) { *mode = OS_SYS_PTR->appMode; return E_OK; } #endif //CFG_SAFETY_PLATFORM /** * During Os Initialization this API will be called. * Interrupt stack is set and applications are set to accessible. */ void Os_ApplStart( void ) { uint16_t i; /* Call startuphooks for all applications */ for(i=0;i<OS_APPLICATION_CNT;i++) { /** @req SWS_Os_00500 */ Os_AppVar[i].state = APPLICATION_ACCESSIBLE; Os_AppVar[i].trusted = Os_AppConst[i].trusted; Os_AppVar[i].appId = Os_AppConst[i].appId; #if ((OS_SC3 == STD_ON) || (OS_SC4 == STD_ON)) /* OsApplication startup hook is not allowed in safety platform*/ #if !(defined(CFG_SAFETY_PLATFORM) || defined(BUILD_OS_SAFETY_PLATFORM)) if( Os_AppConst[i].StartupHook != NULL ) { /** @req SWS_Os_00060 */ Os_AppConst[i].StartupHook(); } #endif /* Trusted application have no interrupt stack */ if( Os_AppVar[i].trusted == FALSE ) { Os_AppVar[i].intStack = (uint8*)Os_AppConst[i].intStack.bottom - BACKCHAIN_SIZE; Os_AppSetIsrEndmark(i); Os_AppSetIsrStartmark(i); } #endif } } #if ((OS_SC3 == STD_ON) || (OS_SC4 == STD_ON)) /** * @brief Perform stack check on ISR that belongs to an application * * @param id The ID of the application */ void Os_AppIsrStackPerformCheck( ApplicationType id ) { #if (OS_STACK_MONITORING == 1) /*lint --e{9036} -e{9007} MISRA:OTHER:Os_AppIsIsrEndmarkOk and Os_AppIsIsrStartmarkOk return boolean value:[MISRA 2012 Rule 14.4, required] [MISRA 2012 Rule 13.5, required]*/ if( (Os_AppIsIsrEndmarkOk(id) == FALSE) || (Os_AppIsIsrStartmarkOk(id) == FALSE) ) { /** @req SWS_Os_00396 * If a stack fault is detected by stack monitoring AND the configured scalability * class is 3 or 4, the Operating System module shall call the ProtectionHook() with * the status E_OS_STACKFAULT. * */ Os_CallProtectionHook(E_OS_STACKFAULT); } #else (void)id; #endif /* (OS_STACK_MONITORING == 1) */ } #if !(defined(CFG_SAFETY_PLATFORM) || defined(BUILD_OS_SAFETY_PLATFORM)) /** * @brief Function to get stack information * @param id Application Id * @param stack Pointer to stack information to fill. */ void Os_AppIsrGetStackInfo( ApplicationType id, OsAppStackType *stack ) { stack->top = Os_AppConst[id].intStack.top; stack->size = Os_AppConst[id].intStack.size; } #endif #endif #endif // #if (OS_USE_APPLICATIONS == STD_ON)
2301_81045437/classic-platform
system/Os/rtos/src/os_application.c
C
unknown
14,442
/*-------------------------------- 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 APPLICATION_H_ #define APPLICATION_H_ /* * IMPLEMENTATION NOTES: * * OS448: The Operating System module shall prevent access of * OS-Applications, trusted or non-trusted, to objects not belonging * to this OS-Application, except access rights for such objects are * explicitly granted by configuration. * * OS509: If a service call is made on an Operating System * object that is owned by another OS-Application without state * APPLICATION_ACCESSIBLE, then the Operating System module shall return E_OS_ACCESS. * * OS056: If an OS-object identifier is the parameter of an Operating System module�s * system service, and no sufficient access rights have been assigned to this OS-object * at configuration time (Parameter Os[...]AccessingApplication) to the calling * Task/Category 2 ISR, the Operating System module�s system service shall return * E_OS_ACCESS. * * OS311: If OsScalabilityClass is SC3 or SC4 AND a Task OR Category 2 ISR OR * Resources OR Counters OR Alarms OR Schedule tables does not belong to exactly * one OS-Application the consistency check shall issue an error. * * Page 52: * It is assumed that the Operating System module itself is trusted. * * Sooo, that gives us: * 1. For each * * * 1. App1, NT * Task11 * 2. App2, NT * Task21 * 3. App3, T * Task31 * 4. App4, T * Task41 * * * App2->App1: ActivateTask(Task11) * This is OK as long as Task11 have granted access to it during configuration * * App4->App3: ActivateTask(Task31) * This is OK as long as Task31 have granted access to it during configuration * * App1->App4: ActivateTask(Task41) * It's not really clear if the OS automagically exports all services.. * But this could also be CallTrustedFunction(ServiceId_AcivateTask,???) * */ #define APPL_ID_TO_MASK(_x) (1UL<<(_x)) #define APPL_REGS_CNT 16 // aligning with task register count #if ( OS_SC3 == STD_ON ) || ( OS_SC4 == STD_ON ) #define OS_APP_CALL_ERRORHOOKS( x ) \ for(uint32 i=0;i<OS_APPLICATION_CNT;i++) { \ if( Os_AppConst[i].ErrorHook != NULL ) { \ Os_AppConst[i].ErrorHook(x); \ } \ } #else #define OS_APP_CALL_ERRORHOOKS( x ) #endif typedef struct OsAppHooks { void (*startup)( void ); void (*shutdown)( Std_ReturnType Error ); void (*error)( Std_ReturnType Error ); } OsAppHooksType; typedef struct { void * bottom; /**< @brief Bottom of the stack (high address) */ void * top; /**< @brief Top of the stack (low address) */ uint32 size; /**< @brief Size of the stack in bytes */ } OsAppStackType; typedef struct OsAppVar { _Bool trusted; /**< @brief just a copy from const */ uint32 appId; /**< @brief just a copy from const */ ApplicationStateType state; /**< @brief The current state of the application */ uint32 regs[APPL_REGS_CNT]; /**< @brief Precalc register used by the MPU */ #if ( OS_SC3 == STD_ON ) || ( OS_SC4 == STD_ON ) uint32 nestCnt; /**< @brief Interrupt nest counter */ void * intStack; /**< @brief Pointer to bottom of Interrupt stack */ void * savedIntStack; /**< @brief Pointer to current int stack */ #endif } OsAppVarType; /* * Application configuration parameters. While generating Os configuration, parameters of the * configured Os application is filled in this structure type. */ typedef struct OsApplication { uint32 appId; /* The ID of the application */ const char *name; /* Name of the application */ _Bool trusted; /* Trusted or not, 0 - Non-trusted */ /** @req SWS_Os_00446 */ uint8 core; /* The core number on which this application runs */ /* hooks, the names are StartupHook_<name>(), etc. */ #if ( OS_SC3 == STD_ON ) || ( OS_SC4 == STD_ON ) void (*StartupHook)( void ); /** @req SWS_Os_00543 Available in SC3 and SC4 (and other SCs (SWS_Os_00240)) */ void (*ShutdownHook)( StatusType Error ); /** @req SWS_Os_545 Available in SC3 and SC4 (and other SCs (SWS_Os_00240)) */ void (*ErrorHook)( StatusType Error ); /** @req SWS_Os_544 Available in SC3 and SC4 (and other SCs (SWS_Os_00240)) */ int restartTaskId; /* Memory Protection regions */ void * dataStart; void * dataEnd; void * bssStart; void * bssEnd; OsAppStackType intStack; /**< @brief Interrupt stack */ #endif } OsAppConstType; #if ( OS_SC1 == STD_ON ) || ( OS_SC4 == STD_ON ) typedef void ( * trusted_func_t)( TrustedFunctionIndexType , TrustedFunctionParameterRefType ); #endif #if OS_APPLICATION_CNT!=0 /*lint -e9003 MISRA:EXTERNAL_FILE:Os_AppVar is declared out of scope since it is used in Os_ApplGet:[MISRA 2012 Rule 8.9, advisory]*/ extern OsAppVarType Os_AppVar[OS_APPLICATION_CNT]; extern const OsAppConstType Os_AppConst[OS_APPLICATION_CNT]; #if !(defined(CFG_SAFETY_PLATFORM) || defined(BUILD_OS_SAFETY_PLATFORM)) static inline ApplicationStateType Os_ApplGetState (ApplicationType applId) { return Os_AppVar[applId].state; } static inline void Os_ApplSetState (ApplicationType applId, ApplicationStateType applState) { Os_AppVar[applId].state = applState; } #endif static inline OsAppVarType *Os_ApplGet(ApplicationType id) { return &Os_AppVar[id]; } static inline const OsAppConstType *Os_ApplGetConst(ApplicationType id) { return &Os_AppConst[id]; } #endif // OS_APPLICATION_CNT!=0 static inline uint8 Os_ApplGetCore( ApplicationType appl ) { return Os_AppConst[appl].core; } /** * * @param mask Target accessing application mask * @return */ static inline StatusType Os_ApplHaveAccess( uint32 mask ) { /* @req SWS_Os_00056 */ if( (APPL_ID_TO_MASK(OS_SYS_PTR->currApplId) & mask) == 0 ) { return E_OS_ACCESS; } /* @req SWS_Os_00504/ActivateTask * The Operating System module shall deny access to Operating System * objects from other OS-Applications to an OS-Application which is not in state * APPLICATION_ACCESSIBLE. * */ /* We are activating a task in another application */ // Currently only APPLICATION_ACCESSIBLE is supported #if 0 if( !( Os_ApplGetState(OS_SYS_PTR->currApplId) == APPLICATION_ACCESSIBLE)) { return E_OS_ACCESS; } #endif return E_OK; } /* Sanity checks */ static inline StatusType Os_ApplCheckState( ApplicationType appId ) { StatusType status = E_OK; (void)appId; /*lint !e920 MISRA:STANDARDIZED_INTERFACE */ // Currently only APPLICATION_ACCESSIBLE is supported #if 0 if( Os_ApplGetState(appId) != APPLICATION_ACCESSIBLE ) { status = E_OS_ACCESS; } #endif return status; } static inline StatusType Os_ApplCheckAccess( ApplicationType appId, uint32 mask ) { StatusType status = E_OK; if( (APPL_ID_TO_MASK(appId) & mask) == 0 ) { status = E_OS_ACCESS; } return status; } /** * Starting Os Applications during Os Init. */ void Os_ApplStart( void ); #if !(defined(CFG_SAFETY_PLATFORM) || defined(BUILD_OS_SAFETY_PLATFORM)) /** * Setting Os Application to accessible */ StatusType AllowAccess( void ); /** * Getting state of the application */ StatusType GetApplicationState( ApplicationType applId, ApplicationStateRefType value ); #endif //CFG_SAFETY_PLATFORM #if (OS_SC3==STD_ON) || (OS_SC4==STD_ON) /** * @brief Set endmark for application interrupt stack. * @param aP Pointer to application */ static inline void Os_AppSetIsrEndmark( ApplicationType id ) { uint8 *end = Os_AppConst[id].intStack.top; *end = STACK_PATTERN; } /** * @brief Set startmark for application interrupt stack. * @param aP Pointer to application */ static inline void Os_AppSetIsrStartmark( ApplicationType id ) { /* Get high address */ uint8 *bottom = Os_AppConst[id].intStack.bottom; *(bottom-1ul) = STACK_PATTERN; } /** @brief Check endmark for application interrupt stack. * @param aP Pointer to application * @return FALSE if the end-mark is not ok. */ static inline boolean Os_AppIsIsrEndmarkOk( ApplicationType id ) { boolean rv = FALSE; uint8 *end = Os_AppConst[id].intStack.top; if( *end == STACK_PATTERN ) { rv = TRUE; } return rv; } /** @brief Check endmark for application interrupt stack. * @param aP Pointer to application * @return FALSE if the end-mark is not ok. */ static inline boolean Os_AppIsIsrStartmarkOk( ApplicationType id ) { boolean rv = FALSE; uint8 *bottom = Os_AppConst[id].intStack.bottom; if( *(bottom-1UL) == STACK_PATTERN ) { rv = TRUE; } return rv; } void Os_AppIsrStackPerformCheck( ApplicationType id ); void Os_AppIsrGetStackInfo( ApplicationType id, OsAppStackType *stack ); #endif /* (OS_SC3==STD_ON) || (OS_SC4==STD_ON) */ #endif /* APPLICATION_H_ */
2301_81045437/classic-platform
system/Os/rtos/src/os_application_i.h
C
unknown
10,062
/*-------------------------------- 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 */ /* * This file only be use with the Os_Cfg.c file and os_config_macros.h */ #include "os_i.h" #include "Os_Cfg.h" #error os_config_funcs.h is deprecated #if 0 /** @req SWS_Os_00327 */ #if (OS_SC3 == STD_ON) || (OS_SC4 == STD_ON) #if (OS_STATUS_STANDARD == STD_ON ) #error req OS327 not fullfilled #endif #endif // COUNTER, RESOURCE, TSAK, must be at least 1 #if (OS_ALARM_CNT!=0) #endif OsErrorType os_error; //------------------------------------------------------------------- /*-----------------------------------------------------------------*/ (void)resource; /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ (void)sched_id; /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ #if 0 OsMessageType *Os_CfgGetMessage(MessageType message_id) { #if (OS_MESSAGE_CNT!=0) return &message_list[message_id]; #else return NULL; #endif } uint32 Os_CfgGetMessageCnt(void ) { return OS_MESSAGE_CNT; } #endif /*-----------------------------------------------------------------*/ #if (OS_USE_APPLICATIONS == STD_ON) uint32 Os_CfgGetServiceCnt( void ) { return OS_SERVICE_CNT; } #endif #endif
2301_81045437/classic-platform
system/Os/rtos/src/os_config_funcs.h
C
unknown
2,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 -----------------------------*/ /* Configure "rules" * - Don't pollute the namespace with the generator tools. The tools should * ONLY know the GEN_xxx macros. * - If something is a container with multiplicity 1 and above, make it a pointer. * - ... */ #ifndef _OS_CONFIG_MACROS_H #define _OS_CONFIG_MACROS_H #include "Std_Types.h" #define false 0 #define true 1 #ifndef ARRAY_SIZE #define ARRAY_SIZE(_x) (sizeof(_x)/sizeof((_x)[0])) #endif /* *---------------------- TASKS --------------------------------------------- */ #define GEN_TASK_HEAD const OsTaskConstType Os_TaskConstList[OS_TASK_CNT] /** * _id * _priority The task priority * _autostart true/false * _resource_int_p Pointer to internal resource. * NULL - if no internal resource or scheduling==NON * Pointer to * _scheduling FULL or NON * _resource_mask Mask of the resources used. Applies to STANDARD and LINKED (NOT INTERNAL) * For example if this task would use resource with id 2 and 4 the mask would * become (1<<2)|(1<<4) = 0x14 (limits resources to 32). * Currently used for calculating the ceiling priority. */ #define GEN_ETASK( _id, _name, _priority, _scheduling, \ _autostart, _resource_int_p, _resource_mask, _event_mask, \ _appl_owner, _accessing_appl_mask) \ { \ .pid = TASK_ID_ ## _id, \ .name = _name, \ .entry = _id, \ .prio = _priority, \ .proc_type = PROC_EXTENDED, \ .stack.size = sizeof stack_##_id, \ .stack.top = stack_##_id, \ .autostart = _autostart, \ .resourceIntPtr = _resource_int_p, \ .scheduling = _scheduling, \ .resourceAccess = _resource_mask, \ .eventMask = _event_mask, \ .activationLimit = 1, \ .applOwnerId = _appl_owner, \ .accessingApplMask = _accessing_appl_mask, \ } #define GEN_BTASK( _id, _name, _priority, _scheduling, \ _autostart, _resource_int_p, _resource_mask, \ _activation_limit, _appl_owner, _accessing_appl_mask ) \ { \ .pid = TASK_ID_ ## _id, \ .name = _name, \ .entry = _id, \ .prio = _priority, \ .proc_type = PROC_BASIC, \ .stack.size = sizeof stack_##_id, \ .stack.top = stack_##_id, \ .autostart = _autostart, \ .resourceIntPtr = _resource_int_p, \ .scheduling = _scheduling, \ .resourceAccess = _resource_mask, \ .activationLimit = _activation_limit, \ .applOwnerId = _appl_owner, \ .accessingApplMask = _accessing_appl_mask, \ } /* *---------------------- INTERRUPTS ---------------------------------------- */ #define GEN_ISR_HEAD const OsIsrConstType Os_IsrConstList[OS_ISR_CNT] #define GEN_ISR1( _name, _vector, _priority, _entry, _appOwner ) \ { \ .vector = (int16_t)_vector, \ .type = ISR_TYPE_1, \ .priority = _priority, \ .entry = _entry, \ .name = _name, \ .resourceMask = 0, \ .appOwner = _appOwner, \ } #define GEN_ISR2( _name, _vector, _priority, _entry, _appOwner, _resourceMask ) \ { \ .vector = (int16_t)_vector, \ .type = ISR_TYPE_2, \ .priority = _priority, \ .entry = _entry, \ .name = _name, \ .resourceMask = _resourceMask, \ .appOwner = _appOwner, \ } #define GEN_ISR_MAP uint8 Os_VectorToIsr[NUMBER_OF_INTERRUPTS_AND_EXCEPTIONS] /* *---------------------- RESOURCES ----------------------------------------- */ #define GEN_RESOURCE_LIST resource_list #define GEN_RESOURCE_HEAD OsResourceType GEN_RESOURCE_LIST[OS_RESOURCE_CNT] /** * _id * _type RESOURCE_TYPE_STANDARD, RESOURCE_TYPE_LINKED or RESOURCE_TYPE_INTERNAL * _ceiling_priority The calculated ceiling priority */ #define GEN_RESOURCE( _id, _type, _ceiling_priority, _appl_owner, _accessing_appl_mask ) \ { \ .nr= _id, \ .type= _type, \ .ceiling_priority = _ceiling_priority, \ .owner = UINT16_MAX, \ .applOwnerId = _appl_owner, \ .accessingApplMask = _accessing_appl_mask \ } /* *---------------------- COUNTERS ------------------------------------------ */ #define GEN_COUNTER_HEAD OsCounterType counter_list[OS_COUNTER_CNT] /** * _id * NOT_USED * _name * Name of the alarm, string * * _type * COUNTER_TYPE_HARD or COUNTER_TYPE_SOFT * * _unit * COUNTER_UNIT_TICKS or COUNTER_UNIT_NANO * * _maxallowedvalue * 0xffffffffUL * * _ticksperbase * 1 * * _mincycle * Say 10000 * _gpt_ch * NOT USED. Set to 0 */ #define GEN_COUNTER( _id, _name, _type, _unit, \ _maxallowedvalue, \ _ticksperbase, \ _mincycle, \ _gpt_ch, \ _appl_owner, \ _accessing_appl_mask ) \ { \ .type = _type, \ .unit = _unit, \ .alarm_base = { \ .maxallowedvalue = _maxallowedvalue, \ .tickperbase = _ticksperbase, \ .mincycle = _mincycle, \ }, \ .applOwnerId = _appl_owner, \ .accessingApplMask = _accessing_appl_mask, \ .val = 0,\ .driver = NULL_PTR,\ } /* *---------------------- ALARMS -------------------------------------------- */ #define GEN_ALARM_HEAD OsAlarmType alarm_list[OS_ALARM_CNT] #define GEN_ALARM_AUTOSTART_NAME(_id) &(Os_AlarmAutoStart_ ## _id) /** * _id * _type * _alarms_time * _cycle_time * _app_mode Mask of the application modes. */ #define GEN_ALARM_AUTOSTART(_id, _type, _alarm_time, _cycle_time, _app_mode ) \ const OsAlarmAutostartType Os_AlarmAutoStart_ ## _id = \ { \ .autostartType = _type, \ .alarmTime = _alarm_time, \ .cycleTime = _cycle_time, \ .appModeRef = _app_mode \ } /** * _id * NOT USED * * _name * Name of the alarm, string * * _counter_id * The id of the counter to drive the alarm * * _autostart_ref * * _X_type - Any of: * ALARM_ACTION_ACTIVATETASK * ALARM_ACTION_SETEVENT * ALARM_ACTION_ALARMCALLBACK * ALARM_ACTION_INCREMENTCOUNTER * * _X_task_id - The task ID to activate if _X_type is: * ALARM_ACTION_ACTIVATETASK or * ALARM_ACTION_SETEVENT * * _X_event_id - The event ID if type is ALARM_ACTION_SETEVENT * * _X_counter_id - The counter ID if type is ALARM_ACTION_INCREMENTCOUNTER * */ #define GEN_ALARM( _id, _name, _counter_id, \ _autostart_ref, \ _action_type, \ _action_task_id, \ _action_event_id, \ _action_counter_id, \ _appl_owner, \ _accessing_appl_mask ) \ { \ .name = _name, \ .counter = &counter_list[_counter_id], \ .counter_id = _counter_id, \ .autostartPtr = _autostart_ref, \ .action = { \ .type = _action_type, \ .task_id = _action_task_id, \ .event_id = _action_event_id, \ .counter_id = _action_counter_id \ }, \ .applOwnerId = _appl_owner, \ .accessingApplMask = _accessing_appl_mask, \ } /* *---------------------- SCHEDULE TABLES ----------------------------------- */ #define GEN_SCHTBL_EXPIRY_POINT_HEAD(_id ) \ OsScheduleTableExpiryPointType Os_SchTblExpPointList_##_id[] = #define GEN_SCHTBL_EXPIRY_POINT_W_TASK_EVENT(_id, _offset ) \ { \ .offset = _offset, \ .taskList = Os_SchTblTaskList_ ## _id ## _ ## _offset, \ .taskListCnt = ARRAY_SIZE(Os_SchTblTaskList_ ## _id ## _ ## _offset), \ .eventList = Os_SchTblEventList_ ## _id ## _ ## _offset, \ .eventListCnt = ARRAY_SIZE(Os_SchTblEventList_ ## _id ## _ ## _offset) \ } #define GEN_SCHTBL_EXPIRY_POINT_W_TASK(_id, _offset ) \ { \ .offset = _offset, \ .taskList = Os_SchTblTaskList_ ## _id ## _ ## _offset, \ .taskListCnt = ARRAY_SIZE(Os_SchTblTaskList_ ## _id ## _ ## _offset), \ } #define GEN_SCHTBL_EXPIRY_POINT_W_EVENT(_id, _offset ) \ { \ .offset = _offset, \ .eventList = Os_SchTblEventList_ ## _id ## _ ## _offset, \ .eventListCnt = ARRAY_SIZE(Os_SchTblEventList_ ## _id ## _ ## _offset) \ } #define GEN_SCHTBL_TASK_LIST_HEAD( _id, _offset ) \ const TaskType Os_SchTblTaskList_ ## _id ## _ ## _offset[] = #define GEN_SCHTBL_EVENT_LIST_HEAD( _id, _offset ) \ const OsScheduleTableEventSettingType Os_SchTblEventList_ ## _id ## _ ## _offset[] = #define GEN_SCHTBL_AUTOSTART(_id, _type, _offset, _app_mode ) \ const struct OsSchTblAutostart Os_SchTblAutoStart_ ## _id = \ { \ .type = _type, \ .offset = _offset, \ .appMode = _app_mode, \ } #define GEN_SCHTBL_AUTOSTART_NAME(_id) &(Os_SchTblAutoStart_ ## _id) #define GEN_SCHTBL_HEAD OsSchTblType sched_list[OS_SCHTBL_CNT] /** * _id * NOT USED * * _name * Name of the alarm, string * * _counter_ref * Pointer to the counter that drives the table * * _repeating * SINGLE_SHOT or REPEATING * * _duration * The duration of the schedule table * * _autostart_ref * Pointer to autostart configuration. * If autostart is desired set name to GEN_SCHTBL_AUTOSTART_NAME(<id>). It also * requires that GEN_SCHTBL_AUTOSTART(...) is set. * Set to NULL if not autostart configuration is desired. * * The usage of the macro requires that GEN_SCHTBL_EXPIRY_POINT_HEAD(<id>) is also * set. */ #define GEN_SCHEDULETABLE( _id, _name, _counter_id, _repeating, \ _duration, \ _autostart_ref, \ _appl_owner, \ _accessing_appl_mask ) \ { \ .name = _name, \ .counter = &counter_list[_counter_id], \ .repeating = _repeating, \ .duration = _duration, \ .expirePointList = { \ .data = (void *)( Os_SchTblExpPointList_ ## _id ), \ .cnt = ARRAY_SIZE(Os_SchTblExpPointList_ ## _id), \ }, \ .autostartPtr = _autostart_ref,\ .applOwnerId = _appl_owner, \ .accessingApplMask = _accessing_appl_mask, \ } /* *---------------------- SPINLOCKS ----------------------------------------- */ #define GEN_SPINLOCK_HEAD OsSpinlockType spinlock_list[OS_SPINLOCK_CNT] /** * _id * Id of the spinlock * _name * Name of the spinlock, string * _lock * SPINLOCK_UNLOCKED, SPINLOCK_LOCKED */ #define GEN_SPINLOCK( _id, _name, _lock, _accessing_appl_mask ) \ { \ .id = _id, \ .name = _name, \ .lock = _lock, \ .accessingApplMask = _accessing_appl_mask, \ } #define ALIGN_16(x) (((x)>>4)<<4) #define DECLARE_STACK(_name,_size) \ __balign(16) uint8_t stack_##_name[_size] #endif // _OS_CONFIG_MACROS_H
2301_81045437/classic-platform
system/Os/rtos/src/os_config_macros.h
C
unknown
12,753
/*-------------------------------- 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 */ /* ----------------------------[includes]------------------------------------*/ #include "os_i.h" #if defined(CFG_LOG) && defined(LOG_OS_COUNTER) #define _LOG_NAME_ "os_cnt" #endif #include "log.h" /* ----------------------------[private define]------------------------------*/ /* ----------------------------[private macro]-------------------------------*/ /* ----------------------------[private typedef]-----------------------------*/ /* ----------------------------[private function prototypes]-----------------*/ /* ----------------------------[private variables]---------------------------*/ /* ----------------------------[private functions]---------------------------*/ static inline boolean IsCounterValid(CounterType counterId) { /*lint -e685 -e568 MISRA:ARGUMENT_CHECK:check counter id:[MISRA 2012 Rule 14.3, required] */ #if (OS_COUNTER_CNT != 0 ) return (boolean)((CounterType)(counterId) < (CounterType)OS_COUNTER_CNT); #else return FALSE; #endif } /* ----------------------------[public functions]----------------------------*/ #ifdef USE_RTE Std_ReturnType Os_GetCounterValue(CounterType counterId, TickType * value) { return (Std_ReturnType)GetCounterValue( counterId , (TickRefType)value); /*lint !e929 MISRA:STANDARDIZED_INTERFACE:pointer cast to correct type:[MISRA 2012 Rule 11.3, required] */ } Std_ReturnType Os_GetElapsedValue(CounterType counterId, TickType * value, TickType * elapsedValue) { return (Std_ReturnType)GetElapsedValue( counterId , (TickRefType)value, (TickRefType)elapsedValue); /*lint !e929 MISRA:STANDARDIZED_INTERFACE:pointer cast to correct type:[MISRA 2012 Rule 11.3, required] */ } #endif /** * * @param counter_id * @return */ /** @req SWS_Os_00530 IncrementCounter() available in all Scalability Classes. */ /** @req SWS_Os_00399 */ /* @req SWS_Os_00529 * Caveats of IncrementCounter(): If called from a task, rescheduling may take place. */ StatusType IncrementCounter( CounterType counter_id ) { StatusType rv = E_OK; OsCounterType *cPtr; imask_t flags; #if (OS_SC3==STD_ON) || (OS_SC4==STD_ON) const OsTaskVarType *currPcbPtr; #endif /* Validation of parameters, if failure, function will return */ /* This is not inline with Table 8, ISO26262-6:2011, Req 1a and 1h */ OS_VALIDATE_STD_1((Os_SysIntAnyDisabled() == FALSE) , E_OS_DISABLEDINT, OSServiceId_IncrementCounter,counter_id); /* @req SWS_Os_00093 */ /*lint -e{9027} MISRA:FALSE_POSITIVE:Not allowed for string, but operand is boolean:[MISRA 2012 Rule 10.1, required] */ OS_VALIDATE_STD_1(IsCounterValid(counter_id), E_OS_ID, OSServiceId_IncrementCounter,counter_id); /* @req SWS_Os_00285 */ cPtr = Os_CounterGet(counter_id); OS_VALIDATE_STD_1(COUNTER_TYPE_SOFT == cPtr->type, E_OS_ID, OSServiceId_IncrementCounter,counter_id); /* @req SWS_Os_00285 */ #if (OS_SC3==STD_ON) || (OS_SC4==STD_ON) currPcbPtr = Os_SysTaskGetCurr(); if( currPcbPtr->constPtr->applOwnerId != cPtr->applOwnerId ) { ApplicationType appId; /* @req SWS_Os_00056 */ OS_VALIDATE_STD_1( (Os_ApplCheckState(cPtr->applOwnerId) != E_OS_ACCESS) , E_OS_ACCESS, OSServiceId_IncrementCounter,counter_id); appId = Os_GetCurrTaskISROwnerId(); OS_VALIDATE_STD_1( (Os_ApplCheckAccess(appId, cPtr->accessingApplMask) != E_OS_ACCESS) , E_OS_ACCESS, OSServiceId_IncrementCounter,counter_id); #if (OS_NUM_CORES > 1) OS_EXT_VALIDATE( Os_ApplGetCore(cPtr->applOwnerId) != GetCoreID(), E_OS_ACCESS ); #endif } #endif Irq_Save(flags); /** @req SWS_Os_00286 */ cPtr->val = Os_CounterAdd( cPtr->val, Os_CounterGetMaxValue(cPtr), 1 ); #if OS_ALARM_CNT!=0 Os_AlarmCheck(cPtr); #endif #if OS_SCHTBL_CNT!=0 Os_SchTblCheck(cPtr); #endif Irq_Restore(flags); /** @req SWS_Os_00321 */ return rv; } /** @req SWS_Os_00532 GetCounterValue() available in all Scalability Classes. */ /** @req SWS_Os_00383 */ StatusType GetCounterValue( CounterType counter_id , TickRefType tick_ref) { StatusType rv = E_OK; const OsCounterType *cPtr; #if (OS_SC3==STD_ON) || (OS_SC4==STD_ON) const OsTaskVarType *currPcbPtr; #endif /* Validation of parameters, if failure, function will return */ /* This is not inline with Table 8, ISO26262-6:2011, Req 1a and 1h */ OS_VALIDATE_STD_2((tick_ref != NULL), E_OS_PARAM_POINTER, OSServiceId_GetCounterValue,counter_id,tick_ref); /* @req SWS_Os_00566 */ OS_VALIDATE_STD_2((Os_SysIntAnyDisabled() == FALSE) , E_OS_DISABLEDINT, OSServiceId_GetCounterValue,counter_id,tick_ref); /* @req SWS_Os_00093 */ /*lint -e{9027} MISRA:FALSE_POSITIVE:Not allowed for string, but operand is boolean:[MISRA 2012 Rule 10.1, required] */ OS_VALIDATE_STD_2(IsCounterValid(counter_id),E_OS_ID, OSServiceId_GetCounterValue,counter_id,tick_ref); /* @req SWS_Os_00376 */ #if (OS_SC3==STD_ON) || (OS_SC4==STD_ON) OS_VALIDATE_STD_2( (OS_VALIDATE_ADDRESS_RANGE(tick_ref,sizeof(TickType)) == TRUE ) , E_OS_ILLEGAL_ADDRESS , OSServiceId_GetCounterValue,counter_id,tick_ref);/*@req SWS_Os_00051 */ #endif cPtr = Os_CounterGet(counter_id); #if (OS_SC3==STD_ON) || (OS_SC4==STD_ON) currPcbPtr = Os_SysTaskGetCurr(); if( currPcbPtr->constPtr->applOwnerId != cPtr->applOwnerId ) { ApplicationType appId; /* @req SWS_Os_00056 */ /* Validation of parameters, if it failure, function will return */ /* This is not inline with Table 8, ISO26262-6:2011, Req 1a and 1h */ OS_VALIDATE_STD_2( (Os_ApplCheckState(cPtr->applOwnerId) != E_OS_ACCESS) , E_OS_ACCESS, OSServiceId_GetCounterValue,counter_id,tick_ref); appId = Os_GetCurrTaskISROwnerId(); OS_VALIDATE_STD_2( (Os_ApplCheckAccess(appId, cPtr->accessingApplMask) != E_OS_ACCESS) , E_OS_ACCESS, OSServiceId_GetCounterValue,counter_id,tick_ref); #if (OS_NUM_CORES > 1) if (Os_ApplGetCore(cPtr->applOwnerId) != GetCoreID()) { StatusType status = Os_NotifyCore(Os_ApplGetCore(cPtr->applOwnerId), OSServiceId_GetCounterValue, counter_id, (uint32_t)tick_ref, 0); return status; } #endif } #endif /** @req SWS_Os_00377 */ if( cPtr->type == COUNTER_TYPE_HARD ) { /* It's OSINTERNAL */ *tick_ref = OS_SYS_PTR->tick; } else { *tick_ref = cPtr->val; } return rv; } /** * * @param counter_id The counter to be read * @param val[in,out] in, The previously read tick value of the counter * out, Contains the current tick value of the counter. * @param elapsed_val[out] The difference * @return */ /** @req SWS_Os_00392 OS provides the service GetElapsedValue() */ /** @req SWS_Os_00534 GetElapsedValue() available in all Scalability Classes. */ StatusType GetElapsedValue ( CounterType counter_id, TickRefType val, TickRefType elapsed_val) { StatusType rv = E_OK; OsCounterType *cPtr; TickType currTick = 0; TickType max; /* @req SWS_Os_00566 */ /* Validation of parameters, if failure, function will return */ /* This is not inline with Table 8, ISO26262-6:2011, Req 1a and 1h */ OS_VALIDATE_STD_3( (val != NULL), E_OS_PARAM_POINTER, OSServiceId_GetElapsedValue, counter_id, val,elapsed_val); OS_VALIDATE_STD_3( (elapsed_val != NULL), E_OS_PARAM_POINTER, OSServiceId_GetElapsedValue, counter_id, val,elapsed_val); #if (OS_SC3==STD_ON) || (OS_SC4==STD_ON) OS_VALIDATE_STD_3( (OS_VALIDATE_ADDRESS_RANGE(val, sizeof(TickType)) == TRUE ) , E_OS_ILLEGAL_ADDRESS , OSServiceId_GetElapsedValue, counter_id, val,elapsed_val);/*@req SWS_Os_00051 */ OS_VALIDATE_STD_3( (OS_VALIDATE_ADDRESS_RANGE(elapsed_val, sizeof(TickType)) == TRUE ) , E_OS_ILLEGAL_ADDRESS , OSServiceId_GetElapsedValue, counter_id, val,elapsed_val);/*@req SWS_Os_00051 */ #endif OS_VALIDATE_STD_3( (Os_SysIntAnyDisabled() == FALSE) , E_OS_DISABLEDINT, OSServiceId_GetElapsedValue, counter_id, val,elapsed_val); /* @req SWS_Os_00093 */ /*lint -e{9027} MISRA:FALSE_POSITIVE:Not allowed for string, but operand is boolean:[MISRA 2012 Rule 10.1, required] */ OS_VALIDATE_STD_3( IsCounterValid(counter_id),E_OS_ID, OSServiceId_GetElapsedValue, counter_id, val,elapsed_val); /* @req SWS_Os_00381 */ cPtr = Os_CounterGet(counter_id); OS_VALIDATE_STD_3( (cPtr != NULL), E_OS_PARAM_POINTER, OSServiceId_GetElapsedValue, counter_id, val,elapsed_val); max = Os_CounterGetMaxValue(cPtr); /** @req SWS_Os_00391 */ OS_VALIDATE_STD_3( *val <= max,E_OS_VALUE, OSServiceId_GetElapsedValue, counter_id, val,elapsed_val); #if (OS_APPLICATION_CNT > 1) && (OS_NUM_CORES > 1) if (Os_ApplGetCore(cPtr->applOwnerId) != GetCoreID()) { StatusType status = Os_NotifyCore(Os_ApplGetCore(cPtr->applOwnerId), OSServiceId_GetElapsedValue, counter_id, (int32_t)val, (int32_t)elapsed_val); return status; } #endif (void)GetCounterValue(counter_id,&currTick); /** @req SWS_Os_00382 */ *elapsed_val = Os_CounterDiff(currTick,*val,max); /** @req SWS_Os_00460 */ *val = currTick; return rv; } /* * The OsTick(): * 1. The Decrementer is setup by Os_SysTickStart(period_ticks) * 2. Os_SysTickInit() setup INTC[7] to trigger OsTick * 3. OsTick() then increment counter os_tick_counter if used */ ISR(OsTick) { /* if not used, Os_Arc_OsTickCounter < 0 and ARC_OSTICK is STD_OFF*/ #if (ARC_OSTICK == STD_ON) OsCounterType *cPtr = Os_CounterGet(Os_Arc_OsTickCounter); #if defined(CFG_KERNEL_EXTRA) OsTaskVarType *pcbPtr; imask_t flags; #endif OS_SYS_PTR->tick++; /* @req SWS_Os_00374 * The Operating System module shall handle all the initialization and * configuration of timers used directly by the Operating System module and * not handled by the GPT driver */ cPtr->val = Os_CounterAdd( cPtr->val, Os_CounterGetMaxValue(cPtr), 1 ); #if defined(CFG_KERNEL_EXTRA) Irq_Save(flags); /* Check tasks in the timer queue for API calls with timeout */ LOG_S_S(__func__,"CheckTQ"); if( !Os_TimerQIsEmpty() ) { /* We have timeouts */ pcbPtr = Os_TimerQFirst(); if( pcbPtr->tmo == OS_SYS_PTR->tick ) { LOG_S_S("TMO, rel:", pcbPtr->constPtr->name); ASSERT( (pcbPtr->state & (ST_SLEEPING|ST_WAIT_SEM)) != 0 ); /* We have timeout, so remove the task from the timer queue and make ready */ pcbPtr->rv = E_OS_TIMEOUT; Os_TimerQRemove(pcbPtr); /* ... and add to the ready queue */ Os_TaskMakeReady(pcbPtr); } } Irq_Restore(flags); #endif #if OS_ALARM_CNT!=0 Os_AlarmCheck(cPtr); #endif #if OS_SCHTBL_CNT!=0 Os_SchTblCheck(cPtr); #endif #endif /* ARC_OSTICK == STD_ON */ } TickType GetOsTick( void ) { return OS_SYS_PTR->tick; } /** * Initialize alarms and schedule-tables for the counters */ void Os_CounterInit( void ) { #if OS_ALARM_CNT!=0 { OsCounterType *cPtr; OsAlarmType *aPtr; aPtr = Os_AlarmGet(0); cPtr = aPtr->counter; /*lint -e{9036} MISRA:EXTERNAL_FILE:while(0) allowed to be used in macros:[MISRA 2012 Rule 14.4, required] */ SLIST_INIT(&cPtr->alarm_head); /* Add the alarms to counters */ for (AlarmType i = 0; i < OS_ALARM_CNT; i++) { aPtr = Os_AlarmGet(i); cPtr = aPtr->counter; /*lint -e{9036} MISRA:EXTERNAL_FILE:while(0) allowed to be used in macros:[MISRA 2012 Rule 14.4, required] */ SLIST_INSERT_HEAD(&cPtr->alarm_head, aPtr, alarm_list); } } #endif #if OS_SCHTBL_CNT!=0 { OsCounterType *cPtr; OsSchTblType *sPtr; /* Add the schedule tables to counters */ sPtr = Os_SchTblGet(0); cPtr = sPtr->counter; /*lint -e{9036} MISRA:EXTERNAL_FILE:while(0) allowed to be used in macros:[MISRA 2012 Rule 14.4, required] */ SLIST_INIT(&cPtr->alarm_head); for(ScheduleTableType i = 0; i < OS_SCHTBL_CNT; i++ ) { sPtr = Os_SchTblGet(i); cPtr = sPtr->counter; /*lint -e{9036} MISRA:EXTERNAL_FILE:while(0) allowed to be used in macros:[MISRA 2012 Rule 14.4, required] */ SLIST_INSERT_HEAD(&cPtr->sched_head, sPtr, sched_list); } } #endif }
2301_81045437/classic-platform
system/Os/rtos/src/os_counter.c
C
unknown
14,237
/*-------------------------------- 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 COUNTER_I_H_ #define COUNTER_I_H_ #define COUNTER_TYPE_HARD 0 #define COUNTER_TYPE_SOFT 1 #define COUNTER_UNIT_TICKS 0 #define COUNTER_UNIT_NANO 1 /* STD container : OsCounter * OsCounterMaxAllowedValue: 1 Integer * OsCounterMinCycle: 1 Integer * OsCounterTicksPerBase: 1 Integer * OsCounterType: 1 Enum HARDWARE/SOFTWARE * OsSecondsPerTick: 0..1 Float * OsCounterAccessingApplication: 0..* Ref * OsDriver[C]: 0..1 * OsTimeConstant[C]: 0..* */ typedef struct OsCounter { char name[16]; _Bool type; /* hardware or software counter, SWS OS255 */ _Bool unit; /* Ticks or nano, SWS OS331 */ TickType val; /* The counter value ( if software counter ) */ #if (OS_USE_APPLICATIONS == STD_ON) ApplicationType applOwnerId; uint32 accessingApplMask; /* Application mask, SWS OS317 */ #endif AlarmBaseType alarm_base; OsDriver * driver; /* Used only if we configure a GPT timer as os timer */ SLIST_HEAD(slist,OsAlarm) alarm_head; /* List of alarms this counter is connected to * Overkill ??? Could have list of id's here, * but easier to debug this way */ SLIST_HEAD(sclist,OsSchTbl) sched_head; /* List of schedule-table connected to this counter */ } OsCounterType; #if OS_COUNTER_CNT!=0 extern GEN_COUNTER_HEAD; #endif static inline TickType Os_CounterGetMaxValue(OsCounterType *cPtr ) { return cPtr->alarm_base.maxallowedvalue; } #if (OS_SCHTBL_CNT != 0) static inline TickType Os_CounterGetMinCycle(OsCounterType *cPtr ) { return cPtr->alarm_base.mincycle; } #endif static inline TickType Os_CounterGetValue( OsCounterType *cPtr ) { return cPtr->val; } static inline OsCounterType *Os_CounterGet(CounterType id) { #if OS_COUNTER_CNT!=0 return &counter_list[id]; #else (void)id; return NULL; #endif } static inline ApplicationType Os_CounterGetApplicationOwner( CounterType id ) { ApplicationType rv; #if (OS_COUNTER_CNT != 0) if( id < OS_COUNTER_CNT ) { rv = Os_CounterGet(id)->applOwnerId; } else { /** @req SWS_Os_00274 */ rv = INVALID_OSAPPLICATION; } #else rv = INVALID_OSAPPLICATION; #endif return rv; } static inline TickType Os_CounterDiff( TickType curr, TickType old, TickType max ) { /* + 1 here because there is one tick between OSMAXALLOWEDVALUE and 0. * That is, if curr = 0, max = 9 and old = 0, then the diff should be 10. */ return (curr >= old ) ? (curr - old) : (curr + (max - old) + 1); } /** * Add value to a counter (that have a max value ) * * @param curr The current counter value * @param max The max value of the counter * @param add The value do add * @return */ static inline TickType Os_CounterAdd( TickType curr, TickType max, TickType add ) { TickType diff = max - curr; TickType result; if( add <= diff ) { result = curr + add; } else { /* @req SWS_Os_00384 * The Operating System module shall adjust the read out values of hardware timers (which drive counters) * in such that the lowest value is zero and consecutive reads return an increasing count value until * the timer wraps at its modulus. */ result = add - (max - curr ) - 1; } return result; } void Os_CounterInit( void ); #endif /*COUNTER_I_H_*/
2301_81045437/classic-platform
system/Os/rtos/src/os_counter_i.h
C
unknown
4,384