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 -----------------------------*/
#include "version.h"
const VersionType ArcticCore_Version = {
.string = ARCTIC_CORE_VERSION_STR,
.info = "Arctic Core v" ARCTIC_CORE_VERSION_STR "; Built:" STRSTR__(BUILD_DATE) "; Compiler: " STRSTR__(CC_INFO) " Opt_Flags:" STRSTR__(BUILD_OPT_FLAGS),
.buildDate = STRSTR__(BUILD_DATE),
.optFlags = STRSTR__(BUILD_OPT_FLAGS),
};
|
2301_81045437/classic-platform
|
common/version.c
|
C
|
unknown
| 1,127
|
/*-------------------------------- 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 -----------------------------*/
/*
* Itoa based on K&R itoa
*/
/*lint -w1 Only errors in generic module used during development */
#include <stdlib.h>
/**
* Convert a number to a string
*
* @param val The value to convert
* @param str Pointer to a space where to put the string
* @param base The base
* @param negative If negative or not.
*/
void xtoa( unsigned long val, char* str, int base, int negative) {
int i;
char *oStr = str;
char c;
if (negative) {
val = -val;
}
if( base < 10 && base > 16 ) {
*str = '0';
return;
}
i = 0;
do {
str[i++] = "0123456789abcdef"[ val % base ];
} while ((val /= base) > 0);
if (negative) {
str[i++] = '-';
}
str[i] = '\0';
str = &str[i]-1;
while(str > oStr) {
c = *str;
*str-- = *oStr;
*oStr++=c;
}
}
#if defined(TEST_XTOA)
/* Some very limited testing */
int main( void ) {
char str[20];
xtoa(123,str,10,0);
printf("%s\n",str);
xtoa(-123,str,10,1);
printf("%s\n",str);
xtoa(0xa123,str,16,0);
printf("%s\n",str);
xtoa(-0xa123,str,16,1);
printf("%s\n",str);
return 0;
}
#endif
/**
* Converts an unsigned long to a string
*
* @param value The value to convert
* @param str Pointer to the string
* @param base The base
*/
void ultoa(unsigned long value, char* str, int base) {
xtoa(value, str, base, 0);
}
/**
* Converts an integer to a string
*
* @param value The value to convert
* @param str Pointer to the string to write to
* @param base The base
*/
char * itoa(int value, char* str, int base) {
xtoa(value, str, base, (value < 0));
return str;
}
|
2301_81045437/classic-platform
|
common/xtoa.c
|
C
|
unknown
| 2,537
|
#CanIf
obj-$(USE_CANIF) += CanIf.o
obj-$(USE_CANIF) += CanIf_Cfg.o
pb-obj-$(USE_CANIF) += CanIf_PBCfg.o
pb-pc-file-$(USE_CANIF) += CanIf_Cfg.h CanIf_Cfg.c
vpath-$(USE_CANIF) += $(ROOTDIR)/communication/CanIf/src
inc-$(USE_CANIF) += $(ROOTDIR)/communication/CanIf/inc
|
2301_81045437/classic-platform
|
communication/CanIf/CanIf.mod.mk
|
Makefile
|
unknown
| 276
|
/*-------------------------------- 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 CANIF_H_
#define CANIF_H_
#if defined(USE_PDUR)
#include "PduR.h"
#endif
#if defined(USE_COM)
#include "Com.h"
#endif
/* @req 4.0.3/CANIF672 */
/* @req 4.0.3/CANIF725 */
/* @req 4.0.3/CANIF726 */
/* @req 4.0.3/CANIF727 */
/* @req 4.0.3/CANIF728 */
/* @req 4.0.3/CANIF729 */
/* @req 4.0.3/CANIF456 */
/* @req 4.0.3/CANIF563 */
/* @req 4.0.3/CANIF564 */
/* @req 4.0.3/CANIF659 */
/* @req 4.0.3/CANIF695 */
/* @req 4.0.3/CANIF696 */
/* @req 4.0.3/CANIF697 */
/* @req 4.0.3/CANIF698 */
/* @req 4.0.3/CANIF710 */
/* @req 4.0.3/CANIF730 */
/* @req 4.0.3/CANIF794 */
/* @req 4.0.3/CANIF795 */
/* @req 4.0.3/CANIF796 */
/* @req 4.0.3/CANIF797 */
/* @req 4.0.3/CANIF798 */
/* @req 4.0.3/CANIF800 */
/* @req 4.0.3/CANIF801 */
/* @req 4.0.3/CANIF802 */
/* @req 4.0.3/CANIF803 */
/* @req 4.0.3/CANIF804 */
/* @req 4.0.3/CANIF823 */
/* @req 4.0.3/CANIF824 */
/* @req 4.0.3/CANIF825 */
/* @req 4.0.3/CANIF826 */
/* @req 4.0.3/CANIF827 */
/* @req 4.0.3/CANIF788 */
/* @req 4.0.3/CANIF799 */
/* @req 4.0.3/CANIF814 */
/* @req 4.0.3/CANIF821 */
/* @req 4.0.3/CANIF822 */
/* @req 4.0.3/CANIF712 */
/* @req 4.0.3/CANIF655 */
/* @req 4.0.3/CANIF693 */
/* @req 4.0.3/CANIF694 */
/* @req 4.0.3/CANIF455 */
/* @req 4.0.3/CANIF532 */
/* @req 4.0.3/CANIF224 */
/* @req 4.0.3/CANIF793 */
#define CANIF_VENDOR_ID 60u
#define CANIF_AR_RELEASE_MAJOR_VERSION 4u
#define CANIF_AR_RELEASE_MINOR_VERSION 0u
#define CANIF_AR_RELEASE_REVISION_VERSION 3u
#define CANIF_MODULE_ID 60u
#define CANIF_AR_MAJOR_VERSION CANIF_AR_RELEASE_MAJOR_VERSION
#define CANIF_AR_MINOR_VERSION CANIF_AR_RELEASE_MINOR_VERSION
#define CANIF_AR_PATCH_VERSION CANIF_AR_RELEASE_REVISION_VERSION
#define CANIF_SW_MAJOR_VERSION 5u
#define CANIF_SW_MINOR_VERSION 3u
#define CANIF_SW_PATCH_VERSION 0u
#if defined(USE_DET)
#include "Det.h"
#endif
#include "CanIf_Types.h"/* Part of CANIF643 */
/* @req 4.0.3/CANIF376 */
#include "CanIf_Cfg.h"
#if (( CANIF_CTRL_WAKEUP_SUPPORT == STD_ON ) || (CANIF_TRCV_WAKEUP_SUPPORT == STD_ON))
#include "EcuM.h"
#endif
#if (CANIF_ARC_TRANSCEIVER_API == STD_ON)
#include "CanTrcv.h"
#endif
// Service IDs
#define CANIF_INIT_ID 0x01u
#define CANIF_INIT_CONTROLLER_ID 0x02u
#define CANIF_SET_CONTROLLER_MODE_ID 0x03u
#define CANIF_GET_CONTROLLER_MODE_ID 0x04u
#define CANIF_TRANSMIT_ID 0x05u
#define CANIF_READTXPDUDATA_ID 0x06u
#define CANIF_READTXNOTIFSTATUS_ID 0x07u
#define CANIF_READRXNOTIFSTATUS_ID 0x08u
#define CANIF_SETPDUMODE_ID 0x09u
#define CANIF_GETPDUMODE_ID 0x0Au
#define CANIF_SETDYNAMICTX_ID 0x0Cu
#define CANIF_SET_TRANSCEIVERMODE_ID 0x0Du
#define CANIF_GET_TRANSCEIVERMODE_ID 0x0Eu
#define CANIF_GET_TRCVWAKEUPREASON_ID 0x0Fu
#define CANIF_SET_TRANSCEIVERWAKEMODE_ID 0x10u
#define CANIF_CHECKWAKEUP_ID 0x11u
#define CANIF_CHECKVALIDATION_ID 0x12u
#define CANIF_TXCONFIRMATION_ID 0x13u
#define CANIF_RXINDICATION_ID 0x14u
#define CANIF_CANCELTXCONFIRMATION_ID 0x15u
#define CANIF_CONTROLLER_BUSOFF_ID 0x16u
#define CANIF_TRANSCEIVER_MODE_INDICATION_ID 0x18u
#define CANIF_CONFIRM_PNAVAILABILITY_ID 0x1au
#define CANIF_CLEARTRCVWUFFLAG_ID 0x1eu
#define CANIF_CHECKTRCVWAKEFLAG_ID 0x1fu
#define CANIF_CLEARTRCV_WUFFLAG_INDICATION 0x20u
#define CANIF_CHECKTRCV_WAKEFLAG_INDICATION 0x21
#define CANIF_CONTROLLER_MODE_INDICATION_ID 0x17u
#define CANIF_SETWAKEUPEVENT_ID 0x40u
#define CANIF_ARCERROR_ID 0x41u
/* @req 4.0.3/CANIF116 */
void CanIf_Init(const CanIf_ConfigType *ConfigPtr);
Std_ReturnType CanIf_SetControllerMode(uint8 Controller,
CanIf_ControllerModeType ControllerMode);
Std_ReturnType CanIf_GetControllerMode(uint8 Controller,
CanIf_ControllerModeType *ControllerModePtr);
Std_ReturnType CanIf_Transmit(PduIdType CanTxPduId,
const PduInfoType *PduInfoPtr);
#if ( CANIF_PUBLIC_READRXPDU_DATA_API == STD_ON )
Std_ReturnType CanIf_ReadRxPduData(PduIdType CanRxPduId,
PduInfoType *PduInfoPtr);
#endif
#if ( CANIF_PUBLIC_READTXPDU_NOTIFY_STATUS_API == STD_ON )
CanIf_NotifStatusType CanIf_ReadTxNotifStatus(PduIdType CanTxPduId);
#endif
#if ( CANIF_PUBLIC_READRXPDU_NOTIFY_STATUS_API == STD_ON )
CanIf_NotifStatusType CanIf_ReadRxNotifStatus(PduIdType CanRxPduId);
#endif
Std_ReturnType CanIf_SetPduMode( uint8 Controller, CanIf_PduSetModeType PduModeRequest );
Std_ReturnType CanIf_GetPduMode( uint8 Controller, CanIf_PduGetModeType *PduModePtr );
#if ( CANIF_PUBLIC_SETDYNAMICTXID_API == STD_ON )
void CanIf_SetDynamicTxId( PduIdType CanTxPduId, Can_IdType CanId );
#endif
#if ( CANIF_ARC_TRANSCEIVER_API == STD_ON )
Std_ReturnType CanIf_SetTrcvMode( uint8 TransceiverId, CanTrcv_TrcvModeType TransceiverMode );
Std_ReturnType CanIf_GetTrcvMode( CanTrcv_TrcvModeType *TransceiverModePtr, uint8 TransceiverId);
Std_ReturnType CanIf_GetTrcvWakeupReason( uint8 TransceiverId, CanTrcv_TrcvWakeupReasonType *TrcvWuReasonPtr );
/* @req 4.0.3/CANIF290 */
Std_ReturnType CanIf_SetTrcvWakeupMode(uint8 TransceiverId,CanTrcv_TrcvWakeupModeType TrcvWakeupMode);
#endif
#if ( CANIF_CTRL_WAKEUP_SUPPORT == STD_ON ) || (CANIF_TRCV_WAKEUP_SUPPORT == STD_ON)
Std_ReturnType CanIf_CheckWakeup( EcuM_WakeupSourceType WakeupSource );
#if ( CANIF_PUBLIC_WAKEUP_CHECK_VALIDATION_SUPPORT == STD_ON)
Std_ReturnType CanIf_CheckValidation( EcuM_WakeupSourceType WakeupSource );
#endif
#endif
/* @req 4.0.3/CANIF351 */
#if ( CANIF_PUBLIC_VERSION_INFO_API == STD_ON )
/* @req 4.0.3/CANIF158 */
/* @req 4.0.3/CANIF350 */
/* !req 4.0.3/CANIF658 */
#define CanIf_GetVersionInfo(_vi) STD_GET_VERSION_INFO(_vi,CANIF)
#endif
#if ( CANIF_PUBLIC_CHANGE_BAUDRATE_SUPPORT == STD_ON )
Std_ReturnType CanIf_CheckBaudrate(uint8 ControllerId, const uint16 Baudrate);
Std_ReturnType CanIf_ChangeBaudrate(uint8 ControllerId, const uint16 Baudrate);
#endif
#if ( CANIF_PUBLIC_TXCONFIRM_POLLING_SUPPORT == STD_ON )
CanIf_NotifStatusType CanIf_GetTxConfirmationState( uint8 ControllerId );
#endif
#if ( CANIF_PUBLIC_PN_SUPPORT == STD_ON )
Std_ReturnType CanIf_ClearTrcvWufFlag( uint8 TransceiverId );
Std_ReturnType CanIf_CheckTrcvWakeFlag( uint8 TransceiverId );
#endif
#if (CANIF_PUBLIC_CANCEL_TRANSMIT_SUPPORT == STD_ON)
Std_ReturnType CanIf_CancelTransmit(PduIdType CanTxPduId);
#endif
#if ( CANIF_PUBLIC_PN_SUPPORT == STD_ON )
/* @req 4.0.3/CANIF815 */
void CanIf_ConfirmPnAvailability( uint8 TransceiverId );
/* @req 4.0.3/CANIF762 */
void CanIf_ClearTrcvWufFlagIndication( uint8 TransceiverId );
/* @req 4.0.3/CANIF763 */
void CanIf_CheckTrcvWakeFlagIndication( uint8 TransceiverId );
#endif
#endif /*CANIF_H_*/
|
2301_81045437/classic-platform
|
communication/CanIf/inc/CanIf.h
|
C
|
unknown
| 7,822
|
/*-------------------------------- 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 CANIF_CBK_H_
#define CANIF_CBK_H_
/* Some external MCALs needs this (Cypress,etc) */
#if defined(CFG_MCAL_EXTERNAL)
#include "CanIf_Types.h"
#endif
/* @req CANIF409 */
void CanIf_TxConfirmation( PduIdType canTxPduId );
#if defined(CFG_CANIF_ASR_4_3_1)
void CanIf_RxIndication (const Can_HwType* Mailbox, const PduInfoType* PduInfoPtr);
#else
void CanIf_RxIndication( Can_HwHandleType Hrh, Can_IdType CanId, uint8 CanDlc, const uint8 *CanSduPtr );
#endif
void CanIf_CancelTxConfirmation(PduIdType canTxPduId, const PduInfoType *pduInfoPtr);
void CanIf_ControllerBusOff( uint8 Controller );
void CanIf_SetWakeupEvent( uint8 Controller );
#if ( CANIF_PUBLIC_PN_SUPPORT == STD_ON )
void CanIf_ConfirmPnAvailability( uint8 TransceiverId );
void CanIf_ClearTrcvWufFlagIndication( uint8 TransceiverId );
void CanIf_CheckTrcvWakeFlagIndication( uint8 TransceiverId );
#endif
#if ( CANIF_ARC_TRANSCEIVER_API == STD_ON )
/* @req 4.0.3/CANIF764 */
void CanIf_TrcvModeIndication( uint8 TransceiverId, CanTrcv_TrcvModeType TransceiverMode );
#endif
/* ArcCore extensions */
/* CANIF699 */
void CanIf_ControllerModeIndication( uint8 ControllerId, CanIf_ControllerModeType ControllerMode);
#endif /*CANIF_CBK_H_*/
|
2301_81045437/classic-platform
|
communication/CanIf/inc/CanIf_Cbk.h
|
C
|
unknown
| 2,016
|
/*-------------------------------- 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 -----------------------------*/
/** @addtogroup CanIf CAN Interface
* @{ */
/** @file CanIf_ConfigTypes.h
* Definitions of configuration parameters for CAN Interface.
*/
#ifndef CANIF_CONFIGTYPES_H_
#define CANIF_CONFIGTYPES_H_
#include "EcuM_Types.h"
#define NO_UPPER_LAYER_PDU 0xFFFFu
/** Type of the upper layer interfacing this module */
typedef enum {
CANIF_USER_TYPE_CAN_NM,
CANIF_USER_TYPE_CAN_TP,
CANIF_USER_TYPE_CAN_PDUR,
CANIF_USER_TYPE_J1939TP,
CANIF_USER_TYPE_CAN_SPECIAL
} CanIf_UserTypeType;
/** Defines if PDU Can id can be changed at runtime. */
typedef enum {
CANIF_PDU_TYPE_STATIC = 0,
CANIF_PDU_TYPE_DYNAMIC /**< Not supported */
} CanIf_PduTypeType;
/** PDU Can id type */
typedef enum {
CANIF_CAN_ID_TYPE_29 = 0,
CANIF_CAN_FD_ID_TYPE_29,
CANIF_CAN_ID_TYPE_11,
CANIF_CAN_FD_ID_TYPE_11
} CanIf_CanIdTypeType;
/** Defining if the CanIf PDU is referring a basic or full CAN Hardware object */
typedef enum {
CANIF_HANDLE_TYPE_BASIC,
CANIF_HANDLE_TYPE_FULL
} CanIf_HohType;
//-------------------------------------------------------------------
/*
* CanIfHrhRangeConfig container
*/
/** Parameters for configuring Can id ranges. Not supported. */
typedef struct {
/** Lower CAN Identifier of a receive CAN L-PDU for identifier range
* definition, in which all CAN Ids shall pass the software filtering. Range: 11
* Bit for Standard CAN Identifier 29 Bit for Extended CAN Identifer */
uint32 CanIfRxPduLowerCanId;
/** Upper CAN Identifier of a receive CAN L-PDU for identifier range
* definition, in which all CAN Ids shall pass the software filtering. Range: 11
* Bit for Standard CAN Identifier 29 Bit for Extended CAN Identifer */
uint32 CanIfRxPduUpperCanId;
} CanIf_HrhRangeConfigType;
//-------------------------------------------------------------------
/*
* CanIfRxPduConfig container
*/
/** Definition of Rx PDU (Protocol Data Unit). */
typedef struct {
/** CAN Identifier of Receive CAN L-PDUs used by the CAN Interface. These are used
* both for single ids and for ranges.
* Exa: Software Filtering. Range: 11 Bit For Standard CAN Identifier ... 29 Bit For
* Extended CAN identifier */
uint32 CanIfCanRxPduLowerCanId;
uint32 CanIfCanRxPduUpperCanId;
/** Index into CanIfUserCddIndidcations specifying indication services to target
* upper layers (PduRouter, CanNm, CanTp and ComplexDeviceDrivers). If parameter
* is NO_FUNCTION_CALLOUT no call-out function is configured. */
uint32 CanIfUserRxIndication;
/** ECU wide unique, symbolic handle for receive CAN L-PDU. The
* CanRxPduId is configurable at pre-compile and post-built time. It shall fulfill
* ANSI/AUTOSAR definitions for constant defines. Range: 0..max. number
* of defined CanRxPduIds */
PduIdType CanIfCanRxPduId;
/** Data Length code of received CAN L-PDUs used by the CAN Interface.
* Exa: DLC check. The data area size of a CAN L-PDU can have a range
* from 0 to 8 bytes. uint8 CanIfCanRxPduDlc; */
uint8 CanIfCanRxPduDlc;
#if ( CANIF_CANPDUID_READDATA_API == STD_ON )
/** Enables and disables the Rx buffering for reading of received L-PDU data.
* True: Enabled False: Disabled */
boolean CanIfReadRxPduData;
#endif
#if ( CANIF_READRXPDU_NOTIF_STATUS_API == STD_ON )
/** CanIfReadRxPduNotifyStatus {CANIF_READRXPDU_NOTIFY_STATUS}
* Enables and disables receive indication for each receive CAN L-PDU for
* reading its' notification status. True: Enabled False: Disabled */
boolean CanIfReadRxPduNotifyStatus;
#endif
/* CanId Extended or Standard */
boolean CanIdIsExtended;
#if (CANIF_OSEKNM_SUPPORT == STD_ON)
/* Check if an indication to OsekNm is required */
boolean OsekNmRxIndicationSupport;
#endif
} CanIf_RxPduConfigType;
//-------------------------------------------------------------------
/*
* CanIfInitHrhConfig container
*/
/** Definition of Hardware Receive Handle */
typedef struct {
/** Defines the HRH type i.e, whether its a BasicCan or FullCan. If BasicCan is
* configured, software filtering is enabled. */
CanIf_HohType CanIfHrhType;
/** Selects the hardware receive objects by using the HRH range/list from
* CAN Driver configuration to define, for which HRH a software filtering has
* to be performed at during receive processing. True: Software filtering is
* enabled False: Software filtering is disabled */
boolean CanIfSoftwareFilterHrh;
/** Reference to controller Id to which the HRH belongs to. A controller can
* contain one or more HRHs. */
CanIf_Arc_ChannelIdType CanIfHrhCanCtrlIdRef;
/** Defines the parameters required for configuring multiple
* CANID ranges for a given same HRH. */
const CanIf_HrhRangeConfigType *CanIfHrhRangeConfig;
const CanIf_RxPduConfigType* RxPduList;
uint16 NofRxPdus;
} CanIf_HrhConfigType;
//-------------------------------------------------------------------
/*
* CanIfInitHthConfig container
*/
/** Definition of Hardware Transmit Handle */
typedef struct {
/** Defines the HTH type i.e, whether its a BasicCan or FullCan. */
CanIf_HohType CanIfHthType;
/** Reference to controller Id to which the HTH belongs to. A controller
* can contain one or more HTHs */
CanIf_Arc_ChannelIdType CanIfCanControllerIdRef;
/** The parameter refers to a particular HTH object in the CAN Driver Module
* configuration. The HTH id is unique in a given CAN Driver. The HTH Ids
* are defined in the CAN Driver Module and hence it is derived from CAN
* Driver Configuration. */
Can_HwHandleType CanIfHthIdSymRef ;
} CanIf_HthConfigType;
//-------------------------------------------------------------------
/*
* CanIfInitHohConfig container
*/
/** Definition of Hardware Object Handle. */
typedef struct {
/** This container contains contiguration parameters for each hardware receive object. */
const CanIf_HrhConfigType *CanIfHrhConfig;
/** This container contains parameters releated to each HTH */
const CanIf_HthConfigType *CanIfHthConfig;
const uint16 *CanHohToCanIfHrhMap;
uint32 HrhListSize;
} CanIf_InitHohConfigType;
//-------------------------------------------------------------------
/*
* CanIfTxBuffer container
*/
/** Definition of Tx Buffer. */
typedef struct {
const CanIf_HthConfigType *CanIfBufferHthRef;
uint16 CanIfBufferSize;
uint8 CanIf_Arc_BufferId;
} CanIf_TxBufferConfigType;
//-------------------------------------------------------------------
/*
* CanIfTxPduConfig container
*/
typedef void (*CanIfUserTxConfirmationType)(PduIdType);
typedef void (*CanIfUserRxIndicationType)(PduIdType , PduInfoType*);
typedef void (*CanIfBusOffNotificationType)(uint8 Controller);
typedef void (*CanIfWakeUpNotificationType)();
typedef void (*CanIfWakeupValidNotificationType)();
typedef void (*CanIfControllerModeIndicationType)(uint8 ControllerId, CanIf_ControllerModeType ControllerMode);
#if !defined(CFG_MCAL_EXTERNAL)
typedef void (*CanIfErrorNotificatonType)(uint8,Can_Arc_ErrorType);
#endif
#define NO_FUNCTION_CALLOUT 0xFFFFFFFF
/** Definition of Tx PDU (Protocol Data Unit). */
typedef struct {
/** Reference to buffer which defines the hardware object or the pool of hardware objects
* configured for transmission. The buffer refers HTH Id, to which the L-
* PDU belongs to. */
const CanIf_TxBufferConfigType *CanIfTxPduBufferRef;
/** Index into CanIfUserCddConfirmations specifying indication services to target
* upper layers (PduRouter, CanNm, CanTp and ComplexDeviceDrivers). If parameter
* is NO_FUNCTION_CALLOUT no call-out function is configured. */
uint32 CanIfUserTxConfirmation;
/** CAN Identifier of transmit CAN L-PDUs used by the CAN Driver for CAN L-
* PDU transmission. Range: 11 Bit For Standard CAN Identifier ... 29 Bit For
* Extended CAN identifier */
uint32 CanIfCanTxPduIdCanId;
/** ECU wide unique, symbolic handle for transmit CAN L-PDU. The
* CanIfCanTxPduId is configurable at pre-compile and post-built time.
* Range: 0..max. number of CantTxPduIds PduIdType CanTxPduId; */
PduIdType CanIfTxPduId;
/** CAN Identifier of transmit CAN L-PDUs used by the CAN Driver for CAN L-
* PDU transmission.
* EXTENDED_CAN The CANID is of type Extended (29 bits).
* STANDARD_CAN The CANID is of type Standard (11 bits). */
CanIf_CanIdTypeType CanIfTxPduIdCanIdType;
/** Defines the type of each transmit CAN L-PDU.
* DYNAMIC CAN ID is defined at runtime.
* STATIC CAN ID is defined at compile-time. */
CanIf_PduTypeType CanIfCanTxPduType;
/** Data length code (in bytes) of transmit CAN L-PDUs used by the CAN
* Driver for CAN L-PDU transmission. The data area size of a CAN L-Pdu
* can have a range from 0 to 8 bytes. */
uint8 CanIfCanTxPduIdDlc;
#if ( CANIF_READTXPDU_NOTIFY_STATUS_API == STD_ON )
/** Enables and disables transmit confirmation for each transmit CAN L-PDU
* for reading its notification status. True: Enabled False: Disabled */
boolean CanIfReadTxPduNotifyStatus;
#endif
/** PDU that is allowed by PN filter */
boolean CanIfTxPduPnFilterEnable;
#if (CANIF_OSEKNM_SUPPORT == STD_ON)
/* OsekNm Tx confirmation required */
boolean OsekNmTxConfirmationSupport;
#endif
} CanIf_TxPduConfigType;
//-------------------------------------------------------------------
/*
* CanIf_TransceiverChannelConfig container
*/
typedef struct {
/* Wake up support indication */
boolean CanIfTrcvWakeupSupport;
/* Reference to underlying Can Transceiver unit */
uint8 CanIfTrcvCanTrcvIdRef;
/* Symbolic name for CanIf transceiver channel */
uint8 CanIfTrcvId;
/* Wakeup Source for the relevant channel if available*/
EcuM_WakeupSourceType CanIfTrcvCanTrcvWakeupSrc;
/* Reference to related CanIfCtrl channel */
uint8 CanIfTrcvChnlToCanIfCtrlChnlRef;
} CanIf_TransceiverChannelConfigType;
/** Callout functions with respect to the upper layers. This callout functions
* defined in this container are common to all configured underlying CAN
* Drivers / CAN Transceiver Drivers. */
typedef struct {
/** Name of target BusOff notification services to target upper layers
* (PduRouter, CanNm, CanTp and ComplexDeviceDrivers). */
void (*CanIfBusOffNotification)(uint8 Controller);
/** Name of target wakeup notification services to target upper layers
* e.g Ecu_StateManager. If parameter is 0
* no call-out function is configured. */
void (*CanIfWakeUpNotification)();
/** Name of target wakeup validation notification services to target upper
* layers (ECU State Manager). If parameter is 0 no call-out function is
* configured. */
void (*CanIfWakeupValidNotification)();
/** Name of target controller mode indication services to target upper
* layers (CanSm). If parameter is 0 no call-out function is
* configured. */
void (*CanIfControllerModeIndication)(uint8 ControllerId, CanIf_ControllerModeType ControllerMode);
/** ArcCore ext. */
#if !defined(CFG_MCAL_EXTERNAL)
void (*CanIfErrorNotificaton)(uint8,Can_Arc_ErrorType);
#endif
#if defined (USE_CANTRCV)
/** Notification when Transceiver wake up flag is set */
void (*CanIfTrcvWakeFlagNotification)(uint8 Transceiver);
/** Notification when Transceiver wake up flag is cleared */
void (*CanIfTrcvClearWakeFlagNotification)(uint8 Transceiver);
/** Notification when PN communication mode is available */
void (*CanIfTrcvConfirmPnAvailabilityNotification)(uint8 TransceiverId);
/** Notification when transceiver mode changes */
void(*CanIfTrcvModeChangeNotification)( uint8 TransceiverId, CanTrcv_TrcvModeType TransceiverMode );
#endif /* USE_CANTRCV */
} CanIf_DispatchConfigType;
/** This container contains the references to the configuration setup of each
* underlying CAN driver. */
typedef struct {
/** Not used. */
uint32 CanIfConfigSet;
/** Size of Rx PDU list. */
uint32 CanIfNumberOfCanRxPduIds;
/** Size of Tx PDU list. */
uint32 CanIfNumberOfCanTXPduIds;
/** Not used */
uint32 CanIfNumberOfDynamicCanTXPduIds;
uint16 CanIfNumberOfTxBuffers;
//
// Containers
//
/* Tx Buffer List */
const CanIf_TxBufferConfigType *CanIfBufferCfgPtr;
/** Hardware Object Handle list */
const CanIf_InitHohConfigType *CanIfHohConfigPtr;
/** Rx PDU's list */
const CanIf_RxPduConfigType *CanIfRxPduConfigPtr;
/** Tx PDU's list */
#if (CANIF_ARC_RUNTIME_PDU_CONFIGURATION == STD_OFF)
const CanIf_TxPduConfigType *CanIfTxPduConfigPtr;
#else
CanIf_TxPduConfigType *CanIfTxPduConfigPtr;
#endif
} CanIf_InitConfigType;
/*
*
*/
/** CanIf channel configuration */
typedef struct {
const CanIf_TxBufferConfigType* const *TxBufferRefList;
const CanIf_RxPduConfigType* RxPduList;
uint16 NofRxPdus;
EcuM_WakeupSourceType CanIfCtrlWakeUpSrc;
uint8 CanControllerId;
uint8 NofTxBuffers;
#if (CANIF_OSEKNM_SUPPORT == STD_ON)
uint8 CanIfOsekNmNetId; /* OsekNm network identifier */
uint8 CanIfOsekNmNodeIdMask; /* OsekNM source node Id mask */
#endif
boolean CanIfCtrlWakeUpSupport;
/** Whether PN filter is required for the controller */
boolean CanIfCtrlPnFilterSet;
} CanIf_Arc_ChannelConfigType;
/** Top level config container. */
/* !req 4.0.3/CANIF523 */
typedef struct {
/** This container contains the init parameters of the CAN Interface. */
const CanIf_InitConfigType *InitConfig;
/** Reference to tranceiver channel list */
const CanIf_TransceiverChannelConfigType *CanIfTransceiverConfig;
/** ArcCore: Contains channel config (including the mapping from CanIf-specific Channels to Can Controllers) */
const CanIf_Arc_ChannelConfigType *Arc_ChannelConfig;
} CanIf_ConfigType;
#endif /* CANIF_CONFIGTYPES_H_ */
/** @} */
|
2301_81045437/classic-platform
|
communication/CanIf/inc/CanIf_ConfigTypes.h
|
C
|
unknown
| 15,256
|
/*-------------------------------- 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 "MemMap.h"
|
2301_81045437/classic-platform
|
communication/CanIf/inc/CanIf_MemMap.h
|
C
|
unknown
| 773
|
/*-------------------------------- 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 -----------------------------*/
/* !req 4.0.3/CANIF643 *//* Types not defined here */
/** @addtogroup CanIf CAN Interface
* @{ */
/** @file CanIf_Types.h
* Definitions of configuration parameters for CAN Interface.
*/
#ifndef CANIF_TYPES_H_
#define CANIF_TYPES_H_
#include "ComStack_Types.h"
// API service with wrong parameter
/** @name Error Codes */
//@{
/* @req 4.0.3/CANIF154 */
#define CANIF_E_PARAM_CANID 10u
#define CANIF_E_PARAM_DLC 11u
#define CANIF_E_PARAM_HRH 12u
#define CANIF_E_PARAM_LPDU 13u
#define CANIF_E_PARAM_CONTROLLER 14u
#define CANIF_E_PARAM_CONTROLLERID 15u
#define CANIF_E_PARAM_WAKEUPSOURCE 16u
#define CANIF_E_PARAM_TRCV 17u
#define CANIF_E_PARAM_TRCVMODE 18u
#define CANIF_E_PARAM_TRCVWAKEUPMODE 19u
#define CANIF_E_PARAM_CTRLMODE 21u
#define CANIF_E_PARAM_POINTER 20u
#define CANIF_E_UNINIT 30u
//#define CANIF_E_NOK_NOSUPPORT 40u
#define CANIF_E_INVALID_TXPDUID 50u
#define CANIF_E_INVALID_RXPDUID 60u
#define CANIF_E_INVALID_DLC 61u
#define CANIF_E_STOPPED 70u
#define CANIF_E_NOT_SLEEP 71u
//@}
typedef enum {
/** UNINIT mode. Default mode of the CAN driver and all
* CAN controllers connected to one CAN network after
* power on. */
CANIF_CS_UNINIT = 0,
/** STOPPED mode. At least one of all CAN controllers
* connected to one CAN network are halted and does
* not operate on the bus. */
CANIF_CS_STOPPED,
/** STARTED mode. All CAN controllers connected to
* one CAN network are started by the CAN driver and
* in full-operational mode. */
CANIF_CS_STARTED,
/** SLEEP mode. At least one of all CAN controllers
* connected to one CAN network are set into the
* SLEEP mode and can be woken up by request of the
* CAN driver or by a network event (must be supported
* by CAN hardware) */
CANIF_CS_SLEEP
} CanIf_ControllerModeType;
/** Status of the PDU channel group. Current mode of the channel defines its
* transmit or receive activity. Communication direction (transmission and/or
* reception) of the channel can be controlled separately or together by upper
* layers. */
typedef enum {
/** Channel shall be set to the offline mode
* => no transmission and reception */
CANIF_SET_OFFLINE = 0,
/** Receive path of the corresponding channel
* shall be disabled */
CANIF_SET_RX_OFFLINE,
/** Receive path of the corresponding channel
* shall be enabled */
CANIF_SET_RX_ONLINE,
/** Transmit path of the corresponding channel
* shall be disabled */
CANIF_SET_TX_OFFLINE,
/** Transmit path of the corresponding channel
* shall be enabled */
CANIF_SET_TX_ONLINE,
/** Channel shall be set to online mode
* => full operation mode */
CANIF_SET_ONLINE,
/** Transmit path of the corresponding channel
* shall be set to the offline active mode
* => notifications are processed but transmit
* requests are blocked. */
CANIF_SET_TX_OFFLINE_ACTIVE
} CanIf_PduSetModeType;
typedef enum {
/** Channel is in the offline mode ==> no transmission or reception */
CANIF_GET_OFFLINE = 0,
/** Receive path of the corresponding channel is enabled and
* transmit path is disabled */
CANIF_GET_RX_ONLINE,
/** Transmit path of the corresponding channel is enabled and
* receive path is disabled */
CANIF_GET_TX_ONLINE,
/** Channel is in the online mode ==> full operation mode */
CANIF_GET_ONLINE,
/** Transmit path of the corresponding channel is in
* the offline mode ==> transmit notifications are processed but
* transmit requests are blocked. The receiver path is disabled. */
CANIF_GET_OFFLINE_ACTIVE,
/** Transmit path of the corresponding channel is in the offline
* active mode ==> transmit notifications are processed but transmit
* requests are blocked. The receive path is enabled. */
CANIF_GET_OFFLINE_ACTIVE_RX_ONLINE
} CanIf_PduGetModeType;
typedef enum {
/** No transmit or receive event occurred for
* the requested L-PDU. */
CANIF_NO_NOTIFICATION = 0,
/** The requested Rx/Tx CAN L-PDU was
* successfully transmitted or received. */
CANIF_TX_RX_NOTIFICATION
} CanIf_NotifStatusType;
typedef enum {
/** Transceiver mode NORMAL */
CANIF_TRCV_MODE_NORMAL = 0,
/** Transceiver mode STANDBY */
CANIF_TRCV_MODE_STANDBY,
/** Transceiver mode SLEEP */
CANIF_TRCV_MODE_SLEEP
} CanIf_TrcvModeType;
typedef enum {
/** Due to an error wake up reason was not detected.
* This value may only be reported when error was
* reported to DEM before. */
CANIF_TRCV_WU_ERROR = 0,
/** The transceiver does not support any information
* for the wakeup reason. */
CANIF_TRCV_WU_NOT_SUPPORTED,
/** The transceiver has detected, that the network has
* caused the wake up of the ECU */
CANIF_TRCV_WU_BY_BUS,
/** The transceiver detected, that the network has woken
* the ECU via a request to NORMAL mode */
CANIF_TRCV_WU_INTERNALLY,
/** The transceiver has detected, that the "wake up"
* is due to an ECU reset */
CANIF_TRCV_WU_RESET,
/** The transceiver has detected, that the "wake up"
* is due to an ECU reset after power on. */
CANIF_TRCV_WU_POWER_ON
} CanIf_TrcvWakeupReasonType;
typedef enum {
/** The notification for wakeup events is enabled
* on the addressed network. */
CANIF_TRCV_WU_ENABLE = 0,
/** The notification for wakeup events is disabled
* on the addressed network. */
CANIF_TRCV_WU_DISABLE,
/** A stored wakeup event is cleared on the addressed network */
CANIF_TRCV_WU_CLEAR
} CanIf_TrcvWakeupModeType;
#endif /*CANIF_TYPES_H_*/
/** @} */
/** @} */
|
2301_81045437/classic-platform
|
communication/CanIf/inc/CanIf_Types.h
|
C
|
unknown
| 6,842
|
/*-------------------------------- 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 -----------------------------*/
/*----------------------------[information]----------------------------------
* Author: mahi/hebe
*
* Part of Release:
* 4.0.3
*
* Description:
* Implements the Can Interface
*
* Support:
* Private Have Support
* ---------------------------------------------------------------
* CANIF_[PRIVATE_]DLC_CHECK Y 4.0.3
* CANIF_[PRIVATE_]SOFTWARE_FILTER_TYPE N 4.0.3
* CANIF_NUMBER_OF_TXBUFFERS N 3.1.5
* CANIF_PRIVATE_SUPPORT_TTCAN N 4.0.3
*
*
* Public Have Support
* ----------------------------------------------------------------
* CANIF_[PUBLIC_]DEV_ERROR_DETECT Y 4.0.3
* CANIF_[PUBLIC_]MULTIPLE_DRIVER_SUPPORT N 4.0.3
* CANIF_[PUBLIC_]NUMBER_OF_CAN_HW_UNITS N 3.1.5
* CANIF_PUBLIC_TXCONFIRM_POLLING_SUPPORT N 4.0.3
* CANIF_[PUBLIC_]READRXPDU_DATA_API N 4.0.3
* CANIF_[PUBLIC_]READRXPDU_NOTIF_STATUS_API N 4.0.3
* CANIF_[PUBLIC_]READTXPDU_NOTIF_STATUS_API N 4.0.3
* CANIF_[PUBLIC_]SETDYNAMICTXID_API N 4.0.3
* CANIF_[PUBLIC_]VERSION_INFO_API Y 4.0.3
*
* CANIF_PUBLIC_CANCEL_TRANSMIT_SUPPORT N 4.0.3
* CANIF_PUBLIC_CDD_HEADERFILE N 4.0.3
* CANIF_PUBLIC_HANDLE_TYPE_ENUM N 4.0.3
* CANIF_PUBLIC_TX_BUFFERING Y 4.0.3
* CANIF_PUBLIC_WAKEUP_CHECK_VALIDATION_API Y 4.0.3
* CANIF_PUBLIC_WAKEUP_CHECK_VALID_BY_NM N 4.0.3
*
* Implementation Notes:
* Channels:
* The specification speaks a lot of channels and it's sometimes confusing
* This implementations interpretation is:
* - Physical Channel
* One physical channel is connected to one CAN controller and one CAN
* transceiver. One or more physical channels may be connected to a single
* network (the physical CAN network)
*
* physical channel physical channel
* | |
* CAN_B CAN_D
* | |
* + NETWORK +
*
*
* Since the CAN controller Id is logical controller Id (e.g. id=0 is CAN_C) channel
* is equal to controllerId in the implementation.
*
* Drivers:
* There is only support for one driver and that is the on-chip CAN.
*
* Configuration:
* 3.1.5 CANIF_NUMBER_OF_TXBUFFERS is defined to be the same as for 4.x, ie
* only have 1 buffer for each L-PDU. In 3.1.5 this was setable.
*
*
*
*/
/* General requirements */
/* @req 4.0.3/CANIF023 *//* CanIf shall avoid direct access to hardware buffers and shall access it exclusively via the CanDrv interface services */
/* @req 4.0.3/CANIF064 *//* Interrupts are disabled when buffers accessed */
/* !req 4.0.3/CANIF142 *//* Not all types imported */
/* ----------------------------[includes]------------------------------------*/
#include "Std_Types.h"
#include "CanIf.h"
#include "CanIf_ConfigTypes.h"
#include <string.h>
#include "arc_assert.h"
#include "SchM_CanIf.h"
#if ( CANIF_PUBLIC_DEV_ERROR_DETECT == STD_ON )
#include "Det.h"
#endif
#if defined(USE_DEM)
/* @req 4.0.3/CANIF150 */
#include "Dem.h"
#endif
#if (CANIF_OSEKNM_SUPPORT == STD_ON)
#include "OsekNm.h"
#endif
/* ----------------------------[Version check]------------------------------*/
#if !(((CANIF_SW_MAJOR_VERSION == 5) && (CANIF_SW_MINOR_VERSION == 3)) )
#error CanIf: Expected BSW module version to be 5.3.*
#endif
/* @req 4.0.3/CANIF021 */
#if !(((CANIF_AR_RELEASE_MAJOR_VERSION == 4) && (CANIF_AR_RELEASE_MINOR_VERSION == 0)) )
#error CanIf: Expected AUTOSAR version to be 4.0.*
#endif
/* ----------------------------[Config check]------------------------------*/
#if (CANIF_CTRLDRV_TX_CANCELLATION == STD_ON) && (CANIF_PUBLIC_TX_BUFFERING == STD_OFF)
#error CanIf: Tx cancellation cannot be enabled without enabling tx buffering
#endif
/* ----------------------------[private define]------------------------------*/
#define EXTENDED_CANID_MAX 0x1FFFFFFF
#define STANDARD_CANID_MAX 0x7FF
#define EXT_ID_BIT_POS 31
#define CAN_FD_BIT_POS 30 /* @req 4.3.0/CAN416 */
#define EXT_ID_STD_ID_START_BIT 18
#define INVALID_CANID 0xFFFFFFFF
#define FEATURE_NOT_SUPPORTED 0
/* ----------------------------[private macro]-------------------------------*/
#if ( CANIF_PUBLIC_DEV_ERROR_DETECT == STD_ON )
/* @req 4.0.3/CANIF018 */
/* @req 4.0.3/CANIF019 */
/* @req 4.0.3/CANIF156 */
#define DET_REPORT_ERROR(_api, _error) \
do { \
(void)Det_ReportError(CANIF_MODULE_ID, 0, _api, _error); \
} while(0)
#else
#define DET_REPORT_ERROR(_api,_err)
#endif
#define IS_EXTENDED_CAN_ID(_x) (0 != (_x & (1ul<<EXT_ID_BIT_POS)))
#define IS_CANFD(_x) (0 != (_x & (1ul<<CAN_FD_BIT_POS)))
#define VALIDATE_NO_RV(_exp,_api,_err ) \
if( !(_exp) ) { \
DET_REPORT_ERROR(_api, _err); \
return; \
}
#define VALIDATE_RV(_exp,_api,_err,_ret ) \
if( !(_exp) ) { \
DET_REPORT_ERROR(_api, _err); \
return (_ret); \
}
#define IS_VALID_CONTROLLER_MODE(_x) \
((CANIF_CS_STARTED == (_x)) || \
(CANIF_CS_SLEEP == (_x)) || \
(CANIF_CS_STOPPED == (_x)))
// Helper to get the Can Controller refered to by a CanIf Channel
/* IMPROVMENT: Could we handle this in another way?
* */
#define ARC_GET_CHANNEL_CONTROLLER(_channel) \
CanIf_ConfigPtr->Arc_ChannelConfig[_channel].CanControllerId
/* Map from CanIfTransceiverId to CanTransceiverId */
#define ARC_GET_CAN_TRANSCEIVERID(_id) \
CanIf_ConfigPtr->CanIfTransceiverConfig[_id].CanIfTrcvCanTrcvIdRef
/* ----------------------------[private typedef]-----------------------------*/
typedef void (*RxIndicationCbType)(PduIdType , const PduInfoType*);
typedef struct
{
CanIf_ControllerModeType ControllerMode;
CanIf_PduGetModeType PduMode;
#if (CANIF_PUBLIC_PN_SUPPORT == STD_ON)
/* @req 4.0.3/CANIF747 */
boolean pnTxFilterEnabled;
#endif
#if (CANIF_PUBLIC_WAKEUP_CHECK_VALIDATION_SUPPORT == STD_ON)
boolean firstRxIndication;
#endif
} CanIf_ChannelPrivateType;
#if (CANIF_ARC_TRANSCEIVER_API == STD_ON)
typedef struct
{
CanTrcv_TrcvModeType trcvMode;
} CanIf_TrcvPrivateType;
#endif
typedef struct
{
boolean initRun;
CanIf_ChannelPrivateType channelData[CANIF_CHANNEL_CNT];
#if (CANIF_ARC_TRANSCEIVER_API == STD_ON)
CanIf_TrcvPrivateType trcvData[CANIF_TRANSCEIVER_CHANNEL_CNT];
#endif
} CanIf_GlobalType;
typedef struct {
PduIdType pduId;
Can_IdType canId;
#if (CANIF_CANFD_SUPPORT == STD_ON)
uint8 data[64];// For flexible datarate data
#else
uint8 data[8];
#endif
uint8 dlc;
} CanIf_LPduType;
#if (CANIF_PUBLIC_TX_BUFFERING == STD_ON)
typedef struct {
/**/
CanIf_LPduType lPdu;
boolean inUse;
}CanIf_Arc_BufferEntryType;
#define CANIF_START_SEC_VAR_CLEARED_UNSPECIFIED
#include "CanIf_MemMap.h"
static CanIf_Arc_BufferEntryType TxPduBuffer[CANIF_ARC_MAX_NUM_LPDU_TX_BUF];
#define CANIF_STOP_SEC_VAR_CLEARED_UNSPECIFIED
#include "CanIf_MemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/
#endif
/* ----------------------------[private function prototypes]-----------------*/
/* ----------------------------[private variables]---------------------------*/
#if (CANIF_PUBLIC_TX_BUFFERING == STD_ON)
/* Mapping from buffer index to start index in the L-PDU buffer */
#define CANIF_START_SEC_VAR_CLEARED_UNSPECIFIED
#include "CanIf_MemMap.h"
static uint16 BufferStartIndex[CANIF_ARC_MAX_NOF_TX_BUFFERS];
#define CANIF_STOP_SEC_VAR_CLEARED_UNSPECIFIED
#include "CanIf_MemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/
#endif
#define CANIF_START_SEC_VAR_CLEARED_UNSPECIFIED
#include "CanIf_MemMap.h"
CanIf_GlobalType CanIf_Global;
#define CANIF_STOP_SEC_VAR_CLEARED_UNSPECIFIED
#include "CanIf_MemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/
/* Global configure */
#define CANIF_START_SEC_VAR_CLEARED_UNSPECIFIED
#include "CanIf_MemMap.h"
static const CanIf_ConfigType *CanIf_ConfigPtr;
#define CANIF_STOP_SEC_VAR_CLEARED_UNSPECIFIED
#include "CanIf_MemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/
#if ( CANIF_PUBLIC_READRXPDU_DATA_API == STD_ON ) && FEATURE_NOT_SUPPORTED
static CanIf_LPduType RxBuffer[CANIF_NUM_RX_LPDU];
#endif
#if ( CANIF_PUBLIC_READTXPDU_NOTIFY_STATUS_API == STD_ON ) && FEATURE_NOT_SUPPORTED
/* !req 4.0.3/CANIF472 */
#define CANIF_START_SEC_VAR_CLEARED_UNSPECIFIED
#include "CanIf_MemMap.h"
CanIf_NotifStatusType TxNotifStatusBuffer[CANIF_NUM_RX_LPDU];
#define CANIF_STOP_SEC_VAR_INIT_UNSPECIFIED
#include "CanIf_MemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/
#endif
#if ( CANIF_PUBLIC_READRXPDU_NOTIFY_STATUS_API == STD_ON ) && FEATURE_NOT_SUPPORTED
/* !req 4.0.3/CANIF473 */
#define CANIF_START_SEC_VAR_CLEARED_UNSPECIFIED
#include "CanIf_MemMap.h"
CanIf_NotifStatusType RxNotifStatusBuffer[CANIF_NUM_TX_LPDU];
#define CANIF_STOP_SEC_VAR_INIT_UNSPECIFIED
#include "CanIf_MemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/
#endif
/* Declared in Can_Cfg.c */
extern const CanIfUserRxIndicationType CanIfUserRxIndications[];
extern const CanIfUserTxConfirmationType CanIfUserTxConfirmations[];
extern const CanIf_DispatchConfigType CanIfDispatchConfig;
/* ----------------------------[private functions]---------------------------*/
#if (CANIF_OSEKNM_SUPPORT == STD_ON)
void canIfOsekNmRxIndication(CanIf_Arc_ChannelIdType canifChnlId,Can_IdType canId, PduInfoType* pduInfo);
void canIfOsekNmTxConfirmation(CanIf_Arc_ChannelIdType canifChnlId,Can_IdType canId);
/**
* @brief Indicate OsekNm about reception of the frame
* @param canifChnlId - CanIf channel
* @param canId - Received CAN frame Identifier
* @param pduInfo - CAN payload
*/
void canIfOsekNmRxIndication(CanIf_Arc_ChannelIdType canifChnlId,Can_IdType canId, PduInfoType* pduInfo){
uint8 netId;
OsekNm_PduType nmData;
nmData.source = (uint8)(canId & (Can_IdType) CanIf_ConfigPtr->Arc_ChannelConfig[canifChnlId].CanIfOsekNmNodeIdMask);
nmData.destination = pduInfo->SduDataPtr[0];
nmData.OpCode.b = pduInfo->SduDataPtr[1];
memcpy(&(nmData.ringData),&pduInfo->SduDataPtr[2],(pduInfo->SduLength -2));
netId = CanIf_ConfigPtr->Arc_ChannelConfig[canifChnlId].CanIfOsekNmNetId;
if (netId != CANIF_OSEKNM_INVALID_NET_ID) {
OsekNm_RxIndication(netId,nmData.source,&nmData);
}
}
/**
* @brief Indicate OsekNm about transmit confirmation
* @param canifChnlId
* @param canId
*/
void canIfOsekNmTxConfirmation(CanIf_Arc_ChannelIdType canifChnlId,Can_IdType canId) {
uint8 netId;
uint8 srcNodeId;
netId = CanIf_ConfigPtr->Arc_ChannelConfig[canifChnlId].CanIfOsekNmNetId;
srcNodeId = (uint8)(canId & (Can_IdType)CanIf_ConfigPtr->Arc_ChannelConfig[canifChnlId].CanIfOsekNmNodeIdMask);
if (netId != CANIF_OSEKNM_INVALID_NET_ID) {
OsekNm_TxConfirmation(netId,srcNodeId);
}
}
#endif
/* ----------------------------[public functions]----------------------------*/
/* IMPROVMENT: Generator changes
*
* - CanIfUserRxIndication should be set according to it's type, e.g
* CanNm_RxIndication, PduR_CanIfRxIndication, CanTp_RxIndication, J1939Tp_RxIndication
* What to do with "special"?
* - The number of PDU's should be generated to CANIF_NUM_TX_LPDU
*
*
*
* */
#if (CANIF_PUBLIC_TX_BUFFERING == STD_ON)
static Std_ReturnType qReplaceOrAdd(const CanIf_TxBufferConfigType *bufferPtr, Can_PduType *canPduPtr, boolean replaceAllowed)
{
/* !req CANIF033 */
boolean found = FALSE;
Std_ReturnType ret = E_NOT_OK;
CanIf_Arc_BufferEntryType *buffPtr = NULL;
uint16 startIndex;
SchM_Enter_CanIf_EA_0();
startIndex = BufferStartIndex[bufferPtr->CanIf_Arc_BufferId];
for( uint16 i = startIndex; (i < (startIndex + bufferPtr->CanIfBufferSize)) && (!found); i++) {
if( TxPduBuffer[i].inUse && (TxPduBuffer[i].lPdu.pduId == canPduPtr->swPduHandle) ) {
/* This pdu was already stored. Replace if allowed. */
/* @req CANIF068 */
if( replaceAllowed ) {
buffPtr = &TxPduBuffer[i];
} else {
buffPtr = NULL;
}
found = TRUE;
} else if( !TxPduBuffer[i].inUse && (NULL == buffPtr)) {
/* Not used. */
/* @req CANIF836 */
buffPtr = &TxPduBuffer[i];
}
}
if( NULL != buffPtr ) {
/* Found an entry to use */
buffPtr->inUse = TRUE;
buffPtr->lPdu.dlc = canPduPtr->length;
buffPtr->lPdu.canId = canPduPtr->id;
buffPtr->lPdu.pduId = canPduPtr->swPduHandle;
memcpy(buffPtr->lPdu.data, canPduPtr->sdu, canPduPtr->length);
ret = E_OK;
} else {
/* @req CANIF837 */
}
SchM_Exit_CanIf_EA_0();
return ret;
}
static void qRemove(const CanIf_TxBufferConfigType *bufferPtr, Can_IdType canId) {
/* Remove entry matching canId from buffer corresponding to bufferPtr */
boolean found = FALSE;
uint16 startIndex;
SchM_Enter_CanIf_EA_0();
startIndex = BufferStartIndex[bufferPtr->CanIf_Arc_BufferId];
for( uint16 i = startIndex; (i < (startIndex + bufferPtr->CanIfBufferSize)) && (!found); i++) {
if( TxPduBuffer[i].inUse && (TxPduBuffer[i].lPdu.canId == canId)) {
TxPduBuffer[i].inUse = FALSE;
found = TRUE;
}
}
SchM_Exit_CanIf_EA_0();
}
static Std_ReturnType qGetBufferedPdu(const CanIf_TxBufferConfigType *bufferPtr, Can_PduType *canPduPtr)
{
/* Search through the buffer and find the highest prioritized entry */
Std_ReturnType ret;
ret = E_NOT_OK;
boolean found = FALSE;
uint16 startIndex;
Can_IdType highestPrioCanId = INVALID_CANID;
boolean highestPrioIsExt = TRUE;
Can_IdType canId = 0;
SchM_Enter_CanIf_EA_0();
startIndex = BufferStartIndex[bufferPtr->CanIf_Arc_BufferId];
for( uint16 i = startIndex; i < (startIndex + bufferPtr->CanIfBufferSize); i++) {
if( TxPduBuffer[i].inUse) {
canId = TxPduBuffer[i].lPdu.canId;
if( (canId & (1ul<<EXT_ID_BIT_POS)) != (highestPrioCanId & (1ul<<EXT_ID_BIT_POS))) {
/* One id is extended and the other standard */
if( highestPrioIsExt ) {
/* The currently highest prioritized canid is extended. Modify the
* standard id to a corresponding extended */
canId = ((canId<<EXT_ID_STD_ID_START_BIT) & EXTENDED_CANID_MAX) | (1ul<<EXT_ID_BIT_POS);
} else {
/* The currently highest prioritized canid is standard. Modify the
* extended id to a corresponding standard */
canId = (canId>>EXT_ID_STD_ID_START_BIT) & STANDARD_CANID_MAX;
}
}
if( (highestPrioCanId > canId) || (highestPrioIsExt && (highestPrioCanId == canId)) ) {
/* Priority higher. */
canPduPtr->id = TxPduBuffer[i].lPdu.canId;
canPduPtr->length = TxPduBuffer[i].lPdu.dlc;
canPduPtr->swPduHandle = TxPduBuffer[i].lPdu.pduId;
canPduPtr->sdu = TxPduBuffer[i].lPdu.data;
highestPrioCanId = TxPduBuffer[i].lPdu.canId;
highestPrioIsExt = (0 != (TxPduBuffer[i].lPdu.canId & (1ul<<EXT_ID_BIT_POS)));
found = TRUE;
}
}
}
SchM_Exit_CanIf_EA_0();
if( found ) {
ret = E_OK;
} else {
ret = E_NOT_OK;
}
return ret;
}
static void qClear(const CanIf_TxBufferConfigType *bufferPtr) {
uint16 startIndex;
SchM_Enter_CanIf_EA_0();
startIndex = BufferStartIndex[bufferPtr->CanIf_Arc_BufferId];
for( uint16 i = startIndex; i < (startIndex + bufferPtr->CanIfBufferSize); i++ ) {
TxPduBuffer[i].inUse = FALSE;
}
SchM_Exit_CanIf_EA_0();
}
#endif
#if !defined(CFG_CAN_USE_SYMBOLIC_CANIF_CONTROLLER_ID)
static Std_ReturnType ControllerToChannel( uint8 controllerId, CanIf_Arc_ChannelIdType *channel )
{
Std_ReturnType ret = E_NOT_OK;
if( NULL != channel ) {
for(CanIf_Arc_ChannelIdType i = 0; i < CANIF_CHANNEL_CNT; i++) {
if(CanIf_ConfigPtr->Arc_ChannelConfig[i].CanControllerId == controllerId) {
*channel = (CanIf_Arc_ChannelIdType)i;
ret = E_OK;
}
}
}
return ret;
}
#endif
#if (CANIF_ARC_TRANSCEIVER_API == STD_ON)
static Std_ReturnType TrcvToChnlId( uint8 Transceiver, uint8 *Channel )
{
Std_ReturnType ret = E_NOT_OK;
if( NULL != Channel ) {
for(uint8 i = 0; i < CANIF_TRANSCEIVER_CHANNEL_CNT; i++) {
if(CanIf_ConfigPtr->CanIfTransceiverConfig[i].CanIfTrcvCanTrcvIdRef == Transceiver) {
*Channel = i;
ret = E_OK;
}
}
}
return ret;
}
#endif
#if (CANIF_PUBLIC_TX_BUFFERING == STD_ON)
static void ClearTxBuffers( uint8 channelId )
{
const CanIf_Arc_ChannelConfigType channelConfigPtr = CanIf_ConfigPtr->Arc_ChannelConfig[channelId];
for( uint8 i = 0; i < channelConfigPtr.NofTxBuffers; i++ ) {
qClear(channelConfigPtr.TxBufferRefList[i]);
}
}
#endif
#if (CANIF_PUBLIC_TX_BUFFERING == STD_ON)
static void ChannelOnEnterPDUMode( uint8 channelId, CanIf_PduSetModeType pduMode )
{
switch(pduMode) {
case CANIF_SET_OFFLINE:/* @req CANIF073 */
case CANIF_SET_TX_OFFLINE:/* @req CANIF489 */
ClearTxBuffers(channelId);
break;
default:
break;
}
}
static void ChannelOnEnterControllerMode( CanIf_Arc_ChannelIdType channelId, CanIf_ControllerModeType controllerMode )
{
if(CANIF_CS_STOPPED == controllerMode) {
/* @req CANIF485 */
ClearTxBuffers((uint8)channelId);
}
}
#endif
/**
*
* @param ConfigPtr
*/
/* @req 4.0.3/CANIF001 */
void CanIf_Init(const CanIf_ConfigType *configPtr) {
/* @req 4.0.3/CANIF085 */ //buffers and flags must be cleared when support is added
/* !req 4.0.3/CANIF479 */ //CCMSM enters CANIF_CS_INIT -> clear stored wakeup events
/* !req 4.0.3/CANIF301 */
/* @req 4.0.3/CANIF302 */
// Only PostBuild case supported
VALIDATE_NO_RV((NULL != configPtr),CANIF_INIT_ID, CANIF_E_PARAM_POINTER);
CanIf_ConfigPtr = configPtr;
/* @req 4.0.3/CANIF476 */
/* @req 4.0.3/CANIF477 */
/* @req 4.0.3/CANIF478 */
/* These all cooks down to controller mode CANIF_CS_STOPPED */
for (uint8 channel = 0; channel < CANIF_CHANNEL_CNT; channel++) {
CanIf_Global.channelData[channel].ControllerMode = CANIF_CS_STOPPED;
// ControllerOnEnterMode(channel, CANIF_CS_STOPPED);
/* No req but still.. : PDU mode to OFFLINE */
CanIf_Global.channelData[channel].PduMode = CANIF_GET_OFFLINE;
#if (CANIF_PUBLIC_PN_SUPPORT == STD_ON)
/* @req 4.0.3/CANIF748 */
if (CanIf_ConfigPtr->Arc_ChannelConfig[channel].CanIfCtrlPnFilterSet)
{
/* @req 4.1.1/CANIF863 */
CanIf_Global.channelData[channel].pnTxFilterEnabled = TRUE;
} else {
CanIf_Global.channelData[channel].pnTxFilterEnabled = FALSE;
}
#endif
#if (CANIF_PUBLIC_WAKEUP_CHECK_VALIDATION_SUPPORT == STD_ON)
CanIf_Global.channelData[channel].firstRxIndication = FALSE;
#endif
}
#if (CANIF_PUBLIC_TX_BUFFERING == STD_ON)
/* Clear tx buffer */
/* @req CANIF387 */
for( uint8 i = 0; (i < CANIF_ARC_MAX_NUM_LPDU_TX_BUF); i++) {
TxPduBuffer[i].inUse = FALSE;
}
/* Setup mapping from buffer index to start index in L_PDU buffer */
uint16 indx = 0;
for( uint16 bufIndex = 0; bufIndex < CanIf_ConfigPtr->InitConfig->CanIfNumberOfTxBuffers; bufIndex++ ) {
BufferStartIndex[CanIf_ConfigPtr->InitConfig->CanIfBufferCfgPtr[bufIndex].CanIf_Arc_BufferId] = indx;
indx += CanIf_ConfigPtr->InitConfig->CanIfBufferCfgPtr[bufIndex].CanIfBufferSize;
}
#endif
#if ( CANIF_ARC_TRANSCEIVER_API == STD_ON )
for (uint8 trcvChnl=0; trcvChnl<CANIF_TRANSCEIVER_CHANNEL_CNT;trcvChnl++)
{
/* Implementation assumes that after initialization all transceivers are in normal mode */
CanIf_Global.trcvData[trcvChnl].trcvMode = CANTRCV_TRCVMODE_NORMAL;
}
#endif
CanIf_Global.initRun = TRUE;
}
/* @req 4.0.3/CANIF699 */
void CanIf_ControllerModeIndication(uint8 ControllerId,
CanIf_ControllerModeType ControllerMode)
{
/* !req 4.0.3/CANIF479 */
/* !req 4.0.3/CANIF703 */
/* @req 4.0.3/CANIF702 */
/* @req 4.0.3/CANIF661 */
VALIDATE_NO_RV((TRUE == CanIf_Global.initRun), CANIF_CONTROLLER_MODE_INDICATION_ID, CANIF_E_UNINIT);
/* NOTE: Should we have this check? */
VALIDATE_NO_RV(IS_VALID_CONTROLLER_MODE(ControllerMode), CANIF_CONTROLLER_MODE_INDICATION_ID, CANIF_E_PARAM_CTRLMODE);
CanIf_Arc_ChannelIdType channel = 0;
#if defined(CFG_CAN_USE_SYMBOLIC_CANIF_CONTROLLER_ID)
VALIDATE_NO_RV((ControllerId < CANIF_CHANNEL_CNT), CANIF_CONTROLLER_MODE_INDICATION_ID, CANIF_E_PARAM_CONTROLLER);
channel = (CanIf_Arc_ChannelIdType)ControllerId;
#else
if(E_OK != ControllerToChannel(ControllerId, &channel)) {
/* @req 4.0.3/CANIF700 */
DET_REPORT_ERROR(CANIF_CONTROLLER_MODE_INDICATION_ID, CANIF_E_PARAM_CONTROLLER);
return;
}
#endif
/* In AUTOSAR 4.0.3 CanIf specification, all mode transitions between the states
* CANIF_CS_STARTED, CANIF_CS_SLEEP and CANIF_CS_STOPPED have requirements
* except between CANIF_CS_STARTED and CANIF_CS_SLEEP. These are invalid transitions.
* CANIF474 says "The CAN Interface module shall not contain any complete controller
* state machine. Therefore we leave it up to the CAN driver not to command these
* transitions. We just set the controller mode to the mode indicated by the CAN driver. */
/* @req 4.0.3/CANIF713 */
/* @req 4.0.3/CANIF714 */
/* @req 4.0.3/CANIF715 */
/* @req 4.0.3/CANIF716 */
/* @req 4.0.3/CANIF717 */
/* @req 4.0.3/CANIF718 */
/* @req 4.0.3/CANIF719 */
#if (CANIF_PUBLIC_TX_BUFFERING == STD_ON)
/* @req CANIF485 */
ChannelOnEnterControllerMode(channel, ControllerMode);
#endif
if( NULL != CanIfDispatchConfig.CanIfControllerModeIndication ) {
/* @req 4.0.3/CANIF687 */
/* @req 4.0.3/CANIF711 */
/* !req 4.0.3/CANIF688 */
CanIfDispatchConfig.CanIfControllerModeIndication(channel, ControllerMode);
}
CanIf_Global.channelData[channel].ControllerMode = ControllerMode;
#if (CANIF_PUBLIC_WAKEUP_CHECK_VALIDATION_SUPPORT == STD_ON)
if(CANIF_CS_SLEEP == ControllerMode)
{
/* @req 4.0.3/CANIF756 */
CanIf_Global.channelData[channel].firstRxIndication = FALSE;
}
#endif
}
/* @req 4.0.3/CANIF003 */
Std_ReturnType CanIf_SetControllerMode(uint8 ControllerId,
CanIf_ControllerModeType ControllerMode)
{
/* !req 4.0.3/CANIF312 */
CanIf_ControllerModeType currMode;
/* @req 4.0.3/CANIF661 */
VALIDATE_RV((TRUE == CanIf_Global.initRun), CANIF_SET_CONTROLLER_MODE_ID, CANIF_E_UNINIT, E_NOT_OK);
/* @req 4.0.3/CANIF311 */
VALIDATE_RV((ControllerId < CANIF_CHANNEL_CNT), CANIF_SET_CONTROLLER_MODE_ID, CANIF_E_PARAM_CONTROLLERID, E_NOT_OK);
/* @req 4.0.3/CANIF774 */
VALIDATE_RV(IS_VALID_CONTROLLER_MODE(ControllerMode), CANIF_SET_CONTROLLER_MODE_ID, CANIF_E_PARAM_CTRLMODE, E_NOT_OK);
uint8 canControllerId = ARC_GET_CHANNEL_CONTROLLER(ControllerId);
currMode = CanIf_Global.channelData[ControllerId].ControllerMode;
/* @req 4.0.3/CANIF474 */
Can_StateTransitionType canTransition = CAN_T_START;
Std_ReturnType ret = E_OK;
switch(ControllerMode) {
case CANIF_CS_STOPPED:
if(CANIF_CS_SLEEP == currMode) {
/* @req 4.0.3/CANIF487 */
canTransition = CAN_T_WAKEUP;
} else {
/* @req 4.0.3/CANIF480 */
/* @req 4.0.3/CANIF585 */
canTransition = CAN_T_STOP;
}
break;
case CANIF_CS_STARTED:
/* @req 4.0.3/CANIF481 */
/* @req 4.0.3/CANIF584 */
/* Invalid transition if current mode is CANIF_CS_SLEEP.
* CAN411 in CanDrv spec. says that "when the function Can_SetControllerMode( CAN_T_SLEEP )
* is entered and the CAN controller is neither in state STOPPED nor in state SLEEP,
* it shall detect an invalid state transition".
* Let CAN driver detect invalid state transition. */
canTransition = CAN_T_START;
break;
case CANIF_CS_SLEEP:
/* @req 4.0.3/CANIF482 */
/* @req 4.0.3/CANIF486 */
/* Invalid transition if current mode is CANIF_CS_STARTED.
* CAN411 in CanDrv spec. says that "when the function Can_SetControllerMode( CAN_T_SLEEP )
* is entered and the CAN controller is neither in state STOPPED nor in state SLEEP,
* it shall detect an invalid state transition".
* Let CAN driver detect invalid state transition. */
canTransition = CAN_T_SLEEP;
break;
default:
ret = E_NOT_OK;
break;
}
if(E_OK == ret) {
/* Forward transition and let the CAN driver detect invalid transition. */
/* @req 4.0.3/CANIF308 */
if(CAN_NOT_OK == Can_SetControllerMode( canControllerId, canTransition )) {
/* @req 4.0.3/CANIF475 */
ret = E_NOT_OK;
}
}
return ret;
}
/* @req 4.0.3/CANIF229 */
Std_ReturnType CanIf_GetControllerMode(uint8 ControllerId,
CanIf_ControllerModeType *ControllerModePtr) {
/* !req 4.0.3/CANIF316 */
/* @req 4.0.3/CANIF661 */
VALIDATE_RV((TRUE == CanIf_Global.initRun), CANIF_GET_CONTROLLER_MODE_ID, CANIF_E_UNINIT, E_NOT_OK);
/* @req 4.0.3/CANIF313 */
VALIDATE_RV((ControllerId < CANIF_CHANNEL_CNT), CANIF_GET_CONTROLLER_MODE_ID, CANIF_E_PARAM_CONTROLLERID, E_NOT_OK);
/* @req 4.0.3/CANIF656 */
VALIDATE_RV((NULL != ControllerModePtr), CANIF_GET_CONTROLLER_MODE_ID, CANIF_E_PARAM_POINTER, E_NOT_OK);
/* @req 4.0.3/CANIF541 */
*ControllerModePtr = CanIf_Global.channelData[ControllerId].ControllerMode;
return E_OK;
}
/**
*
* @param canTxPduId
* @param pduInfoPtr
* @return
*/
/* @req 4.0.3/CANIF005 */
Std_ReturnType CanIf_Transmit(PduIdType CanTxPduId,
const PduInfoType *PduInfoPtr) {
/* !req 4.0.3/CANIF323 */
/* @req 4.0.3/CANIF075 */
/* !req 4.0.3/CANIF666 */
/* !req CANIF058 */
Can_PduType canPdu;
Can_ReturnType writeRet;
Std_ReturnType ret;
Std_ReturnType status;
status = E_NOT_OK;
ret = E_OK;
/* @req 4.0.3/CANIF661 */
VALIDATE_RV((TRUE == CanIf_Global.initRun), CANIF_TRANSMIT_ID, CANIF_E_UNINIT, E_NOT_OK);
/* @req 4.0.3/CANIF320 */
VALIDATE_RV((NULL != PduInfoPtr), CANIF_TRANSMIT_ID, CANIF_E_PARAM_POINTER, E_NOT_OK);
/* @req 4.0.3/CANIF319 */
VALIDATE_RV((CanTxPduId < CanIf_ConfigPtr->InitConfig->CanIfNumberOfCanTXPduIds), CANIF_TRANSMIT_ID, CANIF_E_INVALID_TXPDUID, E_NOT_OK);
const CanIf_TxPduConfigType *txPduPtr = &CanIf_ConfigPtr->InitConfig->CanIfTxPduConfigPtr[CanTxPduId];
uint8 controller = (uint8)txPduPtr->CanIfTxPduBufferRef->CanIfBufferHthRef->CanIfCanControllerIdRef;
/*############################################################################################*/
/* IMPROVEMENT: Cleanup needed... */
/* @req 4.0.3/CANIF382 */
/* @req 4.0.3/CANIF073 Part of */
/* @req 4.0.3/CANIF491 Part of */
if( CANIF_GET_OFFLINE == CanIf_Global.channelData[controller].PduMode || CANIF_GET_RX_ONLINE == CanIf_Global.channelData[controller].PduMode ) {
DET_REPORT_ERROR(CANIF_TRANSMIT_ID, CANIF_E_STOPPED);
return E_NOT_OK;
}
/* @req 4.0.3/CANIF723 */
/* @req 4.0.3/CANIF677 */ //Return
if( CANIF_CS_STOPPED == CanIf_Global.channelData[controller].ControllerMode ) {
DET_REPORT_ERROR(CANIF_TRANSMIT_ID, CANIF_E_STOPPED);
return E_NOT_OK;
}
/* @req 4.0.3/CANIF317 */
/* @req 4.0.3/CANIF491 Part of */
/* @req 4.0.3/CANIF489 Part of*///Return
if( (CANIF_CS_STARTED != CanIf_Global.channelData[controller].ControllerMode) ||
(CANIF_GET_RX_ONLINE == CanIf_Global.channelData[controller].PduMode) ||
(CANIF_GET_OFFLINE == CanIf_Global.channelData[controller].PduMode) ) {
ret = E_NOT_OK;
}
if (ret == E_OK){
/*############################################################################################*/
#if (CANIF_PUBLIC_PN_SUPPORT == STD_ON)
/* @req 4.0.3/CANIF750 */
if ((CanIf_ConfigPtr->Arc_ChannelConfig[controller].CanIfCtrlPnFilterSet) && (CanIf_Global.channelData[controller].pnTxFilterEnabled)
&& (!txPduPtr->CanIfTxPduPnFilterEnable ))
{
ret = E_NOT_OK;
}
#endif
if (ret == E_OK){
/* @req 4.0.3/CANIF072 */
/* @req 4.0.3/CANIF491 Part of */
/* !req 4.0.3/CANIF437 */
if( (CANIF_GET_OFFLINE_ACTIVE == CanIf_Global.channelData[controller].PduMode) ||
(CANIF_GET_OFFLINE_ACTIVE_RX_ONLINE == CanIf_Global.channelData[controller].PduMode) ) {
if((NO_FUNCTION_CALLOUT != txPduPtr->CanIfUserTxConfirmation) &&
(CanIfUserTxConfirmations[txPduPtr->CanIfUserTxConfirmation] != NULL)){
CanIfUserTxConfirmations[txPduPtr->CanIfUserTxConfirmation](txPduPtr->CanIfTxPduId);
}
status = E_OK;
}
if (status == E_NOT_OK) {
/* @req 4.0.3/CANIF318 */
canPdu.id = txPduPtr->CanIfCanTxPduIdCanId;
/* @req 4.0.3/CANIF243 */
if( CANIF_CAN_ID_TYPE_29 == txPduPtr->CanIfTxPduIdCanIdType ) {
canPdu.id |= (1ul << EXT_ID_BIT_POS);
}
else if( CANIF_CAN_FD_ID_TYPE_11 == txPduPtr->CanIfTxPduIdCanIdType ) {
canPdu.id |= (1ul << CAN_FD_BIT_POS); /*setting FD flag*/
}
else if( CANIF_CAN_FD_ID_TYPE_29 == txPduPtr->CanIfTxPduIdCanIdType ) {
canPdu.id |= (3ul << CAN_FD_BIT_POS); /*setting both IDE and FD flag*/
}
/* Dynamic DLC length */
if (PduInfoPtr->SduLength < txPduPtr->CanIfCanTxPduIdDlc) {
canPdu.length = PduInfoPtr->SduLength;
} else {
canPdu.length = txPduPtr->CanIfCanTxPduIdDlc;
}
canPdu.sdu = PduInfoPtr->SduDataPtr;
canPdu.swPduHandle = CanTxPduId;
writeRet = Can_Write(txPduPtr->CanIfTxPduBufferRef->CanIfBufferHthRef->CanIfHthIdSymRef, &canPdu);
if( CAN_BUSY == writeRet ) {
ret = E_NOT_OK;
#if (CANIF_PUBLIC_TX_BUFFERING == STD_ON)
/* @req CANIF381 */
/* @req CANIF835 */
/* @req CANIF063 */
/* Should not really have to check for BASIC here since if buffer size greater than 0
* and FULLCAN violates req CANIF834_Conf */
if( (0 != txPduPtr->CanIfTxPduBufferRef->CanIfBufferSize) &&
(CANIF_HANDLE_TYPE_BASIC == txPduPtr->CanIfTxPduBufferRef->CanIfBufferHthRef->CanIfHthType) ) {
ret = qReplaceOrAdd(txPduPtr->CanIfTxPduBufferRef, &canPdu, TRUE);
}
#endif
} else if( CAN_NOT_OK == writeRet ) {
/* Nothing to do. Throw message */
ret = E_NOT_OK;
} else if( CAN_OK == writeRet ) {
/* @req 4.0.3/CANIF162 */
ret = E_OK;
}
}else {
ret = status;
}
}
}
return ret;
}
/* @req 4.0.3/CANIF007 */
void CanIf_TxConfirmation(PduIdType canTxPduId) {
const CanIf_TxPduConfigType *txPduPtr;
/* !req 4.0.3/CANIF413 */
/* !req 4.0.3/CANIF414 */
/* !req CANIF058 */
/* @req 4.0.3/CANIF412 */
/* @req 4.0.3/CANIF661 */
VALIDATE_NO_RV((TRUE == CanIf_Global.initRun), CANIF_TXCONFIRMATION_ID, CANIF_E_UNINIT);
/* @req 4.0.3/CANIF410 */
VALIDATE_NO_RV((canTxPduId < CanIf_ConfigPtr->InitConfig->CanIfNumberOfCanTXPduIds), CANIF_TXCONFIRMATION_ID, CANIF_E_PARAM_LPDU);
txPduPtr = &CanIf_ConfigPtr->InitConfig->CanIfTxPduConfigPtr[canTxPduId];
#if (CANIF_PUBLIC_TXCONFIRM_POLLING_SUPPORT == STD_ON)
/* !req 4.0.3/CANIF740 */
#endif
CanIf_PduGetModeType mode;
if( E_OK == CanIf_GetPduMode(txPduPtr->CanIfTxPduBufferRef->CanIfBufferHthRef->CanIfCanControllerIdRef, &mode) ) {
/* @req 4.0.3/CANIF489*/
/* @req 4.0.3/CANIF491 Part of */
/* @req 4.0.3/CANIF075 */
if ((mode == CANIF_GET_TX_ONLINE) || (mode == CANIF_GET_ONLINE) ||
(mode == CANIF_GET_OFFLINE_ACTIVE) || (mode == CANIF_GET_OFFLINE_ACTIVE_RX_ONLINE) ) {
#if (CANIF_PUBLIC_TX_BUFFERING == STD_ON)
if((mode == CANIF_GET_TX_ONLINE) || (mode == CANIF_GET_ONLINE) ) {
Can_PduType canPdu;
/* @req CANIF386 */ //Evaluate if there are pending pdus in buffers, assigned to the new free hth
if(E_OK == qGetBufferedPdu(txPduPtr->CanIfTxPduBufferRef, &canPdu)) {
/* Was something in queue. Assume that qGetBufferedPdu returned the pdu
* with the highest priority */
/* @req CANIF668 */ //Initiate transmit of the highest prio pdu
/* @req CANIF070 */ //transmit highest prio pdu
/* NOTE: Foreach hth referenced? */
if( CAN_OK == Can_Write(txPduPtr->CanIfTxPduBufferRef->CanIfBufferHthRef->CanIfHthIdSymRef, &canPdu) ) {
/* @req CANIF183 */ //Remove from buffer if E_OK == Can_Write
qRemove(txPduPtr->CanIfTxPduBufferRef, canPdu.id);
}
}
}
#endif
#if (CANIF_PUBLIC_READTXPDU_NOTIFY_STATUS_API == STD_ON) && FEATURE_NOT_SUPPORTED
/* !req 4.0.3/CANIF391 */
#endif
#if (CANIF_PUBLIC_PN_SUPPORT == STD_ON)
uint8 canIfChannel = txPduPtr->CanIfTxPduBufferRef->CanIfBufferHthRef->CanIfCanControllerIdRef;
/* @req 4.0.3/CANIF751 */
if ((CanIf_ConfigPtr->Arc_ChannelConfig[canIfChannel].CanIfCtrlPnFilterSet) && (CanIf_Global.channelData[canIfChannel].pnTxFilterEnabled)
&& (txPduPtr->CanIfTxPduPnFilterEnable ))
{
CanIf_Global.channelData[canIfChannel].pnTxFilterEnabled = FALSE;
}
#endif
/* @req 4.0.3/CANIF383 */
if( (NO_FUNCTION_CALLOUT != txPduPtr->CanIfUserTxConfirmation ) &&
(CanIfUserTxConfirmations[txPduPtr->CanIfUserTxConfirmation]) != NULL){
/* @req 4.0.3/CANIF011 */
/* !req 4.0.3/CANIF437 */
CanIfUserTxConfirmations[txPduPtr->CanIfUserTxConfirmation](txPduPtr->CanIfTxPduId);
}
#if (CANIF_OSEKNM_SUPPORT == STD_ON)
if (STD_ON == txPduPtr->OsekNmTxConfirmationSupport) {
canIfOsekNmTxConfirmation(txPduPtr->CanIfTxPduBufferRef->CanIfBufferHthRef->CanIfCanControllerIdRef, txPduPtr->CanIfCanTxPduIdCanId);
}
#endif
}
}
}
#if(CANIF_PUBLIC_WAKEUP_CHECK_VALIDATION_SUPPORT == STD_ON) && (( CANIF_CTRL_WAKEUP_SUPPORT == STD_ON ) || (CANIF_TRCV_WAKEUP_SUPPORT == STD_ON))
static inline void setFirstRxIndication(uint8 controllerId);
static inline void setFirstRxIndication(uint8 controllerId)
{
/* @req 4.0.3/CANIF286 */ /*Store event of first call of a CAN controller which has been set to CANIF_CS_STARTED */
/*lint --e{661} */ /* Previously controllerId is checked for validity */
if(!CanIf_Global.channelData[controllerId].firstRxIndication){
CanIf_Global.channelData[controllerId].firstRxIndication = TRUE;
}
return;
}
#endif
#if defined(CANIF_PRIVATE_SOFTWARE_FILTER_TYPE_BINARY)
/**
* Searches for CanId using binary search
* @param rxPduCfgPtr
* @param nofEntries
* @param canId
* @param rxPdu
* @return TRUE: CanId found, False: CanId not found
*/
static boolean binarySearch(const CanIf_RxPduConfigType *rxPduCfgPtr, uint16 nofEntries, uint32 canId, const CanIf_RxPduConfigType **rxPdu)
{
boolean found = FALSE;
boolean done = FALSE;
uint16 currentIndex;
sint32 lowerIndex = 0;
sint32 upperIndex = nofEntries - 1;
uint32 actualCanId;
boolean isExtendedId = IS_EXTENDED_CAN_ID(canId);
#if (CANIF_CANFD_SUPPORT == STD_ON)
actualCanId = canId & ~(3ul<<CAN_FD_BIT_POS);
#else
actualCanId = canId & ~(1ul<<EXT_ID_BIT_POS);
#endif
if(0u != nofEntries) {
while(!done) {
currentIndex = (lowerIndex + upperIndex) / 2;
if( lowerIndex > upperIndex ) {
/* Search done */
done = TRUE;
}
else {
/* @req 4.0.3/CANIF645 */
/* @req 4.0.3/CANIF646 */
if( (actualCanId <= rxPduCfgPtr[currentIndex].CanIfCanRxPduUpperCanId) &&
(actualCanId >= rxPduCfgPtr[currentIndex].CanIfCanRxPduLowerCanId) &&
(isExtendedId == rxPduCfgPtr[currentIndex].CanIdIsExtended) ) {
found = TRUE;
done = TRUE;
*rxPdu = &rxPduCfgPtr[currentIndex];
}
else {
if( rxPduCfgPtr[currentIndex].CanIfCanRxPduLowerCanId < actualCanId ) {
lowerIndex = currentIndex + 1;
}
else {
upperIndex = currentIndex - 1;
}
}
}
}
}
return found;
}
#elif defined(CANIF_PRIVATE_SOFTWARE_FILTER_TYPE_LINEAR)
/**
* Searches for CanId using linear search
* @param rxPduCfgPtr
* @param nofEntries
* @param canId
* @param rxPdu
* @return TRUE: CanId found, False: CanId not found
*/
static boolean linearSearch(const CanIf_RxPduConfigType *rxPduCfgPtr, uint16 nofEntries, uint32 canId, const CanIf_RxPduConfigType **rxPdu)
{
boolean found = FALSE;
boolean isExtendedId = IS_EXTENDED_CAN_ID(canId);
uint32 actualCanId;
#if (CANIF_CANFD_SUPPORT == STD_ON)
actualCanId = canId & ~(3ul<<CAN_FD_BIT_POS);
#else
actualCanId = canId & ~(1ul<<EXT_ID_BIT_POS);
#endif
for(uint16 i = 0; (i < nofEntries) && !found; i++ ) {
/* @req 4.0.3/CANIF645 */
/* @req 4.0.3/CANIF646 */
if( (actualCanId <= rxPduCfgPtr[i].CanIfCanRxPduUpperCanId) &&
(actualCanId >= rxPduCfgPtr[i].CanIfCanRxPduLowerCanId) &&
(isExtendedId == rxPduCfgPtr[i].CanIdIsExtended) ) {
found = TRUE;
*rxPdu = &rxPduCfgPtr[i];
}
}
return found;
}
#endif
#if defined(CFG_CANIF_ASR_4_3_1)
/**
*
@param Mailbox
@param PduInfoPtr
*/
/* @req 4.3.0/CANIF006 */
void CanIf_RxIndication (const Can_HwType* Mailbox,
const PduInfoType* PduInfoPtr) {
uint8 *canSduPtr;
Can_IdType canId;
Can_HwHandleType hrh;
uint8 canDlc;
VALIDATE_NO_RV((NULL != PduInfoPtr), CANIF_RXINDICATION_ID, CANIF_E_PARAM_POINTER);
VALIDATE_NO_RV((NULL != Mailbox), CANIF_RXINDICATION_ID, CANIF_E_PARAM_POINTER);
hrh = Mailbox->Hoh;
canId = Mailbox->CanId;
canSduPtr = PduInfoPtr->SduDataPtr;
canDlc = PduInfoPtr->SduLength;
#else
/**
*
* @param hrh
* @param canId
* @param canDlc
* @param canSduPtr
*/
/* @req 4.0.3/CANIF006 */
void CanIf_RxIndication(Can_HwHandleType hrh, Can_IdType canId, uint8 canDlc,
const uint8 *canSduPtr) {
#endif
CanIf_PduGetModeType mode;
PduInfoType pduInfo;
boolean pduMatch = FALSE;
boolean idCndFlag;
/* !req 4.0.3/CANIF389 */ //Software filter if configured and if no match end
#if (CANIF_PUBLIC_READRXPDU_NOTIFY_STATUS_API == STD_ON) && FEATURE_NOT_SUPPORTED
/* !req 4.0.3/CANIF392 */ //Notification status stored if api on and configured
#endif
/* !req 4.0.3/CANIF422 */
/* !req 4.0.3/CANIF423 */
/* !req 4.0.3/CANIF297 */
/* !req 4.0.3/CANIF198 */
/* !req 4.0.3/CANIF199 */
/* !req 4.0.3/CANIF664 */
//If multiple HRHs, each HRH shall belong at least to a single or fixed group of Rx L-PDU handles (CanRxPduIds)
/* @req 4.0.3/CANIF421 */
/* @req 4.0.3/CANIF661 */
VALIDATE_NO_RV((TRUE == CanIf_Global.initRun), CANIF_RXINDICATION_ID, CANIF_E_UNINIT);
/* @req 4.0.3/CANIF416 */
VALIDATE_NO_RV((hrh < CanIf_ConfigPtr->InitConfig->CanIfHohConfigPtr->HrhListSize), CANIF_RXINDICATION_ID, CANIF_E_PARAM_HRH);
VALIDATE_NO_RV((NO_CANIF_HRH != CanIf_ConfigPtr->InitConfig->CanIfHohConfigPtr->CanHohToCanIfHrhMap[hrh]), CANIF_RXINDICATION_ID, CANIF_E_PARAM_HRH);
const CanIf_HrhConfigType *hrhConfig = &CanIf_ConfigPtr->InitConfig->CanIfHohConfigPtr->CanIfHrhConfig[CanIf_ConfigPtr->InitConfig->CanIfHohConfigPtr->CanHohToCanIfHrhMap[hrh]];
/* @req 4.0.3/CANIF417 */
idCndFlag = ( (IS_EXTENDED_CAN_ID(canId) && ((canId & ~(3ul<<CAN_FD_BIT_POS)) > EXTENDED_CANID_MAX)) ||
(!IS_EXTENDED_CAN_ID(canId) && ((canId & ~(3ul<<CAN_FD_BIT_POS)) > STANDARD_CANID_MAX)));
#if (CANIF_CANFD_SUPPORT == STD_OFF)
if((idCndFlag == TRUE) || IS_CANFD(canId)) {
#else
if( idCndFlag == TRUE) {
#endif
DET_REPORT_ERROR(CANIF_RXINDICATION_ID, CANIF_E_PARAM_CANID);
return;
}
/* @req 4.0.3/CANIF418 */
#if (CANIF_CANFD_SUPPORT == STD_ON)
VALIDATE_NO_RV((canDlc <= 64), CANIF_RXINDICATION_ID, CANIF_E_PARAM_DLC);
#else
VALIDATE_NO_RV((canDlc <= 8), CANIF_RXINDICATION_ID, CANIF_E_PARAM_DLC);
#endif
/* @req 4.0.3/CANIF419 */
VALIDATE_NO_RV((NULL != canSduPtr), CANIF_RXINDICATION_ID, CANIF_E_PARAM_POINTER);
/* @req 4.0.3/CANIF075 */
/* @req 4.0.3/CANIF490 */
/* @req 4.0.3/CANIF492 */
if ( FALSE == ((E_OK != CanIf_GetPduMode(hrhConfig->CanIfHrhCanCtrlIdRef, &mode)) ||
(CANIF_GET_OFFLINE == mode) || (CANIF_GET_TX_ONLINE == mode)
|| (CANIF_GET_OFFLINE_ACTIVE == mode)) ) {
const CanIf_RxPduConfigType *rxPduCfgPtr = hrhConfig->RxPduList;
if( 0u != hrhConfig->NofRxPdus ) {
/* @req 4.0.3/CANIF663 */
/* @req 4.0.3/CANIF665 */
if( (CANIF_HANDLE_TYPE_FULL == hrhConfig->CanIfHrhType) || !hrhConfig->CanIfSoftwareFilterHrh) {
/* No sw filtering or FULL-CAN. Assume match... */
pduMatch = TRUE;
}
else {
/* Software filtering */
/* @req 4.0.3/CANIF211 */
/* @req 4.0.3/CANIF281 */
#if defined(CANIF_PRIVATE_SOFTWARE_FILTER_TYPE_BINARY)
pduMatch = binarySearch(hrhConfig->RxPduList, hrhConfig->NofRxPdus, canId, &rxPduCfgPtr);
#elif defined(CANIF_PRIVATE_SOFTWARE_FILTER_TYPE_LINEAR)
pduMatch = linearSearch(hrhConfig->RxPduList, hrhConfig->NofRxPdus, canId, &rxPduCfgPtr);
#else
#error "CanIf: Filtering method not supported"
#endif
}
}
if( pduMatch ) {
/* @req 4.0.3/CANIF030 */
#if (CANIF_PRIVATE_DLC_CHECK == STD_ON)
/* @req 4.0.3/CANIF390 */
/* @req 4.0.3/CANIF026 */
if( canDlc < rxPduCfgPtr->CanIfCanRxPduDlc ) {
/* @req 4.0.3/CANIF168 */
DET_REPORT_ERROR(CANIF_RXINDICATION_ID, CANIF_E_PARAM_DLC);
return;
}
#endif
#if ( CANIF_PUBLIC_READRXPDU_DATA_API == STD_ON ) && FEATURE_NOT_SUPPORTED
/* IMPROVEMENT: Add support for CANIF_PUBLIC_READRXPDU_DATA_API */
#endif
#if(CANIF_PUBLIC_WAKEUP_CHECK_VALIDATION_SUPPORT == STD_ON) && (( CANIF_CTRL_WAKEUP_SUPPORT == STD_ON ) || (CANIF_TRCV_WAKEUP_SUPPORT == STD_ON))
setFirstRxIndication(hrhConfig->CanIfHrhCanCtrlIdRef);
#endif
/* @req 4.0.3/CANIF012 */
/* @req 4.0.3/CANIF056 */ //If accepted during DLC check, identify target upper layer module if configured
if (( rxPduCfgPtr->CanIfUserRxIndication != NO_FUNCTION_CALLOUT ) &&
(CanIfUserRxIndications[rxPduCfgPtr->CanIfUserRxIndication] != NULL)){
/* @req 4.0.3/CANIF135 */
/* @req 4.0.3/CANIF830 */
/* @req 4.0.3/CANIF829 */
/* @req 4.0.3/CANIF415 */
/* @req 4.0.3/CANIF057 */
/* !req 4.0.3/CANIF440 */
pduInfo.SduLength = canDlc;
pduInfo.SduDataPtr = (uint8 *)canSduPtr; /* throw away const for some reason */
CanIfUserRxIndications[rxPduCfgPtr->CanIfUserRxIndication](rxPduCfgPtr->CanIfCanRxPduId, &pduInfo);
}
#if (CANIF_OSEKNM_SUPPORT == STD_ON)
if (STD_ON == rxPduCfgPtr->OsekNmRxIndicationSupport) {
pduInfo.SduLength = canDlc;
pduInfo.SduDataPtr = (uint8 *)canSduPtr;
canIfOsekNmRxIndication(hrhConfig->CanIfHrhCanCtrlIdRef,canId, &pduInfo);
}
#endif
}
}
}
/* !req 4.0.3/CANIF521 */
#if (CANIF_PUBLIC_CANCEL_TRANSMIT_SUPPORT == STD_ON) && FEATURE_NOT_SUPPORTED
/* !req 4.0.3/CANIF520 */
Std_ReturnType CanIf_CancelTransmit(PduIdType CanTxPduId)
{
/* !req 4.0.3/CANIF652 */
return E_OK;
}
#endif
#if (CANIF_CTRLDRV_TX_CANCELLATION == STD_ON)
/* @req CANIF428 */
/* @req CANIF101 */
void CanIf_CancelTxConfirmation(PduIdType canTxPduId, const PduInfoType *pduInfoPtr)
{
/* !req CANIF427 */
/* !req CANIF058 */
/* @req CANIF426 */
VALIDATE_NO_RV((TRUE == CanIf_Global.initRun), CANIF_CANCELTXCONFIRMATION_ID, CANIF_E_UNINIT);
/* @req CANIF424 */
VALIDATE_NO_RV((canTxPduId < CanIf_ConfigPtr->InitConfig->CanIfNumberOfCanTXPduIds), CANIF_CANCELTXCONFIRMATION_ID, CANIF_E_PARAM_LPDU);
/* @req CANIF828 */
VALIDATE_NO_RV((NULL != pduInfoPtr), CANIF_CANCELTXCONFIRMATION_ID, CANIF_E_PARAM_POINTER);
#if (CANIF_PUBLIC_TX_BUFFERING == STD_ON)
const CanIf_TxPduConfigType *txPduPtr;
txPduPtr = &CanIf_ConfigPtr->InitConfig->CanIfTxPduConfigPtr[canTxPduId];
CanIf_PduGetModeType mode = CanIf_Global.channelData[txPduPtr->CanIfTxPduBufferRef->CanIfBufferHthRef->CanIfCanControllerIdRef].PduMode;
if( ((CANIF_GET_TX_ONLINE == mode) || (CANIF_GET_ONLINE == mode)) &&
(CANIF_CS_STARTED == CanIf_Global.channelData[txPduPtr->CanIfTxPduBufferRef->CanIfBufferHthRef->CanIfCanControllerIdRef].ControllerMode )) {
Can_PduType canPdu;
canPdu.length = pduInfoPtr->SduLength;
canPdu.id = txPduPtr->CanIfCanTxPduIdCanId;
if( CANIF_CAN_ID_TYPE_29 == txPduPtr->CanIfTxPduIdCanIdType ) {
canPdu.id |= (1ul << EXT_ID_BIT_POS);
}
else if( CANIF_CAN_FD_ID_TYPE_11 == txPduPtr->CanIfTxPduIdCanIdType ) {
canPdu.id |= (1ul << CAN_FD_BIT_POS); /*setting FD flag*/
}
else if( CANIF_CAN_FD_ID_TYPE_29 == txPduPtr->CanIfTxPduIdCanIdType ) {
canPdu.id |= (3ul << CAN_FD_BIT_POS); /*setting both IDE and FD flag*/
}
canPdu.sdu = pduInfoPtr->SduDataPtr;
canPdu.swPduHandle = canTxPduId;
/* @req CANIF054 */
/* @req CANIF176 */
(void)qReplaceOrAdd( txPduPtr->CanIfTxPduBufferRef, &canPdu, FALSE);
/* @req CANIF386 */ //Evaluate if there are pending pdus in buffers, assigned to the new free hth
if(E_OK == qGetBufferedPdu(txPduPtr->CanIfTxPduBufferRef, &canPdu)) {
/* Was something in queue. Assume that qGetBufferedPdu returned the pdu
* with the highest priority */
/* @req CANIF668 */ //Initiate transmit of the highest prio pdu
/* @req CANIF070 */ //transmit highest prio pdu
if( CAN_OK == Can_Write(txPduPtr->CanIfTxPduBufferRef->CanIfBufferHthRef->CanIfHthIdSymRef, &canPdu) ) {
/* @req CANIF183 */ //Remove from buffer if E_OK == Can_Write
qRemove(txPduPtr->CanIfTxPduBufferRef, canPdu.id);
/* IMPROVEMENT: Should we try to insert the cancelled pdu into the buffer if
* the attempt above failed due to lack of space? */
}
}
}
#else
(void)canTxPduId;
(void)pduInfoPtr;
#endif
}
#endif
/* !req 4.0.3/CANIF330 */
#if ( CANIF_PUBLIC_READRXPDU_DATA_API == STD_ON ) && FEATURE_NOT_SUPPORTED
/**
*
*
* @param canRxPduId
* @param pduInfoPtr
* @return
*/
/* !req 4.0.3/CANIF194*/
Std_ReturnType CanIf_ReadRxPduData(PduIdType canRxPduId, PduInfoType *pduInfoPtr)
{
/* !req 4.0.3/CANIF324*/
/* !req 4.0.3/CANIF325 */
/* !req 4.0.3/CANIF329 */
/* !req CANIF058 */
VALIDATE_NO_RV(FALSE, CANIF_READTXPDUDATA_ID, CANIF_E_NOK_NOSUPPORT);
//Requirement 661
VALIDATE_NO_RV(CanIf_Global.initRun == STD_ON, CANIF_READTXPDUDATA_ID, CANIF_E_UNINIT );
/* !req 4.0.3/CANIF326 */
VALIDATE_NO_RV(pduInfoPtr != 0, CANIF_READTXPDUDATA_ID, CANIF_E_PARAM_POINTER );
/* IMPROVMENT: Do it?
* This API is actually not used by any upper layers
*/
return E_NOT_OK;
}
#endif
/* !req 4.0.3/CANIF335 */
#if ( CANIF_PUBLIC_READTXPDU_NOTIFY_STATUS_API == STD_ON ) && FEATURE_NOT_SUPPORTED
/* !req 4.0.3/CANIF202 */
CanIf_NotifStatusType CanIf_ReadTxNotifStatus(PduIdType CanTxPduId)
{
/* !req 4.0.3/CANIF331 */
/* !req 4.0.3/CANIF334 */
/* !req 4.0.3/CANIF393 */
return CANIF_NO_NOTIFICATION;
}
#endif
/* !req 4.0.3/CANIF340 */
#if ( CANIF_PUBLIC_READRXPDU_NOTIFY_STATUS_API == STD_ON ) && FEATURE_NOT_SUPPORTED
/* !req 4.0.3/CANIF230 */
CanIf_NotifStatusType CanIf_ReadRxNotifStatus(PduIdType CanRxPduId)
{
/* !req 4.0.3/CANIF336 */
/* !req 4.0.3/CANIF339 */
/* !req 4.0.3/CANIF394 */
return CANIF_NO_NOTIFICATION;
}
#endif
#if (CANIF_PUBLIC_PN_SUPPORT == STD_ON)
static inline void setPnFilterEnable(uint8 ControllerId);
static inline void setPnFilterEnable(uint8 ControllerId)
{
/* @req 4.0.3/CANIF749*/ /* @req 4.0.3/CANIF748 */ /* @req 4.0.3/CANIF752 */
if (CanIf_ConfigPtr->Arc_ChannelConfig[ControllerId].CanIfCtrlPnFilterSet)
{
CanIf_Global.channelData[ControllerId].pnTxFilterEnabled = TRUE;
}
return;
}
#endif
/* @req 4.0.3/CANIF008 */
Std_ReturnType CanIf_SetPduMode( uint8 ControllerId, CanIf_PduSetModeType PduModeRequest )
{
/* !req 4.0.3/CANIF344*/
/* NOTE: The channel id is used and not the controller */
Std_ReturnType ret;
ret = E_OK;
CanIf_PduGetModeType currMode;
CanIf_PduGetModeType newMode;
/* @req 4.0.3/CANIF661 */
VALIDATE_RV((TRUE == CanIf_Global.initRun), CANIF_SETPDUMODE_ID, CANIF_E_UNINIT, E_NOT_OK);
/* @req 4.0.3/CANIF341*/
VALIDATE_RV((ControllerId < CANIF_CHANNEL_CNT), CANIF_SETPDUMODE_ID, CANIF_E_PARAM_CONTROLLERID, E_NOT_OK);
currMode = CanIf_Global.channelData[ControllerId].PduMode;
newMode = currMode;
switch(PduModeRequest) {
case CANIF_SET_OFFLINE:
newMode = CANIF_GET_OFFLINE;
break;
case CANIF_SET_ONLINE:
#if (CANIF_PUBLIC_PN_SUPPORT == STD_ON)
setPnFilterEnable(ControllerId);
#endif
newMode = CANIF_GET_ONLINE;
break;
case CANIF_SET_RX_OFFLINE:
if( CANIF_GET_ONLINE == currMode ) {
newMode = CANIF_GET_TX_ONLINE;
} else if( CANIF_GET_RX_ONLINE == currMode ) {
newMode = CANIF_GET_OFFLINE;
} else if( CANIF_GET_OFFLINE_ACTIVE_RX_ONLINE == currMode ) {
newMode = CANIF_GET_OFFLINE_ACTIVE;
}
break;
case CANIF_SET_RX_ONLINE:
if(CANIF_GET_TX_ONLINE == currMode ) {
newMode = CANIF_GET_ONLINE;
} else if( CANIF_GET_OFFLINE == currMode ) {
newMode = CANIF_GET_RX_ONLINE;
} else if( CANIF_GET_OFFLINE_ACTIVE == currMode ) {
newMode = CANIF_GET_OFFLINE_ACTIVE_RX_ONLINE;
}
break;
case CANIF_SET_TX_OFFLINE:
if( (CANIF_GET_ONLINE == currMode) || (CANIF_GET_OFFLINE_ACTIVE_RX_ONLINE == currMode) ) {
newMode = CANIF_GET_RX_ONLINE;
} else if( (CANIF_GET_TX_ONLINE == currMode) || (CANIF_GET_OFFLINE_ACTIVE == currMode) ) {
newMode = CANIF_GET_OFFLINE;
}
break;
case CANIF_SET_TX_OFFLINE_ACTIVE:
if( CANIF_GET_OFFLINE == currMode || CANIF_GET_TX_ONLINE == currMode) {
newMode = CANIF_GET_OFFLINE_ACTIVE;
} else if( (CANIF_GET_ONLINE == currMode) || (CANIF_GET_RX_ONLINE == currMode) ) {
newMode = CANIF_GET_OFFLINE_ACTIVE_RX_ONLINE;
}
break;
case CANIF_SET_TX_ONLINE:
#if (CANIF_PUBLIC_PN_SUPPORT == STD_ON)
setPnFilterEnable(ControllerId);
#endif
if( CANIF_GET_OFFLINE == currMode ) {
newMode = CANIF_GET_TX_ONLINE;
} else if( (CANIF_GET_RX_ONLINE == currMode) || (CANIF_GET_OFFLINE_ACTIVE_RX_ONLINE == currMode) ) {
newMode = CANIF_GET_ONLINE;
} else if (CANIF_GET_OFFLINE_ACTIVE == currMode ) {
newMode = CANIF_GET_TX_ONLINE;
}
break;
default:
// DET_REPORT_ERROR(CANIF_SETPDUMODE_ID, CANIF_E_PARAM_PDUMODE);
ret = E_NOT_OK;
break;
}
#if (CANIF_PUBLIC_TX_BUFFERING == STD_ON)
if(E_OK == ret) {
/* ChannelOnEnterPDUMode will tx buffers for this channel and thus obey
* parts of the following requirements */
/* CANIF073 */
/* CANIF489 */
ChannelOnEnterPDUMode(ControllerId, PduModeRequest);
}
#endif
CanIf_Global.channelData[ControllerId].PduMode = newMode;
return ret;
}
/* @req 4.0.3/CANIF009 */
Std_ReturnType CanIf_GetPduMode( uint8 ControllerId, CanIf_PduGetModeType *PduModePtr )
{
/* !req 4.0.3/CANIF349 */
/* @req 4.0.3/CANIF661 */
VALIDATE_RV((TRUE == CanIf_Global.initRun), CANIF_GETPDUMODE_ID, CANIF_E_UNINIT, E_NOT_OK);
/* @req 4.0.3/CANIF346 */
VALIDATE_RV((ControllerId < CANIF_CHANNEL_CNT), CANIF_GETPDUMODE_ID, CANIF_E_PARAM_CONTROLLERID, E_NOT_OK);
/* @req 4.0.3/CANIF657 */
VALIDATE_RV((NULL != PduModePtr), CANIF_GETPDUMODE_ID, CANIF_E_PARAM_POINTER, E_NOT_OK);
*PduModePtr = CanIf_Global.channelData[ControllerId].PduMode;
return E_OK;
}
/* @req 4.0.3/CANIF218 */
void CanIf_ControllerBusOff( uint8 ControllerId )
{
CanIf_Arc_ChannelIdType channel = 0;
/* !req 4.0.3/CANIF432 */
/* !req 4.0.3/CANIF433 */
/* @req 4.0.3/CANIF118 */
/* @req 4.0.3/CANIF661 */
/* @req 4.0.3/CANIF431 */
VALIDATE_NO_RV((TRUE == CanIf_Global.initRun), CANIF_CONTROLLER_BUSOFF_ID, CANIF_E_UNINIT);
#if defined(CFG_CAN_USE_SYMBOLIC_CANIF_CONTROLLER_ID)
VALIDATE_NO_RV((ControllerId < CANIF_CHANNEL_CNT), CANIF_CONTROLLER_BUSOFF_ID, CANIF_E_PARAM_CONTROLLER);
channel = (CanIf_Arc_ChannelIdType)ControllerId;
#else
if(E_OK != ControllerToChannel(ControllerId, &channel)) {
/* @req 4.0.3/CANIF429 */
DET_REPORT_ERROR(CANIF_CONTROLLER_BUSOFF_ID, CANIF_E_PARAM_CONTROLLER);
return;
}
#endif
/* @req 4.0.3/CANIF298 */
/* @req 4.0.3/CANIF488 */
if( CANIF_CS_UNINIT != CanIf_Global.channelData[channel].ControllerMode ) {
#if (CANIF_PUBLIC_TX_BUFFERING == STD_ON)
ChannelOnEnterControllerMode(channel, CANIF_CS_STOPPED);
#endif
CanIf_Global.channelData[channel].ControllerMode = CANIF_CS_STOPPED;
}
#if (CANIF_PUBLIC_TXCONFIRM_POLLING_SUPPORT == STD_ON) && FEATURE_NOT_SUPPORTED
/* !req 4.0.3/CANIF739 */
#endif
/* @req 4.0.3/CANIF724 */
if(NULL != CanIfDispatchConfig.CanIfBusOffNotification) {
/* @req 4.0.3/CANIF014 */
/* !req 4.0.3/CANIF449 */
CanIfDispatchConfig.CanIfBusOffNotification(channel);
}
#if (CANIF_OSEKNM_SUPPORT == STD_ON)
if (CanIf_ConfigPtr->Arc_ChannelConfig[channel].CanIfOsekNmNetId != CANIF_OSEKNM_INVALID_NET_ID) {
OsekNm_ControllerBusOff(CanIf_ConfigPtr->Arc_ChannelConfig[channel].CanIfOsekNmNetId);
}
#endif
}
/* !req 4.0.3/CANIF780 */
/* !req 4.0.3/CANIF784 */
#if ( CANIF_PUBLIC_CHANGE_BAUDRATE_SUPPORT == STD_ON ) && FEATURE_NOT_SUPPORTED
/* !req 4.0.3/CANIF775 */
Std_ReturnType CanIf_CheckBaudrate(uint8 ControllerId, const uint16 Baudrate)
{
/* !req 4.0.3/CANIF778 */
/* !req 4.0.3/CANIF779 */
return E_NOT_OK;
}
/* !req 4.0.3/CANIF776 */
Std_ReturnType CanIf_ChangeBaudrate(uint8 ControllerId, const uint16 Baudrate)
{
/* !req 4.0.3/CANIF782 */
/* !req 4.0.3/CANIF783 */
/* !req 4.0.3/CANIF787 */
return E_NOT_OK;
}
#endif
/* !req 4.0.3/CANIF357 */
#if ( CANIF_PUBLIC_SETDYNAMICTXID_API == STD_ON ) && FEATURE_NOT_SUPPORTED
/* !req 4.0.3/CANIF189 */
void CanIf_SetDynamicTxId( PduIdType CanTxPduId, Can_IdType CanId )
{
/* !req 4.0.3/CANIF188 */ //Maybe this req. should be elsewhere
/* !req 4.0.3/CANIF352 */
/* !req 4.0.3/CANIF353 */
/* !req 4.0.3/CANIF355 */
/* !req 4.0.3/CANIF356 */
/* !req 4.0.3/CANIF673 */
}
#endif
/* @req 4.0.3/CANIF362 */
/* @req 4.0.3/CANIF367 */
/* @req 4.0.3/CANIF371 */
/* @req 4.0.3/CANIF373 */
/* @req 4.0.3/CANIF730 */
#if ( CANIF_ARC_TRANSCEIVER_API == STD_ON )
/* @req 4.0.3/CANIF287 */
Std_ReturnType CanIf_SetTrcvMode( uint8 TransceiverId, CanTrcv_TrcvModeType TransceiverMode )
{
uint8 trcvHwCnlId;
boolean validSts;
/* @req 4.0.3/CANIF661 */
VALIDATE_RV((TRUE == CanIf_Global.initRun), CANIF_SET_TRANSCEIVERMODE_ID, CANIF_E_UNINIT,E_NOT_OK);
/* @req 4.0.3/CANIF538 */
VALIDATE_RV((TransceiverId < CANIF_TRANSCEIVER_CHANNEL_CNT), CANIF_SET_TRANSCEIVERMODE_ID, CANIF_E_PARAM_TRCV,E_NOT_OK);
/* @req 4.0.3/CANIF648 */
validSts = ((CANTRCV_TRCVMODE_STANDBY == TransceiverMode)||(CANTRCV_TRCVMODE_SLEEP == TransceiverMode) ||(CANTRCV_TRCVMODE_NORMAL == TransceiverMode));
VALIDATE_RV((validSts), CANIF_SET_TRANSCEIVERMODE_ID, CANIF_E_PARAM_TRCVMODE,E_NOT_OK);
/* Maps from CanIfTransceiverId to CanTransceiverId */
trcvHwCnlId = ARC_GET_CAN_TRANSCEIVERID(TransceiverId);
/* @req 4.0.3/CANIF358 */
return CanTrcv_SetOpMode(trcvHwCnlId, TransceiverMode);
}
/* @req 4.0.3/CANIF288 */
Std_ReturnType CanIf_GetTrcvMode( CanTrcv_TrcvModeType *TransceiverModePtr, uint8 TransceiverId)
{
uint8 trcvHwCnlId;
/* @req 4.0.3/CANIF661 */
VALIDATE_RV((TRUE == CanIf_Global.initRun), CANIF_GET_TRANSCEIVERMODE_ID, CANIF_E_UNINIT,E_NOT_OK);
/* @req 4.0.3/CANIF364 */
VALIDATE_RV((TransceiverId < CANIF_TRANSCEIVER_CHANNEL_CNT), CANIF_GET_TRANSCEIVERMODE_ID, CANIF_E_PARAM_TRCV,E_NOT_OK);
/* @req 4.0.3/CANIF650 */
VALIDATE_RV(( NULL != TransceiverModePtr ), CANIF_GET_TRANSCEIVERMODE_ID, CANIF_E_PARAM_POINTER,E_NOT_OK);
/* Maps from CanIfTransceiverId to CanTransceiverId */
trcvHwCnlId = ARC_GET_CAN_TRANSCEIVERID(TransceiverId);
/* @req 4.0.3/CANIF363 */
return CanTrcv_GetOpMode(trcvHwCnlId, TransceiverModePtr);
}
/* @req 4.0.3/CANIF289 */
Std_ReturnType CanIf_GetTrcvWakeupReason(uint8 TransceiverId, CanTrcv_TrcvWakeupReasonType* TrcvWuReasonPtr)
{
uint8 trcvHwCnlId;
/* @req 4.0.3/CANIF661 */
VALIDATE_RV((TRUE == CanIf_Global.initRun), CANIF_GET_TRCVWAKEUPREASON_ID, CANIF_E_UNINIT,E_NOT_OK);
/* @req 4.0.3/CANIF537 */
VALIDATE_RV((TransceiverId < CANIF_TRANSCEIVER_CHANNEL_CNT), CANIF_GET_TRCVWAKEUPREASON_ID, CANIF_E_PARAM_TRCV,E_NOT_OK);
/* @req 4.0.3/CANIF649 */
VALIDATE_RV(( NULL != TrcvWuReasonPtr ), CANIF_GET_TRCVWAKEUPREASON_ID, CANIF_E_PARAM_POINTER,E_NOT_OK);
/* Maps from CanIfTransceiverId to CanTransceiverId */
trcvHwCnlId = ARC_GET_CAN_TRANSCEIVERID(TransceiverId);
/* @req 4.0.3/CANIF368 */
return CanTrcv_GetBusWuReason(trcvHwCnlId, TrcvWuReasonPtr);
}
/* @req 4.0.3/CANIF290 */
Std_ReturnType CanIf_SetTrcvWakeupMode(uint8 TransceiverId,CanTrcv_TrcvWakeupModeType TrcvWakeupMode)
{
uint8 trcvHwCnlId;
boolean validSts;
/* @req 4.0.3/CANIF661 */
VALIDATE_RV((TRUE == CanIf_Global.initRun), CANIF_SET_TRANSCEIVERWAKEMODE_ID, CANIF_E_UNINIT,E_NOT_OK);
/* @req 4.0.3/CANIF535 */
VALIDATE_RV((TransceiverId < CANIF_TRANSCEIVER_CHANNEL_CNT), CANIF_SET_TRANSCEIVERWAKEMODE_ID, CANIF_E_PARAM_TRCV,E_NOT_OK);
/* @req 4.0.3/CANIF536 */
validSts = (( TrcvWakeupMode == CANTRCV_WUMODE_ENABLE) || (TrcvWakeupMode == CANTRCV_WUMODE_DISABLE) || ( TrcvWakeupMode == CANTRCV_WUMODE_CLEAR));
VALIDATE_RV((validSts), CANIF_SET_TRANSCEIVERWAKEMODE_ID, CANIF_E_PARAM_TRCVWAKEUPMODE,E_NOT_OK);
/* Maps from CanIfTransceiverId to CanTransceiverId */
trcvHwCnlId = ARC_GET_CAN_TRANSCEIVERID(TransceiverId);
/* @req 4.0.3/CANIF372 */
return CanTrcv_SetWakeupMode (trcvHwCnlId,TrcvWakeupMode);
}
/* @req 4.0.3/CANIF764 */
void CanIf_TrcvModeIndication( uint8 TransceiverId, CanTrcv_TrcvModeType TransceiverMode )
{
uint8 Channel;
/* @req 4.0.3/CANIF710 */
/* @req 4.0.3/CANIF661 */
/* @req 4.0.3/CANIF708 */
/* @req 4.0.3/CANIF709 */
VALIDATE_NO_RV((TRUE == CanIf_Global.initRun), CANIF_TRANSCEIVER_MODE_INDICATION_ID, CANIF_E_UNINIT);
/* @req 4.0.3/CANIF706 */
VALIDATE_NO_RV((E_OK == TrcvToChnlId(TransceiverId,&Channel)), CANIF_TRANSCEIVER_MODE_INDICATION_ID, CANIF_E_PARAM_TRCV);
CanIf_Global.trcvData[Channel].trcvMode = TransceiverMode;
if( NULL != CanIfDispatchConfig.CanIfTrcvModeChangeNotification )
{
CanIfDispatchConfig.CanIfTrcvModeChangeNotification(Channel, TransceiverMode);
}
return;
}
#endif
/* @req 4.0.3/CANIF402 */
/* @req 4.0.3/CANIF180 */
#if (( CANIF_CTRL_WAKEUP_SUPPORT == STD_ON ) || (CANIF_TRCV_WAKEUP_SUPPORT == STD_ON))
/* @req 4.0.3/CANIF219 */
Std_ReturnType CanIf_CheckWakeup( EcuM_WakeupSourceType WakeupSource )
{
Std_ReturnType ApiReturn = E_NOT_OK;
uint8 trcvHwCnlId;
uint64 wakUpSrc;
EcuM_WakeupSourceType lastWakUpSrcVal;
boolean wakUpSrcFound;
uint8 i;
/* @req 4.0.3/CANIF661 */
/* @req 4.0.3/CANIF401 */
VALIDATE_RV((TRUE == CanIf_Global.initRun), CANIF_CHECKWAKEUP_ID, CANIF_E_UNINIT,E_NOT_OK);
/* @req 4.0.3/CANIF398 */
/* Wakeup source is bit coded message only one unique bit is set to indicate a source, find the last in the list */
lastWakUpSrcVal = (1<<(ECUM_WKSOURCE_USER_CNT+ECUM_WKSOURCE_SYSTEM_CNT-1));
wakUpSrcFound = FALSE;
for (wakUpSrc=1; wakUpSrc <=lastWakUpSrcVal ;wakUpSrc = (wakUpSrc<<1u))
{
if ((uint32)wakUpSrc == WakeupSource)
{
wakUpSrcFound = TRUE;
break;
}
}
VALIDATE_RV((wakUpSrcFound), CANIF_CHECKWAKEUP_ID, CANIF_E_PARAM_WAKEUPSOURCE,E_NOT_OK);
#if ( CANIF_TRCV_WAKEUP_SUPPORT == STD_ON )
/* @req 4.0.3/CANIF395 */
/* @req 4.0.3/CANIF720 */
/* @req 4.0.3/CANIF678 */
for( i = 0; i < CANIF_TRANSCEIVER_CHANNEL_CNT; i++) {
if((CanIf_ConfigPtr->CanIfTransceiverConfig[i].CanIfTrcvWakeupSupport) && (CanIf_ConfigPtr->CanIfTransceiverConfig[i].CanIfTrcvCanTrcvWakeupSrc == WakeupSource)){
trcvHwCnlId = ARC_GET_CAN_TRANSCEIVERID(i);
if(E_OK == CanTrcv_CheckWakeup(trcvHwCnlId)){
ApiReturn = E_OK;
}
}
}
#endif
#if ( CANIF_CTRL_WAKEUP_SUPPORT == STD_ON )
/* @req 4.0.3/CANIF395 */ /* Not fulfilled for Can controller */
/* @req 4.0.3/CANIF720 */
/* @req 4.0.3/CANIF678 */
/* !req 4.0.3/CANIF679 */
#endif
return ApiReturn;
}
#endif
/* @req 4.0.3/CANIF226 */
/* @req 4.0.3/CANIF408 */
#if (CANIF_PUBLIC_WAKEUP_CHECK_VALIDATION_SUPPORT == STD_ON)
/* @req 4.0.3/CANIF178 */
Std_ReturnType CanIf_CheckValidation( EcuM_WakeupSourceType WakeupSource )
{
Std_ReturnType status;
Std_ReturnType ret;
uint64 wakUpSrc;
EcuM_WakeupSourceType lastWakUpSrcVal;
EcuM_WakeupSourceType temp;
boolean wakUpSrcFound;
uint8 i;
uint8 canIfCtrlChnl;
ret = E_OK;
status = E_NOT_OK;
/* @req 4.0.3/CANIF661 */
/* @req 4.0.3/CANIF407 */
VALIDATE_RV((TRUE == CanIf_Global.initRun), CANIF_CHECKVALIDATION_ID, CANIF_E_UNINIT,E_NOT_OK);
/* @req 4.0.3/CANIF404 */
/* Wakeup source is bit coded message only one unique bit is set to indicate a source, find the last in the list */
lastWakUpSrcVal = (1UL<<(ECUM_WKSOURCE_USER_CNT+ECUM_WKSOURCE_SYSTEM_CNT-1));
wakUpSrcFound = FALSE;
for (wakUpSrc=1; wakUpSrc <=lastWakUpSrcVal ;wakUpSrc = (wakUpSrc<<1u))
{
if ((uint32)wakUpSrc == WakeupSource)
{
wakUpSrcFound = TRUE;
break;
}
}
VALIDATE_RV((wakUpSrcFound), CANIF_CHECKVALIDATION_ID, CANIF_E_PARAM_WAKEUPSOURCE,E_NOT_OK);
#if ( CANIF_TRCV_WAKEUP_SUPPORT == STD_ON )
wakUpSrcFound = FALSE;
for (i=0;i<CANIF_TRANSCEIVER_CHANNEL_CNT;i++)
{
if(CanIf_ConfigPtr->CanIfTransceiverConfig[i].CanIfTrcvCanTrcvWakeupSrc == WakeupSource)
{
wakUpSrcFound = TRUE;
canIfCtrlChnl = CanIf_ConfigPtr->CanIfTransceiverConfig[i].CanIfTrcvChnlToCanIfCtrlChnlRef;
break;
}
}
if (!wakUpSrcFound)
{
status = E_OK; /* The API is accepted but no not notification available because no matching wake up source configured */
}
if (status == E_NOT_OK){
/* @req 4.0.3/CANIF286 */
/*lint --e{661} --e{644} */ /* If wakeup source is unidentified the following code is not executed */
if ((CANTRCV_TRCVMODE_NORMAL == CanIf_Global.trcvData[i].trcvMode)
&& (CANIF_CS_STARTED == CanIf_Global.channelData[canIfCtrlChnl].ControllerMode))
{
if (CanIf_Global.channelData[canIfCtrlChnl].firstRxIndication)
{
/* @req 4.0.3/CANIF179 */
temp = WakeupSource;
} else{
/* @req 4.0.3/CANIF681 */
temp = 0;
}
if (CanIfDispatchConfig.CanIfWakeupValidNotification != NULL)
{
CanIfDispatchConfig.CanIfWakeupValidNotification(temp);
}
ret = E_OK;
}
} else {
ret = status;
}
#endif
#if( CANIF_CTRL_WAKEUP_SUPPORT == STD_ON )
#endif
return ret;
}
#endif
/* !req 4.0.3/CANIF738 */
#if ( CANIF_PUBLIC_TXCONFIRM_POLLING_SUPPORT == STD_ON ) && FEATURE_NOT_SUPPORTED
/* !req 4.0.3/CANIF734 */
CanIf_NotifStatusType CanIf_GetTxConfirmationState( uint8 ControllerId )
{
/* !req 4.0.3/CANIF736 */
/* !req 4.0.3/CANIF737 */
return CANIF_NO_NOTIFICATION;
}
#endif
/* @req 4.0.3/CANIF771 */
#if ( CANIF_PUBLIC_PN_SUPPORT == STD_ON )
/* @req 4.0.3/CANIF760 */
Std_ReturnType CanIf_ClearTrcvWufFlag( uint8 TransceiverId )
{
uint8 trcvHwCnlId;
/* @req 4.0.3/CANIF661 */
VALIDATE_RV((TRUE == CanIf_Global.initRun), CANIF_CLEARTRCVWUFFLAG_ID, CANIF_E_UNINIT,E_NOT_OK);
/* @req 4.0.3/CANIF769 */
VALIDATE_RV((TransceiverId < CANIF_TRANSCEIVER_CHANNEL_CNT), CANIF_CLEARTRCVWUFFLAG_ID, CANIF_E_PARAM_TRCV,E_NOT_OK);
/* Maps from CanIfTransceiverId to CanTransceiverId */
trcvHwCnlId = ARC_GET_CAN_TRANSCEIVERID(TransceiverId);
/* @req 4.0.3/CANIF766 */
return CanTrcv_ClearTrcvWufFlag(trcvHwCnlId);
}
#endif
/* @req 4.0.3/CANIF813 */
#if ( CANIF_PUBLIC_PN_SUPPORT == STD_ON )
/* @req 4.0.3/CANIF761 */
Std_ReturnType CanIf_CheckTrcvWakeFlag( uint8 TransceiverId )
{
uint8 trcvHwCnlId;
/* @req 4.0.3/CANIF661 */
VALIDATE_RV((TRUE == CanIf_Global.initRun), CANIF_CHECKTRCVWAKEFLAG_ID, CANIF_E_UNINIT,E_NOT_OK);
/* @req 4.0.3/CANIF770 */
VALIDATE_RV((TransceiverId < CANIF_TRANSCEIVER_CHANNEL_CNT), CANIF_CHECKTRCVWAKEFLAG_ID, CANIF_E_PARAM_TRCV,E_NOT_OK);
/* Maps from CanIfTransceiverId to CanTransceiverId */
trcvHwCnlId = ARC_GET_CAN_TRANSCEIVERID(TransceiverId);
/* @req 4.0.3/CANIF765 */
return CanTrcv_CheckWakeFlag(trcvHwCnlId);
}
#endif
/* @req 4.0.3/CANIF754 */
#if ( CANIF_PUBLIC_PN_SUPPORT == STD_ON )
/* @req 4.0.3/CANIF815 */
void CanIf_ConfirmPnAvailability( uint8 TransceiverId )
{
uint8 Channel;
/* @req 4.0.3/CANIF661 */
/* @req 4.0.3/CANIF817 */
/* @req 4.0.3/CANIF818 */
VALIDATE_NO_RV((TRUE == CanIf_Global.initRun), CANIF_CONFIRM_PNAVAILABILITY_ID, CANIF_E_UNINIT);
/* @req 4.0.3/CANIF816 */
VALIDATE_NO_RV((E_OK == TrcvToChnlId(TransceiverId,&Channel)), CANIF_CONFIRM_PNAVAILABILITY_ID, CANIF_E_PARAM_TRCV);
/* @req 4.0.3/CANIF753 */
if (CanIfDispatchConfig.CanIfTrcvConfirmPnAvailabilityNotification != NULL)
{
CanIfDispatchConfig.CanIfTrcvConfirmPnAvailabilityNotification(Channel);
}
return;
}
#endif
/* @req 4.0.3/CANIF808 */
#if ( CANIF_PUBLIC_PN_SUPPORT == STD_ON )
/* @req 4.0.3/CANIF762 */
void CanIf_ClearTrcvWufFlagIndication( uint8 TransceiverId )
{
uint8 Channel;
/* @req 4.0.3/CANIF661 */
/* @req 4.0.3/CANIF806 */
/* @req 4.0.3/CANIF807 */
VALIDATE_NO_RV((TRUE == CanIf_Global.initRun), CANIF_CLEARTRCV_WUFFLAG_INDICATION, CANIF_E_UNINIT);
/* @req 4.0.3/CANIF805 */
VALIDATE_NO_RV((E_OK == TrcvToChnlId(TransceiverId,&Channel)), CANIF_CLEARTRCV_WUFFLAG_INDICATION, CANIF_E_PARAM_TRCV);
/* @req 4.0.3/CANIF757 */
if (CanIfDispatchConfig.CanIfTrcvClearWakeFlagNotification != NULL)
{
CanIfDispatchConfig.CanIfTrcvClearWakeFlagNotification(Channel);
}
return;
}
#endif
/* @req 4.0.3/CANIF812 */
#if ( CANIF_PUBLIC_PN_SUPPORT == STD_ON )
/* @req 4.0.3/CANIF763 */
void CanIf_CheckTrcvWakeFlagIndication( uint8 TransceiverId )
{
uint8 Channel;
/* @req 4.0.3/CANIF661 */
/* @req 4.0.3/CANIF810 */
/* @req 4.0.3/CANIF811 */
VALIDATE_NO_RV((TRUE == CanIf_Global.initRun), CANIF_CHECKTRCV_WAKEFLAG_INDICATION, CANIF_E_UNINIT);
/* @req 4.0.3/CANIF809 */
VALIDATE_NO_RV((E_OK == TrcvToChnlId(TransceiverId,&Channel)), CANIF_CHECKTRCV_WAKEFLAG_INDICATION, CANIF_E_PARAM_TRCV);
/* @req 4.0.3/CANIF759 */
if (CanIfDispatchConfig.CanIfTrcvWakeFlagNotification != NULL)
{
CanIfDispatchConfig.CanIfTrcvWakeFlagNotification(Channel);
}
return;
}
#endif
|
2301_81045437/classic-platform
|
communication/CanIf/src/CanIf.c
|
C
|
unknown
| 73,207
|
# CanNm
obj-$(USE_CANNM) += CanNm.o
obj-$(USE_CANNM) += CanNm_Cfg.o
pb-obj-$(USE_CANNM) += CanNm_PBCfg.o
pb-pc-file-$(USE_CANNM) += CanNm_Cfg.c CanNm_Cfg.h
inc-$(USE_CANNM) += $(ROOTDIR)/communication/CanNm/inc
inc-$(USE_CANNM) += $(ROOTDIR)/communication/CanNm/src
vpath-$(USE_CANNM) += $(ROOTDIR)/communication/CanNm/src
|
2301_81045437/classic-platform
|
communication/CanNm/CanNm.mod.mk
|
Makefile
|
unknown
| 333
|
/*-------------------------------- 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 CANNM_H
#define CANNM_H
/** @req CANNM021 */
#define CANNM_VENDOR_ID 60u
#define CANNM_MODULE_ID 31u
#define CANNM_AR_RELEASE_MAJOR_VERSION 4u
#define CANNM_AR_RELEASE_MINOR_VERSION 0u
#define CANNM_AR_RELEASE_REVISION_VERSION 3u
#define CANNM_AR_MAJOR_VERSION CANNM_AR_RELEASE_MAJOR_VERSION
#define CANNM_AR_MINOR_VERSION CANNM_AR_RELEASE_MINOR_VERSION
#define CANNM_AR_PATCH_VERSION CANNM_AR_RELEASE_REVISION_VERSION
#define CANNM_SW_MAJOR_VERSION 2u
#define CANNM_SW_MINOR_VERSION 1u
#define CANNM_SW_PATCH_VERSION 0u
#include "CanNm_Cfg.h"
#include "ComStack_Types.h" /** @req CANNM245 */
#include "NmStack_Types.h" /** @req CANNM245 */
#include "CanNm_ConfigTypes.h"
#include "CanNm_PBCfg.h"
#include "CanNm_Cbk.h"
/** @req CANNM240 */
#define CANNM_E_NO_INIT 0x01u /** @req CANNM316 */ /**< API service used */
#define CANNM_E_INVALID_CHANNEL 0x02u /** @req CANNM317 */ /**< API service called with wrong channel handle */
/** NM-Timeout Timer has abnormally expired outside of the Ready Sleep State;
it may happen: (1) because of Bus-Off state, (2) if some ECU requests bus communication or node detection shortly
before the NMTimeout Timer expires so that a NM message can not be transmitted in time;
this race condition applies to event-triggered systems */
#define CANNM_E_INVALID_PDUID 0x03u /** @req CANNM318 */
#define CANNM_E_NET_START_IND 0x04u /** @req CANNM337 */
#define CANNM_E_INIT_FAILED 0x05u /** @req CANNM319 */
#define CANNM_E_NETWORK_TIMEOUT 0x11u /** @req CANNM321 */
#define CANNM_E_NULL_POINTER 0x12u /** @req CANNM322 */ /**< Null pointer has been passed as an argument (Does not apply to function CanNm_Init) */
#define CANNM_SERVICEID_INIT 0x00u
#define CANNM_SERVICEID_PASSIVESTARTUP 0x01u
#define CANNM_SERVICEID_NETWORKREQUEST 0x02u
#define CANNM_SERVICEID_NETWORKRELEASE 0x03u
#define CANNM_SERVICEID_DISABLECOMMUNICATION 0x0Cu
#define CANNM_SERVICEID_ENABLECOMMUNICATION 0x0Du
#define CANNM_SERVICEID_SETUSERDATA 0x04u
#define CANNM_SERVICEID_GETUSERDATA 0x05u
#define CANNM_SERVICEID_GETNODEIDENTIFIER 0x06u
#define CANNM_SERVICEID_GETLOCALNODEIDENTIFIER 0x07u
#define CANNM_SERVICEID_REPEATMESSAGEREQUEST 0x08u
#define CANNM_SERVICEID_GETPDUDATA 0x0Au
#define CANNM_SERVICEID_GETSTATE 0x0Bu
#define CANNM_SERVICEID_GETVERSIONINFO 0xF1u
#define CANNM_SERVICEID_REQUESTBUSSYNCHRONIZATION 0xC0u
#define CANNM_SERVICEID_CHECKREMOTESLEEPINDICATION 0xD0u
#define CANNM_SERVICEID_TXCONFIRMATION 0x0Fu
#define CANNM_SERVICEID_RXINDICATION 0x10u
#define CANNM_SERVICEID_MAINFUNCTION 0x13u
#define CANNM_SERVICEID_TRANSMIT 0x14u
#define CANNM_SERVICEID_CONFIRMPNAVAILABILITY 0x16u
// Functions called by NM Interface
// --------------------------------
/** Initialize the complete CanNm module, i.e. all channels which are activated */
/** @req CANNM208 */
void CanNm_Init(const CanNm_ConfigType * const cannmConfigPtr);
/** Passive startup of the AUTOSAR CAN NM. It triggers the transition from Bus-
* Sleep Mode to the Network Mode in Repeat Message State.
* This service has no effect if the current state is not equal to Bus-Sleep Mode. In
* that case NM_E_NOT_EXECUTED is returned. */
/** @req CANNM211 */
Std_ReturnType CanNm_PassiveStartUp(const NetworkHandleType nmChannelHandle);
/** Request the network, since ECU needs to communicate on the bus. Network
* state shall be changed to �requested� */
/** @req CANNM213 */
Std_ReturnType CanNm_NetworkRequest(const NetworkHandleType nmChannelHandle);
/** Release the network, since ECU doesn�t have to communicate on the bus. Network
* state shall be changed to �released�. */
/** @req CANNM214 */
Std_ReturnType CanNm_NetworkRelease(const NetworkHandleType nmChannelHandle);
#if (CANNM_COM_CONTROL_ENABLED == STD_ON)
/** Disable the NM PDU transmission ability due to a ISO14229 Communication
* Control (28hex) service */
/** @req CANNM215 */
Std_ReturnType CanNm_DisableCommunication(const NetworkHandleType nmChannelHandle);
/** Enable the NM PDU transmission ability due to a ISO14229 Communication
* Control (28hex) service */
/** @req CANNM216 */
Std_ReturnType CanNm_EnableCommunication(const NetworkHandleType nmChannelHandle);
#endif
/** Set user data for NM messages transmitted next on the bus. */
/** @req CANNM217 */
Std_ReturnType CanNm_SetUserData(const NetworkHandleType nmChannelHandle,
const uint8* const nmUserDataPtr);
/** Get user data out of the most recently received NM message. */
/** @req CANNM218 */
Std_ReturnType CanNm_GetUserData(const NetworkHandleType nmChannelHandle,
uint8* const nmUserDataPtr);
/** Get node identifier out of the most recently received NM PDU. */
/** @req CANNM219 */
Std_ReturnType CanNm_GetNodeIdentifier(const NetworkHandleType nmChannelHandle,
uint8 * const nmNodeIdPtr);
/** Get node identifier configured for the local node. */
/** @req CANNM220 */
Std_ReturnType CanNm_GetLocalNodeIdentifier(
const NetworkHandleType nmChannelHandle, uint8 * const nmNodeIdPtr);
/** Set Repeat Message Request Bit for NM messages transmitted next on the bus. */
/** @req CANNM221 */
Std_ReturnType CanNm_RepeatMessageRequest(
const NetworkHandleType nmChannelHandle);
/** Get the whole PDU data out of the most recently received NM message. */
/** @req CANNM222 */
Std_ReturnType CanNm_GetPduData(const NetworkHandleType nmChannelHandle,
uint8 * const nmPduDataPtr);
/** Returns the state and the mode of the network management. */
/** @req CANNM223 */
Std_ReturnType CanNm_GetState(const NetworkHandleType nmChannelHandle,
Nm_StateType * const nmStatePtr, Nm_ModeType * const nmModePtr);
/** Request bus synchronization. */
/** @req CANNM226 */
Std_ReturnType CanNm_RequestBusSynchronization(
const NetworkHandleType nmChannelHandle);
/** Check if remote sleep indication takes place or not. */
/** @req CANNM227 */
Std_ReturnType CanNm_CheckRemoteSleepIndication(
const NetworkHandleType nmChannelHandle,
boolean * const nmRemoteSleepIndPtr);
/** This service returns the version information of this module. */
/** @req CANNM224 */
#if ( CANNM_VERSION_INFO_API == STD_ON ) /** @req CANNM278 */
#define CanNm_GetVersionInfo(_vi) STD_GET_VERSION_INFO(_vi,CANNM) /** @req CANNM225 */
#endif /* CANNM_VERSION_INFO_API */
// Functions called by CAN Interface
// ---------------------------------
/** This service confirms a previous successfully processed CAN transmit request.
* This callback service is called by the CanIf and implemented by the CanNm. */
/** @req CANNM228 */
void CanNm_TxConfirmation(PduIdType canNmTxPduId);
/** This service indicates a successful reception of a received NM message to the
* CanNm after passing all filters and validation checks.
* This callback service is called by the CAN Interface and implemented by the CanNm. */
/** @req CANNM231 */
void CanNm_RxIndication(PduIdType RxPduId, PduInfoType *PduInfoPtr);
/**
* This function is used by the PduR to trigger a spontaneous transmission of an NM message
* with the provided NM User Data
*/
/* @req CANNM331 */
Std_ReturnType CanNm_Transmit(PduIdType CanNmTxPduId, const PduInfoType *PduInfoPtr);
/**
* Set the NM Coordinator Sleep Ready bit in the Control Bit Vector
* CURRENTLY UNSUPPORTED
*/
Std_ReturnType CanNm_SetSleepReadyBit(const NetworkHandleType nmChannelHandle,
const boolean nmSleepReadyBit);
/** @req 234 **/
void CanNm_MainFunction(void);
#ifdef HOST_TEST
extern void ReportErrorStatus(void);
void GetChannelRunTimeData(uint32 channelId, uint32* messageCycleTimeLeft, uint32* timeoutTimeLeft);
void CanNm_ConfirmPnAvailability(const NetworkHandleType nmChannelHandle);
Std_ReturnType VerifyAllEraBitsZero(void);
boolean IsPNbitSet(uint8 chanIndex, uint8 eraByteindex, uint8 PNbitIndex);
uint32 GetResetTimer(uint8 chanIdx, uint8 pnIdx);
#endif
/* @req CANNM344 */
void CanNm_ConfirmPnAvailability( const NetworkHandleType nmChannelHandle );
#endif /* CANNM_H */
|
2301_81045437/classic-platform
|
communication/CanNm/inc/CanNm.h
|
C
|
unknown
| 9,160
|
/*-------------------------------- 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 CANNM_CBK_H_
#define CANNM_CBK_H_
/* We need this to export pdu id's */
#include "CanNm.h"
#endif /* CANNM_CBK_H_ */
|
2301_81045437/classic-platform
|
communication/CanNm/inc/CanNm_Cbk.h
|
C
|
unknown
| 893
|
/*-------------------------------- 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 CANNM_CONFIGTYPES_H_
#define CANNM_CONFIGTYPES_H_
#define CANNM_UNUSED_CHANNEL 0xFFu
typedef enum {
CANNM_PDU_BYTE_0 = 0x00,
CANNM_PDU_BYTE_1 = 0x01,
CANNM_PDU_OFF = 0xFF
} CanNm_PduBytePositionType;
/** @req CANNM202 */
typedef struct {
const boolean Active;
const NetworkHandleType NmNetworkHandle;
const uint8 NodeId;
const uint32 MainFunctionPeriod;
const uint32 TimeoutTime; /** @req CANNM246 */
const uint32 RepeatMessageTime; /** @req CANNM247 */
const uint32 WaitBusSleepTime; /** @req CANNM248 */
const uint32 MessageCycleTime;
const uint32 MessageCycleOffsetTime;
const uint32 MessageTimeoutTime;
const PduIdType CanIfPduId;
const PduLengthType PduLength;
const CanNm_PduBytePositionType NidPosition; /**< @req CANNM074 */
const CanNm_PduBytePositionType CbvPosition; /**< @req CANNM075 */
const uint32 ImmediateNmCycleTime; /**< @req CANNM335 */
const uint32 ImmediateNmTransmissions;
const boolean CanNmPnEnable;
const boolean CanNmPnEraCalcEnabled;
const boolean CanNmAllNmMsgKeepAwake;
#if (CANNM_COM_USER_DATA_SUPPORT == STD_ON)
const PduIdType CanNmUserDataTxPduId;
#endif
#if ((CANNM_PNC_COUNT > 0) && (CANNM_PNC_ERA_CALC_ENABLED == STD_ON))
PduIdType CanNmERARxNSduId; /* SDU carrying ERA */
#endif /* ((CANNM_PNC_COUNT > 0) && (CANNM_PNC_ERA_CALC_ENABLED == STD_ON)) */
} CanNm_ChannelType;
typedef struct {
uint8 CanNmPnInfoOffset; /* Offset Index */
PduLengthType CanNmPnInfoLen; /* PnInfo Length */
const uint8 *CanNmPnInfoMask; /* Pointer PNC mask bytes */
const uint8 *CanNmPnIndexToTimerMap; /* Mapping from PN index to reset timer index */
const uint8 *CanNmTimerIndexToPnMap; /* Mapping from timer index to PN index */
PduIdType CanNmEIRARxNSduId; /* SDU carrying EIRA */
}CanNm_PnInfoType;
typedef struct {
const CanNm_ChannelType* Channels; /* Pointer to the CanNm channels */
const NetworkHandleType* ChannelLookups; /* Pointer to lookup from NetworkHandle to index in CanNm channels */
const NetworkHandleType ChannelLookupsSize;/* Size of ChannelLookups */
const CanNm_PnInfoType * CanNmPnInfo; /* Pointer to Pn Info */
} CanNm_ConfigType; /** @req CANNM202 */
#endif /* CANNM_CONFIGTYPES_H_ */
|
2301_81045437/classic-platform
|
communication/CanNm/inc/CanNm_ConfigTypes.h
|
C
|
unknown
| 3,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 -----------------------------*/
/* Globally fulfilled requirements */
/** @req CANNM199 */ /* parameter checking */
/** @req CANNM196 */ /* equal to CANNM241 */
/** @req CANNM241 */ /* if det enabled => parameter checking */
/** @req CANNM292 */ /* check parameter pointers == null (all except init) */
/** @req CANNM210 */ /* mainfunction => instande id = 0 when deterror */
/** @req CANNM325 */ /* only describes optional API-functions */
/** @req CANNM206 */
/** @req CANNM192 */ /* => CANNM_VALIDATE_CHANNEL */
/** @req CANNM191 */ /* => CANNM_VALIDATE_INIT */
/** @req CANNM093 */
/** @req CANNM089 */
/** @req CANNM039 */ /* when not init every functions reports deterror => CANNM_VALIDATE_INIT at startup from every function*/
/** @req CANNM088 */ /* 7.1 Coordination algorithm */
/** @req CANNM089 */ /* 7.1 Coordination algorithm */
/** @req CANNM093 */ /* 7.2 Operation modes */
/** @req CANNM146 */ /* cpu independent */
/** @req CANNM158 */ /* supporting user data can be statically turned on or off (config dependent) */
/** @req CANNM161 */ /* passive mode can be statically turned on or off (config dependent) */
/** @req CANNM162 */ /* passive mode is statically configured for all instances */
/** @req CANNM189 */ /* no deterrors returned by NM-API */
/** @req CANNM197 toolchain */ /* type checking at compile time */
/** @req CANNM198 toolchain */ /* value checking at config time */
/* CANNM081 => 299, 300, 301 */
/** !req CANNM299 */ /* CanNm_Cfg.c does not contain any parameters*/
/** !req CANNM300 */ /* CanNm_Lcfg.c does not exist */
/** @req CANNM301 */ /* CanNm_PBcfg.c shall contain post build time configurable parameters */
/* CANNM044 => 302, 303, 304 */
/** @req CANNM302 */ /* CanNm.h shall contain the declaration of provided interface functions */
/** !req CANNM303 */ /* CanNm_Cbk.h shall contain the declaration of provided call-back functions */
/** @req CANNM304 */ /* CanNm_Cfg.h shall contain pre-compile time configurable parameters */
/* CANNM001 => 237, 238 */
/** @req CANNM237 */ /* The CanNm module shall provide the periodic transmission mode. In this transmission mode the CanNm module shall send Network Management PDUs periodically */
/** !req CANNM238 */ /* The CanNm module may provide the periodic transmission mode with bus load reduction. In this transmission mode the CanNm module shall transmit Network Management PDUs due to a specific algorithm */
/* CANNM016 => 243, 244 */
/** @req CANNM243 */ /* parameter value check only in devmode */
/** @req CANNM244 */ /* parameter invalidation */
/** @req CANNM416 *//* 1/0 in a each bit of PN info range represents whether PN is requested or not */
/** @req CANNM417 */ /* 1/0 in each bit of Filter mask byte configuration indicates whether required by ECU or not */
/** @req CANNM428 */ /* If PN supported EIRA reset timer for every PN request bit */
/** @req CANNM438 */ /* If PN supported ERA reset timer for every PN request bit for every channel */
#include "ComStack_Types.h" /** @req CANNM305 */
#include "CanNm.h" /** @req CANNM306 */
#include "CanNm_Cfg.h"
#include "CanNm_Internal.h"
#include "Nm_Cbk.h" /** @req CANNM307 */
#include "NmStack_Types.h" /** @req CANNM309 */
#include "SchM_CanNm.h" /** @req CANNM310 */
#include "MemMap.h" /** @req CANNM311 */
#include "CanIf.h" /** @req CANNM312 */
#include "Nm.h" /** @req CANNM313 */ /* according to the spec it should be Nm_Cfg.h */
#if (CANNM_USER_DATA_ENABLED == STD_ON) && (CANNM_COM_USER_DATA_SUPPORT == STD_ON) /** @req CANNM326 */
#include "PduR_CanNm.h"
#endif
#include <string.h>
#if (CANNM_DEV_ERROR_DETECT == STD_ON) /** @req CANNM188 */
#include "Det.h" /** @req CANNM308 */
#endif
#if defined(USE_DEM)
#include "Dem.h"
#endif
static const CanNm_ConfigType* CanNm_ConfigPtr;
//lint -save -e785 //PC-Lint exception: Too few initializers for aggregate...
CanNm_InternalType CanNm_Internal = {
.InitStatus = CANNM_STATUS_UNINIT,
};
//lint -restore
#ifdef HOST_TEST
void GetChannelRunTimeData(uint32 channelId, uint32* messageCycleTimeLeft, uint32* timeoutTimeLeft) {
const CanNm_Internal_ChannelType* ChannelInternal = &CanNm_Internal.Channels[channelId];
*messageCycleTimeLeft = ChannelInternal->MessageCycleTimeLeft;
*timeoutTimeLeft = ChannelInternal->TimeoutTimeLeft;
}
#if (CANNM_PNC_COUNT > 0)
Std_ReturnType VerifyAllEraBitsZero(void) {
Std_ReturnType ret;
ret = E_OK;
for (uint8 chanIndex = 0; ((chanIndex < CANNM_CHANNEL_COUNT) && (ret == E_OK)); chanIndex++) {
for (uint8 eraByteindex = 0; eraByteindex < CanNm_ConfigPtr->CanNmPnInfo->CanNmPnInfoLen; eraByteindex++) {
if (CanNm_Internal.Channels[chanIndex].pnERA.bytes[eraByteindex] != 0) {
ret = E_NOT_OK;
break;
}
}
}
return ret;
}
boolean IsPNbitSet(uint8 chanIndex, uint8 eraByteindex, uint8 PNbitIndex) {
boolean ret;
ret = FALSE;
if ((CanNm_Internal.Channels[chanIndex].pnERA.bytes[eraByteindex] & (1 << PNbitIndex)) == (1 << PNbitIndex)) {
ret = TRUE;
}
return ret;
}
uint32 GetResetTimer(uint8 chanIdx, uint8 pnIdx) {
uint8 timerIdx = CanNm_ConfigPtr->CanNmPnInfo->CanNmPnIndexToTimerMap[pnIdx];
return CanNm_Internal.Channels[chanIdx].pnERATimers[timerIdx].resetTimer;
}
#endif /* #if (CANNM_PNC_COUNT > 0) */
#endif
/** Initialize the complete CanNm module, i.e. all channels which are activated */
/** must be called directly after canif in order to fulfill CANNM253 */ /** @req CANNM253 */
void CanNm_Init( const CanNm_ConfigType * const cannmConfigPtr ){
CANNM_VALIDATE_NOTNULL_INIT(cannmConfigPtr, CANNM_SERVICEID_INIT, 0); //shall not be done for init
CanNm_ConfigPtr = cannmConfigPtr; /**< @req CANNM060 */
uint8 channel;
for (channel = 0; channel < CANNM_CHANNEL_COUNT; channel++) {
const CanNm_ChannelType* ChannelConf = &CanNm_ConfigPtr->Channels[channel];
CanNm_Internal_ChannelType* ChannelInternal = &CanNm_Internal.Channels[channel];
ChannelInternal->Mode = NM_MODE_BUS_SLEEP; /** @req CANNM144 */
ChannelInternal->State = NM_STATE_BUS_SLEEP; /** @req CANNM141 */
ChannelInternal->Requested = FALSE; /** @req CANNM143 */ /* reqeuested should be a state and not a flag */
ChannelInternal->CommunicationEnabled = TRUE;
ChannelInternal->immediateModeActive = FALSE;
ChannelInternal->MessageFilteringEnabled = FALSE;/** @req CANNM403 */
#if (CANNM_USER_DATA_ENABLED == STD_ON)
#if (CANNM_COM_USER_DATA_SUPPORT == STD_ON)
ChannelInternal->TransmissionStatus = CANNM_NO_TRANSMISSION;
#else
ChannelInternal->IsUserDataSet = FALSE;
#endif
#endif
/** @req CANNM085 */
memset(ChannelInternal->TxMessageSdu, 0x00, 8);
#if (CANNM_USER_DATA_ENABLED == STD_ON) && (CANNM_COM_USER_DATA_SUPPORT == STD_ON)
memset(ChannelInternal->SpontaneousTxMessageSdu, 0x00, 8);
#endif
memset(ChannelInternal->RxMessageSdu, 0x00, 8);
/** @req CANNM025 */
uint8* destUserData = CanNm_Internal_GetUserDataPtr(ChannelConf, ChannelInternal->TxMessageSdu);
PduLengthType userDataLength = CanNm_Internal_GetUserDataLength(ChannelConf);
memset(destUserData, 0xFFu, (size_t)userDataLength);
#if (CANNM_USER_DATA_ENABLED == STD_ON) && (CANNM_COM_USER_DATA_SUPPORT == STD_ON)
destUserData = CanNm_Internal_GetUserDataPtr(ChannelConf, ChannelInternal->SpontaneousTxMessageSdu);
userDataLength = CanNm_Internal_GetUserDataLength(ChannelConf);
memset(destUserData, 0xFF, (size_t)userDataLength);
#endif
/** @req CANNM013 */
if (ChannelConf->NidPosition != CANNM_PDU_OFF) {
ChannelInternal->TxMessageSdu[ChannelConf->NidPosition] = ChannelConf->NodeId;
#if (CANNM_USER_DATA_ENABLED == STD_ON) && (CANNM_COM_USER_DATA_SUPPORT == STD_ON)
ChannelInternal->SpontaneousTxMessageSdu[ChannelConf->NidPosition] = ChannelConf->NodeId;
#endif
}
/** @req CANNM045 */
if (ChannelConf->CbvPosition != CANNM_PDU_OFF) {
ChannelInternal->TxMessageSdu[ChannelConf->CbvPosition] = 0x00;
#if (CANNM_USER_DATA_ENABLED == STD_ON) && (CANNM_COM_USER_DATA_SUPPORT == STD_ON)
ChannelInternal->SpontaneousTxMessageSdu[ChannelConf->CbvPosition] = 0x00;
#endif
}
/** @req CANNM060 */
#if (CANNM_PASSIVE_MODE_ENABLED != STD_ON)
if (ChannelConf->ImmediateNmTransmissions > 0) {
ChannelInternal->MessageCycleTimeLeft = 0;
} else {
ChannelInternal->MessageCycleTimeLeft = 0;
}
ChannelInternal->MessageTimeoutTimeLeft = 0;
#endif
}
/* Initialize the PN reset timer */
#if ((CANNM_PNC_EIRA_CALC_ENABLED == STD_ON) && (CANNM_PNC_COUNT > 0))
for (uint8 i = 0; i < CANNM_PNC_COUNT; i++) {
CanNm_Internal.pnEIRATimers[i].timerRunning = FALSE;
CanNm_Internal.pnEIRATimers[i].resetTimer = 0;
}
/* @req CANNM424 */
CanNm_Internal.pnEIRA.data = 0; /* reset EIRA */
#endif
#if ((CANNM_PNC_ERA_CALC_ENABLED == STD_ON) && (CANNM_PNC_COUNT > 0))
for (uint8 chanIndex = 0; chanIndex < CANNM_CHANNEL_COUNT; chanIndex++) {
for (uint8 timerIndex = 0; timerIndex < CANNM_PNC_COUNT; timerIndex++) {
CanNm_Internal.Channels[chanIndex].pnERATimers[timerIndex].timerRunning = FALSE;
CanNm_Internal.Channels[chanIndex].pnERATimers[timerIndex].resetTimer = 0;
}
/* @req CANNM435 */
CanNm_Internal.Channels[chanIndex].pnERA.data = 0;
}
#endif
CanNm_Internal.InitStatus = CANNM_STATUS_INIT;
/** @req CANNM061 */
/** @req CANNM033 */
}
/** Passive startup of the AUTOSAR CAN NM. It triggers the transition from Bus-
* Sleep Mode to the Network Mode in Repeat Message State.
* This service has no effect if the current state is not equal to Bus-Sleep Mode. In
* that case NM_E_NOT_EXECUTED is returned. */
Std_ReturnType CanNm_PassiveStartUp( const NetworkHandleType nmHandle){
CANNM_VALIDATE_INIT(CANNM_SERVICEID_PASSIVESTARTUP);
CANNM_VALIDATE_CHANNEL(nmHandle, CANNM_SERVICEID_PASSIVESTARTUP);
uint8 channelIndex = CanNm_ConfigPtr->ChannelLookups[nmHandle];
/** @req CANNM254 */
const CanNm_ChannelType* ChannelConf = &CanNm_ConfigPtr->Channels[channelIndex];
CanNm_Internal_ChannelType* ChannelInternal = &CanNm_Internal.Channels[channelIndex];
Std_ReturnType status = E_OK;
if (ChannelInternal->Mode == NM_MODE_BUS_SLEEP) {
CanNm_Internal_BusSleep_to_RepeatMessage(ChannelConf, ChannelInternal,FALSE); /**< @req CANNM128 @req CANNM314 */
status = E_OK;
} else {
status = E_NOT_OK; /** @req CANNM147 */ /** @req CANNM212 */
}
#if (CANNM_PNC_COUNT > 0)
if (ChannelConf->CanNmPnEnable) {
/* @req CANNM413 */
/* @req CANNM414 */
CanNm_Internal_SetPNICbv(ChannelConf,ChannelInternal);
}
#endif
return status;
}
/** Request the network, since ECU needs to communicate on the bus. Network
* state shall be changed to �requested� */
Std_ReturnType CanNm_NetworkRequest( const NetworkHandleType nmHandle ){
CANNM_VALIDATE_INIT(CANNM_SERVICEID_NETWORKREQUEST);
CANNM_VALIDATE_CHANNEL(nmHandle, CANNM_SERVICEID_NETWORKREQUEST);
uint8 channelIndex = CanNm_ConfigPtr->ChannelLookups[nmHandle];
/** @req CANNM256 */
const CanNm_ChannelType* ChannelConf = &CanNm_ConfigPtr->Channels[channelIndex];
CanNm_Internal_ChannelType* ChannelInternal = &CanNm_Internal.Channels[channelIndex];
/** @req CANNM255 */
ChannelInternal->Requested = TRUE; /**< @req CANNM104 */ /* reqeuested should be a state and not a flag */
if (ChannelInternal->Mode == NM_MODE_BUS_SLEEP) {
CanNm_Internal_BusSleep_to_RepeatMessage(ChannelConf, ChannelInternal,TRUE); /**< @req CANNM129 @req CANNM314 */
} else if (ChannelInternal->Mode == NM_MODE_PREPARE_BUS_SLEEP) {
CanNm_Internal_PrepareBusSleep_to_RepeatMessage(ChannelConf, ChannelInternal, TRUE); /**< @req CANNM123 @req CANNM315 */
} else if (ChannelInternal->Mode == NM_MODE_NETWORK) {
if (ChannelInternal->State == NM_STATE_READY_SLEEP) {
CanNm_Internal_ReadySleep_to_NormalOperation(ChannelConf, ChannelInternal); /**< @req CANNM110 */
}
} else {
//Nothing to be done
}
#if (CANNM_PNC_COUNT > 0)
if (ChannelConf->CanNmPnEnable)
{
/* @req CANNM413 */
/* @req CANNM414 */
CanNm_Internal_SetPNICbv(ChannelConf,ChannelInternal);
}
#endif
return E_OK;
}
/** Release the network, since ECU doesn�t have to communicate on the bus. Network
* state shall be changed to �released�. */
Std_ReturnType CanNm_NetworkRelease( const NetworkHandleType nmHandle ){
Std_ReturnType status;
status = E_OK;
CANNM_VALIDATE_INIT(CANNM_SERVICEID_NETWORKRELEASE);
CANNM_VALIDATE_CHANNEL(nmHandle, CANNM_SERVICEID_NETWORKRELEASE);
uint8 channelIndex = CanNm_ConfigPtr->ChannelLookups[nmHandle];
/** @req CANNM259 */
const CanNm_ChannelType* ChannelConf = &CanNm_ConfigPtr->Channels[channelIndex];
CanNm_Internal_ChannelType* ChannelInternal = &CanNm_Internal.Channels[channelIndex];
if (!ChannelInternal->CommunicationEnabled) {
status = E_NOT_OK; /* @req CANNM294 */
}
if (status == E_OK) {
/** @req CANNM258 */
ChannelInternal->Requested = FALSE; /**< @req CANNM105 */ /* released should be a state and not a flag */
if (ChannelInternal->Mode == NM_MODE_NETWORK) {
if (ChannelInternal->State == NM_STATE_NORMAL_OPERATION) {
CanNm_Internal_NormalOperation_to_ReadySleep(ChannelConf, ChannelInternal); /**< @req CANNM118 */
}
}
}
return status;
}
/** Disable the NM PDU transmission ability due to a ISO14229 Communication
* Control (28hex) service */
#if (CANNM_COM_CONTROL_ENABLED == STD_ON) /* @req CANNM262 */
Std_ReturnType CanNm_DisableCommunication( const NetworkHandleType nmHandle ){
Std_ReturnType status;
status = E_OK;
CANNM_VALIDATE_INIT(CANNM_SERVICEID_DISABLECOMMUNICATION); /* @req CANNM261 */
#if (CANNM_PASSIVE_MODE_ENABLED == STD_ON) /** @req CANNM298 */
status = E_NOT_OK;
#endif
if(status == E_OK){
CANNM_VALIDATE_CHANNEL(nmHandle, CANNM_SERVICEID_DISABLECOMMUNICATION);
uint8 channelIndex = CanNm_ConfigPtr->ChannelLookups[nmHandle];
CanNm_Internal_ChannelType* ChannelInternal = &CanNm_Internal.Channels[channelIndex];
if (ChannelInternal->Mode != NM_MODE_NETWORK) {
status = E_NOT_OK; /* @req CANNM172 */
}
if (status == E_OK){
ChannelInternal->CommunicationEnabled = FALSE;
}
}
return status;
}
#endif
/** Enable the NM PDU transmission ability due to a ISO14229 Communication
* Control (28hex) service */
#if (CANNM_COM_CONTROL_ENABLED == STD_ON) /* @req CANNM264 */
Std_ReturnType CanNm_EnableCommunication( const NetworkHandleType nmHandle ){
Std_ReturnType status;
status = E_OK;
CANNM_VALIDATE_INIT(CANNM_SERVICEID_ENABLECOMMUNICATION); /* @req CANNM263 */
#if (CANNM_PASSIVE_MODE_ENABLED == STD_ON) /** @req CANNM297 */
status = E_NOT_OK;
#endif
if (status == E_OK){
CANNM_VALIDATE_CHANNEL(nmHandle, CANNM_SERVICEID_ENABLECOMMUNICATION);
uint8 channelIndex = CanNm_ConfigPtr->ChannelLookups[nmHandle];
CanNm_Internal_ChannelType* ChannelInternal = &CanNm_Internal.Channels[channelIndex];
const CanNm_ChannelType* ChannelConf = &CanNm_ConfigPtr->Channels[channelIndex];
if (ChannelInternal->Mode != NM_MODE_NETWORK) {/* @req CANNM295 */
status = E_NOT_OK; /* @req CANNM295 */
}
if (status == E_OK){
if (ChannelInternal->CommunicationEnabled) {
status = E_NOT_OK; /* @req CANNM177*/
}
if (status == E_OK) {
ChannelInternal->MessageCycleTimeLeft = ChannelConf->MessageCycleOffsetTime + ChannelConf->MainFunctionPeriod; /* @req CANNM178 */
ChannelInternal->TimeoutTimeLeft = ChannelConf->TimeoutTime + ChannelConf->MainFunctionPeriod; /* @req CANNM179 */
ChannelInternal->CommunicationEnabled = TRUE; /* @req CANNM176 */
}
}
}
return status;
}
#endif
#if (CANNM_PASSIVE_MODE_ENABLED != STD_ON) /** @req CANNM266 */
#if (CANNM_USER_DATA_ENABLED == STD_ON) /** @req CANNM158 */
#if (CANNM_COM_USER_DATA_SUPPORT == STD_OFF) /** @req CANNM327 */
/** Set user data for NM messages transmitted next on the bus. */
/** @req CANNM159 */
Std_ReturnType CanNm_SetUserData( const NetworkHandleType nmHandle, const uint8* const nmUserDataPtr ){
CANNM_VALIDATE_INIT(CANNM_SERVICEID_SETUSERDATA);
CANNM_VALIDATE_CHANNEL(nmHandle, CANNM_SERVICEID_SETUSERDATA);
uint8 channelIndex = CanNm_ConfigPtr->ChannelLookups[nmHandle];
CANNM_VALIDATE_NOTNULL(nmUserDataPtr, CANNM_SERVICEID_SETUSERDATA, nmHandle);
/** @req CANNM265 */
Std_ReturnType retVal = E_NOT_OK;
const CanNm_ChannelType* ChannelConf = &CanNm_ConfigPtr->Channels[channelIndex];
CanNm_Internal_ChannelType* ChannelInternal = &CanNm_Internal.Channels[channelIndex];
/* can only be called once per cycle (per channel) */
if (!ChannelInternal->IsUserDataSet) /* this flag avoids inconsistency */
{
SchM_Enter_CanNm_EA_0();
ChannelInternal->IsUserDataSet = TRUE;
SchM_Exit_CanNm_EA_0();
{
uint8* destUserData = CanNm_Internal_GetUserDataPtr(ChannelConf, ChannelInternal->TxMessageSdu);
PduLengthType userDataLength = CanNm_Internal_GetUserDataLength(ChannelConf);
memcpy(destUserData, nmUserDataPtr, (size_t)userDataLength);
}
ChannelInternal->IsUserDataSet = FALSE;
retVal = E_OK;
}
return retVal;
}
#endif
#endif
#endif
#if (CANNM_USER_DATA_ENABLED == STD_ON) /** @req CANNM158 */ /**@req CANNM268 */
/** Get user data out of the most recently received NM message. */
/** @req CANNM160 */
Std_ReturnType CanNm_GetUserData( const NetworkHandleType nmHandle, uint8* const nmUserDataPtr ){
CANNM_VALIDATE_INIT(CANNM_SERVICEID_GETUSERDATA);
CANNM_VALIDATE_CHANNEL(nmHandle, CANNM_SERVICEID_GETUSERDATA);
uint8 channelIndex = CanNm_ConfigPtr->ChannelLookups[nmHandle];
CANNM_VALIDATE_NOTNULL(nmUserDataPtr, CANNM_SERVICEID_GETUSERDATA, nmHandle);
/** @req CANNM267 */
const CanNm_ChannelType* ChannelConf = &CanNm_ConfigPtr->Channels[channelIndex];
CanNm_Internal_ChannelType* ChannelInternal = &CanNm_Internal.Channels[channelIndex];
const uint8* sourceUserData = CanNm_Internal_GetUserDataPtr(ChannelConf, ChannelInternal->RxMessageSdu);
PduLengthType userDataLength = CanNm_Internal_GetUserDataLength(ChannelConf);
memcpy(nmUserDataPtr, sourceUserData, (size_t)userDataLength);
return E_OK;
}
#endif
/** Get node identifier out of the most recently received NM PDU. */
/** @req CANNM132 */
Std_ReturnType CanNm_GetNodeIdentifier( const NetworkHandleType nmHandle, uint8 * const nmNodeIdPtr ){
CANNM_VALIDATE_INIT(CANNM_SERVICEID_GETNODEIDENTIFIER);
CANNM_VALIDATE_CHANNEL(nmHandle, CANNM_SERVICEID_GETNODEIDENTIFIER);
uint8 channelIndex = CanNm_ConfigPtr->ChannelLookups[nmHandle];
CANNM_VALIDATE_NOTNULL(nmNodeIdPtr, CANNM_SERVICEID_GETNODEIDENTIFIER, nmHandle);
/** @req CANNM269 */
const CanNm_ChannelType* ChannelConf = &CanNm_ConfigPtr->Channels[channelIndex];
const CanNm_Internal_ChannelType* ChannelInternal = &CanNm_Internal.Channels[channelIndex];
Std_ReturnType status = E_NOT_OK;
if (ChannelConf->NidPosition == CANNM_PDU_OFF) { /** @req CANNM270 */
/* status = NM_E_NOT_EXECUTED; */
} else {
*nmNodeIdPtr = ChannelInternal->RxMessageSdu[ChannelConf->NidPosition];
status = E_OK;
}
return status;
}
/** Get node identifier configured for the local node. */
/** @req CANNM133 */
Std_ReturnType CanNm_GetLocalNodeIdentifier( const NetworkHandleType nmHandle, uint8 * const nmNodeIdPtr ){
CANNM_VALIDATE_INIT(CANNM_SERVICEID_GETLOCALNODEIDENTIFIER);
CANNM_VALIDATE_CHANNEL(nmHandle, CANNM_SERVICEID_GETLOCALNODEIDENTIFIER);
uint8 channelIndex = CanNm_ConfigPtr->ChannelLookups[nmHandle];
CANNM_VALIDATE_NOTNULL(nmNodeIdPtr, CANNM_SERVICEID_GETLOCALNODEIDENTIFIER, nmHandle);
/** @req CANNM271 */
const CanNm_ChannelType* ChannelConf = &CanNm_ConfigPtr->Channels[channelIndex];
*nmNodeIdPtr = ChannelConf->NodeId;
return E_OK;
}
#if (CANNM_NODE_DETECTION_ENABLED == STD_ON)
/** Set Repeat Message Request Bit for NM messages transmitted next on the bus. */
/** @req CANNM135 @req CANNM274 */
Std_ReturnType CanNm_RepeatMessageRequest( const NetworkHandleType nmHandle ){
CANNM_VALIDATE_INIT(CANNM_SERVICEID_REPEATMESSAGEREQUEST);
CANNM_VALIDATE_CHANNEL(nmHandle, CANNM_SERVICEID_REPEATMESSAGEREQUEST);
uint8 channelIndex = CanNm_ConfigPtr->ChannelLookups[nmHandle];
/** @req CANNM273 */
const CanNm_ChannelType* ChannelConf = &CanNm_ConfigPtr->Channels[channelIndex];
CanNm_Internal_ChannelType* ChannelInternal = &CanNm_Internal.Channels[channelIndex];
Std_ReturnType status = E_NOT_OK; /**< @req CANNM137 */
if (ChannelConf->CbvPosition != CANNM_PDU_OFF) {
if (ChannelInternal->State == NM_STATE_READY_SLEEP) {
ChannelInternal->TxMessageSdu[ChannelConf->CbvPosition] |= CANNM_CBV_REPEAT_MESSAGE_REQUEST; /**< @req CANNM113 */
#if (CANNM_USER_DATA_ENABLED == STD_ON) && (CANNM_COM_USER_DATA_SUPPORT == STD_ON)
ChannelInternal->SpontaneousTxMessageSdu[ChannelConf->CbvPosition] |= CANNM_CBV_REPEAT_MESSAGE_REQUEST;
#endif
CanNm_Internal_ReadySleep_to_RepeatMessage(ChannelConf, ChannelInternal); /**< @req CANNM112 */
status = E_OK;
} else if (ChannelInternal->State == NM_STATE_NORMAL_OPERATION) {
ChannelInternal->TxMessageSdu[ChannelConf->CbvPosition] |= CANNM_CBV_REPEAT_MESSAGE_REQUEST; /**< @req CANNM121 */
#if (CANNM_USER_DATA_ENABLED == STD_ON) && (CANNM_COM_USER_DATA_SUPPORT == STD_ON)
ChannelInternal->SpontaneousTxMessageSdu[ChannelConf->CbvPosition] |= CANNM_CBV_REPEAT_MESSAGE_REQUEST;
#endif
CanNm_Internal_NormalOperation_to_RepeatMessage(ChannelConf, ChannelInternal); /**< @req CANNM120 */
status = E_OK;
} else {
//Nothing to be done
}
}
return status;
}
#endif
/** Get the whole PDU data out of the most recently received NM message. */
/** @req CANNM138 @req CANNM276 */
Std_ReturnType CanNm_GetPduData( const NetworkHandleType nmHandle, uint8 * const nmPduDataPtr ){
CANNM_VALIDATE_INIT(CANNM_SERVICEID_GETPDUDATA);
CANNM_VALIDATE_CHANNEL(nmHandle, CANNM_SERVICEID_GETPDUDATA);
CANNM_VALIDATE_NOTNULL(nmPduDataPtr, CANNM_SERVICEID_GETPDUDATA, nmHandle);
uint8 channelIndex = CanNm_ConfigPtr->ChannelLookups[nmHandle];
/** @req CANNM275 */
const CanNm_ChannelType* ChannelConf = &CanNm_ConfigPtr->Channels[channelIndex];
const CanNm_Internal_ChannelType* ChannelInternal = &CanNm_Internal.Channels[channelIndex];
memcpy(nmPduDataPtr, ChannelInternal->RxMessageSdu, (size_t)ChannelConf->PduLength);
return E_OK;
}
/** Returns the state and the mode of the network management. */
Std_ReturnType CanNm_GetState( const NetworkHandleType nmHandle, Nm_StateType * const nmStatePtr, Nm_ModeType * const nmModePtr ){
CANNM_VALIDATE_INIT(CANNM_SERVICEID_GETSTATE);
CANNM_VALIDATE_CHANNEL(nmHandle, CANNM_SERVICEID_GETSTATE);
uint8 channelIndex = CanNm_ConfigPtr->ChannelLookups[nmHandle];
CANNM_VALIDATE_NOTNULL(nmStatePtr, CANNM_SERVICEID_GETSTATE, nmHandle);
CANNM_VALIDATE_NOTNULL(nmModePtr, CANNM_SERVICEID_GETSTATE, nmHandle);
/** @req CANNM277 */
const CanNm_Internal_ChannelType* ChannelInternal = &CanNm_Internal.Channels[channelIndex];
*nmStatePtr = ChannelInternal->State;
*nmModePtr = ChannelInternal->Mode;
return E_OK;
}
/** Request bus synchronization. */
Std_ReturnType CanNm_RequestBusSynchronization( const NetworkHandleType nmHandle ){
/* @req CANNM279 */
CANNM_VALIDATE_INIT(CANNM_SERVICEID_REQUESTBUSSYNCHRONIZATION);
CANNM_VALIDATE_CHANNEL(nmHandle, CANNM_SERVICEID_REQUESTBUSSYNCHRONIZATION);
// Not implemented
(void)nmHandle;
return E_NOT_OK;
}
/** Check if remote sleep indication takes place or not. */
Std_ReturnType CanNm_CheckRemoteSleepIndication( const NetworkHandleType nmHandle, boolean * const nmRemoteSleepIndPtr ){
/* @req CANNM281 */
CANNM_VALIDATE_INIT(CANNM_SERVICEID_CHECKREMOTESLEEPINDICATION);
CANNM_VALIDATE_CHANNEL(nmHandle, CANNM_SERVICEID_CHECKREMOTESLEEPINDICATION);
CANNM_VALIDATE_NOTNULL(nmRemoteSleepIndPtr, CANNM_SERVICEID_CHECKREMOTESLEEPINDICATION, nmHandle);
//lint -estring(920,pointer) /* cast to void */
(void)nmRemoteSleepIndPtr;
(void)nmHandle;
//lint +estring(920,pointer) /* cast to void */
// Not implemented
return E_NOT_OK;
}
// Functions called by CAN Interface
// ---------------------------------
/** This service confirms a previous successfully processed CAN transmit request.
* This callback service is called by the CanIf and implemented by the CanNm. */
/* modified CanNm_TxConfirmation & CanNm_Internal_TransmitMessage:
-when CanNm_Transmit is called by the PduR due to @req CANNM329 PduR_CanNmTxConfirmation must be called (when message was sent successfully)
=> so CanNm_TxConfirmation was modified
-due to the fact that destinction between cyclic messages and spontaneous massages is now a mondatory feature (spontaneous transmission => CanNm_Transmit)
CanNm_TxConfirmation has to decide what kind of message was lastly sent
=> this is done by a new internal flag in "CanNm_Internal_ChannelType" => TransmissionStatus
=> the flag is set by CanNm_Transmit (spontaneous message = CANNM_SPONTANEOUS_TRANSMISSION) & CanNm_internal_TransmitMessage (cyclic message = CANNM_ONGOING_TRANSMISSION)
=> cyclic messages or spontaneous messages can only be sent when the flag has "CANNM_NO_TRANSMISSION" status
=> when confirmation arrives (CanNm_TxConfirmation) the flag is set back to the lastly mentioned status
-because CanNm_Transmit & CanNm_internal_TransmitMessage both can set the mentioned flag an exclusive area (EXCLUSIVE_AREA_0) is used (SchM_CanNm is now mandatory)
-when CanNm_Transmit is enabled (CANNM_COM_USER_DATA_SUPPORT = STD_ON) CanNm_Internal_TransmitMessage needs to fetch the user Data from PduR by calling PduR_CanNmTriggerTransmit (@req CANNM328) */
void CanNm_TxConfirmation( PduIdType CanNmTxPduId ){
CANNM_VALIDATE_INIT_NORV(CANNM_SERVICEID_TXCONFIRMATION, CanNmTxPduId); /** @req CANNM229 */
CANNM_VALIDATE_PDUID_NORV(CanNmTxPduId, CANNM_SERVICEID_TXCONFIRMATION); /** @req CANNM229 */
/** @req CANNM283 */
const CanNm_ChannelType* ChannelConf = &CanNm_ConfigPtr->Channels[CanNmTxPduId];
CanNm_Internal_ChannelType* ChannelInternal = &CanNm_Internal.Channels[CanNmTxPduId];
#if (CANNM_USER_DATA_ENABLED == STD_ON) && (CANNM_COM_USER_DATA_SUPPORT == STD_ON)
/* is there an ongoing transmit */
if (ChannelInternal->TransmissionStatus == CANNM_SPONTANEOUS_TRANSMISSION)
{
/* transmit was ok */
PduR_CanNmTxConfirmation(ChannelConf->CanNmUserDataTxPduId); /** @req CANNM329 */
ChannelInternal->TransmissionStatus = CANNM_NO_TRANSMISSION;
}
else
#endif
{
if (ChannelInternal->Mode == NM_MODE_NETWORK) {
CanNm_Internal_NetworkMode_to_NetworkMode(ChannelConf, ChannelInternal); /**< @req CANNM099 */
}
}
ChannelInternal->MessageTimeoutTimeLeft = 0; /** @req CANNM065 **/
}
/** This service indicates a successful reception of a received NM message to the
* CanNm after passing all filters and validation checks.
* This callback service is called by the CAN Interface and implemented by the CanNm. */
/* @req CANNM135 */
/*lint -efunc(818,CanNm_RxIndication) Cannot declare pionter as pointing to const as API is defined by AUTOSAR */
void CanNm_RxIndication( PduIdType CanNmRxPduId, PduInfoType *PduInfoPtr ) {
/* @req CANNM285 */
boolean status;
status = TRUE;
CANNM_VALIDATE_INIT_NORV(CANNM_SERVICEID_RXINDICATION, CanNmRxPduId); /** @req CANNM232 */ /** @req CANNM233 */
CANNM_VALIDATE_NOTNULL_NORV(PduInfoPtr, CANNM_SERVICEID_RXINDICATION, CanNmRxPduId); /** @req CANNM232 */ /** @req CANNM233 */
CANNM_VALIDATE_NOTNULL_NORV(PduInfoPtr->SduDataPtr, CANNM_SERVICEID_RXINDICATION, CanNmRxPduId); /** @req CANNM232 */ /** @req CANNM233 */
CANNM_VALIDATE_PDUID_NORV(CanNmRxPduId, CANNM_SERVICEID_RXINDICATION); /** @req CANNM232 */ /** @req CANNM233 */
const CanNm_ChannelType* ChannelConf = &CanNm_ConfigPtr->Channels[CanNmRxPduId];
CanNm_Internal_ChannelType* ChannelInternal = &CanNm_Internal.Channels[CanNmRxPduId];
memcpy(ChannelInternal->RxMessageSdu, PduInfoPtr->SduDataPtr, (size_t)ChannelConf->PduLength); /**< @req CANNM035 */
#if (CANNM_NODE_DETECTION_ENABLED == STD_ON)
boolean repeatMessageBitIndication = FALSE;
#endif /* (CANNM_NODE_DETECTION_ENABLED == STD_ON) */
#if (CANNM_NODE_DETECTION_ENABLED == STD_ON) || (CANNM_PNC_COUNT > 0)
if (ChannelConf->CbvPosition != CANNM_PDU_OFF) {
uint8 cbv = ChannelInternal->RxMessageSdu[ChannelConf->CbvPosition];
#if (CANNM_NODE_DETECTION_ENABLED == STD_ON)
repeatMessageBitIndication = ((cbv & CANNM_CBV_REPEAT_MESSAGE_REQUEST) != 0u) ? TRUE: FALSE;
#endif /* (CANNM_NODE_DETECTION_ENABLED == STD_ON) */
#if (CANNM_PNC_COUNT > 0)
Std_ReturnType ret;
boolean pni = ((cbv & CANNM_CBV_PNI) != 0) ? TRUE: FALSE;
ret = CanNm_Internal_RxProcess(ChannelConf,ChannelInternal,pni);
if (E_NOT_OK == ret){
status = FALSE;
}
#endif
}
#endif /* (CANNM_NODE_DETECTION_ENABLED == STD_ON) || (CANNM_PNC_COUNT > 0) */
if (status == TRUE) {
if (ChannelInternal->Mode == NM_MODE_BUS_SLEEP) {
#if (CANNM_DEV_ERROR_DETECT == STD_ON)
/* @req CANNM019 */
CANNM_DET_REPORTERROR(CANNM_SERVICEID_RXINDICATION, CANNM_E_NET_START_IND, CanNmRxPduId); /** @req CANNM336 */
#endif
CanNm_Internal_BusSleep_to_BusSleep(ChannelConf, ChannelInternal); /**< @req CANNM127 */
} else if (ChannelInternal->Mode == NM_MODE_PREPARE_BUS_SLEEP) {
CanNm_Internal_PrepareBusSleep_to_RepeatMessage(ChannelConf, ChannelInternal,FALSE); /**< @req CANNM124 @req CANNM315 */
} else if (ChannelInternal->Mode == NM_MODE_NETWORK) {
CanNm_Internal_NetworkMode_to_NetworkMode(ChannelConf, ChannelInternal); /**< @req CANNM098 */
#if (CANNM_NODE_DETECTION_ENABLED == STD_ON)
if (repeatMessageBitIndication) {
if (ChannelInternal->State == NM_STATE_READY_SLEEP) {
CanNm_Internal_ReadySleep_to_RepeatMessage(ChannelConf, ChannelInternal); /**< @req CANNM111 */
} else if (ChannelInternal->State == NM_STATE_NORMAL_OPERATION) {
CanNm_Internal_NormalOperation_to_RepeatMessage(ChannelConf, ChannelInternal); /**< @req CANNM119 */
} else {
//Nothing to be done
}
}
#endif /* (CANNM_NODE_DETECTION_ENABLED == STD_ON) */
} else {
//Nothing to be done
}
#if (CANNM_PDU_RX_INDICATION_ENABLED == STD_ON)
// IMPROVEMENT: call NM rx indication
#endif
}
}
/**
* This function is used by the PduR to trigger a spontaneous transmission of an NM message
* with the provided NM User Data
*/
/* when transmit is called trough PduR the given CanNmUserDataTxPduId must be matched to the internal Channel
=> therefore each channel now needs the information which PduID matches to its internal configuration
=> added CanNmUserDataTxPduId to "CanNm_ChannelType"
=> this information must be filled at configuration-time
the transmit-function seeks all channels for the given pdu and goes on when its found => E_NOT_OK when not */
Std_ReturnType CanNm_Transmit( PduIdType CanNmUserDataTxPduId, const PduInfoType *PduInfoPtr) {
(void)CanNmUserDataTxPduId; /* Avoid compiler warning - used depedning on config */
//lint -estring(920,pointer) /* cast to void */
(void)PduInfoPtr; /* Avoid compiler warning - used depedning on config */
//lint +estring(920,pointer) /* cast to void */
Std_ReturnType retVal;
retVal = E_NOT_OK;
#if (CANNM_USER_DATA_ENABLED == STD_ON) && (CANNM_COM_USER_DATA_SUPPORT == STD_ON) /** @req CANNM330 */
/* only transmit when in
* repeat message state or normal operation state
* otherwise return E_NOT_OK;
*/
boolean found = FALSE;
/* read which channel is affected trough this CanNmUserDataTxPduId */
uint8 affectedChannel;
for (affectedChannel = 0; affectedChannel < CANNM_CHANNEL_COUNT; affectedChannel++) {
if (CanNmUserDataTxPduId == CanNm_ConfigPtr->Channels[affectedChannel].CanNmUserDataTxPduId) {
found = TRUE;
break;
}
}
/* If not found this pdu is invalid */
CANNM_VALIDATE(found, CANNM_SERVICEID_TRANSMIT, CANNM_E_INVALID_PDUID, 0, E_NOT_OK);
/* is channel configured */
CANNM_VALIDATE_CHANNEL(affectedChannel, CANNM_SERVICEID_TRANSMIT);
/* is pdu ptr null? */
CANNM_VALIDATE_NOTNULL(PduInfoPtr, CANNM_SERVICEID_TRANSMIT, affectedChannel); /* no requirement */
/* is data ptr null */
CANNM_VALIDATE_NOTNULL(PduInfoPtr->SduDataPtr, CANNM_SERVICEID_TRANSMIT, affectedChannel); /* no requirement */
if ((found == TRUE) && (affectedChannel < CANNM_CHANNEL_COUNT)) {
const CanNm_ChannelType* ChannelConf = &CanNm_ConfigPtr->Channels[affectedChannel];
CanNm_Internal_ChannelType* ChannelInternal = &CanNm_Internal.Channels[affectedChannel];
/* @req CANNM170*/
if (((ChannelInternal->State == NM_STATE_REPEAT_MESSAGE) || (ChannelInternal->State == NM_STATE_NORMAL_OPERATION)) &&
(ChannelInternal->CommunicationEnabled)) {
SchM_Enter_CanNm_EA_0();
/* check if there is an ongoing uncommited transmission */
if (ChannelInternal->TransmissionStatus == CANNM_NO_TRANSMISSION) {
uint8* destUserData = CanNm_Internal_GetUserDataPtr(ChannelConf, ChannelInternal->SpontaneousTxMessageSdu);
PduLengthType userDataLength = CanNm_Internal_GetUserDataLength(ChannelConf);
ChannelInternal->TransmissionStatus = CANNM_SPONTANEOUS_TRANSMISSION;
SchM_Exit_CanNm_EA_0();
memcpy(destUserData, PduInfoPtr->SduDataPtr, (size_t)userDataLength);
{
PduInfoType pdu = {
.SduDataPtr = ChannelInternal->SpontaneousTxMessageSdu,
.SduLength = ChannelConf->PduLength,
};
retVal = CanIf_Transmit(ChannelConf->CanIfPduId, &pdu);
/* in order to avoid locking the possibility to send we have to reset the flag when CanIf_Tansmit fails */
if (retVal != E_OK) {
ChannelInternal->TransmissionStatus = CANNM_NO_TRANSMISSION;
}
#if ((CANNM_PNC_EIRA_CALC_ENABLED == STD_ON) && (CANNM_PNC_COUNT > 0))
if (ChannelConf->CanNmPnEnable) {
CanNm_Internal_ProcessTxPdu(pdu.SduDataPtr+CanNm_ConfigPtr->CanNmPnInfo->CanNmPnInfoOffset);
}
#endif
}
} else {
SchM_Exit_CanNm_EA_0();
}
}
}
#else
retVal = E_OK; /** @req CANNM333 */
#endif
return retVal;
}
/**
* Set the NM Coordinator Sleep Ready bit in the Control Bit Vector
* CURRENTLY UNSUPPORTED
*/
Std_ReturnType CanNm_SetSleepReadyBit( const NetworkHandleType nmHandle, const boolean nmSleepReadyBit) {
/* not supported */
(void)nmHandle;
(void)nmSleepReadyBit;
return E_NOT_OK;
}
/** @req CANNM234 */
void CanNm_MainFunction( void ) {
CANNM_VALIDATE_INIT_NORV(CANNM_SERVICEID_MAINFUNCTION,0); /** @req CANNM235 */ /**@req CANNM236 */
uint8 channel;
for (channel = 0; channel < CANNM_CHANNEL_COUNT; channel++) {
/** @req CANNM108 */
const CanNm_ChannelType* ChannelConf = &CanNm_ConfigPtr->Channels[channel];
CanNm_Internal_ChannelType* ChannelInternal = &CanNm_Internal.Channels[channel];
if (ChannelInternal->Mode == NM_MODE_NETWORK) {
if (ChannelInternal->State == NM_STATE_REPEAT_MESSAGE) {
CanNm_Internal_TickRepeatMessageTime(ChannelConf, ChannelInternal); /**< @req CANNM102 */
}
#if (CANNM_PASSIVE_MODE_ENABLED != STD_ON)
CanNm_Internal_TickTxTimeout(ChannelConf, ChannelInternal);
#endif
/* @req CANNM174 */
if (ChannelInternal->CommunicationEnabled) {
CanNm_Internal_TickTimeoutTime(ChannelConf, ChannelInternal);
}
#if (CANNM_PASSIVE_MODE_ENABLED != STD_ON)
/** @req CANNM161 */ /** @req CANNM162 */ /** @req CANNM072 */
if (((ChannelInternal->State == NM_STATE_REPEAT_MESSAGE) || (ChannelInternal->State == NM_STATE_NORMAL_OPERATION)) &&
(ChannelInternal->CommunicationEnabled)) {
/** @req CANNM051 @req CANNM032 @req CANNM087 @req CANNM100 */
/** @req CANNM173 @req CANNM170 */
CanNm_Internal_TickMessageCycleTime(ChannelConf, ChannelInternal);
}
#endif
} else if (ChannelInternal->Mode == NM_MODE_PREPARE_BUS_SLEEP) {
CanNm_Internal_TickWaitBusSleepTime(ChannelConf, ChannelInternal); /**< @req CANNM115 */
} else {
//Nothing to be done
}
}
#if ((CANNM_PNC_EIRA_CALC_ENABLED == STD_ON) && (CANNM_PNC_COUNT > 0))
CanNm_Internal_TickPnEIRAResetTime();
#endif
#if ((CANNM_PNC_ERA_CALC_ENABLED == STD_ON) && (CANNM_PNC_COUNT > 0))
CanNm_Internal_TickPnEraResetTime();
#endif
}
/* @req CANNM344 */
void CanNm_ConfirmPnAvailability( const NetworkHandleType nmChannelHandle )
{
/* @req CANNM345 */
CANNM_VALIDATE_INIT_NORV(CANNM_SERVICEID_CONFIRMPNAVAILABILITY,0);
CANNM_VALIDATE_NORV((nmChannelHandle< CanNm_ConfigPtr->ChannelLookupsSize), CANNM_SERVICEID_CONFIRMPNAVAILABILITY,CANNM_E_INVALID_CHANNEL,0);
uint8 channelIndex = CanNm_ConfigPtr->ChannelLookups[nmChannelHandle];
CanNm_Internal_ChannelType* ChannelInternal = &CanNm_Internal.Channels[channelIndex];
const CanNm_ChannelType* ChannelConf = &CanNm_ConfigPtr->Channels[channelIndex];
/* @req CANNM346 */
/* @req CANNM404 */
ChannelInternal->MessageFilteringEnabled = ChannelConf->CanNmPnEnable;
}
// Timer helpers
// -------------
#if ((CANNM_PNC_EIRA_CALC_ENABLED == STD_ON) && (CANNM_PNC_COUNT > 0))
/**
* @brief reset EIRA bits in case of timeout
* @param pnIndex - Indices of PNC which have timed out
* @param indexCount - No of PNC that have timed out
* @return void
*/
void CanNm_Internal_resetEIRAPNbits(uint8 *pnIndex, uint8 indexCount)
{
uint8 byteNo;
uint8 bit;
uint8 idx;
for (idx=0;idx<indexCount;idx++)
{
byteNo = (*(pnIndex+idx))/8;
bit = (*(pnIndex+idx))%8;
/* @req CANNM431 */
CanNm_Internal.pnEIRA.bytes[byteNo] &= ~(1u<<bit); /* Reset PN bit */
}
PduInfoType pdu =
{
.SduDataPtr = &CanNm_Internal.pnEIRA.bytes[0],
.SduLength = CanNm_ConfigPtr->CanNmPnInfo->CanNmPnInfoLen,
};
/* @req CANNM432 */
PduR_CanNmRxIndication(CanNm_ConfigPtr->CanNmPnInfo->CanNmEIRARxNSduId,&pdu);
}
/**
* @brief Run PN reset timers every main function cycle
* @param void
* @return void
*/
static inline void CanNm_Internal_TickPnEIRAResetTime(void)
{
uint8 pncIndexReset[CANNM_PNC_COUNT]= {0};
uint8 len;
len = 0;
uint8 timerIdx;
SchM_Enter_CanNm_EA_0();
for (timerIdx=0; timerIdx<CANNM_PNC_COUNT;timerIdx++) {
if (CanNm_Internal.pnEIRATimers[timerIdx].timerRunning)
{
if (CANNM_MAIN_FUNCTION_PERIOD >= CanNm_Internal.pnEIRATimers[timerIdx].resetTimer)
{
CanNm_Internal.pnEIRATimers[timerIdx].timerRunning = FALSE;
pncIndexReset[len] = CanNm_ConfigPtr->CanNmPnInfo->CanNmTimerIndexToPnMap[timerIdx];
len++;
} else {
CanNm_Internal.pnEIRATimers[timerIdx].resetTimer -= CANNM_MAIN_FUNCTION_PERIOD;
}
} else {
/* Do nothing */
}
}
if (len> 0)
{
CanNm_Internal_resetEIRAPNbits(pncIndexReset,len);
} else{
/* Do nothing */
}
SchM_Exit_CanNm_EA_0();
}
#endif
#if ((CANNM_PNC_ERA_CALC_ENABLED == STD_ON) && (CANNM_PNC_COUNT > 0))
/**
* @brief reset ERA bits in case of timeout
* @param pnIndex - Indices of PNC which have timed out
* @param indexCount - No of PNC that have timed out
* @return void
*/
void CanNm_Internal_ResetEraPnBits(uint8 chanIndex, uint8 *pnIndex, uint8 indexCount)
{
uint8 byteNo;
uint8 bit;
uint8 idx;
for (idx = 0; idx < indexCount; idx++)
{
byteNo = (*(pnIndex + idx)) / 8;
bit = (*(pnIndex + idx)) % 8;
/* @req CANNM442 */
CanNm_Internal.Channels[chanIndex].pnERA.bytes[byteNo] &= ~(1u << bit); /* Reset PN bit */
}
PduInfoType pdu =
{
.SduDataPtr = &CanNm_Internal.Channels[chanIndex].pnERA.bytes[0],
.SduLength = CanNm_ConfigPtr->CanNmPnInfo->CanNmPnInfoLen,
};
/* @req CANNM443 */
PduR_CanNmRxIndication(CanNm_ConfigPtr->Channels[chanIndex].CanNmERARxNSduId, &pdu);
}
/**
* @brief Run PN reset timers every main function cycle
* @param void
* @return void
*/
static inline void CanNm_Internal_TickPnEraResetTime(void) {
uint8 pncIndexReset[CANNM_PNC_COUNT]= {0};
uint8 len;
len = 0;
uint8 chanIdx;
uint8 timerIdx;
SchM_Enter_CanNm_EA_0();
for (chanIdx = 0; chanIdx < CANNM_CHANNEL_COUNT; chanIdx++) {
if (CanNm_ConfigPtr->Channels[chanIdx].CanNmPnEraCalcEnabled) {
for (timerIdx = 0; timerIdx < CANNM_PNC_COUNT; timerIdx++) {
if (CanNm_Internal.Channels[chanIdx].pnERATimers[timerIdx].timerRunning) {
if (CANNM_MAIN_FUNCTION_PERIOD >= CanNm_Internal.Channels[chanIdx].pnERATimers[timerIdx].resetTimer) {
CanNm_Internal.Channels[chanIdx].pnERATimers[timerIdx].timerRunning = FALSE;
pncIndexReset[len] = CanNm_ConfigPtr->CanNmPnInfo->CanNmTimerIndexToPnMap[timerIdx];
len++;
} else {
CanNm_Internal.Channels[chanIdx].pnERATimers[timerIdx].resetTimer -= CANNM_MAIN_FUNCTION_PERIOD;
}
}
}
if (len > 0) {
CanNm_Internal_ResetEraPnBits(chanIdx, pncIndexReset, len);
memset(pncIndexReset, 0, (size_t)CANNM_PNC_COUNT);
len = 0;
}
}
}
SchM_Exit_CanNm_EA_0();
}
#endif
/**
* @brief tick NM timeout time every main function cycle
* @param ChannelConf channel configuration
* @param ChannelInternal channel internal runtime data
* @return void
*/
static inline void CanNm_Internal_TickTimeoutTime( const CanNm_ChannelType* ChannelConf, CanNm_Internal_ChannelType* ChannelInternal ) {
if (ChannelConf->MainFunctionPeriod >= ChannelInternal->TimeoutTimeLeft) {
ChannelInternal->TimeoutTimeLeft = 0;
if (ChannelInternal->State == NM_STATE_REPEAT_MESSAGE) {
#if (CANNM_DEV_ERROR_DETECT == STD_ON) /** @req CANNM193 */
/* @req CANNM019 */
CANNM_DET_REPORTERROR(CANNM_SERVICEID_MAINFUNCTION, CANNM_E_NETWORK_TIMEOUT, 0); /* invalid due to requirement CANNM236 => main function should report instance id = channelId BUT we don't have the information here*/
#endif
#if (CANNM_USER_DATA_ENABLED == STD_ON) && (CANNM_COM_USER_DATA_SUPPORT == STD_ON)
/* reset confirmation flag in order for beeing able to send again*/
ChannelInternal->TransmissionStatus = CANNM_NO_TRANSMISSION;
#endif
CanNm_Internal_RepeatMessage_to_RepeatMessage(ChannelConf, ChannelInternal); /**< @req CANNM101 */
} else if (ChannelInternal->State == NM_STATE_NORMAL_OPERATION) {
#if (CANNM_DEV_ERROR_DETECT == STD_ON) /** @req CANNM194 */
/* @req CANNM019 */
CANNM_DET_REPORTERROR(CANNM_SERVICEID_MAINFUNCTION, CANNM_E_NETWORK_TIMEOUT, 0); /* invalid due to requirement CANNM236 => main function should report instance id = channelId BUT we don't have the information here*/
#endif
#if (CANNM_USER_DATA_ENABLED == STD_ON) && (CANNM_COM_USER_DATA_SUPPORT == STD_ON)
/* reset confirmation flag in order for beeing able to send again*/
ChannelInternal->TransmissionStatus = CANNM_NO_TRANSMISSION;
#endif
CanNm_Internal_NormalOperation_to_NormalOperation(ChannelConf, ChannelInternal); /**< @req CANNM117 */
} else if (ChannelInternal->State == NM_STATE_READY_SLEEP) {
CanNm_Internal_ReadySleep_to_PrepareBusSleep(ChannelConf, ChannelInternal); /**< @req CANNM109 */
} else {
//Nothing to be done
}
} else {
ChannelInternal->TimeoutTimeLeft -= ChannelConf->MainFunctionPeriod;
}
}
/**
* @brief tick repeat message time duration
* @param ChannelConf channel configuration
* @param ChannelInternal channel internal runtime data
* @return void
*/
/** @req CANNM102 */
static inline void CanNm_Internal_TickRepeatMessageTime( const CanNm_ChannelType* ChannelConf, CanNm_Internal_ChannelType* ChannelInternal ) {
if (ChannelConf->MainFunctionPeriod >= ChannelInternal->RepeatMessageTimeLeft) {
ChannelInternal->RepeatMessageTimeLeft = 0;
if (ChannelInternal->State == NM_STATE_REPEAT_MESSAGE) {
if (ChannelInternal->Requested) {
CanNm_Internal_RepeatMessage_to_NormalOperation(ChannelConf, ChannelInternal); /** @req CANNM103 */
} else {
CanNm_Internal_RepeatMessage_to_ReadySleep(ChannelConf, ChannelInternal); /** @req CANNM106 */
}
}
} else {
ChannelInternal->RepeatMessageTimeLeft -= ChannelConf->MainFunctionPeriod;
}
}
/**
* @brief tick wait bus sleep time duration
* @param ChannelConf channel configuration
* @param ChannelInternal channel internal runtime data
* @return void
*/
/** @req CANNM115 */
static inline void CanNm_Internal_TickWaitBusSleepTime( const CanNm_ChannelType* ChannelConf, CanNm_Internal_ChannelType* ChannelInternal ) {
if (ChannelConf->MainFunctionPeriod >= ChannelInternal->WaitBusSleepTimeLeft) {
ChannelInternal->WaitBusSleepTimeLeft = 0;
if (ChannelInternal->Mode == NM_MODE_PREPARE_BUS_SLEEP) {
CanNm_Internal_PrepareBusSleep_to_BusSleep(ChannelConf, ChannelInternal); /** @req CANNM088 */ /** @req CANNM115 */
}
} else {
ChannelInternal->WaitBusSleepTimeLeft -= ChannelConf->MainFunctionPeriod;
}
}
/**
* @brief tick timeout for Tx confirmation
* @param ChannelConf channel configuration
* @param ChannelInternal channel internal runtime data
* @return void
*/
/* TxTimeout Processing */
static inline void CanNm_Internal_TickTxTimeout( const CanNm_ChannelType* ChannelConf, CanNm_Internal_ChannelType* ChannelInternal ) {
if (0 != ChannelInternal->MessageTimeoutTimeLeft ) {
if (ChannelConf->MainFunctionPeriod >= ChannelInternal->MessageTimeoutTimeLeft ) {
/** @req CANNM066 **/
Nm_TxTimeoutException(ChannelConf->NmNetworkHandle);
ChannelInternal->MessageTimeoutTimeLeft = 0;
} else {
ChannelInternal->MessageTimeoutTimeLeft -= ChannelConf->MainFunctionPeriod;
}
}
}
/**
* @brief tick message cycle time
* @param ChannelConf channel configuration
* @param ChannelInternal channel internal runtime data
* @return void
*/
static inline void CanNm_Internal_TickMessageCycleTime( const CanNm_ChannelType* ChannelConf, CanNm_Internal_ChannelType* ChannelInternal ) {
if (ChannelConf->MainFunctionPeriod >= ChannelInternal->MessageCycleTimeLeft) {
if (ChannelInternal->immediateModeActive == TRUE) {
ChannelInternal->MessageCycleTimeLeft = ChannelConf->ImmediateNmCycleTime; /** @req CANNM334 */
} else {
ChannelInternal->MessageCycleTimeLeft = ChannelConf->MessageCycleTime; /** @req CANNM040 */
}
/** @req CANNM087 @req CANNM100 */
CanNm_Internal_TransmitMessage(ChannelConf, ChannelInternal); /** CANNM032 */ /* should transmit independently from state?! (CANNM032) */
} else {
ChannelInternal->MessageCycleTimeLeft -= ChannelConf->MainFunctionPeriod;
}
}
// Message helpers
// ---------------
/**
* @brief Handle periodic NM message transmission
* @param ChannelConf channel configuration
* @param ChannelInternal channel internal runtime data
* @return void
*/
static inline void CanNm_Internal_TransmitMessage( const CanNm_ChannelType* ChannelConf, CanNm_Internal_ChannelType* ChannelInternal ) {
boolean internal_status;
internal_status = TRUE;
PduInfoType pdu = {
.SduDataPtr = ChannelInternal->TxMessageSdu,
.SduLength = ChannelConf->PduLength,
};
if (!ChannelInternal->CommunicationEnabled) {
internal_status = FALSE;
}
if (internal_status == TRUE){
#if (CANNM_USER_DATA_ENABLED == STD_ON)
#if (CANNM_COM_USER_DATA_SUPPORT == STD_ON)
SchM_Enter_CanNm_EA_0();
if (ChannelInternal->TransmissionStatus == CANNM_NO_TRANSMISSION) {
PduInfoType userData;
ChannelInternal->TransmissionStatus = CANNM_ONGOING_TRANSMISSION;
SchM_Exit_CanNm_EA_0();
userData.SduDataPtr = CanNm_Internal_GetUserDataPtr(ChannelConf, ChannelInternal->TxMessageSdu);
userData.SduLength = CanNm_Internal_GetUserDataLength(ChannelConf);
/* IMPROVMENT: Add Det error when transmit is failing */
(void)PduR_CanNmTriggerTransmit(ChannelConf->CanNmUserDataTxPduId, &userData); /** @req CANNM328 */
#if ((CANNM_PNC_EIRA_CALC_ENABLED == STD_ON) && (CANNM_PNC_COUNT > 0))
if (ChannelConf->CanNmPnEnable) {
CanNm_Internal_ProcessTxPdu(pdu.SduDataPtr+CanNm_ConfigPtr->CanNmPnInfo->CanNmPnInfoOffset);
}
#endif
#else
SchM_Enter_CanNm_EA_0();
if (!ChannelInternal->IsUserDataSet) {
ChannelInternal->IsUserDataSet = TRUE;
SchM_Exit_CanNm_EA_0();
#endif
#endif
ChannelInternal->MessageTimeoutTimeLeft = ChannelConf->MessageTimeoutTime; /** @req CANNM064 */
// NOTE: what to do if Transmit fails?
Std_ReturnType status = CanIf_Transmit(ChannelConf->CanIfPduId, &pdu);
if (status != E_OK) {
#ifdef HOST_TEST
ReportErrorStatus();
#endif
}
/* check if we are sending immediateMessages */
if (ChannelInternal->immediateModeActive == TRUE) {
/* increment the immediateNmTransmissionsSent counter */
ChannelInternal->immediateNmTransmissionsSent++;
/* check if we already have reached the amount of messages which shall be send via immediateTransmit */
if (ChannelInternal->immediateNmTransmissionsSent == ChannelConf->ImmediateNmTransmissions) {
/* if so then deactivate the immediate mode again */
ChannelInternal->immediateModeActive = FALSE;
/* and wait offset before sending next regular (not immediate) pdu */
if (0 != ChannelConf->MessageCycleOffsetTime) {
ChannelInternal->MessageCycleTimeLeft = ChannelConf->MessageCycleOffsetTime; /** @req CANNM335 */
} else {
/* Offset is zero, wait message cycle time. */
ChannelInternal->MessageCycleTimeLeft = ChannelConf->MessageCycleTime;
}
}
}
#if (CANNM_USER_DATA_ENABLED == STD_ON)
#if (CANNM_COM_USER_DATA_SUPPORT == STD_ON)
/* set back the flag directly => this won't change the previous behaviour */
/* flag is only needed to decide whether the last successfully sent message was a spontaneous transmit or a cyclic message */
/* needed in function TxConfirmation */
ChannelInternal->TransmissionStatus = CANNM_NO_TRANSMISSION; /* no need to lock */
} else {
SchM_Exit_CanNm_EA_0();
}
#else
ChannelInternal->IsUserDataSet = FALSE;
} else {
SchM_Exit_CanNm_EA_0();
}
#endif
#endif
}
}
/**
* @brief Get user data offset byte index in NM Pdu
* @param ChannelConf channel configuration
* @return User starting data byte index in PDU
*/
static inline PduLengthType CanNm_Internal_GetUserDataOffset( const CanNm_ChannelType* ChannelConf ) {
PduLengthType userDataPos = 0;
userDataPos += (ChannelConf->NidPosition == CANNM_PDU_OFF) ? 0 : 1;
userDataPos += (ChannelConf->CbvPosition == CANNM_PDU_OFF) ? 0 : 1;
return userDataPos;
}
/**
* @brief get the ptr to user data location in Nm Pdu
* @param ChannelConf
* @param MessageSduPtr
* @return pointer to user data bytes in PDU
*/
static inline uint8* CanNm_Internal_GetUserDataPtr( const CanNm_ChannelType* ChannelConf, uint8* MessageSduPtr ) {
PduLengthType userDataOffset = CanNm_Internal_GetUserDataOffset(ChannelConf);
return &MessageSduPtr[userDataOffset];
}
/**
* @brief get user data length
* @param ChannelConf
* @return user data length
*/
static inline PduLengthType CanNm_Internal_GetUserDataLength( const CanNm_ChannelType* ChannelConf ) {
PduLengthType userDataOffset = CanNm_Internal_GetUserDataOffset(ChannelConf);
return ChannelConf->PduLength - userDataOffset;
}
/**
* @brief clear repeat message request indication in CBV byte of Nm Pdu
* @param ChannelConf
* @param ChannelInternal
* @return void
*/
static inline void CanNm_Internal_ClearRptMsgRqstCbv( const CanNm_ChannelType* ChannelConf, CanNm_Internal_ChannelType* ChannelInternal ) {
if (ChannelConf->CbvPosition != CANNM_PDU_OFF) {
ChannelInternal->TxMessageSdu[ChannelConf->CbvPosition] &= ~(CANNM_CBV_REPEAT_MESSAGE_REQUEST);
#if (CANNM_USER_DATA_ENABLED == STD_ON) && (CANNM_COM_USER_DATA_SUPPORT == STD_ON)
ChannelInternal->SpontaneousTxMessageSdu[ChannelConf->CbvPosition] &= ~(CANNM_CBV_REPEAT_MESSAGE_REQUEST);
#endif
}
}
/**
* @brief set the PNI bit in CBV byte of Nm Pdu
* @param ChannelConf - channel configuration
* @param ChannelInternal - channel internal runtime data
* @return void
*
*/
#if (CANNM_PNC_COUNT > 0)
static inline void CanNm_Internal_SetPNICbv( const CanNm_ChannelType* ChannelConf, CanNm_Internal_ChannelType* ChannelInternal ) {
if (ChannelConf->CbvPosition != CANNM_PDU_OFF) {
ChannelInternal->TxMessageSdu[ChannelConf->CbvPosition] |= CANNM_CBV_PNI;
#if (CANNM_USER_DATA_ENABLED == STD_ON) && (CANNM_COM_USER_DATA_SUPPORT == STD_ON)
ChannelInternal->SpontaneousTxMessageSdu[ChannelConf->CbvPosition] |= CANNM_CBV_PNI;
#endif
}
}
#endif
// Transition helpers
// ------------------
/**
* @brief transit from prepare bus sleep to repeat message state
* @param ChannelConf
* @param ChannelInternal
* @param isNwReq
* @return void
*/
static inline void CanNm_Internal_PrepareBusSleep_to_RepeatMessage( const CanNm_ChannelType* ChannelConf, CanNm_Internal_ChannelType* ChannelInternal ,boolean isNwReq ) {
ChannelInternal->Mode = NM_MODE_NETWORK;
ChannelInternal->State = NM_STATE_REPEAT_MESSAGE;
if ((ChannelConf->ImmediateNmTransmissions > 0) && isNwReq) /** @req CANNM005 CANNM334 */
{
ChannelInternal->MessageCycleTimeLeft = 0; /* begin transmission immediately */ /** @req CANNM334 */
ChannelInternal->immediateNmTransmissionsSent = 0; /* reset counter of sent immediate messages */
ChannelInternal->immediateModeActive = TRUE; /* activate immediate-transmission-mode */
}
else {
ChannelInternal->MessageCycleTimeLeft = ChannelConf->MessageCycleOffsetTime + ChannelConf->MainFunctionPeriod; /**< @req CANNM100 */
}
ChannelInternal->RepeatMessageTimeLeft = ChannelConf->RepeatMessageTime + ChannelConf->MainFunctionPeriod;
ChannelInternal->TimeoutTimeLeft = ChannelConf->TimeoutTime + ChannelConf->MainFunctionPeriod; /**< @req CANNM096 */
// Notify 'Network Mode'
Nm_NetworkMode(ChannelConf->NmNetworkHandle); /**< @req CANNM097 */
/**< @req CANNM166 */
#if (CANNM_STATE_CHANGE_IND_ENABLED == STD_ON)
Nm_StateChangeNotification(ChannelConf->NmNetworkHandle, NM_STATE_PREPARE_BUS_SLEEP, NM_STATE_REPEAT_MESSAGE);
#endif
}
/**
* @brief transit from prepare bus sleep to bus sleep state
* @param ChannelConf
* @param ChannelInternal
* @return void
*/
static inline void CanNm_Internal_PrepareBusSleep_to_BusSleep( const CanNm_ChannelType* ChannelConf, CanNm_Internal_ChannelType* ChannelInternal ) {
SchM_Enter_CanNm_EA_0();
ChannelInternal->Mode = NM_MODE_BUS_SLEEP;
ChannelInternal->State = NM_STATE_BUS_SLEEP;
// Notify 'Bus-Sleep Mode'
Nm_BusSleepMode(ChannelConf->NmNetworkHandle); /**< @req CANNM126 */ /** @req CANNM324 */
/**< @req CANNM166 */
#if (CANNM_STATE_CHANGE_IND_ENABLED == STD_ON)
Nm_StateChangeNotification(ChannelConf->NmNetworkHandle, NM_STATE_PREPARE_BUS_SLEEP, NM_STATE_BUS_SLEEP);
#endif
SchM_Exit_CanNm_EA_0();
}
/**
* @brief transit from bus sleep to repeat message
* @param ChannelConf
* @param ChannelInternal
* @param isNwReq
* @return void
*/
static inline void CanNm_Internal_BusSleep_to_RepeatMessage( const CanNm_ChannelType* ChannelConf, CanNm_Internal_ChannelType* ChannelInternal,boolean isNwReq ) {
ChannelInternal->Mode = NM_MODE_NETWORK;
ChannelInternal->State = NM_STATE_REPEAT_MESSAGE;
if ((ChannelConf->ImmediateNmTransmissions > 0) && isNwReq) /** @req CANNM005 */
{
ChannelInternal->MessageCycleTimeLeft = 0; /* begin transmission immediately */ /** @req CANNM334 */
ChannelInternal->immediateNmTransmissionsSent = 0; /* reset counter of sent immediate messages */
ChannelInternal->immediateModeActive = TRUE; /* activate immediate-transmission-mode */
} else {
ChannelInternal->MessageCycleTimeLeft = ChannelConf->MessageCycleOffsetTime + ChannelConf->MainFunctionPeriod; /**< @req CANNM100 */
}
ChannelInternal->TimeoutTimeLeft = ChannelConf->TimeoutTime + ChannelConf->MainFunctionPeriod ; /**< @req CANNM096 */
ChannelInternal->RepeatMessageTimeLeft = ChannelConf->RepeatMessageTime + ChannelConf->MainFunctionPeriod;
// Notify 'Network Mode'
Nm_NetworkMode(ChannelConf->NmNetworkHandle); /**< @req CANNM097 */ /** @req CANNM324 */
/**< @req CANNM166 */
#if (CANNM_STATE_CHANGE_IND_ENABLED == STD_ON)
Nm_StateChangeNotification(ChannelConf->NmNetworkHandle, NM_STATE_BUS_SLEEP, NM_STATE_REPEAT_MESSAGE);
#endif
}
/**
* @brief transit from bus sleep to bus sleep
* @param ChannelConf
* @param ChannelInternal
* @return void
*/
static inline void CanNm_Internal_BusSleep_to_BusSleep( const CanNm_ChannelType* ChannelConf, CanNm_Internal_ChannelType* ChannelInternal ) {
// Notify 'Network Start'
#if (CANNM_PNC_COUNT == 0)
Nm_NetworkStartIndication(ChannelConf->NmNetworkHandle); /**< @req CANNM127 */ /** @req CANNM324 */
#else
//lint -estring(920,pointer) /* cast to void */
(void) ChannelConf; //Just to avoid 715 PC-Lint warning about not used.
//lint +estring(920,pointer) /* cast to void */
#endif
//lint -estring(920,pointer) /* cast to void */
(void) ChannelInternal; //Just to avoid 715 PC-Lint warning about not used.
//lint +estring(920,pointer) /* cast to void */
}
/**
* @brief transit from repeat message to repeat message
* @param ChannelConf
* @param ChannelInternal
* @return void
*/
static inline void CanNm_Internal_RepeatMessage_to_RepeatMessage( const CanNm_ChannelType* ChannelConf, CanNm_Internal_ChannelType* ChannelInternal ) {
ChannelInternal->TimeoutTimeLeft = ChannelConf->TimeoutTime; /**< @req CANNM101 */
}
/**
* @brief transit from repeat message state to ready sleep
* @param ChannelConf
* @param ChannelInternal
* @return void
*/
static inline void CanNm_Internal_RepeatMessage_to_ReadySleep( const CanNm_ChannelType* ChannelConf, CanNm_Internal_ChannelType* ChannelInternal ) {
ChannelInternal->Mode = NM_MODE_NETWORK;
ChannelInternal->State = NM_STATE_READY_SLEEP;
#if (CANNM_NODE_DETECTION_ENABLED == STD_ON)
/** @req CANNM107 */
CanNm_Internal_ClearRptMsgRqstCbv(ChannelConf, ChannelInternal);
#endif
/**< @req CANNM166 */
#if (CANNM_STATE_CHANGE_IND_ENABLED == STD_ON)
Nm_StateChangeNotification(ChannelConf->NmNetworkHandle, NM_STATE_REPEAT_MESSAGE, NM_STATE_READY_SLEEP);
#endif
}
/**
* @brief transit from repeat message to normal operation state
* @param ChannelConf
* @param ChannelInternal
* @return void
*/
static inline void CanNm_Internal_RepeatMessage_to_NormalOperation( const CanNm_ChannelType* ChannelConf, CanNm_Internal_ChannelType* ChannelInternal ) {
ChannelInternal->Mode = NM_MODE_NETWORK;
ChannelInternal->State = NM_STATE_NORMAL_OPERATION;
#if (CANNM_NODE_DETECTION_ENABLED == STD_ON)
/** @req CANNM107 */
CanNm_Internal_ClearRptMsgRqstCbv(ChannelConf, ChannelInternal);
#endif
/**< @req CANNM166 */
#if (CANNM_STATE_CHANGE_IND_ENABLED == STD_ON)
Nm_StateChangeNotification(ChannelConf->NmNetworkHandle, NM_STATE_REPEAT_MESSAGE, NM_STATE_NORMAL_OPERATION);
#endif
}
/**
* @brief transit from normal operation to repeat message state
* @param ChannelConf
* @param ChannelInternal
* @return void
*/
static inline void CanNm_Internal_NormalOperation_to_RepeatMessage( const CanNm_ChannelType* ChannelConf, CanNm_Internal_ChannelType* ChannelInternal ) {
ChannelInternal->Mode = NM_MODE_NETWORK;
ChannelInternal->State = NM_STATE_REPEAT_MESSAGE;
ChannelInternal->RepeatMessageTimeLeft = ChannelConf->RepeatMessageTime + ChannelConf->MainFunctionPeriod;
ChannelInternal->MessageCycleTimeLeft = ChannelConf->MessageCycleOffsetTime + ChannelConf->MainFunctionPeriod; /**< @req CANNM100 */
/**< @req CANNM166 */
#if (CANNM_STATE_CHANGE_IND_ENABLED == STD_ON)
Nm_StateChangeNotification(ChannelConf->NmNetworkHandle, NM_STATE_NORMAL_OPERATION, NM_STATE_REPEAT_MESSAGE);
#endif
}
/**
* @brief transition from normal operation to ready sleep
* @param ChannelConf
* @param ChannelInternal
* @return void
*/
static inline void CanNm_Internal_NormalOperation_to_ReadySleep( const CanNm_ChannelType* ChannelConf, CanNm_Internal_ChannelType* ChannelInternal ) {
ChannelInternal->Mode = NM_MODE_NETWORK;
ChannelInternal->State = NM_STATE_READY_SLEEP;
//lint -estring(920,pointer) /* cast to void */
(void) ChannelConf; //Just to avoid 715 PC-Lint warning about not used.
//lint +estring(920,pointer) /* cast to void */
/**< @req CANNM166 */
#if (CANNM_STATE_CHANGE_IND_ENABLED == STD_ON)
Nm_StateChangeNotification(ChannelConf->NmNetworkHandle, NM_STATE_NORMAL_OPERATION, NM_STATE_READY_SLEEP);
#endif
}
/**
* @brief transition from normal operation to normal operation
* @param ChannelConf
* @param ChannelInternal
* @return void
*/
static inline void CanNm_Internal_NormalOperation_to_NormalOperation( const CanNm_ChannelType* ChannelConf, CanNm_Internal_ChannelType* ChannelInternal ) {
ChannelInternal->TimeoutTimeLeft = ChannelConf->TimeoutTime; /**< @req CANNM117 */
}
/**
* @brief transition from ready sleep to normal operation
* @param ChannelConf
* @param ChannelInternal
* @return void
*/
static inline void CanNm_Internal_ReadySleep_to_NormalOperation( const CanNm_ChannelType* ChannelConf, CanNm_Internal_ChannelType* ChannelInternal ) {
ChannelInternal->Mode = NM_MODE_NETWORK;
ChannelInternal->State = NM_STATE_NORMAL_OPERATION;
ChannelInternal->MessageCycleTimeLeft = ChannelConf->MessageCycleOffsetTime + ChannelConf->MainFunctionPeriod; /**< @req CANNM116 */
/**< @req CANNM166 */
#if (CANNM_STATE_CHANGE_IND_ENABLED == STD_ON)
Nm_StateChangeNotification(ChannelConf->NmNetworkHandle, NM_STATE_READY_SLEEP, NM_STATE_NORMAL_OPERATION);
#endif
}
/**
* @brief transition from ready sleep to bus prepare bus sleep state
* @param ChannelConf
* @param ChannelInternal
* @return void
*/
static inline void CanNm_Internal_ReadySleep_to_PrepareBusSleep( const CanNm_ChannelType* ChannelConf, CanNm_Internal_ChannelType* ChannelInternal ) {
SchM_Enter_CanNm_EA_0();
ChannelInternal->Mode = NM_MODE_PREPARE_BUS_SLEEP;
ChannelInternal->State = NM_STATE_PREPARE_BUS_SLEEP;
ChannelInternal->WaitBusSleepTimeLeft = ChannelConf->WaitBusSleepTime;
ChannelInternal->MessageTimeoutTimeLeft = 0;/* Disable tx timeout timer */
// Notify 'Prepare Bus-Sleep Mode'
Nm_PrepareBusSleepMode(ChannelConf->NmNetworkHandle); /**< @req CANNM114 */ /** @req CANNM324 */
/**< @req CANNM166 */
#if (CANNM_STATE_CHANGE_IND_ENABLED == STD_ON)
Nm_StateChangeNotification(ChannelConf->NmNetworkHandle, NM_STATE_READY_SLEEP, NM_STATE_PREPARE_BUS_SLEEP);
#endif
SchM_Exit_CanNm_EA_0();
}
/**
* @brief transition from ready sleep to repeat message state
* @param ChannelConf
* @param ChannelInternal
* @return void
*/
static inline void CanNm_Internal_ReadySleep_to_RepeatMessage( const CanNm_ChannelType* ChannelConf, CanNm_Internal_ChannelType* ChannelInternal ) {
ChannelInternal->Mode = NM_MODE_NETWORK;
ChannelInternal->State = NM_STATE_REPEAT_MESSAGE;
ChannelInternal->RepeatMessageTimeLeft = ChannelConf->RepeatMessageTime + ChannelConf->MainFunctionPeriod;
ChannelInternal->MessageCycleTimeLeft = ChannelConf->MessageCycleOffsetTime + ChannelConf->MainFunctionPeriod; /**< @req CANNM100 */
/**< @req CANNM166 */
#if (CANNM_STATE_CHANGE_IND_ENABLED == STD_ON)
Nm_StateChangeNotification(ChannelConf->NmNetworkHandle, NM_STATE_READY_SLEEP, NM_STATE_REPEAT_MESSAGE);
#endif
}
/**
* @brief transition from Nw mode to Nw mode
* @param ChannelConf
* @param ChannelInternal
* @return void
*/
static inline void CanNm_Internal_NetworkMode_to_NetworkMode( const CanNm_ChannelType* ChannelConf, CanNm_Internal_ChannelType* ChannelInternal ) {
ChannelInternal->TimeoutTimeLeft = ChannelConf->TimeoutTime + ChannelConf->MainFunctionPeriod; /**< @req CANNM098 @req CANNM099 */
}
#if ((CANNM_PNC_EIRA_CALC_ENABLED == STD_ON) && (CANNM_PNC_COUNT > 0))
static inline void restartPnEiraTimer(uint8 pnIndex);
static void restartTimerForInternalExternalRequests(CanNm_Internal_RAType *calcEIRA);
/**
* @brief restart PN timers
* @param pnIndex - Index of PNC
* @return void
*/
static inline void restartPnEiraTimer(uint8 pnIndex) {
uint8 timerIndex = CanNm_ConfigPtr->CanNmPnInfo->CanNmPnIndexToTimerMap[pnIndex];
CanNm_Internal.pnEIRATimers[timerIndex].timerRunning = TRUE;
CanNm_Internal.pnEIRATimers[timerIndex].resetTimer = CANNM_PNC_RESET_TIME;
}
/**
* @brief Identify the PN timer that needs to be restarted
* @param calcEIRA - EIRA of the new received/transmitted and filtered PDU
* @return void
*/
static void restartTimerForInternalExternalRequests(CanNm_Internal_RAType *calcEIRA) {
uint8 byteNo;
uint8 bit;
uint8 byteEIRA;
for (byteNo = 0; byteNo < CanNm_ConfigPtr->CanNmPnInfo->CanNmPnInfoLen; byteNo++) {
byteEIRA = calcEIRA->bytes[byteNo];
if ( byteEIRA > 0) {
for (bit = 0; bit < 8; bit++) {
if ((byteEIRA >> bit) & CANNM_LSBIT_MASK) {
restartPnEiraTimer((byteNo * 8) + bit);
} else {
/* Do nothing */
}
}
} else {
/* Do nothing */
}
}
}
#endif
#if ((CANNM_PNC_ERA_CALC_ENABLED == STD_ON) && (CANNM_PNC_COUNT > 0))
static inline void restartPnEraTimer(CanNm_Internal_ChannelType* ChannelInternal, uint8 pnIndex);
void restartTimerForExternalRequests(CanNm_Internal_ChannelType* ChannelInternal,
CanNm_Internal_RAType *calcEIRA);
/**
* @brief restart PN timers
* @param pnIndex - Index of PNC
* @return void
*/
static inline void restartPnEraTimer(CanNm_Internal_ChannelType* ChannelInternal, uint8 pnIndex) {
uint8 timerIndex = CanNm_ConfigPtr->CanNmPnInfo->CanNmPnIndexToTimerMap[pnIndex];
ChannelInternal->pnERATimers[timerIndex].timerRunning = TRUE;
ChannelInternal->pnERATimers[timerIndex].resetTimer = CANNM_PNC_RESET_TIME;
}
/**
* @brief Identify the PN timer that needs to be restarted
* @param calcERA - ERA of the new received/transmitted and filtered PDU
* @return void
*/
void restartTimerForExternalRequests(CanNm_Internal_ChannelType* ChannelInternal,
CanNm_Internal_RAType *calcERA) {
uint8 byteNo;
uint8 bit;
uint8 byteERA;
for (byteNo = 0; byteNo < CanNm_ConfigPtr->CanNmPnInfo->CanNmPnInfoLen; byteNo++) {
byteERA = calcERA->bytes[byteNo];
if ( byteERA > 0) {
for(bit = 0; bit < 8; bit++) {
if ((byteERA >> bit) & CANNM_LSBIT_MASK) {
restartPnEraTimer(ChannelInternal, (byteNo * 8) + bit);
} else {
/* Do nothing */
}
}
} else {
/* Do nothing */
}
}
}
#endif
/**
* @brief NM filtering process done for each reception
* @param ChannelConf - Channel configuration
* @param ChannelInternal - Channel internal runtime data
* @param pni - PNI bit set in CBV?
* @return reception valid or not
*
*/
#if (CANNM_PNC_COUNT > 0)
static inline Std_ReturnType CanNm_Internal_RxProcess(const CanNm_ChannelType* ChannelConf, CanNm_Internal_ChannelType* ChannelInternal, boolean pni ) {
Std_ReturnType ret;
ret = E_OK;
uint8 i;
uint8 offset;
CanNm_Internal_RAType calculatedEIRA = {0};
#if (CANNM_PNC_ERA_CALC_ENABLED == STD_ON)
CanNm_Internal_RAType calculatedERA = {0};
#endif /* (CANNM_PNC_ERA_CALC_ENABLED == STD_ON) */
boolean isUpdated;
isUpdated = TRUE;
/* @req CANNM409 */
if (!ChannelConf->CanNmPnEnable) {
ret = E_OK; /* No pn normal reception */
}
/* @req CANNM410 */
else if ((ChannelConf->CanNmAllNmMsgKeepAwake) && (!pni)) {
ret = E_OK; /* No pni in cbv - normal reception */
}
/* @req CANNM411 */
else if ((!ChannelConf->CanNmAllNmMsgKeepAwake) && (!pni)) {
ret = E_NOT_OK; /* No pni in cbv - discard reception */
} else if (!ChannelInternal->MessageFilteringEnabled) {
ret = E_NOT_OK; /* pni set in cbv, but filter is disabled - discard reception */
} else {
/* @req CANNM412 */ /* Do nothing - NM filtering done below*/
isUpdated = FALSE;
}
if (!isUpdated) {
/* @req CANNM415 */
/* @req CANNM418 */
offset = CanNm_ConfigPtr->CanNmPnInfo->CanNmPnInfoOffset;
for (i = 0; i < CanNm_ConfigPtr->CanNmPnInfo->CanNmPnInfoLen; i++) {
/* Accumulate external requests */
calculatedEIRA.bytes[i] = ChannelInternal->RxMessageSdu[i + offset] & CanNm_ConfigPtr->CanNmPnInfo->CanNmPnInfoMask[i];
}
#if (CANNM_PNC_ERA_CALC_ENABLED == STD_ON)
calculatedERA.data = calculatedEIRA.data;
#endif /* (CANNM_PNC_ERA_CALC_ENABLED == STD_ON) */
/* EIRA == ERA here so only need to check one. */
if (calculatedEIRA.data == 0) {
if (!ChannelConf->CanNmAllNmMsgKeepAwake) {
ret = E_NOT_OK; /* @req CANNM420 */
isUpdated = TRUE;
} else {
ret = E_OK; /* @req CANNM421 */
isUpdated = TRUE;
}
} else {
/* @req CANNM419 */ /* Do nothing */ /* Process as below */
}
if (!isUpdated) {
/* @req CANNM422 */
#if (CANNM_PNC_EIRA_CALC_ENABLED == STD_ON)
CanNm_Internal_RAType EIRAOld = {0};
boolean changed;
SchM_Enter_CanNm_EA_0();
/* @req CANNM429 */
restartTimerForInternalExternalRequests(&calculatedEIRA);
/* @req CANNM423 */
/* @req CANNM425 */
/* @req CANNM426 */
EIRAOld.data = CanNm_Internal.pnEIRA.data;
CanNm_Internal.pnEIRA.data |= calculatedEIRA.data;
changed = (EIRAOld.data != CanNm_Internal.pnEIRA.data) ? TRUE: FALSE;
SchM_Exit_CanNm_EA_0();
if (changed) {
PduInfoType pdu = {
.SduDataPtr = &CanNm_Internal.pnEIRA.bytes[0],
.SduLength = CanNm_ConfigPtr->CanNmPnInfo->CanNmPnInfoLen,
};
/* @req CANNM432 */
PduR_CanNmRxIndication(CanNm_ConfigPtr->CanNmPnInfo->CanNmEIRARxNSduId,&pdu);
} else {
/* Do nothing */
}
#endif /* (CANNM_PNC_EIRA_CALC_ENABLED == STD_ON) */
/* @req CANNM433 */
#if (CANNM_PNC_ERA_CALC_ENABLED == STD_ON)
if (ChannelConf->CanNmPnEraCalcEnabled) {
CanNm_Internal_RAType ERAOld = {0};
boolean changedERA;
SchM_Enter_CanNm_EA_0();
/* @req CANNM439 */
restartTimerForExternalRequests(ChannelInternal, &calculatedERA);
/* @req CANNM434 */
/* @req CANNM436 */
/* @req CANNM437 */
ERAOld.data = ChannelInternal->pnERA.data;
ChannelInternal->pnERA.data |= calculatedERA.data;
changedERA = (ERAOld.data != ChannelInternal->pnERA.data) ? TRUE: FALSE;
SchM_Exit_CanNm_EA_0();
if (changedERA) {
PduInfoType pdu = {
.SduDataPtr = &ChannelInternal->pnERA.bytes[0],
.SduLength = CanNm_ConfigPtr->CanNmPnInfo->CanNmPnInfoLen,
};
/* @req CANNM443 */
PduR_CanNmRxIndication(ChannelConf->CanNmERARxNSduId, &pdu);
} else {
/* Do nothing */
}
}
#endif /* (CANNM_PNC_ERA_CALC_ENABLED == STD_ON) */
}
}
return ret;
}
#endif
/**
* @brief Determine internal requests from ComM and identify which PN timer has to be started
* @param pnInfo - Pn Info range of the transmitted PDU
* @return void
*/
#if ((CANNM_PNC_EIRA_CALC_ENABLED == STD_ON) && (CANNM_PNC_COUNT > 0))
void CanNm_Internal_ProcessTxPdu(uint8 *pnInfo) {
uint8 byteNo;
CanNm_Internal_RAType calculatedEIRA = {0};
CanNm_Internal_RAType EIRAOld = {0};
boolean changed;
SchM_Enter_CanNm_EA_0();
for (byteNo = 0; byteNo < CanNm_ConfigPtr->CanNmPnInfo->CanNmPnInfoLen; byteNo++) {
calculatedEIRA.bytes[byteNo] = *(pnInfo + byteNo) & CanNm_ConfigPtr->CanNmPnInfo->CanNmPnInfoMask[byteNo]; /* Accumulate internal requests */
}
if (calculatedEIRA.data != 0) {
/* @req CANNM430 */
restartTimerForInternalExternalRequests(&calculatedEIRA);
EIRAOld.data = CanNm_Internal.pnEIRA.data;
CanNm_Internal.pnEIRA.data |= calculatedEIRA.data; /* @req CANNM427 */
changed = (EIRAOld.data != CanNm_Internal.pnEIRA.data) ? TRUE: FALSE;
if (changed) {
PduInfoType pdu = {
.SduDataPtr = &CanNm_Internal.pnEIRA.bytes[0],
.SduLength = CanNm_ConfigPtr->CanNmPnInfo->CanNmPnInfoLen,
};
/* @req CANNM432 */
PduR_CanNmRxIndication(CanNm_ConfigPtr->CanNmPnInfo->CanNmEIRARxNSduId,&pdu);
} else {
/* Do nothing */
}
} else {
/* Do nothing */
}
SchM_Exit_CanNm_EA_0();
}
#endif
|
2301_81045437/classic-platform
|
communication/CanNm/src/CanNm.c
|
C
|
unknown
| 78,932
|
/*-------------------------------- 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 CANNM_INTERNAL_H_
#define CANNM_INTERNAL_H_
/** @req CANNM188 @req CANNM196 @req CANNM199 */
#if (CANNM_DEV_ERROR_DETECT == STD_ON)
#define CANNM_DET_REPORTERROR(serviceId, errorId, instanceId) \
(void)Det_ReportError(CANNM_MODULE_ID, (uint8)instanceId, serviceId, errorId)
#define CANNM_VALIDATE(expression, serviceId, errorId, instanceId, _rv) \
if (!(expression)) { \
CANNM_DET_REPORTERROR(serviceId, errorId, instanceId); \
return (_rv); \
}
#define CANNM_VALIDATE_NORV(expression, serviceId, errorId, instanceId) \
if (!(expression)) { \
CANNM_DET_REPORTERROR(serviceId, errorId, instanceId); \
return; \
}
#else
#define CANNM_DET_REPORTERROR(...)
#define CANNM_VALIDATE(...)
#define CANNM_VALIDATE_NORV(...)
#endif
#define CANNM_VALIDATE_INIT(serviceID) \
CANNM_VALIDATE((CanNm_Internal.InitStatus == CANNM_STATUS_INIT), serviceID, CANNM_E_NO_INIT, 0, E_NOT_OK)
#define CANNM_VALIDATE_INIT_NORV(serviceID, instanceID) \
CANNM_VALIDATE_NORV((CanNm_Internal.InitStatus == CANNM_STATUS_INIT), serviceID, CANNM_E_NO_INIT, instanceID)
/** @req CANNM192 */
#define CANNM_VALIDATE_CHANNEL(nmHandle, serviceID) \
CANNM_VALIDATE( ((nmHandle < CanNm_ConfigPtr->ChannelLookupsSize) && (CanNm_ConfigPtr->ChannelLookups[nmHandle] != CANNM_UNUSED_CHANNEL)), serviceID, CANNM_E_INVALID_CHANNEL, nmHandle, E_NOT_OK)
#define CANNM_VALIDATE_NOTNULL(ptr, serviceID, instanceID) \
CANNM_VALIDATE((ptr != NULL), serviceID, CANNM_E_NULL_POINTER, instanceID, E_NOT_OK)
#define CANNM_VALIDATE_NOTNULL_NORV(ptr, serviceID, instanceID) \
CANNM_VALIDATE_NORV( (ptr != NULL), serviceID, CANNM_E_NULL_POINTER, instanceID)
#define CANNM_VALIDATE_NOTNULL_INIT(ptr, serviceID, instanceID) \
CANNM_VALIDATE_NORV( (ptr != NULL), serviceID, CANNM_E_INIT_FAILED, instanceID)
#define CANNM_VALIDATE_PDUID_NORV(pduID, serviceID) \
CANNM_VALIDATE_NORV( (pduID < CANNM_CHANNEL_COUNT), serviceID, CANNM_E_INVALID_PDUID, pduID)
#if (CANNM_COM_USER_DATA_SUPPORT == STD_ON)
#define CANNM_SPONTANEOUS_TRANSMISSION 3
#define CANNM_ONGOING_TRANSMISSION 1
#define CANNM_NO_TRANSMISSION 0
#endif
/* CBV repeat reques */
#define CANNM_CBV_REPEAT_MESSAGE_REQUEST 0x01u
/* Bit position for PNI in CBV */
#define CANNM_CBV_PNI 0x40u
#define CANNM_LSBIT_MASK 0x1u
typedef enum {
CANNM_STATUS_INIT,
CANNM_STATUS_UNINIT
} CanNm_InitStatusType;
#if (CANNM_PNC_COUNT > 0)
/* Type used for both EIRA and ERA. */
typedef union {
uint64 data;
uint8 bytes[sizeof(uint64)];
}CanNm_Internal_RAType;
#endif
typedef struct{
uint32 resetTimer;
boolean timerRunning;
}CanNm_Internal_PnTimerType;
typedef struct {
Nm_ModeType Mode; /**< @req CANNM092 */
Nm_StateType State; /**< @req CANNM094 */
boolean Requested;
uint32 TimeoutTimeLeft;
uint32 RepeatMessageTimeLeft;
uint32 WaitBusSleepTimeLeft;
uint32 MessageCycleTimeLeft;
uint32 MessageCycleOffsetTimeLeft;
uint32 MessageTimeoutTimeLeft;
uint8 TxMessageSdu[8];
uint8 RxMessageSdu[8];
uint32 immediateNmTransmissionsSent;
boolean immediateModeActive;
#if (CANNM_COM_USER_DATA_SUPPORT == STD_ON)
uint8 TransmissionStatus;
uint8 SpontaneousTxMessageSdu[8];
#elif (CANNM_USER_DATA_ENABLED == STD_ON) /* and com_user_data... == OFF */
boolean IsUserDataSet;
#endif
boolean CommunicationEnabled;
boolean MessageFilteringEnabled;
#if (CANNM_PNC_COUNT > 0)
CanNm_Internal_PnTimerType pnERATimers[CANNM_PNC_COUNT];
CanNm_Internal_RAType pnERA; /* Same type as EIRA. */
#endif
} CanNm_Internal_ChannelType;
typedef struct {
CanNm_InitStatusType InitStatus;
CanNm_Internal_ChannelType Channels[CANNM_CHANNEL_COUNT];
#if (CANNM_PNC_COUNT > 0)
CanNm_Internal_PnTimerType pnEIRATimers[CANNM_PNC_COUNT]; /* @req CANNM426 */
CanNm_Internal_RAType pnEIRA;
#endif
} CanNm_InternalType;
/* Timer helpers */
static inline void CanNm_Internal_TickTimeoutTime( const CanNm_ChannelType* ChannelConf, CanNm_Internal_ChannelType* ChannelInternal );
static inline void CanNm_Internal_TickRepeatMessageTime( const CanNm_ChannelType* ChannelConf, CanNm_Internal_ChannelType* ChannelInternal );
static inline void CanNm_Internal_TickWaitBusSleepTime( const CanNm_ChannelType* ChannelConf, CanNm_Internal_ChannelType* ChannelInternal );
static inline void CanNm_Internal_TickMessageCycleTime( const CanNm_ChannelType* ChannelConf, CanNm_Internal_ChannelType* ChannelInternal );
static inline void CanNm_Internal_TickTxTimeout(const CanNm_ChannelType* ChannelConf, CanNm_Internal_ChannelType* ChannelInternal );
static inline void CanNm_Internal_ClearRptMsgRqstCbv( const CanNm_ChannelType* ChannelConf, CanNm_Internal_ChannelType* ChannelInternal );
/* Message helpers */
static inline void CanNm_Internal_TransmitMessage( const CanNm_ChannelType* ChannelConf, CanNm_Internal_ChannelType* ChannelInternal );
static inline PduLengthType CanNm_Internal_GetUserDataOffset( const CanNm_ChannelType* ChannelConf );
static inline uint8* CanNm_Internal_GetUserDataPtr( const CanNm_ChannelType* ChannelConf, uint8* MessageSduPtr );
static inline PduLengthType CanNm_Internal_GetUserDataLength( const CanNm_ChannelType* ChannelConf );
/* Transition helpers */
static inline void CanNm_Internal_PrepareBusSleep_to_RepeatMessage( const CanNm_ChannelType* ChannelConf, CanNm_Internal_ChannelType* ChannelInternal ,boolean isNwReq );
static inline void CanNm_Internal_PrepareBusSleep_to_BusSleep( const CanNm_ChannelType* ChannelConf, CanNm_Internal_ChannelType* ChannelInternal );
static inline void CanNm_Internal_BusSleep_to_RepeatMessage( const CanNm_ChannelType* ChannelConf, CanNm_Internal_ChannelType* ChannelInternal, boolean isNwReq );
static inline void CanNm_Internal_BusSleep_to_BusSleep( const CanNm_ChannelType* ChannelConf, CanNm_Internal_ChannelType* ChannelInternal );
static inline void CanNm_Internal_RepeatMessage_to_RepeatMessage( const CanNm_ChannelType* ChannelConf, CanNm_Internal_ChannelType* ChannelInternal );
static inline void CanNm_Internal_RepeatMessage_to_ReadySleep( const CanNm_ChannelType* ChannelConf, CanNm_Internal_ChannelType* ChannelInternal );
static inline void CanNm_Internal_RepeatMessage_to_NormalOperation( const CanNm_ChannelType* ChannelConf, CanNm_Internal_ChannelType* ChannelInternal );
static inline void CanNm_Internal_NormalOperation_to_RepeatMessage( const CanNm_ChannelType* ChannelConf, CanNm_Internal_ChannelType* ChannelInternal );
static inline void CanNm_Internal_NormalOperation_to_ReadySleep( const CanNm_ChannelType* ChannelConf, CanNm_Internal_ChannelType* ChannelInternal );
static inline void CanNm_Internal_NormalOperation_to_NormalOperation( const CanNm_ChannelType* ChannelConf, CanNm_Internal_ChannelType* ChannelInternal );
static inline void CanNm_Internal_ReadySleep_to_NormalOperation( const CanNm_ChannelType* ChannelConf, CanNm_Internal_ChannelType* ChannelInternal );
static inline void CanNm_Internal_ReadySleep_to_PrepareBusSleep( const CanNm_ChannelType* ChannelConf, CanNm_Internal_ChannelType* ChannelInternal );
static inline void CanNm_Internal_ReadySleep_to_RepeatMessage( const CanNm_ChannelType* ChannelConf, CanNm_Internal_ChannelType* ChannelInternal );
static inline void CanNm_Internal_NetworkMode_to_NetworkMode( const CanNm_ChannelType* ChannelConf, CanNm_Internal_ChannelType* ChannelInternal );
#if (CANNM_PNC_COUNT > 0)
static inline void CanNm_Internal_SetPNICbv( const CanNm_ChannelType* ChannelConf, CanNm_Internal_ChannelType* ChannelInternal );
static inline Std_ReturnType CanNm_Internal_RxProcess(const CanNm_ChannelType* ChannelConf, CanNm_Internal_ChannelType* ChannelInternal, boolean pni );
#if (CANNM_PNC_EIRA_CALC_ENABLED == STD_ON)
static inline void CanNm_Internal_TickPnEIRAResetTime(void);
void CanNm_Internal_resetEIRAPNbits(uint8 *pnIndex, uint8 indexCount);
void CanNm_Internal_ProcessTxPdu(uint8 *pnInfo);
#endif
#if (CANNM_PNC_ERA_CALC_ENABLED == STD_ON)
static inline void CanNm_Internal_TickPnEraResetTime(void);
void CanNm_Internal_ResetEraPnBits(uint8 chanIndex, uint8 *pnIndex, uint8 indexCount);
#endif
#endif
#endif /* CANNM_INTERNAL_H_ */
|
2301_81045437/classic-platform
|
communication/CanNm/src/CanNm_Internal.h
|
C
|
unknown
| 9,363
|
# CanSm
obj-$(USE_CANSM) += CanSM.o
obj-$(USE_CANSM) += CanSM_Internal.o
obj-$(USE_CANSM) += CanSM_LCfg.o
ifeq ($(filter CanSM_Extension.o,$(obj-y)),)
obj-$(USE_CANSM_EXTENSION) += CanSM_Extension.o
endif
inc-$(USE_CANSM) += $(ROOTDIR)/communication/CanSM/inc
inc-$(USE_CANSM) += $(ROOTDIR)/communication/CanSM/src
vpath-$(USE_CANSM) += $(ROOTDIR)/communication/CanSM/src
|
2301_81045437/classic-platform
|
communication/CanSM/CanSM.mod.mk
|
Makefile
|
unknown
| 384
|
/*-------------------------------- 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 -----------------------------*/
/** @req CANSM008 */
#ifndef CANSM_H_
#define CANSM_H_
#include "ComStack_Types.h" /* @req CANSM238 */
#include "ComM.h" /* @req CANSM174 */
#include "CanSM_ConfigTypes.h"
/* @req CANSM559 */
#define CANSM_VENDOR_ID 60u
#define CANSM_MODULE_ID 140u
#define CANSM_AR_RELEASE_MAJOR_VERSION 4u
#define CANSM_AR_RELEASE_MINOR_VERSION 0u
#define CANSM_AR_RELEASE_REVISION_VERSION 3u
#define CANSM_AR_MAJOR_VERSION CANSM_AR_RELEASE_MAJOR_VERSION
#define CANSM_AR_MINOR_VERSION CANSM_AR_RELEASE_MINOR_VERSION
#define CANSM_AR_PATCH_VERSION CANSM_AR_RELEASE_REVISION_VERSION
#define CANSM_SW_MAJOR_VERSION 3u
#define CANSM_SW_MINOR_VERSION 2u
#define CANSM_SW_PATCH_VERSION 0u
#include "CanSM_Cfg.h"
/* @req CANSM548 */
#if (CANSM_CAN_TRCV_SUPPORT == STD_ON) && defined(USE_CANNM)
#include "CanNm.h"
#endif
#if (CANSM_CAN_TRCV_SUPPORT == STD_ON)
#include "CanTrcv.h"
#endif
/** @req CANSM069 */
#define CANSM_E_UNINIT 0x01u /**< API service used without module initialization */
#define CANSM_E_PARAM_POINTER 0x02u /**< API service called with wrong pointer */
#define CANSM_E_INVALID_NETWORK_HANDLE 0x03u /**< API service called with wrong parameter */
#define CANSM_E_PARAM_CONTROLLER 0x04u /**< API service called with wrong parameter */
#define CANSM_E_PARAM_TRANSCEIVER 0x05u
#define CANSM_E_BUSOFF_RECOVERY_ACTIVE 0x06u
#define CANSM_E_WAIT_MODE_INDICATION 0x07u
#define CANSM_E_INVALID_COMM_REQUEST 0x08u
//#define CANSM_E_PARAM_INVALID_BAUDRATE 0x09u
#define CANSM_E_MODE_REQUEST_TIMEOUT 0x0Au
/* ArcCore extra errors */
#define CANSM_E_INVALID_NETWORK_MODE 0x10u
#define CANSM_E_INVALID_ACTION 0x11u
#define CANSM_E_UNEXPECTED_EXECUTION 0x12u
#define CANSM_E_INVALID_INVALID_BUSOFF 0x13u
#define CANSM_SERVICEID_INIT 0x00u
#define CANSM_SERVICEID_GETVERSIONINFO 0x01u
#define CANSM_SERVICEID_REQUESTCOMMODE 0x02u
#define CANSM_SERVICEID_GETCURRENTCOMMODE 0x03u
#define CANSM_SERVICEID_CONTROLLERBUSOFF 0x04u
#define CANSM_SERVICEID_MAINFUNCTION 0x05u
#define CANSM_SERVICEID_CONFIRMPNAVAILABILITY 0x06u
#define CANSM_SERVICEID_CONTROLLERMODEINDICATION 0x07u
#define CANSM_SERVICEID_CLEARTRCVWUFINDICATION 0x08u
#define CANSM_SERVICEID_TRANSCEIVERMODEINDICATION 0x09u
#define CANSM_SERVICEID_CHECKTRCVWUFINDICATION 0x0au
/* @req CANSM008 */
/** This service puts out the version information of this module */
/** @req CANSM024 @req CANSM367 @req CANSM244 @req CANSM368 @req CANSM366 */
/* !req CANSM374 */
#if (CANSM_VERSION_INFO_API == STD_ON)
#define CanSM_GetVersionInfo(_vi) STD_GET_VERSION_INFO(_vi,CANSM)
#endif
/** This service shall change the communication mode of a CAN network to the requested one. */
/** @req CANSM062 */
/* IMPROVEMENT: Move to CanSM_ComM.h? */
Std_ReturnType CanSM_RequestComMode( NetworkHandleType NetworkHandle, ComM_ModeType ComM_Mode );
/** This service shall put out the current communication mode of a CAN network. */
/** @req CANSM063 */
/* IMPROVEMENT: Move to CanSM_ComM.h? */
Std_ReturnType CanSM_GetCurrentComMode( NetworkHandleType NetworkHandle, ComM_ModeType* ComM_ModePtr );
/** Init function for CanSM */
/** @req CANSM023 */
void CanSM_Init( const CanSM_ConfigType* ConfigPtr );
/** Scheduled function of the CanSM */
/** @req CANSM065 */
void CanSM_MainFunction(void);
#if (CANSM_CAN_TRCV_SUPPORT == STD_ON)
/* @req CANSM399 */
void CanSM_TransceiverModeIndication(uint8 TransceiverId, CanTrcv_TrcvModeType TransceiverMode);
/* @req CANSM413 */
void CanSM_ClearTrcvWufFlagIndication( uint8 Transceiver );
/* @req CANSM416 */
void CanSM_CheckTransceiverWakeFlagIndication( uint8 Transceiver );
/* @req CANSM419 */
void CanSM_ConfirmPnAvailability( uint8 Transceiver );
#endif
#endif /* CANSM_H_ */
|
2301_81045437/classic-platform
|
communication/CanSM/inc/CanSM.h
|
C
|
unknown
| 5,022
|
/*-------------------------------- 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 CANSM_BSWM_H_
#define CANSM_BSWM_H_
/* @req CANSM347 */
/* "The header file CanSM_BswM.h shall export the interfaces, which
* are dedicated to the BswM module..". But there are no interfaces dedicated to
* BswM module..
*/
/** This type shall define the CAN specific communication modes/states notified
* to the BswM module. */
typedef enum
{
CANSM_BSWM_NO_COMMUNICATION = 0,
CANSM_BSWM_SILENT_COMMUNICATION,
CANSM_BSWM_FULL_COMMUNICATION,
CANSM_BSWM_BUS_OFF,
CANSM_BSWM_CHANGE_BAUDRATE,
}CanSM_BswMCurrentStateType;
#endif /* CANSM_BSWM_H_ */
|
2301_81045437/classic-platform
|
communication/CanSM/inc/CanSM_BswM.h
|
C
|
unknown
| 1,352
|
/*-------------------------------- 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 CANSM_CBK_H_
#define CANSM_CBK_H_
/** @req CANSM011 */
/** The CanSM is notified about a bus-off event on a certain CAN controller with this
* call-out function. It shall execute the bus-off recovery state machine for the
* corresponding network handle. */
/* @req CANSM064 */
void CanSM_ControllerBusOff( uint8 ControllerId );
/* @req CANSM396 */
void CanSM_ControllerModeIndication( uint8 ControllerId, CanIf_ControllerModeType ControllerMode );
#if (CANSM_CAN_TRCV_SUPPORT == STD_ON)
/* @req CANSM399 */
void CanSM_TransceiverModeIndication( uint8 TransceiverId, CanTrcv_TrcvModeType TransceiverMode );
#endif
#endif /* CANSM_CBK_H_ */
|
2301_81045437/classic-platform
|
communication/CanSM/inc/CanSM_Cbk.h
|
C
|
unknown
| 1,437
|
/*-------------------------------- 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 CANSM_COMM_H_
#define CANSM_COMM_H_
/* !req CANSM009 */
#endif /* CANSM_COMM_H_ */
|
2301_81045437/classic-platform
|
communication/CanSM/inc/CanSM_ComM.h
|
C
|
unknown
| 858
|
/*-------------------------------- 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 CANSM_CONFIGTYPES_H_
#define CANSM_CONFIGTYPES_H_
/** @req CANSM010.bswbuilder */
#if defined(USE_DEM)
#include "Dem.h"
#endif
typedef struct {
const uint8 CanIfControllerId;
} CanSM_ControllerType;
typedef struct {
const CanSM_ControllerType* Controllers;
const uint8 ControllerCount;
const NetworkHandleType ComMNetworkHandle;
const uint32 CanSMBorTimeTxEnsured;
const uint32 CanSMBorTimeL1;
const uint32 CanSMBorTimeL2;
const uint8 CanSMBorCounterL1ToL2;
const boolean CanSMBorTxConfirmationPolling;
const boolean CanTrcvAvailable;
const uint8 CanIfTransceiverId;
const boolean CanSMTrcvPNEnabled;
#if (USE_DEM)
Dem_EventIdType CanSMDemEventId;
#endif
} CanSM_NetworkType;
typedef struct {
const uint8 CanSMModeRequestRepetitionMax;
const uint32 CanSMModeRequestRepetitionTime;
const CanSM_NetworkType* Networks;
const NetworkHandleType* ChannelMap;
const NetworkHandleType ChannelMapSize;
} CanSM_ConfigType;
#endif /* CANSM_CONFIGTYPES_H_ */
|
2301_81045437/classic-platform
|
communication/CanSM/inc/CanSM_ConfigTypes.h
|
C
|
unknown
| 2,022
|
/*-------------------------------- 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 CANSM_DCM_H_
#define CANSM_DCM_H_
/* !req CANSM547 */
#if 0
/* !req CANSM501 */
Std_ReturnType CanSm_CheckBaudrate(NetworkHandleType network, const uint16 Baudrate);
/* !req CANSM561 */
Std_ReturnType CanSm_ChangeBaudrate(NetworkHandleType network, const uint16 Baudrate);
#endif
#endif /* CANSM_DCM_H_ */
|
2301_81045437/classic-platform
|
communication/CanSM/inc/CanSM_Dcm.h
|
C
|
unknown
| 1,080
|
/*-------------------------------- 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 CANSM_ECUM_H_
#define CANSM_ECUM_H_
#include "CanSM.h"
/** This service initializes the CanSM module */
/** @req CANSM023 */
/** @req CANSM253 */
void CanSM_Init( const CanSM_ConfigType* ConfigPtr );
#endif /* CANSM_ECUM_H_ */
|
2301_81045437/classic-platform
|
communication/CanSM/inc/CanSM_EcuM.h
|
C
|
unknown
| 1,008
|
/*-------------------------------- 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 "MemMap.h"
|
2301_81045437/classic-platform
|
communication/CanSM/inc/CanSM_MemMap.h
|
C
|
unknown
| 771
|
/*-------------------------------- 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 "CanSM_Cfg.h" /* @req CANSM254 *//* CanSM.h includes CanSM_Cfg.h */
#include "ComStack_Types.h"
#include "CanSM.h" /* @req CANSM013 */
#include "ComM.h" /* @req CANSM174 */
#include "ComM_BusSM.h" /* @req CANSM191 */
#include "Det.h" /* @req CANSM015 */
#if defined(USE_DEM)
#include "Dem.h" /* @req CANSM014 */
#endif
#include "CanIf.h" /* @req CANSM017 */
#include "CanSM_Internal.h"
#include "CanSM_BswM.h" /* @req CANSM348 */
#include "CanSM_Cbk.h"
#if defined(USE_BSWM)
#include "BswM_CanSM.h"
#endif
#if defined(USE_CANSM_EXTENSION)
#include "CanSM_Extension.h"
#endif
#define INVALID_CONTROLLER_ID 0xff
#define CANSM_START_SEC_VAR_CLEARED_UNSPECIFIED
#include "CanSM_MemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/
static CanSM_Internal_CtrlStatusType CanSM_InternalControllerStatus[NOF_CANSM_CANIF_CONTROLLERS];
#define CANSM_STOP_SEC_VAR_CLEARED_UNSPECIFIED
#include "CanSM_MemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/
#define CANSM_START_SEC_VAR_CLEARED_UNSPECIFIED
#include "CanSM_MemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/
static CanSM_Internal_NetworkType CanSM_InternalNetworks[CANSM_NETWORK_COUNT];
#define CANSM_STOP_SEC_VAR_CLEARED_UNSPECIFIED
#include "CanSM_MemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/
#define CANSM_START_SEC_VAR_INIT_UNSPECIFIED
#include "CanSM_MemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/
CanSM_InternalType CanSM_Internal = {
.InitStatus = CANSM_STATUS_UNINIT,
.Networks = CanSM_InternalNetworks,
.ControllerModeBuf = CanSM_InternalControllerStatus,
};
#define CANSM_STOP_SEC_VAR_INIT_UNSPECIFIED
#include "CanSM_MemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/
#define CANSM_START_SEC_VAR_CLEARED_UNSPECIFIED
#include "CanSM_MemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/
const CanSM_ConfigType* CanSM_ConfigPtr;
#define CANSM_STOP_SEC_VAR_CLEARED_UNSPECIFIED
#include "CanSM_MemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/
Std_ReturnType CanSM_Internal_GetCanSMCtrlIdx(const uint8 controller, uint8* indexPtr)
{
Std_ReturnType ret = E_NOT_OK;
for(uint8 index = 0; index < NOF_CANSM_CANIF_CONTROLLERS; index++) {
if( controller == CanSM_Internal.ControllerModeBuf[index].controllerId ) {
*indexPtr = index;
ret = E_OK;
break;
}
}
return ret;
}
#if (CANSM_CAN_TRCV_SUPPORT == STD_ON)
Std_ReturnType CanIfTrcvChnlToCanSMNwHdl(uint8 TransceiverId,NetworkHandleType *CanSMNetworkIndex)
{
Std_ReturnType ret = E_NOT_OK;
for (NetworkHandleType i=0; i < CANSM_NETWORK_COUNT; i++ )
{
if (CanSM_Internal.Networks[i].TransceiverModeBuf.trcvId == TransceiverId)
{
ret = E_OK;
*CanSMNetworkIndex =i;
break;
}
}
return ret;
}
#endif
static void CanSM_Internal_ResetControllerIndications(NetworkHandleType CanSMNetworkIndex)
{
const CanSM_NetworkType *NetworkCfg = &CanSM_ConfigPtr->Networks[CanSMNetworkIndex];
for(uint8 ctrl = 0; ctrl < NetworkCfg->ControllerCount; ctrl++) {
uint8 index;
if( E_OK == CanSM_Internal_GetCanSMCtrlIdx(NetworkCfg->Controllers[ctrl].CanIfControllerId, &index) ) {
CanSM_Internal.ControllerModeBuf[index].indCtrlMode = CANIF_CS_UNINIT;
}
}
}
static void CanSM_Internal_EnterState(NetworkHandleType CanSMNetworkIndex, CanSM_Internal_BsmStateType state)
{
CanSM_Internal_NetworkType *Network = &CanSM_Internal.Networks[CanSMNetworkIndex];
Network->RepeatCounter = 0;
Network->subStateTimer = 0;
Network->BsmState = state;
switch(state) {
case CANSM_BSM_S_NOT_INITIALIZED:
break;
case CANSM_BSM_S_PRE_NOCOM:
#if (CANSM_CAN_TRCV_SUPPORT == STD_ON)
if ((TRUE == CanSM_ConfigPtr->Networks[CanSMNetworkIndex].CanTrcvAvailable)
&& (TRUE == CanSM_ConfigPtr->Networks[CanSMNetworkIndex].CanSMTrcvPNEnabled))
{
Network->PreNoCommState = CANSM_PRENOCOMM_S_PN_CLEAR_WUF;
} else {
Network->PreNoCommState = CANSM_PRENOCOMM_S_CC_STOPPED;
}
CanSM_Internal.Networks[CanSMNetworkIndex].TransceiverModeBuf.indTrcvMode = CANTRCV_TRCVMODE_NORMAL;
#else
Network->PreNoCommState = CANSM_PRENOCOMM_S_CC_STOPPED;
#endif
CanSM_Internal_ResetControllerIndications(CanSMNetworkIndex);
break;
case CANSM_BSM_S_NOCOM:
Network->initialNoComRun = TRUE;
break;
case CANSM_BSM_S_PRE_FULLCOM:
#if (CANSM_CAN_TRCV_SUPPORT == STD_ON)
if (TRUE == CanSM_ConfigPtr->Networks[CanSMNetworkIndex].CanTrcvAvailable)
{
Network->PreFullCommState = CANSM_PREFULLCOMM_S_TRCV_NORMAL;
}else {
Network->PreFullCommState = CANSM_PREFULLCOMM_S_CC_STOPPED;
}
CanSM_Internal.Networks[CanSMNetworkIndex].TransceiverModeBuf.indTrcvMode = CANTRCV_TRCVMODE_NORMAL;
#else
Network->PreFullCommState = CANSM_PREFULLCOMM_S_CC_STOPPED;
#endif
CanSM_Internal_ResetControllerIndications(CanSMNetworkIndex);
break;
case CANSM_BSM_S_FULLCOM:
Network->FullCommState = CANSM_FULLCOMM_S_BUSOFF_CHECK;
break;
case CANSM_BSM_S_SILENTCOM:
break;
default:
break;
}
}
static boolean CanSM_Internal_HasPendingControllerIndication(NetworkHandleType CanSMNetworkIndex)
{
boolean hasPendingIndication = FALSE;
const CanSM_NetworkType *NetworkCfg = &CanSM_ConfigPtr->Networks[CanSMNetworkIndex];
for(uint8 ctrl = 0; ctrl < NetworkCfg->ControllerCount; ctrl++) {
uint8 ctrlIndex;
if( E_OK != CanSM_Internal_GetCanSMCtrlIdx(NetworkCfg->Controllers[ctrl].CanIfControllerId, &ctrlIndex) ) {
hasPendingIndication = TRUE;
break;
}
if( TRUE == CanSM_Internal.ControllerModeBuf[ctrlIndex].hasPendingCtrlIndication ) {
/* No indication received after last request */
hasPendingIndication = TRUE;
}
}
return hasPendingIndication;
}
/* @req CANSM023 */
void CanSM_Init( const CanSM_ConfigType* ConfigPtr ) {
boolean done;
/* @req CANSM179 */
if( NULL == ConfigPtr ) {
CANSM_DET_REPORTERROR(CANSM_SERVICEID_INIT, CANSM_E_PARAM_POINTER);
/*lint -e{904} ARGUMENT CHECK */
return;
}
CanSM_ConfigPtr = ConfigPtr;
for( uint8 ctrl = 0; ctrl < NOF_CANSM_CANIF_CONTROLLERS; ctrl++ ) {
CanSM_Internal.ControllerModeBuf[ctrl].controllerId = INVALID_CONTROLLER_ID;
CanSM_Internal.ControllerModeBuf[ctrl].indCtrlMode = CANIF_CS_UNINIT;
CanSM_Internal.ControllerModeBuf[ctrl].hasPendingCtrlIndication = FALSE;
}
for (uint8 i = 0; i < CANSM_NETWORK_COUNT; ++i) {
CanSM_Internal.Networks[i].requestedMode = COMM_NO_COMMUNICATION;
CanSM_Internal.Networks[i].currentMode = COMM_NO_COMMUNICATION;
CanSM_Internal.Networks[i].BsmState = CANSM_BSM_S_NOT_INITIALIZED;
CanSM_Internal.Networks[i].FullCommState = CANSM_FULLCOMM_S_BUSOFF_CHECK;
CanSM_Internal.Networks[i].initialNoComRun = FALSE;
CanSM_Internal.Networks[i].RepeatCounter = 0;
CanSM_Internal.Networks[i].requestAccepted = FALSE;
CanSM_Internal.Networks[i].busoffCounter = 0;
CanSM_Internal.Networks[i].busoffevent = FALSE;
#if (CANSM_CAN_TRCV_SUPPORT == STD_ON)
if (TRUE == CanSM_ConfigPtr->Networks[i].CanTrcvAvailable)
{
CanSM_Internal.Networks[i].TransceiverModeBuf.trcvId = CanSM_ConfigPtr->Networks[i].CanIfTransceiverId ;
CanSM_Internal.Networks[i].TransceiverModeBuf.hasPendingTrcvIndication = FALSE;
CanSM_Internal.Networks[i].TransceiverModeBuf.indTrcvMode = CANTRCV_TRCVMODE_NORMAL;
CanSM_Internal.Networks[i].PreNoCommState = CANSM_PRENOCOMM_S_TRCV_NORMAL;
CanSM_Internal.Networks[i].PreFullCommState = CANSM_PREFULLCOMM_S_TRCV_NORMAL;
CanSM_Internal.Networks[i].TransceiverModeBuf.clearWufPendingIndication = FALSE;
CanSM_Internal.Networks[i].TransceiverModeBuf.checkWufPendingIndication = FALSE;
} else {
CanSM_Internal.Networks[i].PreNoCommState = CANSM_PRENOCOMM_S_CC_STOPPED;
CanSM_Internal.Networks[i].PreFullCommState = CANSM_PREFULLCOMM_S_CC_STOPPED;
}
#else
CanSM_Internal.Networks[i].PreNoCommState = CANSM_PRENOCOMM_S_CC_STOPPED;
CanSM_Internal.Networks[i].PreFullCommState = CANSM_PREFULLCOMM_S_CC_STOPPED;
#endif
for(uint8 ctrl = 0; ctrl < CanSM_ConfigPtr->Networks[i].ControllerCount; ctrl++) {
done = FALSE;
for(uint8 index = 0; (index < NOF_CANSM_CANIF_CONTROLLERS) && (FALSE==done); index++) {
if( CanSM_ConfigPtr->Networks[i].Controllers[ctrl].CanIfControllerId ==
CanSM_Internal.ControllerModeBuf[index].controllerId ) {
/* Controller already indexed */
done = TRUE;/* Will break the loop */
} else if( INVALID_CONTROLLER_ID == CanSM_Internal.ControllerModeBuf[index].controllerId ) {
/* Empty slot, insert controller id */
CanSM_Internal.ControllerModeBuf[index].controllerId = CanSM_ConfigPtr->Networks[i].Controllers[ctrl].CanIfControllerId;
done = TRUE;/* Will break the loop */
} else {
/* Continue.. */
}
}
}
}
CanSM_Internal.InitStatus = CANSM_STATUS_INIT;
}
/* @req CANSM064 */
void CanSM_ControllerBusOff(uint8 ControllerId)
{
/* @req CANSM190 */
if( CANSM_STATUS_UNINIT == CanSM_Internal.InitStatus ) {
CANSM_DET_REPORTERROR(CANSM_SERVICEID_CONTROLLERBUSOFF, CANSM_E_UNINIT);
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return;
}
Std_ReturnType status = E_NOT_OK;
// Find which network has this controller
for (uint8 i = 0; i < CANSM_NETWORK_COUNT; ++i) {
const CanSM_NetworkType* Network = &CanSM_ConfigPtr->Networks[i];
for (uint8 j = 0; j < Network->ControllerCount; ++j) {
const CanSM_ControllerType* ptrController = &Network->Controllers[j];
if(ptrController->CanIfControllerId == ControllerId)
{
if (CANSM_BSM_S_FULLCOM == CanSM_Internal.Networks[i].BsmState)
{
/* @req CANSM235 */
CanSM_Internal.Networks[i].busoffevent = TRUE;
}
else {
CANSM_DET_REPORTERROR(CANSM_SERVICEID_CONTROLLERBUSOFF, CANSM_E_INVALID_INVALID_BUSOFF);
}
status = E_OK;
}
}
}
// Check if controller was valid
if(status != E_OK){
/* @req CANSM189 */
CANSM_DET_REPORTERROR(CANSM_SERVICEID_CONTROLLERBUSOFF, CANSM_E_PARAM_CONTROLLER);
}
}
/* @req CANSM062 */
Std_ReturnType CanSM_RequestComMode( NetworkHandleType NetworkHandle, ComM_ModeType ComM_Mode ) {
Std_ReturnType status;
status = E_OK;
/* @req CANSM182 */
/* @req CANSM369 */
/* @req CANSM370 */
/* @req CANSM278 */
if( CANSM_STATUS_UNINIT == CanSM_Internal.InitStatus ) {
/* @req CANSM184 */
CANSM_DET_REPORTERROR(CANSM_SERVICEID_REQUESTCOMMODE, CANSM_E_UNINIT);
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return E_NOT_OK;
}
if( (NetworkHandle >= CanSM_ConfigPtr->ChannelMapSize) || (CANSM_NETWORK_COUNT <= CanSM_ConfigPtr->ChannelMap[NetworkHandle]) ) {
/* @req CANSM183 */
CANSM_DET_REPORTERROR(CANSM_SERVICEID_REQUESTCOMMODE, CANSM_E_INVALID_NETWORK_HANDLE);
/*lint -e{904} ARGUMENT CHECK */
return E_NOT_OK;
}
/* Not a requirement but still.. */
if( (COMM_NO_COMMUNICATION != ComM_Mode) && (COMM_SILENT_COMMUNICATION != ComM_Mode) && (COMM_FULL_COMMUNICATION != ComM_Mode) ) {
CANSM_DET_REPORTERROR(CANSM_SERVICEID_REQUESTCOMMODE, CANSM_E_INVALID_NETWORK_MODE);
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return E_NOT_OK;
}
NetworkHandleType CanSMNetworkId = CanSM_ConfigPtr->ChannelMap[NetworkHandle];
CanSM_Internal_NetworkType *Network = &CanSM_Internal.Networks[CanSMNetworkId];
/* @req CANSM278 */
/* @req CANSM555 */
if( CANSM_BSM_S_NOT_INITIALIZED == Network->BsmState ) {
status = E_NOT_OK;
}
else if( (TRUE == CanSM_Internal_HasPendingControllerIndication(CanSMNetworkId))
#if (CANSM_CAN_TRCV_SUPPORT == STD_ON)
/*lint -e{9007} */
|| ((TRUE == CanSM_ConfigPtr->Networks[CanSMNetworkId].CanTrcvAvailable) && (E_OK != CanSM_Internal_GetTrcvrModeInd(CanSMNetworkId)))
#endif
)
{
/* @req CANSM395 */
/* Pending indication from CanIf */
CANSM_DET_REPORTERROR(CANSM_SERVICEID_REQUESTCOMMODE, CANSM_E_WAIT_MODE_INDICATION);
status = E_NOT_OK;
}
/* @req CANSM402 */
/* Added to this requirement that state machine cannot be in CANSM_BSM_S_PRECOM
* if COMM_SILENT_COMMUNICATION is requested this to handle the case when
* CANSM_BSM_S_FULLCOM exits with T_REPEAT_MAX. */
else if( ((COMM_NO_COMMUNICATION == Network->currentMode) ||
(CANSM_BSM_S_PRE_NOCOM == Network->BsmState)) &&
(COMM_SILENT_COMMUNICATION == ComM_Mode)) {
/* @req CANSM403 */
CANSM_DET_REPORTERROR(CANSM_SERVICEID_REQUESTCOMMODE, CANSM_E_INVALID_COMM_REQUEST);
status = E_NOT_OK;
}
/* Translate below to busoff state */
/* @req CANSM375 */
/* @req CANSM376 */
else if( (CANSM_BSM_S_FULLCOM == Network->BsmState) &&
(CANSM_FULLCOMM_S_BUSOFF_CHECK != Network->FullCommState) &&
(CANSM_FULLCOMM_S_NO_BUSOFF != Network->FullCommState) ) {
/* @req CANSM377 */
CANSM_DET_REPORTERROR(CANSM_SERVICEID_REQUESTCOMMODE, CANSM_E_BUSOFF_RECOVERY_ACTIVE);
status = E_NOT_OK;
}
/* Deny request if there is a busoff event. Do not report error here since upper layer cannot
* know that there is a busoff event present. If busoff event has been handled in main function
* we will never end up here as if should be handled by check above. */
else if( TRUE == Network->busoffevent ) {
status = E_NOT_OK;
} else {
/* Request accepted! */
Network->requestedMode = ComM_Mode;
status = E_OK;
}
return status;
}
/* @req CANSM063 */
Std_ReturnType CanSM_GetCurrentComMode( NetworkHandleType NetworkHandle, ComM_ModeType* ComM_ModePtr ) {
Std_ReturnType status;
status = E_OK;
/* @req CANSM188 */
if( CANSM_STATUS_UNINIT == CanSM_Internal.InitStatus ) {
CANSM_DET_REPORTERROR(CANSM_SERVICEID_GETCURRENTCOMMODE, CANSM_E_UNINIT);
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return E_NOT_OK;
}
/* @req CANSM371 */
/* @req CANSM372 */
if( (NetworkHandle >= CanSM_ConfigPtr->ChannelMapSize) || (CANSM_NETWORK_COUNT <= CanSM_ConfigPtr->ChannelMap[NetworkHandle]) ) {
/* @req CANSM187 */
CANSM_DET_REPORTERROR(CANSM_SERVICEID_GETCURRENTCOMMODE, CANSM_E_INVALID_NETWORK_HANDLE);
/*lint -e{904} ARGUMENT CHECK */
return E_NOT_OK;
}
if( NULL == ComM_ModePtr ) {
/* @req CANSM360 */
CANSM_DET_REPORTERROR(CANSM_SERVICEID_GETCURRENTCOMMODE, CANSM_E_PARAM_POINTER);
/*lint -e{904} ARGUMENT CHECK */
return E_NOT_OK;
}
/* @req CANSM282 */
if( FALSE == CanSM_Internal.Networks[CanSM_ConfigPtr->ChannelMap[NetworkHandle]].initialNoComRun ) {
status = E_NOT_OK;
}
if (status == E_OK){
/* @req CANSM186 */
*ComM_ModePtr = CanSM_Internal.Networks[CanSM_ConfigPtr->ChannelMap[NetworkHandle]].currentMode;
}
return status;
}
static void CanSM_Internal_SetNetworkPduMode(NetworkHandleType CanSMNetworkIndex, CanIf_PduSetModeType pduMode)
{
const CanSM_NetworkType *NetworkCfg = &CanSM_ConfigPtr->Networks[CanSMNetworkIndex];
for(uint8 ctrl = 0; ctrl < NetworkCfg->ControllerCount; ctrl++) {
if( E_OK != CanIf_SetPduMode(NetworkCfg->Controllers[ctrl].CanIfControllerId, pduMode) ) {
/* This is unexpected.. */
CANSM_DET_REPORTERROR(CANSM_SERVICEID_MAINFUNCTION, CANSM_E_UNEXPECTED_EXECUTION);
}
}
}
static void CanSM_Internal_ResetPendingIndications(NetworkHandleType CanSMNetworkIndex)
{
const CanSM_NetworkType *NetworkCfg = &CanSM_ConfigPtr->Networks[CanSMNetworkIndex];
for(uint8 ctrl = 0; ctrl < NetworkCfg->ControllerCount; ctrl++) {
uint8 ctrlIndex;
if( E_OK == CanSM_Internal_GetCanSMCtrlIdx(NetworkCfg->Controllers[ctrl].CanIfControllerId, &ctrlIndex) ) {
CanSM_Internal.ControllerModeBuf[ctrlIndex].hasPendingCtrlIndication = FALSE;
}
}
#if (CANSM_CAN_TRCV_SUPPORT == STD_ON)
CanSM_Internal.Networks[CanSMNetworkIndex].TransceiverModeBuf.hasPendingTrcvIndication = FALSE;
#endif
}
static void CanSM_Internal_ComM_BusSM_ModeIndication( NetworkHandleType CanSMNetworkIndex, ComM_ModeType ComM_Mode )
{
/* Update internals */
CanSM_Internal.Networks[CanSMNetworkIndex].currentMode = ComM_Mode;
/* Indicate to ComM */
ComM_BusSM_ModeIndication(CanSM_ConfigPtr->Networks[CanSMNetworkIndex].ComMNetworkHandle, &ComM_Mode);
}
#if (CANSM_CAN_TRCV_SUPPORT == STD_ON)
#endif
#if (CANSM_CAN_TRCV_SUPPORT == STD_ON)
CanSM_Internal_TransitionReturnType CanSM_Internal_DeinitWithPnSupport(NetworkHandleType CanSMNetworkIndex,CanSM_Internal_NetworkType *Network,CanSM_Internal_PreNoCommExitPointType *exitPoint,CanSM_Internal_PreNoCommStateType *nextSubState)
{
CanSM_Internal_TransitionReturnType tRet = T_DONE;
switch(Network->PreNoCommState) {
/* @req CANSM438 *//* @req CANSM439 *//* @req CANSM440 *//* @req CANSM443 */
case CANSM_PRENOCOMM_S_PN_CLEAR_WUF:
tRet = CanSM_Internal_Execute(Network, CanSMNetworkIndex, T_PN_CLEAR_WUF_CC_STOPPED);
if( T_DONE == tRet ) {
*nextSubState = CANSM_PRENOCOMM_S_CC_STOPPED;
}
break;
/* @req CANSM441 *//* @req CANSM442 *//* @req CANSM444 *//* @req CANSM445 */
case CANSM_PRENOCOMM_S_CC_STOPPED:
tRet = CanSM_Internal_Execute(Network, CanSMNetworkIndex, T_CC_STOPPED_TRCV_NORMAL);
if( T_DONE == tRet ) {
*nextSubState = CANSM_PRENOCOMM_S_TRCV_NORMAL;
}
break;
/* @req CANSM446 *//* @req CANSM447 *//* @req CANSM448 *//* @req CANSM449 */
case CANSM_PRENOCOMM_S_TRCV_NORMAL:
tRet = CanSM_Internal_Execute(Network, CanSMNetworkIndex, T_TRCV_NORMAL_TRCV_STANDBY);
if( T_DONE == tRet ) {
*nextSubState = CANSM_PRENOCOMM_S_TRCV_STANDBY;
}
break;
/* @req CANSM450 *//* @req CANSM451 *//* @req CANSM452 *//* @req CANSM454 */
case CANSM_PRENOCOMM_S_TRCV_STANDBY:
tRet = CanSM_Internal_Execute(Network, CanSMNetworkIndex, T_TRCV_STANDBY_CC_SLEEP);
if( T_DONE == tRet ) {
*nextSubState = CANSM_PRENOCOMM_S_CC_SLEEP;
}
break;
/* @req CANSM453 *//* @req CANSM455 *//* @req CANSM456 *//* @req CANSM457 */
case CANSM_PRENOCOMM_S_CC_SLEEP:
tRet = CanSM_Internal_Execute(Network, CanSMNetworkIndex, T_CC_SLEEP_CHECK_WUF_IN_CC_SLEEP);
if( T_DONE == tRet ) {
*nextSubState = CANSM_PRENOCOMM_S_CHECK_WUF_IN_CC_SLEEP;
} else if(T_TIMEOUT == tRet){
*nextSubState = CANSM_PRENOCOMM_S_CHECK_WUF_IN_NOT_CC_SLEEP;
}else{
/* Do nothing */
}
break;
/* @req CANSM458 *//* @req CANSM459 *//* @req CANSM460 *//* @req CANSM461 */
case CANSM_PRENOCOMM_S_CHECK_WUF_IN_CC_SLEEP:
tRet = CanSM_Internal_Execute(Network, CanSMNetworkIndex, T_CHECK_WUF_IN_CC_SLEEP_NONE);
if( T_DONE == tRet ) {
*exitPoint = CANSM_PRENOCOMM_EXIT_NOCOM;
} else{
/* Do nothing */
}
break;
/* @req CANSM462 */
case CANSM_PRENOCOMM_S_CHECK_WUF_IN_NOT_CC_SLEEP:
tRet = CanSM_Internal_Execute(Network, CanSMNetworkIndex, T_CHECK_WUF_IN_NOT_CC_SLEEP_PN_CLEAR_WUF);
if( T_DONE == tRet ) {
*nextSubState = CANSM_PRENOCOMM_S_PN_CLEAR_WUF;
}
break;
default:
CANSM_DET_REPORTERROR(CANSM_SERVICEID_MAINFUNCTION, CANSM_E_UNEXPECTED_EXECUTION);
break;
}
return tRet;
}
#endif
CanSM_Internal_TransitionReturnType CanSM_Internal_DeinitWithoutPnSupport(NetworkHandleType CanSMNetworkIndex,CanSM_Internal_NetworkType *Network,CanSM_Internal_PreNoCommExitPointType *exitPoint,CanSM_Internal_PreNoCommStateType *nextSubState)
{
CanSM_Internal_TransitionReturnType tRet = T_DONE;
switch(Network->PreNoCommState) {
#if (CANSM_CAN_TRCV_SUPPORT == STD_ON)
/* @req CANSM472 *//* @req CANSM473 *//* @req CANSM474 *//* @req CANSM475 */
case CANSM_PRENOCOMM_S_TRCV_NORMAL:
tRet = CanSM_Internal_Execute(Network, CanSMNetworkIndex, T_TRCV_NORMAL_TRCV_STANDBY);
if( T_DONE == tRet ) {
*nextSubState = CANSM_PRENOCOMM_S_TRCV_STANDBY;
}else{
/* Do nothing */
}
break;
/* @req CANSM476 *//* @req CANSM477 *//* @req CANSM478 *//* @req CANSM479 */
case CANSM_PRENOCOMM_S_TRCV_STANDBY:
tRet = CanSM_Internal_Execute(Network, CanSMNetworkIndex, T_TRCV_STANDBY_NONE);
if( T_DONE == tRet ) {
*exitPoint = CANSM_PRENOCOMM_EXIT_NOCOM;
}else{
/* Do nothing */
}
break;
#endif
case CANSM_PRENOCOMM_S_CC_STOPPED:
/* @req CANSM464 *//* @req CANSM465 *//* @req CANSM466 *//* @req CANSM467 */
tRet = CanSM_Internal_Execute(Network, CanSMNetworkIndex, T_CC_STOPPED_CC_SLEEP);
if( T_DONE == tRet ) {
*nextSubState = CANSM_PRENOCOMM_S_CC_SLEEP;
}else{
/* Do nothing */
}
break;
case CANSM_PRENOCOMM_S_CC_SLEEP:
/* @req CANSM468 *//* @req CANSM469 *//* @req CANSM470 *//* @req CANSM471 */
/* @req CANSM560 *//* @req CANSM556 *//* @req CANSM557 */
#if (CANSM_CAN_TRCV_SUPPORT == STD_ON)
if (TRUE == CanSM_ConfigPtr->Networks[CanSMNetworkIndex].CanTrcvAvailable){
tRet = CanSM_Internal_Execute(Network, CanSMNetworkIndex, T_CC_SLEEP_TRCV_NORMAL);
if( T_DONE == tRet ) {
*nextSubState = CANSM_PRENOCOMM_S_TRCV_NORMAL;
}else{
/* Do nothing */
}
} else {
tRet = CanSM_Internal_Execute(Network, CanSMNetworkIndex, T_CC_SLEEP_NONE);
if( T_DONE == tRet ) {
*exitPoint = CANSM_PRENOCOMM_EXIT_NOCOM;
}else{
/* Do nothing */
}
}
#else
tRet = CanSM_Internal_Execute(Network, CanSMNetworkIndex, T_CC_SLEEP_NONE);
if( T_DONE == tRet ) {
/* No support for trcv so we are done in this state */
*exitPoint = CANSM_PRENOCOMM_EXIT_NOCOM;
}else{
/* Do nothing */
}
#endif
break;
default:
CANSM_DET_REPORTERROR(CANSM_SERVICEID_MAINFUNCTION, CANSM_E_UNEXPECTED_EXECUTION);
break;
}
return tRet;
}
static CanSM_Internal_PreNoCommExitPointType CanSm_Internal_BSM_S_PRE_NOCOM( NetworkHandleType CanSMNetworkIndex )
{
CanSM_Internal_PreNoCommExitPointType exitPoint = CANSM_PRENOCOMM_EXIT_NONE;
CanSM_Internal_TransitionReturnType tRet ;
CanSM_Internal_NetworkType *Network = &CanSM_Internal.Networks[CanSMNetworkIndex];
CanSM_Internal_PreNoCommStateType nextSubState = Network->PreNoCommState;
#if (CANSM_CAN_TRCV_SUPPORT == STD_ON)
if ((FALSE == CanSM_ConfigPtr->Networks[CanSMNetworkIndex].CanTrcvAvailable)|| (FALSE == CanSM_ConfigPtr->Networks[CanSMNetworkIndex].CanSMTrcvPNEnabled))
{
/* @req CANSM436 */
tRet = CanSM_Internal_DeinitWithoutPnSupport(CanSMNetworkIndex, Network, &exitPoint, &nextSubState);
} else if (TRUE == CanSM_ConfigPtr->Networks[CanSMNetworkIndex].CanSMTrcvPNEnabled){
/* @req CANSM437 */
tRet = CanSM_Internal_DeinitWithPnSupport(CanSMNetworkIndex, Network, &exitPoint, &nextSubState);
}else{
/* Do nothing */
tRet = T_FAIL;
}
#else
tRet = CanSM_Internal_DeinitWithoutPnSupport(CanSMNetworkIndex, Network, &exitPoint, &nextSubState);
#endif
if( T_WAIT_INDICATION != tRet ) {
Network->subStateTimer = 0;
if( T_REPEAT_MAX == tRet ) {
CanSM_Internal_ResetPendingIndications(CanSMNetworkIndex);
/* @req CANSM480 */
/* @req CANSM385 */
CANSM_DET_REPORTERROR(CANSM_SERVICEID_MAINFUNCTION, CANSM_E_MODE_REQUEST_TIMEOUT);
exitPoint = CANSM_PRENOCOMM_EXIT_REP_MAX;
}
}
if( nextSubState != Network->PreNoCommState ) {
/* Changing state */
Network->PreNoCommState = nextSubState;
}
Network->subStateTimer++;
return exitPoint;
}
static CanSM_Internal_PreFullCommExitPointType CanSm_Internal_BSM_S_PRE_FULLCOM( NetworkHandleType CanSMNetworkIndex )
{
CanSM_Internal_PreFullCommExitPointType exitPoint = CANSM_PREFULLCOMM_EXIT_NONE;
CanSM_Internal_TransitionReturnType tRet = T_DONE;
CanSM_Internal_NetworkType *Network = &CanSM_Internal.Networks[CanSMNetworkIndex];
CanSM_Internal_PreFullCommStateType nextSubState = Network->PreFullCommState;
switch(Network->PreFullCommState) {
#if (CANSM_CAN_TRCV_SUPPORT == STD_ON)
/* @req CANSM483 *//* @req CANSM484 *//* @req CANSM485 *//* @req CANSM486 */
case CANSM_PREFULLCOMM_S_TRCV_NORMAL:
tRet = CanSM_Internal_Execute(Network, CanSMNetworkIndex, T_TRCV_NORMAL_CC_STOPPED);
if( T_DONE == tRet ) {
nextSubState = CANSM_PREFULLCOMM_S_CC_STOPPED;
}
break;
#endif
/* @req CANSM560 *//* @req CANSM558 */
case CANSM_PREFULLCOMM_S_CC_STOPPED:
/* @req CANSM487 *//* @req CANSM488 *//* @req CANSM489 *//* @req CANSM490 */
tRet = CanSM_Internal_Execute(Network, CanSMNetworkIndex, T_CC_STOPPED_CC_STARTED);
if( T_DONE == tRet ) {
nextSubState = CANSM_PREFULLCOMM_S_CC_STARTED;
}
break;
case CANSM_PREFULLCOMM_S_CC_STARTED:
/* @req CANSM491 *//* @req CANSM492 *//* @req CANSM493 *//* @req CANSM494 */
tRet = CanSM_Internal_Execute(Network, CanSMNetworkIndex, T_CC_STARTED_NONE);
if( T_DONE == tRet ) {
exitPoint = CANSM_PREFULLCOMM_EXIT_FULLCOMM;
}
break;
default:
CANSM_DET_REPORTERROR(CANSM_SERVICEID_MAINFUNCTION, CANSM_E_UNEXPECTED_EXECUTION);
break;
}
if( T_WAIT_INDICATION != tRet ) {
Network->subStateTimer = 0;
if( T_REPEAT_MAX == tRet ) {
CanSM_Internal_ResetPendingIndications(CanSMNetworkIndex);
/* @req CANSM495 */
/* @req CANSM385 */
CANSM_DET_REPORTERROR(CANSM_SERVICEID_MAINFUNCTION, CANSM_E_MODE_REQUEST_TIMEOUT);
exitPoint = CANSM_PREFULLCOMM_EXIT_REP_MAX;
}
}
if( nextSubState != Network->PreFullCommState ) {
/* Changing state */
Network->PreFullCommState = nextSubState;
}
Network->subStateTimer++;
return exitPoint;
}
static CanSM_Internal_FullCommExitPointType CanSm_Internal_BSM_S_FULLCOM( NetworkHandleType CanSMNetworkIndex )
{
/* Sub state machine for requested full communication requirements
* !req CANSM507
* !req CANSM528
* */
CanSM_Internal_FullCommExitPointType exitPoint = CANSM_FULLCOMM_EXIT_NONE;
CanSM_Internal_NetworkType *Network = &CanSM_Internal.Networks[CanSMNetworkIndex];
CanSM_Internal_TransitionReturnType tRet;
const CanSM_NetworkType *NetworkCfg = &CanSM_ConfigPtr->Networks[CanSMNetworkIndex];
switch(Network->FullCommState) {
case CANSM_FULLCOMM_S_BUSOFF_CHECK:
Network->subStateTimer++;
if( TRUE == Network->busoffevent ) {
/* @req CANSM500 */
Network->busoffTime = 0;
Network->busoffevent = FALSE;
/* Reset indications so that all controllers are restarted. */
CanSM_Internal_ResetControllerIndications(CanSMNetworkIndex);
if( Network->busoffCounter < NetworkCfg->CanSMBorCounterL1ToL2 ) {
Network->busoffCounter++;
}
#if defined(USE_BSWM)
/* @req CANSM508*/
BswM_CanSM_CurrentState(NetworkCfg->ComMNetworkHandle, CANSM_BSWM_BUS_OFF);
#endif
/* @req CANSM521 */
CanSM_Internal_ComM_BusSM_ModeIndication(CanSMNetworkIndex, COMM_SILENT_COMMUNICATION);
#if defined(USE_DEM)
/* @req CANSM522 */
if( DEM_EVENT_ID_NULL != NetworkCfg->CanSMDemEventId ) {
Dem_ReportErrorStatus(NetworkCfg->CanSMDemEventId, DEM_EVENT_STATUS_PREFAILED);
}
#endif
/* Restart controller */
CanSM_Internal_SetNetworkPduMode(CanSMNetworkIndex, CANIF_SET_OFFLINE); /* Non Autosar standard fix to possible frames are sent during busoff situation */
tRet = CanSM_Internal_Execute(Network, CanSMNetworkIndex, T_CC_STARTED_NONE);
if( T_REPEAT_MAX != tRet ) {
Network->FullCommState = CANSM_FULLCOMM_S_RESTART_CC;
} else {
CanSM_Internal_ResetPendingIndications(CanSMNetworkIndex);
/* T_REPEAT_MAX */
/* @req CANSM523 */
/* @req CANSM385 */
CANSM_DET_REPORTERROR(CANSM_SERVICEID_MAINFUNCTION, CANSM_E_MODE_REQUEST_TIMEOUT);
exitPoint = CANSM_FULLCOMM_EXIT_PRENOCOMM;
}
Network->subStateTimer = 0;
} else if( Network->subStateTimer >= NetworkCfg->CanSMBorTimeTxEnsured ) {
/* @req CANSM496 */
/* !req CANSM497 */
#if defined(USE_DEM)
/* @req CANSM498 */
if( DEM_EVENT_ID_NULL != NetworkCfg->CanSMDemEventId ) {
Dem_ReportErrorStatus(NetworkCfg->CanSMDemEventId, DEM_EVENT_STATUS_PASSED);
}
#endif
#if defined(USE_CANSM_EXTENSION)
CanSM_Extension_ReportNoBusOff(CanSMNetworkIndex);
#endif
Network->busoffCounter = 0;
Network->FullCommState = CANSM_FULLCOMM_S_NO_BUSOFF;
} else {
/* Stay in this state. */
}
break;
case CANSM_FULLCOMM_S_NO_BUSOFF:
if( TRUE == Network->busoffevent ) {
/* @req CANSM500 */
Network->busoffevent = FALSE;
Network->busoffTime = 0;
/* Reset indications so that all controllers are restarted. */
CanSM_Internal_ResetControllerIndications(CanSMNetworkIndex);
if( Network->busoffCounter < NetworkCfg->CanSMBorCounterL1ToL2 ) {
Network->busoffCounter++;
}
#if defined(USE_BSWM)
/* @req CANSM508 */
BswM_CanSM_CurrentState(NetworkCfg->ComMNetworkHandle, CANSM_BSWM_BUS_OFF);
#endif
/* @req CANSM521 */
CanSM_Internal_ComM_BusSM_ModeIndication(CanSMNetworkIndex, COMM_SILENT_COMMUNICATION);
#if defined(USE_DEM)
/* @req CANSM522 */
if( DEM_EVENT_ID_NULL != NetworkCfg->CanSMDemEventId ) {
Dem_ReportErrorStatus(NetworkCfg->CanSMDemEventId, DEM_EVENT_STATUS_PREFAILED);
}
#endif
/* Restart controller */
CanSM_Internal_SetNetworkPduMode(CanSMNetworkIndex, CANIF_SET_OFFLINE); /* Non Autosar standard fix to possible frames are sent during busoff situation */
tRet = CanSM_Internal_Execute(Network, CanSMNetworkIndex, T_CC_STARTED_NONE);
if( T_REPEAT_MAX != tRet ) {
Network->busoffevent = FALSE;
Network->FullCommState = CANSM_FULLCOMM_S_RESTART_CC;
} else {
CanSM_Internal_ResetPendingIndications(CanSMNetworkIndex);
/* T_REPEAT_MAX */
/* @req CANSM523 */
/* @req CANSM385 */
CANSM_DET_REPORTERROR(CANSM_SERVICEID_MAINFUNCTION, CANSM_E_MODE_REQUEST_TIMEOUT);
exitPoint = CANSM_FULLCOMM_EXIT_PRENOCOMM;
}
Network->subStateTimer = 0;
} else if( (COMM_SILENT_COMMUNICATION == Network->requestedMode) ||
( COMM_NO_COMMUNICATION == Network->requestedMode ) ) {
/* @req CANSM499 */
/* @req CANSM554 */
exitPoint = CANSM_FULLCOMM_EXIT_SILENTCOMM;
} else {
/* Stay in this state. */
}
break;
case CANSM_FULLCOMM_S_RESTART_CC:
Network->subStateTimer++;
/* @req CANSM509 *//* @req CANSM510 *//* @req CANSM466 *//* @req CANSM467 */
tRet = CanSM_Internal_Execute(Network, CanSMNetworkIndex, T_CC_STARTED_NONE);
if( T_DONE == tRet ) {
/* @req CANSM511 */
/* @req CANSM513 */
CanSM_Internal_SetNetworkPduMode(CanSMNetworkIndex, CANIF_SET_TX_OFFLINE);
Network->FullCommState = CANSM_FULLCOMM_S_TX_OFF;
Network->subStateTimer = 0;
} else if( (T_FAIL == tRet) || (T_REQ_ACCEPTED == tRet)) {
/* Timeout or request not accepted */
Network->subStateTimer = 0;
} else if( T_REPEAT_MAX == tRet ) {
CanSM_Internal_ResetPendingIndications(CanSMNetworkIndex);
/* T_REPEAT_MAX */
/* @req CANSM523 */
/* @req CANSM385 */
CANSM_DET_REPORTERROR(CANSM_SERVICEID_MAINFUNCTION, CANSM_E_MODE_REQUEST_TIMEOUT);
exitPoint = CANSM_FULLCOMM_EXIT_PRENOCOMM;
Network->subStateTimer = 0;
Network->busoffevent = FALSE;
} else {
/* Pending */
}
break;
case CANSM_FULLCOMM_S_TX_OFF:
Network->subStateTimer++;
/* @req CANSM514 */
/* @req CANSM515 */
if( ((Network->busoffTime >= NetworkCfg->CanSMBorTimeL1) &&
(Network->busoffCounter < NetworkCfg->CanSMBorCounterL1ToL2)) ||
((Network->busoffTime >= NetworkCfg->CanSMBorTimeL2) &&
(Network->busoffCounter >= NetworkCfg->CanSMBorCounterL1ToL2))) {
#if defined(USE_CANSM_EXTENSION)
CanSM_Extension_WriteState(CanSMNetworkIndex, Network->busoffCounter, Network->busoffTime, NetworkCfg);
#endif
/* @req CANSM516 */
CanSM_Internal_SetNetworkPduMode(CanSMNetworkIndex, CANIF_SET_ONLINE);
#if defined(USE_BSWM)
/* @req CANSM517*/
BswM_CanSM_CurrentState(NetworkCfg->ComMNetworkHandle, CANSM_BSWM_FULL_COMMUNICATION);
#endif
/* @req CANSM518 */
CanSM_Internal_ComM_BusSM_ModeIndication(CanSMNetworkIndex, COMM_FULL_COMMUNICATION);
Network->FullCommState = CANSM_FULLCOMM_S_BUSOFF_CHECK;
Network->subStateTimer = 0;
}
break;
default:
CANSM_DET_REPORTERROR(CANSM_SERVICEID_MAINFUNCTION, CANSM_E_UNEXPECTED_EXECUTION);
break;
}
Network->busoffTime++;
return exitPoint;
}
/* @req CANSM065 */
void CanSM_MainFunction() {
/* @req CANSM167 */
/* @req CANSM266 */
/* @req CANSM284 */
/* @req CANSM428 */
/* Main state machine requirements
* Guard: G_FULL_COM_MODE_REQUESTED
* !req CANSM427
* Guard: G_SILENT_COM_MODE_REQUESTED
* !req CANSM429
* Effect: E_BR_END_FULL_COM
* !req CANSM432
* Effect: E_BR_END_SILENT_COM
* !req CANSM433
* */
/* Sub state machine to operate a requested baud rate change
*
* !req CANSM524
* !req CANSM525
* !req CANSM526
* !req CANSM527
* !req CANSM529
* !req CANSM531
* !req CANSM532
* !req CANSM533
* !req CANSM534
* !req CANSM535
* !req CANSM536
* !req CANSM542
* !req CANSM543
* */
boolean status;
status = TRUE;
if( CANSM_STATUS_UNINIT == CanSM_Internal.InitStatus ) {
status = FALSE;
}
if (status == TRUE){
for (uint8 CanSMNetworkIndex = 0; CanSMNetworkIndex < CANSM_NETWORK_COUNT; CanSMNetworkIndex++) {
const CanSM_Internal_NetworkType *Network = &CanSM_Internal.Networks[CanSMNetworkIndex];
#if defined(USE_BSWM)
const CanSM_NetworkType *NetworkCfg = &CanSM_ConfigPtr->Networks[CanSMNetworkIndex];
#endif
switch(Network->BsmState) {
case CANSM_BSM_S_NOT_INITIALIZED:
case CANSM_BSM_S_PRE_NOCOM:
case CANSM_BSM_S_SILENTCOM:
/* @req CANSM423 */
/* @req CANSM426 */
if( (CANSM_BSM_S_NOT_INITIALIZED == Network->BsmState) ||
((CANSM_BSM_S_SILENTCOM == Network->BsmState) && (COMM_NO_COMMUNICATION == Network->requestedMode)) ) {
CanSM_Internal_EnterState(CanSMNetworkIndex, CANSM_BSM_S_PRE_NOCOM);
#if defined(USE_BSWM)
/* @req CANSM431 */
BswM_CanSM_CurrentState(NetworkCfg->ComMNetworkHandle, CANSM_BSWM_NO_COMMUNICATION);
#endif
}
if( CANSM_BSM_S_PRE_NOCOM == Network->BsmState ) {
CanSM_Internal_PreNoCommExitPointType preNoComExit = CanSm_Internal_BSM_S_PRE_NOCOM(CanSMNetworkIndex);
if( CANSM_PRENOCOMM_EXIT_NOCOM == preNoComExit ) {
CanSM_Internal_EnterState(CanSMNetworkIndex, CANSM_BSM_S_NOCOM);
/* @req CANSM430 */
CanSM_Internal_ComM_BusSM_ModeIndication(CanSMNetworkIndex, COMM_NO_COMMUNICATION);
} else if( CANSM_PRENOCOMM_EXIT_REP_MAX == preNoComExit ) {
CanSM_Internal_EnterState(CanSMNetworkIndex, CANSM_BSM_S_PRE_NOCOM);
/* Run a loop in PRE_NOCOM.
* NOTE: Not expected to exit that state here. */
if( CANSM_PRENOCOMM_EXIT_NOCOM == CanSm_Internal_BSM_S_PRE_NOCOM(CanSMNetworkIndex) ) {
CANSM_DET_REPORTERROR(CANSM_SERVICEID_MAINFUNCTION, CANSM_E_UNEXPECTED_EXECUTION);
}
} else {
/* No exit. */
}
} else if( (CANSM_BSM_S_SILENTCOM == Network->BsmState) && (COMM_FULL_COMMUNICATION == Network->requestedMode) ) {
// Effect: E_SILENT_TO_FULL_COM
/* Should be same as E_FULL_COMM. Spec. refers to CANSM435 but only obeying that
* requirement would not be the same as E_FULL_COMM. */
CanSM_Internal_EnterState(CanSMNetworkIndex, CANSM_BSM_S_FULLCOM);
/* @req CANSM550 */
#if defined(USE_BSWM)
/* @req CANSM435 */ /* @req CANSM550 */
BswM_CanSM_CurrentState(NetworkCfg->ComMNetworkHandle, CANSM_BSWM_FULL_COMMUNICATION);
#endif
/* @req CANSM435 */
CanSM_Internal_SetNetworkPduMode(CanSMNetworkIndex, CANIF_SET_ONLINE);
CanSM_Internal_ComM_BusSM_ModeIndication(CanSMNetworkIndex, COMM_FULL_COMMUNICATION);
} else {
/* Stay in state. */
}
break;
case CANSM_BSM_S_NOCOM:
case CANSM_BSM_S_PRE_FULLCOM:
/* @req CANSM425 */
if( (CANSM_BSM_S_NOCOM == Network->BsmState) && (COMM_FULL_COMMUNICATION == Network->requestedMode) ) {
/* Entered CANSM_BSM_S_PRE_NOCOM, reset pre full comm substate */
CanSM_Internal_EnterState(CanSMNetworkIndex, CANSM_BSM_S_PRE_FULLCOM);
}
if(CANSM_BSM_S_PRE_FULLCOM == Network->BsmState) {
CanSM_Internal_PreFullCommExitPointType preFullCommExit = CanSm_Internal_BSM_S_PRE_FULLCOM(CanSMNetworkIndex);
if( CANSM_PREFULLCOMM_EXIT_FULLCOMM == preFullCommExit ) {
CanSM_Internal_EnterState(CanSMNetworkIndex, CANSM_BSM_S_FULLCOM);
#if defined(USE_BSWM)
/* @req CANSM435 */
BswM_CanSM_CurrentState(NetworkCfg->ComMNetworkHandle, CANSM_BSWM_FULL_COMMUNICATION);
#endif
/* @req CANSM539 */
CanSM_Internal_SetNetworkPduMode(CanSMNetworkIndex, CANIF_SET_ONLINE);
/* @req CANSM540 */
CanSM_Internal_ComM_BusSM_ModeIndication(CanSMNetworkIndex, COMM_FULL_COMMUNICATION);
} else if( CANSM_PREFULLCOMM_EXIT_REP_MAX == preFullCommExit ) {
CanSM_Internal_EnterState(CanSMNetworkIndex, CANSM_BSM_S_PRE_NOCOM);
/* Run a loop in PRE_NOCOM.
* NOTE: Not expected to exit that state here. */
if( CANSM_PRENOCOMM_EXIT_NOCOM == CanSm_Internal_BSM_S_PRE_NOCOM(CanSMNetworkIndex) ) {
CANSM_DET_REPORTERROR(CANSM_SERVICEID_MAINFUNCTION, CANSM_E_UNEXPECTED_EXECUTION);
}
} else {
/* No exit. */
}
}
break;
case CANSM_BSM_S_FULLCOM:
{
boolean enterPreNoCom = FALSE;
CanSM_Internal_FullCommExitPointType fullCommExit = CanSm_Internal_BSM_S_FULLCOM(CanSMNetworkIndex);
if(CANSM_FULLCOMM_EXIT_PRENOCOMM == fullCommExit) {
/* Exit to PreNoCom is only due to T_REPEAT_MAX */
enterPreNoCom = TRUE;
} else if( CANSM_FULLCOMM_EXIT_SILENTCOMM == fullCommExit ) {
/* Exit due to accepted ComMode request */
CanSM_Internal_EnterState(CanSMNetworkIndex, CANSM_BSM_S_SILENTCOM);
#if defined(USE_BSWM)
/* @req CANSM434 */
BswM_CanSM_CurrentState(NetworkCfg->ComMNetworkHandle, CANSM_BSWM_SILENT_COMMUNICATION);
#endif
/* @req CANSM541 */
CanSM_Internal_SetNetworkPduMode(CanSMNetworkIndex, CANIF_SET_ONLINE);
/* @req CANSM537 */
CanSM_Internal_SetNetworkPduMode(CanSMNetworkIndex, CANIF_SET_TX_OFFLINE);
/* @req CANSM538 */
CanSM_Internal_ComM_BusSM_ModeIndication(CanSMNetworkIndex, COMM_SILENT_COMMUNICATION);
} else {
/* No exit. */
}
if( TRUE == enterPreNoCom ) {
CanSM_Internal_EnterState(CanSMNetworkIndex, CANSM_BSM_S_PRE_NOCOM);
#if defined(USE_BSWM)
/* @req CANSM431 */
BswM_CanSM_CurrentState(NetworkCfg->ComMNetworkHandle, CANSM_BSWM_NO_COMMUNICATION);
#endif
/* Run a loop in PRE_NOCOM.
* NOTE: Not expected to exit that state here. */
if( CANSM_PRENOCOMM_EXIT_NOCOM == CanSm_Internal_BSM_S_PRE_NOCOM(CanSMNetworkIndex) ) {
CANSM_DET_REPORTERROR(CANSM_SERVICEID_MAINFUNCTION, CANSM_E_UNEXPECTED_EXECUTION);
}
}
break;
}
default:
break;
}
}
}
}
/* @req CANSM396 */
void CanSM_ControllerModeIndication( uint8 ControllerId, CanIf_ControllerModeType ControllerMode )
{
if( CANSM_STATUS_UNINIT == CanSM_Internal.InitStatus ) {
/* @req CANSM398 */
CANSM_DET_REPORTERROR(CANSM_SERVICEID_CONTROLLERMODEINDICATION, CANSM_E_UNINIT);
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return;
}
uint8 controllerIndex;
if( E_OK == CanSM_Internal_GetCanSMCtrlIdx(ControllerId, &controllerIndex) ) {
/* Controller was valid */
/* Ignore indication of other modes than the requested */
if( (TRUE == CanSM_Internal.ControllerModeBuf[controllerIndex].hasPendingCtrlIndication) &&
(ControllerMode == CanSM_Internal.ControllerModeBuf[controllerIndex].pendingCtrlMode) ) {
CanSM_Internal.ControllerModeBuf[controllerIndex].hasPendingCtrlIndication = FALSE;
}
CanSM_Internal.ControllerModeBuf[controllerIndex].indCtrlMode = ControllerMode;
} else {
/* @req CANSM397 */
CANSM_DET_REPORTERROR(CANSM_SERVICEID_CONTROLLERMODEINDICATION, CANSM_E_PARAM_CONTROLLER);
}
}
#if 0
Std_ReturnType CanSm_CheckBaudrate(NetworkHandleType network, const uint16 Baudrate) {
/* !req CANSM564 */
/* !req CANSM565 */
/* !req CANSM562 */
/* !req CANSM571 */
/* !req CANSM563 */
/* !req CANSM566 */
/* !req CANSM567 */
/* !req CANSM568 */
/* !req CANSM572 */
return E_NOT_OK;
}
Std_ReturnType CanSm_ChangeBaudrate(NetworkHandleType network, const uint16 Baudrate) {
/* !req CANSM569 */
/* !req CANSM570 */
/* !req CANSM502 */
/* !req CANSM504 */
/* !req CANSM505 */
/* !req CANSM530 */
/* !req CANSM506 */
/* !req CANSM573 */
/* !req CANSM574 */
/* !req CANSM503 */
return E_NOT_OK;
}
void CanSM_TxTimeoutException( NetworkHandleType Channel )
{
/* !req CANSM411 */
/* !req CANSM412 */
}
#endif
#if (CANSM_CAN_TRCV_SUPPORT == STD_ON)
/* @req CANSM413 */
void CanSM_ClearTrcvWufFlagIndication( uint8 Transceiver )
{
NetworkHandleType CanSMNetworkIndex;
/* @req CANSM414 */
if( CANSM_STATUS_UNINIT == CanSM_Internal.InitStatus ) {
CANSM_DET_REPORTERROR(CANSM_SERVICEID_CLEARTRCVWUFINDICATION, CANSM_E_UNINIT);
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return;
}
/* @req CANSM415 */
if (E_NOT_OK == CanIfTrcvChnlToCanSMNwHdl(Transceiver, &CanSMNetworkIndex))
{
CANSM_DET_REPORTERROR(CANSM_SERVICEID_CLEARTRCVWUFINDICATION, CANSM_E_PARAM_TRANSCEIVER);
/*lint -e{904} ARGUMENT CHECK */
return;
}
CanSM_Internal.Networks[CanSMNetworkIndex].TransceiverModeBuf.clearWufPendingIndication = FALSE;
return;
}
/* @req CANSM416 */
void CanSM_CheckTransceiverWakeFlagIndication( uint8 Transceiver )
{
NetworkHandleType CanSMNetworkIndex;
/* @req CANSM417 */
if( CANSM_STATUS_UNINIT == CanSM_Internal.InitStatus ) {
CANSM_DET_REPORTERROR(CANSM_SERVICEID_CHECKTRCVWUFINDICATION, CANSM_E_UNINIT);
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return ;
}
/* @req CANSM418 */
if (E_NOT_OK == CanIfTrcvChnlToCanSMNwHdl(Transceiver, &CanSMNetworkIndex))
{
CANSM_DET_REPORTERROR(CANSM_SERVICEID_CHECKTRCVWUFINDICATION, CANSM_E_PARAM_TRANSCEIVER);
/*lint -e{904} ARGUMENT CHECK */
return;
}
CanSM_Internal.Networks[CanSMNetworkIndex].TransceiverModeBuf.checkWufPendingIndication = FALSE;
return;
}
/* @req CANSM419 */
void CanSM_ConfirmPnAvailability( uint8 Transceiver )
{
NetworkHandleType CanSMNetworkIndex;
/* @req CANSM420 */
if( CANSM_STATUS_UNINIT == CanSM_Internal.InitStatus ) {
/* @req CANSM401 */
CANSM_DET_REPORTERROR(CANSM_SERVICEID_CONFIRMPNAVAILABILITY, CANSM_E_UNINIT);
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return;
}
/* @req CANSM421 */
if (E_NOT_OK == CanIfTrcvChnlToCanSMNwHdl(Transceiver, &CanSMNetworkIndex))
{
CANSM_DET_REPORTERROR(CANSM_SERVICEID_CONFIRMPNAVAILABILITY, CANSM_E_PARAM_TRANSCEIVER);
/*lint -e{904} ARGUMENT CHECK */
return;
}
#if defined(USE_CANNM)
/* @req CANSM546 */
/* @req CANSM422 */
CanNm_ConfirmPnAvailability(CanSM_ConfigPtr->Networks[CanSMNetworkIndex].ComMNetworkHandle);
#endif
return;
}
/* @req CANSM399 */
void CanSM_TransceiverModeIndication(uint8 TransceiverId, CanTrcv_TrcvModeType TransceiverMode)
{
NetworkHandleType CanSMNetworkIndex;
if( CANSM_STATUS_UNINIT == CanSM_Internal.InitStatus ) {
/* @req CANSM401 */
CANSM_DET_REPORTERROR(CANSM_SERVICEID_TRANSCEIVERMODEINDICATION, CANSM_E_UNINIT);
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return;
}
if (E_NOT_OK == CanIfTrcvChnlToCanSMNwHdl(TransceiverId, &CanSMNetworkIndex))
{
/* @req CANSM400 */
CANSM_DET_REPORTERROR(CANSM_SERVICEID_TRANSCEIVERMODEINDICATION, CANSM_E_PARAM_TRANSCEIVER);
/*lint -e{904} ARGUMENT CHECK */
return;
}
if( (TRUE == CanSM_Internal.Networks[CanSMNetworkIndex].TransceiverModeBuf.hasPendingTrcvIndication) &&
(TransceiverMode == CanSM_Internal.Networks[CanSMNetworkIndex].TransceiverModeBuf.pendingTrcvMode))
{
CanSM_Internal.Networks[CanSMNetworkIndex].TransceiverModeBuf.hasPendingTrcvIndication = FALSE;
}
CanSM_Internal.Networks[CanSMNetworkIndex].TransceiverModeBuf.indTrcvMode = TransceiverMode;
return;
}
#endif
|
2301_81045437/classic-platform
|
communication/CanSM/src/CanSM.c
|
C
|
unknown
| 53,290
|
/*-------------------------------- 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 "CanSM_Extension.h"
void CanSM_Extension_WriteState(const NetworkHandleType NetworkHandle,
uint16 busoffCounter,
uint32 busoffTime,
const CanSM_NetworkType *NetworkCfg) {
}
void CanSM_Extension_ReportNoBusOff(const NetworkHandleType NetworkHandle) {
}
|
2301_81045437/classic-platform
|
communication/CanSM/src/CanSM_Extension.c
|
C
|
unknown
| 1,120
|
/*-------------------------------- 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 CANSM_EXTENSTION_H_
#define CANSM_EXTENSTION_H_
#include "ComStack_Types.h"
#include "CanSM_ConfigTypes.h"
void CanSM_Extension_WriteState(const NetworkHandleType NetworkHandle, uint16 busoffCounter, uint32 subStateTimer, const CanSM_NetworkType *NetworkCfg);
void CanSM_Extension_ReportNoBusOff(const NetworkHandleType NetworkHandle);
#endif
|
2301_81045437/classic-platform
|
communication/CanSM/src/CanSM_Extension.h
|
C
|
unknown
| 1,116
|
/*-------------------------------- 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 "CanSM.h"
#include "CanIf.h"
#include "CanSM_Internal.h"
/*lint -esym(9003,CanSM_ConfigPtr )*/
extern const CanSM_ConfigType* CanSM_ConfigPtr;
extern CanSM_InternalType CanSM_Internal;
#if (CANSM_CAN_TRCV_SUPPORT == STD_ON)
typedef enum{
CLEAR_WUF =0,
CHECK_WUF
}CanSM_WufActionType;
#endif
typedef union {
CanIf_ControllerModeType ccMode;
#if (CANSM_CAN_TRCV_SUPPORT == STD_ON)
CanTrcv_TrcvModeType trcvMode;
CanSM_WufActionType wufAction;
#endif
}CanSM_ActionMode;/*lint !e9018*/
typedef enum {
A_CC_MODE = 0,
#if (CANSM_CAN_TRCV_SUPPORT == STD_ON)
A_TRCV_MODE,
A_WUF,
#endif
A_NO_MODE
}CanSM_ActionType;
typedef struct {
CanSM_ActionType FirstAction;
CanSM_ActionMode FirstMode;
CanSM_ActionType SecondAction;
CanSM_ActionMode SecondMode;
}CanSM_TransitionType;
#define CANSM_NOF_TRANSITIONS (uint8)((uint8)T_CC_STARTED_NONE + 1u)
/*lint -esym(9003,TransitionConfig )*/
const CanSM_TransitionType TransitionConfig[T_NOF_TRANSITIONS] = {
[T_CC_STOPPED_CC_SLEEP] = {
.FirstAction = A_CC_MODE,
.FirstMode = {.ccMode = CANIF_CS_STOPPED},
.SecondAction = A_CC_MODE,
.SecondMode = {.ccMode = CANIF_CS_SLEEP}
},
#if (CANSM_CAN_TRCV_SUPPORT == STD_ON)
[T_CC_SLEEP_TRCV_NORMAL] = {
.FirstAction = A_CC_MODE,
.FirstMode = {.ccMode = CANIF_CS_SLEEP},
.SecondAction = A_TRCV_MODE,
.SecondMode = {.trcvMode = CANTRCV_TRCVMODE_NORMAL}
},
[T_TRCV_NORMAL_TRCV_STANDBY] = {
.FirstAction = A_TRCV_MODE,
.FirstMode = {.trcvMode = CANTRCV_TRCVMODE_NORMAL},
.SecondAction = A_TRCV_MODE,
.SecondMode = {.trcvMode = CANTRCV_TRCVMODE_STANDBY}
},
[T_TRCV_STANDBY_NONE] = {
.FirstAction = A_TRCV_MODE,
.FirstMode = {.trcvMode = CANTRCV_TRCVMODE_STANDBY},
.SecondAction = A_NO_MODE,
.SecondMode = {.ccMode = (CanIf_ControllerModeType)0} /* Don't care */
},
[T_TRCV_NORMAL_CC_STOPPED] = {
.FirstAction = A_TRCV_MODE,
.FirstMode = {.trcvMode = CANTRCV_TRCVMODE_NORMAL},
.SecondAction = A_CC_MODE,
.SecondMode = {.ccMode = CANIF_CS_STOPPED}
},
[T_PN_CLEAR_WUF_CC_STOPPED] = {
.FirstAction = A_WUF,
.FirstMode = {.wufAction = CLEAR_WUF},
.SecondAction = A_CC_MODE,
.SecondMode = {.ccMode = CANIF_CS_STOPPED}
},
[T_CC_STOPPED_TRCV_NORMAL] = {
.FirstAction = A_CC_MODE,
.FirstMode = {.ccMode = CANIF_CS_STOPPED},
.SecondAction = A_TRCV_MODE,
.SecondMode = {.trcvMode = CANTRCV_TRCVMODE_NORMAL}
},
[T_TRCV_STANDBY_CC_SLEEP] = {
.FirstAction = A_TRCV_MODE,
.FirstMode = {.trcvMode = CANTRCV_TRCVMODE_STANDBY},
.SecondAction = A_CC_MODE,
.SecondMode = {.ccMode = CANIF_CS_SLEEP}
},
[T_CC_SLEEP_CHECK_WUF_IN_CC_SLEEP] = {
.FirstAction = A_CC_MODE,
.FirstMode = {.ccMode = CANIF_CS_SLEEP},
.SecondAction = A_WUF,
.SecondMode = {.wufAction = CHECK_WUF}
},
[T_CHECK_WUF_IN_CC_SLEEP_NONE] = {
.FirstAction = A_WUF,
.FirstMode = {.wufAction = CHECK_WUF},
.SecondAction = A_NO_MODE,
.SecondMode = {.ccMode = (CanIf_ControllerModeType)0} /* Don't care */
},
[T_CHECK_WUF_IN_NOT_CC_SLEEP_PN_CLEAR_WUF] = {
.FirstAction = A_WUF,
.FirstMode = {.wufAction = CHECK_WUF},
.SecondAction = A_WUF,
.SecondMode = {.wufAction = CLEAR_WUF}
},
#endif
[T_CC_SLEEP_NONE] = {
.FirstAction = A_CC_MODE,
.FirstMode = {.ccMode = CANIF_CS_SLEEP},
.SecondAction = A_NO_MODE,
.SecondMode = {.ccMode = (CanIf_ControllerModeType)0} /* Don't care */
},
[T_CC_STOPPED_CC_STARTED] = {
.FirstAction = A_CC_MODE,
.FirstMode = {.ccMode = CANIF_CS_STOPPED},
.SecondAction = A_CC_MODE,
.SecondMode = {.ccMode = CANIF_CS_STARTED}
},
[T_CC_STARTED_NONE] = {
.FirstAction = A_CC_MODE,
.FirstMode = {.ccMode = CANIF_CS_STARTED},
.SecondAction = A_NO_MODE,
.SecondMode = {.ccMode = (CanIf_ControllerModeType)0} /* Don't care */
}
};
/*lint -save -e9018 *//* We use pointers of type enum and we are careful in handling this */
Std_ReturnType modeRequestAction(NetworkHandleType CanSMNetworkIndex, const CanSM_ActionType *action, const CanSM_ActionMode *mode);
Std_ReturnType modeReadRequest(NetworkHandleType CanSMNetworkIndex, const CanSM_ActionType *action, const CanSM_ActionMode *mode);
static Std_ReturnType CanSM_Internal_GetNetworkControllerModeIndicated(NetworkHandleType CanSMNetworkIndex)
{
Std_ReturnType totalStatus = E_OK;
const CanSM_NetworkType *NetworkCfg = &CanSM_ConfigPtr->Networks[CanSMNetworkIndex];
for(uint8 ctrl = 0; ctrl < NetworkCfg->ControllerCount; ctrl++) {
uint8 ctrlIndex;
if( E_OK != CanSM_Internal_GetCanSMCtrlIdx(NetworkCfg->Controllers[ctrl].CanIfControllerId, &ctrlIndex) ) {
totalStatus = E_NOT_OK;
break;
}
if(CanSM_Internal.ControllerModeBuf[ctrlIndex].indCtrlMode != CanSM_Internal.ControllerModeBuf[ctrlIndex].pendingCtrlMode) {
/* Has not indicated the last requested mode */
totalStatus = E_NOT_OK;
}
if( TRUE == CanSM_Internal.ControllerModeBuf[ctrlIndex].hasPendingCtrlIndication ) {
/* No indication received after last request */
totalStatus = E_NOT_OK;
}
}
return totalStatus;
}
#if (CANSM_CAN_TRCV_SUPPORT == STD_ON)
/* Set Trcv Mode */
Std_ReturnType CanSM_Internal_SetNetworkTransceiverMode(NetworkHandleType CanSMNetworkIndex, CanTrcv_TrcvModeType trcvMode)
{
Std_ReturnType totalStatus = E_OK;
CanSM_Internal.Networks[CanSMNetworkIndex].TransceiverModeBuf.hasPendingTrcvIndication = TRUE;
CanSM_Internal.Networks[CanSMNetworkIndex].TransceiverModeBuf.pendingTrcvMode = trcvMode;
if( E_OK != CanIf_SetTrcvMode(CanSM_Internal.Networks[CanSMNetworkIndex].TransceiverModeBuf.trcvId, trcvMode)) {
/* Not accepted. No mode indication pending */
CanSM_Internal.Networks[CanSMNetworkIndex].TransceiverModeBuf.hasPendingTrcvIndication = FALSE;
totalStatus = E_NOT_OK;
}
return totalStatus;
}
/* Get Trcv Mode */
Std_ReturnType CanSM_Internal_GetTrcvrModeInd(NetworkHandleType CanSMNetworkIndex)
{
Std_ReturnType totalStatus = E_OK;
if( TRUE == CanSM_Internal.Networks[CanSMNetworkIndex].TransceiverModeBuf.hasPendingTrcvIndication) {
totalStatus = E_NOT_OK;
}
return totalStatus;
}
/* Check Wakeup flag status */
Std_ReturnType CanSM_Internal_CheckWuf(NetworkHandleType CanSMNetworkIndex)
{
Std_ReturnType totalStatus;
totalStatus = CanIf_CheckTrcvWakeFlag(CanSM_Internal.Networks[CanSMNetworkIndex].TransceiverModeBuf.trcvId);
if(E_OK == totalStatus) {
CanSM_Internal.Networks[CanSMNetworkIndex].TransceiverModeBuf.checkWufPendingIndication = TRUE;
} else{
CanSM_Internal.Networks[CanSMNetworkIndex].TransceiverModeBuf.checkWufPendingIndication = FALSE;
}
return totalStatus;
}
/* Clear Wakeup flag */
Std_ReturnType CanSM_Internal_ClearWuf(NetworkHandleType CanSMNetworkIndex)
{
Std_ReturnType totalStatus;
totalStatus = CanIf_ClearTrcvWufFlag(CanSM_Internal.Networks[CanSMNetworkIndex].TransceiverModeBuf.trcvId);
if(E_OK == totalStatus) {
CanSM_Internal.Networks[CanSMNetworkIndex].TransceiverModeBuf.clearWufPendingIndication = TRUE;
} else {
CanSM_Internal.Networks[CanSMNetworkIndex].TransceiverModeBuf.clearWufPendingIndication = FALSE;
}
return totalStatus;
}
/* Check wakeup flag indication */
Std_ReturnType CanSM_Internal_CheckWufInd(NetworkHandleType CanSMNetworkIndex)
{
Std_ReturnType totalStatus = E_OK;
if( TRUE == CanSM_Internal.Networks[CanSMNetworkIndex].TransceiverModeBuf.checkWufPendingIndication) {
totalStatus = E_NOT_OK;
}
return totalStatus;
}
/* Clear Wakeup flag Indication provided */
Std_ReturnType CanSM_Internal_ClearWufInd(NetworkHandleType CanSMNetworkIndex)
{
Std_ReturnType totalStatus = E_OK;
if( TRUE == CanSM_Internal.Networks[CanSMNetworkIndex].TransceiverModeBuf.clearWufPendingIndication) {
totalStatus = E_NOT_OK;
}
return totalStatus;
}
#endif
static Std_ReturnType CanSM_Internal_SetNetworkControllerMode(NetworkHandleType CanSMNetworkIndex, CanIf_ControllerModeType controllerMode)
{
Std_ReturnType totalStatus = E_OK;
const CanSM_NetworkType *NetworkCfg = &CanSM_ConfigPtr->Networks[CanSMNetworkIndex];
for(uint8 ctrl = 0; ctrl < NetworkCfg->ControllerCount; ctrl++) {
uint8 value;
if( E_OK != CanSM_Internal_GetCanSMCtrlIdx(NetworkCfg->Controllers[ctrl].CanIfControllerId, &value) ) {
totalStatus = E_NOT_OK;
break;
}
#if !defined(CANSM_REPEAT_ALL_REQUESTS_ON_TIMEOUT)
/* Only request controller mode if it differs from the last indicated */
CanSM_Internal.ControllerModeBuf[value].pendingCtrlMode = controllerMode;
if(CanSM_Internal.ControllerModeBuf[value].indCtrlMode != controllerMode) {
CanSM_Internal.ControllerModeBuf[value].hasPendingCtrlIndication = TRUE;
if( E_OK != CanIf_SetControllerMode(NetworkCfg->Controllers[ctrl].CanIfControllerId, controllerMode)) {
/* Not accepted. No mode indication pending */
CanSM_Internal.ControllerModeBuf[value].hasPendingCtrlIndication = FALSE;
totalStatus = E_NOT_OK;
}
}
#else
CanSM_Internal.ControllerModeBuf[value].hasPendingCtrlIndication = TRUE;
CanSM_Internal.ControllerModeBuf[value].pendingCtrlMode = controllerMode;
if( E_OK != CanIf_SetControllerMode(NetworkCfg->Controllers[ctrl].CanIfControllerId, controllerMode)) {
/* Not accepted. No mode indication pending */
CanSM_Internal.ControllerModeBuf[value].hasPendingCtrlIndication = FALSE;
totalStatus = E_NOT_OK;
}
#endif
}
return totalStatus;
}
Std_ReturnType modeRequestAction(NetworkHandleType CanSMNetworkIndex,const CanSM_ActionType *action,const CanSM_ActionMode *mode)
{
Std_ReturnType actionRet;
actionRet = E_NOT_OK;
if( A_CC_MODE == *action ) {
actionRet = CanSM_Internal_SetNetworkControllerMode(CanSMNetworkIndex,mode->ccMode);
#if (CANSM_CAN_TRCV_SUPPORT == STD_ON)
} else if (A_TRCV_MODE == *action ) {
actionRet = CanSM_Internal_SetNetworkTransceiverMode(CanSMNetworkIndex, mode->trcvMode);
} else if (A_WUF == *action )
{
if (CHECK_WUF == mode->wufAction)
{
actionRet = CanSM_Internal_CheckWuf(CanSMNetworkIndex);
} else if (CLEAR_WUF == mode->wufAction){
actionRet = CanSM_Internal_ClearWuf(CanSMNetworkIndex);
} else{
/* Do nothing */
}
#endif
} else {
CANSM_DET_REPORTERROR(CANSM_SERVICEID_MAINFUNCTION, CANSM_E_INVALID_ACTION);
}
return actionRet;
}
Std_ReturnType modeReadRequest(NetworkHandleType CanSMNetworkIndex,const CanSM_ActionType *action,const CanSM_ActionMode *mode)
{
Std_ReturnType indicationRet;
indicationRet = E_NOT_OK;
/*lint --e{715} */ /* mode will not be used when CANSM_CAN_TRCV_SUPPORT is off */
if( A_CC_MODE == *action ) {
indicationRet = CanSM_Internal_GetNetworkControllerModeIndicated(CanSMNetworkIndex);
}
#if (CANSM_CAN_TRCV_SUPPORT == STD_ON)
else if( A_TRCV_MODE == *action ) {
indicationRet = CanSM_Internal_GetTrcvrModeInd(CanSMNetworkIndex);
}
else if (A_WUF == *action ) {
if (CHECK_WUF == mode->wufAction)
{
indicationRet = CanSM_Internal_CheckWufInd(CanSMNetworkIndex);
} else if (CLEAR_WUF == mode->wufAction){
indicationRet = CanSM_Internal_ClearWufInd(CanSMNetworkIndex);
}else{
/* Do nothing */
}
}
#endif
else {
/* Do nothing */
/* Avoid compiler warning */
(void)mode; /*lint !e920 Avoid compiler warning (variable not used) */
}
return indicationRet;
}
CanSM_Internal_TransitionReturnType CanSM_Internal_Execute(CanSM_Internal_NetworkType *Network, NetworkHandleType CanSMNetworkIndex, CanSM_Internal_TransitionType transition) {
CanSM_Internal_TransitionReturnType ret = T_WAIT_INDICATION;
const CanSM_TransitionType *transitionPtr = &TransitionConfig[transition];
Std_ReturnType actionRet;
Std_ReturnType indicationRet;
if( FALSE == Network->requestAccepted ) {
Network->RepeatCounter++;
/* @req CANSM464 *//* PreNoCom CC_STOPPED */
/* @req CANSM468 *//* PreNoCom CC_SLEEP */
/* @req CANSM487 *//* PreFullCom CC_STOPPED */
/* @req CANSM491 *//* PreFullCom CC_STARTED */
/* @req CANSM509 *//* FullCom RESTART_CC */
/* @req CANSM441 *//* PreNoCom (DEINIT_WITH_PN) CC_STOPPED */
/* @req CANSM453 *//* PreNoCom (DEINIT_WITH_PN) CC_SLEEP */
/* @req CANSM446 *//* PreNoCom (DEINIT_WITH_PN) TRCV_NORMAL */
/* @req CANSM450 *//* PreNoCom (DEINIT_WITH_PN) TRCV_STANDBY */
/* @req CANSM472 *//* PreNoCom (DEINIT_WITHOUT_PN) TRCV_NORMAL */
/* @req CANSM476 *//* PreNoCom (DEINIT_WITHOUT_PN) TRCV_STANDBY */
/* @req CANSM483 *//* PreFullCom TRCV_NORMAL */
/* @req CANSM458 *//* PreNoCom (DEINIT_WITH_PN) PN_CHECK_WUF */
/* @req CANSM462 *//* PreNoCom (DEINIT_WITH_PN) PN_CHECK_WUF_IN_NOT_CC_SLEEP */
/* @req CANSM438 */ /* PreNoCom (DEINIT_WITH_PN) PN_CLEAR_WUF */
actionRet = modeRequestAction(CanSMNetworkIndex,&(transitionPtr->FirstAction),&(transitionPtr->FirstMode));
if( E_OK == actionRet ) {
/* @req CANSM465 *//* PreNoCom CC_STOPPED */
/* @req CANSM469 *//* PreNoCom CC_SLEEP */
/* @req CANSM488 *//* PreFullCom CC_STOPPED */
/* @req CANSM492 *//* PreFullCom CC_STARTED */
/* @req CANSM510 *//* FullCom RESTART_CC */
/* @req CANSM439 *//* PreNoCom (DEINIT_WITH_PN) PN_CLEAR_WUF */
/* @req CANSM442 *//* PreNoCom (DEINIT_WITH_PN) CC_STOPPED */
/* @req CANSM447 *//* PreNoCom (DEINIT_WITH_PN) TRCV_NORMAL */
/* @req CANSM451 *//* PreNoCom (DEINIT_WITH_PN) TRCV_STANDBY */
/* @req CANSM455 *//* PreNoCom (DEINIT_WITH_PN) CC_SLEEP */
/* @req CANSM459 *//* PreNoCom (DEINIT_WITH_PN) PN_CHECK_WUF */
/* @req CANSM473 *//* PreNoCom (DEINIT_WITHOUT_PN) TRCV_NORMAL */
/* @req CANSM477 *//* PreNoCom (DEINIT_WITHOUT_PN) TRCV_STANDBY */
/* @req CANSM484 *//* PreFullCom TRCV_NORMAL */
Network->requestAccepted = TRUE;
ret = T_REQ_ACCEPTED;
} else {
/* Request not accepted */
ret = T_FAIL;
if( Network->RepeatCounter > CanSM_ConfigPtr->CanSMModeRequestRepetitionMax ) {
/* @req CANSM463 */
/* @req CANSM480 */
/* T_REPEAT_MAX */
Network->RepeatCounter = 0;
ret = T_REPEAT_MAX;
}
}
} else {
/* Check if mode has been indicated */
indicationRet = modeReadRequest(CanSMNetworkIndex,&(transitionPtr->FirstAction),&(transitionPtr->FirstMode));
if(E_OK == indicationRet) {
/* @req CANSM466 *//* PreNoCom CC_STOPPED */
/* @req CANSM470 *//* PreNoCom CC_SLEEP */
/* @req CANSM489 *//* PreFullCom CC_STOPPED */
/* @req CANSM493 *//* PreFullCom CC_STARTED */
/* @req CANSM511 *//* FullCom RESTART_CC */
/* @req CANSM440 *//* PreNoCom (DEINIT_WITH_PN) PN_CLEAR_WUF */
/* @req CANSM444 *//* PreNoCom (DEINIT_WITH_PN) CC_STOPPED */
/* @req CANSM448 *//* PreNoCom (DEINIT_WITH_PN) TRCV_NORMAL */
/* @req CANSM452 *//* PreNoCom (DEINIT_WITH_PN) TRCV_STANDBY */
/* @req CANSM456 *//* PreNoCom (DEINIT_WITH_PN) CC_SLEEP */
/* @req CANSM460 *//* PreNoCom (DEINIT_WITH_PN) PN_CHECK_WUF */
/* @req CANSM474 *//* PreNoCom (DEINIT_WITHOUT_PN) TRCV_NORMAL */
/* @req CANSM478 *//* PreNoCom (DEINIT_WITHOUT_PN) TRCV_STANDBY */
/* @req CANSM485 *//* PreFullCom TRCV_NORMAL */
/* Mode indicated, new request */
Network->RepeatCounter = 0;
Network->requestAccepted = FALSE;
if( A_NO_MODE != transitionPtr->SecondAction ) {
actionRet = modeRequestAction(CanSMNetworkIndex,&(transitionPtr->SecondAction),&(transitionPtr->SecondMode));
Network->RepeatCounter++;
if( E_OK == actionRet ) {
/* Request accepted */
Network->requestAccepted = TRUE;
ret = T_DONE;
} else {
/* Not accepted */
if( Network->RepeatCounter <= CanSM_ConfigPtr->CanSMModeRequestRepetitionMax ) {
/* proceed to next state state */
ret = T_DONE;
} else {
/* @req CANSM463 */
/* @req CANSM480 */
/* T_REPEAT_MAX */
ret = T_REPEAT_MAX;
Network->RepeatCounter = 0;
}
}
} else {
/* No second action */
ret = T_DONE;
}
} else if( Network->subStateTimer >= CanSM_ConfigPtr->CanSMModeRequestRepetitionTime ) {
/* Timeout */
/* @req CANSM467 *//* PreNoCom CC_STOPPED */
/* @req CANSM471 *//* PreNoCom CC_SLEEP */
/* @req CANSM490 *//* PreFullCom CC_STOPPED */
/* @req CANSM494 *//* PreFullCom CC_STARTED */
/* @req CANSM512 *//* FullCom RESTART_CC */
/* @req CANSM443 *//* PreNoCom (DEINIT_WITH_PN) PN_CLEAR_WUF */
/* @req CANSM445 *//* PreNoCom (DEINIT_WITH_PN) CC_STOPPED */
/* @req CANSM449 *//* PreNoCom (DEINIT_WITH_PN) TRCV_NORMAL */
/* @req CANSM454 *//* PreNoCom (DEINIT_WITH_PN) TRCV_STANDBY */
/* @req CANSM457 *//* PreNoCom (DEINIT_WITH_PN) CC_SLEEP */
/* @req CANSM461 *//* PreNoCom (DEINIT_WITH_PN) PN_CHECK_WUF */
/* @req CANSM475 *//* PreNoCom (DEINIT_WITHOUT_PN) TRCV_NORMAL */
/* @req CANSM479 *//* PreNoCom (DEINIT_WITHOUT_PN) TRCV_STANDBY */
/* @req CANSM486 *//* PreFullCom TRCV_NORMAL */
Network->requestAccepted = FALSE;
#if (CANSM_CAN_TRCV_SUPPORT == STD_ON)
if ((TRUE == CanSM_ConfigPtr->Networks[CanSMNetworkIndex].CanSMTrcvPNEnabled) && ( A_CC_MODE == transitionPtr->FirstAction )
&& (CANIF_CS_SLEEP == transitionPtr->FirstMode.ccMode))
{
ret = T_TIMEOUT;
}else{
/* Do nothing */
}
#endif
/*lint -e{774} ret value can be T_TIMEOUT depending on CANSM_CAN_TRCV_SUPPORT is STD_ON or STD_OFF*/
if (ret != T_TIMEOUT) {
if( Network->RepeatCounter <= CanSM_ConfigPtr->CanSMModeRequestRepetitionMax ) {
Network->RepeatCounter++;
/* Try again */
actionRet = modeRequestAction(CanSMNetworkIndex,&(transitionPtr->FirstAction),&(transitionPtr->FirstMode));
if( E_OK == actionRet ) {
/* Request accepted */
Network->requestAccepted = TRUE;
ret = T_REQ_ACCEPTED;
} else {
if( Network->RepeatCounter > CanSM_ConfigPtr->CanSMModeRequestRepetitionMax ) {
/* T_REPEAT_MAX */
/* @req CANSM480 *//* PreNoCom */
/* @req CANSM495 *//* PreFullCom */
/* @req CANSM523 *//* FullCom */
/* @req CANSM463 */
Network->RepeatCounter = 0;
ret = T_REPEAT_MAX;
} else {
/* Keep state */
}
}
} else {
/* T_REPEAT_MAX */
/* @req CANSM480 *//* PreNoCom */
/* @req CANSM495 *//* PreFullCom */
/* @req CANSM523 *//* FullCom */
Network->RepeatCounter = 0;
ret = T_REPEAT_MAX;
}
}
} else {
/* Keep waiting. */
}
}
return ret;
}
/*lint -restore */
|
2301_81045437/classic-platform
|
communication/CanSM/src/CanSM_Internal.c
|
C
|
unknown
| 22,387
|
/*-------------------------------- 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 CANSM_INTERNAL_H
#define CANSM_INTERNAL_H
#include "CanSM.h"
#include "CanIf.h"
/** @req CANSM028 @req CANSM071 @req CANSM363 @req CANSM364 */
#if (CANSM_DEV_ERROR_DETECT == STD_ON)
/* @req CANSM074 */
#define CANSM_DET_REPORTERROR(_api, _error) (void)Det_ReportError(CANSM_MODULE_ID, 0, _api, _error)
#else
#define CANSM_DET_REPORTERROR(serviceId, errorId)
#endif
typedef struct {
uint8 controllerId;
boolean hasPendingCtrlIndication;
CanIf_ControllerModeType pendingCtrlMode;
CanIf_ControllerModeType indCtrlMode;
}CanSM_Internal_CtrlStatusType;
#if (CANSM_CAN_TRCV_SUPPORT == STD_ON)
typedef struct {
uint8 trcvId;
boolean hasPendingTrcvIndication;
CanTrcv_TrcvModeType pendingTrcvMode;
CanTrcv_TrcvModeType indTrcvMode;
boolean checkWufPendingIndication;
boolean clearWufPendingIndication;
}CanSM_Internal_TrcvStatusType;
#endif
typedef enum {
CANSM_PRENOCOMM_EXIT_NONE,
CANSM_PRENOCOMM_EXIT_NOCOM,
CANSM_PRENOCOMM_EXIT_REP_MAX
} CanSM_Internal_PreNoCommExitPointType;
typedef enum {
CANSM_PREFULLCOMM_EXIT_NONE,
CANSM_PREFULLCOMM_EXIT_FULLCOMM,
CANSM_PREFULLCOMM_EXIT_REP_MAX
} CanSM_Internal_PreFullCommExitPointType;
typedef enum {
CANSM_FULLCOMM_EXIT_NONE,
CANSM_FULLCOMM_EXIT_PRENOCOMM,
CANSM_FULLCOMM_EXIT_SILENTCOMM
} CanSM_Internal_FullCommExitPointType;
typedef enum {
CANSM_BSM_S_NOT_INITIALIZED = 0,/* @req CANSM424 */
CANSM_BSM_S_PRE_NOCOM,
CANSM_BSM_S_NOCOM,
CANSM_BSM_S_PRE_FULLCOM,
CANSM_BSM_S_FULLCOM,
CANSM_BSM_S_SILENTCOM
// CANSM_BSM_S_CHANGE_BAUDRATE
} CanSM_Internal_BsmStateType;
typedef enum {
CANSM_PRENOCOMM_S_CC_STOPPED = 0,
#if (CANSM_CAN_TRCV_SUPPORT == STD_ON)
CANSM_PRENOCOMM_S_CC_SLEEP,
CANSM_PRENOCOMM_S_TRCV_NORMAL,
CANSM_PRENOCOMM_S_TRCV_STANDBY,
CANSM_PRENOCOMM_S_PN_CLEAR_WUF,
CANSM_PRENOCOMM_S_CHECK_WUF_IN_CC_SLEEP,
CANSM_PRENOCOMM_S_CHECK_WUF_IN_NOT_CC_SLEEP,
#else
CANSM_PRENOCOMM_S_CC_SLEEP
#endif
}CanSM_Internal_PreNoCommStateType;
typedef enum {
#if (CANSM_CAN_TRCV_SUPPORT == STD_ON)
CANSM_PREFULLCOMM_S_TRCV_NORMAL,
#endif
CANSM_PREFULLCOMM_S_CC_STOPPED,
CANSM_PREFULLCOMM_S_CC_STARTED
}CanSM_Internal_PreFullCommStateType;
typedef enum {
CANSM_FULLCOMM_S_BUSOFF_CHECK = 0,
CANSM_FULLCOMM_S_NO_BUSOFF,
CANSM_FULLCOMM_S_RESTART_CC,
CANSM_FULLCOMM_S_TX_OFF
}CanSM_Internal_FullCommStateType;
typedef enum {
CANSM_STATUS_UNINIT,
CANSM_STATUS_INIT
} CanSM_Internal_InitStatusType;
typedef struct {
boolean initialNoComRun;
uint16 busoffCounter; /* Need uint16 since we need to check if greater than configured value in ASR 4.0.2*/
boolean busoffevent;
uint32 subStateTimer;
uint32 busoffTime;
ComM_ModeType requestedMode;
ComM_ModeType currentMode;
CanSM_Internal_BsmStateType BsmState;
CanSM_Internal_PreNoCommStateType PreNoCommState;
CanSM_Internal_PreFullCommStateType PreFullCommState;
CanSM_Internal_FullCommStateType FullCommState;
uint8 RepeatCounter;
boolean requestAccepted;
#if (CANSM_CAN_TRCV_SUPPORT == STD_ON)
CanSM_Internal_TrcvStatusType TransceiverModeBuf;
#endif
} CanSM_Internal_NetworkType;
typedef struct {
CanSM_Internal_InitStatusType InitStatus;
CanSM_Internal_NetworkType* Networks;
CanSM_Internal_CtrlStatusType* ControllerModeBuf;
} CanSM_InternalType;
typedef enum {
//PreNoCom
T_CC_STOPPED_CC_SLEEP = 0,
#if (CANSM_CAN_TRCV_SUPPORT == STD_ON)
T_CC_SLEEP_TRCV_NORMAL,
T_TRCV_NORMAL_TRCV_STANDBY,
T_TRCV_STANDBY_NONE,
T_TRCV_NORMAL_CC_STOPPED,
T_PN_CLEAR_WUF_CC_STOPPED,
T_CC_STOPPED_TRCV_NORMAL,
T_TRCV_STANDBY_CC_SLEEP,
T_CC_SLEEP_CHECK_WUF_IN_CC_SLEEP,
T_CHECK_WUF_IN_CC_SLEEP_NONE,
T_CHECK_WUF_IN_NOT_CC_SLEEP_PN_CLEAR_WUF,
#endif
T_CC_SLEEP_NONE,
T_CC_STOPPED_CC_STARTED,
T_CC_STARTED_NONE, /*NOTE: This must be last!*/
T_NOF_TRANSITIONS
}CanSM_Internal_TransitionType;
typedef enum {
T_REQ_ACCEPTED = 0,
T_WAIT_INDICATION,
T_FAIL,
T_DONE,
T_REPEAT_MAX,
T_TIMEOUT
}CanSM_Internal_TransitionReturnType;
CanSM_Internal_TransitionReturnType CanSM_Internal_Execute(CanSM_Internal_NetworkType *Network, NetworkHandleType CanSMNetworkIndex, CanSM_Internal_TransitionType transition);
Std_ReturnType CanSM_Internal_GetCanSMCtrlIdx(const uint8 controller, uint8* indexPtr);
#if (CANSM_CAN_TRCV_SUPPORT == STD_ON)
CanSM_Internal_TransitionReturnType CanSM_Internal_DeinitWithPnSupport(NetworkHandleType CanSMNetworkIndex,CanSM_Internal_NetworkType *Network,CanSM_Internal_PreNoCommExitPointType *exitPoint,CanSM_Internal_PreNoCommStateType *nextSubState);
Std_ReturnType CanIfTrcvChnlToCanSMNwHdl(uint8 TransceiverId,NetworkHandleType *NetworkHandle);
Std_ReturnType CanSM_Internal_SetNetworkTransceiverMode(NetworkHandleType CanSMNetworkIndex, CanTrcv_TrcvModeType trcvMode);
Std_ReturnType CanSM_Internal_GetTrcvrModeInd(NetworkHandleType CanSMNetworkIndex);
Std_ReturnType CanSM_Internal_CheckWuf(NetworkHandleType CanSMNetworkIndex);
Std_ReturnType CanSM_Internal_ClearWuf(NetworkHandleType CanSMNetworkIndex);
Std_ReturnType CanSM_Internal_CheckWufInd(NetworkHandleType CanSMNetworkIndex);
Std_ReturnType CanSM_Internal_ClearWufInd(NetworkHandleType CanSMNetworkIndex);
#endif
CanSM_Internal_TransitionReturnType CanSM_Internal_DeinitWithoutPnSupport(NetworkHandleType CanSMNetworkIndex,CanSM_Internal_NetworkType *Network,CanSM_Internal_PreNoCommExitPointType *exitPoint,CanSM_Internal_PreNoCommStateType *nextSubState);
#endif /* CANSM_INTERNAL_H */
|
2301_81045437/classic-platform
|
communication/CanSM/src/CanSM_Internal.h
|
C
|
unknown
| 6,517
|
#CanTp
obj-$(USE_CANTP) += CanTp.o
pb-obj-$(USE_CANTP) += CanTp_PBCfg.o
pb-pc-file-$(USE_CANTP) += CanTp_Cfg.h
vpath-$(USE_CANTP) += $(ROOTDIR)/communication/CanTp/src
inc-$(USE_CANTP) += $(ROOTDIR)/communication/CanTp/inc
|
2301_81045437/classic-platform
|
communication/CanTp/CanTp.mod.mk
|
Makefile
|
unknown
| 229
|
/*-------------------------------- 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 -----------------------------*/
/** @req CANTP157 */
#ifndef CANTP_H_
#define CANTP_H_
#define CANTP_MODULE_ID 35u /** @req CANTP115 */
#define CANTP_VENDOR_ID 60u
/** @req CANTP024 */
/** @req CANTP266 */
#define CANTP_SW_MAJOR_VERSION 2
#define CANTP_SW_MINOR_VERSION 0
#define CANTP_SW_PATCH_VERSION 0
#define CANTP_AR_RELEASE_MAJOR_VERSION 4
#define CANTP_AR_RELEASE_MINOR_VERSION 0
#define CANTP_AR_RELEASE_PATCH_VERSION 3
#define CANTP_AR_MAJOR_VERSION CANTP_AR_RELEASE_MAJOR_VERSION
#define CANTP_AR_MINOR_VERSION CANTP_AR_RELEASE_MINOR_VERSION
#define CANTP_AR_PATCH_VERSION CANTP_AR_RELEASE_PATCH_VERSION
#include "ComStack_Types.h" /** @req CANTP209 */ /** @req CANTP264.partially */
#include "Std_Types.h" /** @req CANTP209 */
#include "CanTp_Cfg.h" /** @req CANTP221 */
/*
*
* Errors described by CanTp 7.4 Error classification.
*
****************************/
/** @req CANTP101 */
#define CANTP_E_PARAM_CONFIG 0x01u
#define CANTP_E_PARAM_ID 0x02u
#define CANTP_E_PARAM_POINTER 0x03u
#define CANTP_E_PARAM_ADDRESS 0x04u
#define CANTP_E_UNINIT 0x20u
#define CANTP_E_INVALID_TX_ID 0x30u
#define CANTP_E_INVALID_RX_ID 0x40u
#define CANTP_E_INVALID_TX_BUFFER 0x50u
#define CANTP_E_INVALID_RX_BUFFER 0x60u
#define CANTP_E_INVALID_TX_LENGHT 0x70u
#define CANTP_E_INVALID_RX_LENGTH 0x80u
#define CANTP_E_INVALID_TATYPE 0x90u
#define CANTP_E_OPER_NOT_SUPPORTED 0xA0u
#define CANTP_E_COM 0xB0u
#define CANTP_E_RX_COM 0xC0u
#define CANTP_E_TX_COM 0xD0u
/*
* Service IDs for CanTP function definitions.
*/
#define SERVICE_ID_CANTP_INIT 0x01u
#define SERVICE_ID_CANTP_GET_VERSION_INFO 0x07u
#define SERVICE_ID_CANTP_SHUTDOWN 0x02u
#define SERVICE_ID_CANTP_TRANSMIT 0x03u
#define SERVICE_ID_CANTP_CANCEL_TRANSMIT_REQUEST 0x03u
#define SERVICE_ID_CANTP_MAIN_FUNCTION 0x06u
#define SERVICE_ID_CANTP_RX_INDICATION 0x04u
#define SERVICE_ID_CANTP_TX_CONFIRMATION 0x05u
/*
* Structs
****************************/
typedef enum {
FRTP_CNLDO,
FRTP_CNLNB,
FRTP_CNLOR
} FrTp_CancelReasonType;
/*
* Implemented functions
****************************/
void CanTp_Init(const CanTp_ConfigType* CfgPtr); /** @req CANTP208 **/
#if ( CANTP_VERSION_INFO_API == STD_ON ) /** @req CANTP162 *//** @req CANTP163 */ /** @req CANTP267 */ /** @req CANTP297 */
#define CanTp_GetVersionInfo(_vi) STD_GET_VERSION_INFO(_vi,CANTP) /** @req CANTP210 */ /* @req CANTP218 */ /** @req CANTP308 */
#endif /* CANTP_VERSION_INFO_API */
void CanTp_Shutdown(void); /** @req CANTP211 */
Std_ReturnType CanTp_Transmit( PduIdType CanTpTxSduId, const PduInfoType * CanTpTxInfoPtr ); /** @req CANTP212 */
void CanTp_MainFunction(void); /** @req CANTP213 */
#endif /* CANTP_H_ */
|
2301_81045437/classic-platform
|
communication/CanTp/inc/CanTp.h
|
C
|
unknown
| 3,940
|
/*-------------------------------- 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 CANTP_CBK_H_
#define CANTP_CBK_H_
#include "ComStack_Types.h"
#include "CanTp_PBCfg.h"
void CanTp_RxIndication( PduIdType CanTpRxPduId, PduInfoType *CanTpRxPduPtr ); /** @req CANTP214 */
void CanTp_TxConfirmation( PduIdType CanTpTxPduId ); /** @req CANTP215 */
#endif /* CANTP_CBK_H_ */
|
2301_81045437/classic-platform
|
communication/CanTp/inc/CanTp_Cbk.h
|
C
|
unknown
| 1,073
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/*
* General requirements
*/
/** @req CANTP160 */
/*
* Definitions generated by tools
*/
//lint -save -e451 //PC-Lint Wrong interpretation, "Platform_Types.h included twice without a standard include guard."
#ifndef CANTP_TYPES_H_
#define CANTP_TYPES_H_
#include "Platform_Types.h"
#include "ComStack_Types.h"
// - - - - - - - - - - -
typedef enum {
CANTP_NOT_LAST_ENTRY, CANTP_END_OF_LIST
} CanTp_ListItemType;
typedef enum {
CANTP_EXTENDED, CANTP_STANDARD
} CanTp_AddressingFormantType;
typedef enum {
CANTP_OFF, CANTP_ON
} CanTp_StateType;
typedef enum {
CANTP_RX_WAIT,
CANTP_RX_PROCESSING,
CANTP_TX_WAIT,
CANTP_TX_PROCESSING
} CanTp_TransferInstanceMode;
typedef enum {
CANTP_FUNCTIONAL, CANTP_PHYSICAL
} CanTp_TaTypeType;
typedef struct {
const uint32 CanTpNSa;
} CanTp_NSaType;
typedef struct {
const uint32 CanTpNTa; /* IMPROVEMENT Why is this 32-bit, can it be lowered */
} CanTp_NTaType;
typedef struct {
const uint32 CanTpRxNPduId;
const uint32 CanTpRxNPduRef;
} CanTp_RxNPduType;
typedef struct {
const uint32 CanTpTxNPduId; /* NOTE: Remove this? */
const uint32 CanTpTxNPduRef;
} CanTp_TxNPduType;
typedef struct {
const uint32 CanTpTxFcNPduRef; /* Reference to a PDU in the COM stack. */
} CanTp_TxFcNPduType;
typedef struct {
const uint32 CanTpRxFcNPduRef; /* Reference to a PDU in the COM stack. */
const uint32 CanTpRxFcNPduId;
} CanTp_RxFcNPduType;
typedef struct {
const PduIdType CanTp_FcPduId; // When recieving this Pdu this conf can be used (if TA match in extended).
const PduIdType CanIf_FcPduId; // The polite CanIf PDU index.
const PduIdType PduR_PduId; // The polite PduR index.
const CanTp_AddressingFormantType CanTpAddressingFormant;
const uint8 CanTpBs; /* Sets the maximum number of messages of N-PDUs before flow control. */
const uint16 CanTpNar; /* Timeout for transmission of a CAN frame (ms). */
const uint16 CanTpNbr;
const uint16 CanTpNcr; /* Time out for consecutive frames (ms). */
const uint8 CanTpRxChannel; /* Connection to runtime variable index, see CanTp 266. */
const uint16 CanTpRxDI; /* Data length code for of this RxNsdu. */
const CanTp_StateType CanTpRxPaddingActivation; /* Enable use of padding. */
const CanTp_TaTypeType CanTpRxTaType; /* Functional or physical addressing. */
const uint8 CanTpWftMax; /* Max number FC wait that can be transmitted consecutively. */
const uint16 CanTpSTmin; /* Minimum time the sender shall wait between transmissions of two N-PDU. */
/*const uint32 CanTpNSduRef ** req: CanTp241. This is PDU id - typeless enum. */
const CanTp_NSaType *CanTpNSa;
const CanTp_NTaType *CanTpNTa;
//CanTp_RxNPduType *CanTpRxNPdu;
//CanTp_TxFcNPduType *CanTpTxFcNPdu;
//const PduIdType CanTpRxPduId;
} CanTp_RxNSduType;
typedef struct {
const PduIdType CanIf_PduId; // The polite CanIf index.
const PduIdType PduR_PduId; // The polite PduR index.
const PduIdType CanTp_FcPduId;
const PduLengthType CanTpNPduLen; //Length of TxNPdu
const CanTp_AddressingFormantType CanTpAddressingMode;
const uint16 CanTpNas; /* N_As timeout for transmission of any CAN frame. */
const uint16 CanTpNbs; /* N_Bs timeout of transmission until reception of next Flow Control. */
const uint16 CanTpNcs; /* N_Bs timeout of transmission until reception of next Flow Control. */
const uint8 CanTpTxChannel; /* Link to the TX connection channel (why?). */
const uint16 CanTpTxDI; /* Data length code for of this TxNsdu. */
/*const uint32 CanTpTxNSduId; / ** req: CanTp268: Data length code for of this TxNsdu. */
const CanTp_StateType CanTpTxPaddingActivation; /* Enable use of padding. */
const CanTp_TaTypeType CanTpTxTaType; /* Functional or physical addressing. */
/*const uint32 CanTpNSduRef ** req: CanTp261. This is PDU id - typeless enum. */
const CanTp_NSaType *CanTpNSa;
const CanTp_NTaType *CanTpNTa;
//CanTp_RxFcNPduType *CanTpRxFcNPdu;
//CanTp_TxNPduType *CanTpTxNPdu;
//PduIdType CanTpTxPduId;
} CanTp_TxNSduType;
// - - - - - - - - - - -
typedef struct {
const uint32 main_function_period;
const uint32 number_of_sdus;
const uint32 number_of_pdus;
const uint32 pdu_list_size;
const uint8 padding;
} CanTp_GeneralType;
// - - - - - - - - - - -
typedef enum {
IS015765_TRANSMIT, ISO15765_RECEIVE
} CanTp_DirectionType;
// - - - - - - - - - - -
typedef struct {
const CanTp_DirectionType direction;
const CanTp_ListItemType listItemType;
union {
const CanTp_RxNSduType CanTpRxNSdu;
const CanTp_TxNSduType CanTpTxNSdu;
} configData;
const boolean CanTpFDSupport;
} CanTp_NSduType;
typedef struct {
const CanTp_AddressingFormantType CanTpAddressingMode;
const PduIdType CanTpNSduIndex;
const PduIdType CanTpReferringTxIndex;
const PduIdType CanTpPduId;
} CanTp_RxIdType;
// - - - - - - - - - - -
/** Top level config container for CANTP implementation. */
typedef struct {
/** General configuration paramters for the CANTP module. */
const CanTp_GeneralType *CanTpGeneral; // 10.2.3
/** */
const CanTp_NSduType *CanTpNSduList;
const CanTp_RxIdType *CanTpRxIdList;
/** */
//const CanTp_RxNSduType *CanTpRxNSduList;
/** This container contains the init parameters of the CAN Interface. */
//const CanTp_TxNSduType *CanTpTxNSduList;
} CanTp_ConfigType;
#endif /* CANTP_TYPES_H_ */
|
2301_81045437/classic-platform
|
communication/CanTp/inc/CanTp_Types.h
|
C
|
unknown
| 6,500
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/*
* General requirements
*/
/** @req CANTP133 *//* The detection of production code errors cannot be switched off */
/** @req CANTP289 *//* The number of connection channels is not directly configurable*/
/** @req CANTP288 *//* If a connection channel is assigned to multiple N-SDUs, then resources are shared between different N-SDUs*/
/** @req CANTP287 *//* The CanTp module does not allow for the receiving or the transmission of N-SDU with the same identifier in parallel*/
/** @req CANTP286 *//* All the necessary information (Channel number, Timing parameter etc) is configured inside the CAN Transport Layer module*/
/** @req CANTP285 *//* The connection channels are only destined for CAN TP internal use, so they are not accessible externally*/
/** @req CANTP327 *//* Not applicable requirements*/
/** @req CANTP307 *//* The CanTp module shall perform Inter Module Checks to avoid integration of incompatible files.*/
/** @req CANTP296 *//* The CanTp module shall ensure that implementation-specific types are not "visible" outside of CanTp*/
/** @req CANTP265 *//* Global data types and functions that are only used internally by the CAN Transport Protocol, are given in CanTp.c*/
/** @req CANTP249 *//* Each variable that shall be accessible by AUTOSAR Debugging, shall be defined as global variable*/
/** @req CANTP250 *//* All type definitions of variables that shall be debugged shall be accessible by the header file CanTp.h*/
/** @req CANTP251 *//* The declaration of variables in the header file shall be such, that it is possible to calculate the size of the variables by C-"sizeof"*/
/** @req CANTP252 *//* Variables available for debugging shall be described in the CanTp Software Module Description*/
/** @req CANTP248 *//* A Tx N-PDU Id shall not be used on two or more different connection channels. An Rx N-PDU Id can only be used on two or more different connection channels*/
/** @req CANTP001 *//* CanTp_Cfg.h shall define constant and customizable data for module configuration at pre-compile time*/
/** @req CANTP002 *//* The CanTp module shall label user implemented types as CanTp_<TypeName>Type*/
/** @req CANTP008 *//* On errors and exceptions, the CanTp module shall not modify its current module state*/
/** @req CANTP156.Partially */
/** @req CANTP150 *//* The CanTp module's source (as long as it is written in C) shall conform to the HIS subset of the MISRA C Standard*/
/** @req CANTP151 *//* The CanTp module’s source shall not use compiler and platform specific keywords*/
/** @req CANTP152 *//* The CanTp module’s source shall indicate all global data with read-only properties by explicitly assigning the keyword const*/
/** @req CANTP153 *//* The CanTp module may use macros (instead of functions) where source code is used and runtime is critical*/
/** @req CANTP155 *//* The CanTp module shall not define global data in header files*/
/** @req CANTP158 *//* The CanTp module’s source shall not be processor and compiler dependent*/
/** @req CANTP003 *//* The API Naming convention for the CanTp services is CanTp_<ServiceName>*/
/** @req CANTP216 *//* Mandatory Interfaces*/
/** @req CANTP217 *//* Optional Interfaces*/
/*
* Environmental requirements
*/
/** @req CANTP164 */
/** @req CANTP199 */
#include "CanTp.h" /** @req CANTP219 */
#include "CanTp_Cbk.h" /** @req CANTP233 */
#include "Det.h"
#include "CanIf.h"
#include "SchM_CanTp.h"
#include "PduR_CanTp.h"
//#include "MemMap.h"
#include <string.h>
//#define USE_DEBUG_PRINTF
#include "debug.h"
/*lint -emacro(904,VALIDATE,VALIDATE_NO_RV,DET_REPORTERROR)*/ /*904 PC-Lint exception to MISRA 14.7 (validate DET macros)*/
#if ( CANTP_DEV_ERROR_DETECT == STD_ON ) /** @req CANTP006 *//** @req CANTP134 */
/** @req CANTP132 */ /** @req CANTP021 */ /** @req CANTP294 */
#define VALIDATE(_exp,_api,_err ) \
if( !(_exp) ) { \
(void)Det_ReportError(CANTP_MODULE_ID, 0, _api, _err); \
return E_NOT_OK; \
}
/** @req CANTP132 */ /** @req CANTP021 */
#define VALIDATE_NO_RV(_exp,_api,_err ) \
if( !(_exp) ) { \
(void)Det_ReportError(CANTP_MODULE_ID, 0, _api, _err); \
return; \
}
#define DET_REPORTERROR(_api, _error) \
do { \
(void)Det_ReportError(CANTP_MODULE_ID, 0, _api, _error); \
} while(0)
#else
#define VALIDATE(_exp,_api,_err )
#define VALIDATE_NO_RV(_exp,_api,_err )
#define DET_REPORTERROR(_api,_err)
#endif
#define TIMER_DECREMENT(timer) \
if (timer > 0) { \
timer = timer - 1; \
} \
#define COUNT_DECREMENT(timer) \
if (timer > 0) { \
timer = timer - 1; \
} \
/** @req CANTP033 */
#define CANTP_ERR -1
#define ISO15765_FLOW_CONTROL_STATUS_CTS 0
#define ISO15765_FLOW_CONTROL_STATUS_WAIT 1
#define ISO15765_FLOW_CONTROL_STATUS_OVFLW 2
// - - - - - - - - - - - - - -
#define ISO15765_TPCI_MASK 0x30
#define ISO15765_TPCI_SF 0x00 /* Single Frame */
#define ISO15765_TPCI_FF 0x10 /* First Frame */
#define ISO15765_TPCI_CF 0x20 /* Consecutive Frame */
#define ISO15765_TPCI_FC 0x30 /* Flow Control */
#define ISO15765_TPCI_DL 0xF
#define ISO15765_TPCI_DL_FD 0xFF/* Single frame data length mask */
#define ISO15765_TPCI_FS_MASK 0x0F /* Flowcontrol status mask */
// - - - - - - - - - - - - - -
#define CANFD_FIRST_BYTE_ZERO 0
#define MAX_PAYLOAD_SF_STD_ADDR 7
#define MAX_PAYLOAD_SF_EXT_ADDR 6
#define MAX_PAYLOAD_FF_STD_ADDR 6
#define MAX_PAYLOAD_FF_EXT_ADDR 5
#define MX_PAYLOAD_FF_STD_ADDR_FD_SUPPORT 62
#define MX_PAYLOAD_FF_EXT_ADDR_FD_SUPPORT 61
#define MAX_PAYLOAD_CF_STD_ADDR 7
#define MAX_PAYLOAD_CF_EXT_ADDR 6
#define SEGMENT_NUMBER_MASK 0x0f
#define MAX_SEGMENT_DATA_SIZE 8u // Size of a CAN frame data bytes.
#define MAX_FD_SEGMENT_DATA_SIZE 64u //CanFD data bytes
#define CANTP_TX_CHANNEL 0
#define CANTP_RX_CHANNEL 1
#define CANTP_NO_SIMPLEX_CHANNEL 2
#define INVALID_PDU_ID 0xFFFF
#define MAX_SF_DL_EXTENDADDR 6 // Maximum number of User bytes in a SF for Extended addressing
#define MAX_SF_DL_STDADDR 7 // Maximum number of User bytes in a SF for Standard addressing
#define MAX_SF_DL_STDADDR_FD_SUPPORT 62 // Maximum number of User bytes in a SF for Standard addressing
#define MAX_SF_DL_EXTENDADDR_FD_SUPPORT 61 // Maximum number of User bytes in a SF for Extended addressing
/*
*
*/
typedef enum {
UNINITIALIZED, IDLE, SF_OR_FF_RECEIVED_WAITING_PDUR_BUFFER, /** @req CANTP079 */
RX_WAIT_CONSECUTIVE_FRAME, RX_WAIT_SF_SDU_BUFFER, RX_WAIT_CF_SDU_BUFFER,
TX_WAIT_STMIN,
TX_WAIT_TRANSMIT, TX_WAIT_FLOW_CONTROL,
TX_WAIT_TX_CONFIRMATION
} ISO15765TransferStateTypes;
typedef enum {
INVALID_FRAME, /* Not specified by ISO15765 - used as error return type when decoding frame. */
SINGLE_FRAME,
FIRST_FRAME,
CONSECUTIVE_FRAME,
FLOW_CONTROL_FRAME
} ISO15765FrameType;
/*
* In case no buffer is available at some cases the data needs to be
* temporarily stored away.
*/
typedef struct {
#if (CANTP_CANFD_SUPPORT == STD_OFF)
uint8 data[MAX_SEGMENT_DATA_SIZE];
#else
uint8 data[MAX_FD_SEGMENT_DATA_SIZE];
#endif
PduLengthType byteCount;
} CanIfSduType;
/*
* Structure that is keeping track on the run-time variables for the ongoing
* transfer.
*/
typedef struct {
uint16 nextFlowControlCount; // Count down to next Flow Control.
uint16 framesHandledCount; // Counter keeping track total frames handled.
uint32 stateTimeoutCount; // Counter for timeout.
uint8 extendedAddress; // Not always used but need to be available.
uint8 STmin; // In case we are transmitters the remote node can configure this value (only valid for TX).
uint8 BS; // Blocksize (only valid for TX).
boolean NasNarPending;
uint32 NasNarTimeoutCount; // CanTpNas, CanTpNar.
ISO15765TransferStateTypes state; // Transfer state machine.
} ISO15765TransferControlType;
/*
* Container for TX or RX runtime paramters (TX/RX are identical?)
*/
typedef struct {
ISO15765TransferControlType iso15765;
PduLengthType transferTotal; // Total length of the PDU.
PduLengthType transferCount; // Counter ongoing transfer.
PduLengthType sizeBuffer;
CanIfSduType canFrameBuffer; // Temp storage of SDU data.
CanTp_TransferInstanceMode mode; // CanTp030.
uint16 CanTpWftMaxCounter;
PduIdType pduId;
boolean CanfdSupport;
} CanTp_SimplexChannelPrivateType;
typedef struct {
CanTp_SimplexChannelPrivateType SimplexChnlList[CANTP_NO_SIMPLEX_CHANNEL]; //one for RX and one for TX
CanTp_SimplexChannelPrivateType functionalChnl; //For functional frame reception
}CanTp_ChannelPrivateType;
// - - - - - - - - - - - - - -
typedef struct {
boolean initRun;
CanTp_StateType internalState; /** @req CANTP027 */
CanTp_ChannelPrivateType runtimeDataList[CANTP_MAX_NO_CHANNELS];
} CanTp_RunTimeDataType;
// - - - - - - - - - - - - - -
CanTp_RunTimeDataType CanTpRunTimeData = { .initRun = FALSE,
.internalState = CANTP_OFF }; /** @req CANTP168 */
/* Global configure */
static const CanTp_ConfigType *CanTp_ConfigPtr = NULL;
// - - - - - - - - - - - - - -
static uint32 ConvertMsToMainCycles(uint32 ms) {
return (ms/CanTp_ConfigPtr->CanTpGeneral->main_function_period);
}
/**
* Returns the frame type of the ISO115765 message
* @param formatType
* @param CanTpRxPduPtr
* @return frame type
*/
static ISO15765FrameType getFrameType( const CanTp_AddressingFormantType *formatType, const PduInfoType *CanTpRxPduPtr) {
ISO15765FrameType res = INVALID_FRAME;
uint8 tpci = 0;
boolean validFrameType = TRUE;
switch (*formatType) {
case CANTP_STANDARD:
DEBUG( DEBUG_MEDIUM, "CANTP_STANDARD\n");
tpci = CanTpRxPduPtr->SduDataPtr[0];
break;
case CANTP_EXTENDED:
DEBUG( DEBUG_MEDIUM, "CANTP_EXTENDED\n");
tpci = CanTpRxPduPtr->SduDataPtr[1];
break;
default:
validFrameType = FALSE;
break;
}
if (validFrameType) {
switch (tpci & ISO15765_TPCI_MASK) {
case ISO15765_TPCI_SF:
res = SINGLE_FRAME;
break;
case ISO15765_TPCI_FF:
res = FIRST_FRAME;
break;
case ISO15765_TPCI_CF:
res = CONSECUTIVE_FRAME;
break;
case ISO15765_TPCI_FC: // Some kind of flow control.
res = FLOW_CONTROL_FRAME;
break;
default:
break;
}
}
return res;
}
// - - - - - - - - - - - - - -
static PduLengthType getPduLength(
const CanTp_AddressingFormantType *formatType,
const ISO15765FrameType iso15765Frame, const PduInfoType *CanTpRxPduPtr) {
PduLengthType res = 0;
boolean status;
status = TRUE;
uint8 tpci_offset = 0;
switch (*formatType) {
case CANTP_STANDARD:
tpci_offset = 0;
break;
case CANTP_EXTENDED:
tpci_offset = 1;
break;
default:
res = 0;
status = FALSE;
}
if (status == TRUE) {
switch (iso15765Frame) {
case SINGLE_FRAME:
// Parse the data length from the single frame header.
if(CanTpRxPduPtr->SduLength > MAX_SEGMENT_DATA_SIZE){
/*First byte of CAN FD single frame is zero, hence PCI(SF_DL i.e Data length is taken from second byte)*/
res = CanTpRxPduPtr->SduDataPtr[tpci_offset+1] & ISO15765_TPCI_DL_FD;
}else{
res = CanTpRxPduPtr->SduDataPtr[tpci_offset] & ISO15765_TPCI_DL;
}
break;
case FIRST_FRAME:
// Parse the data length form the first frame.
res = CanTpRxPduPtr->SduDataPtr[tpci_offset + 1] + ((PduLengthType)((CanTpRxPduPtr->SduDataPtr[tpci_offset]) & 0xf) << 8);
break;
default:
res = 0; // IMPROVEMENT: Add Det error
break;
}
}
return res;
}
// - - - - - - - - - - - - - -
static void initRx15765RuntimeData(CanTp_SimplexChannelPrivateType *rxRuntimeParams) {
rxRuntimeParams->iso15765.state = IDLE;
rxRuntimeParams->iso15765.NasNarPending = FALSE;
rxRuntimeParams->iso15765.framesHandledCount = 0;
rxRuntimeParams->iso15765.nextFlowControlCount = 0;
rxRuntimeParams->transferTotal = 0;
rxRuntimeParams->transferCount = 0;
rxRuntimeParams->sizeBuffer = 0;
rxRuntimeParams->CanTpWftMaxCounter = 0;
rxRuntimeParams->mode = CANTP_RX_WAIT; /** @req CANTP030 */
rxRuntimeParams->pduId = INVALID_PDU_ID;
}
// - - - - - - - - - - - - - -
static void initTx15765RuntimeData(CanTp_SimplexChannelPrivateType *txRuntimeParams) {
txRuntimeParams->iso15765.state = IDLE;
txRuntimeParams->iso15765.NasNarPending = FALSE;
txRuntimeParams->iso15765.framesHandledCount = 0;
txRuntimeParams->iso15765.nextFlowControlCount = 0;
txRuntimeParams->transferTotal = 0;
txRuntimeParams->transferCount = 0;
txRuntimeParams->sizeBuffer = 0;
txRuntimeParams->mode = CANTP_TX_WAIT; /** @req CANTP030 */
txRuntimeParams->pduId = INVALID_PDU_ID;
}
// - - - - - - - - - - - - - -
static BufReq_ReturnType copySegmentToPduRRxBuffer(const CanTp_RxNSduType *rxConfig,
CanTp_SimplexChannelPrivateType *rxRuntime, uint8 *segment,
PduLengthType segmentSize, PduLengthType *bytesWrittenSuccessfully) {
BufReq_ReturnType ret;
static PduInfoType tempPdu;
*bytesWrittenSuccessfully = 0;
/* when not a consectuive frame we have to begin a new buffer */
if (rxRuntime->iso15765.state != RX_WAIT_CONSECUTIVE_FRAME)
{
ret = PduR_CanTpStartOfReception(rxConfig->PduR_PduId, rxRuntime->transferTotal, &rxRuntime->sizeBuffer); /** @req CANTP079 */
/* ok buffer is now locked for us */
/* until PduR_CanTpTxConfirmation or PduR_CanTpRxIndication arises */
}
else
{
/** @req CANTP270 */
/* ask how many free space is left */
tempPdu.SduLength = 0;
tempPdu.SduDataPtr = NULL_PTR;
ret = PduR_CanTpCopyRxData(rxConfig->PduR_PduId, &tempPdu, &rxRuntime->sizeBuffer);
}
if (ret == BUFREQ_OK)
{
tempPdu.SduDataPtr = segment;
if (segmentSize <= rxRuntime->sizeBuffer) /** @req CANTP080 */
{
/* everything is ok - we can go on */
tempPdu.SduLength = segmentSize;
ret = PduR_CanTpCopyRxData(rxConfig->PduR_PduId, &tempPdu, &rxRuntime->sizeBuffer);
}
else
{
/* currently there is not enough space available */
ret = BUFREQ_E_BUSY;
}
/* when everything is fine we can adjust our "global" variables and end */
if (ret == BUFREQ_OK)
{
*bytesWrittenSuccessfully = tempPdu.SduLength;
rxRuntime->transferCount += tempPdu.SduLength;
}
}
return ret;
}
// - - - - - - - - - - - - - -
static boolean copySegmentToLocalRxBuffer /*writeDataSegmentToLocalBuffer*/(
CanTp_SimplexChannelPrivateType *rxRuntime, uint8 *segment,
PduLengthType segmentSize) {
uint8 maxSegSize;
boolean ret = FALSE;
if(rxRuntime->CanfdSupport == TRUE){
maxSegSize = MAX_FD_SEGMENT_DATA_SIZE;
}else{
maxSegSize = MAX_SEGMENT_DATA_SIZE;
}
if ( segmentSize < maxSegSize ) {
for (int i=0; i < segmentSize; i++) {
rxRuntime->canFrameBuffer.data[i] = segment[i];
rxRuntime->canFrameBuffer.byteCount = segmentSize;
ret = TRUE;
}
}
return ret;
}
// - - - - - - - - - - - - - -
static Std_ReturnType canReceivePaddingHelper(
const CanTp_RxNSduType *rxConfig, CanTp_SimplexChannelPrivateType *rxRuntime,
PduInfoType *PduInfoPtr) {
if (rxConfig->CanTpRxPaddingActivation == CANTP_ON) {
for (uint8 i = PduInfoPtr->SduLength; i < MAX_SEGMENT_DATA_SIZE; i++) {
PduInfoPtr->SduDataPtr[i] = CanTp_ConfigPtr->CanTpGeneral->padding;
}
}
PduInfoPtr->SduLength = MAX_SEGMENT_DATA_SIZE; //FC length is always expected to be 8B
rxRuntime->iso15765.NasNarTimeoutCount = rxConfig->CanTpNar; /** @req CANTP075 */
rxRuntime->iso15765.NasNarPending = TRUE;
return CanIf_Transmit(rxConfig->CanIf_FcPduId, PduInfoPtr);
}
// - - - - - - - - - - - - - -
static Std_ReturnType canTansmitPaddingHelper(
const CanTp_TxNSduType *txConfig, CanTp_SimplexChannelPrivateType *txRuntime,
PduInfoType *PduInfoPtr) {
/** @req CANTP114 */
/** @req CANTP040 */
/** @req CANTP098 */
/** @req CANTP116 */
/** @req CANTP059 */
if (txConfig->CanTpTxPaddingActivation == CANTP_ON) { /** @req CANTP225 */
for (int i = PduInfoPtr->SduLength; i < txConfig->CanTpNPduLen; i++) {
PduInfoPtr->SduDataPtr[i] = CanTp_ConfigPtr->CanTpGeneral->padding;
}
PduInfoPtr->SduLength = txConfig->CanTpNPduLen;
}
txRuntime->iso15765.NasNarTimeoutCount = txConfig->CanTpNas; /** @req CANTP075 */
txRuntime->iso15765.NasNarPending = TRUE;
return CanIf_Transmit(txConfig->CanIf_PduId, PduInfoPtr);
}
// - - - - - - - - - - - - - -
static void sendFlowControlFrame(const CanTp_RxNSduType *rxConfig, CanTp_SimplexChannelPrivateType *rxRuntime, BufReq_ReturnType flowStatus) {
uint8 indexCount = 0;
Std_ReturnType ret = E_NOT_OK;
PduInfoType pduInfo;
uint8 sduData[8]; // Note that buffer in declared on the stack.
uint16 computedBs = 0;
DEBUG( DEBUG_MEDIUM, "sendFlowControlFrame called!\n");
pduInfo.SduDataPtr = &sduData[0];
if (rxConfig->CanTpAddressingFormant == CANTP_EXTENDED) {
sduData[indexCount++] = rxRuntime->iso15765.extendedAddress;
}
switch (flowStatus) {
case BUFREQ_OK:
{
sduData[indexCount++] = ISO15765_TPCI_FC | ISO15765_FLOW_CONTROL_STATUS_CTS;
if (rxConfig->CanTpAddressingFormant == CANTP_EXTENDED) { /** @req CANTP094 *//** @req CANTP095 */
if(rxRuntime->CanfdSupport == TRUE){
computedBs = (rxRuntime->sizeBuffer / MX_PAYLOAD_FF_EXT_ADDR_FD_SUPPORT) + 1; // + 1 is for local buffer.
}else{
computedBs = (rxRuntime->sizeBuffer / MAX_PAYLOAD_SF_EXT_ADDR) + 1; // + 1 is for local buffer.
}
} else {
if(rxRuntime->CanfdSupport == TRUE){
computedBs = (rxRuntime->sizeBuffer / MX_PAYLOAD_FF_STD_ADDR_FD_SUPPORT) + 1; // + 1 is for local buffer.
}else{
computedBs = (rxRuntime->sizeBuffer / MAX_PAYLOAD_SF_STD_ADDR) + 1; // + 1 is for local buffer.
}
}
if (computedBs > rxConfig->CanTpBs) { // /** @req CANTP091 *//** @req CANTP084 */
computedBs = rxConfig->CanTpBs;
}
rxRuntime->iso15765.BS = rxConfig->CanTpBs;
DEBUG( DEBUG_MEDIUM, "computedBs:%d\n", computedBs);
sduData[indexCount++] = rxRuntime->iso15765.BS; /* @req CANTP067 */
sduData[indexCount++] = (uint8) rxConfig->CanTpSTmin;
rxRuntime->iso15765.nextFlowControlCount = computedBs;
pduInfo.SduLength = indexCount;
rxRuntime->CanTpWftMaxCounter = 0;
break;
}
case BUFREQ_E_NOT_OK:
break;
case BUFREQ_E_BUSY:
sduData[indexCount++] = ISO15765_TPCI_FC | ISO15765_FLOW_CONTROL_STATUS_WAIT;
indexCount +=2;
pduInfo.SduLength = indexCount;
rxRuntime->CanTpWftMaxCounter++;
break;
case BUFREQ_E_OVFL: /** @req CANTP318 Assuming 1-byte frame length */
sduData[indexCount++] = ISO15765_TPCI_FC | ISO15765_FLOW_CONTROL_STATUS_OVFLW;
indexCount +=2;
pduInfo.SduLength = indexCount;
break;
default:
break;
}
ret = canReceivePaddingHelper(rxConfig, rxRuntime, &pduInfo);
if (ret != E_OK) {
PduR_CanTpRxIndication(rxConfig->PduR_PduId, NTFRSLT_E_NOT_OK); /** @req CANTP084 */
rxRuntime->iso15765.state = IDLE;
rxRuntime->pduId = INVALID_PDU_ID;
rxRuntime->mode = CANTP_RX_WAIT;
}
}
/**
* Handles next consecutive frame
* @param rxConfig
* @param rxRuntime
* @param rxPduData
*/
static void handleConsecutiveFrame(const CanTp_RxNSduType *rxConfig,
CanTp_SimplexChannelPrivateType *rxRuntime, const PduInfoType *rxPduData) {
uint8 indexCount = 0;
uint8 segmentNumber = 0;
PduLengthType bytesLeftToCopy = 0;
PduLengthType bytesLeftToTransfer = 0;
PduLengthType currentSegmentSize = 0;
PduLengthType currentSegmentMaxSize = 0;
PduLengthType bytesCopiedToPdurRxBuffer = 0;
BufReq_ReturnType ret = BUFREQ_E_NOT_OK;
if (rxConfig->CanTpAddressingFormant == CANTP_EXTENDED)
{
uint8 extendedAddress = 0;
extendedAddress = rxPduData->SduDataPtr[indexCount++];
//Verfify the target address i.e. source adress
if (extendedAddress != rxConfig->CanTpNTa->CanTpNTa)
/*lint -e{904} Return statement is necessary to avoid multiple if loops and hence increase readability in case of argument check */
return;
}
if (rxRuntime->iso15765.state == RX_WAIT_CONSECUTIVE_FRAME) {
segmentNumber = rxPduData->SduDataPtr[indexCount++] & SEGMENT_NUMBER_MASK;
if (segmentNumber != (rxRuntime->iso15765.framesHandledCount & SEGMENT_NUMBER_MASK)) { /** @req CANTP314 */
DEBUG(DEBUG_MEDIUM,"Segmentation number error detected - is the sending"
"unit too fast? Increase STmin (cofig) to slow it down!\n");
PduR_CanTpRxIndication(rxConfig->PduR_PduId, NTFRSLT_E_WRONG_SN); /** @req CANTP084 */
rxRuntime->iso15765.state = IDLE;
rxRuntime->pduId = INVALID_PDU_ID;
rxRuntime->mode = CANTP_RX_WAIT;
} else {
currentSegmentMaxSize = rxPduData->SduLength - indexCount;
bytesLeftToCopy = rxRuntime->transferTotal - rxRuntime->transferCount;
if (bytesLeftToCopy < currentSegmentMaxSize) {
currentSegmentSize = bytesLeftToCopy; // 1-5.
} else {
currentSegmentSize = currentSegmentMaxSize; // 6 or 7, depends on addressing format used.
}
// Copy received data to buffer provided by SDUR.
ret = copySegmentToPduRRxBuffer(rxConfig, rxRuntime,
&rxPduData->SduDataPtr[indexCount],
currentSegmentSize,
&bytesCopiedToPdurRxBuffer); /** @req CANTP269 */
if (ret == BUFREQ_E_NOT_OK) {
PduR_CanTpRxIndication(rxConfig->PduR_PduId, NTFRSLT_E_NOT_OK); /** @req CANTP084 */
rxRuntime->iso15765.state = IDLE; /** @req CANTP271 */
rxRuntime->pduId = INVALID_PDU_ID;
rxRuntime->mode = CANTP_RX_WAIT;
} else if (ret == BUFREQ_E_BUSY) {
boolean status = FALSE;
status = (rxConfig->CanTpAddressingFormant == CANTP_STANDARD) ? (bytesLeftToCopy > 7 ) : (bytesLeftToCopy > 6 );
// Check whether this is the last CF in the block and a FC is to be sent
if ((rxRuntime->iso15765.nextFlowControlCount == 1) && (status))
{
boolean dataCopyFailure = FALSE;
PduLengthType bytesNotCopiedToPdurRxBuffer = currentSegmentSize - bytesCopiedToPdurRxBuffer;
if (rxConfig->CanTpAddressingFormant == CANTP_STANDARD) {
if ( copySegmentToLocalRxBuffer(rxRuntime,
&rxPduData->SduDataPtr[1 + bytesCopiedToPdurRxBuffer],
bytesNotCopiedToPdurRxBuffer ) != TRUE ) {
rxRuntime->iso15765.state = IDLE; /** @req CANTP271 */ /* this can be quite dangerous! imagine a concurrent reception (ok sender should wait some time..) - we set first to idle and then a few steps later to RX_WAIT_SDU_BUFFER => in the meantime a new firstframe could come in?!?! */
/* by the way - requirement 271 isn't correct!! when receiving busy we still have wait until WFT > the configured value */
rxRuntime->pduId = INVALID_PDU_ID;
rxRuntime->mode = CANTP_RX_WAIT;
dataCopyFailure = TRUE;
DEBUG( DEBUG_MEDIUM, "Unexpected error, could not copy 'unaligned leftover' " "data to local buffer!\n");
}
} else {
if ( copySegmentToLocalRxBuffer(rxRuntime,
&rxPduData->SduDataPtr[2 + bytesCopiedToPdurRxBuffer],
bytesNotCopiedToPdurRxBuffer) != TRUE ) {
rxRuntime->iso15765.state = IDLE; /** @req CANTP271 */ /* this can be quite dangerous! imagine a concurrent reception (ok sender should wait some time..) - we set first to idle and then a few steps later to RX_WAIT_SDU_BUFFER => in the meantime a new firstframe could come in?!?! */
/* by the way - requirement 271 isn't correct!! when receiving busy we still have wait until WFT > the configured value */
rxRuntime->pduId = INVALID_PDU_ID;
rxRuntime->mode = CANTP_RX_WAIT;
dataCopyFailure = TRUE;
DEBUG( DEBUG_MEDIUM, "Unexpected error, could not copy 'unaligned leftover' " "data to local buffer!\n");
}
}
if ( !dataCopyFailure ) {
rxRuntime->iso15765.framesHandledCount++;
rxRuntime->iso15765.stateTimeoutCount = (rxConfig->CanTpNbr) + 1;
rxRuntime->iso15765.state = RX_WAIT_CF_SDU_BUFFER;
rxRuntime->mode = CANTP_RX_PROCESSING;
sendFlowControlFrame(rxConfig, rxRuntime, ret); /** @req CANTP268 */
}
}
else
{
// Abort connection /** @req CANTP271 */
PduR_CanTpRxIndication(rxConfig->PduR_PduId, NTFRSLT_E_NOT_OK); /** @req CANTP084 */
rxRuntime->iso15765.state = IDLE; /** @req CANTP271 */
rxRuntime->pduId = INVALID_PDU_ID;
rxRuntime->mode = CANTP_RX_WAIT;
}
} else if (ret == BUFREQ_OK) {
bytesLeftToTransfer = rxRuntime->transferTotal - rxRuntime->transferCount;
if (bytesLeftToTransfer > 0) {
rxRuntime->iso15765.framesHandledCount++;
COUNT_DECREMENT(rxRuntime->iso15765.nextFlowControlCount);
if (rxRuntime->iso15765.nextFlowControlCount == 0 && rxRuntime->iso15765.BS > 0) {
sendFlowControlFrame(rxConfig, rxRuntime, BUFREQ_OK);
} else {
rxRuntime->iso15765.stateTimeoutCount = (rxConfig->CanTpNcr) + 1; //UH /** @req CANTP312 */
}
} else {
DEBUG( DEBUG_MEDIUM,"ISO15765-Rx session finished, going back to IDLE!\n");
rxRuntime->iso15765.state = IDLE;
rxRuntime->pduId = INVALID_PDU_ID;
rxRuntime->mode = CANTP_RX_WAIT;
PduR_CanTpRxIndication(rxConfig->PduR_PduId, NTFRSLT_OK); /** @req CANTP084 */
}
} else {
/* Do nothing */
}
}
}
}
/**
* Function for sending tx frame
* @param txConfig
* @param txRuntime
* @return
*/
static BufReq_ReturnType sendNextTxFrame(const CanTp_TxNSduType *txConfig,
CanTp_SimplexChannelPrivateType *txRuntime) {
uint8 maxDataSize;
BufReq_ReturnType ret = BUFREQ_OK;
PduInfoType pduInfo;
uint8 offset = txRuntime->canFrameBuffer.byteCount;
pduInfo.SduDataPtr = &txRuntime->canFrameBuffer.data[offset];
if(txRuntime->CanfdSupport == TRUE){
maxDataSize = txConfig->CanTpNPduLen;
}else{
maxDataSize = MAX_SEGMENT_DATA_SIZE;
}
if( (txRuntime->transferTotal - txRuntime->transferCount) > (maxDataSize - offset) ) {
pduInfo.SduLength = maxDataSize - offset;
} else {
pduInfo.SduLength = txRuntime->transferTotal - txRuntime->transferCount;
}
ret = PduR_CanTpCopyTxData(txConfig->PduR_PduId, &pduInfo, NULL_PTR, &txRuntime->sizeBuffer); /** @req CANTP272 */ /** @req CANTP226 */ /** @req CANTP086 */
if(ret == BUFREQ_OK) {
txRuntime->canFrameBuffer.byteCount += pduInfo.SduLength; /* SduLength could have changed during transmit (when frame is smaller than MAX_SEGMENT_DATA_SIZE) */
txRuntime->transferCount += pduInfo.SduLength; /* SduLength could have changed during transmit (when frame is smaller than MAX_SEGMENT_DATA_SIZE) */
Std_ReturnType resp;
pduInfo.SduDataPtr = &txRuntime->canFrameBuffer.data[0];
pduInfo.SduLength += offset;
// change state to verify tx confirm within timeout
txRuntime->iso15765.stateTimeoutCount = (txConfig->CanTpNas) + 1;
txRuntime->iso15765.state = TX_WAIT_TX_CONFIRMATION;
resp = canTansmitPaddingHelper(txConfig, txRuntime, &pduInfo);
if(resp == E_OK) {
// sending done
} else {
// failed to send
ret = BUFREQ_E_NOT_OK;
}
}
return ret;
}
/**
* Function to called when a tx confirmation is received and handles the next frame
* to be sent
* @param txConfig
* @param txRuntime
*/
static void handleNextTxFrameSent(
const CanTp_TxNSduType *txConfig, CanTp_SimplexChannelPrivateType *txRuntime) {
txRuntime->iso15765.framesHandledCount++;
// prepare tx buffer for next frame
txRuntime->canFrameBuffer.byteCount = 1;
if (txConfig->CanTpAddressingMode == CANTP_EXTENDED) {
txRuntime->canFrameBuffer.byteCount++;
}
txRuntime->canFrameBuffer.data[txRuntime->canFrameBuffer.byteCount - 1] =
(txRuntime->iso15765.framesHandledCount & SEGMENT_NUMBER_MASK) + ISO15765_TPCI_CF;
COUNT_DECREMENT(txRuntime->iso15765.nextFlowControlCount);
if (txRuntime->transferTotal <= txRuntime->transferCount) {
// Transfer finished!
PduR_CanTpTxConfirmation(txConfig->PduR_PduId, NTFRSLT_OK); /** @req CANTP090 *//** @req CANTP204 */
txRuntime->iso15765.state = IDLE;
txRuntime->pduId = INVALID_PDU_ID;
txRuntime->mode = CANTP_TX_WAIT;
} else if (txRuntime->iso15765.nextFlowControlCount == 0 && txRuntime->iso15765.BS) {
// receiver expects flow control.
txRuntime->iso15765.stateTimeoutCount = (txConfig->CanTpNbs) + 1; /** @req CANTP315.partially */
txRuntime->iso15765.state = TX_WAIT_FLOW_CONTROL;
} else if (txRuntime->iso15765.STmin == 0) {
// Send next consecutive frame!
BufReq_ReturnType resp;
resp = sendNextTxFrame(txConfig, txRuntime);
if (resp == BUFREQ_OK ) {
// successfully sent frame, wait for tx confirm
} else if(BUFREQ_E_BUSY == resp) { /** @req CANTP184 */ /** @req CANTP279 */
// change state and setup timeout
txRuntime->iso15765.stateTimeoutCount = (txConfig->CanTpNcs) + 1;
txRuntime->iso15765.state = TX_WAIT_TRANSMIT;
} else {
PduR_CanTpTxConfirmation(txConfig->PduR_PduId, NTFRSLT_E_NOT_OK); /** @req CANTP177 */ /** @req CANTP087 */
txRuntime->iso15765.state = IDLE;
txRuntime->pduId = INVALID_PDU_ID;
txRuntime->mode = CANTP_TX_WAIT;
}
} else {
// Send next consecutive frame after stmin!
//ST MIN error handling ISO 15765-2 sec 7.6
if (txRuntime->iso15765.STmin < 0x80) {
txRuntime->iso15765.stateTimeoutCount = ConvertMsToMainCycles(txRuntime->iso15765.STmin) + 1;
} else if (txRuntime->iso15765.STmin > 0xF0 && txRuntime->iso15765.STmin < 0xFA) {
//txRuntime->iso15765.stateTimeoutCount = ConvertMsToMainCycles((txRuntime->iso15765.STmin - 0xF0)/10) + 1;
txRuntime->iso15765.stateTimeoutCount = 1; //This is hard coded to 1 main cycle since achieving 0.1ms task is difficult
}
else {
txRuntime->iso15765.stateTimeoutCount = ConvertMsToMainCycles(0x7F) + 1;
}
txRuntime->iso15765.state = TX_WAIT_STMIN;
}
}
/**
* Handles a flow control frame
* @param txConfig
* @param txRuntime
* @param txPduData
*/
static void handleFlowControlFrame(const CanTp_TxNSduType *txConfig,
CanTp_SimplexChannelPrivateType *txRuntime, const PduInfoType *txPduData) {
int indexCount = 0;
if (txConfig->CanTpAddressingMode == CANTP_EXTENDED)
{
/** @req CANTP094 *//** @req CANTP095 */
uint8 extendedAddress = 0;
extendedAddress = txPduData->SduDataPtr[indexCount++];
//Verfify the target address
if (extendedAddress != txConfig->CanTpNSa->CanTpNSa)
/*lint -e{904} Return statement is necessary to avoid multiple if loops and hence increase readability in case of argument check */
return;
}
if ( txRuntime->iso15765.state == TX_WAIT_FLOW_CONTROL )
{
switch (txPduData->SduDataPtr[indexCount++] & ISO15765_TPCI_FS_MASK)
{
case ISO15765_FLOW_CONTROL_STATUS_CTS:
#if 1
{ // This construction is added to make the hcs12 compiler happy.
const uint8 bs = txPduData->SduDataPtr[indexCount++];
txRuntime->iso15765.BS = bs;
txRuntime->iso15765.nextFlowControlCount = bs;
}
txRuntime->iso15765.STmin = txPduData->SduDataPtr[indexCount++]; /** @req CANTP282 */
#else
txRuntime->iso15765.BS = txPduData->SduDataPtr[indexCount++];
txRuntime->iso15765.nextFlowControlCount = txRuntime->iso15765.BS;
txRuntime->iso15765.STmin = txPduData->SduDataPtr[indexCount++];
#endif
DEBUG( DEBUG_MEDIUM, "txRuntime->iso15765.STmin = %d\n", txRuntime->iso15765.STmin);
// change state and setup timout
txRuntime->iso15765.stateTimeoutCount = (txConfig->CanTpNcs) + 1;
txRuntime->iso15765.state = TX_WAIT_TRANSMIT;
break;
case ISO15765_FLOW_CONTROL_STATUS_WAIT:
txRuntime->iso15765.stateTimeoutCount = (txConfig->CanTpNbs) + 1; /** @req CANTP315.partially */
txRuntime->iso15765.state = TX_WAIT_FLOW_CONTROL;
break;
case ISO15765_FLOW_CONTROL_STATUS_OVFLW:
PduR_CanTpTxConfirmation(txConfig->PduR_PduId, NTFRSLT_E_NO_BUFFER); /* @req ISO/FDIS 15765-2:2004(E) 7.5.5.2*/ /** @req CANTP309 */
txRuntime->iso15765.state = IDLE;
txRuntime->pduId = INVALID_PDU_ID;
txRuntime->mode = CANTP_TX_WAIT;
break;
default:
/* Abort transmission if invalid FS */
PduR_CanTpTxConfirmation(txConfig->PduR_PduId,NTFRSLT_E_INVALID_FS); /* @req ISO/FDIS 15765-2:2004(E) 7.5.5.3*/ /** @req CANTP317 */
txRuntime->iso15765.state = IDLE;
txRuntime->pduId = INVALID_PDU_ID;
txRuntime->mode = CANTP_TX_WAIT;
break;
}
} else {
DEBUG( DEBUG_MEDIUM, "Ignoring flow control, we do not expect it!");
}
}
/**
* Handles a single frame
* @param rxConfig
* @param rxRuntime
* @param rxPduData
* @param CanTpRxNSduId
*/
static void handleSingleFrame(const CanTp_RxNSduType *rxConfig,
CanTp_SimplexChannelPrivateType *rxRuntime, const PduInfoType *rxPduData, PduIdType CanTpRxNSduId) {
BufReq_ReturnType ret;
PduLengthType pduLength;
uint8 *data = NULL;
PduLengthType bytesWrittenToSduRBuffer;
boolean status;
status = TRUE;
pduLength = getPduLength(&rxConfig->CanTpAddressingFormant, SINGLE_FRAME, rxPduData);
if (rxConfig->CanTpAddressingFormant == CANTP_EXTENDED)
{
uint8 extendedAddress = 0;
extendedAddress = rxPduData->SduDataPtr[0];
//Verify the target address in the PDU is source address
//Verify user DL is less than 7 & not zero
if ((extendedAddress != rxConfig->CanTpNTa->CanTpNTa)||(pduLength > MAX_SF_DL_EXTENDADDR) || !(pduLength)) {
status = FALSE;
if ((rxRuntime->CanfdSupport == TRUE) && (pduLength <= MAX_SF_DL_EXTENDADDR_FD_SUPPORT)){
status = TRUE;
}
}
} else if ((pduLength > MAX_SF_DL_STDADDR) || (!(pduLength))){ //Verify user DL is less than 8 & not zero
status = FALSE;
if ((rxRuntime->CanfdSupport == TRUE) && (pduLength <= MAX_SF_DL_STDADDR_FD_SUPPORT)){
status = TRUE;
}
}
if (status == TRUE) {
if ((rxRuntime->iso15765.state != IDLE) && (rxRuntime->iso15765.state != RX_WAIT_CF_SDU_BUFFER) &&
(rxRuntime->iso15765.state != RX_WAIT_SF_SDU_BUFFER)){
DEBUG( DEBUG_MEDIUM, "Single frame received and channel not IDLE!\n");
PduIdType pdurPduOngoing=CanTp_ConfigPtr->CanTpNSduList[rxRuntime->pduId].configData.CanTpRxNSdu.PduR_PduId;
PduR_CanTpRxIndication(pdurPduOngoing, NTFRSLT_E_NOT_OK); /** @req CANTP084 */ // Abort current reception, we need to tell the current receiver it has been aborted.
}
initRx15765RuntimeData(rxRuntime); /** @req CANTP124 */
if (rxConfig->CanTpAddressingFormant == CANTP_STANDARD) { /** @req CANTP094 *//** @req CANTP095 */
if(rxRuntime->CanfdSupport == TRUE){
/*First byte of CAN FD will be zero and second byte consists of PCI(i.e data length). Actual data contains from third byte*/
data = &rxPduData->SduDataPtr[2];
}else{
data = &rxPduData->SduDataPtr[1];
}
} else {
if(rxRuntime->CanfdSupport == TRUE){
/*First byte of CAN FD consists of Target Address(TA),Second byte will be zero and second byte consists of PCI(i.e data length). Actual data contains from third byte*/
data = &rxPduData->SduDataPtr[3];
}else{
data = &rxPduData->SduDataPtr[2];
}
}
rxRuntime->transferTotal = pduLength;
rxRuntime->iso15765.state = SF_OR_FF_RECEIVED_WAITING_PDUR_BUFFER;
rxRuntime->mode = CANTP_RX_PROCESSING;
rxRuntime->iso15765.stateTimeoutCount = (rxConfig->CanTpNbr) + 1; /** @req CANTP166 */
rxRuntime->pduId = CanTpRxNSduId;
ret = copySegmentToPduRRxBuffer(rxConfig, rxRuntime, data, pduLength, &bytesWrittenToSduRBuffer); /** @req CANTP277 */
if (ret == BUFREQ_OK) {
PduR_CanTpRxIndication(rxConfig->PduR_PduId, NTFRSLT_OK); /** @req CANTP084 */
rxRuntime->iso15765.state = IDLE;
rxRuntime->pduId = INVALID_PDU_ID;
rxRuntime->mode = CANTP_RX_WAIT;
} else if (ret == BUFREQ_E_BUSY) {
if (rxConfig->CanTpAddressingFormant == CANTP_STANDARD) {
if(rxRuntime->CanfdSupport == TRUE){
/*First byte of CAN FD will be zero and second byte consists of PCI(i.e data length). Actual data contains from third byte*/
data = &rxPduData->SduDataPtr[2];
}else{
data = &rxPduData->SduDataPtr[1];
}
} else {
if(rxRuntime->CanfdSupport == TRUE){
/*First byte of CAN FD consists of Target Address(TA),Second byte will be zero and second byte consists of PCI(i.e data length). Actual data contains from third byte*/
data = &rxPduData->SduDataPtr[3];
}else{
data = &rxPduData->SduDataPtr[2];
}
}
(void)copySegmentToLocalRxBuffer(rxRuntime, data, pduLength );
rxRuntime->iso15765.state = RX_WAIT_SF_SDU_BUFFER;
rxRuntime->mode = CANTP_RX_PROCESSING;
} else {
PduR_CanTpRxIndication(rxConfig->PduR_PduId, NTFRSLT_E_NOT_OK); /** @req CANTP084 */
rxRuntime->iso15765.state = IDLE;
rxRuntime->pduId = INVALID_PDU_ID;
rxRuntime->mode = CANTP_RX_WAIT;
}
}
}
// - - - - - - - - - - - - - -
static void handleFirstFrame(const CanTp_RxNSduType *rxConfig,
CanTp_SimplexChannelPrivateType *rxRuntime, const PduInfoType *rxPduData, PduIdType CanTpRxNSduId) {
BufReq_ReturnType ret;
boolean status;
status = TRUE;
PduLengthType pduLength = 0;
PduLengthType bytesWrittenToSduRBuffer;
uint8 extendedAddress = 0;
uint16 maxSizeStd;
uint16 maxSizeExt;
maxSizeStd=0;
maxSizeExt=0;
if (rxConfig->CanTpAddressingFormant == CANTP_EXTENDED)
{
extendedAddress = rxPduData->SduDataPtr[0];
//Verfify the target address i.e. source adress
if (extendedAddress != rxConfig->CanTpNTa->CanTpNTa)
/*lint -e{904} Return statement is necessary to avoid multiple if loops and hence increase readability */
return;
}
if ((rxRuntime->iso15765.state != IDLE) && (rxRuntime->iso15765.state != RX_WAIT_CF_SDU_BUFFER) &&
(rxRuntime->iso15765.state != RX_WAIT_SF_SDU_BUFFER)) {
DEBUG( DEBUG_MEDIUM, "First frame received during Rx-session!\n" );
PduIdType pdurPduOngoing=CanTp_ConfigPtr->CanTpNSduList[rxRuntime->pduId].configData.CanTpRxNSdu.PduR_PduId;
PduR_CanTpRxIndication(pdurPduOngoing, NTFRSLT_E_NOT_OK); /** @req CANTP084 */ // Abort current reception, we need to tell the current receiver it has been aborted.
}
initRx15765RuntimeData(rxRuntime); /** @req CANTP124 */
pduLength = getPduLength(&rxConfig->CanTpAddressingFormant, FIRST_FRAME,
rxPduData);
rxRuntime->transferTotal = pduLength;
rxRuntime->pduId = CanTpRxNSduId;
VALIDATE_NO_RV( rxRuntime->transferTotal != 0,
SERVICE_ID_CANTP_RX_INDICATION, CANTP_E_INVALID_RX_LENGTH );
// Validate that that there is a reason for using the segmented transfers and
// if not simply skip (single frame should have been used).
if (rxConfig->CanTpAddressingFormant == CANTP_STANDARD) { /** @req CANTP094 *//** @req CANTP095 */
if (pduLength <= MAX_PAYLOAD_SF_STD_ADDR){
status = FALSE;
if ((rxRuntime->CanfdSupport == TRUE) && (pduLength <= MAX_SF_DL_STDADDR_FD_SUPPORT)){
status = TRUE;
}
}
} else {
if (pduLength <= MAX_PAYLOAD_SF_EXT_ADDR){
status = FALSE;
if ((rxRuntime->CanfdSupport == TRUE) && (pduLength <= MAX_SF_DL_EXTENDADDR_FD_SUPPORT)){
status = TRUE;
}
}
}
if (status == TRUE) {
// Validate that the SDU is full length in this first frame.
if (rxPduData->SduLength < MAX_SEGMENT_DATA_SIZE) {
/*lint -e{904} Return statement is necessary to avoid multiple if loops(limit cyclomatic complexity) and hence increase readability */
return;
}
rxRuntime->iso15765.framesHandledCount = 1; // Segment count begins with 1 (FirstFrame has the 0).
rxRuntime->iso15765.state = SF_OR_FF_RECEIVED_WAITING_PDUR_BUFFER;
rxRuntime->mode = CANTP_RX_PROCESSING;
rxRuntime->iso15765.stateTimeoutCount = rxConfig->CanTpNbr; /** @req CANTP166 */
if(rxConfig->CanTpAddressingFormant == CANTP_STANDARD ){
if(rxRuntime->CanfdSupport == TRUE){
maxSizeStd = MX_PAYLOAD_FF_STD_ADDR_FD_SUPPORT;
}else{
maxSizeStd = MAX_PAYLOAD_FF_STD_ADDR;
}
}else{
if(rxRuntime->CanfdSupport == TRUE){
maxSizeExt = MX_PAYLOAD_FF_EXT_ADDR_FD_SUPPORT;
}else{
maxSizeExt = MAX_PAYLOAD_FF_EXT_ADDR;
}
}
if (rxConfig->CanTpAddressingFormant == CANTP_STANDARD) {
ret = copySegmentToPduRRxBuffer(rxConfig, rxRuntime,
&rxPduData->SduDataPtr[2],
maxSizeStd,
&bytesWrittenToSduRBuffer);
} else {
rxRuntime->iso15765.extendedAddress = rxConfig->CanTpNTa->CanTpNTa;
ret = copySegmentToPduRRxBuffer(rxConfig, rxRuntime,
&rxPduData->SduDataPtr[3],
maxSizeExt,
&bytesWrittenToSduRBuffer);
}
if (ret == BUFREQ_OK) {
rxRuntime->iso15765.stateTimeoutCount = (rxConfig->CanTpNcr) + 1; /** @req CANTP312 */
rxRuntime->iso15765.state = RX_WAIT_CONSECUTIVE_FRAME;
rxRuntime->mode = CANTP_RX_PROCESSING;
sendFlowControlFrame(rxConfig, rxRuntime, ret); /** @req CANTP064 */
} else if (ret == BUFREQ_E_BUSY) {
/** @req CANTP222 */
if (rxConfig->CanTpAddressingFormant == CANTP_STANDARD) {
(void)copySegmentToLocalRxBuffer(rxRuntime, &rxPduData->SduDataPtr[2], maxSizeStd );
} else {
(void)copySegmentToLocalRxBuffer(rxRuntime, &rxPduData->SduDataPtr[3], maxSizeExt );
}
rxRuntime->iso15765.stateTimeoutCount = (rxConfig->CanTpNbr) + 1;
rxRuntime->iso15765.state = RX_WAIT_CF_SDU_BUFFER;
rxRuntime->mode = CANTP_RX_PROCESSING;
sendFlowControlFrame(rxConfig, rxRuntime, ret); /** @req CANTP082 */ /** @req CANTP064 */
} else if (ret == BUFREQ_E_OVFL) {
sendFlowControlFrame(rxConfig, rxRuntime, ret); /** @req CANTP318 */ /** @req CANTP064 */
rxRuntime->iso15765.state = IDLE;
rxRuntime->pduId = INVALID_PDU_ID;
rxRuntime->mode = CANTP_RX_WAIT;
}
else if (ret == BUFREQ_E_NOT_OK) {
PduR_CanTpRxIndication(rxRuntime->pduId, NTFRSLT_E_NOT_OK); /** @req CANTP084 */ // Abort current reception, we need to tell the current receiver it has been aborted.
rxRuntime->iso15765.state = IDLE;
rxRuntime->pduId = INVALID_PDU_ID;
rxRuntime->mode = CANTP_RX_WAIT;
}
else {
/* Do nothing */
}
/** @req CANTP081 */
}
}
// - - - - - - - - - - - - - -
static ISO15765FrameType calcRequiredProtocolFrameType(
const CanTp_TxNSduType *txConfig, CanTp_SimplexChannelPrivateType *txRuntime) {
uint8 maxPayload;
ISO15765FrameType ret = INVALID_FRAME;
if (txConfig->CanTpAddressingMode == CANTP_EXTENDED) {
if(txRuntime->CanfdSupport == TRUE){
maxPayload = MX_PAYLOAD_FF_EXT_ADDR_FD_SUPPORT;
}else{
maxPayload = MAX_PAYLOAD_CF_EXT_ADDR;
}
}else{
if(txRuntime->CanfdSupport == TRUE){
maxPayload = MX_PAYLOAD_FF_STD_ADDR_FD_SUPPORT;
}else{
maxPayload = MAX_PAYLOAD_CF_STD_ADDR;
}
}
if (txConfig->CanTpAddressingMode == CANTP_EXTENDED) {
if (txRuntime->transferTotal <= maxPayload) {
ret = SINGLE_FRAME;
} else {
if (txConfig->CanTpTxTaType == CANTP_PHYSICAL) {
ret = FIRST_FRAME;
} else {
DET_REPORTERROR(SERVICE_ID_CANTP_TRANSMIT, CANTP_E_INVALID_TATYPE ); /** @req CANTP093 */
}
}
} else { // CANTP_STANDARD
if (txRuntime->transferTotal <= maxPayload) {
ret = SINGLE_FRAME;
} else {
if (txConfig->CanTpTxTaType == CANTP_PHYSICAL) {
ret = FIRST_FRAME;
} else {
DET_REPORTERROR(SERVICE_ID_CANTP_TRANSMIT, CANTP_E_INVALID_TATYPE ); /** @req CANTP093 */
}
}
}
return ret;
}
// - - - - - - - - - - - - - -
Std_ReturnType CanTp_Transmit(PduIdType CanTpTxSduId,
const PduInfoType *CanTpTxInfoPtr) /** @req CANTP176 */
{
const CanTp_TxNSduType *txConfig = NULL;
CanTp_SimplexChannelPrivateType *txRuntime = NULL;
Std_ReturnType ret = 0;
PduIdType CanTp_InternalTxNSduId;
DEBUG( DEBUG_MEDIUM, "CanTp_Transmit called in polite index: %d!\n", CanTpTxSduId);
VALIDATE( CanTpTxInfoPtr != NULL,
SERVICE_ID_CANTP_TRANSMIT, CANTP_E_PARAM_ADDRESS ); /** @req CANTP321 */
VALIDATE( CanTpRunTimeData.internalState == CANTP_ON, /** @req CANTP238 */
SERVICE_ID_CANTP_TRANSMIT, CANTP_E_UNINIT ); /** @req CANTP031 */
VALIDATE( CanTpTxSduId < CanTp_ConfigPtr->CanTpGeneral->number_of_sdus, SERVICE_ID_CANTP_TRANSMIT, CANTP_E_INVALID_TX_ID );
if( CanTp_ConfigPtr->CanTpRxIdList[CanTpTxSduId].CanTpNSduIndex != 0xFFFF ) {
CanTp_InternalTxNSduId = CanTp_ConfigPtr->CanTpRxIdList[CanTpTxSduId].CanTpNSduIndex;
txConfig =&CanTp_ConfigPtr->CanTpNSduList[CanTp_InternalTxNSduId].configData.CanTpTxNSdu;
txRuntime = &CanTpRunTimeData.runtimeDataList[txConfig->CanTpTxChannel].SimplexChnlList[CANTP_TX_CHANNEL]; // Runtime data.
if (txRuntime->iso15765.state == IDLE) {
ISO15765FrameType iso15765Frame;
txRuntime->canFrameBuffer.byteCount = 0;
txRuntime->transferCount = 0;
txRuntime->iso15765.framesHandledCount = 0;
txRuntime->transferTotal = CanTpTxInfoPtr->SduLength; /** @req CANTP225 */ /** @req CANTP299 */
txRuntime->iso15765.stateTimeoutCount = (txConfig->CanTpNcs) + 1; /** @req CANTP167 */
txRuntime->mode = CANTP_TX_PROCESSING;
txRuntime->pduId = CanTp_InternalTxNSduId;
txRuntime->CanfdSupport = CanTp_ConfigPtr->CanTpNSduList[CanTp_InternalTxNSduId].CanTpFDSupport;
iso15765Frame = calcRequiredProtocolFrameType(txConfig, txRuntime); /** @req CANTP231 */ /** @req CANTP232 */
if (txConfig->CanTpAddressingMode == CANTP_EXTENDED) { /** @req CANTP094 *//** @req CANTP095 */
txRuntime->canFrameBuffer.data[txRuntime->canFrameBuffer.byteCount++] =
(uint8) txConfig->CanTpNTa->CanTpNTa; // Target address.
}
switch(iso15765Frame) {
case SINGLE_FRAME:
if(txRuntime->CanfdSupport == TRUE){
/*First Byte of CanFD is zero. Second Byte contains PCI(SF_DL i.e Complete data length) value*/
txRuntime->canFrameBuffer.data[txRuntime->canFrameBuffer.byteCount++] = CANFD_FIRST_BYTE_ZERO;
txRuntime->canFrameBuffer.data[txRuntime->canFrameBuffer.byteCount++] = ISO15765_TPCI_DL_FD & (uint8)(txRuntime->transferTotal);
}
else{
txRuntime->canFrameBuffer.data[txRuntime->canFrameBuffer.byteCount++] =
ISO15765_TPCI_DL & (uint8)(txRuntime->transferTotal);
}
ret = E_OK;
break;
case FIRST_FRAME:
txRuntime->canFrameBuffer.data[txRuntime->canFrameBuffer.byteCount++] =
ISO15765_TPCI_FF | (uint8)((txRuntime->transferTotal & 0xf00) >> 8);
txRuntime->canFrameBuffer.data[txRuntime->canFrameBuffer.byteCount++] =
(uint8)(txRuntime->transferTotal & 0xff);
// setup block size so that state machine waits for flow control after first frame
txRuntime->iso15765.nextFlowControlCount = 1;
txRuntime->iso15765.BS = 1;
ret = E_OK;
break;
default:
ret = E_NOT_OK;
}
txRuntime->iso15765.state = TX_WAIT_TRANSMIT;
} else {
DEBUG( DEBUG_MEDIUM, "CanTp can't transmit, it is already occupied!\n", CanTpTxSduId);
ret = E_NOT_OK; /** @req CANTP123 *//** @req CANTP206 */
}
}
return ret; // CAN level error code.
}
/* @req CANTP273 */
/* @req CANTP208 */
void CanTp_Init( const CanTp_ConfigType* CfgPtr)
{
VALIDATE_NO_RV(CfgPtr != NULL, SERVICE_ID_CANTP_INIT,CANTP_E_PARAM_POINTER); /* @req CANTP320 */
CanTp_ConfigPtr = CfgPtr;
for (uint8 i=0; i < CANTP_MAX_NO_CHANNELS; i++) {
initTx15765RuntimeData(&CanTpRunTimeData.runtimeDataList[i].SimplexChnlList[CANTP_TX_CHANNEL]);
initRx15765RuntimeData(&CanTpRunTimeData.runtimeDataList[i].SimplexChnlList[CANTP_RX_CHANNEL]);
initRx15765RuntimeData(&CanTpRunTimeData.runtimeDataList[i].functionalChnl);
}
CanTpRunTimeData.internalState = CANTP_ON; /** @req CANTP170 */
}
// - - - - - - - - - - - - - -
/** @req CANTP214 */
void CanTp_RxIndication(PduIdType CanTpRxPduId, /** @req CANTP078 */ /** @req CANTP035 */
PduInfoType *CanTpRxPduPtr)
{
const CanTp_RxNSduType *rxConfigParams = NULL; // Params reside in ROM.
const CanTp_TxNSduType *txConfigParams = NULL;
const CanTp_AddressingFormantType *addressingFormat; // Configured
CanTp_SimplexChannelPrivateType *runtimeParams = 0; // Params reside in RAM.
ISO15765FrameType frameType = INVALID_FRAME;
PduIdType CanTpTxNSduId, CanTpRxNSduId;
CanTpRxNSduId = INVALID_PDU_ID;
//Check if PduId is valid
if (CanTpRxPduId >= CanTp_ConfigPtr->CanTpGeneral->number_of_pdus ) {
/*lint -e{904} Return statement is necessary to avoid multiple if loops and hence increase readability in case of argument check */
return;
}
if( CanTpRunTimeData.internalState != CANTP_ON ) {
DET_REPORTERROR(SERVICE_ID_CANTP_RX_INDICATION, CANTP_E_UNINIT ); /** @req CANTP238 */ /** @req CANTP031 */
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return;
}
DEBUG( DEBUG_MEDIUM, "CanTp_RxIndication: PduId=%d, [", CanTpRxPduId);
for (int i=0; i<CanTpRxPduPtr->SduLength; i++) {
DEBUG( DEBUG_MEDIUM, "%x, ", CanTpRxPduPtr->SduDataPtr[i]);
}
DEBUG( DEBUG_MEDIUM, "]");
VALIDATE_NO_RV( CanTpRunTimeData.internalState == CANTP_ON,
SERVICE_ID_CANTP_RX_INDICATION, CANTP_E_UNINIT ); /** @req CANTP031 */
PduIdType TpIndex = INVALID_PDU_ID;
const CanTp_RxNSduType *rxConfig;
const CanTp_TxNSduType *txConfig;
for(uint32 i = 0; (i < CanTp_ConfigPtr->CanTpGeneral->pdu_list_size) && (INVALID_PDU_ID == TpIndex); i++) {
if( CanTpRxPduId == CanTp_ConfigPtr->CanTpRxIdList[i].CanTpPduId ) {
if( CANTP_EXTENDED == CanTp_ConfigPtr->CanTpRxIdList[i].CanTpAddressingMode ) {
if( FLOW_CONTROL_FRAME == getFrameType(&CanTp_ConfigPtr->CanTpRxIdList[i].CanTpAddressingMode, CanTpRxPduPtr) ) {
if( CanTp_ConfigPtr->CanTpRxIdList[i].CanTpReferringTxIndex != 0xFFFF ) {
txConfig = &CanTp_ConfigPtr->CanTpNSduList[CanTp_ConfigPtr->CanTpRxIdList[i].CanTpReferringTxIndex].configData.CanTpTxNSdu;
if( CanTpRxPduPtr->SduDataPtr[0] == txConfig->CanTpNSa->CanTpNSa ) {
TpIndex = i;
}
}
} else {
if( CanTp_ConfigPtr->CanTpRxIdList[i].CanTpNSduIndex != 0xFFFF ) {
if( ISO15765_RECEIVE == CanTp_ConfigPtr->CanTpNSduList[CanTp_ConfigPtr->CanTpRxIdList[i].CanTpNSduIndex].direction ) {
rxConfig = &CanTp_ConfigPtr->CanTpNSduList[CanTp_ConfigPtr->CanTpRxIdList[i].CanTpNSduIndex].configData.CanTpRxNSdu;
if( CanTpRxPduPtr->SduDataPtr[0] == rxConfig->CanTpNTa->CanTpNTa ) {
TpIndex = i;
}
}
}
}
} else {
TpIndex = i;
}
}
}
if( INVALID_PDU_ID != TpIndex) {
addressingFormat = &CanTp_ConfigPtr->CanTpRxIdList[TpIndex].CanTpAddressingMode;
frameType = getFrameType(addressingFormat, CanTpRxPduPtr); /** @req CANTP094 *//** @req CANTP095 */ /** @req CANTP284 */
if( frameType == FLOW_CONTROL_FRAME ) {
if( CanTp_ConfigPtr->CanTpRxIdList[TpIndex].CanTpReferringTxIndex != 0xFFFF ) {
CanTpTxNSduId = CanTp_ConfigPtr->CanTpRxIdList[TpIndex].CanTpReferringTxIndex;
txConfigParams = &CanTp_ConfigPtr->CanTpNSduList[CanTpTxNSduId].configData.CanTpTxNSdu;
runtimeParams = &CanTpRunTimeData.runtimeDataList[txConfigParams->CanTpTxChannel].SimplexChnlList[CANTP_TX_CHANNEL];
} else {
//Invalid FC received
/*lint -e{904} Return statement is necessary to avoid multiple if loops (limit cyclomatic complexity) and hence increase readability*/
return;
}
rxConfigParams = NULL;
} else {
if( CanTp_ConfigPtr->CanTpRxIdList[TpIndex].CanTpNSduIndex != 0xFFFF ) {
CanTpRxNSduId = CanTp_ConfigPtr->CanTpRxIdList[TpIndex].CanTpNSduIndex;
rxConfigParams = &CanTp_ConfigPtr->CanTpNSduList[CanTpRxNSduId].configData.CanTpRxNSdu; /** @req CANTP120 */
if( CANTP_FUNCTIONAL == rxConfigParams->CanTpRxTaType) {// Find if the current Pdu received is on a functional channel
runtimeParams = &CanTpRunTimeData.runtimeDataList[rxConfigParams->CanTpRxChannel].functionalChnl;
}
else {
runtimeParams = &CanTpRunTimeData.runtimeDataList[rxConfigParams->CanTpRxChannel].SimplexChnlList[CANTP_RX_CHANNEL]; /** @req CANTP096 *//** @req CANTP121 *//** @req CANTP122 *//** @req CANTP190 */
}
runtimeParams->CanfdSupport = CanTp_ConfigPtr->CanTpNSduList[CanTpRxNSduId].CanTpFDSupport;
} else {
//Invalid Frame received
/*lint -e{904} Return statement is necessary to avoid multiple if loops (limit cyclomatic complexity) and hence increase readability*/
return;
}
txConfigParams = NULL;
}
}
switch (frameType) {
case SINGLE_FRAME:
if (rxConfigParams != NULL) {
DEBUG( DEBUG_MEDIUM, "calling handleSingleFrame!\n");
handleSingleFrame(rxConfigParams, runtimeParams, CanTpRxPduPtr, CanTpRxNSduId); /** @req CANTP096 *//** @req CANTP121 *//** @req CANTP122 *//** @req CANTP190 */
} else{
DEBUG( DEBUG_MEDIUM, "Single frame received on ISO15765-Tx - is ignored!\n");
}
break;
case FIRST_FRAME:
if (rxConfigParams != NULL) {
DEBUG( DEBUG_MEDIUM, "calling handleFirstFrame!\n");
handleFirstFrame(rxConfigParams, runtimeParams, CanTpRxPduPtr,CanTpRxNSduId);
} else {
DEBUG( DEBUG_MEDIUM, "First frame received on ISO15765-Tx - is ignored!\n");
}
break;
case CONSECUTIVE_FRAME:
if (rxConfigParams != NULL) {
DEBUG( DEBUG_MEDIUM, "calling handleConsecutiveFrame!\n");
handleConsecutiveFrame(rxConfigParams, runtimeParams, CanTpRxPduPtr);
} else {
DEBUG( DEBUG_MEDIUM, "Consecutive frame received on ISO15765-Tx - is ignored!\n");
}
break;
case FLOW_CONTROL_FRAME:
if (txConfigParams != NULL) {
DEBUG( DEBUG_MEDIUM, "calling handleFlowControlFrame!\n");
handleFlowControlFrame(txConfigParams, runtimeParams, CanTpRxPduPtr);
} else {
DEBUG( DEBUG_MEDIUM, "Flow control frame received on ISO15765-Rx - is ignored!\n");
}
break;
case INVALID_FRAME:
DEBUG( DEBUG_MEDIUM, "INVALID_FRAME received - is ignored!\n!\n");
break;
default:
break;
}
DEBUG( DEBUG_LOW, "CanTp_RxIndication_Main exit!\n");
}
// - - - - - - - - - - - - - -
/** @req CANTP215 */
void CanTp_TxConfirmation(PduIdType CanTpTxPduId) /** @req CANTP076 */
{
PduIdType CanTpNSduId;
const CanTp_RxNSduType *rxConfigParams = NULL;
const CanTp_TxNSduType *txConfigParams = NULL;
DEBUG( DEBUG_MEDIUM, "CanTp_TxConfirmation called.\n" );
VALIDATE_NO_RV( CanTpRunTimeData.internalState == CANTP_ON,
SERVICE_ID_CANTP_TX_CONFIRMATION, CANTP_E_UNINIT ); /** @req CANTP031 */
VALIDATE_NO_RV( CanTpTxPduId < CanTp_ConfigPtr->CanTpGeneral->number_of_pdus,
SERVICE_ID_CANTP_TX_CONFIRMATION, CANTP_E_INVALID_TX_ID ); /** @req CANTP158 */
/** @req CANTP236 */
if( CanTp_ConfigPtr->CanTpRxIdList[CanTpTxPduId].CanTpNSduIndex != 0xFFFF ) {
CanTpNSduId = CanTp_ConfigPtr->CanTpRxIdList[CanTpTxPduId].CanTpNSduIndex;
if ( CanTp_ConfigPtr->CanTpNSduList[CanTpNSduId].direction == IS015765_TRANSMIT ) {
txConfigParams = (CanTp_TxNSduType*)&CanTp_ConfigPtr->CanTpNSduList[CanTpNSduId].configData.CanTpTxNSdu;
CanTp_SimplexChannelPrivateType *txRuntime = &CanTpRunTimeData.runtimeDataList[txConfigParams->CanTpTxChannel].SimplexChnlList[CANTP_TX_CHANNEL];
if(txRuntime->iso15765.state == TX_WAIT_TX_CONFIRMATION) {
handleNextTxFrameSent(txConfigParams, txRuntime);
}
} else {
rxConfigParams = (CanTp_RxNSduType*)&CanTp_ConfigPtr->CanTpNSduList[CanTpNSduId].configData.CanTpRxNSdu;
CanTpRunTimeData.runtimeDataList[rxConfigParams->CanTpRxChannel].SimplexChnlList[CANTP_RX_CHANNEL].iso15765.NasNarPending = FALSE;
}
}
}
// - - - - - - - - - - - - - -
void CanTp_Shutdown(void) /** @req CANTP202 *//** @req CANTP200 *//** @req CANTP010 */
{
VALIDATE_NO_RV( CanTpRunTimeData.internalState == CANTP_ON,
SERVICE_ID_CANTP_SHUTDOWN, CANTP_E_UNINIT ); /** @req CANTP031 */
CanTpRunTimeData.internalState = CANTP_OFF;
}
// - - - - - - - - - - - - - -
#if 0
/* IMPROVEMENT: Add support for Nas/Nar .*/
boolean checkNasNarTimeout(PduIdType CanTpTxPduId, CanTp_SimplexChannelPrivateType *runtimeData) { /* this function is NEVER CALLED */
boolean ret = FALSE;
if (runtimeData->iso15765.NasNarPending) {
TIMER_DECREMENT(runtimeData->iso15765.NasNarTimeoutCount);
if (runtimeData->iso15765.NasNarTimeoutCount == 0) {
DEBUG( DEBUG_MEDIUM, "NAS timed out.\n" );
runtimeData->iso15765.state = IDLE;
rxRuntime->pduId = INVALID_PDU_ID;
runtimeData->iso15765.NasNarPending = FALSE;
ret = TRUE;
PduR_CanTpTxConfirmation(CanTpTxPduId, NTFRSLT_E_TIMEOUT_A); /** @req CANTP310 */ /** @req CANTP311 */
}
}
return ret;
}
#endif
//This function tries to obtain a buffer in every MainFunction for a SF which is denied buffer by higher layers. This is not an ASR req.
void getBuffSingleFrame(const CanTp_RxNSduType *rxConfigListItem, CanTp_SimplexChannelPrivateType *rxRuntimeListItem) {
/* We end up here if we have requested a buffer from the
* PDUR but the response have been BUSY.
*/
BufReq_ReturnType ret;
PduLengthType bytesWrittenToSduRBuffer;
TIMER_DECREMENT (rxRuntimeListItem->iso15765.stateTimeoutCount);
/* first try to copy the the old data to the buffer */
/** @req CANTP222 */
ret = copySegmentToPduRRxBuffer(rxConfigListItem, rxRuntimeListItem, rxRuntimeListItem->canFrameBuffer.data, rxRuntimeListItem->canFrameBuffer.byteCount, &bytesWrittenToSduRBuffer);
if (ret == BUFREQ_OK)
{
PduR_CanTpRxIndication(rxConfigListItem->PduR_PduId, NTFRSLT_OK); /** @req CANTP084 */
/** @req CANTP204 */
rxRuntimeListItem->iso15765.state = IDLE;
rxRuntimeListItem->pduId = INVALID_PDU_ID;
rxRuntimeListItem->mode = CANTP_RX_WAIT;
}
else if (((ret == BUFREQ_E_BUSY) && (rxRuntimeListItem->iso15765.stateTimeoutCount == 0)) || (ret == BUFREQ_E_NOT_OK ))
{
rxRuntimeListItem->iso15765.state = IDLE;
rxRuntimeListItem->pduId = INVALID_PDU_ID;
rxRuntimeListItem->mode = CANTP_RX_WAIT;
}
else
{
/* Do nothing */
}
return;
}
void txSduStateMachine(const CanTp_TxNSduType *txConfigListItem, CanTp_SimplexChannelPrivateType *txRuntimeListItem) {
BufReq_ReturnType ret;
switch (txRuntimeListItem->iso15765.state) {
case TX_WAIT_STMIN:
TIMER_DECREMENT(txRuntimeListItem->iso15765.stateTimeoutCount); // Make sure that STmin timer has expired.
if (txRuntimeListItem->iso15765.stateTimeoutCount != 0) {
break;
}
txRuntimeListItem->iso15765.state = TX_WAIT_TRANSMIT;
txRuntimeListItem->iso15765.stateTimeoutCount = (txConfigListItem->CanTpNcs) + 1;
// no break, continue
case TX_WAIT_TRANSMIT: {
ret = sendNextTxFrame(txConfigListItem, txRuntimeListItem); /** @req CANTP184 */ /** @req CANTP089 */
if ( ret == BUFREQ_OK ) {
// successfully sent frame, wait for tx confirm
} else if(BUFREQ_E_BUSY == ret) { /** @req CANTP184 */
// check N_Cs timeout
TIMER_DECREMENT(txRuntimeListItem->iso15765.stateTimeoutCount);
if (txRuntimeListItem->iso15765.stateTimeoutCount == 0) {
/* Cs timeout */
/** @req CANTP205 */
DEBUG( DEBUG_MEDIUM, "ERROR: N_Cs timeout when sending consecutive frame!\n");
txRuntimeListItem->iso15765.state = IDLE;
txRuntimeListItem->pduId = INVALID_PDU_ID;
txRuntimeListItem->mode = CANTP_TX_WAIT;
PduR_CanTpTxConfirmation(txConfigListItem->PduR_PduId, NTFRSLT_E_NOT_OK); /** @req CANTP204 */ /** @req CANTP280 */ /** @req CANTP185 */
} else {
DEBUG( DEBUG_MEDIUM, "Waiting for STmin timer to expire!\n");
}
} else {
DEBUG( DEBUG_MEDIUM, "ERROR: Consecutive frame could not be sent!\n");
txRuntimeListItem->iso15765.state = IDLE;
txRuntimeListItem->pduId = INVALID_PDU_ID;
txRuntimeListItem->mode = CANTP_TX_WAIT;
PduR_CanTpTxConfirmation(txConfigListItem->PduR_PduId, NTFRSLT_E_NOT_OK); /** @req CANTP204 */ /** @req CANTP087 */
}
break;
}
case TX_WAIT_FLOW_CONTROL:
//DEBUG( DEBUG_MEDIUM, "Waiting for flow control!\n");
TIMER_DECREMENT(txRuntimeListItem->iso15765.stateTimeoutCount);
if (txRuntimeListItem->iso15765.stateTimeoutCount == 0) {
/* N_Bs timeout */
/** @req CANTP205 */
DEBUG( DEBUG_MEDIUM, "State TX_WAIT_FLOW_CONTROL timed out!\n");
txRuntimeListItem->iso15765.state = IDLE;
txRuntimeListItem->pduId = INVALID_PDU_ID;
txRuntimeListItem->mode = CANTP_TX_WAIT;
PduR_CanTpTxConfirmation(txConfigListItem->PduR_PduId, NTFRSLT_E_TIMEOUT_BS ); /** @req CANTP204 */ /** @req CANTP316 */
}
break;
case TX_WAIT_TX_CONFIRMATION:
TIMER_DECREMENT(txRuntimeListItem->iso15765.stateTimeoutCount);
if (txRuntimeListItem->iso15765.stateTimeoutCount == 0) { /** @req CANTP075 */
/* N_As timeout */
/** @req CANTP205 */
txRuntimeListItem->iso15765.state = IDLE;
txRuntimeListItem->pduId = INVALID_PDU_ID;
txRuntimeListItem->mode = CANTP_TX_WAIT;
PduR_CanTpTxConfirmation(txConfigListItem->PduR_PduId, NTFRSLT_E_TIMEOUT_A );/* @req CANTP310 *//* @req CANTP311 */
}
break;
default:
break;
}
}
void rxPhySduStateMachine(const CanTp_RxNSduType *rxConfigListItem, CanTp_SimplexChannelPrivateType *rxRuntimeListItem) {
BufReq_ReturnType ret;
PduLengthType bytesWrittenToSduRBuffer;
switch (rxRuntimeListItem->iso15765.state) {
case RX_WAIT_CONSECUTIVE_FRAME: {
TIMER_DECREMENT (rxRuntimeListItem->iso15765.stateTimeoutCount);
if (rxRuntimeListItem->iso15765.stateTimeoutCount == 0) {
/* N_Cr timeout */
DEBUG( DEBUG_MEDIUM, "TIMEOUT!\n");
PduR_CanTpRxIndication(rxConfigListItem->PduR_PduId, NTFRSLT_E_TIMEOUT_CR); /** @req CANTP084 */ /** @req CANTP313 */
rxRuntimeListItem->iso15765.state = IDLE;
rxRuntimeListItem->pduId = INVALID_PDU_ID;
rxRuntimeListItem->mode = CANTP_RX_WAIT;
}
break;
}
case RX_WAIT_CF_SDU_BUFFER: {
/* We end up here if we have requested a buffer from the
* PDUR but the response have been BUSY. We assume
* we have data in our local buffer and we are expected
* to send a flow-control clear to send (CTS).
*/
TIMER_DECREMENT (rxRuntimeListItem->iso15765.stateTimeoutCount);
/* first try to copy the the old data to the buffer */
/** @req CANTP222 */
PduLengthType bytesRemaining = 0;
ret = copySegmentToPduRRxBuffer(rxConfigListItem, rxRuntimeListItem, rxRuntimeListItem->canFrameBuffer.data, rxRuntimeListItem->canFrameBuffer.byteCount, &bytesWrittenToSduRBuffer);
bytesRemaining = rxRuntimeListItem->transferTotal - rxRuntimeListItem->transferCount;
if (ret == BUFREQ_OK)
{
if (( bytesRemaining > 0))
{
/** @req CANTP224 */
sendFlowControlFrame( rxConfigListItem, rxRuntimeListItem, ret );
/** @req CANTP312 */
rxRuntimeListItem->iso15765.stateTimeoutCount = rxConfigListItem->CanTpNcr;
rxRuntimeListItem->iso15765.state = RX_WAIT_CONSECUTIVE_FRAME;
}
else
{
/** @req CANTP204 */
rxRuntimeListItem->iso15765.state = IDLE;
rxRuntimeListItem->pduId = INVALID_PDU_ID;
rxRuntimeListItem->mode = CANTP_RX_WAIT;
PduR_CanTpRxIndication(rxConfigListItem->PduR_PduId, NTFRSLT_OK); /** @req CANTP084 */
}
}
else if (ret == BUFREQ_E_BUSY)
{
if (rxRuntimeListItem->iso15765.stateTimeoutCount == 0)
{
/* N_Br timeout */
if ((rxRuntimeListItem->CanTpWftMaxCounter < rxConfigListItem->CanTpWftMax))
{
/** @req CANTP082 */
sendFlowControlFrame( rxConfigListItem, rxRuntimeListItem, BUFREQ_E_BUSY);
rxRuntimeListItem->iso15765.stateTimeoutCount = rxConfigListItem->CanTpNbr;
}
else
{
/** @req CANTP223 */
rxRuntimeListItem->iso15765.state = IDLE;
rxRuntimeListItem->pduId = INVALID_PDU_ID;
rxRuntimeListItem->mode = CANTP_RX_WAIT;
rxRuntimeListItem->CanTpWftMaxCounter = 0;
/* If FF has already acquired a buffer and last CF in a block fails indicate failure to PduR */
if (rxRuntimeListItem->transferCount != 0)
{
PduR_CanTpRxIndication(rxConfigListItem->PduR_PduId, NTFRSLT_E_NOT_OK); /** @req CANTP084 */
}
}
}
else
{
if (rxRuntimeListItem->CanTpWftMaxCounter >= rxConfigListItem->CanTpWftMax)
{
/** @req CANTP223 */
rxRuntimeListItem->iso15765.state = IDLE;
rxRuntimeListItem->pduId = INVALID_PDU_ID;
rxRuntimeListItem->mode = CANTP_RX_WAIT;
rxRuntimeListItem->CanTpWftMaxCounter = 0;
/* If FF has already acquired a buffer and last CF in a block fails indicate failure to PduR */
if (rxRuntimeListItem->transferCount != 0)
{
PduR_CanTpRxIndication(rxConfigListItem->PduR_PduId, NTFRSLT_E_NOT_OK); /** @req CANTP084 */
}
}
}
}
else if (ret == BUFREQ_E_NOT_OK )
{
rxRuntimeListItem->iso15765.state = IDLE;
rxRuntimeListItem->pduId = INVALID_PDU_ID;
rxRuntimeListItem->mode = CANTP_RX_WAIT;
rxRuntimeListItem->CanTpWftMaxCounter = 0;
/* If FF has already acquired a buffer and last CF in a block fails indicate failure to PduR */
if (rxRuntimeListItem->transferCount != 0)
{
PduR_CanTpRxIndication(rxConfigListItem->PduR_PduId, NTFRSLT_E_NOT_OK); /** @req CANTP084 */
}
}
break;
}
case RX_WAIT_SF_SDU_BUFFER: {
getBuffSingleFrame(rxConfigListItem, rxRuntimeListItem);
break;
}
default:
break;
}
}
void rxFncSduStateMachine(const CanTp_RxNSduType *rxConfigListItem, CanTp_SimplexChannelPrivateType *rxRuntimeListItem) {
switch (rxRuntimeListItem->iso15765.state) {
case RX_WAIT_SF_SDU_BUFFER: {
getBuffSingleFrame(rxConfigListItem, rxRuntimeListItem);
break;
}
default:
break;
}
}
// - - - - - - - - - - - - - -
void CanTp_MainFunction(void)
{
PduIdType pduTxId, pduRxId,pduRxFuncId;
CanTp_SimplexChannelPrivateType *txRuntimeListItem = NULL;
CanTp_SimplexChannelPrivateType *rxRuntimeListItem = NULL;
const CanTp_TxNSduType *txConfigListItem = NULL;
const CanTp_RxNSduType *rxConfigListItem = NULL;
if( CanTpRunTimeData.internalState != CANTP_ON ) {
DET_REPORTERROR(SERVICE_ID_CANTP_MAIN_FUNCTION, CANTP_E_UNINIT ); /** @req CANTP031 */
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return;
}
for( uint32 i=0; i < CANTP_MAX_NO_CHANNELS; i++ ) {
pduTxId = CanTpRunTimeData.runtimeDataList[i].SimplexChnlList[CANTP_TX_CHANNEL].pduId;
pduRxId = CanTpRunTimeData.runtimeDataList[i].SimplexChnlList[CANTP_RX_CHANNEL].pduId;
pduRxFuncId = CanTpRunTimeData.runtimeDataList[i].functionalChnl.pduId;
if (pduTxId != INVALID_PDU_ID)
{
txConfigListItem = (CanTp_TxNSduType*)&CanTp_ConfigPtr->CanTpNSduList[pduTxId].configData.CanTpTxNSdu;
txRuntimeListItem = &CanTpRunTimeData.runtimeDataList[i].SimplexChnlList[CANTP_TX_CHANNEL];
txSduStateMachine(txConfigListItem, txRuntimeListItem);
}
if (pduRxId != INVALID_PDU_ID)
{
rxConfigListItem = (CanTp_RxNSduType*)&CanTp_ConfigPtr->CanTpNSduList[pduRxId].configData.CanTpRxNSdu;
rxRuntimeListItem = &CanTpRunTimeData.runtimeDataList[i].SimplexChnlList[CANTP_RX_CHANNEL];
rxPhySduStateMachine(rxConfigListItem, rxRuntimeListItem);
}
if (pduRxFuncId != INVALID_PDU_ID)
{
rxConfigListItem = (CanTp_RxNSduType*)&CanTp_ConfigPtr->CanTpNSduList[pduRxFuncId].configData.CanTpRxNSdu;
rxRuntimeListItem = &CanTpRunTimeData.runtimeDataList[i].functionalChnl;
rxFncSduStateMachine(rxConfigListItem, rxRuntimeListItem);
}
}
}
|
2301_81045437/classic-platform
|
communication/CanTp/src/CanTp.c
|
C
|
unknown
| 78,753
|
# Com
obj-$(USE_COM) += Com_Cfg.o
pb-obj-$(USE_COM) += Com_PbCfg.o
pb-pc-file-$(USE_COM) += Com_Cfg.h Com_Cfg.c
obj-$(USE_COM) += Com_Com.o
obj-$(USE_COM) += Com_Sched.o
obj-$(USE_COM) += Com.o
obj-$(USE_COM) += Com_misc.o
inc-$(USE_COM) += $(ROOTDIR)/communication/Com/inc
inc-$(USE_COM) += $(ROOTDIR)/communication/Com/src
vpath-$(USE_COM) += $(ROOTDIR)/communication/Com/src
|
2301_81045437/classic-platform
|
communication/Com/Com.mod.mk
|
Makefile
|
unknown
| 393
|
/*-------------------------------- 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 -----------------------------*/
/* @req COM005 */
#ifndef COM_H_
#define COM_H_
#include "Std_Types.h"
#include "ComStack_Types.h"
/* @req COM786 */
/* @req COM424 */
#define COM_AR_RELEASE_MAJOR_VERSION 4u
#define COM_AR_RELEASE_MINOR_VERSION 0u
#define COM_AR_RELEASE_REVISION_VERSION 3u
#define COM_AR_MAJOR_VERSION COM_AR_RELEASE_MAJOR_VERSION
#define COM_AR_MINOR_VERSION COM_AR_RELEASE_MINOR_VERSION
#define COM_AR_PATCH_VERSION COM_AR_RELEASE_REVISION_VERSION
#define COM_VENDOR_ID 60u
#define COM_MODULE_ID 50u
#define COM_SW_MAJOR_VERSION 1u
#define COM_SW_MINOR_VERSION 2u
#define COM_SW_PATCH_VERSION 2u
#include "Com_Cfg.h"
// This is needed since the RTE is using signal names (needs attention when it comes to post build)
#include "Com_PbCfg.h"
#include "Com_Types.h"
#include "Com_Com.h"
#include "Com_Sched.h"
typedef uint8 Com_IpduGroupVector[((COM_N_SUPPORTED_IPDU_GROUPS - 1)/8) + 1];
//-------------------------------------------------------------------
// From OSEK_VDX
/* The service SendMessage updates the message object identified by
* <Message> with the application message referenced by the
* <DataRef> parameter.
*
* Internal communication:
* The message <Message> is routed to the receiving part of the IL.
*/
// Update 2008-10-30, SendMessage and ReceiveMessage should not be required. ensured by RTE. COM013
//StatusType SendMessage(MessageIdentifier , ApplicationDataRef );
// The service ReceiveMessage updates the application message
// referenced by <DataRef> with the data in the message object
// identified by <Message>. It resets all flags (Notification classes 1 and
// 3) associated with <Message>.
//StatusType ReceiveMessage ( MessageIdentifier , ApplicationDataRef );
// From Autosar
/* @req COM432 */
void Com_Init(const Com_ConfigType * config);
/* @req COM130 */
void Com_DeInit(void);
/* @req COM751 */
void Com_IpduGroupControl(Com_IpduGroupVector ipduGroupVector, boolean Initialize);
/* @req COM749 */
void Com_ClearIpduGroupVector(Com_IpduGroupVector ipduGroupVector);
/* @req COM750 */
void Com_SetIpduGroup(Com_IpduGroupVector ipduGroupVector, Com_IpduGroupIdType ipduGroupId, boolean bitval);
/* @req COM194 */
Com_StatusType Com_GetStatus(void);
#if ( COM_VERSION_INFO_API == STD_ON )
/* @req COM425 */
/* @req COM426 */
#define Com_GetVersionInfo(_vi) STD_GET_VERSION_INFO(_vi,COM)
#endif
/* Autosar 4 api */
/* @req COM693 */
BufReq_ReturnType Com_CopyTxData(PduIdType PduId, PduInfoType* PduInfoPtr, RetryInfoType* RetryInfoPtr, PduLengthType* TxDataCntPtr);
/* @req COM692 */
BufReq_ReturnType Com_CopyRxData(PduIdType PduId, const PduInfoType* PduInfoPtr, PduLengthType* RxBufferSizePtr);
/* @req COM691 */
BufReq_ReturnType Com_StartOfReception(PduIdType ComRxPduId, PduLengthType TpSduLength, PduLengthType* RxBufferSizePtr);
/* @req COM650 */
void Com_TpRxIndication(PduIdType PduId, NotifResultType Result);
/* @req COM725 */
void Com_TpTxConfirmation(PduIdType PduId, NotifResultType Result);
/* @req COM752 */
void Com_ReceptionDMControl(Com_IpduGroupVector ipduGroupVector);
/* @req COM784 */
void Com_SwitchIpduTxMode(PduIdType PduId, boolean Mode);
/* @req COM459 */ /* Partly */
#define COM_BUSY 0x81
#define COM_SERVICE_NOT_AVAILABLE 0x80
#endif /*COM_H_*/
|
2301_81045437/classic-platform
|
communication/Com/inc/Com.h
|
C
|
unknown
| 4,272
|
/*-------------------------------- 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 -----------------------------*/
/* This file should contain all callback functions
* and all configurable callout functions.
* */
/* !req COM731 */
#ifndef COM_CBK_H_
#define COM_CBK_H_
#endif /*COM_CBK_H_*/
|
2301_81045437/classic-platform
|
communication/Com/inc/Com_Cbk.h
|
C
|
unknown
| 953
|
/*-------------------------------- 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 COM_COM_H_
#define COM_COM_H_
#include <Com.h>
#include <PduR.h>
/* @req COM197 */
uint8 Com_SendSignal(Com_SignalIdType SignalId, const void *SignalDataPtr);
/* @req COM198 */
uint8 Com_ReceiveSignal(Com_SignalIdType SignalId, void* SignalDataPtr);
/* @req COM690 */
uint8 Com_ReceiveDynSignal(Com_SignalIdType SignalId, void* SignalDataPtr, uint16* Length);
/* @req COM627 */
uint8 Com_SendDynSignal(Com_SignalIdType SignalId, const void* SignalDataPtr, uint16 Length);
/* @req COM001 */
Std_ReturnType Com_TriggerTransmit(PduIdType TxPduId, PduInfoType *PduInfoPtr);
/* @req COM348 */
void Com_TriggerIPDUSend(PduIdType PduId);
/* @req COM123 */
void Com_RxIndication(PduIdType RxPduId, PduInfoType* PduInfoPtr);
/* @req COM124 */
void Com_TxConfirmation(PduIdType TxPduId);
/* Signal Groups */
/* @req COM200 */
uint8 Com_SendSignalGroup(Com_SignalGroupIdType SignalGroupId);
/* @req COM201 */
uint8 Com_ReceiveSignalGroup(Com_SignalGroupIdType SignalGroupId);
/* @req COM199 */
void Com_UpdateShadowSignal(Com_SignalIdType SignalId, const void *SignalDataPtr);
/* @req COM202 */
void Com_ReceiveShadowSignal(Com_SignalIdType SignalId, void *SignalDataPtr);
#endif /* COM_COM_H_ */
|
2301_81045437/classic-platform
|
communication/Com/inc/Com_Com.h
|
C
|
unknown
| 1,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 -----------------------------*/
#include "MemMap.h"
|
2301_81045437/classic-platform
|
communication/Com/inc/Com_MemMap.h
|
C
|
unknown
| 771
|
/*-------------------------------- 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 COM_SCHED_H_
#define COM_SCHED_H_
#include "Com.h"
/* @req COM398 */
void Com_MainFunctionRx(void);
/* @req COM399 */
void Com_MainFunctionTx(void);
void Com_MainFunctionRouteSignals(void);
#endif /* COM_SCHED_H_ */
|
2301_81045437/classic-platform
|
communication/Com/inc/Com_Sched.h
|
C
|
unknown
| 1,000
|
/*-------------------------------- 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 -----------------------------*/
/** @addtogroup Com COM module
* @{ */
/** @file Com_Types.h
* Definitions of configuration types and parameters for the COM module.
*/
#ifndef COM_TYPES_H_
#define COM_TYPES_H_
#include "ComStack_Types.h"
typedef uint16 Com_IpduGroupIdType;
typedef uint16 Com_SignalIdType;
typedef uint16 Com_SignalGroupIdType;
typedef uint16 Com_BitPositionType;
/* @req COM346 */
typedef boolean (*ComRxIPduCalloutType)(PduIdType PduId, const uint8 *IPduData);
/* @req COM700 */
typedef boolean (*ComTxIPduCalloutType)(PduIdType PduId, uint8 *IPduData);
/* @req COM555 COM554 COM491 COM556*/
typedef void (*ComNotificationCalloutType) (void);
#define COM_NO_FUNCTION_CALLOUT 0xFFFFFFFFu
#define NO_PDU_REFERENCE 0xFFFFu
typedef enum{
CONFIRMATION = 0,
TRANSMIT,
TRIGGERTRANSMIT
}ComTxIPduClearUpdateBitType;
typedef enum {
COM_UNINIT = 0,
COM_INIT
}Com_StatusType;
typedef enum {
COM_IMMEDIATE,
COM_DEFERRED
} Com_IPduSignalProcessingMode;
typedef enum {
COM_RECEIVE,
COM_SEND
} Com_IPduDirection;
typedef enum {
COM_BOOLEAN,
COM_UINT8,
COM_UINT16,
COM_UINT32,
COM_UINT64,
COM_UINT8_N,
COM_UINT8_DYN,
COM_SINT8,
COM_SINT16,
COM_SINT32,
COM_SINT64
} Com_SignalType;
#define COM_SIGNALTYPE_UNSIGNED FALSE
#define COM_SIGNALTYPE_SIGNED TRUE
typedef enum {
COM_PENDING,
COM_TRIGGERED,
COM_TRIGGERED_WITHOUT_REPETITION,
COM_TRIGGERED_ON_CHANGE_WITHOUT_REPETITION,
COM_TRIGGERED_ON_CHANGE
} ComTransferPropertyType;
typedef enum {
COM_DIRECT,
COM_MIXED,
COM_NONE,
COM_PERIODIC
} ComTxModeModeType;
typedef enum {
COM_ALWAYS,
COM_MASKED_NEW_DIFFERS_MASKED_OLD,
COM_MASKED_NEW_DIFFERS_X,
COM_MASKED_NEW_EQUALS_X,
COM_NEVER,
COM_NEW_IS_OUTSIDE,
COM_NEW_IS_WITHIN,
COM_ONE_EVERY_N
} ComFilterAlgorithmType;
typedef enum {
COM_BIG_ENDIAN,
COM_LITTLE_ENDIAN,
COM_OPAQUE
} ComSignalEndianess_type;
typedef enum {
COM_TIMEOUT_DATA_ACTION_NONE,
COM_TIMEOUT_DATA_ACTION_REPLACE
} ComRxDataTimeoutAction_type;
/*
typedef enum {
} ComTransmissionMode_type;
*/
// Shortcut macros
#define M_BOOLEAN boolean
#define M_UINT8 uint8
#define M_UINT16 uint16
#define M_UINT32 uint32
#define M_UINT64 uint64
#define M_UINT8_N uint8
#define M_SINT8 sint8
#define M_SINT16 sint16
#define M_SINT32 sint32
#define M_SINT64 sint64
#define SignalTypeToSize(type,length) \
((type == COM_UINT8) ? sizeof(uint8) : \
(type == COM_UINT16) ? sizeof(uint16) : \
(type == COM_UINT32) ? sizeof(uint32) : \
(type == COM_UINT64) ? sizeof(uint64) : \
(type == COM_UINT8_N) ? (sizeof(uint8) * (length)) : \
(type == COM_SINT8) ? sizeof(sint8) : \
(type == COM_SINT16) ? sizeof(sint16) : \
(type == COM_SINT32) ? sizeof(sint32) : \
(type == COM_SINT64) ? sizeof(sint64) : sizeof(boolean)) \
#define SignalTypeSignedness(type) \
(( (type == COM_SINT8) || (type == COM_SINT16) || (type == COM_SINT32 || (type == COM_SINT64) ) ? \
COM_SIGNALTYPE_SIGNED : COM_SIGNALTYPE_UNSIGNED)
/** Filter configuration type.
* NOT SUPPORTED
*/
typedef struct {
/** The algorithm that this filter uses. */
ComFilterAlgorithmType ComFilterAlgorithm;
/** Filter mask. */
uint32 ComFilterMask;
/** Max value for filter. */
uint32 ComFilterMax;
/** Min value for filter. */
uint32 ComFilterMin;
/** Offset for filter. */
uint32 ComFilterOffset;
uint32 ComFilterPeriodFactor;
uint32 ComFilterX;
uint32 ComFilterArcN;
uint32 ComFilterArcNewValue;
uint32 ComFilterArcOldValue;
} ComFilter_type;
/** Configuration structure for group signals */
typedef struct {
/** Starting position (bit) of the signal within the IPDU.
* Range 0 to 63.
*/
const Com_BitPositionType ComBitPosition;
/** The size of the signal in bits.
* Range 0 to 64.
*/
const uint16 ComBitSize;
/** Identifier for the signal.
* Should be the same value as the index in the COM signal array.
*/
const uint16 ComHandleId;
/** Defines the endianess of the signal's network representation. */
const ComSignalEndianess_type ComSignalEndianess;
/** Value used to initialize this signal. */
const void *ComSignalInitValue;
/** Defines the type of the signal. */
const Com_SignalType ComSignalType;
/** Defines the handle for the associated signal group */
const uint16 ComSigGrpHandleId;
/** Filter for this signal.
* NOT SUPPORTED
*/
//const ComFilter_type ComFilter;
/* Pointer to the shadow buffer of the signal group that this group signal is contained in.
*
* This is initialized by Com_Init() and should not be configured.
*/
//void *Com_Arc_ShadowBuffer;
/* Callback function used when an invalid signal is received. */
// ComInvalidNotification;
//uint8 ComSignalDataInvalidValue;
/* IPDU id of the IPDU that this signal belongs to.
*
* This is initialized by Com_Init() and should not be configured.
*/
//const uint8 ComIPduHandleId;
//const uint8 ComSignalUpdated;
/** Marks the end of list for the configuration array. */
const uint8 Com_Arc_EOL;
} ComGroupSignal_type;
/** Configuration structure for signals and signal groups. */
typedef struct {
/** Starting position (bit) of the signal within the IPDU.
* Range 0 to 2031.
*/
const Com_BitPositionType ComBitPosition;
/** Ending position (bit) of the signal group within the IPDU.
* Range 0 to 2031.
* Only relevant to Signal group
*/
const Com_BitPositionType ComEndBitPosition;
/** The size of the signal in bits.
* Range 0 to 63. 16 bit variable required to support UINT8_DYN signals(Max 4095* 8 bits)
*/
const uint16 ComBitSize;
/** Notification function for error notification. */
const uint32 ComErrorNotification;
/** First timeout period for deadline monitoring. */
const uint32 ComFirstTimeoutFactor;
/** Identifier for the signal.
* Should be the same value as the index in the COM signal array.
*/
const uint16 ComHandleId;
/** Tx and Rx notification function. */
const uint32 ComNotification;
/** Action to be performed when a reception timeout occurs. */
const ComRxDataTimeoutAction_type ComRxDataTimeoutAction;
/** Defines the endianess of the signal's network representation. */
const ComSignalEndianess_type ComSignalEndianess;
/** Value used to initialized this signal. */
const void *ComSignalInitValue;
/** The number of bytes if the signal has type UINT8_N;
* Range 1 to 8.
*/
//const uint8 ComSignalLength;
/** Defines the type of the signal. */
const Com_SignalType ComSignalType;
/** Timeout period for deadline monitoring. */
const uint32 ComTimeoutFactor;
/** Timeout notification function. */
const uint32 ComTimeoutNotification;
/** Transfer property of the signal */
const ComTransferPropertyType ComTransferProperty;
/** The bit position in the PDU for this signal's update bit.
* Range 0 to 2031.
* Only applicable if an update bit is used. NULL otherwise.
*/
const Com_BitPositionType ComUpdateBitPosition;
/** Marks if this signal uses an update bit.
* Should be set to one if an update bit is used.
*/
const boolean ComSignalArcUseUpdateBit;
/** Filter for this signal.
* NOT SUPPORTED.
*/
//const ComFilter_type ComFilter;
/** Marks if this signal is a signal group.
* Should be set to 1 if the signal is a signal group.
*/
const boolean Com_Arc_IsSignalGroup;
/** Array of group signals.
* Only applicable if this signal is a signal group.
*/
const ComGroupSignal_type * const *ComGroupSignal;
const uint8 *Com_Arc_ShadowBuffer_Mask;
//void *Com_Arc_IPduDataPtr;
/* Pointer to the data storage of this signals IPDU.
* This is initialized by Com_Init() and should not be configured.
*/
//const void *ComIPduDataPtr;
/* IPDU id of the IPDU that this signal belongs to.
* This is initialized by Com_Init() and should not be configured.
*/
const uint16 ComIPduHandleId;
uint8 ComOsekNmNetId; /* Network Id of the associated communication channel */
uint8 ComOsekNmNodeId; /* Node Id of the associated ComSignal */
//const uint8 ComSignalUpdated;
/* Callback function used when an invalid signal is received.
*/
// ComInvalidNotification;
//uint8 ComSignalDataInvalidValue;
/* Action to be taken if an invalid signal is received.
*/
// ComDataInvalidAction;
/* Determines if any gateway operation is required for the signal */
const boolean ComSigGwRoutingReq;
/** Marks the end of list for the signal configuration array. */
const uint8 Com_Arc_EOL;
} ComSignal_type;
/** Configuration structure for Tx-mode for I-PDUs. */
typedef struct {
/** Transmission mode for this IPdu. */
const ComTxModeModeType ComTxModeMode;
/** Defines the number of times this IPdu will be sent in each IPdu cycle.
* Should be set to 0 for DIRECT transmission mode and >0 for DIRECT/N-times mode.
*/
const uint8 ComTxModeNumberOfRepetitions;
/** Defines the period of the transmissions in DIRECT/N-times and MIXED transmission modes. */
const uint32 ComTxModeRepetitionPeriodFactor;
/** Time before first transmission of this IPDU. (i.e. between the ipdu group start and this IPDU is sent for the first time. */
const uint32 ComTxModeTimeOffsetFactor;
/** Period of cyclic transmission. */
const uint32 ComTxModeTimePeriodFactor;
} ComTxMode_type;
/** Extra configuration structure for Tx I-PDUs. */
typedef struct {
/** Minimum delay between successive transmissions of the IPdu. */
const uint32 ComTxIPduMinimumDelayFactor;
/** Defines when the I-PDU Tx update bit shall be cleared.*/
const ComTxIPduClearUpdateBitType ComTxIPduClearUpdateBit;
/** COM will fill unused areas within an IPdu with this bit patter.
*/
const uint8 ComTxIPduUnusedAreasDefault;
/** Transmission modes for the IPdu.
* TMS is not implemented so only one static transmission mode is supported.
*/
const ComTxMode_type ComTxModeTrue;
const ComTxMode_type ComTxModeFalse;
} ComTxIPdu_type;
/** Configuration structure for I-PDU counters */
typedef struct {
/* Range of counter e.g 8 bit counter has a range of 256 */
const uint16 ComIPduCntrRange;
/* Starting bit (lsbit) of the counter in the IPDU */
const uint16 ComIPduCntrStartPos;
/* Maximum tolerable threshold step */
const uint8 ComIPduCntrThrshldStep;
/* Call back for IPDU counter error notification */
const uint32 ComIPduCntErrNotification;
/* Index of the counter used */
const uint16 ComIPduCntrIndex;
} ComIPduCounter_type;
/** Configuration structure for I-PDU groups */
typedef struct {
/** ID of this group.
*/
const Com_IpduGroupIdType ComIPduGroupHandleId;
/** Marks the end of list for the I-PDU group configuration array. */
const uint8 Com_Arc_EOL;
} ComIPduGroup_type;
/** Configuration structure for an I-PDU. */
typedef struct {
/** Callout function of this IPDU.
* The callout function is an optional function used both on sender and receiver side.
* If configured, it determines whether an IPdu is considered for further processing. If
* the callout return false the IPdu will not be received/sent.
*/
uint32 ComRxIPduCallout;
uint32 ComTxIPduCallout;
uint32 ComTriggerTransmitIPduCallout;
/** The outgoing PDU id. For polite PDU id handling. */
const PduIdType ArcIPduOutgoingId;
/** Signal processing mode for this IPDU. */
const Com_IPduSignalProcessingMode ComIPduSignalProcessing;
/** Size of the IPDU in bytes.
* Range 0-8 for CAN and LIN and 0-256 for FlexRay.
*/
const uint16 ComIPduSize;
/** The direction of the IPDU. Receive or Send. */
const Com_IPduDirection ComIPduDirection;
/** References to the IPDU groups that this IPDU belongs to. */
const ComIPduGroup_type *const ComIPduGroupRefs;
/** Container of transmission related parameters. */
const ComTxIPdu_type ComTxIPdu;
/** References to all signals and signal groups contained in this IPDU.
* It probably makes little sense not to define at least one signal or signal group for each IPDU.
*/
const ComSignal_type * const *ComIPduSignalRef;
const ComSignal_type * const ComIPduDynSignalRef;
/*
* The following two variables are used to control the per I-PDU based Rx/Tx-deadline monitoring.
*/
//const uint32 Com_Arc_DeadlineCounter;
//const uint32 Com_Arc_TimeoutFactor;
/* Transmission related timers and parameters.
* These are internal variables and should not be configured.
*/
//ComTxIPduTimer_type Com_Arc_TxIPduTimers;
/* Reference to ComIpduCounterStructure */
const ComIPduCounter_type * const ComIpduCounterRef;
/* Gateway routing required for this IPdu */
const boolean ComIPduGwRoutingReq;
/* Gateway signal description handle for this IPdu */
const uint16 * ComIPduGwMapSigDescHandle;
/** Marks the end of list for this configuration array. */
const uint8 Com_Arc_EOL;
} ComIPdu_type;
/* Type of signal configuration used in gateway mapping */
typedef enum{
COM_SIGNAL_REFERENCE,
COM_GROUP_SIGNAL_REFERENCE,
COM_SIGNAL_GROUP_REFERENCE,
GATEWAY_SIGNAL_DESCRIPTION
} ComGwSignalRef_type;
/* Structure of gateway source description */
typedef struct {
/** Starting position (bit) of the signal within the IPDU.
* Range 0 to 63.
*/
const Com_BitPositionType ComBitPosition;
/** The size of the signal in bits.
* Range 0 to 64.
*/
const uint16 ComBitSize;
/** Defines the endianess of the signal's network representation. */
const ComSignalEndianess_type ComSignalEndianess;
/** Value used to initialize this signal. */
const void *ComSignalInitValue;
/** Defines the type of the signal. */
const Com_SignalType ComSignalType;
/** The bit position in the PDU for this signal's update bit.
* Range 0 to 2031.
* Only applicable if an update bit is used. NULL otherwise.
*/
const Com_BitPositionType ComUpdateBitPosition;
/** Marks if this signal uses an update bit.
* Should be set to one if an update bit is used.
*/
const boolean ComSignalArcUseUpdateBit;
/** IPDU id of the IPDU that this signal belongs to.
*/
const uint16 ComIPduHandleId;
/** Marks the end of list for this configuration array. */
const uint8 Com_Arc_EOL;
}ComGwSrcDesc_type;
/* Structure of gateway destination description */
typedef struct {
/** The size of the signal in bits.
* Range 0 to 64.
*/
const uint16 ComBitSize;
/** Value used to initialized this signal. */
const void *ComSignalInitValue;
/** Starting position (bit) of the signal within the IPDU.
* Range 0 to 63.
*/
const Com_BitPositionType ComBitPosition;
/** Defines the type of the signal. */
const Com_SignalType ComSignalType;
/** Defines the endianess of the signal's network representation. */
const ComSignalEndianess_type ComSignalEndianess;
/** The bit position in the PDU for this signal's update bit.
* Range 0 to 2031.
* Only applicable if an update bit is used. NULL otherwise.
*/
const Com_BitPositionType ComUpdateBitPosition;
/** Marks if this signal uses an update bit.
* Should be set to one if an update bit is used.
*/
const boolean ComSignalArcUseUpdateBit;
/** Transfer property of the signal */
const ComTransferPropertyType ComTransferProperty;
/** IPDU id of the IPDU that this signal belongs to.
*/
const uint16 ComIPduHandleId;
/** Marks the end of list for this configuration array. */
const uint8 Com_Arc_EOL;
}ComGwDestnDesc_type;
typedef struct {
const ComGwSignalRef_type ComGwDestinationSignalRef;
const uint16 ComGwDestinationSignalHandle;
const uint8 Com_Arc_EOL;
} ComGwDestn_type;
/* @req COM377 */
typedef struct {
const ComGwSignalRef_type ComGwSourceSignalRef;
const uint16 ComGwSourceSignalHandle;
const ComGwDestn_type * ComGwDestinationRef;
const uint8 ComGwNoOfDesitnationRoutes;
const uint8 Com_Arc_EOL;
}ComGwMapping_type;
/** Top-level configuration container for COM. Exists once per configuration. */
typedef struct {
/** The ID of this configuration. This is returned by Com_GetConfigurationId(); */
const uint8 ComConfigurationId;
/* The number of IPdus */
const uint16 ComNofIPdus;
/* The number of signals */
const uint16 ComNofSignals;
/* The number of group signals */
const uint16 ComNofGroupSignals;
/* Signal Gateway mappings */
const ComGwMapping_type * ComGwMappingRef;
/** IPDU definitions */
const ComIPdu_type * const ComIPdu;
//uint16 Com_Arc_NIPdu;
/** IPDU group definitions */
const ComIPduGroup_type * const ComIPduGroup;
/** Signal definitions */
const ComSignal_type *const ComSignal;
// Signal group definitions
//ComSignalGroup_type *ComSignalGroup;
/** Group signal definitions */
const ComGroupSignal_type * const ComGroupSignal;
/** Reference to Gateway source description */
const ComGwSrcDesc_type * ComGwSrcDesc;
/** Reference to Gateway destination description */
const ComGwDestnDesc_type * ComGwDestnDesc;
} Com_ConfigType;
#endif /*COM_TYPES_H_*/
/** @} */
|
2301_81045437/classic-platform
|
communication/Com/inc/Com_Types.h
|
C
|
unknown
| 19,239
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/* General requirements on Com module */
/* @req COM584 */
/* !req COM220 */ /* Include file structure */
/* !req COM673 */ /* Version check */
/* !req COM010 */ /* IMPROVEMENT: OSEK-COM, what is implemented? */
/* !req COM011 */ /* IMPROVEMENT: OSEK-COM, what is implemented? */
/* !req COM012 */ /* IMPROVEMENT: OSEK-COM, what is implemented? */
/* !req COM013 */ /* IMPROVEMENT: OSEK-COM, what is implemented? */
/* COM759, COM760: ComIPduType not used */
/* !req COM759 */
/* !req COM760 */
/* @req COM059 */ /* Interpretation of update-bit */
/* !req COM320 */ /* !req COM321 */ /* Reentrant/Non-reentrant functions */
/* @req COM606 */ /* Pre-compile */
/* @req COM608 */ /* Post-build */
#include "arc_assert.h"
#include <string.h>
#include "Com.h"
#include "Com_Arc_Types.h"
#include "Com_Internal.h"
#include "Com_misc.h"
#include "Cpu.h"
#include "SchM_Com.h"
#include "debug.h"
#define COM_START_SEC_VAR_INIT_UNSPECIFIED
#include "Com_MemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/
static Com_StatusType initStatus = COM_UNINIT;
#define COM_STOP_SEC_VAR_INIT_UNSPECIFIED
#include "Com_MemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/
#define COM_START_SEC_VAR_CLEARED_UNSPECIFIED
#include "Com_MemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/
const Com_ConfigType * ComConfig;
#define COM_STOP_SEC_VAR_CLEARED_UNSPECIFIED
#include "Com_MemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/
#define COM_START_SEC_VAR_CLEARED_UNSPECIFIED
#include "Com_MemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/
static Com_Arc_IPdu_type Com_Arc_IPdu[COM_MAX_N_IPDUS];
#define COM_STOP_SEC_VAR_CLEARED_UNSPECIFIED
#include "Com_MemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/
#define COM_START_SEC_VAR_CLEARED_UNSPECIFIED
#include "Com_MemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/
static Com_Arc_Signal_type Com_Arc_Signal[COM_MAX_N_SIGNALS];
#define COM_STOP_SEC_VAR_CLEARED_UNSPECIFIED
#include "Com_MemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/
#define COM_START_SEC_VAR_CLEARED_UNSPECIFIED
#include "Com_MemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/
Com_BufferPduStateType Com_BufferPduState[COM_MAX_N_IPDUS]={{0,0}};
#define COM_STOP_SEC_VAR_CLEARED_UNSPECIFIED
#include "Com_MemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/
#if (COM_SIG_GATEWAY_ENABLE == STD_ON)
#define COM_START_SEC_VAR_CLEARED_UNSPECIFIED
#include "Com_MemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/
static Com_Arc_GwSrcDesc_type Com_Arc_GwSrcDescSignals[COM_MAX_N_SUPPORTED_GWSOURCE_DESCRIPTIONS] = {{0}};
#define COM_STOP_SEC_VAR_CLEARED_UNSPECIFIED
#include "Com_MemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/
#endif
#if (COM_MAX_N_GROUP_SIGNALS != 0)
#define COM_START_SEC_VAR_CLEARED_UNSPECIFIED
#include "Com_MemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/
static Com_Arc_GroupSignal_type Com_Arc_GroupSignal[COM_MAX_N_GROUP_SIGNALS];
#define COM_STOP_SEC_VAR_CLEARED_UNSPECIFIED
#include "Com_MemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/
#endif
/* Data, deferred data and shadow buffer */
#define COM_START_SEC_VAR_CLEARED_UNSPECIFIED
#include "Com_MemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/
static uint8 Com_Arc_Buffer[COM_MAX_BUFFER_SIZE];
#define COM_STOP_SEC_VAR_CLEARED_UNSPECIFIED
#include "Com_MemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/
const Com_Arc_Config_type Com_Arc_Config = {
.ComIPdu = Com_Arc_IPdu,
.ComSignal = Com_Arc_Signal,
#if (COM_MAX_N_GROUP_SIGNALS != 0)
.ComGroupSignal = Com_Arc_GroupSignal,
#else
.ComGroupSignal = NULL,
#endif
#if (COM_SIG_GATEWAY_ENABLE == STD_ON)
.ComGwSrcDescSignal = Com_Arc_GwSrcDescSignals
#else
.ComGwSrcDescSignal = NULL
#endif
};
void Com_Init(const Com_ConfigType *config ) {
DEBUG(DEBUG_LOW, "--Initialization of COM--\n");
/* !req COM328 */ /* Shall not enable inter-ECU communication */
/* !req COM483 */
/* @req COM128 */
/* @req COM217 */
/* @req COM444 */
/* @req COM772 */ /* If timeout set to 0*/
boolean failure = FALSE;
/* @req COM433 */
if( NULL == config ) {
DET_REPORTERROR(COM_INIT_ID, COM_E_PARAM_POINTER);
/*lint -e{904} ARGUMENT CHECK */
return;
}
ComConfig = config;
boolean dataChanged = FALSE;
const ComSignal_type *Signal;
const ComGroupSignal_type *GroupSignal;
uint16 bufferIndex = 0;
for (uint16 i = 0; 0 == ComConfig->ComIPdu[i].Com_Arc_EOL; i++) {
boolean pduHasGroupSignal = FALSE;
const ComIPdu_type *IPdu = GET_IPdu(i);
Com_Arc_IPdu_type *Arc_IPdu = GET_ArcIPdu(i);
Arc_IPdu->Com_Arc_DynSignalLength = 0;
Arc_IPdu->Com_Arc_IpduRxDMControl = TRUE; /* Enabling by default, assign 0 if not */
Arc_IPdu->Com_Arc_TxIPduTimers.ComTxDMTimer = 0; /* Initialise Tx deadline timer*/
if (i >= ComConfig->ComNofIPdus) {
DET_REPORTERROR(COM_INIT_ID ,COM_E_TOO_MANY_IPDU);
failure = TRUE;
break;
}
/* Set the data ptr for this Pdu */
Arc_IPdu->ComIPduDataPtr = (void *)&Com_Arc_Buffer[bufferIndex];
bufferIndex += IPdu->ComIPduSize;
/* Set TMS to TRUE as default */
Arc_IPdu->Com_Arc_IpduTxMode = TRUE;
/* If this is a TX and cyclic IPdu, configure the first deadline.*/
if ( (IPdu->ComIPduDirection == COM_SEND) &&
((IPdu->ComTxIPdu.ComTxModeTrue.ComTxModeMode == COM_PERIODIC) || (IPdu->ComTxIPdu.ComTxModeTrue.ComTxModeMode == COM_MIXED))) {
Arc_IPdu->Com_Arc_TxIPduTimers.ComTxModeTimePeriodTimer = IPdu->ComTxIPdu.ComTxModeTrue.ComTxModeTimeOffsetFactor + 1;
}
/* Initialize the memory with the default value.*/
/* @req COM015 */
if (IPdu->ComIPduDirection == COM_SEND) {
memset((void *)Arc_IPdu->ComIPduDataPtr, IPdu->ComTxIPdu.ComTxIPduUnusedAreasDefault, IPdu->ComIPduSize);
/* It is not clear if this value should be set 0 or the configured value. This means that the frames
* will be sent the first time Com_MainFunctionTx()
*/
Arc_IPdu->Com_Arc_TxIPduTimers.ComTxIPduMinimumDelayTimer = 0;
}
/* For each signal in this PDU.*/
for (uint16 j = 0; (IPdu->ComIPduSignalRef != NULL) && (IPdu->ComIPduSignalRef[j] != NULL) ; j++) {
Signal = IPdu->ComIPduSignalRef[j];
Com_Arc_Signal_type * Arc_Signal = GET_ArcSignal(Signal->ComHandleId);
/* Configure signal deadline monitoring if used.*/
/* @req COM333 */ /* If timeout set to 0*/
/* @req COM292 */ /* handled in generator*/
/* @req COM290 */ /* handled also in generator*/
/* the signal does not use an update bit, and should use per I-PDU deadline monitoring.*/
/* the signal uses an update bit, and hence has its own deadline monitoring.*/
if (Signal->ComTimeoutFactor > 0){
if(IPdu->ComIPduDirection == COM_RECEIVE ){
/* Configure the deadline counter */
Arc_Signal->Com_Arc_DeadlineCounter = Signal->ComFirstTimeoutFactor;
} else {
/* @req COM445 */ /* handled in generator */
/* @req COM481 */
/* if one of the signal enabled for DM this means DM exists for this pdu */
Arc_IPdu->Com_Arc_TxDeadlineCounter = Signal->ComTimeoutFactor;
}
}
/* Clear update bits*/
/* @req COM117 */
if (TRUE == Signal->ComSignalArcUseUpdateBit) {
/*lint -e{9016} Array indexing couldn't be implemented, as parameters are of different data types */
CLEARBIT(Arc_IPdu->ComIPduDataPtr, Signal->ComUpdateBitPosition);
}
/* If this signal is a signal group*/
if (TRUE == Signal->Com_Arc_IsSignalGroup) {
pduHasGroupSignal = TRUE;
Arc_Signal->Com_Arc_ShadowBuffer = (void *)&Com_Arc_Buffer[bufferIndex];
/* For each group signal of this signal group.*/
for(uint8 h = 0; Signal->ComGroupSignal[h] != NULL; h++) {
GroupSignal = Signal->ComGroupSignal[h];
Com_Arc_GroupSignal_type *Arc_GroupSignal = GET_ArcGroupSignal(GroupSignal->ComHandleId);
/* Set pointer to shadow buffer*/
/*lint -e{9005} Com_Arc_Buffer can be modified via Arc_GroupSignal->Com_Arc_ShadowBuffer pointer*/
Arc_GroupSignal->Com_Arc_ShadowBuffer = ((void *)Arc_Signal->Com_Arc_ShadowBuffer);
/* Initialize shadowbuffer.*/
/* @req COM484 */
Com_Misc_UpdateShadowSignal(GroupSignal->ComHandleId, GroupSignal->ComSignalInitValue);
}
/* Initialize group signal data from shadowbuffer.*/
/* @req COM098 */
Com_Misc_CopySignalGroupDataFromShadowBufferToPdu(Signal->ComHandleId, false, &dataChanged);
} else {
/* Initialize signal data.*/
/* @req COM098 */
Com_Misc_WriteSignalDataToPdu(
Signal->ComSignalInitValue,
Signal->ComSignalType,
Arc_IPdu->ComIPduDataPtr,
Signal->ComBitPosition,
Signal->ComBitSize,
Signal->ComSignalEndianess,
&dataChanged);
}
}
if( TRUE == pduHasGroupSignal ) {
/* This pdu has includes group signals. Means that a shodow buffer was set up.
* Increment index. */
bufferIndex += IPdu->ComIPduSize;
}
if ((IPdu->ComIPduDirection == COM_RECEIVE) && (IPdu->ComIPduSignalProcessing == COM_DEFERRED)) {
/* Set pointer to the deferred buffer */
Arc_IPdu->ComIPduDeferredDataPtr = (void *)&Com_Arc_Buffer[bufferIndex];
bufferIndex += IPdu->ComIPduSize;
/* Copy the initialized pdu to deferred buffer*/
memcpy(Arc_IPdu->ComIPduDeferredDataPtr,Arc_IPdu->ComIPduDataPtr,IPdu->ComIPduSize);
}
#if (COM_SIG_GATEWAY_ENABLE == STD_ON)
const ComGwDestnDesc_type * GwDestnPtr;
/* Set the initial values for Destination description signals*/
if((NULL != IPdu->ComIPduGwMapSigDescHandle) && (IPdu->ComIPduDirection== COM_SEND)){
for (uint16 k=0; IPdu->ComIPduGwMapSigDescHandle[k] != INVALID_GWSIGNAL_DESCRIPTION_HANDLE; k++){
GwDestnPtr = GET_GwDestnSigDesc(IPdu->ComIPduGwMapSigDescHandle[k]);
Com_Misc_WriteSignalDataToPdu(
GwDestnPtr->ComSignalInitValue,
GwDestnPtr->ComSignalType,
Arc_IPdu->ComIPduDataPtr,
GwDestnPtr->ComBitPosition,
GwDestnPtr->ComBitSize,
GwDestnPtr->ComSignalEndianess,
&dataChanged);
}
}
#endif
}
for (uint16 i = 0; i < ComConfig->ComNofIPdus; i++) {
Com_BufferPduState[i].currentPosition = 0;
Com_BufferPduState[i].locked = false;
}
#if(COM_IPDU_COUNTING_ENABLE == STD_ON )
/* @req COM687 */
ResetInternalCounterRxStartSts();
#endif
/* An error occurred.*/
if (TRUE == failure) {
DEBUG(DEBUG_LOW, "--Initialization of COM failed--\n");
} else {
initStatus = COM_INIT;
DEBUG(DEBUG_LOW, "--Initialization of COM completed--\n");
}
}
void Com_DeInit( void ) {
if(COM_INIT != initStatus) {
DET_REPORTERROR(COM_DEINIT_ID, COM_E_UNINIT);
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return;
}
/* @req COM129 */
for (uint16 i = 0; 0 == ComConfig->ComIPdu[i].Com_Arc_EOL; i++) {
Com_Arc_Config.ComIPdu[i].Com_Arc_IpduStarted = FALSE;
}
initStatus = COM_UNINIT;
}
Com_StatusType Com_GetStatus( void )
{
return initStatus;
}
/* Prerequisite com_init()function called */
void Com_IpduGroupControl(Com_IpduGroupVector ipduGroupVector, boolean Initialize)
{
/* !req COM614 */
/* Starting groups */
/* @req COM114 */
/* !req COM787 */
/* !req COM222 */
/* @req COM733 */
/* !req COM740 */
/* Stopping groups */
/* !req COM479 */
/* !req COM713 */
/* !req COM714 */
const ComIPdu_type * IPdu;
const ComSignal_type * comSignal;
Com_Arc_Signal_type * Arc_Signal;
if(COM_INIT != initStatus) {
DET_REPORTERROR(COM_IPDUGROUPCONTROL_ID, COM_E_UNINIT);
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return;
}
for (uint16 i = 0; 0 == ComConfig->ComIPdu[i].Com_Arc_EOL; i++) {
const ComIPduGroup_type *const groupRefs = ComConfig->ComIPdu[i].ComIPduGroupRefs;
boolean started = FALSE;
for(uint32 gri=0; ((0 == groupRefs[gri].Com_Arc_EOL) && (FALSE == started)); gri++) {
uint16 byteIndex;
uint8 bitIndex;
byteIndex = groupRefs[gri].ComIPduGroupHandleId / 8;
bitIndex = groupRefs[gri].ComIPduGroupHandleId % 8;
/* @req COM771 */
started |= ((ipduGroupVector[byteIndex] >> bitIndex) & 1u);
}
if((Com_Arc_Config.ComIPdu[i].Com_Arc_IpduStarted != started)||(Initialize == TRUE)){
/* @req COM612 */
/* @req COM613 */
/* @req COM615 */
Com_Arc_Config.ComIPdu[i].Com_Arc_IpduStarted = started;
#if(COM_IPDU_COUNTING_ENABLE == STD_ON )
/* @req COM687 */
if ((TRUE == Initialize) && (TRUE == started) && (ComConfig->ComIPdu[i].ComIpduCounterRef != NULL) ) {
/*Partial fulfillment of COM787 - Only action for IPDU counters are implemented*/
uint16 idx = ComConfig->ComIPdu[i].ComIpduCounterRef->ComIPduCntrIndex;
if (ComConfig->ComIPdu[i].ComIPduDirection == COM_SEND) {
ResetInternalCounter(idx);
} else {
ReSetInternalRxStartSts(idx);
}
}
#endif
/* @req COM115 */ /* cancel deadline monitoring if stopped*/
/* !req COM787 party satisfied for DM,If an I-PDU is started as result of a call Com_IpduGroupControl
2) timeout attributes of I-PDUs for deadline monitoring aspect: all timeout timers (ComFirstTimeout, ComTimeout) shall restart */
IPdu = GET_IPdu(i);
SchM_Enter_Com_EA_0(); /* DM space */
/* RX PDUS */
if (IPdu->ComIPduDirection == COM_RECEIVE) {
if(TRUE == started) {
if(TRUE == Com_Arc_Config.ComIPdu[i].Com_Arc_IpduRxDMControl) {/* if running */
/* timeout attributes of I-PDUs for deadline monitoring aspect:
* all timeout timers (ComFirstTimeout, ComTimeout) shall restart */
for (uint16 j = 0; IPdu->ComIPduSignalRef[j] != NULL; j++) {
comSignal = IPdu->ComIPduSignalRef[j];
Arc_Signal = GET_ArcSignal(comSignal->ComHandleId);
if(0 < comSignal->ComTimeoutFactor) {
if(0 < comSignal->ComFirstTimeoutFactor) {
Arc_Signal->Com_Arc_DeadlineCounter = comSignal->ComFirstTimeoutFactor;
} else {
Arc_Signal->Com_Arc_DeadlineCounter = 0;
}
}
}
}
} else {
/* disable rx monitoring */
/* @req COM685 */
/* @req COM115 */ /* cancel pending confirmations and it does automatically when Com_Arc_IpduRxDMControl is 0 */
/* rx DM timers are re initialised when it is enabled back */
Com_Arc_Config.ComIPdu[i].Com_Arc_IpduRxDMControl = FALSE;
}
} else {/* TX PDUS */
const ComTxMode_type *txModePtr;
if( TRUE == Com_Arc_Config.ComIPdu[i].Com_Arc_IpduTxMode ) {
txModePtr = &IPdu->ComTxIPdu.ComTxModeTrue;
}
else {
txModePtr = &IPdu->ComTxIPdu.ComTxModeFalse;
}
if((TRUE == started) && (0 < Com_Arc_Config.ComIPdu[i].Com_Arc_TxDeadlineCounter)) {
/* can pdus be started two consecutive times without state change? */
Com_Arc_Config.ComIPdu[i].Com_Arc_TxIPduTimers.ComTxDMTimer = 0;
/* @req COM696 - redundant? */
if (txModePtr->ComTxModeMode == COM_NONE) {
Com_Arc_Config.ComIPdu[i].Com_Arc_TxIPduTimers.ComTxDMTimer = Com_Arc_Config.ComIPdu[i].Com_Arc_TxDeadlineCounter;
}
} else {
/* fall back in any case here */
/* @req COM685 */
/* @req COM115 */
/* cancel pending confirmations and ComTxDMTimer */
Com_Arc_Config.ComIPdu[i].Com_Arc_TxIPduTimers.ComTxDMTimer = 0;
Com_Arc_Config.ComIPdu[i].Com_Arc_TxIPduTimers.ComTxIPduNumberOfTxConfirmations = 0;
}
if ((TRUE == Initialize) && (TRUE == started)) {
/* Only parts of COM622 and COM787 are supported */
Com_Arc_Config.ComIPdu[i].Com_Arc_TxIPduTimers.ComTxModeRepetitionPeriodTimer = 0;
Com_Arc_Config.ComIPdu[i].Com_Arc_TxIPduTimers.ComTxIPduNumberOfRepetitionsLeft = 0;
if ((txModePtr->ComTxModeMode == COM_PERIODIC) ||
(txModePtr->ComTxModeMode == COM_MIXED)) {
Com_Arc_Config.ComIPdu[i].Com_Arc_TxIPduTimers.ComTxModeTimePeriodTimer =
txModePtr->ComTxModeTimeOffsetFactor + 1;
}
}
}
SchM_Exit_Com_EA_0(); /* DM space */
}
}
}
void Com_ClearIpduGroupVector(Com_IpduGroupVector ipduGroupVector)
{
if(COM_INIT != initStatus) {
DET_REPORTERROR(COM_CLEARIPDUGROUPVECTOR_ID, COM_E_UNINIT);
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return;
}
memset(ipduGroupVector, 0, sizeof(Com_IpduGroupVector));
}
void Com_SetIpduGroup(Com_IpduGroupVector ipduGroupVector, Com_IpduGroupIdType ipduGroupId, boolean bitval)
{
if(COM_INIT != initStatus) {
DET_REPORTERROR(COM_SETIPDUGROUP_ID, COM_E_UNINIT);
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return;
}
uint16 byteIndex;
uint8 bitIndex;
byteIndex = ipduGroupId / 8;
bitIndex = ipduGroupId % 8;
/* @req COM623 */
if( TRUE == bitval ) {
/*lint -e{734} bit-index is limited to value 7,result will not loose precision */
ipduGroupVector[byteIndex] |= (1u<<bitIndex);
} else {
ipduGroupVector[byteIndex] &= ~(1u<<bitIndex);
}
}
/**
*
* @param PduId
* @param PduInfoPtr
* @param RetryInfoPtr not supported
* @param TxDataCntPtr
* @return
*/
/*lint -e{818} PduInfoPtr is declared as pointing to const in version 4.2.2*/
BufReq_ReturnType Com_CopyTxData(PduIdType PduId, PduInfoType* PduInfoPtr, RetryInfoType* RetryInfoPtr, PduLengthType* TxDataCntPtr) {
/* IMPROVEMENT: Validate PduId, etc? */
/* !req COM663*/
/* !req COM783*/ /* Do not copy any data and return BUFREQ_E_NOT_OK if pdu group stopped */
BufReq_ReturnType r = BUFREQ_OK;
if(COM_INIT != initStatus) {
DET_REPORTERROR(COM_COPYTXDATA_ID, COM_E_UNINIT);
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return BUFREQ_NOT_OK;
}
const ComIPdu_type *IPdu = GET_IPdu(PduId);
boolean dirOk = ComConfig->ComIPdu[PduId].ComIPduDirection == COM_SEND;
boolean sizeOk;
//lint -estring(920,pointer) /* cast to void */
(void)RetryInfoPtr; /* get rid of compiler warning*/
//lint +estring(920,pointer) /* cast to void */
SchM_Enter_Com_EA_0();
sizeOk = (IPdu->ComIPduSize >= (Com_BufferPduState[PduId].currentPosition + PduInfoPtr->SduLength))? TRUE : FALSE;
Com_BufferPduState[PduId].locked = TRUE;
if ((TRUE == dirOk) && (TRUE == sizeOk)) {
const uint8* source = (uint8 *)GET_ArcIPdu(PduId)->ComIPduDataPtr;
memcpy(PduInfoPtr->SduDataPtr,&(source[Com_BufferPduState[PduId].currentPosition]), PduInfoPtr->SduLength);
Com_BufferPduState[PduId].currentPosition += PduInfoPtr->SduLength;
*TxDataCntPtr = IPdu->ComIPduSize - Com_BufferPduState[PduId].currentPosition;
} else {
r = BUFREQ_NOT_OK;
}
SchM_Exit_Com_EA_0();
return r;
}
BufReq_ReturnType Com_CopyRxData(PduIdType PduId, const PduInfoType* PduInfoPtr, PduLengthType* RxBufferSizePtr) {
/* !req COM782 */ /* If pdu group stopped -> return BUFREQ_E_NOT_OK */
BufReq_ReturnType r = BUFREQ_OK;
uint16 remainingBytes;
boolean sizeOk;
boolean dirOk;
boolean lockOk;
if(COM_INIT != initStatus) {
DET_REPORTERROR(COM_COPYRXDATA_ID, COM_E_UNINIT);
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return BUFREQ_NOT_OK;
}
SchM_Enter_Com_EA_0();
/* @req COM658 */ /* Interrupts disabled */
LDEBUG_PRINTF(" Com_CopyRxData: PduId=%d, Size=%d, Pos=%d, sduLength=%d\n",PduId, GET_IPdu(PduId)->ComIPduSize,Com_BufferPduState[PduId].currentPosition, PduInfoPtr->SduLength);
LDEBUG_PRINTF(" data[0]=%x [1]=%x...\n",PduInfoPtr->SduDataPtr[0],PduInfoPtr->SduDataPtr[1]);
remainingBytes = ((GET_IPdu(PduId)->ComIPduSize) - (Com_BufferPduState[PduId].currentPosition));
sizeOk = remainingBytes >= PduInfoPtr->SduLength;
dirOk = GET_IPdu(PduId)->ComIPduDirection == COM_RECEIVE;
lockOk = isPduBufferLocked(PduId);
if ((TRUE == dirOk) && (TRUE == lockOk) && (TRUE == sizeOk)) {
uint8* ComIPduDataPtr1 = (uint8 *)GET_ArcIPdu(PduId)->ComIPduDataPtr;
memcpy((void *)(&ComIPduDataPtr1[Com_BufferPduState[PduId].currentPosition]), PduInfoPtr->SduDataPtr, PduInfoPtr->SduLength);
Com_BufferPduState[PduId].currentPosition += PduInfoPtr->SduLength;
*RxBufferSizePtr = GET_IPdu(PduId)->ComIPduSize - Com_BufferPduState[PduId].currentPosition;
} else {
r = BUFREQ_NOT_OK;
}
SchM_Exit_Com_EA_0();
return r;
}
static void Com_SetDynSignalLength(PduIdType ComRxPduId,PduLengthType TpSduLength) {
const ComIPdu_type *IPdu = GET_IPdu(ComRxPduId);
if (IPdu->ComIPduDynSignalRef != 0) {
const ComSignal_type * const dynSignal = IPdu->ComIPduDynSignalRef;
Com_Arc_IPdu_type *Arc_IPdu = GET_ArcIPdu(ComRxPduId);
/* @req COM758 */
if( TpSduLength > (dynSignal->ComBitPosition/8) ) {
Arc_IPdu->Com_Arc_DynSignalLength = TpSduLength - (dynSignal->ComBitPosition/8);
} else {
Arc_IPdu->Com_Arc_DynSignalLength = 0;
}
}
return;
}
BufReq_ReturnType Com_StartOfReception(PduIdType ComRxPduId, PduLengthType TpSduLength, PduLengthType* RxBufferSizePtr) {
/* IMPROVEMENT: Validate ComRxPduId? */
PduLengthType ComIPduSize;
BufReq_ReturnType r = BUFREQ_OK;
if(COM_INIT != initStatus) {
DET_REPORTERROR(COM_STARTOFRECEPTION_ID, COM_E_UNINIT);
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return BUFREQ_NOT_OK;
}
const Com_Arc_IPdu_type *Arc_IPdu = GET_ArcIPdu(ComRxPduId);
SchM_Enter_Com_EA_0();
if (TRUE == Arc_IPdu->Com_Arc_IpduStarted) {
if (GET_IPdu(ComRxPduId)->ComIPduDirection == COM_RECEIVE) {
/* !req COM657 */
if (FALSE == Com_BufferPduState[ComRxPduId].locked) {
ComIPduSize = GET_IPdu(ComRxPduId)->ComIPduSize;
if (ComIPduSize >= TpSduLength) {
Com_BufferPduState[ComRxPduId].locked = true;
*RxBufferSizePtr = ComIPduSize;
/* @req COM656 */
Com_SetDynSignalLength(ComRxPduId,TpSduLength);
} else {
/* @req COM654 */
/* @req COM655 */
r = BUFREQ_OVFL;
}
} else {
r = BUFREQ_BUSY;
}
}
} else {
/* @req COM721 */
r = BUFREQ_NOT_OK;
}
SchM_Exit_Com_EA_0();
return r;
}
/* @req COM752 */
/**
* This service enables or disables RX I-PDU group Deadline Monitoring
* @param ipduGroupVector
* @return none
*/
void Com_ReceptionDMControl(Com_IpduGroupVector ipduGroupVector)
{
if(COM_INIT != initStatus) {
DET_REPORTERROR(COM_RECEPTIONDMCONTROL_ID, COM_E_UNINIT);
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return;
}
for (uint16 i = 0; 0 == ComConfig->ComIPdu[i].Com_Arc_EOL; i++)
{
const ComIPduGroup_type *const groupRefs = ComConfig->ComIPdu[i].ComIPduGroupRefs;
boolean enabled = FALSE;
/* @req COM534 */
if(ComConfig->ComIPdu[i].ComIPduDirection == COM_RECEIVE) {/* check for only rx pdus */
for(uint16 gri=0; ((0 == groupRefs[gri].Com_Arc_EOL) && (FALSE == enabled)); gri++) {
uint16 byteIndex;
uint8 bitIndex;
byteIndex = groupRefs[gri].ComIPduGroupHandleId / 8;
bitIndex = groupRefs[gri].ComIPduGroupHandleId % 8;
enabled |= ((ipduGroupVector[byteIndex] >> bitIndex) & 1u);
}
/* @req COM486 */
/* @req COM225 */
/* @req COM616 */
/* @req COM618 */
if ( Com_Arc_Config.ComIPdu[i].Com_Arc_IpduRxDMControl != enabled) {/* change of state check space*/
const ComSignal_type *comSignal;
const ComIPdu_type *IPdu = GET_IPdu(i);
Com_Arc_Signal_type * Arc_Signal;
SchM_Enter_Com_EA_0();
Com_Arc_Config.ComIPdu[i].Com_Arc_IpduRxDMControl = enabled;
/* @req COM224 */
if(TRUE == enabled) {
for (uint16 j = 0; IPdu->ComIPduSignalRef[j] != NULL; j++) {
comSignal = IPdu->ComIPduSignalRef[j];
Arc_Signal = GET_ArcSignal(comSignal->ComHandleId);
if(comSignal->ComTimeoutFactor > 0) {
/* Reset the deadline monitoring timer */
/* @req COM292 */ /* taken care in the generator */
/* @req COM291 */ /* taken care in the generator */
if(0 < comSignal->ComFirstTimeoutFactor) {
Arc_Signal->Com_Arc_DeadlineCounter = comSignal->ComFirstTimeoutFactor;
}
else{ /* wait for first reception to occur, since first time factor is not configured */
Arc_Signal->Com_Arc_DeadlineCounter = 0;
}
}
}
}
SchM_Exit_Com_EA_0();
} /* change of state check space*/
}
}
}
/**
* The service Com_SwitchIpduTxMode sets the transmission mode of the I-PDU referenced
* by PduId to Mode. In case the transmission mode changes, the new mode shall immediately
* be effective (see COM239). In case the requested transmission mode was already active
* for this I-PDU, the call will have no effect.
* @param PduId
* @param Mode
*/
/* @req COM784 */
void Com_SwitchIpduTxMode(PduIdType PduId, boolean Mode)
{
/* @req COM238 */
/* @req COM239 */
/* !req COM582 */
const ComIPdu_type *IPdu;
Com_Arc_IPdu_type *Arc_IPdu;
if(COM_INIT != initStatus) {
DET_REPORTERROR(COM_SWITCHIPDUTXMODE_ID, COM_E_UNINIT);
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return;
}
if(PduId >= ComConfig->ComNofIPdus) {
DET_REPORTERROR(COM_SWITCHIPDUTXMODE_ID, COM_E_PARAM);
/*lint -e{904} ARGUMENT CHECK */
return;
}
IPdu = GET_IPdu(PduId);
if( COM_SEND != IPdu->ComIPduDirection ) {
DET_REPORTERROR(COM_SWITCHIPDUTXMODE_ID, COM_E_PARAM);
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return;
}
Arc_IPdu = GET_ArcIPdu(PduId);
if( Arc_IPdu->Com_Arc_IpduTxMode != Mode ) {
/* Switching mode */
const ComTxMode_type *txModePtr;
if( TRUE == Mode) {
txModePtr = &IPdu->ComTxIPdu.ComTxModeTrue;
}
else {
txModePtr = &IPdu->ComTxIPdu.ComTxModeFalse;
}
Arc_IPdu->Com_Arc_IpduTxMode = Mode;/* @req COM032 */
Arc_IPdu->Com_Arc_TxIPduTimers.ComTxModeRepetitionPeriodTimer = 0;
Arc_IPdu->Com_Arc_TxIPduTimers.ComTxIPduNumberOfRepetitionsLeft = 0;
if ((txModePtr->ComTxModeMode == COM_PERIODIC) ||
(txModePtr->ComTxModeMode == COM_MIXED)) {
/* @req COM244 */
Arc_IPdu->Com_Arc_TxIPduTimers.ComTxModeTimePeriodTimer = txModePtr->ComTxModeTimePeriodFactor;
}
}
}
|
2301_81045437/classic-platform
|
communication/Com/src/Com.c
|
C
|
unknown
| 32,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 -----------------------------*/
#ifndef COM_ARC_TYPES_H_
#define COM_ARC_TYPES_H_
#include "Std_Types.h"
#include "Com_Types.h"
typedef struct {
uint32 ComFilterArcN;
uint32 ComFilterArcNewValue;
uint32 ComFilterArcOldValue;
} Com_Arc_Filter_type;
typedef struct {
const void *Com_Arc_ShadowBuffer;
uint32 Com_Arc_DeadlineCounter;
boolean ComSignalUpdated;
boolean ComSignalUpdatedGwRouting; /* Indicating signal update for gateway routing. Relevant only to Gateway source signals */
boolean ComSignalRoutingReq; /* Routing is requested if ComSignalUpdatedGwRouting is set */
} Com_Arc_Signal_type;
typedef struct {
void *Com_Arc_ShadowBuffer;
boolean ComSignalUpdated;
uint8 Com_Arc_EOL;
} Com_Arc_GroupSignal_type;
typedef struct {
uint32 ComTxModeRepetitionPeriodTimer;
uint32 ComTxIPduMinimumDelayTimer;
uint32 ComTxModeTimePeriodTimer;
uint32 ComTxDMTimer; /* Tx DM timer */
uint8 ComTxIPduNumberOfRepetitionsLeft;
uint8 ComTxIPduNumberOfTxConfirmations; /* Tx confirmations from Pdu for the repeted requests(N times) */
} Com_Arc_TxIPduTimer_type;
typedef struct {
/** Reference to the actual pdu data storage */
void *ComIPduDataPtr;
void *ComIPduDeferredDataPtr;
Com_Arc_TxIPduTimer_type Com_Arc_TxIPduTimers;
uint32 Com_Arc_TxDeadlineCounter; /* a separate counter storage for Tx deadline monitor,
no need to parse all the signals everytime for the timeout refilling */
uint16 Com_Arc_DynSignalLength;
boolean Com_Arc_IpduStarted;
boolean Com_Arc_IpduRxDMControl;
boolean Com_Arc_IpduTxMode; /* @req COM605 */
} Com_Arc_IPdu_type;
typedef struct {
boolean ComSignalUpdatedGwRouting;
boolean ComSignalRoutingReq; /* Routing is requested if ComSignalUpdatedGwRouting is set */
}Com_Arc_GwSrcDesc_type;
typedef struct {
Com_Arc_IPdu_type *ComIPdu; // Only used in PduIdCheck()
Com_Arc_Signal_type *ComSignal;
Com_Arc_GroupSignal_type *ComGroupSignal;
Com_Arc_GwSrcDesc_type * ComGwSrcDescSignal;
} Com_Arc_Config_type;
typedef struct{
Com_BitPositionType ComBitPosition;
uint16 ComBitSize;
ComSignalEndianess_type ComSignalEndianess;
Com_SignalType ComSignalType;
}Com_Arc_ExtractPduInfo_Type;
#endif
|
2301_81045437/classic-platform
|
communication/Com/src/Com_Arc_Types.h
|
C
|
unknown
| 3,106
|
/*-------------------------------- 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 -----------------------------*/
//lint -esym(960,8.7) PC-Lint misunderstanding of Misra 8.7 for Com_SystenEndianness and endianess_test
#include <string.h>
#include "PduR.h"
#include "Com_Arc_Types.h"
#include "Com.h"
#include "Com_Internal.h"
#include "Com_misc.h"
#include "debug.h"
#include "Det.h"
#include "Cpu.h"
#include "SchM_Com.h"
#include "arc_assert.h"
#if defined(USE_LINUXOS)
#include "linos_logger.h" /* Logger functions */
#endif
/* Declared in Com_Cfg.c */
/*lint -esym(9003, ComRxIPduCallouts)*/ /* ComRxIPduCallouts is defined in com_cfg.c */
extern const ComRxIPduCalloutType ComRxIPduCallouts[];
/*lint -e9003 ComNotificationCallouts cannot be defined at block scope because it is used in Com_RxIndication and Com_TxConfirmation */
extern const ComNotificationCalloutType ComNotificationCallouts[];
/*lint -esym(9003, ComTriggerTransmitIPduCallouts)*/ /* ComTriggerTransmitIPduCallouts is defined in com_cfg.c */
extern const ComTxIPduCalloutType ComTriggerTransmitIPduCallouts[];
uint8 Com_SendSignal(Com_SignalIdType SignalId, const void *SignalDataPtr) {
/* @req COM334 */ /* Shall update buffer if pdu stopped, should not store trigger */
uint8 ret = E_OK;
boolean dataChanged = FALSE;
if( COM_INIT != Com_GetStatus() ) {
DET_REPORTERROR(COM_SENDSIGNAL_ID, COM_E_UNINIT);
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return COM_SERVICE_NOT_AVAILABLE;
}
if(SignalId >= ComConfig->ComNofSignals) {
DET_REPORTERROR(COM_SENDSIGNAL_ID, COM_E_PARAM);
/*lint -e{904} ARGUMENT CHECK */
return COM_SERVICE_NOT_AVAILABLE;
}
/* Store pointer to signal for easier coding.*/
const ComSignal_type * Signal = GET_Signal(SignalId);
#if defined(USE_LINUXOS)
logger(LOG_INFO, "Com_SendSignal SignalDataPtr [%s] ComBitSize [%d]",
logger_format_hex((char*)SignalDataPtr, (Signal->ComBitSize / 8)),
Signal->ComBitSize
);
#endif
if (Signal->ComIPduHandleId == NO_PDU_REFERENCE) {
/* Return error if signal is not connected to an IPdu*/
ret = COM_SERVICE_NOT_AVAILABLE;
} else if (TRUE == isPduBufferLocked(Signal->ComIPduHandleId)) {
ret = COM_BUSY;
} else {
if (Signal->ComBitSize != 0) {
//DEBUG(DEBUG_LOW, "Com_SendSignal: id %d, nBytes %d, BitPosition %d, intVal %d\n", SignalId, nBytes, signal->ComBitPosition, (uint32)*(uint8 *)SignalDataPtr);
const Com_Arc_IPdu_type *Arc_IPdu = GET_ArcIPdu(Signal->ComIPduHandleId);
/* @req COM624 */
uint8 *comIPduDataPtr = Arc_IPdu->ComIPduDataPtr;
SchM_Enter_Com_EA_0();
Com_Misc_WriteSignalDataToPdu(
(const uint8 *)SignalDataPtr,
Signal->ComSignalType,
comIPduDataPtr,
Signal->ComBitPosition,
Signal->ComBitSize,
Signal->ComSignalEndianess,
&dataChanged);
/* If the signal has an update bit. Set it!*/
/* @req COM061 */
if (TRUE == Signal->ComSignalArcUseUpdateBit) {
/*lint -e{926} pointer cast is essential since SETBIT parameters are of different pointer data type*/
/*lint -e{9016} Array indexing couldn't be implemented, as parameters are of different data types */
SETBIT(comIPduDataPtr, Signal->ComUpdateBitPosition);
}
}
/* Assign the number of repetitions based on Transfer property */
if( FALSE == Com_Misc_TriggerTxOnConditions(Signal->ComIPduHandleId, dataChanged, Signal->ComTransferProperty) ) {
ret = COM_SERVICE_NOT_AVAILABLE;
}
SchM_Exit_Com_EA_0();
}
return ret;
}
uint8 Com_ReceiveSignal(Com_SignalIdType SignalId, void* SignalDataPtr) {
uint8 ret;
ret = E_OK;
if( COM_INIT != Com_GetStatus() ) {
DET_REPORTERROR(COM_RECEIVESIGNAL_ID, COM_E_UNINIT);
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return COM_SERVICE_NOT_AVAILABLE;
}
if(SignalId >= ComConfig->ComNofSignals) {
DET_REPORTERROR(COM_RECEIVESIGNAL_ID, COM_E_PARAM);
/*lint -e{904} ARGUMENT CHECK */
return COM_SERVICE_NOT_AVAILABLE;
}
DEBUG(DEBUG_LOW, "Com_ReceiveSignal: SignalId %d\n", SignalId);
const ComSignal_type * Signal = GET_Signal(SignalId);
if (Signal->ComIPduHandleId == NO_PDU_REFERENCE) {
/* Return error init value signal if signal is not connected to an IPdu*/
memcpy(SignalDataPtr, Signal->ComSignalInitValue, SignalTypeToSize(Signal->ComSignalType, Signal->ComBitSize/8));
ret = E_OK;
} else {
const ComIPdu_type *IPdu = GET_IPdu(Signal->ComIPduHandleId);
const Com_Arc_IPdu_type *Arc_IPdu = GET_ArcIPdu(Signal->ComIPduHandleId);
const void* pduBuffer = NULL;
if ((IPdu->ComIPduSignalProcessing == COM_DEFERRED) && (IPdu->ComIPduDirection == COM_RECEIVE)) {
pduBuffer = Arc_IPdu->ComIPduDeferredDataPtr;
} else {
if (TRUE == isPduBufferLocked(Signal->ComIPduHandleId)) {
ret = COM_BUSY;
}
pduBuffer = Arc_IPdu->ComIPduDataPtr;
}
/* @req COM631 */
Com_Misc_ReadSignalDataFromPdu(
pduBuffer,
Signal->ComBitPosition,
Signal->ComBitSize,
Signal->ComSignalEndianess,
Signal->ComSignalType,
SignalDataPtr);
if( (FALSE == Arc_IPdu->Com_Arc_IpduStarted) && (E_OK == ret) ) {
ret = COM_SERVICE_NOT_AVAILABLE;
}
}
return ret;
}
uint8 Com_ReceiveDynSignal(Com_SignalIdType SignalId, void* SignalDataPtr, uint16* Length) {
/* IMPROVEMENT: Validate signal id?*/
uint8 ret;
ret = E_OK;
if( COM_INIT != Com_GetStatus() ) {
DET_REPORTERROR(COM_RECEIVEDYNSIGNAL_ID, COM_E_UNINIT);
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return COM_SERVICE_NOT_AVAILABLE;
}
const ComSignal_type * Signal = GET_Signal(SignalId);
const Com_Arc_IPdu_type *Arc_IPdu = GET_ArcIPdu(Signal->ComIPduHandleId);
const ComIPdu_type *IPdu = GET_IPdu(Signal->ComIPduHandleId);
Com_SignalType signalType = Signal->ComSignalType;
/* @req COM753 */
if (signalType != COM_UINT8_DYN) {
ret = COM_SERVICE_NOT_AVAILABLE;
} else {
SchM_Enter_Com_EA_0();
/* @req COM712 */
if( *Length >= Arc_IPdu->Com_Arc_DynSignalLength ) {
if (*Length > Arc_IPdu->Com_Arc_DynSignalLength) {
*Length = Arc_IPdu->Com_Arc_DynSignalLength;
}
uint16 startFromPduByte = (Signal->ComBitPosition) / 8;
const uint8* pduDataPtr = NULL;
if ((IPdu->ComIPduSignalProcessing == COM_DEFERRED) && (IPdu->ComIPduDirection == COM_RECEIVE)) {
pduDataPtr = (uint8 *)Arc_IPdu->ComIPduDeferredDataPtr;
} else {
if (TRUE == isPduBufferLocked(getPduId(IPdu))) {
ret = COM_BUSY;
}
pduDataPtr = (uint8 *)Arc_IPdu->ComIPduDataPtr;
}
/* @req COM711 */
memcpy(SignalDataPtr, (&pduDataPtr[startFromPduByte]), *Length);
} else {
/* @req COM724 */
*Length = Arc_IPdu->Com_Arc_DynSignalLength;
ret = E_NOT_OK;
}
SchM_Exit_Com_EA_0();
if( (FALSE == Arc_IPdu->Com_Arc_IpduStarted) && (E_OK == ret) ) {
ret = COM_SERVICE_NOT_AVAILABLE;
}
}
return ret;
}
/**
* Send a dynamic signal (ie ComSignalType=COM_UINT8_DYN)
*
* @param SignalId - The signal ID
* @param SignalDataPtr - Pointer to the data.
* @param Length - The signal length in bytes
* @return
*/
uint8 Com_SendDynSignal(Com_SignalIdType SignalId, const void* SignalDataPtr, uint16 Length) {
/* IMPROVEMENT: validate SignalId */
/* !req COM629 */
/* @req COM630 */
if( COM_INIT != Com_GetStatus() ) {
DET_REPORTERROR(COM_SENDDYNSIGNAL_ID, COM_E_UNINIT);
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return COM_SERVICE_NOT_AVAILABLE;
}
const ComSignal_type * Signal = GET_Signal(SignalId);
Com_Arc_IPdu_type *Arc_IPdu = GET_ArcIPdu(Signal->ComIPduHandleId);
const ComIPdu_type *IPdu = GET_IPdu(Signal->ComIPduHandleId);
uint8 ret = E_OK;
Com_SignalType signalType = Signal->ComSignalType;
boolean dataChanged = FALSE;
const uint8* Arc_IpduDataPtr;
uint8* Arc_IpduDataPtr1;
/* @req COM753 */
if (signalType != COM_UINT8_DYN) {
ret = COM_SERVICE_NOT_AVAILABLE;
} else if (TRUE == isPduBufferLocked(getPduId(IPdu))) {
ret = COM_BUSY;
} else {
/* Get signalLength in bytes,
* Note!, ComBitSize is set to ComSignalLength in case of COM_UINT8_DYN or COM_UINT8_N */
uint32 signalLength = Signal->ComBitSize / 8;
Com_BitPositionType bitPosition = Signal->ComBitPosition;
/* Check so that we are not trying to send a signal that is
* bigger that the actual space */
if (signalLength < Length) {
ret = E_NOT_OK;
} else {
uint16 startFromPduByte = bitPosition / 8;
SchM_Enter_Com_EA_0();
Arc_IpduDataPtr = (uint8 *)Arc_IPdu->ComIPduDataPtr;
/*lint -e{9007} Either one of the condition yielding true is sufficient */
if( (Arc_IPdu->Com_Arc_DynSignalLength != Length) ||
(0 != memcmp((&Arc_IpduDataPtr[startFromPduByte]), SignalDataPtr, Length)) ) {
dataChanged = TRUE;
}
/* @req COM628 */
Arc_IpduDataPtr1 = (uint8 *)Arc_IPdu->ComIPduDataPtr;
memcpy((&Arc_IpduDataPtr1[startFromPduByte]), SignalDataPtr, Length);
/* !req COM757 */ /*Length of I-PDU?*/
Arc_IPdu->Com_Arc_DynSignalLength = Length;
/* If the signal has an update bit. Set it!*/
if (TRUE == Signal->ComSignalArcUseUpdateBit) {
/*lint -e{9016} Array indexing couldn't be implemented, as parameters are of different data types */
SETBIT(Arc_IPdu->ComIPduDataPtr, Signal->ComUpdateBitPosition);
}
/* Assign the number of repetitions based on Transfer property */
if(FALSE == Com_Misc_TriggerTxOnConditions(Signal->ComIPduHandleId, dataChanged, Signal->ComTransferProperty) ) {
ret = COM_SERVICE_NOT_AVAILABLE;
}
SchM_Exit_Com_EA_0();
}
}
return ret;
}
Std_ReturnType Com_TriggerTransmit(PduIdType TxPduId, PduInfoType *PduInfoPtr) {
Std_ReturnType status;
status = E_OK;
/* @req COM475 */
if( COM_INIT != Com_GetStatus() ) {
DET_REPORTERROR(COM_TRIGGERTRANSMIT_ID, COM_E_UNINIT);
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return E_NOT_OK;
}
if( TxPduId >= ComConfig->ComNofIPdus ) {
DET_REPORTERROR(COM_TRIGGERTRANSMIT_ID, COM_E_PARAM);
/*lint -e{904} ARGUMENT CHECK */
return E_NOT_OK;
}
/*
* !req COM260: This function must not check the transmission mode of the I-PDU
* since it should be possible to use it regardless of the transmission mode.
* Only for ComIPduType = NORMAL.
*/
const ComIPdu_type *IPdu = GET_IPdu(TxPduId);
const Com_Arc_IPdu_type *Arc_IPdu = GET_ArcIPdu(TxPduId);
SchM_Enter_Com_EA_0();
/* @req COM766 */
if( (IPdu->ComTriggerTransmitIPduCallout != COM_NO_FUNCTION_CALLOUT) && (ComTriggerTransmitIPduCallouts[IPdu->ComTriggerTransmitIPduCallout] != NULL) ) {
/* @req COM395 */
(void)ComTriggerTransmitIPduCallouts[IPdu->ComTriggerTransmitIPduCallout](TxPduId, Arc_IPdu->ComIPduDataPtr);
}
/* @req COM647 */
/* @req COM648 */ /* Interrups disabled */
memcpy(PduInfoPtr->SduDataPtr, Arc_IPdu->ComIPduDataPtr, IPdu->ComIPduSize);
PduInfoPtr->SduLength = IPdu->ComIPduSize;
if( FALSE == Arc_IPdu->Com_Arc_IpduStarted ) {
status = E_NOT_OK;
} else {
if (IPdu->ComTxIPdu.ComTxIPduClearUpdateBit == TRIGGERTRANSMIT) {
/* Clear all update bits for the contained signals*/
/* @req COM578 */
for (uint16 i = 0;(IPdu->ComIPduSignalRef != NULL)&& (IPdu->ComIPduSignalRef[i] != NULL); i++) {
if (TRUE == IPdu->ComIPduSignalRef[i]->ComSignalArcUseUpdateBit) {
/*lint -e{9016} Array indexing couldn't be implemented, as parameters are of different data types */
CLEARBIT(Arc_IPdu->ComIPduDataPtr,IPdu->ComIPduSignalRef[i]->ComUpdateBitPosition);
}
}
}
status = E_OK;
}
SchM_Exit_Com_EA_0();
return status;
}
void Com_TriggerIPDUSend(PduIdType PduId) {
/* !req COM789 */
/* !req COM662 */ /* May be supported, but when is buffer locked?*/
if( COM_INIT != Com_GetStatus() ) {
DET_REPORTERROR(COM_TRIGGERIPDUSEND_ID, COM_E_UNINIT);
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return;
}
if( PduId >= ComConfig->ComNofIPdus ) {
DET_REPORTERROR(COM_TRIGGERIPDUSEND_ID, COM_E_PARAM);
/*lint -e{904} ARGUMENT CHECK */
return;
}
(void)Com_Misc_TriggerIPDUSend(PduId);
}
/*lint --e{818} 'PduInfoPtr' could be declared as pointing to const, this is done in 4.2.2 */
void Com_RxIndication(PduIdType RxPduId, PduInfoType* PduInfoPtr) {
boolean status;
status = TRUE;
if( COM_INIT != Com_GetStatus() ) {
DET_REPORTERROR(COM_RXINDICATION_ID, COM_E_UNINIT);
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return;
}
if( RxPduId >= ComConfig->ComNofIPdus ) {
DET_REPORTERROR(COM_RXINDICATION_ID, COM_E_PARAM);
/*lint -e{904} ARGUMENT CHECK */
return;
}
const ComIPdu_type *IPdu = GET_IPdu(RxPduId);
const Com_Arc_IPdu_type *Arc_IPdu = GET_ArcIPdu(RxPduId);
SchM_Enter_Com_EA_0();
/* @req COM649 */ /* Interrups disabled */
/* If Ipdu is stopped*/
/* @req COM684 */
if (FALSE == Arc_IPdu->Com_Arc_IpduStarted) {
} else {
/* Check callout status*/
/* @req COM555 */
/* @req COM700 */
if ((IPdu->ComRxIPduCallout != COM_NO_FUNCTION_CALLOUT) && (ComRxIPduCallouts[IPdu->ComRxIPduCallout] != NULL)) {
if (FALSE == ComRxIPduCallouts[IPdu->ComRxIPduCallout](RxPduId, PduInfoPtr->SduDataPtr)) {
// IMPROVMENT: Report error to DET.
// Det_ReportError();
/* !req COM738 */
status = FALSE;
}
}
/* !req COM574 */
/* !req COM575 */
if (status == TRUE) {
#if(COM_IPDU_COUNTING_ENABLE == STD_ON )
if (ComConfig->ComIPdu[RxPduId].ComIpduCounterRef != NULL) {
/* Ignore the IPdu if errors detected*/
if (FALSE == (Com_Misc_validateIPduCounter(ComConfig->ComIPdu[RxPduId].ComIpduCounterRef,PduInfoPtr->SduDataPtr))){
/* @req COM726 *//* @req COM727 */
if (ComConfig->ComIPdu[RxPduId].ComIpduCounterRef->ComIPduCntErrNotification != COM_NO_FUNCTION_CALLOUT) {
ComNotificationCallouts[ComConfig->ComIPdu[RxPduId].ComIpduCounterRef->ComIPduCntErrNotification](); /*Trigger error callback*/
}
/* @req COM590 */
status = FALSE;
}
}
#endif
/* Copy IPDU data*/
if (status == TRUE) { /*lint !e774 status value can be update based on configuration */
memcpy(Arc_IPdu->ComIPduDataPtr, PduInfoPtr->SduDataPtr, IPdu->ComIPduSize);
Com_Misc_RxProcessSignals(IPdu,Arc_IPdu);
}
}
}
SchM_Exit_Com_EA_0();
return;
}
void Com_TpRxIndication(PduIdType PduId, NotifResultType Result) {
/* @req COM720 */
if( COM_INIT != Com_GetStatus() ) {
DET_REPORTERROR(COM_TPRXINDICATION_ID, COM_E_UNINIT);
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return;
}
if( PduId >= ComConfig->ComNofIPdus ) {
DET_REPORTERROR(COM_RXINDICATION_ID, COM_E_PARAM);
/*lint -e{904} ARGUMENT CHECK */
return;
}
const ComIPdu_type *IPdu = GET_IPdu(PduId);
const Com_Arc_IPdu_type *Arc_IPdu = GET_ArcIPdu(PduId);
/* @req COM651 */ /* Interrups disabled */
SchM_Enter_Com_EA_0();
/* If Ipdu is stopped */
/* @req COM684 */
if (FALSE == Arc_IPdu->Com_Arc_IpduStarted) {
Com_Misc_UnlockTpBuffer(getPduId(IPdu));
SchM_Exit_Com_EA_0();
} else {
if (Result == NTFRSLT_OK) {
if (IPdu->ComIPduSignalProcessing == COM_IMMEDIATE) {
/* irqs needs to be disabled until signal notifications have been called*/
/* Otherwise a new Tp session can start and fill up pdus*/
Com_Misc_UnlockTpBuffer(getPduId(IPdu));
}
/* In deferred mode, buffers are unlocked in mainfunction*/
Com_Misc_RxProcessSignals(IPdu,Arc_IPdu);
} else {
Com_Misc_UnlockTpBuffer(getPduId(IPdu));
}
SchM_Exit_Com_EA_0();
}
}
void Com_TpTxConfirmation(PduIdType PduId, NotifResultType Result) {
/* !req COM713 */
/* !req COM662 */ /* Tp buffer unlocked but buffer is never locked */
if( COM_INIT != Com_GetStatus() ) {
DET_REPORTERROR(COM_TPTXCONFIRMATION_ID, COM_E_UNINIT);
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return;
}
if( PduId >= ComConfig->ComNofIPdus ) {
DET_REPORTERROR(COM_RXINDICATION_ID, COM_E_PARAM);
/*lint -e{904} ARGUMENT CHECK */
return;
}
(void)Result; /* touch*/
SchM_Enter_Com_EA_0();
Com_Misc_UnlockTpBuffer(PduId);
SchM_Exit_Com_EA_0();
}
void Com_TxConfirmation(PduIdType TxPduId) {
/* !req COM469 */
/* !req COM053 */
/* @req COM652 */ /* Function does nothing.. */
/* Need to implement COM305 */
if( COM_INIT != Com_GetStatus() ) {
DET_REPORTERROR(COM_TXCONFIRMATION_ID, COM_E_UNINIT);
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return;
}
if( TxPduId >= ComConfig->ComNofIPdus ) {
DET_REPORTERROR(COM_RXINDICATION_ID, COM_E_PARAM);
/*lint -e{904} ARGUMENT CHECK */
return;
}
/* @req COM468 */
/* Call all notifications for the PDU */
const ComIPdu_type *IPdu = GET_IPdu(TxPduId);
Com_Arc_IPdu_type *Arc_IPdu = GET_ArcIPdu(TxPduId);
if (IPdu->ComIPduDirection == COM_RECEIVE) {
DET_REPORTERROR(COM_TXCONFIRMATION_ID, COM_INVALID_PDU_ID);
}
else {
/* take care DM handling */
if(0 < Arc_IPdu->Com_Arc_TxDeadlineCounter){ /* if DM configured */
Com_Misc_TxHandleDM(IPdu,Arc_IPdu);
/* IMPROVEMENT - handle also in Com_TpTxConfirmation */
}
/* Clear all update bits for the contained signals*/
/* @req COM577 */
if (IPdu->ComTxIPdu.ComTxIPduClearUpdateBit == CONFIRMATION) {
for (uint16 i = 0; (IPdu->ComIPduSignalRef != NULL) && (IPdu->ComIPduSignalRef[i] != NULL); i++) {
if (TRUE == IPdu->ComIPduSignalRef[i]->ComSignalArcUseUpdateBit) {
/*lint -e{9016} Array indexing couldn't be implemented, as parameters are of different data types */
CLEARBIT(Arc_IPdu->ComIPduDataPtr, IPdu->ComIPduSignalRef[i]->ComUpdateBitPosition);
}
}
}
if (IPdu->ComIPduSignalProcessing == COM_IMMEDIATE) {
/* If immediate, call the notification functions */
for (uint16 i = 0; IPdu->ComIPduSignalRef[i] != NULL; i++) {
const ComSignal_type *signal = IPdu->ComIPduSignalRef[i];
if ((signal->ComNotification != COM_NO_FUNCTION_CALLOUT) &&
(ComNotificationCallouts[signal->ComNotification] != NULL) ) {
ComNotificationCallouts[signal->ComNotification]();
}
}
}
else {
/* If deferred, set status and let the main function call the notification function */
Com_Misc_SetTxConfirmationStatus(IPdu, TRUE);
}
}
}
uint8 Com_SendSignalGroup(Com_SignalGroupIdType SignalGroupId) {
/* Validate signalgroupid?*/
/* @req COM334 */
uint8 ret = E_OK;
boolean dataChanged = FALSE;
if( COM_INIT != Com_GetStatus() ) {
DET_REPORTERROR(COM_SENDSIGNALGROUP_ID, COM_E_UNINIT);
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return COM_SERVICE_NOT_AVAILABLE;
}
const ComSignal_type * Signal = GET_Signal(SignalGroupId);
if (Signal->ComIPduHandleId == NO_PDU_REFERENCE) {
ret = COM_SERVICE_NOT_AVAILABLE;
} else {
const Com_Arc_IPdu_type *Arc_IPdu = GET_ArcIPdu(Signal->ComIPduHandleId);
const ComIPdu_type *IPdu = GET_IPdu(Signal->ComIPduHandleId);
if (TRUE == isPduBufferLocked(getPduId(IPdu))) {
ret = COM_BUSY;
} else {
/* Copy shadow buffer to Ipdu data space*/
SchM_Enter_Com_EA_0();
/* @req COM635 */
/* @req COM050 */
Com_Misc_CopySignalGroupDataFromShadowBufferToPdu(SignalGroupId,
(((IPdu->ComIPduSignalProcessing == COM_DEFERRED) &&
(IPdu->ComIPduDirection == COM_RECEIVE))? TRUE : FALSE),
&dataChanged);
/* If the signal has an update bit. Set it!*/
/* @req COM061 */
if (TRUE== Signal->ComSignalArcUseUpdateBit) {
/*lint -e{9016} Array indexing couldn't be implemented, as parameters are of different data types */
SETBIT(Arc_IPdu->ComIPduDataPtr, Signal->ComUpdateBitPosition);
}
/* Assign the number of repetitions based on Transfer property */
if( FALSE == Com_Misc_TriggerTxOnConditions(Signal->ComIPduHandleId, dataChanged, Signal->ComTransferProperty) ) {
ret = COM_SERVICE_NOT_AVAILABLE;
}
SchM_Exit_Com_EA_0();
}
}
return ret;
}
uint8 Com_ReceiveSignalGroup(Com_SignalGroupIdType SignalGroupId) {
uint8 status;
status = E_NOT_OK;
if( COM_INIT != Com_GetStatus() ) {
DET_REPORTERROR(COM_RECEIVESIGNALGROUP_ID, COM_E_UNINIT);
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return COM_SERVICE_NOT_AVAILABLE;
}
const ComSignal_type * Signal = GET_Signal(SignalGroupId);
if (Signal->ComIPduHandleId == NO_PDU_REFERENCE) {
status = COM_SERVICE_NOT_AVAILABLE;
} else {
const ComIPdu_type *IPdu = GET_IPdu(Signal->ComIPduHandleId);
if (TRUE == isPduBufferLocked(getPduId(IPdu))) {
status = COM_BUSY;
} else {
/* Copy Ipdu data buffer to shadow buffer.*/
/* @req COM638 */
/* @req COM461 */
/* @req COM051 */
SchM_Enter_Com_EA_0();
Com_Misc_CopySignalGroupDataFromPduToShadowBuffer(SignalGroupId);
SchM_Exit_Com_EA_0();
if( FALSE == GET_ArcIPdu(Signal->ComIPduHandleId)->Com_Arc_IpduStarted ) {
status = COM_SERVICE_NOT_AVAILABLE;
} else {
status = E_OK;
}
}
}
return status;
}
void Com_UpdateShadowSignal(Com_SignalIdType SignalId, const void *SignalDataPtr) {
if( COM_INIT != Com_GetStatus() ) {
DET_REPORTERROR(COM_UPDATESHADOWSIGNAL_ID, COM_E_UNINIT);
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return;
}
if( SignalId >= ComConfig->ComNofGroupSignals ) {
DET_REPORTERROR(COM_UPDATESHADOWSIGNAL_ID, COM_E_PARAM);
/*lint -e{904} ARGUMENT CHECK */
return;
}
const Com_Arc_GroupSignal_type *Arc_GroupSignal = GET_ArcGroupSignal(SignalId);
if (Arc_GroupSignal->Com_Arc_ShadowBuffer != NULL) {
Com_Misc_UpdateShadowSignal(SignalId, SignalDataPtr);
}
}
void Com_ReceiveShadowSignal(Com_SignalIdType SignalId, void *SignalDataPtr) {
if( COM_INIT != Com_GetStatus() ) {
DET_REPORTERROR(COM_RECEIVESHADOWSIGNAL_ID, COM_E_UNINIT);
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return;
}
if( SignalId >= ComConfig->ComNofGroupSignals ) {
DET_REPORTERROR(COM_RECEIVESHADOWSIGNAL_ID, COM_E_PARAM);
/*lint -e{904} ARGUMENT CHECK */
return;
}
const ComGroupSignal_type *GroupSignal = GET_GroupSignal(SignalId);
const Com_Arc_GroupSignal_type *Arc_GroupSignal = GET_ArcGroupSignal(SignalId);
/* Get default value if unconnected */
if (Arc_GroupSignal->Com_Arc_ShadowBuffer == NULL) {
memcpy(SignalDataPtr, GroupSignal->ComSignalInitValue, SignalTypeToSize(GroupSignal->ComSignalType, (GroupSignal->ComBitSize/8)));
}
else {
/* @req COM640 */
Com_Misc_ReadSignalDataFromPdu(
Arc_GroupSignal->Com_Arc_ShadowBuffer,
GroupSignal->ComBitPosition,
GroupSignal->ComBitSize,
GroupSignal->ComSignalEndianess,
GroupSignal->ComSignalType,
SignalDataPtr);
}
}
|
2301_81045437/classic-platform
|
communication/Com/src/Com_Com.c
|
C
|
unknown
| 27,415
|
/*-------------------------------- 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 -----------------------------*/
/*
* NB! This file is for COM internal use only and may only be included from COM C-files!
*/
#ifndef COM_INTERNAL_H_
#define COM_INTERNAL_H_
#include "Com_Arc_Types.h"
typedef enum {
COM_TX_TRIGGERED = 0,
COM_TX_MIN_DELAY_NOT_FULFILLED,
COM_TX_NOT_TRIGGERED
}ComTxTriggerStatusType;
typedef struct {
PduLengthType currentPosition;
boolean locked;
} Com_BufferPduStateType;
//lint -esym(9003, Com_BufferPduState)
extern Com_BufferPduStateType Com_BufferPduState[];
extern const Com_ConfigType *ComConfig;
extern const Com_Arc_Config_type Com_Arc_Config;
#if COM_DEV_ERROR_DETECT == STD_ON
#include "Det.h"
/* @req COM442 */
/* @req COM028 */
#define DET_REPORTERROR(_api, _error) \
(void)Det_ReportError(COM_MODULE_ID, 0, _api, _error);
#else
#define DET_REPORTERROR(_api,_err)
#endif
/* Error codes */
/* !req COM707 */
#define COM_E_PARAM 0x01
#define COM_E_UNINIT 0x02
#define COM_E_PARAM_POINTER 0x03
/* Service ids */
#define COM_INIT_ID 0x01
#define COM_DEINIT_ID 0x02
#define COM_IPDUGROUPCONTROL_ID 0x03
#define COM_RECEPTIONDMCONTROL_ID 0x06
//#define COM_GETSTATUS_ID 0x07
//#define COM_GETCONFIGURATIONID_ID 0x08
//#define COM_GETVERSIONINFO_ID 0x09
#define COM_SENDSIGNAL_ID 0x0A
#define COM_RECEIVESIGNAL_ID 0x0B
#define COM_UPDATESHADOWSIGNAL_ID 0x0C
#define COM_SENDSIGNALGROUP_ID 0x0D
#define COM_RECEIVESIGNALGROUP_ID 0x0E
#define COM_RECEIVESHADOWSIGNAL_ID 0x0F
//#define COM_INVALIDATESIGNAL_ID 0x10
#define COM_INVALIDATESHADOWSIGNAL_ID 0x16
#define COM_TRIGGERIPDUSEND_ID 0x17
#define COM_MAINFUNCTIONRX_ID 0x18
#define COM_MAINFUNCTIONTX_ID 0x19
#define COM_MAINFUNCTIONROUTESIGNALS_ID 0x1A
//#define COM_INVALIDATESIGNAL_GROUP_ID 0x1B
#define COM_CLEARIPDUGROUPVECTOR_ID 0x1C
#define COM_SETIPDUGROUP_ID 0x1D
#define COM_TPRXINDICATION_ID 0x1E
#define COM_SENDDYNSIGNAL_ID 0x21
#define COM_RECEIVEDYNSIGNAL_ID 0x22
#define COM_COPYRXDATA_ID 0x23
#define COM_COPYTXDATA_ID 0x24
#define COM_STARTOFRECEPTION_ID 0x25
#define COM_TPTXCONFIRMATION_ID 0x26
#define COM_SWITCHIPDUTXMODE_ID 0x27
#define COM_TXCONFIRMATION_ID 0x40
#define COM_TRIGGERTRANSMIT_ID 0x41
#define COM_RXINDICATION_ID 0x42
#define TESTBIT(source,bit) ( *( (uint8 *)source + (bit / 8) ) & (uint8)(1u << (bit % 8u)) )
#define SETBIT(dest,bit) ( *( (uint8 *)dest + (bit / 8) ) |= (uint8)(1u << (bit % 8u)) )
#define CLEARBIT(dest,bit) ( *( (uint8 *)dest + (bit / 8) ) &= ~(uint8)(1u << (bit % 8u)) )
#define GET_Signal(SignalId) \
(&ComConfig->ComSignal[SignalId])
#define GET_ArcSignal(SignalId) \
(&Com_Arc_Config.ComSignal[SignalId])
#define GET_IPdu(IPduId) \
(&ComConfig->ComIPdu[IPduId])
#define GET_ArcIPdu(IPduId) \
(&Com_Arc_Config.ComIPdu[IPduId])
#define GET_GroupSignal(GroupSignalId) \
(&ComConfig->ComGroupSignal[GroupSignalId])
#define GET_ArcGroupSignal(GroupSignalId) \
(&Com_Arc_Config.ComGroupSignal[GroupSignalId])
#define GET_GwSrcSigDesc(SignalId) \
(&ComConfig->ComGwSrcDesc[SignalId])
#define GET_ArcGwSrcSigDesc(GwSrcDesc) \
(&Com_Arc_Config.ComGwSrcDescSignal[GwSrcDesc])
#define GET_GwDestnSigDesc(SignalId) \
(&ComConfig->ComGwDestnDesc[SignalId])
ComTxTriggerStatusType Com_Misc_TriggerIPDUSend(PduIdType PduId);
boolean Com_Misc_TriggerTxOnConditions(uint16 pduHandleId, boolean dataChanged, ComTransferPropertyType transferProperty);
boolean Com_Misc_validateIPduCounter(const ComIPduCounter_type *CounterCfgRef, const uint8 * sduPtr);
#if(COM_IPDU_COUNTING_ENABLE == STD_ON )
void ResetInternalCounter(uint16 indx);
void ReSetInternalRxStartSts(uint16 indx);
void ResetInternalCounterRxStartSts(void);
#if defined (HOST_TEST)
uint8 ReadInternalCouner(uint16 indx);
#endif
#endif
#endif /* COM_INTERNAL_H_ */
|
2301_81045437/classic-platform
|
communication/Com/src/Com_Internal.h
|
C
|
unknown
| 4,744
|
/*-------------------------------- 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 "Com_Arc_Types.h"
#include "Com.h"
#include "Com_Internal.h"
#include "Com_misc.h"
#include <string.h>
#include "debug.h"
#include "Cpu.h"
#include "SchM_Com.h"
#if (COM_OSEKNM_SUPPORT == STD_ON)
#include "OsekNm.h"
#endif
#define timerDec(timer) \
if (timer > 0) { \
timer = timer - 1; \
} \
/* Declared in Com_Cfg.c */
extern const ComNotificationCalloutType ComNotificationCallouts[];
/**
* Tx sub main function- routed from Com_MainFunctionTx
* Processes mixed or periodic tx pdus
* handles the Tx timing functionalities/timers as well
* @param IPduId
* @param dmTimeOut
* @return none
*/
static void Com_ProcessMixedOrPeriodicTxMode(uint16 IPduId,boolean dmTimeOut){
const ComIPdu_type *IPdu;
IPdu = &ComConfig->ComIPdu[IPduId];
Com_Arc_IPdu_type *Arc_IPdu = GET_ArcIPdu(IPduId);
const ComTxMode_type *txModePtr;
if( TRUE == Arc_IPdu->Com_Arc_IpduTxMode ) {
txModePtr = &IPdu->ComTxIPdu.ComTxModeTrue;
}
else {
txModePtr = &IPdu->ComTxIPdu.ComTxModeFalse;
}
timerDec(Arc_IPdu->Com_Arc_TxIPduTimers.ComTxModeTimePeriodTimer);
/* Is it time for a direct transmission?*/
if ( (txModePtr->ComTxModeMode == COM_MIXED)
&& (Arc_IPdu->Com_Arc_TxIPduTimers.ComTxIPduNumberOfRepetitionsLeft > 0) ) {
timerDec(Arc_IPdu->Com_Arc_TxIPduTimers.ComTxModeRepetitionPeriodTimer);
if(FALSE == dmTimeOut) {
/* @req COM305.2 */
/* Is it time for a transmission?*/
if ( (Arc_IPdu->Com_Arc_TxIPduTimers.ComTxModeRepetitionPeriodTimer == 0)
&& (Arc_IPdu->Com_Arc_TxIPduTimers.ComTxIPduMinimumDelayTimer == 0) ) {
Com_TriggerIPDUSend(IPduId);
/* Reset periodic timer*/
Arc_IPdu->Com_Arc_TxIPduTimers.ComTxModeRepetitionPeriodTimer = txModePtr->ComTxModeRepetitionPeriodFactor;
/* Register this nth-transmission.*/
/* @req COM494 */
Arc_IPdu->Com_Arc_TxIPduTimers.ComTxIPduNumberOfRepetitionsLeft--;
}
} else {
/* @req COM392 */
/* @req COM305.2 */
/* Cancel outstanding N time transmission due to DM timeout */
Arc_IPdu->Com_Arc_TxIPduTimers.ComTxIPduNumberOfRepetitionsLeft = 0;
/* Cancel the wait for outstanding Tx confirmations as well */
Arc_IPdu->Com_Arc_TxIPduTimers.ComTxIPduNumberOfTxConfirmations = 0;
}
}
/* Is it time for a cyclic transmission?*/
if ( (Arc_IPdu->Com_Arc_TxIPduTimers.ComTxModeTimePeriodTimer == 0) && (Arc_IPdu->Com_Arc_TxIPduTimers.ComTxIPduMinimumDelayTimer == 0) ) {
Com_TriggerIPDUSend(IPduId);
/* Reset periodic timer.*/
Arc_IPdu->Com_Arc_TxIPduTimers.ComTxModeTimePeriodTimer = txModePtr->ComTxModeTimePeriodFactor;
/* start/reset the DM timer for cyclic part (Mixed or periodic) only if not running or cancelled */
if((0 < Arc_IPdu->Com_Arc_TxDeadlineCounter) &&
(Arc_IPdu->Com_Arc_TxIPduTimers.ComTxDMTimer == 0)){
Arc_IPdu->Com_Arc_TxIPduTimers.ComTxDMTimer = Arc_IPdu->Com_Arc_TxDeadlineCounter;
}
}
}
/**
* Tx sub main function- routed from Com_MainFunctionTx
* Processes direct tx pdus
* handles the Tx timing functionalities/timers as well
* @param IPduId
* @param dmTimeOut
* @return none
*/
static void Com_ProcessDirectTxMode(uint16 IPduId,boolean dmTimeOut){
const ComIPdu_type *IPdu;
IPdu = &ComConfig->ComIPdu[IPduId];
Com_Arc_IPdu_type *Arc_IPdu = GET_ArcIPdu(IPduId);
const ComTxMode_type *txModePtr;
if( TRUE == Arc_IPdu->Com_Arc_IpduTxMode ) {
txModePtr = &IPdu->ComTxIPdu.ComTxModeTrue;
}
else {
txModePtr = &IPdu->ComTxIPdu.ComTxModeFalse;
}
/* Do we need to transmit anything?*/
if (Arc_IPdu->Com_Arc_TxIPduTimers.ComTxIPduNumberOfRepetitionsLeft > 0) {
timerDec(Arc_IPdu->Com_Arc_TxIPduTimers.ComTxModeRepetitionPeriodTimer);
if(FALSE == dmTimeOut) {
/* @req COM305.2 */
/* Is it time for a transmission?*/
if ( (Arc_IPdu->Com_Arc_TxIPduTimers.ComTxModeRepetitionPeriodTimer == 0) && (Arc_IPdu->Com_Arc_TxIPduTimers.ComTxIPduMinimumDelayTimer == 0) ) {
Com_TriggerIPDUSend(IPduId);
/* Reset periodic timer*/
Arc_IPdu->Com_Arc_TxIPduTimers.ComTxModeRepetitionPeriodTimer = txModePtr->ComTxModeRepetitionPeriodFactor;
/* Register this nth-transmission.*/
Arc_IPdu->Com_Arc_TxIPduTimers.ComTxIPduNumberOfRepetitionsLeft--;
}
}
else {
/* @req COM392 */
/* Cancel outstanding N time transmission due to DM timeout */
Arc_IPdu->Com_Arc_TxIPduTimers.ComTxIPduNumberOfRepetitionsLeft = 0;
/* Cancel the wait for outstanding Tx confirmations as well */
Arc_IPdu->Com_Arc_TxIPduTimers.ComTxIPduNumberOfTxConfirmations = 0;
}
}
}
/**
* Rx Main function- called from the task context
* Processes the incoming signals or signal groups,
* updates responsibles of their signals
* handles the rx timing functionalities/timers
* @param void
* @return none
*/
void Com_MainFunctionRx(void) {
/* !req COM513 */
/* !req COM053 */
/* !req COM352 */
/* @req COM664 */
if( COM_INIT != Com_GetStatus() ) {
DET_REPORTERROR(COM_MAINFUNCTIONRX_ID, COM_E_UNINIT);
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return;
}
for (uint16 pduId = 0; 0 == ComConfig->ComIPdu[pduId].Com_Arc_EOL; pduId++) {
const ComIPdu_type *IPdu = GET_IPdu(pduId);
const Com_Arc_IPdu_type *Arc_IPdu = GET_ArcIPdu(pduId);
if((IPdu->ComIPduDirection == COM_RECEIVE) && (TRUE == Arc_IPdu->Com_Arc_IpduStarted)){
boolean pduUpdated = false;
SchM_Enter_Com_EA_0();
for (uint16 sri = 0; (IPdu->ComIPduSignalRef != NULL) && (IPdu->ComIPduSignalRef[sri] != NULL); sri++) {
const ComSignal_type *signal = IPdu->ComIPduSignalRef[sri];
Com_Arc_Signal_type * Arc_Signal = GET_ArcSignal(signal->ComHandleId);
/* Monitor signal reception deadline*/
/* @req COM685 */
/* @req COM292 */
/* @req COM290 */
/* @req COM716 */
/* @req COM617 */
if ( (TRUE == Arc_IPdu->Com_Arc_IpduRxDMControl)&&
(signal->ComTimeoutFactor > 0) ) {
/* @req COM716 */
/* deadline timer can be zero for some signals as well hence the check for valid counter */
if(Arc_Signal->Com_Arc_DeadlineCounter != 0){
/* Decrease deadline monitoring timer.*/
timerDec(Arc_Signal->Com_Arc_DeadlineCounter);
/* Check if a timeout has occurred.*/
if (Arc_Signal->Com_Arc_DeadlineCounter == 0) {
/* @req COM500 */
/* @req COM744 */
boolean signalChanged = FALSE;
if (signal->Com_Arc_IsSignalGroup != FALSE) {
if (signal->ComRxDataTimeoutAction == COM_TIMEOUT_DATA_ACTION_REPLACE) {
for (uint32 i=0;signal->ComGroupSignal[i]!=NULL; i++)
{
Com_Misc_WriteSignalDataToPdu(
signal->ComGroupSignal[i]->ComSignalInitValue,
signal->ComGroupSignal[i]->ComSignalType,
Arc_IPdu->ComIPduDataPtr,
signal->ComGroupSignal[i]->ComBitPosition,
signal->ComGroupSignal[i]->ComBitSize,
signal->ComGroupSignal[i]->ComSignalEndianess,
&signalChanged);
}
Arc_Signal->ComSignalUpdated = TRUE;
}
}
else if (signal->ComRxDataTimeoutAction == COM_TIMEOUT_DATA_ACTION_REPLACE) {
/* Replace signal data.*/
/* @req COM470 */
Arc_Signal->ComSignalUpdated = TRUE;
Com_Misc_WriteSignalDataToPdu(
signal->ComSignalInitValue,
signal->ComSignalType,
Arc_IPdu->ComIPduDataPtr,
signal->ComBitPosition,
signal->ComBitSize,
signal->ComSignalEndianess,
&signalChanged);
}
else {
/*intentionally left blank, else part is for lint exception*/
}
/* A timeout has occurred.*/
/* @req COM556 */
/* take out this out of resource protection mechanism ?*/
if ((signal->ComTimeoutNotification != COM_NO_FUNCTION_CALLOUT) && (ComNotificationCallouts[signal->ComTimeoutNotification] != NULL) ) {
ComNotificationCallouts[signal->ComTimeoutNotification]();
}
#if (COM_OSEKNM_SUPPORT == STD_ON)
if (signal->ComOsekNmNetId != COM_OSEKNM_INVALID_NET_ID) {
OsekNm_TimeoutNotification(signal->ComOsekNmNetId, signal->ComOsekNmNodeId);
}
#endif
/* Restart timer*/
Arc_Signal->Com_Arc_DeadlineCounter = signal->ComTimeoutFactor;
}
}
}
if (TRUE == Arc_Signal->ComSignalUpdated) {
pduUpdated = true;
}
#if (COM_SIG_GATEWAY_ENABLE == STD_ON)
/* Use ComSignalRoutingReq variable for updated signal indication to avoid data consistency problems */
Arc_Signal->ComSignalRoutingReq = Arc_Signal->ComSignalUpdatedGwRouting;
Arc_Signal->ComSignalUpdatedGwRouting = FALSE;
#endif
}
if ((TRUE == pduUpdated) && (IPdu->ComIPduSignalProcessing == COM_DEFERRED) ) {
Com_Misc_UnlockTpBuffer(getPduId(IPdu));
memcpy(Arc_IPdu->ComIPduDeferredDataPtr,Arc_IPdu->ComIPduDataPtr,IPdu->ComIPduSize);
for (uint16 i = 0; (IPdu->ComIPduSignalRef != NULL) && (IPdu->ComIPduSignalRef[i] != NULL); i++) {
const ComSignal_type *signal = IPdu->ComIPduSignalRef[i];
Com_Arc_Signal_type * Arc_Signal = GET_ArcSignal(signal->ComHandleId);
if (TRUE == Arc_Signal->ComSignalUpdated) {
/* take out this out of resource protection mechanism ?*/
if ((signal->ComNotification != COM_NO_FUNCTION_CALLOUT) && (ComNotificationCallouts[signal->ComNotification] != NULL) ) {
ComNotificationCallouts[signal->ComNotification]();
}
Arc_Signal->ComSignalUpdated = FALSE;
}
}
}
#if (COM_SIG_GATEWAY_ENABLE == STD_ON)
Com_Arc_GwSrcDesc_type * gwSrcPtr;
uint16 srcSigDescHandle;
uint8 j;
/* Indicate new source description value */
if ((TRUE == IPdu->ComIPduGwRoutingReq) && (NULL != IPdu->ComIPduGwMapSigDescHandle)) {
for (j=0; IPdu->ComIPduGwMapSigDescHandle[j] != INVALID_GWSIGNAL_DESCRIPTION_HANDLE; j++){
srcSigDescHandle = IPdu->ComIPduGwMapSigDescHandle[j];
gwSrcPtr = GET_ArcGwSrcSigDesc(srcSigDescHandle);
/* Use ComSignalRoutingReq variable for updated signal indication to avoid data consistency problems */
gwSrcPtr->ComSignalRoutingReq= gwSrcPtr->ComSignalUpdatedGwRouting;
gwSrcPtr->ComSignalUpdatedGwRouting = FALSE;
}
}
#endif
SchM_Exit_Com_EA_0();
}
}
}
/**
* Tx Main function- called from the task context
* Processes the PDUS of all the tx modes, handles the timing functionalities/timers
* @param void
* @return none
*/
void Com_MainFunctionTx(void) {
/* !req COM789 */
boolean dmTimeOut;
/* @req COM665 */
if( COM_INIT != Com_GetStatus() ) {
DET_REPORTERROR(COM_MAINFUNCTIONTX_ID, COM_E_UNINIT);
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return;
}
const ComIPdu_type *IPdu;
for (uint16 i = 0; 0 == ComConfig->ComIPdu[i].Com_Arc_EOL; i++) {
IPdu = &ComConfig->ComIPdu[i];
Com_Arc_IPdu_type *Arc_IPdu = GET_ArcIPdu(i);
dmTimeOut = FALSE;
/* Is this a IPdu that should be transmitted?*/
if ( (IPdu->ComIPduDirection == COM_SEND) && (TRUE == Arc_IPdu->Com_Arc_IpduStarted) ) {
const ComTxMode_type *txModePtr;
if( TRUE == Arc_IPdu->Com_Arc_IpduTxMode ) {
txModePtr = &IPdu->ComTxIPdu.ComTxModeTrue;
}
else {
txModePtr = &IPdu->ComTxIPdu.ComTxModeFalse;
}
SchM_Enter_Com_EA_0();
/* Decrease minimum delay timer*/
timerDec(Arc_IPdu->Com_Arc_TxIPduTimers.ComTxIPduMinimumDelayTimer);
if(0 < Arc_IPdu->Com_Arc_TxDeadlineCounter) /* if DM configured for this TX pdu */
{
/* Decrement Tx deadline monitoring timer.*/
if(0 < Arc_IPdu->Com_Arc_TxIPduTimers.ComTxDMTimer){ /* if DM timer is running */
timerDec(Arc_IPdu->Com_Arc_TxIPduTimers.ComTxDMTimer);
if(Arc_IPdu->Com_Arc_TxIPduTimers.ComTxDMTimer == 0){/* if timed out */
dmTimeOut = TRUE;
/*NOTE : it could happen that a new request arrive via Com_SendSignalGroup() or Com_SendSignal() or
* Com_SendDynamicSignal() during wait for last request(at this time) hence DM timer would be restarted there
* */
}
}
}
/* If IPDU has periodic or mixed transmission mode.*/
if ( (txModePtr->ComTxModeMode == COM_PERIODIC)
|| (txModePtr->ComTxModeMode == COM_MIXED) ) {
Com_ProcessMixedOrPeriodicTxMode(i,dmTimeOut);
/* If IPDU has direct transmission mode.*/
} else if (txModePtr->ComTxModeMode == COM_DIRECT) {
Com_ProcessDirectTxMode(i,dmTimeOut);
}
/* The IDPU has NONE transmission mode.*/
/* @req COM135 */
/* !req COM835 */
else {
/* Don't send!*/
}
SchM_Exit_Com_EA_0();
/* Check notifications */
boolean confirmationStatus = Com_Misc_GetTxConfirmationStatus(IPdu);
Com_Misc_SetTxConfirmationStatus(IPdu, FALSE);
/* !req COM708 */
for (uint16 signalIndex = 0; (IPdu->ComIPduSignalRef != NULL) &&
(IPdu->ComIPduSignalRef[signalIndex] != NULL); signalIndex++)
{
const ComSignal_type *signal = IPdu->ComIPduSignalRef[signalIndex];
if(TRUE == confirmationStatus)
{
if ((signal->ComNotification != COM_NO_FUNCTION_CALLOUT) &&
(ComNotificationCallouts[signal->ComNotification] != NULL) ) {
ComNotificationCallouts[signal->ComNotification]();
}
}
/* notify with the DM callbacks registered */
/* @req COM554 */
/* @req COM304 */
if(TRUE == dmTimeOut){
if ((signal->ComTimeoutNotification != COM_NO_FUNCTION_CALLOUT) &&
(ComNotificationCallouts[signal->ComTimeoutNotification] != NULL) ) {
ComNotificationCallouts[signal->ComTimeoutNotification]();
}
#if (COM_OSEKNM_SUPPORT == STD_ON)
if (signal->ComOsekNmNetId != COM_OSEKNM_INVALID_NET_ID) {
OsekNm_TimeoutNotification(signal->ComOsekNmNetId, signal->ComOsekNmNodeId);
}
#endif
}
}
}
}
}
/**
* Main function gateway route - called from the task context
* Checks for all received signals and signal groups and routes
* @param void
* @return none
*/
/* @req COM400 */
/* @req COM667 */
/* @req COM668 */
void Com_MainFunctionRouteSignals( void ) {
/* @req COM666 */
if( COM_INIT != Com_GetStatus() ) {
DET_REPORTERROR(COM_MAINFUNCTIONROUTESIGNALS_ID, COM_E_UNINIT);
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return;
}
#if (COM_SIG_GATEWAY_ENABLE == STD_ON)
uint16 iPduHandle,sigHandle, bitSize,srcByteNo, destByteNo,noOfBytes,byteCnt;
const uint8 *srcDataPtr;
uint8 *destDataPtr;
const void *comSignalSrc;
const void * arcSignalSrc;
uint8 Data[8],j,i;
ComGwSignalRef_type sigRefType;
boolean isUpdated;
const Com_Arc_Signal_type *arcSignalDest;
Com_SignalType sigType;
const ComSignal_type* comSigGrp;
Com_Arc_ExtractPduInfo_Type pduInfo;
const ComSignal_type *comSignalDest;
/* @req COM359 */
/* @req COM370 */ /*Configs for gateway are empty if gateway mapping are absent*/
for (i=0;ComConfig->ComGwMappingRef[i].Com_Arc_EOL != 1; i++) {
isUpdated = FALSE;
sigRefType = ComConfig->ComGwMappingRef[i].ComGwSourceSignalRef;
sigHandle = ComConfig->ComGwMappingRef[i].ComGwSourceSignalHandle;
/*lint -save -e644 -e645 */
/* Signal group mapping */
if (COM_SIGNAL_GROUP_REFERENCE == sigRefType) {
/* @req COM361 */
comSignalSrc = GET_Signal(sigHandle);
arcSignalSrc = GET_ArcSignal(sigHandle);
isUpdated = ((const Com_Arc_Signal_type *)arcSignalSrc)->ComSignalRoutingReq;
if (TRUE == isUpdated) {
SchM_Enter_Com_EA_0();
Com_Misc_CopySignalGroupDataFromPduToShadowBuffer(sigHandle);
SchM_Exit_Com_EA_0();
for (j=0;j < ComConfig->ComGwMappingRef[i].ComGwNoOfDesitnationRoutes;j++) {
sigHandle = ComConfig->ComGwMappingRef[i].ComGwDestinationRef[j].ComGwDestinationSignalHandle;
comSignalDest = GET_Signal(sigHandle);
arcSignalDest = GET_ArcSignal(sigHandle);
srcByteNo = ((const ComSignal_type *)comSignalSrc)->ComBitPosition/8; /*Starting bit position*/
noOfBytes = ((((const ComSignal_type *)comSignalSrc)->ComEndBitPosition/8) - srcByteNo) + 1; /*No of data bytes*/
destByteNo = ((comSignalDest)->ComBitPosition/8);
srcDataPtr = (const uint8 *)(((const Com_Arc_Signal_type *)arcSignalSrc)->Com_Arc_ShadowBuffer);
/*lint -e{9005} GET_ArcSignal(sigHandle) value is modified by destDataPtr*/
destDataPtr = (uint8 *)((arcSignalDest)->Com_Arc_ShadowBuffer);
/* Manage Signal group routing as one consistent block by utilizing shadow buffer */
/* @req COM383 */
SchM_Enter_Com_EA_0();
for (byteCnt=0; byteCnt<noOfBytes; byteCnt++){
destDataPtr[destByteNo] = srcDataPtr[srcByteNo];
destByteNo++;
srcByteNo++;
}
SchM_Exit_Com_EA_0();
(void)Com_SendSignalGroup(sigHandle); /*Update destination IPdu ram buffer*/
}
}
} else {
switch(sigRefType) {
/* Signal mapping */
case COM_SIGNAL_REFERENCE:
/* @req COM357 */
comSignalSrc = GET_Signal(sigHandle);
arcSignalSrc = GET_ArcSignal(((const ComSignal_type *)comSignalSrc)->ComHandleId);
isUpdated = ((const Com_Arc_Signal_type *)arcSignalSrc)->ComSignalRoutingReq;
iPduHandle = ((const ComSignal_type *)comSignalSrc)->ComIPduHandleId;
bitSize =((const ComSignal_type *)comSignalSrc)->ComBitSize;
sigType =((const ComSignal_type *)comSignalSrc)->ComSignalType;
pduInfo.ComSignalType = sigType;
pduInfo.ComBitPosition = ((const ComSignal_type *)comSignalSrc)->ComBitPosition;
pduInfo.ComBitSize = bitSize;
pduInfo.ComSignalEndianess = ((const ComSignal_type *)comSignalSrc)->ComSignalEndianess;
break;
/* Group Signal mapping */
case COM_GROUP_SIGNAL_REFERENCE:
comSignalSrc = GET_GroupSignal(sigHandle);
comSigGrp = &ComConfig->ComSignal[((const ComGroupSignal_type *)comSignalSrc)->ComSigGrpHandleId];
arcSignalSrc = GET_ArcSignal(comSigGrp->ComHandleId);
isUpdated = ((const Com_Arc_Signal_type *)arcSignalSrc)->ComSignalRoutingReq;
iPduHandle = comSigGrp->ComIPduHandleId;
bitSize =((const ComGroupSignal_type *)comSignalSrc)->ComBitSize;
sigType =((const ComGroupSignal_type *)comSignalSrc)->ComSignalType;
pduInfo.ComSignalType = sigType;
pduInfo.ComBitPosition = ((const ComGroupSignal_type *)comSignalSrc)->ComBitPosition;
pduInfo.ComBitSize = bitSize;
pduInfo.ComSignalEndianess = ((const ComGroupSignal_type *)comSignalSrc)->ComSignalEndianess;
break;
/* Gateway source signal mapping */
case GATEWAY_SIGNAL_DESCRIPTION:
comSignalSrc = GET_GwSrcSigDesc(sigHandle);
arcSignalSrc = GET_ArcGwSrcSigDesc(sigHandle);
isUpdated = ((const Com_Arc_GwSrcDesc_type *)arcSignalSrc)->ComSignalRoutingReq;
iPduHandle = ((const ComGwSrcDesc_type *)comSignalSrc)->ComIPduHandleId;
bitSize =((const ComGwSrcDesc_type *)comSignalSrc)->ComBitSize;
sigType =((const ComGwSrcDesc_type *)comSignalSrc)->ComSignalType;
pduInfo.ComSignalType = sigType;
pduInfo.ComBitPosition = ((const ComGwSrcDesc_type *)comSignalSrc)->ComBitPosition;
pduInfo.ComBitSize = bitSize;
pduInfo.ComSignalEndianess = ((const ComGwSrcDesc_type *)comSignalSrc)->ComSignalEndianess;
break;
case COM_SIGNAL_GROUP_REFERENCE:
break;
default : break;
}
/* Route for new receptions */
if (TRUE == isUpdated) {
Com_Misc_ExtractGwSrcSigData(comSignalSrc,iPduHandle,Data,&pduInfo);
Com_Misc_RouteGwDestnSignals(i,Data,sigType,bitSize);
}
}
}
/*lint -restore */
#endif
}
|
2301_81045437/classic-platform
|
communication/Com/src/Com_Sched.c
|
C
|
unknown
| 25,431
|
/*-------------------------------- 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 <string.h>
#include "arc_assert.h"
#include "Com_Arc_Types.h"
#include "Com.h"
#include "Com_Internal.h"
#include "Com_misc.h"
#include "debug.h"
#include "Cpu.h"
#include "SchM_Com.h"
#if defined(USE_LINOS)
#include "linos_logger.h" /* Logger functions */
#endif
/* General tagging */
/* @req COM221 */
/* @req COM353 */
/* @req COM007 *//* Endianness conversion of integer types */
/* @req COM008 *//* Sign extension */
/* @req COM674 *//* Endianness conversion of signed data types */
/* @req COM723 *//* The AUTOSAR COM module shall extend the init value (ComSignalInitValue) of a signal to the size of its ComSignalType. */
/*lint -esym(9003, ComNotificationCallouts)*/ /* Defined in Com_Cfg.c */
extern const ComNotificationCalloutType ComNotificationCallouts[];
/*lint -esym(9003, ComTxIPduCallouts)*/ /* Defined in Com_Cfg.c */
extern const ComTxIPduCalloutType ComTxIPduCallouts[];
#if(COM_IPDU_COUNTING_ENABLE == STD_ON )
/* Com IPdu counters
* Next counter value to be transmitted or received */
#define COM_START_SEC_VAR_CLEARED_UNSPECIFIED
#include "Com_MemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/
static boolean ComIPduCountRxStart[COM_MAX_N_SUPPORTED_IPDU_COUNTERS];
#define COM_STOP_SEC_VAR_CLEARED_UNSPECIFIED
#include "Com_MemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/
#define COM_START_SEC_VAR_CLEARED_UNSPECIFIED
#include "Com_MemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/
static uint8 Com_IPdu_Counters[COM_MAX_N_SUPPORTED_IPDU_COUNTERS];
#define COM_STOP_SEC_VAR_CLEARED_UNSPECIFIED
#include "Com_MemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/
#if defined (HOST_TEST)
uint8 ReadInternalCouner(uint16 indx){
return Com_IPdu_Counters[indx];
}
#endif
/* Internal functions used to access IPdu counters*/
void ResetInternalCounter(uint16 indx) {
Com_IPdu_Counters[indx] = 0;
}
void ReSetInternalRxStartSts(uint16 indx) {
ComIPduCountRxStart[indx] = FALSE;
}
void ResetInternalCounterRxStartSts(void){
for (uint16 i = 0; i < COM_MAX_N_SUPPORTED_IPDU_COUNTERS ; i++){
Com_IPdu_Counters[i] = 0;
ComIPduCountRxStart[i] = FALSE;
}
}
static uint8 updateIPduCntr(const ComIPduCounter_type *CounterCfgRef, uint8 * sduPtr, uint16 * cntrIdx){
uint16 bytPos, bitPos, startPos, bitMask, cntrRng;
uint8 cntrVal, val;
startPos= CounterCfgRef->ComIPduCntrStartPos ;
bytPos = startPos / 8 ;
bitPos = startPos % 8 ;
cntrRng = CounterCfgRef->ComIPduCntrRange ;
/*lint -e{734} bit-pos is limited to value 7, result will not loose precision */
bitMask = ~((cntrRng - 1u) << bitPos) ;
*cntrIdx= CounterCfgRef->ComIPduCntrIndex ; /* Find the appropriate counter index */
/*lint -e{734} cntrRng can have range value 256 hence declared as uint16*/
cntrVal = (Com_IPdu_Counters[*cntrIdx] + 1) % (cntrRng); /* calculate updated counter value */
/* update the counter value in the IPdu */
val = (sduPtr[bytPos]) ;
/*lint -e{734} bit-pos is limited to value 7, result will not loose precision */
/*lint -e{701} cntrVal is unsigned*/
(sduPtr[bytPos]) = (val & (uint8) bitMask) | (cntrVal << bitPos) ;
return cntrVal;
}
static uint8 extractIPduCntr(const ComIPduCounter_type *CounterCfgRef, const uint8 * sduPtr){
uint16 bytPos, bitPos, startPos,cntrRng;
uint8 val, bitMask;
startPos= CounterCfgRef->ComIPduCntrStartPos ;
bytPos = startPos / 8 ;
bitPos = startPos % 8 ;
cntrRng = (CounterCfgRef->ComIPduCntrRange -1);
bitMask = (uint8)(cntrRng) ;
/* Extract IPdu counter from appropriate byte positions */
val = (sduPtr[bytPos]) ;
val = (val >> bitPos) & bitMask;
return val;
}
boolean Com_Misc_validateIPduCounter(const ComIPduCounter_type *CounterCfgRef, const uint8 * sduPtr) {
uint16 cntrIdx,cntrRng;
uint8 rxCntrVal,diff;
boolean ret = FALSE;
cntrIdx = CounterCfgRef->ComIPduCntrIndex ;
cntrRng = CounterCfgRef->ComIPduCntrRange ;
if (TRUE == ComIPduCountRxStart[cntrIdx]){
rxCntrVal = extractIPduCntr(CounterCfgRef, sduPtr);
/*lint -e{734} cntrRng can have range value 256 hence declared as uint16*/
diff = (rxCntrVal >= Com_IPdu_Counters[cntrIdx]) ? (rxCntrVal - Com_IPdu_Counters[cntrIdx]): (rxCntrVal + cntrRng - Com_IPdu_Counters[cntrIdx]);
/* @req COM590 */
if (diff <= CounterCfgRef->ComIPduCntrThrshldStep){
ret = TRUE; /*Accept IPdu only when criterion is fulfilled */
}
} else{
rxCntrVal = extractIPduCntr(CounterCfgRef, sduPtr);
ComIPduCountRxStart[cntrIdx] = TRUE;
/* @req COM587 */
ret = TRUE;
}
/* @req COM588 */
/*lint -e{734} cntrRng can have range value 256 hence declared as uint16*/
Com_IPdu_Counters[cntrIdx] = (rxCntrVal + 1) % cntrRng ;/* Set the next expected value*/
return ret;
}
#endif
/**
* Routine to handle new repetitions based on Transfer property if some transmit repetitions are already in progress
* correspondingly tx deadline counter is embedded with repetitions
* @param iPdu
* @param arcIPdu
* @param dataChanged
* @param transferProperty
* @return TRUE: Operation sucessful, FALSE: operation failed
*/
boolean Com_Misc_TriggerTxOnConditions(uint16 pduHandleId, boolean dataChanged, ComTransferPropertyType transferProperty)
{
const ComIPdu_type *IPdu = GET_IPdu(pduHandleId);
Com_Arc_IPdu_type *Arc_IPdu = GET_ArcIPdu(pduHandleId);
uint8 nofReps = 0;
boolean ret = FALSE;
boolean triggeredNow = FALSE;
const ComTxMode_type *txModePtr;
if( TRUE == Arc_IPdu->Com_Arc_IpduStarted ) {
if( TRUE == Arc_IPdu->Com_Arc_IpduTxMode ) {
txModePtr = &IPdu->ComTxIPdu.ComTxModeTrue;
}
else {
txModePtr = &IPdu->ComTxIPdu.ComTxModeFalse;
}
/* If signal has triggered transmit property, trigger a transmission!*/
/** Signal Requirements */
/* @req COM767 */
/* @req COM734 *//* NOTE: The actual sending is done in the main function */
/* @req COM768 */
/* @req COM762 *//* Signal with ComBitSize 0 should never be detected as changed */
/** Signal Group Requirements */
/* @req COM769 */
/* @req COM742 */
/* !req COM743 */
/* @req COM770 */
if ( (COM_TRIGGERED == transferProperty) || ( COM_TRIGGERED_WITHOUT_REPETITION == transferProperty ) ||
(((COM_TRIGGERED_ON_CHANGE == transferProperty) ||
(COM_TRIGGERED_ON_CHANGE_WITHOUT_REPETITION == transferProperty )) && (TRUE == dataChanged))) {
/* @req COM305.1 */
/* @req COM279 */
/** Signal Requirements */
/* @req COM330 */
/* @req COM467 */ /* Though RetryFailedTransmitRequests not supported. */
/** Signal Group Requirements */
/* @req COM741 */
switch(transferProperty) {
case COM_TRIGGERED:
case COM_TRIGGERED_ON_CHANGE:
if( 0 == txModePtr->ComTxModeNumberOfRepetitions ) {
nofReps = 1;
} else {
nofReps = txModePtr->ComTxModeNumberOfRepetitions;
}
break;
case COM_TRIGGERED_WITHOUT_REPETITION:
case COM_TRIGGERED_ON_CHANGE_WITHOUT_REPETITION:
nofReps = 1;
break;
default:
break;
}
ComTxModeModeType txMode = txModePtr->ComTxModeMode;
ComTxTriggerStatusType txTrigSts;
if ((COM_DIRECT == txMode) || (COM_MIXED == txMode)) {
if (nofReps > 0) {
/* @req COM625 */
/* @req COM701 *//* Routing is independent of DM. A new Transmission cycle is started for GW routing request */
txTrigSts = Com_Misc_TriggerIPDUSend(pduHandleId);
if(COM_TX_TRIGGERED == txTrigSts) {
/* Transmission triggered */
triggeredNow = TRUE;
Arc_IPdu->Com_Arc_TxIPduTimers.ComTxModeRepetitionPeriodTimer = txModePtr->ComTxModeRepetitionPeriodFactor;
nofReps--;
} else if (COM_TX_NOT_TRIGGERED == txTrigSts) {
/* Transmission was triggered but failed.*/
nofReps--;
Arc_IPdu->Com_Arc_TxIPduTimers.ComTxModeRepetitionPeriodTimer = txModePtr->ComTxModeRepetitionPeriodFactor;
} else if (COM_TX_MIN_DELAY_NOT_FULFILLED == txTrigSts) {
/* Transmission was delayed because Delay timer did not expire */
Arc_IPdu->Com_Arc_TxIPduTimers.ComTxModeRepetitionPeriodTimer =0;/*This triggers an IPDU immediately after delay timer expires*/
} else {
/*else created to avoid lint error*/
}
}
/* @req COM739 */ /* All new Tx Requests results in resetting DM timer */
if( Arc_IPdu->Com_Arc_TxIPduTimers.ComTxIPduNumberOfRepetitionsLeft <= nofReps ) {
/* All outstanding Transmission requests are kept as it is, if greater than current nofReps
* Probable case when first signal with transfer property TRIGGERED starts a cycle with n periodic transmissions
* and subsequently signal with transfer property TRIGGERED_WITHOUT_REPITION is requested for send. Total no. of Tx = n.*/
Arc_IPdu->Com_Arc_TxIPduTimers.ComTxIPduNumberOfRepetitionsLeft = nofReps;
/* * DM RESTART with this new request * */
if(0 < Arc_IPdu->Com_Arc_TxDeadlineCounter){
Arc_IPdu->Com_Arc_TxIPduTimers.ComTxIPduNumberOfTxConfirmations = nofReps + ((TRUE == triggeredNow) ? 1 : 0);
Arc_IPdu->Com_Arc_TxIPduTimers.ComTxDMTimer = Arc_IPdu->Com_Arc_TxDeadlineCounter;
}
} else if((TRUE == triggeredNow) && (0 != Arc_IPdu->Com_Arc_TxIPduTimers.ComTxIPduNumberOfRepetitionsLeft)) {
Arc_IPdu->Com_Arc_TxIPduTimers.ComTxIPduNumberOfRepetitionsLeft--;
} else {
/*else created to avoid lint error*/
}
}
}
ret = TRUE;
}
return ret;
}
void Com_Misc_CopySignalGroupDataFromShadowBufferToPdu(const Com_SignalIdType signalGroupId, boolean deferredBufferDestination, boolean *dataChanged) {
/* Get PDU*/
const ComSignal_type * Signal = GET_Signal(signalGroupId);
const ComIPdu_type *IPdu = GET_IPdu(Signal->ComIPduHandleId);
const Com_Arc_Signal_type * Arc_Signal = GET_ArcSignal(Signal->ComHandleId);
uint8 *pduDataPtr = NULL;
if (TRUE == deferredBufferDestination) {
pduDataPtr = GET_ArcIPdu(Signal->ComIPduHandleId)->ComIPduDeferredDataPtr;
} else {
pduDataPtr = GET_ArcIPdu(Signal->ComIPduHandleId)->ComIPduDataPtr;
}
/* Aligned opaque data -> straight copy with signalgroup mask*/
const uint8 *buf = (const uint8*)Arc_Signal->Com_Arc_ShadowBuffer;
uint8 data = 0;
*dataChanged = FALSE;
for(uint16 i= 0; i < IPdu->ComIPduSize; i++){
data = (~Signal->Com_Arc_ShadowBuffer_Mask[i] & *pduDataPtr) |
(Signal->Com_Arc_ShadowBuffer_Mask[i] & *buf);
if(*pduDataPtr != data) {
*dataChanged = TRUE;
}
*pduDataPtr = data;
buf++;
pduDataPtr++;
}
}
void Com_Misc_CopySignalGroupDataFromPduToShadowBuffer(const Com_SignalIdType signalGroupId) {
/* Get PDU*/
const ComSignal_type * Signal = GET_Signal(signalGroupId);
const ComIPdu_type *IPdu = GET_IPdu(Signal->ComIPduHandleId);
const uint8 *pduDataPtr = NULL;
if ((IPdu->ComIPduSignalProcessing == COM_DEFERRED) && (IPdu->ComIPduDirection == COM_RECEIVE)) {
pduDataPtr = GET_ArcIPdu(Signal->ComIPduHandleId)->ComIPduDeferredDataPtr;
} else {
pduDataPtr = GET_ArcIPdu(Signal->ComIPduHandleId)->ComIPduDataPtr;
}
if ( (FALSE == Signal->ComSignalArcUseUpdateBit) ||
/*lint -e{9016} -e{9005} -e{926} Array indexing couldn't be implemented, as parameters are of different data types */
( (TRUE == Signal->ComSignalArcUseUpdateBit) && (TESTBIT(pduDataPtr, Signal->ComUpdateBitPosition) > 0) ) ) {
/* Aligned opaque data -> straight copy with signalgroup mask*/
/*lint -e{9005} Com_Arc_ShadowBuffer value is required to be modified */
uint8 *buf = (uint8 *)GET_ArcSignal(Signal->ComHandleId)->Com_Arc_ShadowBuffer;
for(uint16 i= 0; i < IPdu->ComIPduSize; i++){
/*lint -e{9049} The post increment operation is required*/
*buf = (*buf & ~Signal->Com_Arc_ShadowBuffer_Mask[i]) | (Signal->Com_Arc_ShadowBuffer_Mask[i] & *pduDataPtr);
pduDataPtr++;
buf++;
}
}
}
/**
* Routine to read a 64 bits signal from a PDU
* @param comIPduDataPtr: Pointer to IPdu pduBuffer
* @param bitPosition: Signal bit position
* @param bitSize: Signal bit size
* @param endian: Signal endianness
* @param signalType: Signal type
* @param SignalData: Pointer where to store resulting signal data
* @return None
*/
static inline void Com_Misc_ReadSignalDataFromPdu64Bits (const uint8 *comIPduDataPtr,
Com_BitPositionType bitPosition, uint16 bitSize,
ComSignalEndianess_type endian, Com_SignalType signalType,
uint8 *SignalData) {
/* Covers signed and unsigned 64 bits signal types*/
/* Unaligned data and/or endianness conversion*/
uint64 pduData = 0ULL;
if(endian == COM_BIG_ENDIAN) {
uint32 lsbIndex = (((bitPosition ^ 0x7u) + bitSize - 1) ^ 7u); /* calculate lsb bit index. This could be moved to generator*/
const uint8 *pduDataPtr = ((&comIPduDataPtr [lsbIndex / 8])-7); /* calculate big endian ptr to data*/
uint8 bitShift = lsbIndex % 8;
for(uint32 i = 0; i < 8; i++) {
pduData = (pduData << 8) | pduDataPtr[i];
}
pduData >>= bitShift;
if((64 - bitShift) < bitSize) {
pduData |= (uint64)pduDataPtr[-1] << (64u - bitShift);
}
} else if (endian == COM_LITTLE_ENDIAN) {
uint32 lsbIndex = bitPosition;
const uint8 *pduDataPtr = &comIPduDataPtr[(bitPosition/8)];
uint8 bitShift = lsbIndex % 8;
for(sint32 i = 7; i >= 0; i--) {
pduData = (pduData << 8) | pduDataPtr[i];
}
pduData >>= bitShift;
if((64 - bitShift) < bitSize) {
pduData |= (uint64)pduDataPtr[8] << (64u - bitShift);
}
} else {
ASSERT(0);
}
SchM_Exit_Com_EA_0();
uint64 mask = (0xFFFFFFFFFFFFFFFFULL >> (64u - bitSize)); /* calculate mask for SigVal*/
pduData &= mask; /* clear bit out of range*/
uint64 signmask = ~(mask >> 1u);
switch(signalType) {
case COM_SINT64:
if(0 < (pduData & signmask)) {
pduData |= signmask; /* add sign bits*/
}
/* sign extended data can be written as uint*/
/*lint -e{826} -e{927} pointer cast is essential */
*(uint64*)SignalData = pduData;
break;
case COM_UINT64:
/*lint -e{826} -e{927} pointer cast is essential */
*(uint64*)SignalData = pduData;
break;
default:
/* This function is for 64 bits values only, even if it in theory could handle also other signal types*/
// IMPROVEMENT: Report error to DET.
ASSERT(0);
}
}
void Com_Misc_ReadSignalDataFromPdu (
const uint8 *comIPduDataPtr,
Com_BitPositionType bitPosition,
uint16 bitSize,
ComSignalEndianess_type endian,
Com_SignalType signalType,
uint8 *SignalData) {
SchM_Enter_Com_EA_0();
if ((endian == COM_OPAQUE) || (signalType == COM_UINT8_N)) {
/* Aligned opaque data -> straight copy*/
/* @req COM472 */
memcpy(SignalData, &comIPduDataPtr[bitPosition/8], bitSize / 8);
SchM_Exit_Com_EA_0();
} else if ((signalType != COM_UINT64) && (signalType != COM_SINT64)) {
/* Unaligned data and/or endian-ness conversion*/
uint32 pduData = 0ULL;
if(endian == COM_BIG_ENDIAN) {
uint32 lsbIndex = ((bitPosition ^ 0x7u) + bitSize - 1) ^ 7u; /* calculate lsb bit index. This could be moved to generator*/
const uint8 *pduDataPtr = ((&comIPduDataPtr [lsbIndex / 8])-3); /* calculate big endian ptr to data*/
uint8 bitShift = lsbIndex % 8;
for(uint32 i = 0; i < 4; i++) {
pduData = (pduData << 8) | pduDataPtr[i];
}
pduData >>= bitShift;
if((32 - bitShift) < bitSize) {
pduData |= (uint32)pduDataPtr[-1] << (32u - bitShift);
}
} else if (endian == COM_LITTLE_ENDIAN) {
uint32 lsbIndex = bitPosition;
const uint8 *pduDataPtr = &comIPduDataPtr[(bitPosition/8)];
uint8 bitShift = lsbIndex % 8;
for(sint32 i = 3; i >= 0; i--) {
pduData = (pduData << 8) | pduDataPtr[i];
}
pduData >>= bitShift;
if((32 - bitShift) < bitSize) {
pduData |= (uint32)pduDataPtr[4] << (32u - bitShift);
}
} else {
ASSERT(0);
}
SchM_Exit_Com_EA_0();
uint32 mask = 0xFFFFFFFFUL >> (32u - bitSize); /* calculate mask for SigVal */
pduData &= mask; /* clear bit out of range */
uint32 signmask = ~(mask >> 1u);
switch(signalType) {
case COM_SINT8:
if(0 < (pduData & signmask)) {
pduData |= signmask; /* add sign bits */
}
/* sign extended data can be written as uint*/
/*lint -e{734} pointer cast and assigning 32bit pduData to 8bit SignalData is required operation*/
*SignalData = pduData;
break;
case COM_BOOLEAN:
/*lint -e{734} pointer cast and assigning 32bit pduData to 8bit SignalData is required operation*/
*SignalData = pduData;
break;
case COM_UINT8:
/*lint -e{734} pointer cast and assigning 32bit pduData to 8bit SignalData is required operation*/
*SignalData = pduData;
break;
case COM_SINT16:
if(0 < (pduData & signmask)) {
pduData |= signmask; /* add sign bits*/
}
/* sign extended data can be written as uint*/
/*lint -e{927} -e{734} -e{826} pointer cast and assigning 32bit pduData to 16bit SignalData is required operation*/
*(uint16*)SignalData = pduData;
break;
case COM_UINT16:
/*lint -e{927} -e{734} -e{826} pointer cast and assigning 32bit pduData to 16bit SignalData is required operation*/
*(uint16*)SignalData = pduData;
break;
case COM_SINT32:
if(0 < (pduData & signmask)) {
pduData |= signmask; /* add sign bits*/
}
/*sign extended data can be written as uint */
/*lint -e{927} -e{826} pointer cast is required operation*/
*(uint32*)SignalData = pduData;
break;
case COM_UINT32:
/*lint -e{927} -e{826} pointer cast is required operation*/
*(uint32*)SignalData = pduData;
break;
case COM_UINT8_N:
case COM_UINT8_DYN:
case COM_SINT64:
case COM_UINT64:
ASSERT(0);
break;
default : break;
}
} else {
/* Call separate function for 64bits values.*/
/* Note: SchM_Exit_Com_EA_0 is called from within called function */
Com_Misc_ReadSignalDataFromPdu64Bits(comIPduDataPtr, bitPosition,
bitSize, endian, signalType, SignalData);
}
}
/**
* Routine to write a 64 bits signal to a PDU
* @param SignalDataPtr: Pointer to signal data to write
* @param signalType: Signal type
* @param comIPduDataPtr: Pointer to IPdu pduBuffer
* @param bitPosition: Signal bit position
* @param bitSize: Signal bit size
* @param endian: Signal endianness
* @param dataChanged: Pointer where to write data changed indication
* @return None
*/
static inline void Com_Misc_WriteSignalDataToPdu64Bits(const uint8 *SignalDataPtr,
Com_SignalType signalType, uint8 *comIPduDataPtr,
Com_BitPositionType bitPosition, uint16 bitSize,
ComSignalEndianess_type endian, boolean *dataChanged) {
/* Covers signed and unsigned 64 bits signal types*/
if ((signalType != COM_UINT64) && (signalType != COM_SINT64)) {
/* This function is for 64 bits values only, even if it in theory could handle also other signal types*/
// IMPROVEMENT: Report error to DET.
ASSERT(0);
}
/*lint -e{927} -e{826} pointer cast is required operation*/
uint64 sigVal = *((const uint64*)SignalDataPtr);
uint64 mask = 0xFFFFFFFFFFFFFFFFu >> (64u - bitSize); /* calculate mask for SigVal*/
sigVal &= mask; // mask sigVal;
SchM_Enter_Com_EA_0();
if(endian == COM_BIG_ENDIAN) {
uint32 lsbIndex = ((bitPosition ^ 0x7u) + bitSize - 1) ^ 7u; /* calculate lsb bit index. This could be moved to generator*/
uint8 *pduDataPtr = ((&comIPduDataPtr [lsbIndex / 8])-7); /* calculate big endian ptr to data*/
uint64 pduData = 0;
for(uint32 i = 0; i < 8; i++) {
pduData = (pduData << 8) | pduDataPtr[i];
}
uint8 bitShift = lsbIndex % 8;
uint64 sigLo = sigVal << bitShift;
uint64 maskLo = ~(mask << bitShift);
uint64 newPduData = (pduData & maskLo) | sigLo;
*dataChanged = (newPduData != pduData);
for(sint16 i = 7; i >= 0; i--) {
pduDataPtr[i] = (uint8)newPduData;
newPduData >>= 8;
}
uint8 maxBitsWritten = 64 - bitShift;
if(maxBitsWritten < bitSize) {
pduDataPtr--;
pduData = *pduDataPtr;
uint64 maskHi = ~(mask >> maxBitsWritten);
uint64 sigHi = sigVal >> maxBitsWritten;
newPduData = (pduData & maskHi) | sigHi;
*dataChanged |= (newPduData != pduData) ? TRUE : *dataChanged;
*pduDataPtr = (uint8)newPduData;
}
} else if (endian == COM_LITTLE_ENDIAN) {
uint32 lsbIndex = bitPosition; /* calculate lsb bit index.*/
uint8 *pduDataPtr = (&comIPduDataPtr[lsbIndex / 8]); /* calculate big endian ptr to data*/
uint64 pduData = 0;
for(sint32 i = 7; i >= 0; i--) {
pduData = (pduData << 8) | pduDataPtr[i];
}
uint8 bitShift = lsbIndex % 8;
uint64 sigLo = sigVal << bitShift;
uint64 maskLo = ~(mask << bitShift);
uint64 newPduData = (pduData & maskLo) | sigLo;
*dataChanged = (newPduData != pduData);
for(uint32 i = 0; i < 8; i++) {
pduDataPtr[i] = (uint8)newPduData;
newPduData >>= 8;
}
uint8 maxBitsWritten = 64u - bitShift;
if(maxBitsWritten < bitSize) {
pduDataPtr = &pduDataPtr[8];
pduData = *pduDataPtr;
uint64 maskHi = ~(mask >> maxBitsWritten);
uint64 sigHi = sigVal >> maxBitsWritten;
newPduData = (pduData & maskHi) | sigHi;
*dataChanged = (newPduData != pduData) ? TRUE : *dataChanged;
*pduDataPtr = (uint8)newPduData;
}
} else {
ASSERT(0);
}
}
void Com_Misc_WriteSignalDataToPdu(const uint8 *SignalDataPtr, Com_SignalType signalType,
uint8 *comIPduDataPtr, Com_BitPositionType bitPosition,
uint16 bitSize, ComSignalEndianess_type endian,
boolean *dataChanged) {
if ((endian == COM_OPAQUE) || (signalType == COM_UINT8_N)) {
/* @req COM472 */
uint8 *pduBufferBytes = &(comIPduDataPtr[bitPosition / 8]);
uint16 signalLength = bitSize / 8;
SchM_Enter_Com_EA_0();
*dataChanged = ( 0 != memcmp(pduBufferBytes, SignalDataPtr, signalLength) );
memcpy(pduBufferBytes, SignalDataPtr, signalLength);
#if defined(USE_LINOS)
logger(LOG_INFO, "Com_Misc_WriteSignalDataToPdu pduBufferBytes [%s]",
logger_format_hex(pduBufferBytes, signalLength));
#endif
} else if ((signalType != COM_UINT64) && (signalType != COM_SINT64)) {
uint32 sigVal = 0;
switch(signalType) {
case COM_BOOLEAN:
case COM_UINT8:
case COM_SINT8:
sigVal = *(SignalDataPtr);
break;
case COM_UINT16:
case COM_SINT16:
/*lint -e{826} -e{927} uint8* to uint16* casting is required */
sigVal = *((const uint16*)SignalDataPtr);
break;
case COM_UINT32:
case COM_SINT32:
/*lint -e{826} -e{927} uint8* to uint16* casting is required */
sigVal = *((const uint32*)SignalDataPtr);
break;
case COM_UINT8_N:
case COM_UINT8_DYN:
case COM_UINT64:
case COM_SINT64:
ASSERT(0);
break;
default: break;
}
uint32 mask = 0xFFFFFFFFu >> (32u - bitSize); /* calculate mask for SigVal*/
sigVal &= mask; // mask sigVal;
SchM_Enter_Com_EA_0();
if(endian == COM_BIG_ENDIAN) {
uint32 lsbIndex = ((bitPosition ^ 0x7u) + bitSize - 1) ^ 7u; /* calculate lsb bit index. This could be moved to generator*/
uint8 *pduDataPtr = ((&comIPduDataPtr [lsbIndex / 8])-3); /* calculate big endian ptr to data*/
uint32 pduData = 0;
for(uint32 i = 0; i < 4; i++) {
pduData = (pduData << 8) | pduDataPtr[i];
}
uint8 bitShift = lsbIndex % 8;
uint32 sigLo = sigVal << bitShift;
uint32 maskLo = ~(mask << bitShift);
uint32 newPduData = (pduData & maskLo) | sigLo;
*dataChanged = (newPduData != pduData);
for(sint16 i = 3; i >= 0; i--) {
pduDataPtr[i] = (uint8)newPduData;
newPduData >>= 8;
}
uint8 maxBitsWritten = 32 - bitShift;
if(maxBitsWritten < bitSize) {
pduDataPtr--;
pduData = *pduDataPtr;
uint32 maskHi = ~(mask >> maxBitsWritten);
uint32 sigHi = sigVal >> maxBitsWritten;
newPduData = (pduData & maskHi) | sigHi;
*dataChanged |= (newPduData != pduData) ? TRUE : *dataChanged;
*pduDataPtr = (uint8)newPduData;
}
} else if (endian == COM_LITTLE_ENDIAN) {
uint32 lsbIndex = bitPosition; /* calculate lsb bit index.*/
uint8 *pduDataPtr = (&comIPduDataPtr[lsbIndex / 8]); /* calculate big endian ptr to data*/
uint32 pduData = 0;
for(sint32 i = 3; i >= 0; i--) {
pduData = (pduData << 8) | pduDataPtr[i];
}
uint8 bitShift = lsbIndex % 8;
uint32 sigLo = sigVal << bitShift;
uint32 maskLo = ~(mask << bitShift);
uint32 newPduData = (pduData & maskLo) | sigLo;
*dataChanged = (newPduData != pduData);
for(uint32 i = 0; i < 4; i++) {
pduDataPtr[i] = (uint8)newPduData;
newPduData >>= 8;
}
uint8 maxBitsWritten = 32 - bitShift;
if(maxBitsWritten < bitSize) {
pduDataPtr = &pduDataPtr[4];
pduData = *pduDataPtr;
uint32 maskHi = ~(mask >> maxBitsWritten);
uint32 sigHi = sigVal >> maxBitsWritten;
newPduData = (pduData & maskHi) | sigHi;
*dataChanged = (newPduData != pduData) ? TRUE : *dataChanged;
*pduDataPtr = (uint8)newPduData;
}
} else {
ASSERT(0);
}
} else {
/* Separate function for 64bits values*/
/* Note: SchM_Enter_Com_EA_0 is called from within called function*/
Com_Misc_WriteSignalDataToPdu64Bits(SignalDataPtr, signalType,
comIPduDataPtr, bitPosition, bitSize, endian, dataChanged);
}
SchM_Exit_Com_EA_0();
}
void Com_Misc_RxProcessSignals(const ComIPdu_type *IPdu,const Com_Arc_IPdu_type *Arc_IPdu) {
/* !req COM053 */
/* @req COM055 */
/* !req COM396 */ /* Neither invalidation nor filtering supported */
/* !req COM352 */
const ComSignal_type *comSignal;
for (uint16 i = 0; IPdu->ComIPduSignalRef[i] != NULL; i++) {
comSignal = IPdu->ComIPduSignalRef[i];
Com_Arc_Signal_type * Arc_Signal = GET_ArcSignal(comSignal->ComHandleId);
/* If this signal uses an update bit, then it is only considered if this bit is set.*/
/* @req COM324 */
/* @req COM067 */
/* Eligible for gateway routing if update bit is available and set */
/* @req COM702 */
/* @req COM703 */
/* @req COM705 */
if ( (FALSE == comSignal->ComSignalArcUseUpdateBit) ||
/*lint -e{9016} Array indexing couldn't be implemented, as parameters are of different data types */
( (TRUE == comSignal->ComSignalArcUseUpdateBit) && (TESTBIT(Arc_IPdu->ComIPduDataPtr, comSignal->ComUpdateBitPosition) > 0) ) ) {
if (comSignal->ComTimeoutFactor > 0) { /* If reception deadline monitoring is used.*/
/* Reset the deadline monitoring timer.*/
/* @req COM715 */
Arc_Signal->Com_Arc_DeadlineCounter = comSignal->ComTimeoutFactor;
}
#if (COM_SIG_GATEWAY_ENABLE == STD_ON)
/* Save the indication of new signal for gateway routing */
if ((TRUE == IPdu->ComIPduGwRoutingReq) && (TRUE == comSignal->ComSigGwRoutingReq)) {
Arc_Signal->ComSignalUpdatedGwRouting = TRUE;
}
#endif
/* Check the signal processing mode.*/
if (IPdu->ComIPduSignalProcessing == COM_IMMEDIATE) {
/* If signal processing mode is IMMEDIATE, notify the signal callback.*/
/* @req COM300 */
/* @req COM301 */
if ((IPdu->ComIPduSignalRef[i]->ComNotification != COM_NO_FUNCTION_CALLOUT) &&
(ComNotificationCallouts[IPdu->ComIPduSignalRef[i]->ComNotification] != NULL) ) {
ComNotificationCallouts[IPdu->ComIPduSignalRef[i]->ComNotification]();
}
} else {
/* Signal processing mode is DEFERRED, mark the signal as updated.*/
Arc_Signal->ComSignalUpdated = TRUE;
}
} else {
DEBUG(DEBUG_LOW, "Com_RxIndication: Ignored signal %d of I-PDU %d since its update bit was not set\n", comSignal->ComHandleId, comSignal->ComIPduHandleId);
}
}
#if (COM_SIG_GATEWAY_ENABLE == STD_ON)
const ComGwSrcDesc_type * comGwSrcPtr;
uint16 srcSigDescHandle;
/* Save the indication for a new gateway signal description reception */
if ((TRUE == IPdu->ComIPduGwRoutingReq) && (NULL != IPdu->ComIPduGwMapSigDescHandle)) {
for (uint8 j=0; IPdu->ComIPduGwMapSigDescHandle[j] != INVALID_GWSIGNAL_DESCRIPTION_HANDLE; j++){
srcSigDescHandle = IPdu->ComIPduGwMapSigDescHandle[j];
comGwSrcPtr = GET_GwSrcSigDesc(srcSigDescHandle);
if ( (FALSE == comGwSrcPtr->ComSignalArcUseUpdateBit) ||
/*lint -e{9016} Array indexing couldn't be implemented, as parameters are of different data types */
( (TRUE == comGwSrcPtr->ComSignalArcUseUpdateBit) && (TESTBIT(Arc_IPdu->ComIPduDataPtr, comGwSrcPtr->ComUpdateBitPosition)> 0) ) ) {
(GET_ArcGwSrcSigDesc(srcSigDescHandle))->ComSignalUpdatedGwRouting = TRUE;
}
}
}
#endif
}
/**
* Sevice to handle transmission deadline monitoring logic
* Internal call
* Called from reception APIs
* @param IPdu
* @param Arc_IPdu
* @return none
*/
void Com_Misc_TxHandleDM(const ComIPdu_type *IPdu, Com_Arc_IPdu_type *Arc_IPdu)
{
const ComTxMode_type *txModePtr;
if((IPdu != NULL) && (Arc_IPdu != NULL) ){
if( TRUE == Arc_IPdu->Com_Arc_IpduTxMode ) {
txModePtr = &IPdu->ComTxIPdu.ComTxModeTrue;
}
else {
txModePtr = &IPdu->ComTxIPdu.ComTxModeFalse;
}
SchM_Enter_Com_EA_0();
switch( txModePtr->ComTxModeMode ) {
/* @req COM308 */
/* @req COM305.3 */
/* @req COM305.4 */ /* deviation - but no RTE callback at nth confirmation*/
case COM_DIRECT:
case COM_MIXED:
/* cancel the DM timer at the Nth( even if N = 1) confirmation */
if(0 < Arc_IPdu->Com_Arc_TxIPduTimers.ComTxIPduNumberOfTxConfirmations) {
Arc_IPdu->Com_Arc_TxIPduTimers.ComTxIPduNumberOfTxConfirmations--;
if(Arc_IPdu->Com_Arc_TxIPduTimers.ComTxIPduNumberOfTxConfirmations == 0){
Arc_IPdu->Com_Arc_TxIPduTimers.ComTxDMTimer = 0;
}
}
else { /* fall back */
Arc_IPdu->Com_Arc_TxIPduTimers.ComTxDMTimer = 0; /* cancel the DM timer at every confirmation */
}
break;
case COM_PERIODIC:
/* blindly cancel the timer, no check,
* since if timed out,indication could have gone for the timed out request
* and timer would have not started even if there was a new request */
Arc_IPdu->Com_Arc_TxIPduTimers.ComTxDMTimer = 0;
break;
case COM_NONE:
/* !req COM835 */
/* @req COM697 */ /* reset timer for each confirmation for TX mode NONE
* NONE mode is not taken care in the implementations */
Arc_IPdu->Com_Arc_TxIPduTimers.ComTxDMTimer = Arc_IPdu->Com_Arc_TxDeadlineCounter;
break;
default:
break;
}
SchM_Exit_Com_EA_0();
}
}
void Com_Misc_UnlockTpBuffer(PduIdType PduId) {
Com_BufferPduState[PduId].locked = false;
Com_BufferPduState[PduId].currentPosition = 0;
}
void Com_Misc_UpdateShadowSignal(Com_SignalIdType SignalId, const void *SignalDataPtr) {
const Com_Arc_GroupSignal_type *Arc_GroupSignal = GET_ArcGroupSignal(SignalId);
const ComGroupSignal_type *GroupSignal = GET_GroupSignal(SignalId);
/* @req COM632 */
/* @req COM633 */ /* Sign extension? */
boolean dataChanged = FALSE;
Com_Misc_WriteSignalDataToPdu(
SignalDataPtr,
GroupSignal->ComSignalType,
Arc_GroupSignal->Com_Arc_ShadowBuffer,
GroupSignal->ComBitPosition,
GroupSignal->ComBitSize,
GroupSignal->ComSignalEndianess,
&dataChanged);
}
/* Helpers for getting and setting that a TX PDU confirmation status
* These function uses the ComSignalUpdated for the first signal within the Pdu. The
* ComSignalUpdated isn't used for anything else in TxSignals and it is mainly used
* in Rx signals.
* The reason is to save RAM.
*/
void Com_Misc_SetTxConfirmationStatus(const ComIPdu_type *IPdu, boolean value) {
const ComSignal_type *signal = IPdu->ComIPduSignalRef[0];
if (signal != NULL) {
Com_Arc_Signal_type * Arc_Signal = GET_ArcSignal(signal->ComHandleId);
Arc_Signal->ComSignalUpdated = value;
}
}
boolean Com_Misc_GetTxConfirmationStatus(const ComIPdu_type *IPdu) {
boolean status;
status = FALSE;
if (IPdu != NULL) {
const ComSignal_type *signal = IPdu->ComIPduSignalRef[0];
if (signal == NULL) {
status = FALSE;
} else {
const Com_Arc_Signal_type * Arc_Signal = GET_ArcSignal(signal->ComHandleId);
status = Arc_Signal->ComSignalUpdated;
}
}
return status;
}
/**
* Implements functionality for Com_TriggerIPDUSend but returns
* wether transmission was triggered or not
* @param PduId
* @return COM_TX_TRIGGERED: Tx was triggered, COM_TX_NOT_TRIGGERED: Not triggered
*/
ComTxTriggerStatusType Com_Misc_TriggerIPDUSend(PduIdType PduId) {
#if(COM_IPDU_COUNTING_ENABLE == STD_ON )
uint16 cntrIdx = 0;
uint8 cntrVal = 0;
#endif
boolean status;
status = TRUE;
ComTxTriggerStatusType txTriggerStatus = COM_TX_NOT_TRIGGERED;
const ComIPdu_type *IPdu = GET_IPdu(PduId);
Com_Arc_IPdu_type *Arc_IPdu = GET_ArcIPdu(PduId);
SchM_Enter_Com_EA_0();
/* Is the IPdu ready for transmission?*/
/* @req COM388 */
if (Arc_IPdu->Com_Arc_TxIPduTimers.ComTxIPduMinimumDelayTimer == 0) {
/* Check callout status*/
/* @req COM492 */
/* @req COM346 */
/* !req COM381 */
/* IMPROVEMENT: No other COM API than Com_TriggerIPDUSend, Com_SendSignal or Com_SendSignalGroup
* can be called from an an I-PDU callout.*/
/* !req COM780 */
/* !req COM781 */
/* @req COM719 */
if ((IPdu->ComTxIPduCallout != COM_NO_FUNCTION_CALLOUT) && (ComTxIPduCallouts[IPdu->ComTxIPduCallout] != NULL) ) {
if (FALSE == ComTxIPduCallouts[IPdu->ComTxIPduCallout](PduId, Arc_IPdu->ComIPduDataPtr)) {
// IMPROVEMENT: Report error to DET.
// Det_ReportError();
txTriggerStatus = COM_TX_NOT_TRIGGERED;
status = FALSE;
}
}
if (status == TRUE) {
PduInfoType PduInfoPackage;
PduInfoPackage.SduDataPtr = (uint8 *)Arc_IPdu->ComIPduDataPtr;
if (IPdu->ComIPduDynSignalRef != 0) {
/* !req COM757 */ /*Length of I-PDU?*/
uint16 sizeWithoutDynSignal = IPdu->ComIPduSize - (IPdu->ComIPduDynSignalRef->ComBitSize/8);
PduInfoPackage.SduLength = sizeWithoutDynSignal + Arc_IPdu->Com_Arc_DynSignalLength;
} else {
PduInfoPackage.SduLength = IPdu->ComIPduSize;
}
#if(COM_IPDU_COUNTING_ENABLE == STD_ON )
if (ComConfig->ComIPdu[PduId].ComIpduCounterRef != NULL){
cntrVal = updateIPduCntr(ComConfig->ComIPdu[PduId].ComIpduCounterRef, PduInfoPackage.SduDataPtr, &cntrIdx) ;
}
#endif
/* Send IPdu!*/
/* @req COM138 */
if (PduR_ComTransmit(IPdu->ArcIPduOutgoingId, &PduInfoPackage) == E_OK) {
txTriggerStatus = COM_TX_TRIGGERED;
if (IPdu->ComTxIPdu.ComTxIPduClearUpdateBit == TRANSMIT) {
/* Clear all update bits for the contained signals*/
/* @req COM062 */
for (uint16 i = 0; (IPdu->ComIPduSignalRef != NULL) && (IPdu->ComIPduSignalRef[i] != NULL); i++) {
if (TRUE == IPdu->ComIPduSignalRef[i]->ComSignalArcUseUpdateBit) {
/*lint -e{9016} Array indexing couldn't be implemented, as parameters are of different data types */
CLEARBIT(Arc_IPdu->ComIPduDataPtr, IPdu->ComIPduSignalRef[i]->ComUpdateBitPosition);
}
}
}
#if (COM_SIG_GATEWAY_ENABLE == STD_ON)
const ComGwDestnDesc_type * gwSigDesc;
/* Reset the update bit for destination gateway signal description */
/* @req COM702 */
/* @req COM706 */
for (uint8 i = 0; (IPdu->ComIPduGwMapSigDescHandle != NULL) && (IPdu->ComIPduGwMapSigDescHandle[i] != INVALID_GWSIGNAL_DESCRIPTION_HANDLE); i++){
gwSigDesc = GET_GwDestnSigDesc(IPdu->ComIPduGwMapSigDescHandle[i]);
if (TRUE == gwSigDesc->ComSignalArcUseUpdateBit) {
/*lint -e{9016} Array indexing couldn't be implemented, as parameters are of different data types */
CLEARBIT(Arc_IPdu->ComIPduDataPtr, gwSigDesc->ComUpdateBitPosition);
}
}
#endif
#if(COM_IPDU_COUNTING_ENABLE == STD_ON )
/* @req COM688 */
if (ComConfig->ComIPdu[PduId].ComIpduCounterRef != NULL){
//lint -save -e644 //Warning:cntrVal & cntrIdx may not have been initialized. These are computed above
Com_IPdu_Counters[cntrIdx] = cntrVal ; /* Update counter value*/
//lint -restore
}
#endif
} else {
Com_Misc_UnlockTpBuffer(getPduId(IPdu));
}
/* Reset miminum delay timer.*/
/* @req COM471 */
/* @req COM698 */
Arc_IPdu->Com_Arc_TxIPduTimers.ComTxIPduMinimumDelayTimer = IPdu->ComTxIPdu.ComTxIPduMinimumDelayFactor;
}
} else {
/* Not time for transmission */
txTriggerStatus = COM_TX_MIN_DELAY_NOT_FULFILLED;
}
SchM_Exit_Com_EA_0();
return txTriggerStatus;
}
#if (COM_SIG_GATEWAY_ENABLE == STD_ON)
/* Rout destination signals and group signals */
void Com_Misc_RouteGwDestnSignals(uint8 gwMapidx, const uint8 * SignalDataPtr,Com_SignalType ComSigType,uint16 ComBitSize){
uint16 j,sigHandle, bitpos,ubitPos, iPduHandle;
ComGwSignalRef_type gwSignalRef;
boolean dataChanged;
const void * comSignalDest;
const Com_Arc_IPdu_type *arcIPduDest;
uint8 *comIPduDataPtr;
const Com_Arc_Signal_type * arcSigDest;
ComSignalEndianess_type endian;
boolean updateBitUsed;
const ComSignal_type* comSigGrp;
ComTransferPropertyType transferProperty;
boolean isValid = FALSE;
/* Copy gated signals to target IPdus and Evaluate runtime transmission properties */
/* @req COM466 */
for (j=0;j < ComConfig->ComGwMappingRef[gwMapidx].ComGwNoOfDesitnationRoutes;j++) {
/* Loop over all destination mappings */
gwSignalRef = ComConfig->ComGwMappingRef[gwMapidx].ComGwDestinationRef[j].ComGwDestinationSignalRef;
sigHandle = ComConfig->ComGwMappingRef[gwMapidx].ComGwDestinationRef[j].ComGwDestinationSignalHandle;
dataChanged = FALSE;
isValid = FALSE;
/* Type of destination signal */
switch (gwSignalRef) {
/*lint -save -e644 -e645 */
case COM_SIGNAL_REFERENCE:
/*lint -e{929} pointer cast is required*/
comSignalDest = (const ComSignal_type *)GET_Signal(sigHandle) ;
iPduHandle = ((const ComSignal_type *)comSignalDest)->ComIPduHandleId;
arcIPduDest = GET_ArcIPdu(iPduHandle);
comIPduDataPtr = arcIPduDest->ComIPduDataPtr;
bitpos = ((const ComSignal_type *)comSignalDest)->ComBitPosition;
endian = ((const ComSignal_type *)comSignalDest)->ComSignalEndianess;
ubitPos = ((const ComSignal_type *)comSignalDest)->ComUpdateBitPosition;
updateBitUsed = ((const ComSignal_type *)comSignalDest)->ComSignalArcUseUpdateBit;
transferProperty = ((const ComSignal_type *)comSignalDest)->ComTransferProperty;
isValid = TRUE;
break;
case COM_GROUP_SIGNAL_REFERENCE:
/*lint -e{929} pointer cast is required*/
comSignalDest = (const ComGroupSignal_type *)GET_GroupSignal(sigHandle) ;
sigHandle = ((const ComGroupSignal_type *)comSignalDest)->ComSigGrpHandleId;
comSigGrp = GET_Signal(sigHandle);
iPduHandle = comSigGrp->ComIPduHandleId;
arcIPduDest = GET_ArcIPdu(iPduHandle);
arcSigDest = GET_ArcSignal(sigHandle);
/*lint -e{9005} GET_ArcSignal(sigHandle) handled via comIPduDataPtr pointer*/
comIPduDataPtr = (uint8*)arcSigDest->Com_Arc_ShadowBuffer;
bitpos = ((const ComGroupSignal_type *)comSignalDest)->ComBitPosition;
endian = ((const ComGroupSignal_type *)comSignalDest)->ComSignalEndianess;
ubitPos = comSigGrp->ComUpdateBitPosition;
updateBitUsed = comSigGrp->ComSignalArcUseUpdateBit;
transferProperty = comSigGrp->ComTransferProperty;
isValid = TRUE;
break;
case GATEWAY_SIGNAL_DESCRIPTION:
/*lint -e{929} pointer cast is required*/
comSignalDest = (const ComGwDestnDesc_type *)GET_GwDestnSigDesc(sigHandle) ;
iPduHandle = ((const ComGwDestnDesc_type *)comSignalDest)->ComIPduHandleId;
arcIPduDest = GET_ArcIPdu(iPduHandle);
comIPduDataPtr = arcIPduDest->ComIPduDataPtr;
bitpos = ((const ComGwDestnDesc_type *)comSignalDest)->ComBitPosition;
endian = ((const ComGwDestnDesc_type *)comSignalDest)->ComSignalEndianess;
ubitPos = ((const ComGwDestnDesc_type *)comSignalDest)->ComUpdateBitPosition;
updateBitUsed = ((const ComGwDestnDesc_type *)comSignalDest)->ComSignalArcUseUpdateBit;
transferProperty = ((const ComGwDestnDesc_type *)comSignalDest)->ComTransferProperty;
isValid = TRUE;
break;
case COM_SIGNAL_GROUP_REFERENCE:/*This condition is erroneous*/
break;
default:/*This condition is erroneous*/
break;
}
if (FALSE == isValid) {
break;
}
/* Endianness conversion is handled by Com_Misc_WriteSignalDataToPdu() */
/* @req COM360 */
/* @req COM362 */
Com_Misc_WriteSignalDataToPdu(
SignalDataPtr,
ComSigType,
comIPduDataPtr,
bitpos,
ComBitSize,
endian,
&dataChanged);
/* Only if Update bit available it is set */
/* @req COM704 */
/* @req COM706 */
if (TRUE == updateBitUsed) {
/*lint -e{926} pointer cast is essential since SETBIT parameters are of different pointer data type*/
/*lint -e{9016} Array indexing couldn't be implemented, as parameters are of different data types */
SETBIT(comIPduDataPtr, ubitPos);
}
SchM_Enter_Com_EA_0();
if (COM_GROUP_SIGNAL_REFERENCE == gwSignalRef) {
/* Copy from shadow buffer to IPdu ram buffer */
Com_Misc_CopySignalGroupDataFromShadowBufferToPdu(sigHandle,FALSE,&dataChanged);
/* Only if Update bit available it is set */
/* @req COM704 */
/* @req COM706 */
if (TRUE == updateBitUsed) {
/*lint -e{9016} Array indexing couldn't be implemented, as parameters are of different data types */
SETBIT(arcIPduDest->ComIPduDataPtr, ubitPos);
}
}
/* Assign the number of repetitions based on Transfer property */
(void)Com_Misc_TriggerTxOnConditions(iPduHandle, dataChanged, transferProperty);
SchM_Exit_Com_EA_0();
/*lint -restore */
}
}
/* Extract source signal for gateway routing */
void Com_Misc_ExtractGwSrcSigData(const void* comSignalSrc, uint16 iPduHandle,uint8 *SigDataPtr, const Com_Arc_ExtractPduInfo_Type *pduInfo ) {
/*lint -e{920} comSignalSrc not used */
(void)comSignalSrc;
const Com_Arc_IPdu_type *arcIPduSrc;
const ComIPdu_type *iPdu;
const uint8* pduDataPtr = NULL;
uint16 startFromPduByte;
arcIPduSrc = GET_ArcIPdu(iPduHandle);
iPdu = GET_IPdu(iPduHandle);
if (iPdu->ComIPduSignalProcessing == COM_DEFERRED) {
pduDataPtr = arcIPduSrc->ComIPduDeferredDataPtr;
}else {
pduDataPtr = arcIPduSrc->ComIPduDataPtr;
}
if ((COM_UINT8_N != pduInfo->ComSignalType) && (COM_UINT8_DYN != pduInfo->ComSignalType)) {
Com_Misc_ReadSignalDataFromPdu(
pduDataPtr,
pduInfo->ComBitPosition,
pduInfo->ComBitSize,
pduInfo->ComSignalEndianess,
pduInfo->ComSignalType,
SigDataPtr);
} else {
startFromPduByte = (pduInfo->ComBitPosition) / 8;
SchM_Enter_Com_EA_0();
memcpy(SigDataPtr, (&pduDataPtr[startFromPduByte]), (pduInfo->ComBitSize)/8);
SchM_Exit_Com_EA_0();
}
}
#endif
|
2301_81045437/classic-platform
|
communication/Com/src/Com_misc.c
|
C
|
unknown
| 50,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 -----------------------------*/
#ifndef COM_MISC_H_
#define COM_MISC_H_
/* Copy Signal group data from PDU to shadowbuffer*/
void Com_Misc_CopySignalGroupDataFromPduToShadowBuffer(
const Com_SignalIdType signalGroupId);
/* Copy Signal group data from shadowbuffer to Pdu*/
void Com_Misc_CopySignalGroupDataFromShadowBufferToPdu(
const Com_SignalIdType signalGroupId,
boolean deferredBufferDestination,
boolean *dataChanged);
/**
* Reads signal data from Pdu
* @param comIPduDataPtr
* @param bitPosition
* @param bitSize
* @param endian
* @param signalType
* @param SignalData
*/
void Com_Misc_ReadSignalDataFromPdu (
const uint8 *comIPduDataPtr,
Com_BitPositionType bitPosition,
uint16 bitSize,
ComSignalEndianess_type endian,
Com_SignalType signalType,
uint8 *SignalData);
/**
* Write signal data to PDU
* @param SignalDataPtr
* @param signalType
* @param comIPduDataPtr
* @param bitPosition
* @param bitSize
* @param endian
* @param dataChanged
*/
void Com_Misc_WriteSignalDataToPdu(
const uint8 *SignalDataPtr,
Com_SignalType signalType,
uint8 *comIPduDataPtr,
Com_BitPositionType bitPosition,
uint16 bitSize,
ComSignalEndianess_type endian,
boolean *dataChanged);
void Com_Misc_UpdateShadowSignal(Com_SignalIdType SignalId, const void *SignalDataPtr);
/*
* This function copies numBits bits of data from Source to Destination with the possibility to offset
* both the source and destination.
*
* Return value: the last bit it copies (sign bit).
*/
//uint8 Com_CopyData(void *Destination, const void *Source, uint8 numBits, uint8 destOffset, uint8 sourceOffset);
//void Com_CopyData2(char *dest, const char *source, uint8 destByteLength, uint8 segmentStartBitOffset, uint8 segmentBitLength);
void Com_Misc_RxProcessSignals(const ComIPdu_type *IPdu,const Com_Arc_IPdu_type *Arc_IPdu);
void Com_Misc_TxHandleDM (const ComIPdu_type *IPdu, Com_Arc_IPdu_type *Arc_IPdu);
static inline PduIdType getPduId(const ComIPdu_type* IPdu) {
extern const Com_ConfigType * ComConfig;
/*lint -e{946} -e{947} pointers are subtracted to get the address
* which intern type-casted to uint16, the address of PduId is returned, which is the required operation*/
/*lint -e{9033} addresses are subtracted and casted to uint16, this is required operation*/
return (PduIdType)(IPdu - ComConfig->ComIPdu);
}
void Com_Misc_UnlockTpBuffer(PduIdType PduId);
#define isPduBufferLocked(id) Com_BufferPduState[id].locked
/* Helpers for getting and setting that a PDU confirmation status */
void Com_Misc_SetTxConfirmationStatus(const ComIPdu_type *IPdu, boolean value);
boolean Com_Misc_GetTxConfirmationStatus(const ComIPdu_type *IPdu);
/* Assign repition cycles for DIRECT and MIXED transmission modes */
boolean Com_Misc_ReAssignReps(const ComIPdu_type *IPdu,Com_Arc_IPdu_type *arcIPdu, boolean dataChanged, ComTransferPropertyType transferProperty);
#if (COM_SIG_GATEWAY_ENABLE == STD_ON)
/* Transmit destination signals/group signals */
void Com_Misc_RouteGwDestnSignals(uint8 gwMapidx, const uint8 * SignalDataPtr,Com_SignalType ComSigType,uint16 ComBitSize);
/* Extract receive signals/group signals */
void Com_Misc_ExtractGwSrcSigData(const void* comSignalSrc, uint16 iPduHandle,uint8 *SigDataPtr, const Com_Arc_ExtractPduInfo_Type *pduInfo ) ;
#endif
#endif /* COM_MISC_H_ */
|
2301_81045437/classic-platform
|
communication/Com/src/Com_misc.h
|
C
|
unknown
| 4,271
|
# ComM
obj-$(USE_COMM) += ComM.o
obj-$(USE_COMM) += ComM_Cfg.o
obj-$(USE_COMM) += ComM_ASIL.o
pb-obj-$(USE_COMM) += ComM_PBcfg.o
pb-pc-file-$(USE_COMM) += ComM_Cfg.h ComM_Cfg.c
inc-$(USE_COMM) += $(ROOTDIR)/communication/ComM/inc
inc-$(USE_COMM) += $(ROOTDIR)/communication/ComM/src
vpath-$(USE_COMM) += $(ROOTDIR)/communication/ComM/src
|
2301_81045437/classic-platform
|
communication/ComM/ComM.mod.mk
|
Makefile
|
unknown
| 349
|
/*-------------------------------- 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 COMM_H
#define COMM_H
/** @req COMM466 *//* ComStack_Types.h includes Std_Types.h */
#include "ComStack_Types.h" /** !req COMM820.partially */
#include "ComM_Types.h" /* @req COMM956 *//* Indirectly, ComM_Types.h includes Rte_ComM_Type.h */
#include "ComM_ConfigTypes.h"
/* @req COMM280 */
#define COMM_MODULE_ID 12u
#define COMM_VENDOR_ID 60u
#define COMM_AR_RELEASE_MAJOR_VERSION 4u
#define COMM_AR_RELEASE_MINOR_VERSION 0u
#define COMM_AR_RELEASE_REVISION_VERSION 3u
#define COMM_SW_MAJOR_VERSION 3u
#define COMM_SW_MINOR_VERSION 0u
#define COMM_SW_PATCH_VERSION 1u
/** @req COMM456 */
#include "ComM_Cfg.h"
#include "ComM_PBcfg.h"
#if (COMM_PNC_SUPPORT == STD_ON)
#include "Com.h"
#endif
/** Function call has been successfully but mode can not
* be granted because of mode inhibition. */
/** @req COMM649.1 */
#define COMM_E_MODE_LIMITATION 0x02u
/** ComM not initialized */
/** @req COMM649.2 */
#define COMM_E_UNINIT 0x03u
/** @req COMM509 */
#define COMM_E_NOT_INITED 0x1u /**< API service used without module initialization */
#define COMM_E_WRONG_PARAMETERS 0x2u /**< API service used with wrong parameters (e.g. a NULL pointer) */
#define COMM_SERVICEID_INIT 0x01u
#define COMM_SERVICEID_DEINIT 0x02u
#define COMM_SERVICEID_GETSTATUS 0x03u
#define COMM_SERVICEID_GETINHIBITIONSTATUS 0x04u
#define COMM_SERVICEID_REQUESTCOMMODE 0x05u
#define COMM_SERVICEID_GETMAXCOMMODE 0x06u
#define COMM_SERVICEID_GETREQUESTEDCOMMODE 0x07u
#define COMM_SERVICEID_GETCURRENTCOMMODE 0x08u
#define COMM_SERVICEID_PREVENTWAKEUP 0x09u
#define COMM_SERVICEID_LIMITCHANNELTONOCOMMODE 0x0bu
#define COMM_SERVICEID_LIMITECUTONOCOMMODE 0x0cu
#define COMM_SERVICEID_READINHIBITCOUNTER 0x0du
#define COMM_SERVICEID_RESETINHIBITCOUNTER 0x0eu
#define COMM_SERVICEID_SETECUGROUPCLASSIFICATION 0x0fu
#define COMM_SERVICEID_GETVERSIONINFO 0x10u
#define COMM_SERVICEID_NM_NETWORKSTARTINDICATION 0x15u
#define COMM_SERVICEID_NM_NETWORKMODE 0x18u
#define COMM_SERVICEID_NM_PREPAREBUSSLEEPMODE 0x19u
#define COMM_SERVICEID_NM_BUSSLEEPMODE 0x1au
#define COMM_SERVICEID_NM_RESTARTINDICATION 0x1bu
#define COMM_SERVICEID_DCM_ACTIVEDIAGNOSTIC 0x1fu
#define COMM_SERVICEID_DCM_INACTIVEDIAGNOSTIC 0x20u
//#define COMM_SERVICEID_ECUM_RUNMODEINDICATION 0x29u
#define COMM_SERVICEID_ECUM_WAKEUPINDICATION 0x2au
#define COMM_SERVICEID_BUSSM_MODEINDICATION 0x33u
#define COMM_SERVICEID_MAINFUNCTION 0x60u
#define COMM_SERVICEID_GETSTATE 0x34u
#define COMM_SERVICEID_COMMUNICATIONALLOWED 0x35u
#define COMM_MAIN_FUNCTION_PROTOTYPE(channel) \
void ComM_MainFunction_##channel (void)
#define COMM_MAIN_FUNCTION(channel) \
void ComM_MainFunction_##channel (void) { \
ComM_MainFunction(COMM_NETWORK_HANDLE_##channel); \
}
void ComM_MainFunction_All_Channels(void);
/** Initializes the AUTOSAR Communication Manager and restarts the internal state machines.*/
void ComM_Init(const ComM_ConfigType* Config); /**< @req COMM146 */
/** De-initializes (terminates) the AUTOSAR Communication Manager. */
void ComM_DeInit(void); /**< @req COMM147 */
/** @req COMM370 */
#if (COMM_VERSION_INFO_API == STD_ON) /** @req COMM823 */
/** @req COMM824 *//** @req COMM822 */
#define ComM_GetVersionInfo(_vi) \
((_vi)->vendorID = COMM_VENDOR_ID);\
((_vi)->moduleID = COMM_MODULE_ID);\
((_vi)->sw_major_version = COMM_SW_MAJOR_VERSION);\
((_vi)->sw_minor_version = COMM_SW_MINOR_VERSION);\
((_vi)->sw_patch_version = COMM_SW_PATCH_VERSION);
#endif
/** Returns the initialization status of the AUTOSAR Communication Manager. */
Std_ReturnType ComM_GetState(NetworkHandleType Channel, ComM_StateType *State);
Std_ReturnType ComM_GetStatus( ComM_InitStatusType* Status ); /**< @req COMM242 */
Std_ReturnType ComM_GetInhibitionStatus( NetworkHandleType Channel, ComM_InhibitionStatusType* Status ); /**< @req COMM619 */
Std_ReturnType ComM_RequestComMode( ComM_UserHandleType User, ComM_ModeType ComMode ); /**< @req COMM110 */
Std_ReturnType ComM_GetMaxComMode( ComM_UserHandleType User, ComM_ModeType* ComMode );
Std_ReturnType ComM_GetRequestedComMode( ComM_UserHandleType User, ComM_ModeType* ComMode ); /**< @req COMM79 */
Std_ReturnType ComM_GetCurrentComMode( ComM_UserHandleType User, ComM_ModeType* ComMode ); /**< @req COMM83 */
Std_ReturnType ComM_PreventWakeUp( NetworkHandleType Channel, boolean Status ); /**< @req COMM156 */
Std_ReturnType ComM_LimitChannelToNoComMode( NetworkHandleType Channel, boolean Status ); /**< @req COMM163 */
Std_ReturnType ComM_LimitECUToNoComMode( boolean Status ); /**< @req COMM124 */
Std_ReturnType ComM_ReadInhibitCounter( uint16* CounterValue ); /**< @req COMM224 */
Std_ReturnType ComM_ResetInhibitCounter(void); /**< @req COMM108 */
Std_ReturnType ComM_SetECUGroupClassification( ComM_InhibitionStatusType Status );
void ComM_EcuM_WakeUpIndication( NetworkHandleType Channel );
/** @req COMM871 */
void ComM_CommunicationAllowed(NetworkHandleType Channel, boolean Allowed);
#if (COMM_PNC_SUPPORT == STD_ON)
/**
* @brief Function to register new EIRA receive indication
*/
void ComM_Arc_IndicateNewRxEIRA(void);
/**
* @brief Function to register new ERA receive indication
*/
void ComM_Arc_IndicateNewRxERA(uint8 channelIndex);
#if (HOST_TEST == STD_ON)
uint64 * readEira(void);
ComM_PncStateType checkPncStatus(uint8 idx);
ComM_PncModeType checkPncMode(uint8 idx);
#endif
#endif
#endif /*COMM_H*/
|
2301_81045437/classic-platform
|
communication/ComM/inc/ComM.h
|
C
|
unknown
| 6,965
|
/*-------------------------------- 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 COMM_BUSSM_H_
#define COMM_BUSSM_H_
#include "ComStack_Types.h"
#include "ComM_Types.h"
void ComM_BusSM_ModeIndication( NetworkHandleType Channel,ComM_ModeType *ComMode );
#endif /*COMM_BUSSM_H_*/
|
2301_81045437/classic-platform
|
communication/ComM/inc/ComM_BusSM.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 COMM_CONFIGTYPES_H_
#define COMM_CONFIGTYPES_H_
#include "Com_Types.h"
typedef enum {
COMM_BUS_TYPE_CAN,
COMM_BUS_TYPE_FR,
COMM_BUS_TYPE_INTERNAL,
COMM_BUS_TYPE_LIN,
COMM_BUS_TYPE_ETH
} ComM_BusTypeType;
typedef enum {
COMM_NM_VARIANT_NONE,
COMM_NM_VARIANT_LIGHT,
COMM_NM_VARIANT_PASSIVE,
COMM_NM_VARIANT_FULL
} ComM_NmVariantType;
typedef enum {
COMM_GATEWAY_TYPE_NONE,
COMM_GATEWAY_TYPE_ACTIVE,
COMM_GATEWAY_TYPE_PASSIVE
} ComM_PncGatewayType;
typedef struct {
const ComM_BusTypeType BusType;
const NetworkHandleType ComMChannelId;
const NetworkHandleType NmChannelHandle;
const ComM_NmVariantType NmVariant;
const uint32 MainFunctionPeriod;
const uint32 LightTimeout;
const ComM_PncGatewayType PncGatewayType;
} ComM_ChannelType;
typedef Std_ReturnType (*ComM_RteSwitchUM)(/*IN*/uint8 mode);
typedef struct {
const ComM_ChannelType* const* ChannelList; /* Channels referred by User */
const ComM_ChannelType* const* PncChnlList; /* Channels referred by User via Pnc configuration */
ComM_RteSwitchUM ComMRteSwitchUM; /* Report mode change to users*/
const uint8 ChannelCount; /* No. of Channels mapped to user */
const uint8 PncChnlCount; /* No. of channels referenced by user via Pnc configuration */
} ComM_UserType;
/* configuration of PncComSignal */
typedef struct{
Com_SignalIdType ComMPncSignalId; /* Signal handle */
}ComM_PncComSignalType;
/* configuration of Pnc */
typedef struct{
const NetworkHandleType* ComMPncChnlRef; /* reference to Channels */
const uint8* ComMPncUserRef; /* reference to users */
PNCHandleType ComMPncId; /* Identifier for PNC */
uint8 ComMPncChnlRefNum; /* No of reference channels*/
uint8 ComMPncUserRefNum; /* No of reference users */
}ComM_PncType;
/* configuration collection for partial network*/
typedef struct{
const ComM_PncType* ComMPnc; /* reference to PNC config */
const uint8* ComMPncIdToPncCountVal; /* mapping from Pnc Id to PNC count(index) of the PNC */
const ComM_PncComSignalType* ComMPncEIRARxComSigIdRef; /* Signal Id Ref for Rx EIRA */
const ComM_PncComSignalType* ComMPncTxComSigIdRef; /* Signal Id reference for Tx signals */
const ComM_PncComSignalType* ComMPncERARxComSigIdRefs; /* Signal Id Refs for Rx ERA */
uint8 ComMPncNum; /* number of PNC config */
boolean ComMPncEnabled; /* switch to enable PN processing */
}ComM_PNConfigType;
typedef struct {
const ComM_ChannelType* Channels;
const ComM_UserType* Users;
const ComM_PNConfigType* ComMPncConfig;
} ComM_ConfigType;
#endif /* COMM_CONFIGTYPES_H_ */
|
2301_81045437/classic-platform
|
communication/ComM/inc/ComM_ConfigTypes.h
|
C
|
unknown
| 3,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 COMM_DCM_H
#define COMM_DCM_H
void ComM_DCM_ActiveDiagnostic(NetworkHandleType Channel); /** @req COMM873 */
void ComM_DCM_InactiveDiagnostic(NetworkHandleType Channel); /** @req COMM874 */
#endif /*COMM_DCM_H*/
|
2301_81045437/classic-platform
|
communication/ComM/inc/ComM_Dcm.h
|
C
|
unknown
| 988
|
/*-------------------------------- 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 COMM_ECUM_H
#define COMM_ECUM_H
void ComM_EcuM_WakeUpIndication( NetworkHandleType Channel );
#endif /*COMM_ECUM_H*/
|
2301_81045437/classic-platform
|
communication/ComM/inc/ComM_EcuM.h
|
C
|
unknown
| 892
|
/*-------------------------------- 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 "MemMap.h"
|
2301_81045437/classic-platform
|
communication/ComM/inc/ComM_MemMap.h
|
C
|
unknown
| 771
|
/*-------------------------------- 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 COMM_NM_H_
#define COMM_NM_H_
void ComM_Nm_NetworkStartIndication( NetworkHandleType Channel ); /**< @req COMM383 */
void ComM_Nm_NetworkMode( NetworkHandleType Channel ); /**< @req COMM390 */
void ComM_Nm_PrepareBusSleepMode( NetworkHandleType Channel ); /**< @req COMM391 */
void ComM_Nm_BusSleepMode( NetworkHandleType Channel ); /**< @req COMM392 */
void ComM_Nm_RestartIndication( NetworkHandleType Channel ); /**< @req COMM792 */
#endif /*COMM_NM_H_*/
|
2301_81045437/classic-platform
|
communication/ComM/inc/ComM_Nm.h
|
C
|
unknown
| 1,271
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
#ifndef COMM_TYPES_H
#define COMM_TYPES_H
#include "Rte_ComM_Type.h"
typedef enum {
COMM_NO_COM_NO_PENDING_REQUEST = 0,
COMM_NO_COM_REQUEST_PENDING,
COMM_FULL_COM_NETWORK_REQUESTED,
COMM_FULL_COM_READY_SLEEP,
COMM_SILENT_COM
} ComM_StateType;
/** Initialization status of ComM. */
typedef enum {
COMM_UNINIT,
COMM_INIT
} ComM_InitStatusType;
/** Enum literals for ComM_ModeType */
#ifndef COMM_NO_COMMUNICATION
#define COMM_NO_COMMUNICATION 0U
#endif /* COMM_NO_COMMUNICATION */
#ifndef COMM_SILENT_COMMUNICATION
#define COMM_SILENT_COMMUNICATION 1U
#endif /* COMM_SILENT_COMMUNICATION */
#ifndef COMM_FULL_COMMUNICATION
#define COMM_FULL_COMMUNICATION 2U
#endif /* COMM_FULL_COMMUNICATION */
#ifndef COMM_NOT_USED_USER_ID
#define COMM_NOT_USED_USER_ID 255U
#endif /* COMM_NOT_USED_USER_ID */
/** Inhibition status of ComM. Inhibition status is really a bit struct with bit 0 = inhibit to nocomm and bit 1 = wakeup inhibit */
#define COMM_INHIBITION_STATUS_NONE (0u)
/** Wake Up inhibition active */
#define COMM_INHIBITION_STATUS_WAKE_UP (1u)
/** Limit to �No Communication� mode active */
#define COMM_INHIBITION_STATUS_NO_COMMUNICATION (uint8)(1u << 1)
typedef enum{
PNC_NO_COMMUNICATION=0,
/* @req ComM907 */
PNC_REQUESTED,
PNC_READY_SLEEP,
PNC_PREPARE_SLEEP
}ComM_PncModeType;
typedef enum{
/* @req ComM924 */
PNC_NO_COMMUNICATION_STATE=0,
PNC_FULL_COMMUNICATION_STATE
}ComM_PncStateType;
typedef uint8 PNCHandleType;
#endif /*COMM_TYPES_H*/
|
2301_81045437/classic-platform
|
communication/ComM/inc/ComM_Types.h
|
C
|
unknown
| 2,353
|
/*-------------------------------- 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 -----------------------------*/
/* Globally fulfilled requirements */
/** @req COMM863 */
/** @req COMM051 */
/** @req COMM845 */
/** @req COMM846 */
/** @req COMM881 */
/** @req COMM880 */
/** @req COMM51.partially */
/** @req COMM191 */
/** @req COMM301 */
/** @req COMM488 */
/** @req COMM599.partially */
/** @req COMM459 */
/** @req COMM462 */
/** @req COMM549.bswbuilder */
/** @req COMM464 */
/** @req ComM910 *//* Pnc exists only if ComMPncSupport is enabled */
/** @req ComM909 *//* One Pnc SM per PNC supported*/
/** @req ComM920 *//* 48 PNC SM supported */
/** @req ComM994 *//* BusNm config does not restrict ComM user assignment to PNC */
/** @req ComM996 *//* Redundant configuration of a User mapping to PNC and Channel is not allowed */
/** @req ComM912 */ /* Configurable No. of ComMUsers can be mapped to one or more Pncs */
/* @req ComM981 */ /* IF ComMPncGatewayEnabled is True, COMM_GATEWAY_TYPE_ACTIVE can be a default setting. Both ERA and EIRA are present */
/* @req ComM919 */ /* More than one Com signal can be assigned to a PNC */
/* @req ComM964 *//* Active gateway handled according to SM */
#include <string.h>
#include "ComM.h" /** @req COMM463.partially */
#include "ComM_Dcm.h" /** @req COMM463.partially */
#if defined(USE_DEM)
#include "Dem.h"
#endif
#include "ComM_BusSM.h" /** @req COMM463.partially */
#include "ComM_Internal.h"
/** !req COMM506.partially *//* Com.h, SchM_ComM.h, NvM.h etc. are missing */
#if defined(USE_CANSM)
#include "CanSM.h"
#endif
#if defined(USE_LINSM)
#include "LinSM.h"
#endif
#if defined(USE_ETHSM)
#include "EthSM.h"
#endif
#if defined(USE_FRSM)
#include "FrSM.h"
#endif
#if defined(USE_NM)
#include "Nm.h"
#endif
#if defined(USE_BSWM)
#include "BswM_ComM.h"
#endif
#if defined(USE_DCM)
#include "Dcm_Cbk.h"
#endif
#include "SchM_ComM.h"
#define COMM_START_SEC_VAR_INIT_UNSPECIFIED
#include "ComM_BswMemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/
ComM_InternalType ComM_Internal = {
.InitStatus = COMM_UNINIT,
.InhibitCounter = 0,
#if (COMM_NO_COM == STD_ON)
.NoCommunication = TRUE,
#else
.NoCommunication = FALSE,
#endif
#if (COMM_PNC_SUPPORT == STD_ON)
.newEIRARxSignal = FALSE,
#endif
};
#define COMM_STOP_SEC_VAR_INIT_UNSPECIFIED
#include "ComM_BswMemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/
static const ComM_ConfigType * ComM_ConfigPtr;
#if (COMM_PNC_SUPPORT == STD_ON)
#define PNC_FIRST_CHNL_REF 0u
#define COMM_START_SEC_VAR_CLEARED_UNSPECIFIED
#include "ComM_BswMemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/
static boolean ComM_PncStateTrans_ThisCycle;
#define COMM_STOP_SEC_VAR_CLEARED_UNSPECIFIED
#include "ComM_BswMemMap.h" /*lint !e9019 OTHER [MISRA 2012 Rule 20.1, advisory] OTHER AUTOSAR specified way of using MemMap*/
#endif /* (COMM_PNC_SUPPORT == STD_ON) */
// ----------------------------------------------------------------------------
// Internal functions
// ----------------------------------------------------------------------------
#if (COMM_PNC_SUPPORT == STD_ON)
static void ComM_Internal_Monitor_RdySlpToPrpSlpTrns(void);
#if (COMM_PNC_GATEWAY_ENABLED == STD_ON)
static void ComM_Internal_Monitor_GwPassiveChnl(void);
static boolean externalPncRelease(uint8 pncCount,uint8 byteNo,uint8 bitNo);
static boolean externalPncRequest(uint8 pncCount,uint8 channelIndex);
#endif
#endif
static void resetInternalStateRequests (ComM_Internal_ChannelType* channelInternal);
static inline const ComM_ChannelType* getComMChannelConfig(boolean pncEnabled, uint8 iterator, const ComM_UserType* userConfig);
#if defined(USE_RTE)
static void ComM_Rte_ModeChangeIndication(NetworkHandleType Channel){
const ComM_UserType* userConfig;
ComM_Internal_ChannelType* channelInternal;
const ComM_ChannelType* comMchannelConf;
ComM_Internal_UserType* UserInternal;
ComM_ModeType commMode;
ComM_ModeType commLeastMode;
boolean commChnlStatus;
uint8 userIdx;
uint8 chnlIdx;
uint8 loopCount;
boolean pncEnableSts;
const ComM_ChannelType* channelConf;
channelConf = &ComM_ConfigPtr->Channels[Channel];
/* @req ComM091 */
for(userIdx=0; userIdx < COMM_USER_COUNT; userIdx++){
commLeastMode = COMM_FULL_COMMUNICATION;
commMode = COMM_NOT_USED_USER_ID;
commChnlStatus = FALSE;
UserInternal = &ComM_Internal.Users[userIdx];
userConfig = &ComM_ConfigPtr->Users[userIdx];
loopCount = userConfig->ChannelCount;
#if (COMM_PNC_SUPPORT == STD_ON)
/* Check if PNC is enabled and user references any PNC */
pncEnableSts = ((TRUE == ComM_ConfigPtr->ComMPncConfig->ComMPncEnabled) && (userConfig->PncChnlCount !=0));
if (TRUE == pncEnableSts){
loopCount += userConfig->PncChnlCount; /* PNCs mapped to users and channels */
}
#else
pncEnableSts = FALSE;
#endif
for(chnlIdx=0; chnlIdx < loopCount; chnlIdx++){
comMchannelConf = getComMChannelConfig(pncEnableSts,chnlIdx,userConfig);
channelInternal = &ComM_Internal.Channels[comMchannelConf->ComMChannelId];
if(comMchannelConf->ComMChannelId == channelConf->ComMChannelId){
commChnlStatus = TRUE;
}
commMode = channelInternal->Mode;
/* @req ComM663 */
if(commMode <= commLeastMode){
commLeastMode = commMode;
}
}
if((UserInternal->CurrentMode != commLeastMode)&&(commChnlStatus == TRUE)){
/*Rte mode change indication is not supported in post build*/
if(ComM_ConfigPtr->Users[userIdx].ComMRteSwitchUM != NULL_PTR){
/* @req ComM778 */
(void)ComM_ConfigPtr->Users[userIdx].ComMRteSwitchUM(/*IN*/commLeastMode);
}
UserInternal->CurrentMode = commLeastMode;
}
}
/*lint -e{954} CONFIGURATION*/
}
#endif
/**
* @brief Check FullCom Min duration
* @param ChannelConf
* @param ChannelInternal
* @return
*/
static inline boolean ComM_Internal_FullComMinTime_AllowsExit(const ComM_ChannelType* ChannelConf, const ComM_Internal_ChannelType* ChannelInternal) {
boolean rv;
if ((ChannelConf->NmVariant == COMM_NM_VARIANT_LIGHT) ||
(ChannelConf->NmVariant == COMM_NM_VARIANT_NONE)){
rv = (ChannelInternal->FullComMinDurationTimeLeft == 0);
} else {
rv = TRUE;
}
return rv;
}
/** @req COMM073 @req COMM071
* @req COMM069 @req COMM402 */
/**
* @brief Propagates channel mode to BusSM
* @param ChannelConf
* @param ComMode
* @return
*/
static Std_ReturnType ComM_Internal_PropagateComMode( const ComM_ChannelType* ChannelConf, ComM_ModeType ComMode ){
Std_ReturnType busSMStatus = E_OK;
boolean flexrayReqNoCom;
flexrayReqNoCom = FALSE;
switch (ChannelConf->BusType) {
#if defined(USE_CANSM)
case COMM_BUS_TYPE_CAN:
busSMStatus = CanSM_RequestComMode(ChannelConf->ComMChannelId, ComMode); /** @req COMM854 */
break;
#endif
#if defined(USE_LINSM)
case COMM_BUS_TYPE_LIN:
busSMStatus = LinSM_RequestComMode(ChannelConf->ComMChannelId, ComMode); /** @req COMM856 */
break;
#endif
#if defined(USE_ETHSM)
case COMM_BUS_TYPE_ETH:
busSMStatus = EthSM_RequestComMode(ChannelConf->ComMChannelId, ComMode); /** @req COMM859 */
break;
#endif
#if defined (USE_FRSM)
case COMM_BUS_TYPE_FR:
busSMStatus = FrSM_RequestComMode(ChannelConf->ComMChannelId, ComMode); /** @req ComM852 */
flexrayReqNoCom = (ComMode == COMM_NO_COMMUNICATION);
break;
#endif
default:
busSMStatus = E_NOT_OK;
break;
}
/*lint -e774 FALSE_POSITIVE flexrayReqNoCom is not evaluated for other bus types */
if ((E_OK == busSMStatus) && (flexrayReqNoCom == FALSE))
{
/* FrSM is in current mode COMM_FULL_COMMUNICATION and when COMM_NO_COMMUNICATION is requested. ComM_BusSM_ModeIndication() is called from FrSM_RequestComMode() context
* and we need not set requestPending flag in this case*/
ComM_Internal.Channels[ChannelConf->ComMChannelId].requestPending = TRUE;
}
return busSMStatus;
}
/** @req COMM602 @req COMM261 */
/**
* @brief Requests/releases Nm network according to channel mode
* @param ChannelConf
* @param busOffRecovery
* @return
*/
static Std_ReturnType ComM_Internal_NotifyNm( const ComM_ChannelType* ChannelConf, boolean busOffRecovery){
ComM_Internal_ChannelType* ChannelInternal = &ComM_Internal.Channels[ChannelConf->ComMChannelId];
Std_ReturnType status = E_OK;
if ((ChannelConf->NmVariant == COMM_NM_VARIANT_FULL) || (ChannelConf->NmVariant == COMM_NM_VARIANT_PASSIVE))
{
#if defined(USE_NM)
if (ChannelInternal->Mode == COMM_FULL_COMMUNICATION)
{
if (ChannelInternal->SubMode == COMM_FULL_COM_NETWORK_REQUESTED)
{
/* 1. Check if the network is requested because of user or diagnostic module */
if ((ChannelInternal->UserRequestMask != 0) || (ChannelInternal->DCM_Requested == TRUE)) {
if ((ChannelConf->NmVariant == COMM_NM_VARIANT_FULL)) {
status = Nm_NetworkRequest(ChannelConf->NmChannelHandle); /** @req COMM869 */ /** @req COMM870 *//** @req COMM667 */
/* Clear any pending EcuM wake up indication or network start/restart indication */
ChannelInternal->EcuMWkUpIndication = FALSE;
ChannelInternal->nwStartIndication = FALSE;
} else if (ChannelConf->NmVariant == COMM_NM_VARIANT_PASSIVE) {
status = Nm_PassiveStartUp(ChannelConf->NmChannelHandle); /* Seq diagram 9.1*/
/* Clear EcuM wake up indication or network start/restart indication */
ChannelInternal->EcuMWkUpIndication = FALSE;
ChannelInternal->nwStartIndication = FALSE;
} else {
/* Do nothing */
}
}
/* 2. Check if it is due to wake up or restart indication */
else if ((TRUE == ChannelInternal->EcuMWkUpIndication) || (TRUE == ChannelInternal->nwStartIndication)) {
// In case of passive wake up or network start/restart indication
status = Nm_PassiveStartUp(ChannelConf->NmChannelHandle); /* @req COMM665 ComM902 ComM903 */
/* Clear EcuM wake up indication or network start/restart indication */
ChannelInternal->EcuMWkUpIndication = FALSE;
ChannelInternal->nwStartIndication = FALSE;
}
#if ((COMM_PNC_SUPPORT == STD_ON) && (COMM_PNC_GATEWAY_ENABLED == STD_ON))
/* 3. If PNC is enabled & gateway is supported consider this
* as case where PNC is requested externally (i.e due to PNC bit set to 1 in corresponding channel's ERA) */
else if ((TRUE == ComM_ConfigPtr->ComMPncConfig->ComMPncEnabled)
&& (ChannelConf->NmVariant == COMM_NM_VARIANT_FULL)){/** @req COMM667 */
status = Nm_NetworkRequest(ChannelConf->NmChannelHandle);
}else if ((TRUE == ComM_ConfigPtr->ComMPncConfig->ComMPncEnabled)
&& (ChannelConf->NmVariant == COMM_NM_VARIANT_PASSIVE)) {
status = Nm_PassiveStartUp(ChannelConf->NmChannelHandle); /* Seq diagram 9.1*/
}
#endif
else if (busOffRecovery == TRUE){
/* The execution can end up here in this scenario of CAN bus off recovery:
* ComM channel initially in COMM_FULL_COMMUNICATION mode and COMM_FULL_COM_READY_SLEEP sub mode (implies UserRequestMask = 0).
* CanSM detects bus off and indicates COMM_SILENT_COMMUNICATION.Recovers after some time and indicates COMM_FULL_COMMUNICATION.
* Now we request a passive startup and after Nm reports ComM_Nm_NetworkMode(), ComM reaches COMM_FULL_COMMUNICATION mode and COMM_FULL_COM_READY_SLEEP sub mode
* which was the initial state before bus off.
*/
status = Nm_PassiveStartUp(ChannelConf->NmChannelHandle);
} else {
/* Do nothing */
}
}
else if ((ChannelConf->NmVariant == COMM_NM_VARIANT_FULL) && (ChannelInternal->SubMode == COMM_FULL_COM_READY_SLEEP))
{
status = Nm_NetworkRelease(ChannelConf->NmChannelHandle); /**< @req COMM133 */
}else{
/* Do nothing */
}
}
#else
status = E_NOT_OK;
#endif
}
if ((ChannelConf->NmVariant == COMM_NM_VARIANT_NONE) || (ChannelConf->NmVariant == COMM_NM_VARIANT_LIGHT))
{
if (ChannelInternal->Mode == COMM_FULL_COMMUNICATION)
{
if (ChannelInternal->SubMode == COMM_FULL_COM_NETWORK_REQUESTED)
{
/* start timer */ /* cancelling timer by restarting it */
ChannelInternal->FullComMinDurationTimeLeft = COMM_T_MIN_FULL_COM_MODE_DURATION; /** @req COMM886 */ /** @req COMM887 */
ChannelInternal->fullComMinDurationTimerStopped = FALSE;
}
else if (ChannelInternal->SubMode == COMM_FULL_COM_READY_SLEEP)
{
ChannelInternal->LightTimeoutTimeLeft = ChannelConf->LightTimeout; /** @req COMM891 */
ChannelInternal->nmLightTimeoutTimerStopped = FALSE;
}else{
/* Do nothing */
}
}
}
return status;
}
/**
* @brief Enter No Com
* @param ChannelConf
* @param ChannelInternal
* @return
*/
static inline Std_ReturnType ComM_Internal_Enter_NoCom(const ComM_ChannelType* ChannelConf,
ComM_Internal_ChannelType* ChannelInternal, boolean isRequest) {
Std_ReturnType status;
status = ComM_Internal_PropagateComMode(ChannelConf, COMM_NO_COMMUNICATION);
if( E_OK == status ) {
ChannelInternal->lastRequestedMode = COMM_NO_COMMUNICATION;
/* New mode is successfully requested - reset the flags */
if (isRequest == TRUE) {
ChannelInternal->userOrPncReqPending = FALSE;
} else {
resetInternalStateRequests(ChannelInternal);
}
}
return status;
}
/**
* @brief Enter Silent Com
* @param ChannelConf
* @param ChannelInternal
* @return
*/
static inline Std_ReturnType ComM_Internal_Enter_SilentCom(const ComM_ChannelType* ChannelConf,
ComM_Internal_ChannelType* ChannelInternal, boolean isRequest) {
Std_ReturnType status ;
status = ComM_Internal_PropagateComMode(ChannelConf, COMM_SILENT_COMMUNICATION);
if( E_OK == status ) {
ChannelInternal->lastRequestedMode = COMM_SILENT_COMMUNICATION;
/* New mode is successfully requested - reset the flags */
if (isRequest == TRUE) {
ChannelInternal->userOrPncReqPending = FALSE;
} else {
resetInternalStateRequests(ChannelInternal);
}
}
return status;
}
/**
* @brief Enter Network requested phase
* @param ChannelConf
* @param ChannelInternal
* @return
*/
static inline Std_ReturnType ComM_Internal_Enter_NetworkRequested(const ComM_ChannelType* ChannelConf,
ComM_Internal_ChannelType* ChannelInternal, boolean isRequest) {
Std_ReturnType status = E_OK;
Std_ReturnType retType = E_OK;
if (ChannelInternal->SubMode == COMM_NO_COM_NO_PENDING_REQUEST)
{
ChannelInternal->SubMode = COMM_NO_COM_REQUEST_PENDING; /** @req COMM875 */ /* @req ComM893 */ /** @req COMM894 */ /** @req COMM876 */
}
/*The state is changed from COMM_FULL_COM_READY_SLEEP to COMM_FULL_COM_NETWORK_REQUESTED directly here.
* The reason is ComM_BusSM_Indication() may/will not be called by lower SM module (ex. CanSM) if it is already in COMM_FULL_COMMUNICATION.
* In other words ComM_Internal_PropagateComMode() will not have any affect in CanSM module (if it is already in COMM_FULL_COMMUNICATION)
* and ComM_BusSM_Indication() will never be called because no mode transitions occur in CanSM module.
* Otherwise usually all mode and state changes in ComM take place in ComM_BusSM_Indication()*/
if (COMM_FULL_COM_READY_SLEEP == ChannelInternal->SubMode){
ChannelInternal->SubMode = COMM_FULL_COM_NETWORK_REQUESTED;
retType=ComM_Internal_NotifyNm(ChannelConf,FALSE);
}
if (ChannelInternal->CommunicationAllowed == TRUE)
{
/* @req COMM895 */
/* !req COMM896 *//* Or do we only end up here in COMM_NO_COM_REQUEST_PENDING. */
status = ComM_Internal_PropagateComMode(ChannelConf, COMM_FULL_COMMUNICATION);
if(status == E_OK) {
ChannelInternal->lastRequestedMode = COMM_FULL_COMMUNICATION;
/* New mode is successfully requested - reset the flags */
if (isRequest == TRUE) {
ChannelInternal->userOrPncReqPending = FALSE;
} else {
resetInternalStateRequests(ChannelInternal);
if ((ChannelInternal->EcuMWkUpIndication == FALSE) &&(ChannelInternal->DCM_Requested == FALSE)) {
//If this is an internal request due to ComM_Nm_RestartIndication()/ComM_Nm_NetworkStartIndication()
ChannelInternal->nwStartIndication = TRUE;
}
}
}
}
return (status & retType);
}
/**
* @brief Enter ready sleep phase
* @param ChannelConf
* @param ChannelInternal
* @return
*/
static inline Std_ReturnType ComM_Internal_Enter_ReadySleep(const ComM_ChannelType* ChannelConf,
ComM_Internal_ChannelType* ChannelInternal, boolean isRequest) {
Std_ReturnType status;
ChannelInternal->Mode = COMM_FULL_COMMUNICATION;
ChannelInternal->lastRequestedMode = COMM_FULL_COMMUNICATION;
ChannelInternal->SubMode = COMM_FULL_COM_READY_SLEEP;
status = ComM_Internal_NotifyNm(ChannelConf,FALSE);
if (status == E_OK) {
/* New mode is successfully requested - reset the flags */
if (isRequest == TRUE) {
ChannelInternal->userOrPncReqPending = FALSE;
} else {
resetInternalStateRequests(ChannelInternal);
}
}
return status;
}
/**
* @brief Transition from No Com
* @param ChannelConf
* @param ChannelInternal
* @param isRequest
* @return
*/
static inline Std_ReturnType ComM_Internal_UpdateFromNoCom(const ComM_ChannelType* ChannelConf,
ComM_Internal_ChannelType* ChannelInternal, boolean isRequest) {
Std_ReturnType status;
boolean limitToNoCom;
boolean inhibitWakeUp;
status = E_OK;
limitToNoCom = ((ComM_Internal.NoCommunication == TRUE) ||
((ChannelInternal->InhibitionStatus & COMM_INHIBITION_STATUS_NO_COMMUNICATION) == COMM_INHIBITION_STATUS_NO_COMMUNICATION));
inhibitWakeUp = ((ChannelInternal->InhibitionStatus & COMM_INHIBITION_STATUS_WAKE_UP) == COMM_INHIBITION_STATUS_WAKE_UP);
if ((ChannelInternal->NmIndicationMask & COMM_NM_INDICATION_BUS_SLEEP) == COMM_NM_INDICATION_BUS_SLEEP) {
/* This is a quite unusual case */
/* Bus sleep is a possible case when lower FrNm and ComM are not in sync. When all other nodes on flexray network cease to exist, POC state
* can be changed to Halt or Freeze (depending on other factors) which results in FrSM indicating ComM COMM_NO_COMMUNICATION. After some time out delay in
* FrNm will result in reporting ComM_Nm_BusSleepMode(). This condition will clear such requests. */
resetInternalStateRequests(ChannelInternal);
}
/* @req ComM066 */ /* The first check is related to passive wake up - EcuM wake up indication */
else if (TRUE == ChannelInternal->EcuMWkUpIndication) {
/* EcuM wake up indication */
status = ComM_Internal_Enter_NetworkRequested(ChannelConf, ChannelInternal, isRequest);
} /* Check if there is any mode inhibitions */
else if (((limitToNoCom == TRUE) || (inhibitWakeUp == TRUE)) && (ChannelInternal->DCM_Requested == FALSE)) {
/** @req COMM182 */
status = E_OK; /* No Full Com mode requests */
}
else if ((ChannelInternal->NmIndicationMask & COMM_NM_INDICATION_RESTART) == COMM_NM_INDICATION_RESTART ) {
/* restart indication */
status = ComM_Internal_Enter_NetworkRequested(ChannelConf, ChannelInternal, isRequest); /**< @req COMM583 */
}
else {
if ((ChannelInternal->UserRequestMask != 0) || (ChannelInternal->userOrPncReqMode == COMM_FULL_COMMUNICATION)
|| (ChannelInternal->DCM_Requested == TRUE)) {
// Channel is requested either by user or PNC gateway or diagnostic module
status = ComM_Internal_Enter_NetworkRequested(ChannelConf, ChannelInternal, isRequest);
} else {
// Channel is not requested
/* It is better to request COMM_NO_COMMUNICATION even though current ComM mode is COMM_NO_COMMUNICATION.
* Consider case where bus is flexray.
* 1. User requests COMM_FULL_COMMUNICATION, FrSM accepts the request and indicates ComM_BusSM_ModeIndication (COMM_FULL_COMMUNICATION) after some time
* 2. Flexray network is down after some time, FrSM detects POC state either as halt or freeze and indicates ComM_BusSM_ModeIndication (COMM_NO_COMMUNICATION). ComM switches to COMM_NO_COMMUNICATION.
* 3. FrSM remembers that previous requested mode was COMM_FULL_COMMUNICATION and keeps trying to restart Flexray controller and transceivers to enter operational mode.
* 4. User requests for COMM_NO_COMMUNICATION. Now ComM has to request FrSM to stop all its attempt (to turn on controllers and transceivers) and switch off completely. This requires ComM_Internal_Enter_NoCom().
*/
status = ComM_Internal_Enter_NoCom(ChannelConf, ChannelInternal,isRequest);
ChannelInternal->SubMode = COMM_NO_COM_NO_PENDING_REQUEST; /** @req COMM897 */
ChannelInternal->requestPending = FALSE; /* Reset any pending request to <bus>SM module and we will not expect an further ComM_BusSM_ModeIndication() */
}
}
return status;
}
/**
* @brief Transition from Silent Com
* @param ChannelConf
* @param ChannelInternal
* @param isRequest
* @return
*/
static inline Std_ReturnType ComM_Internal_UpdateFromSilentCom(const ComM_ChannelType* ChannelConf,
ComM_Internal_ChannelType* ChannelInternal, boolean isRequest) {
Std_ReturnType status;
boolean limitToNoCom;
boolean inhibitWakeUp;
limitToNoCom = ((ComM_Internal.NoCommunication == TRUE) ||
((ChannelInternal->InhibitionStatus & COMM_INHIBITION_STATUS_NO_COMMUNICATION) == COMM_INHIBITION_STATUS_NO_COMMUNICATION));
inhibitWakeUp = ((ChannelInternal->InhibitionStatus & COMM_INHIBITION_STATUS_WAKE_UP) == COMM_INHIBITION_STATUS_WAKE_UP);
if ((ChannelInternal->NmIndicationMask & COMM_NM_INDICATION_BUS_SLEEP)==COMM_NM_INDICATION_BUS_SLEEP) {
// "bus sleep" indication
status = ComM_Internal_Enter_NoCom(ChannelConf, ChannelInternal,isRequest); /**< @req COMM295 */
} else if (((limitToNoCom == TRUE) || (inhibitWakeUp == TRUE)) && (ChannelInternal->DCM_Requested == FALSE)) { /** @req COMM182 */
/* Check if there is any mode inhibitions - This must be the check before checking if channel is requested */
status = E_OK;
} else if ((ChannelInternal->NmIndicationMask & COMM_NM_INDICATION_NETWORK_MODE)==COMM_NM_INDICATION_NETWORK_MODE) {
// "network mode" indication (<bus>Nm has transitioned from prepare bus sleep
/* If the current mode is COMM_SILENT_COMMUNICATION then <bus>Nm module should be in prepare bus sleep state.
* ComM_Nm_NetworkMode(ChX) trigger implies <bus>Nm module changes to repeat message state because of a
* received Nm PDU and in ComM we are required to change the current mode to full communication.
* There is no necessity to request COMM_FULL_COMMUNICATION on this channel again
* because <bus>Nm module is capable of reception in repeat message state.
*/
status = ComM_Internal_Enter_ReadySleep(ChannelConf, ChannelInternal,isRequest); /**< @req COMM296 */
}else {
/** @req COMM686 (ChannelInternal->UserRequestMask != 0) */
if ((ChannelInternal->UserRequestMask != 0) || (ChannelInternal->userOrPncReqMode == COMM_FULL_COMMUNICATION)
|| (ChannelInternal->DCM_Requested == TRUE)) { /** @req COMM878 *//** @req COMM877 */
// Channel is requested either by user or PNC gateway or diagnostic module
status = ComM_Internal_Enter_NetworkRequested(ChannelConf, ChannelInternal,isRequest);
} else {
// Stay in SILENT
status = E_OK;
}
}
return status;
/* Note: "restart" indication usually cannot occur when ComM is in silent communication. This is because to
* get a trigger ComM_Nm_NetworkStartIndication() <bus>Nm module should be in bus sleep state and receives a Nm PDU.
* This implies ComM will be in COMM_NO_COMMUNICATION (corresponding to bus sleep state in <bus>Nm) and not in COMM_SILENT_COMMUNICATION.
* There can be one exception to the above argument i.e when ComM is in a transition from COMM_SILENT_COMMUNICATION to COMM_NO_COMMUNICATION
* and <bus>SM has not indicated a COMM_NO_COMMUNICATION and restart indicated from Nm module. This is resolved by ComM first switching
* to desired mode COMM_NO_COMMUNICATION and then recognizing COMM_NM_INDICATION_RESTART flag. In subsequent ComM_MainFunction will
* trigger request COMM_FULL_COMMUNICATION mode. The above discussion applies to passive wake up also.
*/
}
/**
* @brief Transition from Full Com
* @param ChannelConf
* @param ChannelInternal
* @param isRequest
* @return
*/
static inline Std_ReturnType ComM_Internal_UpdateFromFullCom(const ComM_ChannelType* ChannelConf,
ComM_Internal_ChannelType* ChannelInternal, boolean isRequest) {
Std_ReturnType status = E_OK;
boolean limitToNoCom;
/* @req ComM219 */
/* If the current mode is FULL_COMM and wake up inhibition is requested then there is no action (inhibition does not become active) */
if ((ChannelInternal->NmIndicationMask & COMM_NM_INDICATION_BUS_SLEEP)==COMM_NM_INDICATION_BUS_SLEEP) {
// "bus sleep" indication
status = ComM_Internal_Enter_NoCom(ChannelConf, ChannelInternal,isRequest); /**< @req COMM637 */
} else if (((ChannelInternal->NmIndicationMask & COMM_NM_INDICATION_PREPARE_BUS_SLEEP)==COMM_NM_INDICATION_PREPARE_BUS_SLEEP) &&
(((ChannelInternal->SubMode == COMM_FULL_COM_NETWORK_REQUESTED) && (ChannelConf->NmVariant == COMM_NM_VARIANT_PASSIVE)) || (ChannelInternal->SubMode == COMM_FULL_COM_READY_SLEEP))) {
// "prepare bus sleep" indication
status = ComM_Internal_Enter_SilentCom(ChannelConf, ChannelInternal,isRequest); /**< @req COMM299.partially */ /** @req COMM900 */
} else {
limitToNoCom = ((ComM_Internal.NoCommunication == TRUE) ||
((ChannelInternal->InhibitionStatus & COMM_INHIBITION_STATUS_NO_COMMUNICATION) == COMM_INHIBITION_STATUS_NO_COMMUNICATION));
if ((limitToNoCom== TRUE) && (ChannelInternal->DCM_Requested == FALSE)) { /** @req COMM182 *//** @req COMM841 @req ComM215 */
// Inhibition is active
if (TRUE == ComM_Internal_FullComMinTime_AllowsExit(ChannelConf, ChannelInternal)) {
if (ChannelInternal->SubMode == COMM_FULL_COM_READY_SLEEP) {
if ((ChannelConf->NmVariant == COMM_NM_VARIANT_LIGHT) &&
(ChannelInternal->LightTimeoutTimeLeft == 0)) {
status = ComM_Internal_Enter_NoCom(ChannelConf, ChannelInternal,isRequest); /**< @req COMM610 */
}
} else {
/** @req COMM303 *//* Trigger state changes to Ready sleep if current state is COMM_FULL_COMMUNICATION - Limit to NoCom action */
status = ComM_Internal_Enter_ReadySleep(ChannelConf, ChannelInternal,isRequest);
}
}
} else {
if ((ChannelInternal->UserRequestMask == 0) && (ChannelInternal->DCM_Requested == FALSE)
&& ((ChannelInternal->userOrPncReqMode == COMM_NO_COMMUNICATION))) {
// Channel no longer requested
if (TRUE == ComM_Internal_FullComMinTime_AllowsExit(ChannelConf, ChannelInternal)) {
if (ChannelInternal->SubMode == COMM_FULL_COM_READY_SLEEP) {
if ((ChannelConf->NmVariant == COMM_NM_VARIANT_LIGHT) &&
(ChannelInternal->LightTimeoutTimeLeft == 0)) {
status = ComM_Internal_Enter_NoCom(ChannelConf, ChannelInternal,isRequest); /**< @req COMM610 */
}
} else {
/* When current mode is COMM_FULL_COMMUNICATION and sub mode is COMM_FULL_COM_NETWORK_REQUESTED, We can end up here in the following possible cases:
* 1. The User or PNC requests are released. So the journey starts towards COMM_NO_COMMUNICATION
* 2. ComM_Nm_NetworkMode(ChX) is indicated by Nm for transition from NM_MODE_BUS_SLEEP to NM_STATE_REPEAT_MESSAGE and this transition
* was due to passive wake up or network start/restart indication. Since there is no active User or PNC request for COMM_FULL_COM_NETWORK_REQUESTED
* ComM switches to COMM_FULL_COM_READY_SLEEP sub mode.
*/
status = ComM_Internal_Enter_ReadySleep(ChannelConf, ChannelInternal,isRequest); /** @req COMM889 */ /** @req COMM888 */ /** @req COMM890 */
}
}
} else {
/** @req COMM686 (ChannelInternal->UserRequestMask != 0) */
if (ChannelInternal->SubMode != COMM_FULL_COM_NETWORK_REQUESTED) {
//Expected to be in COMM_FULL_COM_NETWORK_REQUESTED
status = ComM_Internal_Enter_NetworkRequested(ChannelConf, ChannelInternal,isRequest); /** @req COMM882 */ /* @req COMM883 */
} else if (((ChannelInternal->NmIndicationMask & COMM_NM_INDICATION_NETWORK_MODE)==COMM_NM_INDICATION_NETWORK_MODE)) {
//Nm reports ComM_Nm_NetworkMode()
ChannelInternal->NmIndicationMask &= ~(COMM_NM_INDICATION_NETWORK_MODE); //Reset
ChannelInternal->internalRequest = FALSE;
} else {
ChannelInternal->internalRequest = FALSE; //Reset any internal requests for FullCom Minimum duration in case of Nm variant - None
}
}
}
}
return status;
/* restart indication, EcuM wake up indication cannot occur while in FULL communication (No passive wake up possible) */
}
/**
* @brief Processes all requests stored for a channel. and makes state machine transitions accordingly
* @param ChannelConf
* @param isRequest
* @return
*/
static Std_ReturnType ComM_Internal_UpdateChannelState( const ComM_ChannelType* ChannelConf, boolean isRequest ) {
ComM_Internal_ChannelType* ChannelInternal = &ComM_Internal.Channels[ChannelConf->ComMChannelId];
Std_ReturnType status = E_OK;
switch (ChannelInternal->Mode) {
case COMM_NO_COMMUNICATION:
status = ComM_Internal_UpdateFromNoCom(ChannelConf, ChannelInternal, isRequest);
break;
case COMM_SILENT_COMMUNICATION:
status = ComM_Internal_UpdateFromSilentCom(ChannelConf, ChannelInternal, isRequest);
break;
case COMM_FULL_COMMUNICATION:
status = ComM_Internal_UpdateFromFullCom(ChannelConf, ChannelInternal, isRequest);
break;
default:
status = E_NOT_OK;
break;
}
return status;
}
/**
* @brief Tick 'Min full com duration' timeout, and update state if needed
* @param ChannelConf
* @param ChannelInternal
*/
static inline void ComM_Internal_TickFullComMinTime(const ComM_ChannelType* ChannelConf, ComM_Internal_ChannelType* ChannelInternal) {
if ((ChannelInternal->Mode == COMM_FULL_COMMUNICATION) && (ChannelInternal->fullComMinDurationTimerStopped == FALSE)){
if (ChannelConf->MainFunctionPeriod >= ChannelInternal->FullComMinDurationTimeLeft){
ChannelInternal->FullComMinDurationTimeLeft = 0;
ChannelInternal->fullComMinDurationTimerStopped = TRUE;
ChannelInternal->internalRequest = TRUE;
} else {
ChannelInternal->FullComMinDurationTimeLeft -= ChannelConf->MainFunctionPeriod;
}
}
}
/**
* @brief Tick 'Light nm' timeout, and update state if needed
* @param ChannelConf
* @param ChannelInternal
*/
static inline void ComM_Internal_TickLightTime(const ComM_ChannelType* ChannelConf, ComM_Internal_ChannelType* ChannelInternal) {
if ((ChannelInternal->Mode == COMM_FULL_COMMUNICATION) &&
(ChannelInternal->SubMode == COMM_FULL_COM_READY_SLEEP)&& (ChannelInternal->nmLightTimeoutTimerStopped == FALSE)) {
if (ChannelConf->MainFunctionPeriod >= ChannelInternal->LightTimeoutTimeLeft){
ChannelInternal->LightTimeoutTimeLeft = 0;
ChannelInternal->nmLightTimeoutTimerStopped = TRUE;
ChannelInternal->internalRequest = TRUE;
} else {
ChannelInternal->LightTimeoutTimeLeft -= ChannelConf->MainFunctionPeriod;
}
}
}
/**
* @brief Propagate query to channel Bus SMs. Collect overall mode and status
* @param User
* @param ComMode
* @return
*/
static Std_ReturnType ComM_Internal_GetCurrentComMode( const ComM_ChannelType* Channel, ComM_ModeType* mode ){
Std_ReturnType status;
switch (Channel->BusType) {
#if defined(USE_CANSM)
case COMM_BUS_TYPE_CAN:
status = CanSM_GetCurrentComMode(Channel->ComMChannelId, mode); /** @req COMM855 */
break;
#endif
#if defined(USE_LINSM)
case COMM_BUS_TYPE_LIN:
status = LinSM_GetCurrentComMode(Channel->ComMChannelId, mode); /** @req COMM857 */
break;
#endif
#if defined(USE_ETHSM)
case COMM_BUS_TYPE_ETH:
status = EthSM_GetCurrentComMode(Channel->ComMChannelId, mode); /** @req COMM860 */
break;
#endif
#if defined (USE_FRSM)
case COMM_BUS_TYPE_FR:
status = FrSM_GetCurrentComMode(Channel->ComMChannelId, mode); /** @req ComM853 */
break;
#endif
default:
status = E_NOT_OK;
break;
}
return status;
}
/**
* @brief Propagate query to channel Bus SMs. Collect overall mode and status
* @param User
* @param ComMode
* @return
*/
static Std_ReturnType ComM_Internal_PropagateGetCurrentComMode( ComM_UserHandleType User, ComM_ModeType* ComMode ){
const ComM_UserType* UserConfig;
const ComM_ChannelType* Channel;
ComM_ModeType requestMode;
Std_ReturnType totalStatus;
uint8 loopCount;
boolean pncEnableSts;
UserConfig = &ComM_ConfigPtr->Users[User];
requestMode = COMM_FULL_COMMUNICATION;
totalStatus = E_OK;
loopCount = UserConfig->ChannelCount;
pncEnableSts = FALSE;
#if (COMM_PNC_SUPPORT == STD_ON)
/* Check if PNC is enabled and user references any PNC */
/*lint -e{838} OTHER Previous value is not used as it serves as initialization when PNC support is OFF */
pncEnableSts = ((TRUE == ComM_ConfigPtr->ComMPncConfig->ComMPncEnabled) && (UserConfig->PncChnlCount !=0));
if (TRUE == pncEnableSts){
loopCount += UserConfig->PncChnlCount; /* PNCs mapped to users and channels */
}
#endif
/* Go through users channels. Relay to SMs. Collect overall mode and success status */
for (uint8 i = 0; i < loopCount; ++i) {
Channel = getComMChannelConfig(pncEnableSts,i,UserConfig);
Std_ReturnType status;
ComM_ModeType mode = COMM_FULL_COMMUNICATION;
status = ComM_Internal_GetCurrentComMode(Channel, &mode);
if (status == E_OK) {
if (mode < requestMode) { /** @req COMM176 */
requestMode = mode;
}
} else {
totalStatus = status;
}
}
*ComMode = requestMode;
return totalStatus;
}
static inline const ComM_ChannelType* getComMChannelConfig(boolean pncEnabled, uint8 iterator, const ComM_UserType* userConfig) {
const ComM_ChannelType* ch;
#if (COMM_PNC_SUPPORT == STD_ON)
if((TRUE == pncEnabled) && (iterator >= userConfig->ChannelCount)) {
/* Get channel configuration for a channel mapped to user indirectly via PNC */
ch = userConfig->PncChnlList[iterator-userConfig->ChannelCount];
} else {
ch = userConfig->ChannelList[iterator]; /* Get channel configuration */ /** @req COMM798 */
}
#else
ch = userConfig->ChannelList[iterator]; /* Get channel configuration */ /** @req COMM798 */
(void)pncEnabled;
#endif
return ch;
}
static inline Std_ReturnType checkForModeInhibitions(const ComM_Internal_ChannelType* chnlIntrnal,ComM_ModeType comMode) {
Std_ReturnType ret;
ret = E_OK;
/* @req ComM182 */ /* No mode inhibition during active diagnostic session */
if ((chnlIntrnal->DCM_Requested == FALSE)){
/* @req ComM303 */ /* Inhibition due to limit to No communication */
if ((ComM_Internal.NoCommunication == TRUE)||
((chnlIntrnal->InhibitionStatus & COMM_INHIBITION_STATUS_NO_COMMUNICATION) == COMM_INHIBITION_STATUS_NO_COMMUNICATION)) {
/* @req ComM842 */ /* Current sub mode is not COMM_FULL_COM_NETWORK_REQUESTED (i.e Mode is either NO_COM, SILENT_COM OR FULL_COM (Ready sleep) */
if ((chnlIntrnal->SubMode != COMM_FULL_COM_NETWORK_REQUESTED) && (comMode == COMM_FULL_COMMUNICATION)) {
ret = COMM_E_MODE_LIMITATION;
}
}
/* @req ComM302 */ /* Bus wake up inhibition */
else if ((chnlIntrnal->InhibitionStatus & COMM_INHIBITION_STATUS_WAKE_UP) == COMM_INHIBITION_STATUS_WAKE_UP) {
/* @req ComM218 ComM219 */ /* If the current mode is not COMM_FULL_COMMUNICATION then inhibit */
if ((chnlIntrnal->Mode != COMM_FULL_COMMUNICATION) && (comMode == COMM_FULL_COMMUNICATION)) {
ret = COMM_E_MODE_LIMITATION;
}
} else {
/* Do nothing */
}
}
return ret;
}
static inline void saveRequestedMode(boolean pncEnabled, ComM_Internal_ChannelType* chnlIntrnal,const ComM_ChannelType* chnlConfig,ComM_ModeType comMode) {
/*lint -save -e715 OTHER */ /* pncEnabled & chnlConfig will not be used in case of (COMM_PNC_SUPPORT == STD_OFF) */
#if (COMM_PNC_SUPPORT == STD_ON)
NetworkHandleType chnlId;
chnlId = chnlConfig->ComMChannelId;
/* Check if partial networking is disabled or the channel is not associated with any PNC */
/* Check if this ComMChannels is related to any PNC
* Shortcut would be to see if there exists a ComM_TxComSignals[] at an index of this ComMChannelId
* Note: configuration ComM_TxComSignals[] is generated in the same order as ComM_Channels[]
*/
/* In case of PNC enabled and channel associated with a PNC the state will be handled by ComM_Internal_HandlePncStateChange() or PNC gateway handling */
if ((pncEnabled == FALSE) ||
(ComM_ConfigPtr->ComMPncConfig->ComMPncTxComSigIdRef[chnlId].ComMPncSignalId == INVALID_SIGNAL_HANDLE))
#endif
{
/* If full communication is requested */
if (comMode == COMM_FULL_COMMUNICATION) {
chnlIntrnal->userOrPncReqMode = comMode; /* @req COMM92 */
chnlIntrnal->userOrPncReqPending = TRUE;
} else if (chnlIntrnal->UserRequestMask == 0){
/* @req COMM686 *//* If all users release this channel then request no communication */
/* No partial networking - Save the requested modes */
chnlIntrnal->userOrPncReqMode = comMode; /* @req COMM92 */
chnlIntrnal->userOrPncReqPending = TRUE;
} else {
/* Do nothing */
}
}
/*lint -restore */
}
#if (COMM_PNC_SUPPORT == STD_ON)
static void ComM_Internal_UpdatePncChangeRequests(ComM_UserHandleType User,ComM_ModeType ComMode);
#endif
/**
* @brief Delegate request to users channels and call ComM_Internal_UpdateChannelState
* @param User
* @param ComMode
* @return
*/
static Std_ReturnType ComM_Internal_RequestComMode(
ComM_UserHandleType User, ComM_ModeType ComMode ){
const ComM_UserType* UserConfig; /** @req COMM795 */
ComM_Internal_UserType* UserInternal;
const ComM_ChannelType* Channel;
ComM_Internal_ChannelType* ChannelInternal;
uint64 userMask;
ComM_ModeType mode;
Std_ReturnType status;
Std_ReturnType totalStatus;
uint8 loopCount;
uint8 i;
boolean pncEnableSts;
UserConfig = &ComM_ConfigPtr->Users[User]; /** @req COMM795 */
UserInternal = &ComM_Internal.Users[User];
status = E_OK;
totalStatus = E_OK;
loopCount = UserConfig->ChannelCount; /* Number of channels mapped to this user */
pncEnableSts = FALSE;
#if (COMM_PNC_SUPPORT == STD_ON)
/* Check if PNC is enabled and user references any PNC */
/*lint -e{838} OTHER Previous value is not used as it serves as initialization when PNC support is OFF */
pncEnableSts = ((TRUE == ComM_ConfigPtr->ComMPncConfig->ComMPncEnabled) && (UserConfig->PncChnlCount !=0));
if (TRUE == pncEnableSts){
loopCount += UserConfig->PncChnlCount; /* Increment by number of channels mapped to PNCs referenced by this user */
}
#endif
/* Loop through users channels */
for (i = 0; i < loopCount ; i++) {
Channel = getComMChannelConfig(pncEnableSts,i,UserConfig);
ChannelInternal = &ComM_Internal.Channels[Channel->ComMChannelId];
/* @req ComM066 */ /* ModeInhibition check is done only for user requests */
status = checkForModeInhibitions(ChannelInternal,ComMode);
if (status > totalStatus) {
totalStatus = status;
}
/* If there is no ComM_BusSM_ModeIndication() pending, an extra check to
* see if ComM current mode and lower <module>SM mode are in sync*/
if ((ChannelInternal->requestPending == FALSE) && (E_OK == status)) {
status = ComM_Internal_GetCurrentComMode(Channel, &mode);
if ((status == E_OK) && (mode != ChannelInternal->Mode)){
totalStatus = E_NOT_OK;
break;
}
}
}
/* If new mode request is valid - remember */
if (totalStatus != E_NOT_OK) {
/* Consider the new user mode request */
UserInternal->RequestedMode = ComMode;
userMask = (1ULL << User);
#if (COMM_PNC_SUPPORT == STD_ON)
/* Pnc related action is performed first and channel related action later */
/** @req ComM953 */
/** @req ComM979 */
if (TRUE == pncEnableSts) {
ComM_Internal_UpdatePncChangeRequests(User,ComMode);
}
#endif
for (i = 0; i < loopCount; i++) {
Channel = getComMChannelConfig(pncEnableSts,i,UserConfig);
ChannelInternal = &ComM_Internal.Channels[Channel->ComMChannelId];
/** @req COMM625 */
/** @req COMM839 */
/** @req COMM840 */
// Put user request into mask
/** @req COMM500 */
if (ComMode == COMM_NO_COMMUNICATION) {
ChannelInternal->UserRequestMask &= ~(userMask);
} else if (ComMode == COMM_FULL_COMMUNICATION) {
ChannelInternal->UserRequestMask |= userMask;
} else {
/*Nothing to be done.*/
}
saveRequestedMode(pncEnableSts,ChannelInternal,Channel,ComMode);
}
}
/* Mode inhibitions is active */
/* @req ComM142 */
if ((totalStatus == COMM_E_MODE_LIMITATION) && (ComM_Internal.InhibitCounter < 65535)) {
ComM_Internal.InhibitCounter++;
}
return totalStatus;
}
#if (COMM_PNC_SUPPORT == STD_ON)
/**
* @brief Register new user requests for PN
* @param User
* @param ComMode
*/
static void ComM_Internal_UpdatePncChangeRequests(ComM_UserHandleType User,ComM_ModeType ComMode){
const ComM_PNConfigType * pncCfg;
uint8 pncCount;
uint8 usrCnt;
pncCfg = ComM_ConfigPtr->ComMPncConfig;
/** check all PNCs mapped to this user */
for (pncCount=0;(pncCount < pncCfg->ComMPncNum);pncCount++) {
if (pncCfg->ComMPnc[pncCount].ComMPncUserRefNum !=0) {
/** Scan all users associated with the PNC */
for (usrCnt=0; usrCnt < pncCfg->ComMPnc[pncCount].ComMPncUserRefNum; usrCnt++) {
if (pncCfg->ComMPnc[pncCount].ComMPncUserRef[usrCnt] == User) {
ComM_Internal.pncRunTimeData[pncCount].pncRequestedState = ComMode;
ComM_Internal.pncRunTimeData[pncCount].pncNewUserRequest = TRUE;
}
}
}
}
}
/**
* @brief Save the trigger for new EIRA reception
*/
void ComM_Arc_IndicateNewRxEIRA(void) {
ComM_Internal.newEIRARxSignal = TRUE;
}
/**
* @brief update bits in TxComSignal
* @param byteIndex
* @param bitIndex
* @param set
*/
static inline void ComM_Internal_updateTxComSignal(uint8 chnlIdx, uint8 byteIndex,uint8 bitIndex,boolean set) {
uint8 mask;
mask =(uint8)(1u << bitIndex);
if (FALSE == set) {
mask = ~mask;
ComM_Internal.Channels[chnlIdx].TxComSignal.bytes[byteIndex] &= mask;
} else {
ComM_Internal.Channels[chnlIdx].TxComSignal.bytes[byteIndex] |= mask;
}
}
/**
*
* @param pncCount
* @param trig - Set Internal request or release
* @param gwType - Type of gw channel to be selected for send operation
*/
static void comTransmitSignal(uint8 pncCount, ComM_Internal_TriggerSendType trig, ComM_PncGatewayType gwType)
{
uint8 i;
uint8 chnlIdx;
uint8 pncId;
uint8 byteNo;
uint8 bitNo;
uint8 mask;
pncId = ComM_ConfigPtr->ComMPncConfig->ComMPnc[pncCount].ComMPncId;
byteNo = pncId/8;
bitNo = pncId%8;
Com_SignalIdType sigId;
for (i = 0;i < ComM_ConfigPtr->ComMPncConfig->ComMPnc[pncCount].ComMPncChnlRefNum; i++)
{
chnlIdx = ComM_ConfigPtr->ComMPncConfig->ComMPnc[pncCount].ComMPncChnlRef[i];
#if (COMM_PNC_GATEWAY_ENABLED == STD_ON)
if ((gwType != ComM_ConfigPtr->Channels[chnlIdx].PncGatewayType) && (gwType != COMM_GATEWAY_TYPE_NONE))
{
continue; /* Only ComMChannels with active/passive gateway is requested */
/*gwType is COMM_GATEWAY_TYPE_NONE, both acitve and passive channel Tx signals are sent */
}
#else
(void)gwType;
#endif
mask =(uint8)(1u << bitNo);
if (TRIGGER_SEND_PNC_VAL_0 == trig) {
if ((ComM_Internal.Channels[chnlIdx].TxComSignal.bytes[byteNo] & mask) != 0) {
ComM_Internal_updateTxComSignal(chnlIdx, byteNo, bitNo, FALSE); /** @req ComM960 */
} else {
continue; /* No re-transmission required */
}
}
else {
if ((ComM_Internal.Channels[chnlIdx].TxComSignal.bytes[byteNo] & mask) == 0) {
ComM_Internal_updateTxComSignal(chnlIdx, byteNo, bitNo, TRUE); /** @req ComM930 */
} else {
continue; /* No re-transmission required */
}
}
sigId = ComM_ConfigPtr->ComMPncConfig->ComMPncTxComSigIdRef[chnlIdx].ComMPncSignalId;
/** @req ComM975 */
if ( sigId != INVALID_SIGNAL_HANDLE) {
(void)Com_SendSignal(sigId, ComM_Internal.Channels[chnlIdx].TxComSignal.bytes);
}
}
}
/**
* @brief Request all Channels to Enter Full Com
* @param pncCount
*/
static inline void reqAllPncComMChlsFullCom(uint8 pncCount) {
uint8 chnlId;
uint8 i;
ComM_Internal_ChannelType* ChannelInternal;
for (i=0;i < ComM_ConfigPtr->ComMPncConfig->ComMPnc[pncCount].ComMPncChnlRefNum; i++)
{
chnlId = ComM_ConfigPtr->ComMPncConfig->ComMPnc[pncCount].ComMPncChnlRef[i]; /* Get the channel handle */
ChannelInternal = &ComM_Internal.Channels[chnlId];
/* Partial networking - Save the new mode */
ChannelInternal->userOrPncReqMode = COMM_FULL_COMMUNICATION; /* @req COMM92 */
ChannelInternal->userOrPncReqPending = TRUE;
}
}
/**
* @brief Release all channels
* @param pncCount
*/
static inline void reqAllPncNmChannelsRelease(uint8 pncCount) {
/* This function is called whenever PNC State READY_SLEEP is entered.
* The ComMChannels are requested NO_COMMUNICATION
*/
uint8 chnlId;
uint8 i;
ComM_Internal_ChannelType* ChannelInternal;
for (i=0;i < ComM_ConfigPtr->ComMPncConfig->ComMPnc[pncCount].ComMPncChnlRefNum; i++){
chnlId = ComM_ConfigPtr->ComMPncConfig->ComMPnc[pncCount].ComMPncChnlRef[i]; /* Get the channel handle */
ChannelInternal = &ComM_Internal.Channels[chnlId];
/* Partial networking - Save the new mode */
ChannelInternal->userOrPncReqMode = COMM_NO_COMMUNICATION; /* @req COMM92 */
ChannelInternal->userOrPncReqPending = TRUE;
}
}
/**
* @brief update bits in EIRA
* @param byteIndex
* @param bitIndex
* @param set
*/
static inline void ComM_Internal_updateEIRAPNCBit(uint8 byteIndex,uint8 bitIndex,boolean set) {
uint8 mask;
mask = (uint8)(1u << bitIndex);
if (FALSE == set) {
mask = ~mask;
ComM_Internal.pnEIRA.bytes[byteIndex] &= mask;
} else {
ComM_Internal.pnEIRA.bytes[byteIndex] |= mask;
}
}
#define LSBIT_MASK 0x1u
/**
* @brief Update ComM PNC states for new EIRA received
* @return Indicate if the state has change to PNC_PREPARE_SLEEP or not
*/
static void ComM_Internal_EIRARxSignalUpdate(void) {
uint8 newEIRA[COMM_PNC_COMSIGNAL_VECTOR_LEN];
uint8 byteNo;
uint8 bitNo;
uint8 set;
PNCHandleType pnc;
uint8 pncCount;
uint8 ret;
boolean isStateChanged;
uint8 i;
ComM_Internal.newEIRARxSignal = FALSE;
if (ComM_ConfigPtr->ComMPncConfig->ComMPncEIRARxComSigIdRef == NULL) {
/*nothing*/
} else {
/** @req ComM984 */
ret = Com_ReceiveSignal(ComM_ConfigPtr->ComMPncConfig->ComMPncEIRARxComSigIdRef->ComMPncSignalId,newEIRA);
for (byteNo=0;(byteNo< COMM_PNC_COMSIGNAL_VECTOR_LEN) && (ret == E_OK);byteNo++) {
if (ComM_Internal.pnEIRA.bytes[byteNo] != newEIRA[byteNo]) {
for (bitNo=0;bitNo<8;bitNo++) {
set = ((newEIRA[byteNo] >> bitNo)&LSBIT_MASK);
if (((ComM_Internal.pnEIRA.bytes[byteNo] >> bitNo)&LSBIT_MASK) != set) {
ComM_Internal_updateEIRAPNCBit(byteNo,bitNo,(boolean)set);
/*lint -e{734} *//* the number of pnc is limited to 48, no loss of precision */
pnc = (byteNo*8)+bitNo;
for (i=0;i <ComM_ConfigPtr->ComMPncConfig->ComMPncNum; i++){
if (ComM_ConfigPtr->ComMPncConfig->ComMPnc[i].ComMPncId == pnc) {
break; /* Found */
}
}
if (i == ComM_ConfigPtr->ComMPncConfig->ComMPncNum) {
continue; /* Not found */
}
pncCount = ComM_ConfigPtr->ComMPncConfig->ComMPncIdToPncCountVal[pnc];
isStateChanged = FALSE;
if (set==1) {
/** @req ComM944 */
if (PNC_PREPARE_SLEEP == ComM_Internal.pncRunTimeData[pncCount].pncSubState) {
/** @req ComM950 */
ComM_Internal.pncRunTimeData[pncCount].pncSubState = PNC_READY_SLEEP;
isStateChanged = TRUE;
} else if (PNC_NO_COMMUNICATION == ComM_Internal.pncRunTimeData[pncCount].pncSubState) {
/** @req ComM933 */
ComM_Internal.pncRunTimeData[pncCount].pncSubState = PNC_READY_SLEEP;
ComM_Internal.pncRunTimeData[pncCount].pncState = PNC_FULL_COMMUNICATION_STATE;
isStateChanged = TRUE;
/* @adma No need to fulfill ComM929 here, if channels are requested FULL_COM, it leads
* to Nm network request which is not intended in READY_SLEEP state.
* Also because of the reason we are in FULL_COM we have received this EIRA indication from CanNm
*/
} else {
/* Do nothing */
}
} else {
if (PNC_READY_SLEEP == ComM_Internal.pncRunTimeData[pncCount].pncSubState) {
/** @req ComM940 */
ComM_Internal.pncRunTimeData[pncCount].pncSubState = PNC_PREPARE_SLEEP;
/** @req ComM952 */
ComM_Internal.pncRunTimeData[pncCount].prepareSleepTimer = COMM_T_PNC_PREPARE_SLEEP;
isStateChanged = TRUE;
}
}
if (TRUE == isStateChanged) {
ComM_PncStateTrans_ThisCycle = TRUE;
#if defined(USE_BSWM)
/** @req ComM908 */
/** @req COMM976 */
/*switch between version 4.2.2 and 4.0.3 to support Pnc id range for both versions*/
#if ( STD_ON == ARC_COMM_ASR_COMPATIBILITY_LESS_THAN_4_2)
BswM_ComM_CurrentPNCMode(pnc,ComM_Internal.pncRunTimeData[pncCount].pncSubState);
#else
BswM_ComM_CurrentPNCMode((pnc+(8 * ARC_COMM_PNC_VECTOR_OFFSET)),ComM_Internal.pncRunTimeData[pncCount].pncSubState);
#endif
#endif
}
}
}
}
}
}
}
/** @req ComM988 *//* Pnc SM description */
/**
* @brief Handle PNC state change
* @param idx index of PNC
* @param req flag to indicate if EIRA has to be updated or not
* @param Channel Related ComM channel
* @return
*/
static void ComM_Internal_HandlePncStateChange(uint8 pncCount, ComM_Internal_TriggerSendType *req) {
uint8 byteIndex;
uint8 bitIndex;
PNCHandleType pnc;
uint8 i;
uint8 usr;
uint8 channelIndex;
boolean isStateChanged;
boolean status;
status = TRUE;
pnc = ComM_ConfigPtr->ComMPncConfig->ComMPnc[pncCount].ComMPncId;
isStateChanged= FALSE;
if(COMM_NO_COMMUNICATION == ComM_Internal.pncRunTimeData[pncCount].pncRequestedState) {
if (PNC_REQUESTED == ComM_Internal.pncRunTimeData[pncCount].pncSubState) {
/* If current state is PNC_REQUESTED check whether any other user is requesting this PNC */
for (i=0;i < ComM_ConfigPtr->ComMPncConfig->ComMPnc[pncCount].ComMPncUserRefNum; i++)
{
usr = ComM_ConfigPtr->ComMPncConfig->ComMPnc[pncCount].ComMPncUserRef[i]; /* Get the user handle */
if (ComM_Internal.Users[usr].RequestedMode == COMM_FULL_COMMUNICATION) {
/** @req ComM936 */
status = FALSE;
break; /* No need of PNC state change. At least one user requesting COMM_FULL_COMMUNICATION */
}
}
#if (COMM_PNC_GATEWAY_ENABLED == STD_OFF)
/** @req ComM938 */
if(status == TRUE){
ComM_Internal.pncRunTimeData[pncCount].pncSubState = PNC_READY_SLEEP;
*req = TRIGGER_SEND_PNC_VAL_0;
isStateChanged = TRUE;
reqAllPncNmChannelsRelease(pncCount); /* @req 4.2.2SWS_ComM_00961 */ /* This is required to make CanNm enter Ready sleep state*/
channelIndex = 0;
(void)channelIndex;
byteIndex = 0;
bitIndex = 0;
(void)byteIndex;
(void)bitIndex;
}
}
#else /* COMM_PNC_GATEWAY_ENABLED == STD_ON */
if(status == TRUE){
byteIndex = pnc/8;
bitIndex = pnc%8;
for (channelIndex = 0; channelIndex < COMM_CHANNEL_COUNT; channelIndex++) {
if ((ComM_Internal.Channels[channelIndex].pnERA.bytes[byteIndex] & (1u << bitIndex)) != 0) {
status = FALSE;
break; /* PNC in all ERA is not released */
}
}
if (status == TRUE) {
/** @req ComM991 */
ComM_Internal.pncRunTimeData[pncCount].pncSubState = PNC_READY_SLEEP;
*req = TRIGGER_SEND_PNC_VAL_0;
isStateChanged = TRUE;
reqAllPncNmChannelsRelease(pncCount); /* @req 4.2.2SWS_ComM_00961 */ /* This is required to make CanNm enter Ready sleep state*/
}
}
}
#endif /* COMM_PNC_GATEWAY_ENABLED */
} else {
if (ComM_Internal.pncRunTimeData[pncCount].pncSubState != PNC_REQUESTED) {
/** @req ComM932 */ /** @req ComM948 */
ComM_Internal.pncRunTimeData[pncCount].pncSubState = PNC_REQUESTED;
ComM_Internal.pncRunTimeData[pncCount].pncState = PNC_FULL_COMMUNICATION_STATE;
reqAllPncComMChlsFullCom(pncCount); /* @req ComM993 */
*req = TRIGGER_SEND_PNC_VAL_1; /** @req ComM992 */ /* @req 4.2.2 SWS_ComM_00164 */
isStateChanged = TRUE;
}
*req = TRIGGER_SEND_PNC_VAL_1; /** @req ComM992 */ /* @req 4.2.2 SWS_ComM_00164 */
}
if ((status == TRUE) && (TRUE == isStateChanged)) {
ComM_PncStateTrans_ThisCycle = TRUE;
#if defined(USE_BSWM)
/** @req ComM908 */
/** @req COMM976 */
/*switch between version 4.2.2 and 4.0.3 to support Pnc id range for both versions*/
#if ( STD_ON == ARC_COMM_ASR_COMPATIBILITY_LESS_THAN_4_2)
BswM_ComM_CurrentPNCMode(pnc,ComM_Internal.pncRunTimeData[pncCount].pncSubState);
#else
BswM_ComM_CurrentPNCMode((pnc+(8 * ARC_COMM_PNC_VECTOR_OFFSET)),ComM_Internal.pncRunTimeData[pncCount].pncSubState);
#endif
#endif
}
(void)pnc; // Lint: Symbol not accessed
}
/**
* @brief Process new user requests
* @param Channel
* @return indicates if Channel is requested to change state or not
*/
static void ComM_Internal_ProcessPNReqMode(NetworkHandleType Channel) {
uint8 pncCount;
uint8 chnlIdx;
ComM_Internal_TriggerSendType trigVal;
trigVal= INVALID_TRIGGER_SEND;
for (pncCount=0;pncCount<ComM_ConfigPtr->ComMPncConfig->ComMPncNum;pncCount++) {
for(chnlIdx=0;chnlIdx < ComM_ConfigPtr->ComMPncConfig->ComMPnc[pncCount].ComMPncChnlRefNum;chnlIdx++) {
/* Find any matching channel for the current iteration PNC */
if (Channel == ComM_ConfigPtr->ComMPncConfig->ComMPnc[pncCount].ComMPncChnlRef[chnlIdx]) {
if (TRUE == ComM_Internal.pncRunTimeData[pncCount].pncNewUserRequest){
ComM_Internal_HandlePncStateChange(pncCount,&trigVal);
ComM_Internal.pncRunTimeData[pncCount].pncNewUserRequest = FALSE;
if (trigVal != INVALID_TRIGGER_SEND ) {
comTransmitSignal(pncCount,trigVal, COMM_GATEWAY_TYPE_NONE);
}
break; /* channel found */
}
}
}
}
}
/**
* @brief Tick prepare sleep timer for PNC
* @param ChannelConf
*/
static inline void ComM_Internal_TickPncPrepareSleepTime(const ComM_ChannelType* ChannelConf) {
uint8 pncCount;
PNCHandleType pncId = 0;
for (pncCount=0;pncCount<ComM_ConfigPtr->ComMPncConfig->ComMPncNum;pncCount++) {
/** @req ComM943 */
if (PNC_PREPARE_SLEEP == ComM_Internal.pncRunTimeData[pncCount].pncSubState ) {
/* Decrement PN sleep timers for 1st main function of the PNC only */
if (ChannelConf->ComMChannelId == ComM_ConfigPtr->ComMPncConfig->ComMPnc[pncCount].ComMPncChnlRef[PNC_FIRST_CHNL_REF]) {
if (ChannelConf->MainFunctionPeriod > ComM_Internal.pncRunTimeData[pncCount].prepareSleepTimer) {
ComM_Internal.pncRunTimeData[pncCount].prepareSleepTimer = 0;
pncId = ComM_ConfigPtr->ComMPncConfig->ComMPnc[pncCount].ComMPncId;
/** @req ComM947 */
ComM_Internal.pncRunTimeData[pncCount].pncSubState = PNC_NO_COMMUNICATION;
ComM_Internal.pncRunTimeData[pncCount].pncState = PNC_NO_COMMUNICATION_STATE;
ComM_PncStateTrans_ThisCycle = TRUE;
#if defined(USE_BSWM)
/** @req ComM908 */
/** @req COMM976 */
/*switch between version 4.2.2 and 4.0.3 to support Pnc id range for both versions*/
#if ( STD_ON == ARC_COMM_ASR_COMPATIBILITY_LESS_THAN_4_2)
BswM_ComM_CurrentPNCMode(pncId,ComM_Internal.pncRunTimeData[pncCount].pncSubState);
#else
BswM_ComM_CurrentPNCMode((pncId+(8 * ARC_COMM_PNC_VECTOR_OFFSET)),ComM_Internal.pncRunTimeData[pncCount].pncSubState);
#endif
#endif /* defined(USE_BSWM) */
} else {
ComM_Internal.pncRunTimeData[pncCount].prepareSleepTimer -= ChannelConf->MainFunctionPeriod;
}
}
}
}
(void)pncId; // Lint: Symbol not accessed
}
/**
* @brief All pnc in ready sleep is checked whether a transition to prepare sleep is required
*/
static void ComM_Internal_Monitor_RdySlpToPrpSlpTrns(void)
{
uint8 byteNo;
uint8 bitNo;
uint8 pncCount;
PNCHandleType pncId;
uint8 mask;
/** @req ComM942 */ /* Retain this state until no new Internal requests*/
for(pncCount=0;pncCount<ComM_ConfigPtr->ComMPncConfig->ComMPncNum;pncCount++) {
if (PNC_READY_SLEEP == ComM_Internal.pncRunTimeData[pncCount].pncSubState) {
pncId = ComM_ConfigPtr->ComMPncConfig->ComMPnc[pncCount].ComMPncId;
byteNo = pncId /8;
bitNo = pncId %8;
mask = (uint8)(1u << bitNo);
if( (ComM_Internal.pnEIRA.bytes[byteNo] & mask) == 0)
{
/** @req ComM940 */
ComM_Internal.pncRunTimeData[pncCount].pncSubState = PNC_PREPARE_SLEEP;
/** @req ComM952 */
ComM_Internal.pncRunTimeData[pncCount].prepareSleepTimer = COMM_T_PNC_PREPARE_SLEEP;
ComM_PncStateTrans_ThisCycle = TRUE;
#if defined(USE_BSWM)
/** @req ComM908 */
/** @req COMM976 */
/*switch between version 4.2.2 and 4.0.3 to support Pnc id range for both versions*/
#if ( STD_ON == ARC_COMM_ASR_COMPATIBILITY_LESS_THAN_4_2)
BswM_ComM_CurrentPNCMode(pncId,ComM_Internal.pncRunTimeData[pncCount].pncSubState);
#else
BswM_ComM_CurrentPNCMode((pncId+(8 * ARC_COMM_PNC_VECTOR_OFFSET)),ComM_Internal.pncRunTimeData[pncCount].pncSubState);
#endif
#endif /* defined(USE_BSWM) */
}
}
}
}
#if (HOST_TEST == STD_ON)
uint64 * readEira(void) {
return &ComM_Internal.pnEIRA.data;
}
ComM_PncStateType checkPncStatus(uint8 idx) {
return ComM_Internal.pncRunTimeData[idx].pncState;
}
ComM_PncModeType checkPncMode(uint8 idx) {
return ComM_Internal.pncRunTimeData[idx].pncSubState;
}
#endif /* (HOST_TEST == STD_ON) */
#if (COMM_PNC_GATEWAY_ENABLED == STD_ON)
/**
* @brief Save the trigger for new ERA reception
*/
void ComM_Arc_IndicateNewRxERA(uint8 channelIndex) {
ComM_Internal.Channels[channelIndex].newERARxSignal = TRUE;
}
/**
* @brief update bits in RA
* @param byteIndex
* @param bitIndex
* @param set
*/
/*lint -e{9018} No issue using union as per the logic */
static inline void ComM_Internal_updateRAPNCBit(ComM_Internal_RAType *RA,
uint8 byteIndex, uint8 bitIndex, boolean set) {
if (FALSE == set) {
RA->bytes[byteIndex] &=(uint8) ~(1u << bitIndex);
} else {
RA->bytes[byteIndex] |=(uint8)(1u << bitIndex);
}
}
/**
* @brief Process external PNC request i.e Rx ERA with PNC bit set to 1
* @param pncCount
* @param channelIndex
* @return
*/
static boolean externalPncRequest(uint8 pncCount,uint8 channelIndex){
boolean isStateChanged;
boolean doReqestStateTrans;
isStateChanged = FALSE;
doReqestStateTrans = TRUE;
/** @req ComM945 */
if (PNC_PREPARE_SLEEP == ComM_Internal.pncRunTimeData[pncCount].pncSubState) {
/** @req ComM951 */
ComM_Internal.pncRunTimeData[pncCount].pncSubState = PNC_REQUESTED;
reqAllPncComMChlsFullCom(pncCount); /* @req ComM993 */
isStateChanged = TRUE;
} else if (PNC_NO_COMMUNICATION == ComM_Internal.pncRunTimeData[pncCount].pncSubState) {
/** @req ComM934 */
ComM_Internal.pncRunTimeData[pncCount].pncSubState = PNC_REQUESTED;
ComM_Internal.pncRunTimeData[pncCount].pncState = PNC_FULL_COMMUNICATION_STATE;
/** @req ComM929 */
reqAllPncComMChlsFullCom(pncCount); /* @req ComM993 */
isStateChanged = TRUE;
} else if (PNC_READY_SLEEP == ComM_Internal.pncRunTimeData[pncCount].pncSubState) {
ComM_Internal.pncRunTimeData[pncCount].pncSubState = PNC_REQUESTED;
reqAllPncComMChlsFullCom(pncCount); /* @req ComM993 */
isStateChanged = TRUE;
} else {
doReqestStateTrans = FALSE;
}
if (COMM_GATEWAY_TYPE_ACTIVE == ComM_ConfigPtr->Channels[channelIndex].PncGatewayType )
{
comTransmitSignal(pncCount, TRIGGER_SEND_PNC_VAL_1,COMM_GATEWAY_TYPE_NONE); /** @req ComM992 */ /* @req 4.2.2 SWS_ComM_00164 */
} else if (TRUE == doReqestStateTrans) {
comTransmitSignal(pncCount, TRIGGER_SEND_PNC_VAL_1, COMM_GATEWAY_TYPE_ACTIVE); /** @req ComM992 */
} else {
/* Do nothing */
}
return isStateChanged;
}
/**
* @brief Release any external PNC request (i.e Rx ERA with PNC bit set to 0)
* @param pncCount
* @param byteNo
* @param bitNo
* @return
*/
static boolean externalPncRelease(uint8 pncCount,uint8 byteNo,uint8 bitNo) {
boolean isStateChanged;
boolean doReadySleepTrans;
uint8 usrHandle;
uint8 usrCnt;
uint8 channelId;
isStateChanged = FALSE;
doReadySleepTrans = TRUE;
if (PNC_REQUESTED == ComM_Internal.pncRunTimeData[pncCount].pncSubState) {
/* If current state is PNC_REQUESTED check whether any other user is requesting this PNC */
for (usrCnt=0;usrCnt< ComM_ConfigPtr->ComMPncConfig->ComMPnc[pncCount].ComMPncUserRefNum; usrCnt++)
{
usrHandle = ComM_ConfigPtr->ComMPncConfig->ComMPnc[pncCount].ComMPncUserRef[usrCnt]; /* Get the user handle */
if (ComM_Internal.Users[usrHandle].RequestedMode == COMM_FULL_COMMUNICATION) {
doReadySleepTrans = FALSE;
break;/* @req ComM936 */
}
}
if (TRUE == doReadySleepTrans) { /* All user is requesting No Communication */
for (channelId = 0; channelId < COMM_CHANNEL_COUNT; channelId++) {
if ((ComM_Internal.Channels[channelId].pnERA.bytes[byteNo] & (1u << bitNo)) != 0) {
doReadySleepTrans = FALSE;
break; /* No need of PNC state change */ /* @req ComM937 */
}
}
if (TRUE == doReadySleepTrans) { /* All ERAn for this PNC is relased go to Ready Sleep*/
/** @req ComM991 */
ComM_Internal.pncRunTimeData[pncCount].pncSubState = PNC_READY_SLEEP;
/** @req ComM960 */
comTransmitSignal(pncCount, TRIGGER_SEND_PNC_VAL_0, COMM_GATEWAY_TYPE_NONE);
isStateChanged = TRUE;
reqAllPncNmChannelsRelease(pncCount); /* @req 4.2.2SWS_ComM_00961 */ /* This is required to make CanNm enter Ready sleep state*/
}
}
}
return isStateChanged;
}
/**
* @brief Update ComM PNC states for new ERA received
*/
static void ComM_Internal_ERARxSignalUpdate(uint8 channelIndex) {
uint8 newERA[COMM_PNC_COMSIGNAL_VECTOR_LEN];
uint8 byteNo;
uint8 bitNo;
uint8 set;
PNCHandleType pnc;
uint8 pncCount;
uint8 ret;
uint8 i;
Com_SignalIdType rxSignalId;
boolean isStateChanged;
ComM_Internal.Channels[channelIndex].newERARxSignal = FALSE;
rxSignalId = ComM_ConfigPtr->ComMPncConfig->ComMPncERARxComSigIdRefs[channelIndex].ComMPncSignalId;
if ( rxSignalId != INVALID_SIGNAL_HANDLE) {
/** @req ComM984 */
ret = Com_ReceiveSignal(rxSignalId, newERA);
if (ret == E_OK)
{
for (byteNo = 0; byteNo < COMM_PNC_COMSIGNAL_VECTOR_LEN; byteNo++) {
if (ComM_Internal.Channels[channelIndex].pnERA.bytes[byteNo] != newERA[byteNo]) {
for (bitNo = 0; bitNo < 8; bitNo++) {
set = ((newERA[byteNo] >> bitNo) & LSBIT_MASK);
if (((ComM_Internal.Channels[channelIndex].pnERA.bytes[byteNo] >> bitNo) & LSBIT_MASK) != set) {
/* @req COMM945 */ /* We update all ERA's irrespective of gateway type */
ComM_Internal_updateRAPNCBit(&ComM_Internal.Channels[channelIndex].pnERA,
byteNo, bitNo, (boolean) set);
/*lint -e{734} *//* the number of pnc is limited to 48, no loss of precision */
pnc = (byteNo * 8) + bitNo;
for (i=0;i <ComM_ConfigPtr->ComMPncConfig->ComMPncNum; i++){
if (ComM_ConfigPtr->ComMPncConfig->ComMPnc[i].ComMPncId == pnc) {
break; /* Found */
}
}
/*lint -e{539} Did not expect positive indentation from line. OK, false positive. */
if (i == ComM_ConfigPtr->ComMPncConfig->ComMPncNum) {
continue; /* Not found */
}
pncCount = ComM_ConfigPtr->ComMPncConfig->ComMPncIdToPncCountVal[pnc];
isStateChanged = FALSE;
if (set == 1) {
isStateChanged = externalPncRequest(pncCount, channelIndex);
} else {
isStateChanged = externalPncRelease(pncCount, byteNo, bitNo);
}
if (isStateChanged == TRUE) {
ComM_PncStateTrans_ThisCycle = TRUE;
#if defined(USE_BSWM)
/** @req ComM908 */
/** @req COMM976 */
/*switch between version 4.2.2 and 4.0.3 to support Pnc id range for both versions*/
#if ( STD_ON == ARC_COMM_ASR_COMPATIBILITY_LESS_THAN_4_2)
BswM_ComM_CurrentPNCMode(pnc,ComM_Internal.pncRunTimeData[pncCount].pncSubState);
#else
BswM_ComM_CurrentPNCMode((pnc+(8 * ARC_COMM_PNC_VECTOR_OFFSET)),ComM_Internal.pncRunTimeData[pncCount].pncSubState);
#endif
#endif
}
}
}
}
}
}
}
}
/**
* @brief Monitors the ComMChannel of type COMM_GATEWAY_TYPE_PASSIVE when PNC is in requested mode
*/
static void ComM_Internal_Monitor_GwPassiveChnl(void)
{
uint8 pncCount;
uint8 i;
uint8 usr;
boolean sendZeroPncVal;
uint8 chnlIdx;
uint8 mask;
uint8 byteNo;
uint8 bitNo;
PNCHandleType pncId;
for(pncCount=0;pncCount<ComM_ConfigPtr->ComMPncConfig->ComMPncNum;pncCount++) {
if (PNC_REQUESTED == ComM_Internal.pncRunTimeData[pncCount].pncSubState) {
sendZeroPncVal = TRUE;
/* If current state is PNC_REQUESTED check whether any other user is requesting this PNC */
for (i=0;i < ComM_ConfigPtr->ComMPncConfig->ComMPnc[pncCount].ComMPncUserRefNum; i++)
{
usr = ComM_ConfigPtr->ComMPncConfig->ComMPnc[pncCount].ComMPncUserRef[i]; /* Get the user handle */
if (ComM_Internal.Users[usr].RequestedMode == COMM_FULL_COMMUNICATION) {
sendZeroPncVal = FALSE;
break;/* @req ComM936 */
}
}
if (TRUE == sendZeroPncVal) {
pncId = ComM_ConfigPtr->ComMPncConfig->ComMPnc[pncCount].ComMPncId;
byteNo = pncId /8;
bitNo = pncId %8;
mask = (uint8)(1u << bitNo);
for (i = 0;i < ComM_ConfigPtr->ComMPncConfig->ComMPnc[pncCount].ComMPncChnlRefNum; i++)
{
chnlIdx = ComM_ConfigPtr->ComMPncConfig->ComMPnc[pncCount].ComMPncChnlRef[i];
if (COMM_GATEWAY_TYPE_ACTIVE == ComM_ConfigPtr->Channels[chnlIdx].PncGatewayType)
{
if( (ComM_Internal.Channels[chnlIdx].pnERA.bytes[byteNo] & mask) != 0) {
sendZeroPncVal = FALSE;
break;
}
}
}
if (TRUE == sendZeroPncVal) {
/* @req ComM966 */
/* @req ComM955 */
/* @req ComM959 */
/* @req ComM946 */
comTransmitSignal(pncCount, TRIGGER_SEND_PNC_VAL_0, COMM_GATEWAY_TYPE_PASSIVE);
}
}
}
}
}
#endif/* COMM_PNC_GATEWAY_ENABLED == STD_ON */
#endif /* (COMM_PNC_SUPPORT == STD_ON) */
void ComM_Init(const ComM_ConfigType * Config ){
uint8 i;
COMM_VALIDATE_PARAMETER_NORV( (Config != NULL), COMM_SERVICEID_INIT);
COMM_VALIDATE_PARAMETER_NORV( (Config->Channels != NULL), COMM_SERVICEID_INIT);
COMM_VALIDATE_PARAMETER_NORV( (Config->Users != NULL), COMM_SERVICEID_INIT);
ComM_ConfigPtr = Config;
for (i = 0; i < COMM_CHANNEL_COUNT; ++i) {
ComM_Internal.Channels[i].Mode = COMM_NO_COMMUNICATION; /**< @req COMM485 */
ComM_Internal.Channels[i].SubMode = COMM_NO_COM_NO_PENDING_REQUEST; /** @req COMM898 */
ComM_Internal.Channels[i].UserRequestMask = 0;
ComM_Internal.Channels[i].DCM_Requested = FALSE;
ComM_Internal.Channels[i].InhibitionStatus = COMM_INHIBITION_STATUS_NONE;
ComM_Internal.Channels[i].NmIndicationMask = COMM_NM_INDICATION_NONE;
ComM_Internal.Channels[i].CommunicationAllowed = FALSE; /** @req COMM884 */
ComM_Internal.Channels[i].requestPending = FALSE;
ComM_Internal.Channels[i].EcuMWkUpIndication = FALSE;
ComM_Internal.Channels[i].userOrPncReqMode = COMM_NO_COMMUNICATION; /* @req COMM92 */
ComM_Internal.Channels[i].userOrPncReqPending = FALSE;
ComM_Internal.Channels[i].lastRequestedMode = COMM_NO_COMMUNICATION;
ComM_Internal.Channels[i].internalRequest = FALSE;
ComM_Internal.Channels[i].nwStartIndication = FALSE;
ComM_Internal.Channels[i].fullComMinDurationTimerStopped = TRUE;
ComM_Internal.Channels[i].nmLightTimeoutTimerStopped = TRUE;
#if (COMM_PNC_SUPPORT == STD_ON)
ComM_Internal.Channels[i].TxComSignal.data = 0; /* Reset all Tx data */
#if (COMM_PNC_GATEWAY_ENABLED == STD_ON)
ComM_Internal.Channels[i].pnERA.data = 0;
ComM_Internal.Channels[i].newERARxSignal = FALSE;
#endif
#endif
}
for (i = 0; i < COMM_USER_COUNT; ++i) {
ComM_Internal.Users[i].RequestedMode = COMM_NO_COMMUNICATION;
ComM_Internal.Users[i].CurrentMode = COMM_NOT_USED_USER_ID;
}
#if (COMM_PNC_SUPPORT == STD_ON)
for (i = 0; ((i < ComM_ConfigPtr->ComMPncConfig->ComMPncNum) && (TRUE == ComM_ConfigPtr->ComMPncConfig->ComMPncEnabled)); ++i) {
/** @req ComM925 */
/** @req ComM926 */
/** @req ComM927 */
ComM_Internal.pncRunTimeData[i].pncState = PNC_NO_COMMUNICATION_STATE;
ComM_Internal.pncRunTimeData[i].pncSubState = PNC_NO_COMMUNICATION;
ComM_Internal.pncRunTimeData[i].pncRequestedState = COMM_NO_COMMUNICATION;
ComM_Internal.pncRunTimeData[i].prepareSleepTimer = 0;
ComM_Internal.pncRunTimeData[i].pncNewUserRequest = FALSE;
}
ComM_Internal.pnEIRA.data = 0;
ComM_Internal.newEIRARxSignal = FALSE;
#endif
ComM_Internal.InhibitCounter = 0;
ComM_Internal.InitStatus = COMM_INIT;
/** @req COMM313 */
}
void ComM_DeInit(){
/* !req COMM794 */
COMM_VALIDATE_INIT_NORV(COMM_SERVICEID_DEINIT);
ComM_Internal.InitStatus = COMM_UNINIT;
}
/* @req COMM872 */
Std_ReturnType ComM_GetState(NetworkHandleType Channel, ComM_StateType *State)
{
COMM_VALIDATE_INIT(COMM_SERVICEID_GETSTATE);
const ComM_Internal_ChannelType* ChannelInternal = &ComM_Internal.Channels[Channel];
*State = ChannelInternal->SubMode;
return E_OK;
}
Std_ReturnType ComM_GetStatus( ComM_InitStatusType* Status ){
COMM_VALIDATE_PARAMETER( (Status != NULL), COMM_SERVICEID_GETSTATUS);
*Status = ComM_Internal.InitStatus;
return E_OK;
}
Std_ReturnType ComM_GetInhibitionStatus( NetworkHandleType Channel, ComM_InhibitionStatusType* Status ){
COMM_VALIDATE_INIT(COMM_SERVICEID_GETINHIBITIONSTATUS);
const ComM_Internal_ChannelType* ChannelInternal = &ComM_Internal.Channels[Channel];
*Status = ChannelInternal->InhibitionStatus;
return E_OK;
}
Std_ReturnType ComM_RequestComMode( ComM_UserHandleType User, ComM_ModeType ComMode ){
COMM_VALIDATE_INIT(COMM_SERVICEID_REQUESTCOMMODE);
COMM_VALIDATE_USER(User, COMM_SERVICEID_REQUESTCOMMODE);
/** @req COMM151 */
COMM_VALIDATE_PARAMETER((ComMode != COMM_SILENT_COMMUNICATION), COMM_SERVICEID_REQUESTCOMMODE);
return ComM_Internal_RequestComMode(User, ComMode);
}
/* !req COMM085 */
Std_ReturnType ComM_GetMaxComMode( ComM_UserHandleType User, ComM_ModeType* ComMode ){
/* !req COMM796 */
COMM_VALIDATE_INIT(COMM_SERVICEID_GETMAXCOMMODE);
COMM_VALIDATE_USER(User, COMM_SERVICEID_GETMAXCOMMODE);
// Not implemented
//lint -estring(920,pointer) /* cast to void */
(void)ComMode;
//lint +estring(920,pointer) /* cast to void */
return E_NOT_OK;
}
Std_ReturnType ComM_GetRequestedComMode( ComM_UserHandleType User, ComM_ModeType* ComMode ){
COMM_VALIDATE_INIT(COMM_SERVICEID_GETREQUESTEDCOMMODE);
COMM_VALIDATE_USER(User, COMM_SERVICEID_GETREQUESTEDCOMMODE);
/** @req COMM797 */
const ComM_Internal_UserType* UserInternal = &ComM_Internal.Users[User];
*ComMode = UserInternal->RequestedMode;
return E_OK;
}
/** @req COMM084 */
Std_ReturnType ComM_GetCurrentComMode( ComM_UserHandleType User, ComM_ModeType* ComMode ){
COMM_VALIDATE_INIT(COMM_SERVICEID_GETCURRENTCOMMODE);
COMM_VALIDATE_USER(User, COMM_SERVICEID_GETCURRENTCOMMODE);
return ComM_Internal_PropagateGetCurrentComMode(User, ComMode);
}
/* !req COMM799 */
Std_ReturnType ComM_PreventWakeUp( NetworkHandleType Channel, boolean Status ){
COMM_VALIDATE_INIT(COMM_SERVICEID_PREVENTWAKEUP);
COMM_VALIDATE_CHANNEL(Channel, COMM_SERVICEID_PREVENTWAKEUP);
#if (COMM_MODE_LIMITATION_ENABLED == STD_ON)
ComM_Internal_ChannelType* ChannelInternal = &ComM_Internal.Channels[Channel];
if (TRUE == Status) {
ChannelInternal->InhibitionStatus |= (COMM_INHIBITION_STATUS_WAKE_UP);
} else {
ChannelInternal->InhibitionStatus &= ~(COMM_INHIBITION_STATUS_WAKE_UP);
}
return E_OK;
#else
(void)Status; /* Avoid compiler warning */
return E_NOT_OK;
#endif
}
/** !req COMM800.partially */
Std_ReturnType ComM_LimitChannelToNoComMode( NetworkHandleType Channel, boolean Status ){
COMM_VALIDATE_INIT(COMM_SERVICEID_LIMITCHANNELTONOCOMMODE);
COMM_VALIDATE_CHANNEL(Channel, COMM_SERVICEID_LIMITCHANNELTONOCOMMODE);
#if (COMM_MODE_LIMITATION_ENABLED == STD_ON)
ComM_Internal_ChannelType* ChannelInternal = &ComM_Internal.Channels[Channel];
if (TRUE == Status) {
ChannelInternal->InhibitionStatus |= (COMM_INHIBITION_STATUS_NO_COMMUNICATION);
} else {
ChannelInternal->InhibitionStatus &= ~(COMM_INHIBITION_STATUS_NO_COMMUNICATION);
}
/* Trigger state changes to Ready sleep if current state is COMM_FULL_COMMUNICATION - Limit to NoCom action */
ChannelInternal->internalRequest = TRUE;
return E_OK;
#else
(void)Status; /* Avoid compiler warning */
return E_NOT_OK;
#endif
}
/** !req COMM801.partially */
Std_ReturnType ComM_LimitECUToNoComMode( boolean Status ){
COMM_VALIDATE_INIT(COMM_SERVICEID_LIMITECUTONOCOMMODE);
#if (COMM_MODE_LIMITATION_ENABLED == STD_ON)
ComM_Internal_ChannelType* ChannelInternal;
ComM_Internal.NoCommunication = Status;
uint8 Channel;
for (Channel = 0; Channel < COMM_CHANNEL_COUNT; Channel++) {
ChannelInternal = &ComM_Internal.Channels[Channel];
/* Trigger state changes to Ready sleep if current state is COMM_FULL_COMMUNICATION - Limit to NoCom action */
ChannelInternal->internalRequest = TRUE;
}
return E_OK;
#else
(void)Status; /* Avoid compiler warning */
return E_NOT_OK;
#endif
}
/** @req COMM143 !req COMM802 */
Std_ReturnType ComM_ReadInhibitCounter( uint16* CounterValue ){
COMM_VALIDATE_INIT(COMM_SERVICEID_READINHIBITCOUNTER);
#if (COMM_MODE_LIMITATION_ENABLED == STD_ON)
*CounterValue = ComM_Internal.InhibitCounter;
return E_OK;
#else
/*lint -e{920} Intentional */
(void)(CounterValue);
return E_NOT_OK;
#endif
}
/** !req COMM803 */
Std_ReturnType ComM_ResetInhibitCounter(){
COMM_VALIDATE_INIT(COMM_SERVICEID_RESETINHIBITCOUNTER);
#if (COMM_MODE_LIMITATION_ENABLED == STD_ON)
ComM_Internal.InhibitCounter = 0;
return E_OK;
#else
return E_NOT_OK;
#endif
}
Std_ReturnType ComM_SetECUGroupClassification( ComM_InhibitionStatusType Status ){
COMM_VALIDATE_INIT(COMM_SERVICEID_SETECUGROUPCLASSIFICATION);
// Not implemented
(void)Status;
return E_NOT_OK;
}
// Network Management Interface Callbacks
// --------------------------------------
/** @req COMM383 */
void ComM_Nm_NetworkStartIndication( NetworkHandleType Channel ){
COMM_VALIDATE_INIT_NORV(COMM_SERVICEID_NM_NETWORKSTARTINDICATION);
COMM_VALIDATE_CHANNEL_NORV(Channel, COMM_SERVICEID_NM_NETWORKSTARTINDICATION);
ComM_Internal_ChannelType* ChannelInternal = &ComM_Internal.Channels[Channel];
// Used to simulate Wake-up
ChannelInternal->NmIndicationMask |= COMM_NM_INDICATION_RESTART;
ChannelInternal->internalRequest = TRUE;
}
/** @req COMM390 */
void ComM_Nm_NetworkMode( NetworkHandleType Channel ){
COMM_VALIDATE_INIT_NORV(COMM_SERVICEID_NM_NETWORKMODE);
COMM_VALIDATE_CHANNEL_NORV(Channel, COMM_SERVICEID_NM_NETWORKMODE);
ComM_Internal_ChannelType* ChannelInternal = &ComM_Internal.Channels[Channel];
ChannelInternal->NmIndicationMask |= COMM_NM_INDICATION_NETWORK_MODE;
ChannelInternal->internalRequest = TRUE;
}
/** @req COMM391 */
void ComM_Nm_PrepareBusSleepMode( NetworkHandleType Channel ){
COMM_VALIDATE_INIT_NORV(COMM_SERVICEID_NM_PREPAREBUSSLEEPMODE);
COMM_VALIDATE_CHANNEL_NORV(Channel, COMM_SERVICEID_NM_PREPAREBUSSLEEPMODE);
ComM_Internal_ChannelType* ChannelInternal = &ComM_Internal.Channels[Channel];
ChannelInternal->NmIndicationMask |= COMM_NM_INDICATION_PREPARE_BUS_SLEEP;
ChannelInternal->internalRequest = TRUE;
}
/** @req COMM392 */
void ComM_Nm_BusSleepMode( NetworkHandleType Channel ){
COMM_VALIDATE_INIT_NORV(COMM_SERVICEID_NM_BUSSLEEPMODE);
COMM_VALIDATE_CHANNEL_NORV(Channel, COMM_SERVICEID_NM_BUSSLEEPMODE);
ComM_Internal_ChannelType* ChannelInternal = &ComM_Internal.Channels[Channel];
ChannelInternal->NmIndicationMask |= COMM_NM_INDICATION_BUS_SLEEP;
ChannelInternal->internalRequest = TRUE;
}
/** @req COMM792 */
void ComM_Nm_RestartIndication( NetworkHandleType Channel ){
COMM_VALIDATE_INIT_NORV(COMM_SERVICEID_NM_RESTARTINDICATION);
COMM_VALIDATE_CHANNEL_NORV(Channel, COMM_SERVICEID_NM_RESTARTINDICATION);
ComM_Internal_ChannelType* ChannelInternal = &ComM_Internal.Channels[Channel];
ChannelInternal->NmIndicationMask |= COMM_NM_INDICATION_RESTART;
ChannelInternal->internalRequest = TRUE;
}
// Diagnostic Communication Manager Callbacks
// ------------------------------------------
void ComM_DCM_ActiveDiagnostic(NetworkHandleType Channel){
COMM_VALIDATE_INIT_NORV(COMM_SERVICEID_DCM_ACTIVEDIAGNOSTIC);
COMM_VALIDATE_CHANNEL_NORV(Channel, COMM_SERVICEID_DCM_ACTIVEDIAGNOSTIC);
ComM_Internal.Channels[Channel].DCM_Requested = TRUE;
ComM_Internal.Channels[Channel].internalRequest = TRUE;/** @req COMM866 */
}
void ComM_DCM_InactiveDiagnostic(NetworkHandleType Channel){
COMM_VALIDATE_INIT_NORV(COMM_SERVICEID_DCM_INACTIVEDIAGNOSTIC);
COMM_VALIDATE_CHANNEL_NORV(Channel, COMM_SERVICEID_DCM_INACTIVEDIAGNOSTIC);
ComM_Internal.Channels[Channel].DCM_Requested = FALSE;
ComM_Internal.Channels[Channel].internalRequest = TRUE;
}
// Bus State Manager Callbacks
// ---------------------------
/* @req COMM675 */
void ComM_BusSM_ModeIndication( NetworkHandleType Channel, ComM_ModeType *Mode ){
/* !req COMM288: Should release network on entering NO_COMMUNICATION when Nm variant is FULL.
* Seems strange since COMM133 says it should be released when entering ready sleep. */
COMM_VALIDATE_INIT_NORV(COMM_SERVICEID_BUSSM_MODEINDICATION);
COMM_VALIDATE_CHANNEL_NORV(Channel, COMM_SERVICEID_BUSSM_MODEINDICATION);
ComM_ModeType ComMode;
ComMode = *Mode;
ComM_Internal_ChannelType* ChannelInternal = &ComM_Internal.Channels[Channel];
const ComM_ChannelType* ChannelConf = &ComM_ConfigPtr->Channels[Channel];
boolean busOffNotification;
boolean busOffRecoveryNotification;
boolean validIndication;
SchM_Enter_ComM_EA_0();
/* Mode indication must 1.match the previously requested mode Or 2. indications from <bus>SM
* 1. If it is not then it's an indication for an obsolete request and it is ignored.
* 2. Bus off
* a. Silent communication can be indicated to ComM when bus off is detected by <bus>SM
* b. FrSM reporting COMM_NO_COMMUNICATION due to
* i. Network errors - POC state halt or freeze reached because of no sync or cold start nodes
* ii. ComM_BusSM_ModeIndication(COMM_NO_COMMUNICATION) is called in FrSM_RequestComMode(COMM_NO_COMMUNICATION) context and requestPending will not be set to TRUE in this case
*
* Bus off recovery
* a. full communication is indicated when <bus>SM recovers from bus off
* b. FrSM reporting COMM_FULL_COMMUNICATION due to recovery from POC states halt or freeze (when previously COMM_FULL_COMMUNICATION was requested)
*/
busOffNotification = ((ChannelConf->BusType == COMM_BUS_TYPE_CAN) && (ChannelInternal->requestPending == FALSE) &&(ComMode == COMM_SILENT_COMMUNICATION));
busOffNotification = (busOffNotification == TRUE) || ((ChannelConf->BusType == COMM_BUS_TYPE_FR) && (ChannelInternal->requestPending == FALSE) &&(ComMode == COMM_NO_COMMUNICATION));
busOffRecoveryNotification = ((ChannelConf->BusType == COMM_BUS_TYPE_CAN) && (ChannelInternal->requestPending == FALSE) &&(ComMode == COMM_FULL_COMMUNICATION));
busOffRecoveryNotification = (busOffRecoveryNotification == TRUE) || ((ChannelConf->BusType == COMM_BUS_TYPE_FR) && (ChannelInternal->requestPending == FALSE) &&(ComMode == COMM_FULL_COMMUNICATION));
//Expect indication for the latest mode requests
validIndication = ((ChannelInternal->requestPending == TRUE ) && (ChannelInternal->lastRequestedMode == ComMode));
if ((validIndication == TRUE) || ( busOffNotification == TRUE) || (busOffRecoveryNotification == TRUE)) {
ComM_ModeType existingMode;
existingMode = ChannelInternal->Mode;
ChannelInternal->Mode = ComMode;
#if defined(USE_BSWM) || defined(USE_DCM) || defined(USE_RTE)
/* !req COMM472 *//* Should report to users */
if( existingMode != ComMode) {
#if defined(USE_BSWM)
BswM_ComM_CurrentMode(Channel, ComMode); /* @req COMM976 */
#endif
#if defined(USE_RTE)
ComM_Rte_ModeChangeIndication(Channel);
#endif
#if defined(USE_DCM)
/* @req COMM266 */
/* !req COMM693 */
switch(ComMode) {
case COMM_NO_COMMUNICATION:
Dcm_ComM_NoComModeEntered(Channel);
break;
case COMM_SILENT_COMMUNICATION:
Dcm_ComM_SilentComModeEntered(Channel);
break;
case COMM_FULL_COMMUNICATION:
Dcm_ComM_FullComModeEntered(Channel);
break;
default:
break;
}
#endif
}
#else
(void)existingMode;/* To avoid PC lint error */
#endif
ChannelInternal->requestPending = FALSE;
switch(ComMode)
{
case COMM_NO_COMMUNICATION:
ChannelInternal->SubMode = COMM_NO_COM_NO_PENDING_REQUEST;/** @req COMM898 */
break;
case COMM_SILENT_COMMUNICATION:
ChannelInternal->SubMode = COMM_SILENT_COM;
break;
case COMM_FULL_COMMUNICATION:
ChannelInternal->SubMode = COMM_FULL_COM_NETWORK_REQUESTED;/** @req COMM899 *//** @req COMM883 */
/* IMPROVMENT: What to do if return error */
(void)ComM_Internal_NotifyNm(ChannelConf, busOffRecoveryNotification);
break;
default:
/* Do Nothing */
break;
}
}
if ((busOffRecoveryNotification == TRUE) &&
(((ChannelInternal->NmIndicationMask & COMM_NM_INDICATION_BUS_SLEEP) == COMM_NM_INDICATION_BUS_SLEEP) ||
((ChannelInternal->NmIndicationMask & COMM_NM_INDICATION_PREPARE_BUS_SLEEP)==COMM_NM_INDICATION_PREPARE_BUS_SLEEP))) {
/* If bus off recovery time was too long and underlying CanNm has reported bus sleep mode or prepare bus sleep mode,
* then there is a constant attempt by ComM to request COMM_SILENT_COMMUNICATION or COMM_NO_COMMUNICATION respectively.
* But CanSM would reject any further mode requests when bus off is active.
* So here we clear any such pending request for transitions when CanSM has recovered from bus off.
*/
resetInternalStateRequests(ChannelInternal);
}
SchM_Exit_ComM_EA_0();
/*lint -e818 Declaring Mode as const ComM_ModeType* will cause deviation in ASR API prototype */
}
static void resetInternalStateRequests (ComM_Internal_ChannelType* channelInternal) {
channelInternal->NmIndicationMask &= ~(COMM_NM_INDICATION_RESTART);
channelInternal->NmIndicationMask &= ~(COMM_NM_INDICATION_NETWORK_MODE);
channelInternal->NmIndicationMask &= ~(COMM_NM_INDICATION_PREPARE_BUS_SLEEP);
channelInternal->NmIndicationMask &= ~(COMM_NM_INDICATION_BUS_SLEEP);
channelInternal->internalRequest = FALSE;
}
// Scheduled main function
// -----------------------
// Prototype right here because this function should not be exposed
void ComM_MainFunction(NetworkHandleType Channel);
/** @req COMM429 */
void ComM_MainFunction(NetworkHandleType Channel){
const ComM_ChannelType* ChannelConf;
ComM_Internal_ChannelType* ChannelInternal;
Std_ReturnType status;
status = E_OK;
ChannelConf = &ComM_ConfigPtr->Channels[Channel];
ChannelInternal = &ComM_Internal.Channels[Channel];
/* Timer updates */
if (ChannelConf->NmVariant == COMM_NM_VARIANT_NONE) {
ComM_Internal_TickFullComMinTime(ChannelConf, ChannelInternal);
} else if (ChannelConf->NmVariant == COMM_NM_VARIANT_LIGHT) {
ComM_Internal_TickFullComMinTime(ChannelConf, ChannelInternal);
ComM_Internal_TickLightTime(ChannelConf, ChannelInternal);
} else {
/* Do nothing */
}
if (ChannelInternal->internalRequest == TRUE){
/* This condition is to cover internal state changes in ComM */
status = ComM_Internal_UpdateChannelState(ChannelConf, FALSE);
}
#if (COMM_PNC_SUPPORT == STD_ON)
/** @req ComM978 */
/** @req ComM979 */
/** @req ComM953 */
SchM_Enter_ComM_EA_0(); /* Disable interrupts (Required for no new newEIRARxSignal) */
ComM_PncStateTrans_ThisCycle = FALSE;
if(TRUE == ComM_ConfigPtr->ComMPncConfig->ComMPncEnabled) {
ComM_Internal_TickPncPrepareSleepTime(ChannelConf); /* Tick Prepare sleep timer */
/** @req ComM987 */
ComM_Internal_ProcessPNReqMode(Channel); /* User requesting PN */
#if (COMM_PNC_GATEWAY_ENABLED == STD_ON)
if (TRUE == ChannelInternal->newERARxSignal) {
ComM_Internal_ERARxSignalUpdate(Channel); /* new ERA received */
}
ComM_Internal_Monitor_GwPassiveChnl(); /*Monitor Passive Gateway channels when PNC in PNC_REQUESTED state */
#endif
if (TRUE == ComM_Internal.newEIRARxSignal) {
ComM_Internal_EIRARxSignalUpdate(); /* new EIRA received */
}
if (ComM_PncStateTrans_ThisCycle != TRUE) { /* To avoid multiple transition in one mainf function */
ComM_Internal_Monitor_RdySlpToPrpSlpTrns(); /* Monitor ready sleep to prepare sleep transitions*/
}
}
SchM_Exit_ComM_EA_0(); /* Enable interrupts */
#endif
if (ChannelInternal->userOrPncReqPending == TRUE) {
if (ChannelInternal->internalRequest == TRUE){
/* If any previous internal request which is still not accepted by lower modules clear them as
* we are now going to make a new request. User or PNC request is considered with higher priority */
resetInternalStateRequests(ChannelInternal);
}
/* New user requests or any pending user requests due to ComM_PreventWakeUp() inhibition is handled here */
/* @req ComM840 */
/* This condition is to cover user or pnc state changes in ComM */
status = ComM_Internal_UpdateChannelState(ChannelConf, TRUE);
}
(void) status; /* status used for debugging */
}
void ComM_CommunicationAllowed( NetworkHandleType Channel, boolean Allowed) {
COMM_VALIDATE_INIT_NORV(COMM_SERVICEID_COMMUNICATIONALLOWED);
COMM_VALIDATE_CHANNEL_NORV(Channel, COMM_SERVICEID_COMMUNICATIONALLOWED);
ComM_Internal_ChannelType* ChannelInternal = &ComM_Internal.Channels[Channel];
ChannelInternal->CommunicationAllowed = Allowed; /** @req COMM885 */
}
|
2301_81045437/classic-platform
|
communication/ComM/src/ComM.c
|
C
|
unknown
| 99,082
|
/*-------------------------------- 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 -----------------------------*/
/** @fileSafetyClassification ASIL **/
#include "ComM.h"
#include "ComM_Internal.h"
#include "ComM_EcuM.h"
// ECU State Manager Callbacks
// As it is called during startup, it is safety classified.
// ---------------------------
/* @req COMM275 */
void ComM_EcuM_WakeUpIndication( NetworkHandleType Channel ){
/* @req COMM814 */
/* Validates parameters / status, and if it fails will call DET and then immediately leave the function with the specified return code */
/* This is not inline with Table 8, ISO26262-6:2011, Req 1a and 1h */
COMM_VALIDATE_INIT_NORV(COMM_SERVICEID_ECUM_WAKEUPINDICATION);
COMM_VALIDATE_CHANNEL_NORV(Channel, COMM_SERVICEID_ECUM_WAKEUPINDICATION);
if ((ComM_Internal.Channels[Channel].Mode == COMM_NO_COMMUNICATION) ||
((ComM_Internal.Channels[Channel].SubMode == COMM_SILENT_COM) && /* during silent communication to no communication transition*/
(ComM_Internal.Channels[Channel].lastRequestedMode == COMM_NO_COMMUNICATION) && (ComM_Internal.Channels[Channel].requestPending == TRUE))){ /* wake up arrival during a boundary condition where ComM unsync with SM */
ComM_Internal.Channels[Channel].EcuMWkUpIndication = TRUE;
ComM_Internal.Channels[Channel].internalRequest = TRUE;
}
}
|
2301_81045437/classic-platform
|
communication/ComM/src/ComM_ASIL.c
|
C
|
unknown
| 2,026
|
/*-------------------------------- 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 COMM_MEMMAP_ERROR
#ifdef COMM_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 COMM_MEMMAP_ERROR
#undef COMM_START_SEC_VAR_INIT_UNSPECIFIED
#endif
#ifdef COMM_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 COMM_MEMMAP_ERROR
#undef COMM_STOP_SEC_VAR_INIT_UNSPECIFIED
#endif
#ifdef COMM_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 COMM_MEMMAP_ERROR
#undef COMM_START_SEC_VAR_CLEARED_UNSPECIFIED
#endif
#ifdef COMM_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 COMM_MEMMAP_ERROR
#undef COMM_STOP_SEC_VAR_CLEARED_UNSPECIFIED
#endif
#ifdef COMM_MEMMAP_ERROR
#error "BswM_BswMemMap.h error, section not mapped"
#endif
|
2301_81045437/classic-platform
|
communication/ComM/src/ComM_BswMemMap.h
|
C
|
unknown
| 2,176
|
/*-------------------------------- 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 COMM_INTERNAL_H
#define COMM_INTERNAL_H
#include "ComM_Types.h"
#if (COMM_DEV_ERROR_DETECT == STD_ON)
#include "Det.h"
#endif
#define COMM_PNC_MAX_NUM 48u
/*lint -emacro(904,COMM_VALIDATE_PARAMETER_NORV,COMM_VALIDATE_INIT_NORV,COMM_VALIDATE_INIT,COMM_VALIDATE_PARAMETER)
* ARGUMENT_CHECK Macros used for checking arguments before performing any functionality [MISRA 2004 Rule 14.7, required] */
/** @req COMM612 @req COMM511 @req COMM512 @req COMM270 */
#if (COMM_DEV_ERROR_DETECT == STD_ON)
#define COMM_DET_REPORTERROR(serviceId, errorId) \
(void)Det_ReportError(COMM_MODULE_ID, 0, serviceId, errorId)
#define COMM_VALIDATE(expression, serviceId, errorId, ret) \
if (!(expression)) { \
COMM_DET_REPORTERROR(serviceId, errorId); \
return ret; \
}
#define COMM_VALIDATE_NORV(expression, serviceId, errorId) \
if (!(expression)) { \
COMM_DET_REPORTERROR(serviceId, errorId); \
return; \
}
#else
#define COMM_DET_REPORTERROR(...)
#define COMM_VALIDATE(...)
#define COMM_VALIDATE_NORV(...)
#endif
#define COMM_VALIDATE_INIT(serviceID) \
COMM_VALIDATE((ComM_Internal.InitStatus == COMM_INIT), serviceID, COMM_E_NOT_INITED, COMM_E_UNINIT) /** @req COMM234 */ /** @req COMM858 */
#define COMM_VALIDATE_INIT_NORV(serviceID) \
COMM_VALIDATE_NORV((ComM_Internal.InitStatus == COMM_INIT), serviceID, COMM_E_NOT_INITED)
#define COMM_VALIDATE_PARAMETER(expression, serviceID) \
COMM_VALIDATE(expression, serviceID, COMM_E_WRONG_PARAMETERS, E_NOT_OK)
#define COMM_VALIDATE_PARAMETER_NORV(expression, serviceID) \
COMM_VALIDATE_NORV(expression, serviceID, COMM_E_WRONG_PARAMETERS) /** @req COMM234 */
#define COMM_VALIDATE_CHANNEL(channel, serviceID) \
COMM_VALIDATE_PARAMETER( (channel < COMM_CHANNEL_COUNT), serviceID)
#define COMM_VALIDATE_CHANNEL_NORV(channel, serviceID) \
COMM_VALIDATE_PARAMETER_NORV( (channel < COMM_CHANNEL_COUNT), serviceID)
#define COMM_VALIDATE_USER(user, serviceID) \
COMM_VALIDATE_PARAMETER( (user < COMM_USER_COUNT), serviceID )
typedef enum {
COMM_SUBMODE_NETWORK_REQUESTED,
COMM_SUBMODE_READY_SLEEP,
COMM_SUBMODE_NONE
} ComM_Internal_SubModeType;
typedef enum {
TRIGGER_SEND_PNC_VAL_0,
TRIGGER_SEND_PNC_VAL_1,
INVALID_TRIGGER_SEND
}ComM_Internal_TriggerSendType;
typedef struct {
ComM_ModeType RequestedMode;
ComM_ModeType CurrentMode;
} ComM_Internal_UserType;
#if (COMM_PNC_SUPPORT == STD_ON)
#define MAX_PNC_NUM_BYTES 8u
typedef union {
uint64 data;
uint8 bytes[MAX_PNC_NUM_BYTES];
}ComM_Internal_RAType; /* Same type for EIRA and ERA. */
typedef struct {
uint32 prepareSleepTimer;
ComM_PncStateType pncState;
ComM_PncModeType pncSubState;
ComM_ModeType pncRequestedState;
boolean pncNewUserRequest;
}ComM_PncInternalType;
#endif /* (COMM_PNC_SUPPORT == STD_ON) */
typedef struct {
ComM_ModeType Mode;
ComM_StateType SubMode;
uint64 UserRequestMask;
ComM_InhibitionStatusType InhibitionStatus;
uint32 FullComMinDurationTimeLeft;
uint32 LightTimeoutTimeLeft;
ComM_ModeType userOrPncReqMode;
ComM_ModeType lastRequestedMode;
uint8 NmIndicationMask;
boolean CommunicationAllowed;
boolean DCM_Requested;
boolean requestPending;
boolean EcuMWkUpIndication;
boolean userOrPncReqPending;
boolean internalRequest;
boolean nwStartIndication;
boolean fullComMinDurationTimerStopped;
boolean nmLightTimeoutTimerStopped;
#if (COMM_PNC_SUPPORT == STD_ON)
ComM_Internal_RAType TxComSignal;
#if (COMM_PNC_GATEWAY_ENABLED == STD_ON)
ComM_Internal_RAType pnERA;
boolean newERARxSignal;
#endif
#endif
} ComM_Internal_ChannelType;
typedef struct {
ComM_InitStatusType InitStatus;
ComM_Internal_ChannelType Channels[COMM_CHANNEL_COUNT];
ComM_Internal_UserType Users[COMM_USER_COUNT];
boolean NoCommunication;
uint16 InhibitCounter; /**< @req COMM138 @req COMM141 */
#if (COMM_PNC_SUPPORT == STD_ON)
ComM_PncInternalType pncRunTimeData[COMM_PNC_NUM];
ComM_Internal_RAType pnEIRA;
boolean newEIRARxSignal;
#endif
} ComM_InternalType;
#define COMM_NM_INDICATION_NONE (uint8)(0u)
#define COMM_NM_INDICATION_NETWORK_MODE (uint8)(1u)
#define COMM_NM_INDICATION_PREPARE_BUS_SLEEP (uint8)(1u << 1)
#define COMM_NM_INDICATION_BUS_SLEEP (uint8)(1u << 2)
#define COMM_NM_INDICATION_RESTART (uint8)(1u << 3)
/*lint -esym(9003,ComM_Internal) FALSE_POSITIVE ComM_Internal cannot be defined at block scope because it is used in ComM.c and ComM_ASIL.c */
extern ComM_InternalType ComM_Internal;
#endif /* COMM_INTERNAL_H */
|
2301_81045437/classic-platform
|
communication/ComM/src/ComM_Internal.h
|
C
|
unknown
| 6,000
|
# DoIP
obj-$(USE_DOIP) += DoIP_Cfg.o
obj-$(USE_DOIP) += DoIP.o
ifeq ($(filter DoIP_Callout_Stubs.o,$(obj-y)),)
obj-$(USE_DOIP) += DoIP_Callout_Stubs.o
endif
inc-$(USE_DOIP) += $(ROOTDIR)/communication/DoIP/inc
vpath-$(USE_DOIP) += $(ROOTDIR)/communication/DoIP/src
|
2301_81045437/classic-platform
|
communication/DoIP/DoIP.mod.mk
|
Makefile
|
unknown
| 279
|
/*-------------------------------- 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 DOIP_H_
#define DOIP_H_
#include "DoIP_Types.h"
#include "SoAd_Types.h"
#define DOIP_AR_RELEASE_MAJOR_VERSION 4u
#define DOIP_AR_RELEASE_MINOR_VERSION 2u
#define DOIP_AR_RELEASE_REVISION_VERSION 2u
#define DOIP_VENDOR_ID 60u
#define DOIP_MODULE_ID (173u)
#define DOIP_AR_MAJOR_VERSION DOIP_AR_RELEASE_MAJOR_VERSION
#define DOIP_AR_MINOR_VERSION DOIP_AR_RELEASE_MINOR_VERSION
#define DOIP_AR_PATCH_VERSION DOIP_AR_RELEASE_REVISION_VERSION
#define DOIP_SW_MAJOR_VERSION 1u
#define DOIP_SW_MINOR_VERSION 0u
#define DOIP_SW_PATCH_VERSION 0u
/** @name Service id's */
#define DOIP_TP_TRANSMIT_SERVICE_ID 0x03u /* In Autosar 4.3.0 spec, it is menioned as 49 which is repeated */
#define DOIP_TP_CANCEL_TRANSMIT_SERVICE_ID 0x04u /* In Autosar 4.3.0 spec, it is menioned as 4A which is repeated */
#define DOIP_TP_CANCEL_RECEIVE_SERVICE_ID 0x05u
#define DOIP_IF_TRANSMIT_SERVICE_ID 0x49u
#define DOIP_IF_CANCEL_TRANSMIT_SERVICE_ID 0x4Au
#define DOIP_INIT_SERVICE_ID 0x01u
#define DOIP_GET_VERSION_INFO_SERVICE_ID 0x00u
#define DOIP_SOAD_TP_COPY_TX_DATA_SERVICE_ID 0x43u
#define DOIP_SOAD_TP_TX_CONFIRMATION_SERVICE_ID 0x48u
#define DOIP_SOAD_TP_COPY_RX_DATA_SERVICE_ID 0x44u
#define DOIP_SOAD_TP_START_OF_RECEPTION_SERVICE_ID 0x46u
#define DOIP_SOAD_TP_RX_INDICATION_SERVICE_ID 0x45u
#define DOIP_SOAD_IF_RX_INDICATION_SERVICE_ID 0x42u
#define DOIP_SOAD_IF_TX_CONFIRMATION_SERVICE_ID 0x40u
#define DOIP_SO_CON_MODE_CHG_SERVICE_ID 0x0Bu
#define DOIP_LOCAL_IP_ADDR_ASSIGN_CHG_SERVICE_ID 0x0Cu
#define DOIP_ACTIVATION_LINE_SW_ACTIVE_SERVICE_ID 0x0Fu
#define DOIP_ACTIVATION_LINE_SW_INACTIVE_SERVICE_ID 0x0Eu
#define DOIP_MAIN_FUNCTION_SERVICE_ID 0x02u
/* Local function IDs */
#define DOIP_HANDLE_VEHICLE_ID_REQ_ID 0x50u
#define DOIP_SEND_VEHICLE_ANNOUNCE_REQ_ID 0x51u
#define DOIP_HANDLE_ENTITY_STATUS_REQ_ID 0x52u
#define DOIP_CREATE_AND_SEND_ALIVE_CHECK_ID 0x53u
#define DOIP_ROUTING_ACTIVATION_REQ_ID 0x54u
#define DOIP_HANDLE_DIAG_MSG_ID 0x55u
#define DOIP_CREATE_AND_SEND_NACK_ID 0x56u
#define DOIP_CREATE_AND_SEND_D_ACK_ID 0x57u
#define DOIP_CREATE_AND_SEND_D_NACK_ID 0x58u
#define DOIP_HANDLE_POWER_MODE_REQ_ID 0x59u
#define DOIP_HANDLE_ALIVECHECK_TIMEOUT_ID 0x5Au
#define DOIP_HANDLE_ALIVECHECK_RESP_ID 0x5Bu
#define DOIP_HANDLE_TIMEOUT_ID 0x5Cu
#define DOIP_GET_EID_ID 0x5Du
/* Development errors as in DoIP 7.6 Error classification */
/** @req SWS_DoIP_00148 */
#define DOIP_E_UNINIT 0x01u
#define DOIP_E_PARAM_POINTER 0x02u
#define DOIP_E_INVALID_PDU_SDU_ID 0x03u
#define DOIP_E_INVALID_PARAMETER 0x04u
#define DOIP_E_INIT_FAILED 0x05u
/* Development errors - Runtime */
/** @req SWS_DoIP_00282 */
#define DOIP_E_UNEXPECTED_EXECUTION 0x06u
#define DOIP_E_BUFFER_BUSY 0x07u
#define DOIP_E_INVALID_CH_INDEX 0x08u
#define DOIP_E_IF_TRANSMIT_ERROR 0x09u
#define DOIP_E_TP_TRANSMIT_ERROR 0x0Au
#define DOIP_E_INVALID_SOCKET_STATE 0x0Bu
/** @req SWS_DoIP_00025*/
typedef struct{
const DoIP_ChannelType *DoIP_Channel;
const DoIP_TcpType *DoIP_TcpMsg;
const DoIP_UdpType *DoIP_UdpMsg;
const DoIP_TargetAddrType *const DoIP_TargetAddress;
const DoIP_RoutActType *const DoIP_RoutingActivation;
const DoIP_TesterType *const DoIP_Tester;
}DoIP_ConfigType;
extern const DoIP_ConfigType DoIP_Config;
/* @req SWS_DoIP_00022 */
Std_ReturnType DoIP_TpTransmit(PduIdType DoIPPduRTxId, const PduInfoType* DoIPPduRTxInfoPtr);
/* @req SWS_DoIP_00023 */
Std_ReturnType DoIP_TpCancelTransmit(PduIdType DoIPPduRTxId);
/* @req SWS_DoIP_00277 */
Std_ReturnType DoIP_IfTransmit(PduIdType id, const PduInfoType* info);
/* @req SWS_DoIP_00278 */
Std_ReturnType DoIP_IfCancelTransmit(PduIdType id);
/* @req SWS_DoIP_00026 */
void DoIP_Init(const DoIP_ConfigType* DoIPConfigPtr);
/* @req SWS_DoIP_00027 */
void DoIP_GetVersionInfo(Std_VersionInfoType* versioninfo);
/* @req SWS_DoIP_00031 */
BufReq_ReturnType DoIP_SoAdTpCopyTxData( PduIdType id, const PduInfoType* info, RetryInfoType* retry, PduLengthType* availableDataPtr );
/* @req SWS_DoIP_00032 */
void DoIP_SoAdTpTxConfirmation(PduIdType id, Std_ReturnType result);
/* @req SWS_DoIP_00033 */
BufReq_ReturnType DoIP_SoAdTpCopyRxData(PduIdType id,const PduInfoType* info,PduLengthType* bufferSizePtr);
/* @req SWS_DoIP_00037 */
BufReq_ReturnType DoIP_SoAdTpStartOfReception(PduIdType id, const PduInfoType* info, PduLengthType TpSduLength, PduLengthType* bufferSizePtr);
/* @req SWS_DoIP_00038 */
void DoIP_SoAdTpRxIndication(PduIdType id, Std_ReturnType result);
/* @req SWS_DoIP_00244 */
void DoIP_SoAdIfRxIndication(PduIdType RxPduId,const PduInfoType* PduInfoPtr);
/* @req SWS_DoIP_00245 */
void DoIP_SoAdIfTxConfirmation(PduIdType TxPduId);
/* @req SWS_DoIP_0039 */
void DoIP_SoConModeChg(SoAd_SoConIdType SoConId, SoAd_SoConModeType Mode);
/* @req SWS_DoIP_00040 */
void DoIP_LocalIpAddrAssignmentChg(SoAd_SoConIdType SoConId, TcpIp_IpAddrStateType State);
/* @req SWS_DoIP_00251 */
void DoIP_ActivationLineSwitchActive(void);
/* @req SWS_DoIP_91001 */
void DoIP_ActivationLineSwitchInactive(void);
/* @req SWS_DoIP_00041 */
void DoIP_MainFunction (void);
/* DoIP call-outs */
Std_ReturnType DoIP_Arc_GetVin(uint8* Data, uint8 noOfBytes);
void DoIP_Arc_TcpConnectionNotification(SoAd_SoConIdType id);
#endif /* DOIP_H_ */
|
2301_81045437/classic-platform
|
communication/DoIP/inc/DoIP.h
|
C
|
unknown
| 6,939
|
/*-------------------------------- 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 -----------------------------*/
|
2301_81045437/classic-platform
|
communication/DoIP/inc/DoIP_Cbk.h
|
C
|
unknown
| 754
|
/*-------------------------------- 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 DOIP_TYPES_H_
#define DOIP_TYPES_H_
#include "Std_Types.h"
#include "ComStack_Types.h"
#define DOIP_E_PENDING 0x10u /** @req SWS_DoIP_00272*/ /** @req SWS_DoIP_00273*/ //done
typedef enum {
DOIP_TPPDU,
DOIP_IFPDU
} DoIP_PduType;
typedef enum {
DOIP_POWER_STATE_NOT_READY,
DOIP_POWER_STATE_READY,
} DoIP_PowerStateType;
typedef Std_ReturnType (*DoIP_RoutActConfFuncType)(boolean* confirmed, uint8* confReqData, uint8* confResData);
typedef Std_ReturnType (*DoIP_RoutActAuthFuncType)(boolean* authenticated, uint8* authReqData, uint8* authResData);
typedef uint32 DoIPPayloadType;
typedef struct{
DoIP_RoutActConfFuncType DoIP_RoutActAuthFunc;
uint8 DoIP_RoutActAuthReqLen;
uint8 DoIP_RoutActAuthResLen;
}DoIP_RoutActAuthType;
typedef struct{
DoIP_RoutActAuthFuncType DoIP_RoutActConfFunc;
uint8 DoIP_RoutActConfReqLen;
uint8 DoIP_RoutActConfResLen;
}DoIP_RoutActConfType;
typedef struct {
const uint16 *DoIP_TargetRef;
const DoIP_RoutActAuthType *DoIP_RoutActAuthRef;
const DoIP_RoutActConfType *DoIP_RoutActConfRef;
uint8 DoIP_chnlTARef_Size;
uint8 DoIP_RoutActNum;
}DoIP_RoutActType;
typedef struct {
const DoIP_RoutActType **DoIP_RoutActRef;
uint32 DoIP_NumByteDiagAckNack;
uint16 DoIP_TesterSA;
uint16 DoIp_RoutRefSize;
}DoIP_TesterType;
typedef struct{
uint16 DoIP_TargetAddrValue;
}DoIP_TargetAddrType;
typedef struct{
PduIdType DoIP_TxPduRef;
DoIP_PduType DoIP_TxPduType;
}DoIP_PduTransmitType;
typedef struct{
PduIdType DoIP_RxPduRef;
}DoIP_PduReceiveType;
typedef struct{
const DoIP_TesterType *DoIP_ChannelSARef;
const DoIP_TargetAddrType *DoIP_ChannelTARef;
const DoIP_PduReceiveType *DoIP_PduReceiveRef;
const DoIP_PduTransmitType *DoIP_PduTransmitRef;
PduIdType DoIP_UpperLayerRxPduId;
PduIdType DoIP_RxPduId;
PduIdType DoIP_UpperLayerTxPduId;
PduIdType DoIP_TxPduId;
}DoIP_ChannelType;
typedef struct{
PduIdType DoIP_TcpSoADRxPduRef;
PduIdType DoIP_TcpRxPduRef;
PduIdType DoIP_TcpSoADTxPduRef;
PduIdType DoIP_TcpTxPduRef;
}DoIP_TcpType;
typedef struct{
PduIdType DoIP_UdpSoADRxPduRef;
PduIdType DoIP_UdpRxPduRef;
PduIdType DoIP_UdpSoADTxPduRef;
PduIdType DoIP_UdpTxPduRef;
}DoIP_UdpType;
#endif /* DOIP_TYPES_H_ */
|
2301_81045437/classic-platform
|
communication/DoIP/inc/DoIP_Types.h
|
C
|
unknown
| 3,111
|
/*-------------------------------- 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.2.2 */
#include "DoIP.h"
#include "DoIP_Cfg.h"
#include "DoIP_Cbk.h"
#include "DoIP_Types.h"
#include "DoIP_Internal.h"
#include "DoIP_MemMap.h"
#if defined(USE_RTE)
#include "Rte_DoIP.h"
#endif
#if (DOIP_DEV_ERROR_DETECT == STD_ON)
#include "Det.h"
#endif
#include "SoAd.h"
#include "PduR_DoIP.h"
#include "SchM_DoIP.h"
#include <string.h>
//lint -emacro(904,VALIDATE) MISRA:OTHER:Readiability:[MISRA 2004 Rule 14.7, required]
//lint -emacro(904,VALIDATE_W_RV) MISRA:OTHER:Readiability:[MISRA 2004 Rule 14.7, required]
#if (DOIP_DEV_ERROR_DETECT == STD_ON)
#define VALIDATE(_exp, _api, _err ) \
if( !(_exp) ) {\
(void)Det_ReportError(DOIP_MODULE_ID, 0, _api, _err); \
return; \
}
#define VALIDATE_W_RV(_exp, _api, _err, _rv ) \
if( !(_exp) ) { \
(void)Det_ReportError(DOIP_MODULE_ID, 0, _api, _err); \
return (_rv); \
}
#define DOIP_DET_REPORTERROR(_api, _err) (void)Det_ReportError(DOIP_MODULE_ID, 0, _api, _err)
#else
#define VALIDATE(_exp, _api, _err ) \
if( !(_exp) ) {\
return; \
}
#define VALIDATE_W_RV(_exp, _api, _err, _rv ) \
if( !(_exp) ) { \
return (_rv); \
}
#define DOIP_DET_REPORTERROR(_api, _err)
#endif
/***** Macro - Definition *****/
/* Macro to get the payload length from the DoIP message */
/** @req SWS_DoIP_000010 */
#define GET_PL_LEN_FROM_DOIP_MSG_PTR(_rxBuf) (((DoIPPayloadType)_rxBuf[PL_LEN_INDEX] << SHIFT_BY_THREE_BYTES) | \
((DoIPPayloadType)_rxBuf[PL_LEN_INDEX+1u] << SHIFT_BY_TW0_BYTES) | \
((DoIPPayloadType)_rxBuf[PL_LEN_INDEX+2u] << SHIFT_BY_ONE_BYTE) | \
((DoIPPayloadType)_rxBuf[PL_LEN_INDEX+3u]))
/** @req SWS_DoIP_00007 */
#define GET_PL_TYPE_FROM_DOIP_MSG_PTR(_rxBuf) (((DoIPPayloadType)_rxBuf[PL_TYPE_INDEX] << SHIFT_BY_ONE_BYTE) | \
((DoIPPayloadType)_rxBuf[PL_TYPE_INDEX+1u]))
#define GET_SA_FROM_DOIP_MSG_PTR(_rxBuf) (((uint16)_rxBuf[SA_INDEX] << SHIFT_BY_ONE_BYTE) | \
((uint16)_rxBuf[SA_INDEX+1u]))
#define GET_TA_FROM_DOIP_MSG_PTR(_rxBuf) (((uint16)_rxBuf[TA_INDEX] << SHIFT_BY_ONE_BYTE) | \
((uint16)_rxBuf[TA_INDEX+1u]))
#define GET_ACT_TYPE_FROM_DOIP_MSG_PTR(_rxBuf) ((uint8)_rxBuf[ROUT_ACTIV_TYPE_INDEX])
/***** Local variables *****/
static DoIP_Internal_TcpConRxBufAdType DoIP_TcpConRxBufferAdmin;
static DoIP_Internal_TcpConAdminType DoIP_TcpConAdmin[DOIP_TCP_CON_NUM];
static DoIP_Internal_TcpQueueAdminType DoIP_TcpQueueAdmin[DOIP_TCP_CON_NUM];
static DoIP_Internal_UdpConAdminType DoIP_UdpConAdmin[DOIP_UDP_CON_NUM];
static DoIP_Internal_StatusType DoIP_Status = DOIP_UNINIT;
static uint32 DoIP_TcpRxRemainingBufferSize;
/** @req SWS_DoIP_00201 */
static DoIP_Internal_ActnLineStsType DoIP_ActivationLineStatus;
static const DoIP_ConfigType* DoIP_ConfigPtr = NULL;
static uint8 DoIP_Vin[PL_LEN_VID_VIN_REQ_RES];
static boolean DoIP_VinUpdated;
static uint8 DoIP_Eid[PL_LEN_VID_EID_REQ_RES];
static boolean DoIP_EidUpdated;
static boolean DoIP_PendingRoutActivFlag;
static uint16 DoIP_PendingRoutActivConIndex;
static uint16 DoIP_PendingRoutActivSa;
static uint16 DoIP_pendingRoutActivActType;
#if (DOIPTGRGIDSYNCCALLBACK_CONFIGURED == TRUE) && (DOIP_VIN_GID_MASTER == STD_ON)
static boolean DoIP_GidSyncDone = FALSE;
#endif
/***** Local function - Prototypes *****/
static void freeUdpTxBuffer(SoAd_SoConIdType conIndex);
static void freeUdpRxBuffer(SoAd_SoConIdType conIndex);
static void freeTcpTxBuffer(SoAd_SoConIdType conIndex);
static void freeTcpRxBuffer(void);
static void resetUdpConnection(SoAd_SoConIdType conIndex);
static void resetTcpConnection(SoAd_SoConIdType conIndex);
static Std_ReturnType getVin(uint8* bufferPtr);
static Std_ReturnType getEid(uint8* bufferPtr, SoAd_SoConIdType conIndex);
static void getGid(uint8* txBufferPtr, SoAd_SoConIdType conIndex);
static uint8 getChIndexFromTargetIndex(uint8 targetIndex);
static Std_ReturnType getConTypeConIndexFromSoConId(SoAd_SoConIdType SoConId, DoIP_Internal_ConType* conTypePtr, uint16* conIndexPtr);
static uint8 getNofCurrentlyUsedTcpSockets(void);
static void getFurtherActionRequired(uint8* txBufferPtr);
static boolean isSourceAddressKnown(uint16 sa, uint8 *testerIndex);
static boolean isRoutingTypeSupported(uint16 activationType, uint8 testerIndex, uint16* routActRefIndex);
#if 0
/* Routing and confirmation callbacks not supported */
static boolean isAuthenticationRequired(uint16 routActRefIndex);
static boolean isAuthenticated(uint16 routActRefIndex);
static boolean isConfirmationRequired(uint16 routActRefIndex);
static boolean isConfirmed(uint16 routActRefIndex);
#endif
static void registerSocket(SoAd_SoConIdType conIndex, uint16 sa, uint16 activationType);
static void closeSocket(DoIP_Internal_ConType conType, SoAd_SoConIdType conIndex, uint16 txPdu);
static void handleTimeout(SoAd_SoConIdType conIndex);
static void updateRemoteAddrAsBroadcast(SoAd_SoConIdType conIndex);
static void createAndSendNackIf(SoAd_SoConIdType conIndex, uint8 nackCode);
static void createAndSendNackTp(SoAd_SoConIdType conIndex, uint8 nackCode);
static void createAndSendDiagnosticAck(SoAd_SoConIdType conIndex, uint16 sa, uint16 ta);
static void createAndSendDiagnosticNack(SoAd_SoConIdType conIndex, uint16 sa, uint16 ta, uint8 nackCode);
static void createVehicleIdentificationResponse(uint8* txBuffer, SoAd_SoConIdType conIndex);
static void sendVehicleAnnouncement(SoAd_SoConIdType conIndex);
static void fillRoutingActivationResponseData(uint8 *txBuffer, uint16 sa, uint8 routingActivationResponseCode);
static void createAndSendAliveCheck(SoAd_SoConIdType conIndex);
static void startSingleSaAliveCheck(SoAd_SoConIdType conIndex);
static void startAllSocketsAliveCheck(void);
static DoIP_Internal_LookupResType lookupSaTa(SoAd_SoConIdType conIndex, uint16 sa, uint16 ta, uint8* targetIndex);
static DoIP_Internal_SockAssigResType socketHandle(SoAd_SoConIdType conIndex, uint16 activationType, uint16 sa, uint8* routingActivationResponseCode);
static void handleAliveCheckResp(SoAd_SoConIdType conIndex, const uint8* rxBuffer);
static void handleRoutingActivationReq(SoAd_SoConIdType conIndex, const uint8 *rxBuffer);
static void handleDiagnosticMessage(SoAd_SoConIdType conIndex, uint8 *rxBuffer);
static void handleVehicleIdentificationReq(SoAd_SoConIdType conIndex, const uint8 *rxBuffer, DoIP_Internal_VehReqType type);
static void handleEntityStatusReq(SoAd_SoConIdType conIndex,const uint8 *rxBuffer);
static void handlePowerModeCheckReq(SoAd_SoConIdType conIndex, const uint8 *rxBuffer);
static void handleTcpRx(SoAd_SoConIdType conIndex, uint8* rxBuffer);
static void handleUdpRx(SoAd_SoConIdType conIndex,const uint8* rxBuffer);
/***** Local function - Definition *****/
static void freeUdpTxBuffer(SoAd_SoConIdType conIndex) {
DoIP_UdpConAdmin[conIndex].txBufferState = BUFFER_IDLE;
}
static void freeUdpRxBuffer(SoAd_SoConIdType conIndex) {
DoIP_UdpConAdmin[conIndex].rxBufferStartIndex = UDP_RX_BUFFER_RESET_INDEX;
DoIP_UdpConAdmin[conIndex].rxBufferEndIndex = UDP_RX_BUFFER_RESET_INDEX;
DoIP_UdpConAdmin[conIndex].rxBufferPresent = FALSE;
DoIP_UdpConAdmin[conIndex].rxPduIdUnderProgress = INVALID_PDU_ID;
}
static void freeTcpTxBuffer(SoAd_SoConIdType conIndex) {
DoIP_TcpConAdmin[conIndex].txBufferState = BUFFER_IDLE;
DoIP_TcpConAdmin[conIndex].txBytesToTransmit = 0u;
DoIP_TcpConAdmin[conIndex].txBytesCopied = 0u;
DoIP_TcpConAdmin[conIndex].txBytesTransmitted = 0u;
DoIP_TcpConAdmin[conIndex].txPduIdUnderProgress = INVALID_PDU_ID;
}
static void freeTcpRxBuffer(void) {
DoIP_TcpConRxBufferAdmin.bufferState = BUFFER_IDLE;
DoIP_TcpConRxBufferAdmin.pduIdUnderProgress = INVALID_PDU_ID;
}
static void resetUdpConnection(SoAd_SoConIdType conIndex) {
DoIP_UdpConAdmin[conIndex].sockNr = INVALID_SOCKET_NUMBER;
DoIP_UdpConAdmin[conIndex].socketState = CONNECTION_INVALID;
DoIP_UdpConAdmin[conIndex].vehicleAnnounceTgr = FALSE;
DoIP_UdpConAdmin[conIndex].vehicleAnnounceInProgress = FALSE;
DoIP_UdpConAdmin[conIndex].vehicleAnnounceInitialTime = 0u;
DoIP_UdpConAdmin[conIndex].vehicleAnnounceTimeInterval = 0u;
DoIP_UdpConAdmin[conIndex].vehicleAnnounceRepetition = 0u;
DoIP_UdpConAdmin[conIndex].txBufferState = BUFFER_IDLE;
DoIP_UdpConAdmin[conIndex].rxBufferStartIndex = UDP_RX_BUFFER_RESET_INDEX;
DoIP_UdpConAdmin[conIndex].rxBufferEndIndex = UDP_RX_BUFFER_RESET_INDEX;
DoIP_UdpConAdmin[conIndex].rxBufferPresent = FALSE;
DoIP_UdpConAdmin[conIndex].rxPduIdUnderProgress = INVALID_PDU_ID;
}
static void resetTcpConnection(SoAd_SoConIdType conIndex) {
DoIP_TcpConAdmin[conIndex].sockNr = INVALID_SOCKET_NUMBER;
DoIP_TcpConAdmin[conIndex].socketState = CONNECTION_INVALID;
DoIP_TcpConAdmin[conIndex].sa = INVALID_SOURCE_ADDRESS;
DoIP_TcpConAdmin[conIndex].generalInactivityTimer = 0u;
DoIP_TcpConAdmin[conIndex].initialInactivityTimer = 0u;
DoIP_TcpConAdmin[conIndex].aliveCheckTimer = 0u;
DoIP_TcpConAdmin[conIndex].authenticated = FALSE;
DoIP_TcpConAdmin[conIndex].confirmed = FALSE;
DoIP_TcpConAdmin[conIndex].awaitingAliveCheckResponse = FALSE;
DoIP_TcpConAdmin[conIndex].closeSocketIndication = FALSE;
DoIP_TcpConAdmin[conIndex].uLMsgTxInProgress = FALSE;
DoIP_TcpConAdmin[conIndex].txBufferState = BUFFER_IDLE;
DoIP_TcpConAdmin[conIndex].txBytesToTransmit = 0u;
DoIP_TcpConAdmin[conIndex].txBytesCopied = 0u;
DoIP_TcpConAdmin[conIndex].txBytesTransmitted = 0u;
DoIP_TcpConAdmin[conIndex].txPduIdUnderProgress = INVALID_PDU_ID;
DoIP_TcpConAdmin[conIndex].channelIndex = INVALID_CHANNEL_INDEX;
DoIP_TcpQueueAdmin[conIndex].diagAckQueueActive = FALSE;
DoIP_TcpQueueAdmin[conIndex].tpTransmitQueueActive = FALSE;
}
static Std_ReturnType getVin(uint8* bufferPtr) {
Std_ReturnType retVal;
uint8 i;
/** @req SWS_DoIP_00070 */ /** @req SWS_DoIP_00072 */
/* Dcm_GetVin to be called from the DoIP_Arc_GetVin() */
retVal = DoIP_Arc_GetVin(bufferPtr, PL_LEN_VID_VIN_REQ_RES);
if (E_OK != retVal) {
for (i = 0u; i < PL_LEN_VID_VIN_REQ_RES; i++) {
bufferPtr[i] = DOIP_VIN_INVALIDITY_PATTERN;
}
}
return retVal;
}
static Std_ReturnType getEid(uint8* bufferPtr, SoAd_SoConIdType conIndex) {
Std_ReturnType retVal;
#if (DOIP_USE_MAC_ADD_FOR_ID == STD_ON)
PduIdType soadTxPduId;
SoAd_SoConIdType SoConId;
uint8 phyAddrPtr[PL_LEN_VID_EID_REQ_RES];
uint8 i;
soadTxPduId = DoIP_ConfigPtr->DoIP_TcpMsg[conIndex].DoIP_TcpSoADTxPduRef;
(void)SoAd_GetSoConId(soadTxPduId, &SoConId);
/** @req SWS_DoIP_00065 */ /** @req SWS_DoIP_00074 */
if (E_OK == SoAd_GetPhysAddr(SoConId, phyAddrPtr)) {
bufferPtr[0] = phyAddrPtr[0];
bufferPtr[1] = phyAddrPtr[1];
bufferPtr[2] = phyAddrPtr[2];
bufferPtr[3] = phyAddrPtr[3];
bufferPtr[4] = phyAddrPtr[4];
bufferPtr[5] = phyAddrPtr[5];
retVal = E_OK;
} else {
for (i = 0u; i < PL_LEN_VID_EID_REQ_RES; i++) {
bufferPtr[19u+i] = 0xEE;
}
DOIP_DET_REPORTERROR(DOIP_GET_EID_ID, DOIP_E_UNEXPECTED_EXECUTION);
retVal = E_NOT_OK;
}
#else
(void)conIndex;
/** @req SWS_DoIP_00075 */
#if (DOIP_EID_CONFIGURED == TRUE)
/*lint -e{572} MISRA:FALSE_POSITIVE:Inspite of keeping the define DOIP_EID with suffix uLL PC lint throws this warning Excessive shift value (precision 33 shifted right by 40):[MISRA 2004 Rule 12.8, required] */
/*lint -e{778} MISRA:FALSE_POSITIVE::False positive info - Constant expression evaluates to 0 in operation '>>' */
bufferPtr[0] = (uint8)(DOIP_EID >> SHIFT_BY_FIVE_BYTES);
bufferPtr[1] = (uint8)(DOIP_EID >> SHIFT_BY_FOUR_BYTES);
bufferPtr[2] = (uint8)(DOIP_EID >> SHIFT_BY_THREE_BYTES);
bufferPtr[3] = (uint8)(DOIP_EID >> SHIFT_BY_TW0_BYTES);
bufferPtr[4] = (uint8)(DOIP_EID >> SHIFT_BY_ONE_BYTE);
bufferPtr[5] = (uint8)(DOIP_EID);
retVal = E_OK;
#else
#error "EID is not configured"
#endif
#endif
return retVal;
}
static void getGid(uint8* bufferPtr, SoAd_SoConIdType conIndex) {
#if (DOIP_USE_EID_AS_GID == TRUE)
uint8 i;
/** @req SWS_DoIP_00077 */
if (E_OK != getEid(bufferPtr, conIndex)) {
for (i = 0u; i < PL_LEN_VID_EID_REQ_RES; i++) {
bufferPtr[25u+i] = 0xEE;
}
}
#else
(void)conIndex;
#if (DOIP_GID_CONFIGURED == TRUE)
/** @req SWS_DoIP_00078 */
/*lint -e{572} MISRA:FALSE_POSITIVE:Inspite of keeping the define DOIP_EID with suffix uLL PC lint throws this warning Excessive shift value (precision 33 shifted right by 40):[MISRA 2004 Rule 12.8, required] */
/*lint -e{778} MISRA:FALSE_POSITIVE::False positive info - Constant expression evaluates to 0 in operation '>>' */
bufferPtr[0] = (uint8)(DOIP_GID >> SHIFT_BY_FIVE_BYTES);
bufferPtr[1] = (uint8)(DOIP_GID >> SHIFT_BY_FOUR_BYTES);
bufferPtr[2] = (uint8)(DOIP_GID >> SHIFT_BY_THREE_BYTES);
bufferPtr[3] = (uint8)(DOIP_GID >> SHIFT_BY_TW0_BYTES);
bufferPtr[4] = (uint8)(DOIP_GID >> SHIFT_BY_ONE_BYTE);
bufferPtr[5] = (uint8)(DOIP_GID);
#else
uint8 i;
/** @req SWS_DoIP_00079 */ /** @req SWS_DoIP_00080 */
if (E_OK != DOIP_GETGIDCALLBACK_FUNCTION()) {
for (i = 0u; i < PL_LEN_GID; i++) {
/** @req SWS_DoIP_00081 */
bufferPtr[i] = DOIP_GID_INVALIDITY_PATTERN;
}
}
#endif
#endif
}
static uint8 getChIndexFromTargetIndex(uint8 targetIndex) {
uint8 chIndex;
uint8 retVal;
retVal = INVALID_CHANNEL_INDEX;
for (chIndex = 0u; chIndex < DOIP_CHANNEL_COUNT; chIndex++) {
if (DoIP_ConfigPtr->DoIP_Channel[chIndex].DoIP_ChannelTARef->DoIP_TargetAddrValue == DoIP_ConfigPtr->DoIP_TargetAddress[targetIndex].DoIP_TargetAddrValue) {
retVal = chIndex;
break;
}
}
return retVal;
}
static Std_ReturnType getConTypeConIndexFromSoConId(SoAd_SoConIdType SoConId, DoIP_Internal_ConType* conTypePtr, uint16* conIndexPtr) {
SoAd_SoConIdType conIndex;
Std_ReturnType retVal;
SoAd_SoConIdType tempSoConId;
boolean found;
found = FALSE;
retVal = E_NOT_OK;
for (conIndex = 0u; conIndex < DOIP_TCP_CON_NUM; conIndex++) {
(void)SoAd_GetSoConId(DoIP_ConfigPtr->DoIP_TcpMsg[conIndex].DoIP_TcpSoADTxPduRef, &tempSoConId);
if (tempSoConId == SoConId) {
found = TRUE;
*conTypePtr = TCP_TYPE;
*conIndexPtr = conIndex;
retVal = E_OK;
break;
}
}
if (FALSE == found) {
for (conIndex = 0u; conIndex < DOIP_UDP_CON_NUM; conIndex++) {
(void)SoAd_GetSoConId(DoIP_ConfigPtr->DoIP_UdpMsg[conIndex].DoIP_UdpSoADTxPduRef, &tempSoConId);
if (tempSoConId == SoConId) {
found = TRUE;
*conTypePtr = UDP_TYPE;
*conIndexPtr = conIndex;
retVal = E_OK;
break;
}
}
if (FALSE == found) {
retVal = E_NOT_OK;
}
}
return retVal;
}
static uint8 getNofCurrentlyUsedTcpSockets(void) {
SoAd_SoConIdType conIndex;
uint8 openSocketCount = 0u;
for (conIndex = 0u; conIndex < DOIP_TCP_CON_NUM; conIndex++) {
if (DoIP_TcpConAdmin[conIndex].socketState == CONNECTION_REGISTERED) {
openSocketCount++;
}
}
return openSocketCount;
}
/** @req SWS_DoIP_00082 */ /** @req SWS_DoIP_00083 */ /** @req SWS_DoIP_00084 */
static void getFurtherActionRequired(uint8* txBufferPtr) {
SoAd_SoConIdType conIndex;
uint8 i;
for (i = 0; i < DOIP_NUM_ROUTING_ACTIVATION; i++) {
if (0xE0 == DoIP_ConfigPtr->DoIP_RoutingActivation[i].DoIP_RoutActNum) {
break;
}
}
if (i != DOIP_NUM_ROUTING_ACTIVATION) {
for (conIndex = 0u; conIndex < DOIP_TCP_CON_NUM; conIndex++) {
if (CONNECTION_REGISTERED == DoIP_TcpConAdmin[conIndex].socketState) {
if (0xE0 == DoIP_TcpConAdmin[conIndex].activationType) {
*txBufferPtr = 0x00;
break;
} else {
*txBufferPtr = 0x10;
}
}
}
} else {
*txBufferPtr = 0x00;
}
}
static boolean isSourceAddressKnown(uint16 sa, uint8 *testerIndex) {
boolean saKnown;
uint8 i;
saKnown = FALSE;
for (i = 0u; (i < DOIP_TESTER_COUNT); i++) {
if (DoIP_ConfigPtr->DoIP_Tester[i].DoIP_TesterSA == sa) {
saKnown = TRUE;
*testerIndex =i;
break;
}
}
return saKnown;
}
static boolean isRoutingTypeSupported(uint16 activationType, uint8 testerIndex, uint16* routActRefIndex) {
boolean supported;
uint8 i;
supported = FALSE;
for (i = 0u; i < DoIP_ConfigPtr->DoIP_Tester[testerIndex].DoIp_RoutRefSize; i++) {
if (DoIP_ConfigPtr->DoIP_Tester[testerIndex].DoIP_RoutActRef[i]->DoIP_RoutActNum == activationType) {
supported = TRUE;
*routActRefIndex = i;
}
}
return supported;
}
#if 0
/* Routing and confirmation callbacks not supported */
static boolean isAuthenticationRequired(uint16 routActRefIndex) {
boolean required;
required = FALSE;
if (NULL == DoIP_ConfigPtr->DoIP_RoutingActivation[routActRefIndex].DoIP_RoutActAuthRef) {
required = FALSE;
} else {
required = TRUE;
}
return required;
}
static boolean isAuthenticated(uint16 routActRefIndex) {
return E_OK;
}
static boolean isConfirmationRequired(uint16 routActRefIndex) {
boolean required;
required = FALSE;
if (NULL == DoIP_ConfigPtr->DoIP_RoutingActivation[routActRefIndex].DoIP_RoutActConfRef) {
required = FALSE;
} else {
required = TRUE;
}
return required;
}
static boolean isConfirmed(uint16 routActRefIndex) {
return E_OK;
}
#endif
static void registerSocket(SoAd_SoConIdType conIndex, uint16 sa, uint16 activationType) {
DoIP_TcpConAdmin[conIndex].socketState = CONNECTION_REGISTERED;
DoIP_TcpConAdmin[conIndex].sa = sa;
DoIP_TcpConAdmin[conIndex].activationType = activationType;
DoIP_TcpConAdmin[conIndex].generalInactivityTimer = 0u;
DoIP_TcpConAdmin[conIndex].initialInactivityTimer = 0u;
DoIP_TcpConAdmin[conIndex].aliveCheckTimer = 0u;
DoIP_TcpConAdmin[conIndex].authenticated = FALSE;
DoIP_TcpConAdmin[conIndex].confirmed = FALSE;
DoIP_TcpConAdmin[conIndex].awaitingAliveCheckResponse = FALSE;
}
static void closeSocket(DoIP_Internal_ConType conType, SoAd_SoConIdType conIndex, uint16 txPdu) {
SoAd_SoConIdType SoConId;
Std_ReturnType ret;
if (TCP_TYPE == conType) {
DoIP_TcpConAdmin[conIndex].closeSocketIndication = TRUE;
} else {
/** @req SWS_DoIP_00058 */
ret = SoAd_GetSoConId(txPdu, &SoConId);
if (E_OK == ret) {
(void)SoAd_CloseSoCon(SoConId, TRUE);
/** @req SWS_DoIP_00115 */
resetTcpConnection(conIndex);
}
}
}
static void updateRemoteAddrAsBroadcast(SoAd_SoConIdType conIndex) {
TcpIp_SockAddrType ad;
ad.domain = TCPIP_AF_INET;
(void)SoAd_GetRemoteAddr(DoIP_UdpConAdmin[conIndex].sockNr, &ad);
ad.addr[0u] = 255u;
ad.addr[1u] = 255u;
ad.addr[2u] = 255u;
ad.addr[3u] = 255u;
ad.port = DOIP_PORT_NUM;
(void)SoAd_SetRemoteAddr(DoIP_UdpConAdmin[conIndex].sockNr, &ad);
}
static void handleTimeout(SoAd_SoConIdType conIndex) {
PduIdType soadTxPduId;
PduInfoType txPduInfo;
PduIdType doipLoTxPduId;
Std_ReturnType ret;
uint8 routingActivationResponseCode;
soadTxPduId = DoIP_ConfigPtr->DoIP_TcpMsg[conIndex].DoIP_TcpTxPduRef;
if (TRUE == DoIP_PendingRoutActivFlag) {
registerSocket(conIndex, DoIP_PendingRoutActivSa, DoIP_pendingRoutActivActType);
soadTxPduId = DoIP_ConfigPtr->DoIP_TcpMsg[DoIP_PendingRoutActivConIndex].DoIP_TcpSoADTxPduRef;
txPduInfo.SduLength = MSG_LEN_INCL_PL_LEN_FIELD + PL_LEN_ROUT_ACTIV_RES;
ret = SoAd_TpTransmit(soadTxPduId, &txPduInfo);
if (E_OK == ret) {
doipLoTxPduId = DoIP_ConfigPtr->DoIP_TcpMsg[DoIP_PendingRoutActivConIndex].DoIP_TcpTxPduRef;
/* Routing successfully activated */
routingActivationResponseCode = 0x10u;
fillRoutingActivationResponseData(DoIP_TcpConAdmin[DoIP_PendingRoutActivConIndex].txBuffer, DoIP_PendingRoutActivSa, routingActivationResponseCode);
DoIP_TcpConAdmin[DoIP_PendingRoutActivConIndex].txBytesToTransmit = MSG_LEN_INCL_PL_LEN_FIELD + PL_LEN_ROUT_ACTIV_RES;
DoIP_TcpConAdmin[DoIP_PendingRoutActivConIndex].txBytesCopied = MSG_LEN_INCL_PL_LEN_FIELD + PL_LEN_ROUT_ACTIV_RES;
DoIP_TcpConAdmin[DoIP_PendingRoutActivConIndex].txBytesTransmitted = 0u;
DoIP_TcpConAdmin[DoIP_PendingRoutActivConIndex].txPduIdUnderProgress = doipLoTxPduId;
DoIP_TcpConAdmin[DoIP_PendingRoutActivConIndex].txBufferState = BUFFER_LOCK;
} else {
DOIP_DET_REPORTERROR(DOIP_HANDLE_TIMEOUT_ID, DOIP_E_TP_TRANSMIT_ERROR);
}
DoIP_PendingRoutActivFlag = FALSE;
} else {
/* Close current connection (which has timed out anyway)
and register a new connection with the pending routing activation */
closeSocket(TCP_FORCE_CLOSE_TYPE, conIndex, soadTxPduId);
}
}
/** @req SWS_DoIP_00009 */
static void createAndSendNackIf(SoAd_SoConIdType conIndex, uint8 nackCode) {
PduInfoType txPduInfo;
PduIdType soadTxPduId;
Std_ReturnType ret;
if (BUFFER_IDLE == DoIP_UdpConAdmin[conIndex].txBufferState) {
/** @req SWS_DoIP_00004 */ /** @req SWS_DoIP_00005 */ /** @req SWS_DoIP_00006 */
DoIP_UdpConAdmin[conIndex].txBuffer[0u] = PROTOCOL_VERSION;
DoIP_UdpConAdmin[conIndex].txBuffer[1u] = ~(uint8)PROTOCOL_VERSION;
/*lint -e9053 MISRA:FALSE_POSITIVE:lint operates on left operand which define (values) and provides false Note - the shift value is at least the precision of the essential type of the left hand side:[MISRA 2012 Rule 12.2, mandatory] */
/*lint -e572 MISRA:FALSE_POSITIVE:lint operates on define and if define is zero false warning - Excessive shift value (precision 0 shifted right by 8):[MISRA 2004 Rule 12.8, required] */
DoIP_UdpConAdmin[conIndex].txBuffer[2u] = (uint8)(PL_TYPE_GENERIC_N_ACK >> SHIFT_BY_ONE_BYTE);
DoIP_UdpConAdmin[conIndex].txBuffer[3u] = (uint8)PL_TYPE_GENERIC_N_ACK;
/* Length < 255, hence 2nd, 3rd and 4th byte of payload length field is 0 */
DoIP_UdpConAdmin[conIndex].txBuffer[4u] = 0u;
DoIP_UdpConAdmin[conIndex].txBuffer[5u] = 0u;
DoIP_UdpConAdmin[conIndex].txBuffer[6u] = 0u;
DoIP_UdpConAdmin[conIndex].txBuffer[7u] = PL_LEN_GENERIC_N_ACK;
DoIP_UdpConAdmin[conIndex].txBuffer[8u+0u] = nackCode;
txPduInfo.SduDataPtr = DoIP_UdpConAdmin[conIndex].txBuffer;
txPduInfo.SduLength = MSG_LEN_INCL_PL_LEN_FIELD + PL_LEN_GENERIC_N_ACK;
soadTxPduId = DoIP_ConfigPtr->DoIP_UdpMsg[conIndex].DoIP_UdpSoADTxPduRef;
ret = SoAd_IfTransmit(soadTxPduId, &txPduInfo);
if (E_OK == ret) {
DoIP_UdpConAdmin[conIndex].txBufferState = BUFFER_LOCK;
} else {
DOIP_DET_REPORTERROR(DOIP_CREATE_AND_SEND_NACK_ID, DOIP_E_IF_TRANSMIT_ERROR);
}
} else {
DOIP_DET_REPORTERROR(DOIP_CREATE_AND_SEND_NACK_ID, DOIP_E_BUFFER_BUSY);
}
}
/** @req SWS_DoIP_00009 */
static void createAndSendNackTp(SoAd_SoConIdType conIndex, uint8 nackCode) {
PduInfoType txPduInfo;
PduIdType soadTxPduId;
PduIdType doipLoTxPduId;
Std_ReturnType ret;
SchM_Enter_DoIP_EA_0();
if (BUFFER_IDLE == DoIP_TcpConAdmin[conIndex].txBufferState) {
txPduInfo.SduLength = MSG_LEN_INCL_PL_LEN_FIELD + PL_LEN_GENERIC_N_ACK;
soadTxPduId = DoIP_ConfigPtr->DoIP_TcpMsg[conIndex].DoIP_TcpSoADTxPduRef;
ret = SoAd_TpTransmit(soadTxPduId, &txPduInfo);
if (E_OK == ret) {
doipLoTxPduId = DoIP_ConfigPtr->DoIP_TcpMsg[conIndex].DoIP_TcpTxPduRef;
DoIP_TcpConAdmin[conIndex].txBuffer[0u] = PROTOCOL_VERSION;
DoIP_TcpConAdmin[conIndex].txBuffer[1u] = ~(uint8)PROTOCOL_VERSION;
/*lint -e9053 MISRA:FALSE_POSITIVE:lint operates on left operand which define (values) and provides false Note - the shift value is at least the precision of the essential type of the left hand side:[MISRA 2012 Rule 12.2, mandatory] */
/*lint -e572 MISRA:FALSE_POSITIVE:lint operates on define and if define is zero false warning - Excessive shift value (precision 0 shifted right by 8):[MISRA 2004 Rule 12.8, required] */
DoIP_TcpConAdmin[conIndex].txBuffer[2u] = (uint8)(PL_TYPE_GENERIC_N_ACK >> SHIFT_BY_ONE_BYTE);
DoIP_TcpConAdmin[conIndex].txBuffer[3u] = (uint8)PL_TYPE_GENERIC_N_ACK;
/* Length < 255, hence 2nd, 3rd and 4th byte of payload length field is 0 */
DoIP_TcpConAdmin[conIndex].txBuffer[4u] = 0u;
DoIP_TcpConAdmin[conIndex].txBuffer[5u] = 0u;
DoIP_TcpConAdmin[conIndex].txBuffer[6u] = 0u;
DoIP_TcpConAdmin[conIndex].txBuffer[7u] = PL_LEN_GENERIC_N_ACK;
DoIP_TcpConAdmin[conIndex].txBuffer[8u+0u] = nackCode;
DoIP_TcpConAdmin[conIndex].txBytesToTransmit = MSG_LEN_INCL_PL_LEN_FIELD + PL_LEN_GENERIC_N_ACK;
DoIP_TcpConAdmin[conIndex].txBytesCopied = MSG_LEN_INCL_PL_LEN_FIELD + PL_LEN_GENERIC_N_ACK;
DoIP_TcpConAdmin[conIndex].txBytesTransmitted = 0u;
DoIP_TcpConAdmin[conIndex].txPduIdUnderProgress = doipLoTxPduId;
DoIP_TcpConAdmin[conIndex].txBufferState = BUFFER_LOCK;
DoIP_TcpConAdmin[conIndex].channelIndex = INVALID_CHANNEL_INDEX;
} else {
DOIP_DET_REPORTERROR(DOIP_CREATE_AND_SEND_D_ACK_ID, DOIP_E_TP_TRANSMIT_ERROR);
}
} else {
DOIP_DET_REPORTERROR(DOIP_CREATE_AND_SEND_D_ACK_ID, DOIP_E_BUFFER_BUSY);
}
SchM_Exit_DoIP_EA_0();
}
/** @req SWS_DoIP_00009 */
static void createAndSendDiagnosticAck(SoAd_SoConIdType conIndex, uint16 sa, uint16 ta) {
PduInfoType txPduInfo;
PduIdType soadTxPduId;
PduIdType doipLoTxPduId;
Std_ReturnType ret;
SchM_Enter_DoIP_EA_0();
if (BUFFER_IDLE == DoIP_TcpConAdmin[conIndex].txBufferState) {
txPduInfo.SduLength = MSG_LEN_INCL_PL_LEN_FIELD + PL_LEN_DIAG_MSG_ACK;
soadTxPduId = DoIP_ConfigPtr->DoIP_TcpMsg[conIndex].DoIP_TcpSoADTxPduRef;
ret = SoAd_TpTransmit(soadTxPduId, &txPduInfo);
if (E_OK == ret) {
doipLoTxPduId = DoIP_ConfigPtr->DoIP_TcpMsg[conIndex].DoIP_TcpTxPduRef;
/** @req SWS_DoIP_00132 */ /** @req SWS_DoIP_00133 */ /** @req SWS_DoIP_00134 */
DoIP_TcpConAdmin[conIndex].txBuffer[0u] = PROTOCOL_VERSION;
DoIP_TcpConAdmin[conIndex].txBuffer[1u] = ~(uint8)PROTOCOL_VERSION;
DoIP_TcpConAdmin[conIndex].txBuffer[2u] = (uint8)(PL_TYPE_DIAG_MSG_P_ACK >> SHIFT_BY_ONE_BYTE);
DoIP_TcpConAdmin[conIndex].txBuffer[3u] = (uint8)PL_TYPE_DIAG_MSG_P_ACK;
/* Length < 255, hence 2nd, 3rd and 4th byte of payload length field is 0 */
DoIP_TcpConAdmin[conIndex].txBuffer[4u] = 0u;
DoIP_TcpConAdmin[conIndex].txBuffer[5u] = 0u;
DoIP_TcpConAdmin[conIndex].txBuffer[6u] = 0u;
DoIP_TcpConAdmin[conIndex].txBuffer[7u] = PL_LEN_DIAG_MSG_ACK;
DoIP_TcpConAdmin[conIndex].txBuffer[8u+0u] = ta >> SHIFT_BY_ONE_BYTE;
DoIP_TcpConAdmin[conIndex].txBuffer[8u+1u] = (uint8) ta;
DoIP_TcpConAdmin[conIndex].txBuffer[8u+2u] = sa >> SHIFT_BY_ONE_BYTE;
DoIP_TcpConAdmin[conIndex].txBuffer[8u+3u] = (uint8) sa;
DoIP_TcpConAdmin[conIndex].txBuffer[8u+4u] = 0u;
DoIP_TcpConAdmin[conIndex].txBytesToTransmit = MSG_LEN_INCL_PL_LEN_FIELD + PL_LEN_DIAG_MSG_ACK;
DoIP_TcpConAdmin[conIndex].txBytesCopied = MSG_LEN_INCL_PL_LEN_FIELD + PL_LEN_DIAG_MSG_ACK;
DoIP_TcpConAdmin[conIndex].txBytesTransmitted = 0u;
DoIP_TcpConAdmin[conIndex].txPduIdUnderProgress = doipLoTxPduId;
DoIP_TcpConAdmin[conIndex].txBufferState = BUFFER_LOCK;
DoIP_TcpConAdmin[conIndex].channelIndex = INVALID_CHANNEL_INDEX;
} else {
DOIP_DET_REPORTERROR(DOIP_CREATE_AND_SEND_D_ACK_ID, DOIP_E_TP_TRANSMIT_ERROR);
}
} else {
/* Push the transmission related data into the queue */
if ((FALSE == DoIP_TcpQueueAdmin[conIndex].tpTransmitQueueActive) &&
(FALSE == DoIP_TcpQueueAdmin[conIndex].diagAckQueueActive)) {
DoIP_TcpQueueAdmin[conIndex].diagAckQueueActive = TRUE;
DoIP_TcpQueueAdmin[conIndex].sa = sa;
DoIP_TcpQueueAdmin[conIndex].ta = ta;
} else {
DOIP_DET_REPORTERROR(DOIP_CREATE_AND_SEND_D_ACK_ID, DOIP_E_BUFFER_BUSY);
}
}
SchM_Exit_DoIP_EA_0();
}
static void createAndSendDiagnosticNack(SoAd_SoConIdType conIndex, uint16 sa, uint16 ta, uint8 nackCode) {
PduInfoType txPduInfo;
PduIdType soadTxPduId;
PduIdType doipLoTxPduId;
Std_ReturnType ret;
SchM_Enter_DoIP_EA_0();
soadTxPduId = DoIP_ConfigPtr->DoIP_TcpMsg[conIndex].DoIP_TcpSoADTxPduRef;
if (BUFFER_IDLE == DoIP_TcpConAdmin[conIndex].txBufferState) {
txPduInfo.SduLength = MSG_LEN_INCL_PL_LEN_FIELD + PL_LEN_DIAG_MSG_ACK;
ret = SoAd_TpTransmit(soadTxPduId, &txPduInfo);
if (E_OK == ret) {
doipLoTxPduId = DoIP_ConfigPtr->DoIP_TcpMsg[conIndex].DoIP_TcpTxPduRef;
/** @req SWS_DoIP_00135 */ /** @req SWS_DoIP_00136 */ /** @req SWS_DoIP_00137 */
DoIP_TcpConAdmin[conIndex].txBuffer[0u] = PROTOCOL_VERSION;
DoIP_TcpConAdmin[conIndex].txBuffer[1u] = ~(uint8)PROTOCOL_VERSION;
DoIP_TcpConAdmin[conIndex].txBuffer[2u] = (uint8)(PL_TYPE_DIAG_MSG_N_ACK >> SHIFT_BY_ONE_BYTE);
DoIP_TcpConAdmin[conIndex].txBuffer[3u] = (uint8)PL_TYPE_DIAG_MSG_N_ACK;
/* Length < 255, hence 2nd, 3rd and 4th byte of payload length field is 0 */
DoIP_TcpConAdmin[conIndex].txBuffer[4u] = 0u;
DoIP_TcpConAdmin[conIndex].txBuffer[5u] = 0u;
DoIP_TcpConAdmin[conIndex].txBuffer[6u] = 0u;
DoIP_TcpConAdmin[conIndex].txBuffer[7u] = PL_LEN_DIAG_MSG_ACK;
DoIP_TcpConAdmin[conIndex].txBuffer[8u+0u] = ta >> SHIFT_BY_ONE_BYTE;
DoIP_TcpConAdmin[conIndex].txBuffer[8u+1u] = (uint8) ta;
DoIP_TcpConAdmin[conIndex].txBuffer[8u+2u] = sa >> SHIFT_BY_ONE_BYTE;
DoIP_TcpConAdmin[conIndex].txBuffer[8u+3u] = (uint8) sa;
DoIP_TcpConAdmin[conIndex].txBuffer[8u+4u] = nackCode;
DoIP_TcpConAdmin[conIndex].txBytesToTransmit = MSG_LEN_INCL_PL_LEN_FIELD + PL_LEN_DIAG_MSG_ACK;
DoIP_TcpConAdmin[conIndex].txBytesCopied = MSG_LEN_INCL_PL_LEN_FIELD + PL_LEN_DIAG_MSG_ACK;
DoIP_TcpConAdmin[conIndex].txBytesTransmitted = 0u;
DoIP_TcpConAdmin[conIndex].txPduIdUnderProgress = doipLoTxPduId;
DoIP_TcpConAdmin[conIndex].txBufferState = BUFFER_LOCK;
DoIP_TcpConAdmin[conIndex].channelIndex = INVALID_CHANNEL_INDEX;
} else {
DOIP_DET_REPORTERROR(DOIP_CREATE_AND_SEND_D_NACK_ID, DOIP_E_TP_TRANSMIT_ERROR);
}
} else {
DOIP_DET_REPORTERROR(DOIP_CREATE_AND_SEND_D_NACK_ID, DOIP_E_BUFFER_BUSY);
}
SchM_Exit_DoIP_EA_0();
}
static void createVehicleIdentificationResponse(uint8* txBuffer, SoAd_SoConIdType conIndex) {
boolean getVinResult;
getVinResult = FALSE;
txBuffer[0u] = PROTOCOL_VERSION;
txBuffer[1u] = ~(uint8)PROTOCOL_VERSION;
/*lint -e9053 MISRA:FALSE_POSITIVE:lint operates on left operand which define (values) and provides false Note - the shift value is at least the precision of the essential type of the left hand side:[MISRA 2012 Rule 12.2, mandatory] */
/*lint -e{572,778} MISRA:FALSE_POSITIVE:lint operates on define and if define is zero false warning - Excessive shift value (precision 0 shifted right by 8):[MISRA 2004 Rule 12.8, required] */
txBuffer[2u] = (uint8)(PL_TYPE_VID_RES >> SHIFT_BY_ONE_BYTE);
txBuffer[3u] = (uint8)PL_TYPE_VID_RES;
/* Length < 255, hence 2nd, 3rd and 4th byte of payload length field is 0 */
txBuffer[4u] = 0u;
txBuffer[5u] = 0u;
txBuffer[6u] = 0u;
txBuffer[7u] = PL_LEN_VID_RES;
/* VIN field */
if (FALSE == DoIP_VinUpdated) {
getVinResult = getVin(DoIP_Vin);
}
memcpy(&txBuffer[VID_VIN_INDEX], DoIP_Vin, sizeof(DoIP_Vin));
/** @req SWS_DoIP_00073 */
/* Logical address field */
txBuffer[VID_LA_INDEX+0u] = (uint8)(DoIP_LOGICAL_ADDRESS >> SHIFT_BY_ONE_BYTE);
txBuffer[VID_LA_INDEX+1u] = (uint8)DoIP_LOGICAL_ADDRESS;
/* EID field */
if (FALSE == DoIP_EidUpdated) {
(void)getEid(DoIP_Eid, conIndex);
}
memcpy(&txBuffer[VID_EID_INDEX], DoIP_Eid, sizeof(DoIP_Eid));
/* GID field */
getGid(&txBuffer[VID_GID_INDEX], conIndex);
/* Further action required field */
if (E_OK != getVinResult) {
txBuffer[VID_FUR_ACT_REQ_INDEX] = 0x00u;
} else {
getFurtherActionRequired(&txBuffer[VID_FUR_ACT_REQ_INDEX]);
}
#if (DOIP_USE_VEHICLE_ID_SYNC_STATUS == STD_ON)
/** @req SWS_DoIP_00086 */
/* VIN/GID Sync Status field */
if (E_OK != getVinResult) {
txBuffer[VID_VIN_GID_STS_INDEX] = 0x10u;
} else {
txBuffer[VID_VIN_GID_STS_INDEX] = 0x00;
}
#endif
}
static void sendVehicleAnnouncement(SoAd_SoConIdType conIndex) {
PduInfoType txPduInfo;
PduIdType soadTxPduId;
Std_ReturnType ret;
if (BUFFER_IDLE == DoIP_UdpConAdmin[conIndex].txBufferState) {
createVehicleIdentificationResponse(DoIP_UdpConAdmin[conIndex].txBuffer, conIndex);
txPduInfo.SduDataPtr = DoIP_UdpConAdmin[conIndex].txBuffer;
txPduInfo.SduLength = MSG_LEN_INCL_PL_LEN_FIELD + PL_LEN_VID_RES;
soadTxPduId = DoIP_ConfigPtr->DoIP_UdpMsg[conIndex].DoIP_UdpSoADTxPduRef;
updateRemoteAddrAsBroadcast(conIndex);
ret = SoAd_IfTransmit(soadTxPduId, &txPduInfo);
if (E_OK == ret) {
DoIP_UdpConAdmin[conIndex].txBufferState = BUFFER_LOCK;
} else {
DOIP_DET_REPORTERROR(DOIP_SEND_VEHICLE_ANNOUNCE_REQ_ID, DOIP_E_IF_TRANSMIT_ERROR);
}
} else {
DOIP_DET_REPORTERROR(DOIP_SEND_VEHICLE_ANNOUNCE_REQ_ID, DOIP_E_BUFFER_BUSY);
}
}
static void fillRoutingActivationResponseData(uint8 *txBuffer, uint16 sa, uint8 routingActivationResponseCode) {
txBuffer[0u] = PROTOCOL_VERSION;
txBuffer[1u] = ~(uint8)PROTOCOL_VERSION;
/*lint -e{572,778} MISRA:FALSE_POSITIVE:lint operates on define and if define is zero false warning - Excessive shift value (precision 0 shifted right by 8):[MISRA 2004 Rule 12.8, required] */
txBuffer[2u] = (uint8)PL_TYPE_ROUT_ACTIV_RES >> SHIFT_BY_ONE_BYTE;
txBuffer[3u] = (uint8)PL_TYPE_ROUT_ACTIV_RES;
/* Length < 255, hence 2nd, 3rd and 4th byte of payload length field is 0 */
txBuffer[4u] = 0u;
txBuffer[5u] = 0u;
txBuffer[6u] = 0u;
txBuffer[7u] = PL_LEN_ROUT_ACTIV_RES;
txBuffer[8u+0u] = sa >> SHIFT_BY_ONE_BYTE;
txBuffer[8u+1u] = (uint8)sa;
txBuffer[8u+2u] = (uint8)(DoIP_LOGICAL_ADDRESS >> SHIFT_BY_ONE_BYTE);
txBuffer[8u+3u] = (uint8)DoIP_LOGICAL_ADDRESS;
txBuffer[8u+4u] = routingActivationResponseCode;
/* Reserved */
txBuffer[8u+5u] = 0u;
txBuffer[8u+6u] = 0u;
txBuffer[8u+7u] = 0u;
txBuffer[8u+8u] = 0u;
#if 0
/* OEM Specific not supported */
txBuffer[8u+9u] = 0u;
txBuffer[8u+10u] = 0u;
txBuffer[8u+11u] = 0u;
txBuffer[8u+12u] = 0u;
#endif
}
static void createAndSendAliveCheck(SoAd_SoConIdType conIndex) {
PduInfoType txPduInfo;
PduIdType soadTxPduId;
PduIdType doipLoTxPduId;
Std_ReturnType ret;
soadTxPduId = DoIP_ConfigPtr->DoIP_TcpMsg[conIndex].DoIP_TcpTxPduRef;
if (BUFFER_IDLE == DoIP_TcpConAdmin[conIndex].txBufferState) {
txPduInfo.SduLength = MSG_LEN_INCL_PL_LEN_FIELD + PL_LEN_ALIVE_CHK_REQ;
ret = SoAd_TpTransmit(soadTxPduId, &txPduInfo);
if (E_OK == ret) {
doipLoTxPduId = DoIP_ConfigPtr->DoIP_TcpMsg[conIndex].DoIP_TcpTxPduRef;
DoIP_TcpConAdmin[conIndex].txBuffer[0u] = PROTOCOL_VERSION;
DoIP_TcpConAdmin[conIndex].txBuffer[1u] = ~(uint8)PROTOCOL_VERSION;
/*lint -e{572,778} MISRA:FALSE_POSITIVE:lint operates on define and if define is zero false warning - Excessive shift value (precision 0 shifted right by 8):[MISRA 2004 Rule 12.8, required] */
DoIP_TcpConAdmin[conIndex].txBuffer[2u] = (uint8)(PL_TYPE_ALIVE_CHK_REQ >> SHIFT_BY_ONE_BYTE);
DoIP_TcpConAdmin[conIndex].txBuffer[3u] = (uint8)PL_TYPE_ALIVE_CHK_REQ;
/* Length < 255, hence 2nd, 3rd and 4th byte of payload length field is 0 */
DoIP_TcpConAdmin[conIndex].txBuffer[4u] = 0u;
DoIP_TcpConAdmin[conIndex].txBuffer[5u] = 0u;
DoIP_TcpConAdmin[conIndex].txBuffer[6u] = 0u;
DoIP_TcpConAdmin[conIndex].txBuffer[7u] = PL_LEN_ALIVE_CHK_REQ;
DoIP_TcpConAdmin[conIndex].txBytesToTransmit = MSG_LEN_INCL_PL_LEN_FIELD + PL_LEN_ALIVE_CHK_REQ;
DoIP_TcpConAdmin[conIndex].txBytesCopied = MSG_LEN_INCL_PL_LEN_FIELD + PL_LEN_ALIVE_CHK_REQ;
DoIP_TcpConAdmin[conIndex].txBytesTransmitted = 0u;
DoIP_TcpConAdmin[conIndex].txPduIdUnderProgress = doipLoTxPduId;
DoIP_TcpConAdmin[conIndex].txBufferState = BUFFER_LOCK;
} else {
/* Could not send data - socket probably broken, so let's close the socket. */
/* If there are pending routing activations waiting, activate that one. */
if (TRUE == DoIP_PendingRoutActivFlag) {
handleTimeout(conIndex);
} else {
closeSocket(TCP_FORCE_CLOSE_TYPE, conIndex, soadTxPduId);
}
}
} else {
/* No TX buffer available. Report a Det error. */
DOIP_DET_REPORTERROR(DOIP_CREATE_AND_SEND_ALIVE_CHECK_ID, DOIP_E_BUFFER_BUSY);
}
}
static void startSingleSaAliveCheck(SoAd_SoConIdType conIndex) {
if (FALSE == DoIP_TcpConAdmin[conIndex].awaitingAliveCheckResponse) {
DoIP_TcpConAdmin[conIndex].awaitingAliveCheckResponse = TRUE;
DoIP_TcpConAdmin[conIndex].generalInactivityTimer = 0u;
DoIP_TcpConAdmin[conIndex].aliveCheckTimer = 0u;
createAndSendAliveCheck(conIndex);
}
}
static void startAllSocketsAliveCheck() {
SoAd_SoConIdType conIndex;
for (conIndex = 0u; conIndex < DOIP_TCP_CON_NUM; conIndex++) {
/* No need to check connection states as this method is only called
when all sockets are in registered state. */
DoIP_TcpConAdmin[conIndex].awaitingAliveCheckResponse = TRUE;
DoIP_TcpConAdmin[conIndex].generalInactivityTimer = 0u;
DoIP_TcpConAdmin[conIndex].aliveCheckTimer = 0u;
createAndSendAliveCheck(conIndex);
}
}
static DoIP_Internal_LookupResType lookupSaTa(SoAd_SoConIdType conIndex, uint16 sa, uint16 ta, uint8* targetIndex) {
uint8 j;
DoIP_Internal_LookupResType retVal;
uint8 testerIndex;
uint8 i;
boolean found;
testerIndex = 0;
/* Check whether the tester(source address) is configured */
for (i = 0u; (i < DOIP_TESTER_COUNT); i++) {
if (DoIP_ConfigPtr->DoIP_Tester[i].DoIP_TesterSA == sa) {
testerIndex = (uint8)i;
break;
}
}
found = FALSE;
/* Tester(source address) is configured, check further .... */
if (i != DOIP_TESTER_COUNT) {
/* Check whether tester is linked to the connection handler */
if (sa == DoIP_TcpConAdmin[conIndex].sa) {
/* Is the connection handler registered ? */
if (CONNECTION_REGISTERED == DoIP_TcpConAdmin[conIndex].socketState) {
/* Is Target address linked with the Tester ?
Check all the Target addresses linked with each of the
routing activations which are assigned to the tester */
for (i = 0u; i < DoIP_ConfigPtr->DoIP_Tester[testerIndex].DoIp_RoutRefSize; i++) {
for (j = 0u; j < DoIP_ConfigPtr->DoIP_RoutingActivation[i].DoIP_chnlTARef_Size; j++) {
if (DoIP_ConfigPtr->DoIP_RoutingActivation[i].DoIP_TargetRef[j] == ta) {
*targetIndex = i;
found = TRUE;
break;
}
}
}
if (TRUE == found) {
retVal = LOOKUP_SA_TA_OK;
} else {
retVal = LOOKUP_SA_TA_TAUNKNOWN;
}
} else {
retVal = LOOKUP_SA_TA_ROUTING_ERR;
}
} else {
retVal = LOOKUP_SA_TA_SAERR;
}
} else {
retVal = LOOKUP_SA_TA_SAERR;
}
return retVal;
}
static DoIP_Internal_SockAssigResType socketHandle(SoAd_SoConIdType conIndex, uint16 activationType, uint16 sa, uint8* routingActivationResponseCode) {
SoAd_SoConIdType numRegisteredSockets;
SoAd_SoConIdType tempConIndex;
/* This method is intended to implement Figure 13 in ISO/FDIS 13400-2:2012(E) */
DoIP_Internal_SockAssigResType socketHandleResult;
numRegisteredSockets = 0u;
socketHandleResult = SOCKET_ASSIGNMENT_FAILED;
for (tempConIndex = 0u; tempConIndex < DOIP_TCP_CON_NUM; tempConIndex++) {
if (CONNECTION_REGISTERED == DoIP_TcpConAdmin[tempConIndex].socketState) {
numRegisteredSockets++;
}
}
if (0u == numRegisteredSockets) {
/* No registered sockets, so we pick a slot for this connection: */
registerSocket(conIndex, sa, activationType);
/* No need to set *routingActivationResponseCode when socket assignment is successful. */
socketHandleResult = SOCKET_ASSIGNMENT_SUCCESSFUL;
} else {
/* We found the TCP socket. Is it registered? */
if (CONNECTION_REGISTERED == DoIP_TcpConAdmin[conIndex].socketState) {
/* We found the registered TCP socket. Is it assigned to this tester (SA)? */
if (DoIP_TcpConAdmin[conIndex].sa == sa) {
socketHandleResult = SOCKET_ASSIGNMENT_SUCCESSFUL;
} else {
/** @req SWS_DoIP_00106 */
/* Routing activation denied because an SA different from the table connection entry
was received on the already activated TCP_DATA socket. */
*routingActivationResponseCode = 0x02u;
socketHandleResult = SOCKET_ASSIGNMENT_FAILED;
}
} else {
/** @req SWS_DoIP_00103 */
/* Next up: Check if SA is already registered to another socket... */
for (tempConIndex = 0u; tempConIndex < DOIP_TCP_CON_NUM; tempConIndex++) {
if ((DoIP_TcpConAdmin[tempConIndex].sa == sa) && (CONNECTION_REGISTERED == DoIP_TcpConAdmin[tempConIndex].socketState)) {
/** @req SWS_DoIP_00105 */
/* Yes, the SA is already registered on another socket! */
/* perform alive check single SA */
startSingleSaAliveCheck(tempConIndex);
socketHandleResult = SOCKET_ASSIGNMENT_PENDING;
break;
}
}
/** @req SWS_DoIP_00107 */
if (DOIP_TCP_CON_NUM == tempConIndex) {
/* Next up: Check to see that there is a free socket slot available.. */
for (tempConIndex = 0u; tempConIndex < DOIP_TCP_CON_NUM; tempConIndex++) {
if (CONNECTION_INITIALIZED == DoIP_TcpConAdmin[tempConIndex].socketState) {
/* Yes, we found a free slot */
registerSocket(tempConIndex, activationType, sa);
socketHandleResult = SOCKET_ASSIGNMENT_SUCCESSFUL;
break;
}
}
if (DOIP_TCP_CON_NUM == tempConIndex) {
/* For loop terminated; that means that there are no free slots.
Perform alive check on all registered sockets... */
startAllSocketsAliveCheck();
socketHandleResult = SOCKET_ASSIGNMENT_PENDING;
}
}
}
}
return socketHandleResult;
}
static void handleAliveCheckResp(SoAd_SoConIdType conIndex,const uint8* rxBuffer) {
DoIPPayloadType payloadLength;
PduInfoType txPduInfo;
PduIdType soadTxPduId;
PduIdType doipLoTxPduId;
SoAd_SoConIdType i;
uint16 remainingConnections;
uint16 sa;
Std_ReturnType ret;
uint8 routingActivationResponseCode;
routingActivationResponseCode = 0;
payloadLength = GET_PL_LEN_FROM_DOIP_MSG_PTR(rxBuffer);
soadTxPduId = DoIP_ConfigPtr->DoIP_TcpMsg[conIndex].DoIP_TcpSoADTxPduRef;
if (PL_LEN_ALIVE_CHK_RES == payloadLength) {
remainingConnections = 0u;
/* Connections remaining to receive alive check responses */
for (i = 0u; i < DOIP_TCP_CON_NUM; i++) {
if (TRUE == DoIP_TcpConAdmin[i].awaitingAliveCheckResponse) {
remainingConnections++;
}
}
if (remainingConnections != 0x00u) {
remainingConnections--;
DoIP_TcpConAdmin[conIndex].generalInactivityTimer = 0u;
DoIP_TcpConAdmin[conIndex].awaitingAliveCheckResponse = FALSE;
sa = GET_SA_FROM_DOIP_MSG_PTR(rxBuffer);
if (CONNECTION_REGISTERED == DoIP_TcpConAdmin[conIndex].socketState) {
if (DoIP_TcpConAdmin[conIndex].sa == sa) {
/* 0x03: Routing activation denied because the SA is already registered
and active on a different TCP_DATA socket */
routingActivationResponseCode = 0x03u;
} else {
if (0x00u == remainingConnections) {
/* 0x01: Routing activation denied because all concurrently supported
TCP_DATA sockets are registered and active. */
routingActivationResponseCode = 0x01u;
}
}
}
if ((0x03u == routingActivationResponseCode) || (0x00u == routingActivationResponseCode)) {
soadTxPduId = DoIP_ConfigPtr->DoIP_TcpMsg[DoIP_PendingRoutActivConIndex].DoIP_TcpSoADTxPduRef;
txPduInfo.SduLength = MSG_LEN_INCL_PL_LEN_FIELD + PL_LEN_ROUT_ACTIV_RES;
/** @req SWS_DoIP_00220 */
ret = SoAd_TpTransmit(soadTxPduId, &txPduInfo);
if (E_OK == ret) {
doipLoTxPduId = DoIP_ConfigPtr->DoIP_TcpMsg[DoIP_PendingRoutActivConIndex].DoIP_TcpTxPduRef;
fillRoutingActivationResponseData(DoIP_TcpConAdmin[DoIP_PendingRoutActivConIndex].txBuffer, DoIP_PendingRoutActivSa, routingActivationResponseCode);
DoIP_TcpConAdmin[DoIP_PendingRoutActivConIndex].txBytesToTransmit = MSG_LEN_INCL_PL_LEN_FIELD + PL_LEN_ROUT_ACTIV_RES;
DoIP_TcpConAdmin[DoIP_PendingRoutActivConIndex].txBytesCopied = MSG_LEN_INCL_PL_LEN_FIELD + PL_LEN_ROUT_ACTIV_RES;
DoIP_TcpConAdmin[DoIP_PendingRoutActivConIndex].txBytesTransmitted = 0u;
DoIP_TcpConAdmin[DoIP_PendingRoutActivConIndex].txPduIdUnderProgress = doipLoTxPduId;
DoIP_TcpConAdmin[DoIP_PendingRoutActivConIndex].txBufferState = BUFFER_LOCK;
} else {
/** @req SWS_DoIP_00014 */ /** @req SWS_DoIP_00223 */
DOIP_DET_REPORTERROR(DOIP_HANDLE_ALIVECHECK_RESP_ID, DOIP_E_TP_TRANSMIT_ERROR);
}
DoIP_PendingRoutActivFlag = FALSE;
}
}
} else {
/* Invalid payload length! */
createAndSendNackTp(conIndex, ERROR_INVALID_PAYLOAD_LENGTH);
closeSocket(TCP_TYPE, conIndex, soadTxPduId);
}
}
static void handleRoutingActivationReq(SoAd_SoConIdType conIndex, const uint8 *rxBuffer) {
DoIPPayloadType payloadLength;
PduInfoType txPduInfo;
PduIdType soadTxPduId;
PduIdType doipLoTxPduId;
SoAd_SoConIdType SoConId;
uint16 sa;
uint16 activationType;
uint16 routActRefIndex;
Std_ReturnType ret;
DoIP_Internal_SockAssigResType socketHandleResult;
uint8 testerIndex;
uint8 routingActivationResponseCode;
payloadLength = GET_PL_LEN_FROM_DOIP_MSG_PTR(rxBuffer);
soadTxPduId = DoIP_ConfigPtr->DoIP_TcpMsg[conIndex].DoIP_TcpSoADTxPduRef;
/** @req SWS_DoIP_00117 is invalid (refers to the wrong service and does not match
* ISO13400-2:2012 issued on 2012-06-18)
*
* Decision made together with Customer's diagnostic tester group that activation
* type is only one byte, thus payload length may be 11 or 7. (Not 12 or 8 as
* AUTOSAR requirement states)
*/
/** @req SWS_DoIP_00117 */
if ((PL_LEN_ROUT_ACTIV_REQ == payloadLength) || (PL_LEN_ROUT_ACTIV_OEM_REQ == payloadLength)) {
sa = GET_SA_FROM_DOIP_MSG_PTR(rxBuffer);
activationType = GET_ACT_TYPE_FROM_DOIP_MSG_PTR(rxBuffer);
if (BUFFER_IDLE == DoIP_TcpConAdmin[conIndex].txBufferState) {
/* Vehicle manufacturer-specific */
routingActivationResponseCode = 0x7eu;
if (TRUE == isSourceAddressKnown(sa, &testerIndex)) {
/** @req SWS_DoIP_00108 */
if (TRUE == isRoutingTypeSupported(activationType, testerIndex, &routActRefIndex)) {
(void)SoAd_GetSoConId(soadTxPduId, &SoConId);
socketHandleResult = socketHandle(conIndex, activationType, sa, &routingActivationResponseCode);
if (SOCKET_ASSIGNMENT_SUCCESSFUL == socketHandleResult) {
/* Routing successfully activated */
/** @req SWS_DoIP_00113 */
routingActivationResponseCode = 0x10u;
DoIP_Arc_TcpConnectionNotification(SoConId);
#if 0
boolean authenticated;
/* Routing and confirmation callbacks not supported */
if (TRUE == isAuthenticationRequired(routActRefIndex)) {
authenticated = isAuthenticated(routActRefIndex);
} else {
authenticated = TRUE;
}
if (authenticated) {
if (TRUE == isConfirmationRequired(routActRefIndex)) {
if (TRUE == isConfirmed(routActRefIndex)) {
/* Routing successfully activated */
/** @req SWS_DoIP_00113 */
routingActivationResponseCode = 0x10u;
} else {
/* Routing will be activated; confirmation required */
routingActivationResponseCode = 0x11u;
}
} else {
/* Routing successfully activated */
routingActivationResponseCode = 0x10u;
}
} else {
/* Routing activation rejected due to missing authentication */
routingActivationResponseCode = 0x04u;
}
#endif
} else if (SOCKET_ASSIGNMENT_FAILED == socketHandleResult) { /* socketHandle */
/* Routing activation denied because:
* 0x01 - all concurrently supported TCP_DATA sockets are
* registered and active
* 0x02 - an SA different from the table connection entry
* was received on the already activated TCP_DATA
* socket
* 0x03 - the SA is already registered and active on a
* different TCP_DATA socket
*
* socketHandle() shall already have written the corresponding response code to
* routingActivationResponseCode
*/
/* Validate response code */
if (0x02 != routingActivationResponseCode) {
/* Socket will be closed */
} else {
/* Unsupported response code at this level */
routingActivationResponseCode = 0x7eu;
DOIP_DET_REPORTERROR(DOIP_ROUTING_ACTIVATION_REQ_ID, DOIP_E_UNEXPECTED_EXECUTION);
}
} else if (SOCKET_ASSIGNMENT_PENDING == socketHandleResult) { /* socketHandle */
/*
* Trying to assign a connection slot, but pending
* alive check responses before continuing.
* Continuation handled from DoIP_MainFunction (if a
* connection times out and thus becomes free) or from
* handleAliveCheckResp (if all connections remain
* active)
*/
if (FALSE == DoIP_PendingRoutActivFlag) {
DoIP_PendingRoutActivFlag = TRUE;
DoIP_PendingRoutActivConIndex = conIndex;
DoIP_PendingRoutActivSa = sa;
DoIP_pendingRoutActivActType = activationType;
} else {
/* Socket assignment pending; alive check response already pending
This should not happen - the connection attempt should not have been accepted. */
DOIP_DET_REPORTERROR(DOIP_ROUTING_ACTIVATION_REQ_ID, DOIP_E_UNEXPECTED_EXECUTION);
}
} else {
/* This cannot happen */
DOIP_DET_REPORTERROR(DOIP_ROUTING_ACTIVATION_REQ_ID, DOIP_E_UNEXPECTED_EXECUTION);
}
} else {
/* @req SWS_DoIP_00160 */
/* Routing activation denied due to unsupported routing activation type */
routingActivationResponseCode = 0x06u;
}
} else {
/** @req SWS_DoIP_00104 */
/* Routing activation rejected due to unknown source address */
routingActivationResponseCode = 0x00u;
}
txPduInfo.SduLength = MSG_LEN_INCL_PL_LEN_FIELD + PL_LEN_ROUT_ACTIV_RES;
ret = SoAd_TpTransmit(soadTxPduId, &txPduInfo);
if (E_OK == ret) {
doipLoTxPduId = DoIP_ConfigPtr->DoIP_TcpMsg[conIndex].DoIP_TcpTxPduRef;
fillRoutingActivationResponseData(DoIP_TcpConAdmin[conIndex].txBuffer, sa, routingActivationResponseCode);
DoIP_TcpConAdmin[conIndex].txBytesToTransmit = MSG_LEN_INCL_PL_LEN_FIELD + PL_LEN_ROUT_ACTIV_RES;
DoIP_TcpConAdmin[conIndex].txBytesCopied = MSG_LEN_INCL_PL_LEN_FIELD + PL_LEN_ROUT_ACTIV_RES;
DoIP_TcpConAdmin[conIndex].txBytesTransmitted = 0u;
DoIP_TcpConAdmin[conIndex].txPduIdUnderProgress = doipLoTxPduId;
DoIP_TcpConAdmin[conIndex].txBufferState = BUFFER_LOCK;
} else {
DOIP_DET_REPORTERROR(DOIP_ROUTING_ACTIVATION_REQ_ID, DOIP_E_TP_TRANSMIT_ERROR);
}
/* Negative response code --> Close socket on which the current message was received */
switch (routingActivationResponseCode) {
/* Routing activated. */
case 0x10:
/* Confirmation pending */
case 0x11:
/* Missing authentication */
case 0x04:
break;
default:
closeSocket(TCP_TYPE, conIndex, soadTxPduId);
break;
}
} else {
DOIP_DET_REPORTERROR(DOIP_ROUTING_ACTIVATION_REQ_ID, DOIP_E_BUFFER_BUSY);
}
} else {
createAndSendNackTp(conIndex, ERROR_INVALID_PAYLOAD_LENGTH);
closeSocket(TCP_TYPE, conIndex, soadTxPduId);
}
}
static void handleDiagnosticMessage(SoAd_SoConIdType conIndex, uint8 *rxBuffer) {
DoIPPayloadType payloadLength;
PduInfoType pduInfo;
PduIdType soadTxPduId;
PduIdType pduRRxPduId;
PduLengthType bufferSize;
PduIdType diagMessageLengthToRecv;
uint16 sa;
uint16 ta;
DoIP_Internal_LookupResType lookupResult;
BufReq_ReturnType result;
uint8 chIndex;
uint8 targetIndex;
payloadLength = GET_PL_LEN_FROM_DOIP_MSG_PTR(rxBuffer);
soadTxPduId = DoIP_ConfigPtr->DoIP_TcpMsg[conIndex].DoIP_TcpSoADTxPduRef;
SchM_Enter_DoIP_EA_0();
/** @req SWS_DoIP_00122 */
if (payloadLength >= PL_LEN_DIAG_MIN_REQ) {
diagMessageLengthToRecv = (PduIdType) (payloadLength - SA_AND_TA_LEN);
sa = GET_SA_FROM_DOIP_MSG_PTR(rxBuffer);
ta = GET_TA_FROM_DOIP_MSG_PTR(rxBuffer);
/** @req SWS_DoIP_00125 */
if (diagMessageLengthToRecv <= DOIP_MAX_REQUEST_BYTES) {
lookupResult = lookupSaTa(conIndex, sa, ta, &targetIndex);
if (lookupResult == LOOKUP_SA_TA_OK) {
/* Send diagnostic message to PduR */
chIndex = getChIndexFromTargetIndex(targetIndex);
if (chIndex != INVALID_CHANNEL_INDEX) {
pduRRxPduId = DoIP_ConfigPtr->DoIP_Channel[chIndex].DoIP_UpperLayerRxPduId;
pduInfo.SduDataPtr = &(rxBuffer[MSG_LEN_INCL_PL_LEN_FIELD + SA_AND_TA_LEN]);
/** @req SWS_DoIP_00212 */
result = PduR_DoIPTpStartOfReception(pduRRxPduId, &pduInfo, diagMessageLengthToRecv, &bufferSize);
if (result == BUFREQ_OK) {
/** @req SWS_DoIP_00260 */
/* Let PduR copy received data */
/** @req SWS_DoIP_00128 */
if (diagMessageLengthToRecv <= bufferSize) {
pduInfo.SduLength = diagMessageLengthToRecv;
(void)PduR_DoIPTpCopyRxData(pduRRxPduId, &pduInfo, &bufferSize);
}
/** @req SWS_DoIP_00221 */
/* Finished reception */
PduR_DoIPTpRxIndication(pduRRxPduId, E_OK);
/** @req SWS_DoIP_00129 */
/* Send diagnostic message positive ack */
createAndSendDiagnosticAck(conIndex, sa, ta);
}
else {
/** @req SWS_DoIP_00174 */
createAndSendDiagnosticNack(conIndex, sa, ta, ERROR_DIAG_TP_ERROR);
}
} else {
DOIP_DET_REPORTERROR(DOIP_HANDLE_DIAG_MSG_ID, DOIP_E_UNEXPECTED_EXECUTION);
}
} else if (lookupResult == LOOKUP_SA_TA_SAERR) {
/** @req SWS_DoIP_00123 */ /** @req SWS_DoIP_00104 */
/* SA not registered on receiving socket */
createAndSendDiagnosticNack(conIndex, sa, ta, ERROR_DIAG_INVALID_SA);
closeSocket(TCP_TYPE, conIndex, soadTxPduId);
} else if (lookupResult == LOOKUP_SA_TA_TAUNKNOWN) {
/** @req SWS_DoIP_00124 */
createAndSendDiagnosticNack(conIndex, sa, ta, ERROR_DIAG_UNKNOWN_TA);
} else if (lookupResult == LOOKUP_SA_TA_ROUTING_ERR) {
/** @req SWS_DoIP_00127 */
createAndSendDiagnosticNack(conIndex, sa, ta, ERROR_DIAG_TARGET_UNREACHABLE);
} else {
}
} else {
createAndSendDiagnosticNack(conIndex, sa, ta, ERROR_DIAG_MESSAGE_TO_LARGE);
}
} else {
createAndSendNackTp(conIndex, ERROR_INVALID_PAYLOAD_LENGTH);
closeSocket(TCP_TYPE, conIndex, soadTxPduId);
}
SchM_Exit_DoIP_EA_0();
}
static void handleVehicleIdentificationReq(SoAd_SoConIdType conIndex, const uint8 *rxBuffer, DoIP_Internal_VehReqType type) {
DoIPPayloadType payloadLength;
PduInfoType txPduInfo;
PduIdType soadTxPduId;
Std_ReturnType ret;
boolean doRespond;
soadTxPduId = DoIP_ConfigPtr->DoIP_UdpMsg[conIndex].DoIP_UdpSoADTxPduRef;
payloadLength = GET_PL_LEN_FROM_DOIP_MSG_PTR(rxBuffer);
if (ID_REQUEST_ALL == type) {
/** @req SWS_DoIP_00059 */
if (PL_LEN_VID_REQ == payloadLength) {
doRespond = TRUE;
} else {
/* Invalid payload length! */
createAndSendNackIf(conIndex, ERROR_INVALID_PAYLOAD_LENGTH);
closeSocket(UDP_TYPE, conIndex, soadTxPduId);
doRespond = FALSE;
}
} else if (ID_REQUEST_BY_EID == type) {
/** @req SWS_DoIP_00063 */
if (PL_LEN_VID_EID_REQ_RES == payloadLength) {
ret = E_OK;
if (FALSE == DoIP_EidUpdated) {
ret = getEid(DoIP_Eid, conIndex);
}
if (E_OK == ret) {
/** @req SWS_DoIP_00066 */
/*lint -e737 MISRA:FALSE_POSITIVE:Loss of sign in promotion from into to unsigned int:Other */
if (E_OK == memcmp(DoIP_Eid, &rxBuffer[REQ_PAYLOAD_INDEX], sizeof(DoIP_Eid))) {
doRespond = TRUE;
} else {
doRespond = FALSE;
}
} else {
doRespond = FALSE;
}
} else {
/* Invalid payload length! */
createAndSendNackIf(conIndex, ERROR_INVALID_PAYLOAD_LENGTH);
closeSocket(UDP_TYPE, conIndex, soadTxPduId);
doRespond = FALSE;
}
} else if (type == ID_REQUEST_BY_VIN) {
/** @req SWS_DoIP_00068 */
if (PL_LEN_VID_VIN_REQ_RES == payloadLength) {
ret = E_OK;
if (FALSE == DoIP_VinUpdated) {
ret = getVin(DoIP_Vin);
}
if (E_OK == ret) {
/*lint -e737 MISRA:FALSE_POSITIVE:Loss of sign in promotion from into to unsigned int:Other */
if (E_OK == memcmp(DoIP_Vin, &rxBuffer[REQ_PAYLOAD_INDEX], sizeof(DoIP_Vin))) {
doRespond = TRUE;
} else {
doRespond = FALSE;
}
} else {
doRespond = FALSE;
}
} else {
/* Invalid payload length! */
createAndSendNackIf(conIndex, ERROR_INVALID_PAYLOAD_LENGTH);
closeSocket(UDP_TYPE, conIndex, soadTxPduId);
doRespond = FALSE;
}
} else {
/* Not reachable code */
/* Unknown payload type! */
createAndSendNackIf(conIndex, ERROR_UNKNOWN_PAYLOAD_TYPE);
doRespond = FALSE;
}
/** @req SWS_DoIP_00060 */
if (TRUE == doRespond) {
if (BUFFER_IDLE == DoIP_UdpConAdmin[conIndex].txBufferState) {
createVehicleIdentificationResponse(DoIP_UdpConAdmin[conIndex].txBuffer, conIndex);
updateRemoteAddrAsBroadcast(conIndex);
txPduInfo.SduDataPtr = DoIP_UdpConAdmin[conIndex].txBuffer;
txPduInfo.SduLength = MSG_LEN_INCL_PL_LEN_FIELD + PL_LEN_VID_RES;
ret = SoAd_IfTransmit(soadTxPduId, &txPduInfo);
if (E_OK == ret) {
DoIP_UdpConAdmin[conIndex].txBufferState = BUFFER_LOCK;
} else {
DOIP_DET_REPORTERROR(DOIP_HANDLE_VEHICLE_ID_REQ_ID, DOIP_E_IF_TRANSMIT_ERROR);
}
} else {
/* Not TX buffer available. Report a Det error */
DOIP_DET_REPORTERROR(DOIP_HANDLE_VEHICLE_ID_REQ_ID, DOIP_E_BUFFER_BUSY);
}
} else {
/* Do nothing */
}
}
static void handleEntityStatusReq(SoAd_SoConIdType conIndex, const uint8 *rxBuffer) {
DoIPPayloadType payloadLength;
PduInfoType txPduInfo;
PduIdType soadTxPduId;
Std_ReturnType ret;
uint8 curNofOpenSockets;
soadTxPduId = DoIP_ConfigPtr->DoIP_UdpMsg[conIndex].DoIP_UdpSoADTxPduRef;
payloadLength = GET_PL_LEN_FROM_DOIP_MSG_PTR(rxBuffer);
/** @req SWS_DoIP_00095 */
if (PL_LEN_ENT_STATUS_REQ == payloadLength) {
if (BUFFER_IDLE == DoIP_UdpConAdmin[conIndex].txBufferState) {
curNofOpenSockets = getNofCurrentlyUsedTcpSockets();
/** @req SWS_DoIP_00096 */
DoIP_UdpConAdmin[conIndex].txBuffer[0u] = PROTOCOL_VERSION;
DoIP_UdpConAdmin[conIndex].txBuffer[1u] = ~(uint8)PROTOCOL_VERSION;
DoIP_UdpConAdmin[conIndex].txBuffer[2u] = (uint8)(PL_TYPE_ENT_STATUS_RES >> SHIFT_BY_ONE_BYTE);
DoIP_UdpConAdmin[conIndex].txBuffer[3u] = (uint8)PL_TYPE_ENT_STATUS_RES;
/* Length < 255, hence 2nd, 3rd and 4th byte of payload length field is 0 */
DoIP_UdpConAdmin[conIndex].txBuffer[4u] = 0u;
DoIP_UdpConAdmin[conIndex].txBuffer[5u] = 0u;
DoIP_UdpConAdmin[conIndex].txBuffer[6u] = 0u;
DoIP_UdpConAdmin[conIndex].txBuffer[7u] = PL_LEN_ENT_STATUS_RES;
/** @req SWS_DoIP_00097 */
DoIP_UdpConAdmin[conIndex].txBuffer[8u+0u] = DOIP_NODE_TYPE;
/** @req SWS_DoIP_00098 */
DoIP_UdpConAdmin[conIndex].txBuffer[8u+1u] = DOIP_MAX_TESTER_CONNECTIONS;
/** @req SWS_DoIP_00099 */
DoIP_UdpConAdmin[conIndex].txBuffer[8u+2u] = curNofOpenSockets;
#if (DOIP_ENTITY_MAX_BYTE_USE == STD_ON)
/** @req SWS_DoIP_00100 */
/*lint -e778 MISRA:FALSE_POSITIVE:Macro value DOIP_MAX_REQUEST_BYTES leads to false errors - Constant expression evaluates to 0 in operation '>>:Other */
DoIP_UdpConAdmin[conIndex].txBuffer[8u+3u] = (uint8)(DOIP_MAX_REQUEST_BYTES >> SHIFT_BY_THREE_BYTES);
/*lint -e778 MISRA:FALSE_POSITIVE:Macro value DOIP_MAX_REQUEST_BYTES leads to false errors - Constant expression evaluates to 0 in operation '>>:Other */
DoIP_UdpConAdmin[conIndex].txBuffer[8u+4u] = (uint8)(DOIP_MAX_REQUEST_BYTES >> SHIFT_BY_TW0_BYTES);
/*lint -e778 MISRA:FALSE_POSITIVE:Macro value DOIP_MAX_REQUEST_BYTES leads to false errors - Constant expression evaluates to 0 in operation '>>:Other */
DoIP_UdpConAdmin[conIndex].txBuffer[8u+5u] = (uint8)(DOIP_MAX_REQUEST_BYTES >> SHIFT_BY_ONE_BYTE);
DoIP_UdpConAdmin[conIndex].txBuffer[8u+6u] = (uint8)DOIP_MAX_REQUEST_BYTES;
#endif
txPduInfo.SduDataPtr = DoIP_UdpConAdmin[conIndex].txBuffer;
txPduInfo.SduLength = MSG_LEN_INCL_PL_LEN_FIELD + PL_LEN_ENT_STATUS_RES;
/** @req SWS_DoIP_00198 */
ret = SoAd_IfTransmit(soadTxPduId, &txPduInfo);
if (E_OK == ret) {
DoIP_UdpConAdmin[conIndex].txBufferState = BUFFER_LOCK;
} else {
DOIP_DET_REPORTERROR(DOIP_HANDLE_ENTITY_STATUS_REQ_ID, DOIP_E_IF_TRANSMIT_ERROR);
}
} else {
DOIP_DET_REPORTERROR(DOIP_HANDLE_ENTITY_STATUS_REQ_ID, DOIP_E_BUFFER_BUSY);
}
} else {
/* Invalid payload length! */
createAndSendNackIf(conIndex, ERROR_INVALID_PAYLOAD_LENGTH);
closeSocket(UDP_TYPE, conIndex, soadTxPduId);
}
}
static void handlePowerModeCheckReq(SoAd_SoConIdType conIndex,const uint8 *rxBuffer) {
DoIPPayloadType payloadLength;
PduInfoType txPduInfo;
PduIdType soadTxPduId;
DoIP_PowerStateType powerMode;
Std_ReturnType ret;
powerMode = DOIP_POWER_STATE_NOT_READY;
soadTxPduId = DoIP_ConfigPtr->DoIP_UdpMsg[conIndex].DoIP_UdpSoADTxPduRef;
payloadLength = GET_PL_LEN_FROM_DOIP_MSG_PTR(rxBuffer);
/** @req SWS_DoIP_00091 */
if (PL_LEN_POWER_MODE_REQ == payloadLength) {
if (BUFFER_IDLE == DoIP_UdpConAdmin[conIndex].txBufferState) {
#if (DOIPPWRMODECALLBACK_CONFIGURED == TRUE)
if (E_OK == DOIP_GETPWRMODECALLBACK_FUNCTION(&powerMode)) {
/** @req SWS_DoIP_00093 */
powerMode = DOIP_POWER_STATE_READY;
} else {
powerMode = DOIP_POWER_STATE_NOT_READY;
}
#endif
/** @req SWS_DoIP_00092 */
DoIP_UdpConAdmin[conIndex].txBuffer[0u] = PROTOCOL_VERSION;
DoIP_UdpConAdmin[conIndex].txBuffer[1u] = ~(uint8)PROTOCOL_VERSION;
DoIP_UdpConAdmin[conIndex].txBuffer[2u] = (uint8)(PL_TYPE_POWER_MODE_RES >> SHIFT_BY_ONE_BYTE);
DoIP_UdpConAdmin[conIndex].txBuffer[3u] = (uint8)PL_TYPE_POWER_MODE_RES;
/* Length < 255, hence 2nd, 3rd and 4th byte of payload length field is 0 */
DoIP_UdpConAdmin[conIndex].txBuffer[4u] = 0u;
DoIP_UdpConAdmin[conIndex].txBuffer[5u] = 0u;
DoIP_UdpConAdmin[conIndex].txBuffer[6u] = 0u;
DoIP_UdpConAdmin[conIndex].txBuffer[7u] = PL_LEN_POWER_MODE_RES;
/** @req SWS_DoIP_00093 */
DoIP_UdpConAdmin[conIndex].txBuffer[8u+0u] = (uint8)powerMode;
txPduInfo.SduDataPtr = DoIP_UdpConAdmin[conIndex].txBuffer;
txPduInfo.SduLength = MSG_LEN_INCL_PL_LEN_FIELD + PL_LEN_POWER_MODE_RES;
ret = SoAd_IfTransmit(soadTxPduId, &txPduInfo);
if (E_OK == ret) {
DoIP_UdpConAdmin[conIndex].txBufferState = BUFFER_LOCK;
} else {
DOIP_DET_REPORTERROR(DOIP_HANDLE_POWER_MODE_REQ_ID, DOIP_E_IF_TRANSMIT_ERROR);
}
} else {
DOIP_DET_REPORTERROR(DOIP_HANDLE_POWER_MODE_REQ_ID, DOIP_E_BUFFER_BUSY);
}
} else {
/* Invalid payload length! */
createAndSendNackIf(conIndex, ERROR_INVALID_PAYLOAD_LENGTH);
closeSocket(UDP_TYPE, conIndex, soadTxPduId);
}
}
static void handleTcpRx(SoAd_SoConIdType conIndex, uint8* rxBuffer) {
DoIPPayloadType payloadType;
payloadType = GET_PL_TYPE_FROM_DOIP_MSG_PTR(rxBuffer);
/** @req SWS_DoIP_0008 */ /** @req SWS_DoIP_00101 */ /** @req SWS_DoIP_00121 */
switch (payloadType) {
/*
* Vehicle identification requests are not supported over TCP
* 0x0001: Vehicle Identification Request
* 0x0002: Vehicle Identification Request with EID
* 0x0003: Vehicle Identification Request with VIN
*/
/* Routing Activation request */
case PL_TYPE_ROUT_ACTIV_REQ:
handleRoutingActivationReq(conIndex, rxBuffer);
break;
/* Alive check response */
case PL_TYPE_ALIVE_CHK_RES:
handleAliveCheckResp(conIndex, rxBuffer);
break;
/* Diagnostic message */
case PL_TYPE_DIAG_MSG:
handleDiagnosticMessage(conIndex, rxBuffer);
break;
default:
/* Unknown payload type! */
createAndSendNackTp(conIndex, ERROR_UNKNOWN_PAYLOAD_TYPE);
break;
}
}
static void handleUdpRx(SoAd_SoConIdType conIndex, const uint8* rxBuffer) {
DoIPPayloadType payloadType;
payloadType = GET_PL_TYPE_FROM_DOIP_MSG_PTR(rxBuffer);
/** @req SWS_DoIP_0008 */ /** @req SWS_DoIP_00061 */ /** @req SWS_DoIP_00062 */
/** @req SWS_DoIP_00064 */ /** @req SWS_DoIP_00067 */ /** @req SWS_DoIP_00069 */
/** @req SWS_DoIP_00090 */ /** @req SWS_DoIP_00094 */
switch (payloadType) {
/*
* 0x0005: Routing Activation request is not supported over UDP
* 0x8001: Diagnostic messages is not to be supported over UDP
*/
/* Vehicle Identification Request */
case PL_TYPE_VID_REQ:
handleVehicleIdentificationReq(conIndex, rxBuffer, ID_REQUEST_ALL);
break;
/* Vehicle Identification Request with EID */
case PL_TYPE_VID_EID_REQ:
handleVehicleIdentificationReq(conIndex, rxBuffer, ID_REQUEST_BY_EID);
break;
/* Vehicle Identification Request with VIN */
case PL_TYPE_VID_VIN_REQ:
handleVehicleIdentificationReq(conIndex, rxBuffer, ID_REQUEST_BY_VIN);
break;
/* DoIP entity status request */
case PL_TYPE_ENT_STATUS_REQ:
handleEntityStatusReq(conIndex, rxBuffer);
break;
/* DoIP power mode check request */
case PL_TYPE_POWER_MODE_REQ:
handlePowerModeCheckReq(conIndex, rxBuffer);
break;
default:
/* Unknown payload type! */
createAndSendNackIf(conIndex, ERROR_UNKNOWN_PAYLOAD_TYPE);
break;
}
}
/***** Global function - Definition *****/
/**
* @brief The service DoIP_TpTransmit Requests transmission of a PDU
* @note Reentrant for different PduIds. Non reentrant for the same PduId.
* @param[in] DoIPPduRTxId - Identifier of the PDU to be transmitted
* @param[in] DoIPPduRTxInfoPtr - Length of and pointer to the PDU data and pointer to MetaData
* @return Result of the function
*/
/** @req SWS_DoIP_00022 */
Std_ReturnType DoIP_TpTransmit(PduIdType DoIPPduRTxId, const PduInfoType* DoIPPduRTxInfoPtr) {
DoIPPayloadType bytesToTransmit;
PduInfoType txPdu;
PduIdType doipLoTxPduId;
PduIdType soadTxPduId;
DoIP_PduType pduType;
uint16 conIndex;
uint16 sourceAddress;
uint16 targetAddress;
Std_ReturnType retVal;
uint8 chIndex;
/** @req SWS_DoIP_00162 */
VALIDATE_W_RV((DoIP_Status == DOIP_INIT), DOIP_TP_TRANSMIT_SERVICE_ID, DOIP_E_UNINIT, E_NOT_OK);
for (chIndex = 0u; chIndex < DOIP_CHANNEL_COUNT; chIndex++) {
if (DoIP_ConfigPtr->DoIP_Channel[chIndex].DoIP_PduTransmitRef != NULL) {
if (DoIP_ConfigPtr->DoIP_Channel[chIndex].DoIP_PduTransmitRef->DoIP_TxPduRef == DoIPPduRTxId) {
break;
}
}
}
/** @req SWS_DoIP_00163 */
VALIDATE_W_RV((chIndex != DOIP_CHANNEL_COUNT), DOIP_TP_TRANSMIT_SERVICE_ID, DOIP_E_INVALID_PDU_SDU_ID, E_NOT_OK);
/** @req SWS_DoIP_00164 */
VALIDATE_W_RV((DoIPPduRTxInfoPtr != NULL_PTR) ,DOIP_TP_TRANSMIT_SERVICE_ID, DOIP_E_PARAM_POINTER, E_NOT_OK);
for (conIndex = 0u; conIndex < DOIP_TCP_CON_NUM; conIndex++) {
/* This is required since SBL is sending routine control OK without a request */
/** @req SWS_DoIP_00130 */
if ((CONNECTION_REGISTERED == DoIP_TcpConAdmin[conIndex].socketState)) {
break;
}
}
/** @req SWS_DoIP_00226 */
VALIDATE_W_RV((conIndex != DOIP_TCP_CON_NUM), DOIP_TP_TRANSMIT_SERVICE_ID, DOIP_E_INVALID_SOCKET_STATE, E_NOT_OK);
SchM_Enter_DoIP_EA_0();
/** @req SWS_DoIP_00230 */
if (BUFFER_IDLE == DoIP_TcpConAdmin[conIndex].txBufferState) {
pduType = DoIP_ConfigPtr->DoIP_Channel[chIndex].DoIP_PduTransmitRef->DoIP_TxPduType;
if (DOIP_TPPDU == pduType) {
bytesToTransmit = MSG_LEN_INCL_PL_LEN_FIELD + SA_AND_TA_LEN + DoIPPduRTxInfoPtr->SduLength;
txPdu.SduLength = (PduLengthType)bytesToTransmit;
soadTxPduId = DoIP_ConfigPtr->DoIP_TcpMsg[conIndex].DoIP_TcpSoADTxPduRef;
/** @req SWS_DoIP_00228 */
retVal = SoAd_TpTransmit(soadTxPduId, &txPdu);
if (E_OK == retVal) {
sourceAddress = DoIP_ConfigPtr->DoIP_Channel[chIndex].DoIP_ChannelTARef->DoIP_TargetAddrValue;
targetAddress = DoIP_ConfigPtr->DoIP_Channel[chIndex].DoIP_ChannelSARef->DoIP_TesterSA;
doipLoTxPduId = DoIP_ConfigPtr->DoIP_TcpMsg[conIndex].DoIP_TcpTxPduRef;
/** @req SWS_DoIP_00131 */ /** @req SWS_DoIP_00173 */
/** @req SWS_DoIP_00284 */
DoIP_TcpConAdmin[conIndex].txBuffer[0u] = PROTOCOL_VERSION;
DoIP_TcpConAdmin[conIndex].txBuffer[1u] = ~(uint8)(PROTOCOL_VERSION);
DoIP_TcpConAdmin[conIndex].txBuffer[2u] = (uint8)(PL_TYPE_DIAG_MSG >> SHIFT_BY_ONE_BYTE);
DoIP_TcpConAdmin[conIndex].txBuffer[3u] = (uint8)PL_TYPE_DIAG_MSG;
DoIP_TcpConAdmin[conIndex].txBuffer[4u] = 0u;
DoIP_TcpConAdmin[conIndex].txBuffer[5u] = 0u;
DoIP_TcpConAdmin[conIndex].txBuffer[6u] = (SA_AND_TA_LEN + DoIPPduRTxInfoPtr->SduLength) >> SHIFT_BY_ONE_BYTE;
DoIP_TcpConAdmin[conIndex].txBuffer[7u] = (uint8) (SA_AND_TA_LEN + DoIPPduRTxInfoPtr->SduLength);
DoIP_TcpConAdmin[conIndex].txBuffer[8u+0u] = sourceAddress >> SHIFT_BY_ONE_BYTE;
DoIP_TcpConAdmin[conIndex].txBuffer[8u+1u] = (uint8) sourceAddress;
DoIP_TcpConAdmin[conIndex].txBuffer[8u+2u] = targetAddress >> SHIFT_BY_ONE_BYTE;
DoIP_TcpConAdmin[conIndex].txBuffer[8u+3u] = (uint8) targetAddress;
DoIP_TcpConAdmin[conIndex].txBytesToTransmit = bytesToTransmit;
DoIP_TcpConAdmin[conIndex].txBytesCopied = MSG_LEN_INCL_PL_LEN_FIELD + SA_AND_TA_LEN;
DoIP_TcpConAdmin[conIndex].txBytesTransmitted = 0u;
DoIP_TcpConAdmin[conIndex].txPduIdUnderProgress = doipLoTxPduId;
DoIP_TcpConAdmin[conIndex].txBufferState = BUFFER_LOCK;
DoIP_TcpConAdmin[conIndex].channelIndex = chIndex;
DoIP_TcpConAdmin[conIndex].uLMsgTxInProgress = TRUE;
}
}else {
retVal = E_NOT_OK;
}
} else {
/** @req SWS_DoIP_00230 */
/* Push the transmission related data into the queue */
if ((FALSE == DoIP_TcpQueueAdmin[conIndex].tpTransmitQueueActive) &&
(FALSE == DoIP_TcpQueueAdmin[conIndex].diagAckQueueActive)) {
DoIP_TcpQueueAdmin[conIndex].tpTransmitQueueActive = TRUE;
DoIP_TcpQueueAdmin[conIndex].txPduId = DoIPPduRTxId;
DoIP_TcpQueueAdmin[conIndex].SduDataPtr = DoIPPduRTxInfoPtr->SduDataPtr;
DoIP_TcpQueueAdmin[conIndex].SduLength = DoIPPduRTxInfoPtr->SduLength;
retVal = E_OK;
} else {
DOIP_DET_REPORTERROR(DOIP_CREATE_AND_SEND_D_ACK_ID, DOIP_E_BUFFER_BUSY);
retVal = E_NOT_OK;
}
}
SchM_Exit_DoIP_EA_0();
return retVal;
}
/**
* @brief The service DoIP_TpCancelTransmit Requests cancellation of an ongoing transmission of a PDU in a lower layer
* @param[in] DoIPPduRTxId - Identification of the PDU to be canceled
* @return Result of the function
*/
/** @req SWS_DoIP_00023 */
Std_ReturnType DoIP_TpCancelTransmit(PduIdType DoIPPduRTxId) {
SoAd_SoConIdType conIndex;
Std_ReturnType retVal = FALSE;
uint8 chIndex;
/** @req SWS_DoIP_00166 */
VALIDATE_W_RV((DoIP_Status == DOIP_INIT), DOIP_TP_CANCEL_TRANSMIT_SERVICE_ID, DOIP_E_UNINIT, E_NOT_OK);
for (chIndex = 0u; chIndex < DOIP_CHANNEL_COUNT; chIndex++) {
if (DoIP_ConfigPtr->DoIP_Channel[chIndex].DoIP_PduTransmitRef->DoIP_TxPduRef == DoIPPduRTxId) {
break;
}
}
/** @req SWS_DoIP_00167 */
VALIDATE_W_RV((chIndex != DOIP_CHANNEL_COUNT), DOIP_TP_CANCEL_TRANSMIT_SERVICE_ID, DOIP_E_INVALID_PDU_SDU_ID, E_NOT_OK);
for (conIndex = 0u; conIndex < DOIP_TCP_CON_NUM;conIndex++) {
if((CONNECTION_REGISTERED == DoIP_TcpConAdmin[conIndex].socketState) && (DoIP_TcpConAdmin[conIndex].channelIndex == chIndex)){
break;
}
}
VALIDATE_W_RV((conIndex != DOIP_TCP_CON_NUM), DOIP_TP_CANCEL_TRANSMIT_SERVICE_ID, DOIP_E_INVALID_PDU_SDU_ID, E_NOT_OK);
/** @req SWS_DoIP_00257 */
if (E_OK == SoAd_TpCancelTransmit(DoIP_TcpConAdmin[conIndex].txPduIdUnderProgress)) {
freeTcpTxBuffer(conIndex);
retVal = TRUE;
}
return retVal;
}
/**
* @brief The service DoIP_IfTransmit Requests transmission of a PDU
* @note Non-Reentrant
* @param[in] id - Identification of the PDU to be canceled
* @param[in] info - Identification of the PDU to be canceled
* @return Result of the function
*/
/** @req SWS_DoIP_00277 */
/*lint --e{715} MISRA:OTHER:unsupported argument:[MISRA 2012 Rule 2.7, advisory] */
Std_ReturnType DoIP_IfTransmit(PduIdType id, const PduInfoType* info) {
VALIDATE_W_RV((DoIP_Status == DOIP_INIT), DOIP_IF_TRANSMIT_SERVICE_ID, DOIP_E_UNINIT, E_NOT_OK);
(void)id;
/* Not implemented */
return E_OK;
}
/**
* @brief The service DoIP_IfCancelTransmit Requests cancellation of an ongoing transmission of a PDU in
* a lower layer communication module
* @note Non-Reentrant
* @param[in] id - Identification of the PDU to be canceled
* @return Result of the function
*/
/** @req SWS_DoIP_00278*/
Std_ReturnType DoIP_IfCancelTransmit(PduIdType id) {
VALIDATE_W_RV((DoIP_Status == DOIP_INIT), DOIP_IF_CANCEL_TRANSMIT_SERVICE_ID, DOIP_E_UNINIT, E_NOT_OK);
/* Not implemented */
return E_OK;
}
/**
* @brief The service DoIP_Init Initializes all global variables of the DoIP module.
* After return of this service, the DoIP module is operational
* @note Non-Reentrant
* @param[in] DoIPConfigPtr - Pointer to the configuration data of the DoIP module
*/
/** @req SWS_DoIP_00026 */
void DoIP_Init(const DoIP_ConfigType* DoIPConfigPtr) {
SoAd_SoConIdType conIndex;
VALIDATE((DoIPConfigPtr != NULL_PTR) ,DOIP_INIT_SERVICE_ID, DOIP_E_PARAM_POINTER);
DoIP_ConfigPtr = DoIPConfigPtr;
DoIP_Status = DOIP_INIT;
DoIP_ActivationLineStatus = ACTIVATION_LINE_INACTIVE;
for (conIndex = 0u; conIndex < DOIP_TCP_CON_NUM; conIndex++) {
resetTcpConnection(conIndex);
}
for (conIndex = 0u; conIndex < DOIP_UDP_CON_NUM; conIndex++) {
resetUdpConnection(conIndex);
}
DoIP_VinUpdated = FALSE;
DoIP_EidUpdated = FALSE;
#if (DOIPTGRGIDSYNCCALLBACK_CONFIGURED == TRUE) && (DOIP_VIN_GID_MASTER == STD_ON)
DoIP_GidSyncDone = FALSE;
#endif
DoIP_PendingRoutActivFlag = FALSE;
}
/**
* @brief The service DoIP_GetVersionInfo Returns the version information of this module
* @note Reentrant
* @param[out] versioninfo - Pointer to where to store the version information of this module
*/
/** @req SWS_DoIP_00027 */
void DoIP_GetVersionInfo(Std_VersionInfoType* versioninfo) {
/** @req SWS_DoIP_00172 */
VALIDATE((NULL != versioninfo),DOIP_GET_VERSION_INFO_SERVICE_ID,DOIP_E_PARAM_POINTER);
versioninfo->vendorID = DOIP_VENDOR_ID;
versioninfo->moduleID = DOIP_MODULE_ID;
versioninfo->sw_major_version = DOIP_SW_MAJOR_VERSION;
versioninfo->sw_minor_version = DOIP_SW_MINOR_VERSION;
versioninfo->sw_patch_version = DOIP_SW_PATCH_VERSION;
}
/**
* @brief The service DoIP_SoAdTpCopyTxData Acquires the transmit data of an I-PDU segment
* @note Reentrant
* @param[in] id - Identifier of the PDU to be transmitted
* @param[in] info - Provides the destination buffer and the number of bytes to be copied
* @param[in] retry - Used to acknowledge transmitted data or to retransmit data after transmission problems
* @param[out] availableDataPtr - Indicates the remaining number of bytes that are available in the upper layer module's Tx buffer
* @return Result of the function
*/
/** @req SWS_DoIP_00031 */
/*lint --e{818} MISRA:STANDARDIZED_INTERFACE:Pointer parameter 'retry' could be declared as pointing to const:[MISRA 2004 Rule 16.7, advisory] */
BufReq_ReturnType DoIP_SoAdTpCopyTxData(PduIdType id, const PduInfoType* info, RetryInfoType* retry, PduLengthType* availableDataPtr) {
PduInfoType pudInfo;
PduLengthType sduLenghtToTransmit;
SoAd_SoConIdType conIndex;
PduIdType pduRTxId;
DoIP_PduType pduType;
BufReq_ReturnType retVal;
uint8 chIndex;
pudInfo.SduDataPtr = info->SduDataPtr;
pudInfo.SduLength = info->SduLength;
retVal = BUFREQ_E_NOT_OK;
/** @req SWS_DoIP_00175 */
VALIDATE_W_RV((DoIP_Status == DOIP_INIT), DOIP_SOAD_TP_COPY_TX_DATA_SERVICE_ID, DOIP_E_UNINIT, BUFREQ_E_NOT_OK);
for (conIndex = 0u; conIndex < DOIP_TCP_CON_NUM; conIndex++) {
if (DoIP_ConfigPtr->DoIP_TcpMsg[conIndex].DoIP_TcpTxPduRef == id) {
/* Match! */
break;
}
}
/** @req SWS_DoIP_00176 */
VALIDATE_W_RV(conIndex != DOIP_TCP_CON_NUM, DOIP_SOAD_TP_COPY_TX_DATA_SERVICE_ID, DOIP_E_INVALID_PDU_SDU_ID, BUFREQ_E_NOT_OK);
/** @req SWS_DoIP_00177 */
VALIDATE_W_RV((info != NULL_PTR), DOIP_SOAD_TP_COPY_TX_DATA_SERVICE_ID, DOIP_E_PARAM_POINTER, BUFREQ_E_NOT_OK);
VALIDATE_W_RV((availableDataPtr != NULL_PTR), DOIP_SOAD_TP_COPY_TX_DATA_SERVICE_ID, DOIP_E_PARAM_POINTER, BUFREQ_E_NOT_OK);
SchM_Enter_DoIP_EA_0();
if ((DoIP_TcpConAdmin[conIndex].uLMsgTxInProgress != TRUE) ||
((TRUE == DoIP_TcpConAdmin[conIndex].uLMsgTxInProgress) && (CONNECTION_REGISTERED == DoIP_TcpConAdmin[conIndex].socketState))) {
if (BUFFER_LOCK == DoIP_TcpConAdmin[conIndex].txBufferState) {
if (DoIP_TcpConAdmin[conIndex].txPduIdUnderProgress == id) {
sduLenghtToTransmit = pudInfo.SduLength;
if (sduLenghtToTransmit == 0u) {
/** @req SWS_DoIP_00224 */
*availableDataPtr = (PduLengthType) ( DoIP_TcpConAdmin[conIndex].txBytesToTransmit - DoIP_TcpConAdmin[conIndex].txBytesTransmitted );
retVal = BUFREQ_OK;
} else if (sduLenghtToTransmit > (DoIP_TcpConAdmin[conIndex].txBytesToTransmit - DoIP_TcpConAdmin[conIndex].txBytesTransmitted)) {
retVal = BUFREQ_NOT_OK;
} else {
/** @req SWS_DoIP_00225 */
if (0 == DoIP_TcpConAdmin[conIndex].txBytesTransmitted) {
memcpy(pudInfo.SduDataPtr, DoIP_TcpConAdmin[conIndex].txBuffer, DoIP_TcpConAdmin[conIndex].txBytesCopied);
DoIP_TcpConAdmin[conIndex].txBytesTransmitted += DoIP_TcpConAdmin[conIndex].txBytesCopied;
/*lint -e9016 MISRA:OTHER:pointer arithmetic other than array indexing used:[MISRA 2012 Rule 18.4, advisory] */
pudInfo.SduDataPtr += DoIP_TcpConAdmin[conIndex].txBytesTransmitted;
pudInfo.SduLength -= (PduLengthType)DoIP_TcpConAdmin[conIndex].txBytesTransmitted;
retVal = BUFREQ_OK;
}
if (DoIP_TcpConAdmin[conIndex].txBytesTransmitted < DoIP_TcpConAdmin[conIndex].txBytesToTransmit) {
retVal = BUFREQ_NOT_OK;
chIndex = DoIP_TcpConAdmin[conIndex].channelIndex;
if (chIndex != INVALID_CHANNEL_INDEX) {
if (DoIP_ConfigPtr->DoIP_Channel[chIndex].DoIP_PduTransmitRef != NULL) {
pduType = DoIP_ConfigPtr->DoIP_Channel[chIndex].DoIP_PduTransmitRef->DoIP_TxPduType;
if (DOIP_TPPDU == pduType) {
pduRTxId = DoIP_ConfigPtr->DoIP_Channel[chIndex].DoIP_UpperLayerTxPduId;
/** @req SWS_DoIP_00232 */ /** @req SWS_DoIP_00233 */
retVal = PduR_DoIPTpCopyTxData(pduRTxId, &pudInfo, /* retry */NULL, availableDataPtr);
if (retVal == BUFREQ_OK) {
DoIP_TcpConAdmin[conIndex].txBytesTransmitted += pudInfo.SduLength;
}
} else {
DOIP_DET_REPORTERROR(DOIP_HANDLE_VEHICLE_ID_REQ_ID, DOIP_E_UNEXPECTED_EXECUTION);
}
} else {
retVal = BUFREQ_OK;
}
} else {
/* We should not end up here */
DOIP_DET_REPORTERROR(DOIP_HANDLE_VEHICLE_ID_REQ_ID, DOIP_E_UNEXPECTED_EXECUTION);
}
}
if (BUFREQ_OK == retVal) {
/** @req SWS_DoIP_00254 */
*availableDataPtr = (PduLengthType)(DoIP_TcpConAdmin[conIndex].txBytesToTransmit - DoIP_TcpConAdmin[conIndex].txBytesTransmitted);
}
}
} else {
retVal = BUFREQ_NOT_OK;
}
} else {
retVal = BUFREQ_NOT_OK;
}
} else {
retVal = BUFREQ_NOT_OK;
}
SchM_Exit_DoIP_EA_0();
return retVal;
}
/**
* @brief The service DoIP_SoAdTpTxConfirmation Is called after the I-PDU has been transmitted on its network.
* The result indicates whether the transmission was successful or not
* @note Reentrant
* @param[in] id - Identification of the transmitted I-PDU
* @param[in] result - Result of the transmission of the I-PDU
*/
/** @req SWS_DoIP_00032 */
void DoIP_SoAdTpTxConfirmation(PduIdType id, Std_ReturnType result) {
PduIdType pduRTxId;
SoAd_SoConIdType SoConId;
SoAd_SoConIdType conIndex;
uint8 chIndex;
/** @req SWS_DoIP_00180 */
VALIDATE((DoIP_Status == DOIP_INIT), DOIP_SOAD_TP_TX_CONFIRMATION_SERVICE_ID, DOIP_E_UNINIT);
for (conIndex = 0u; conIndex < DOIP_TCP_CON_NUM; conIndex++) {
if (DoIP_ConfigPtr->DoIP_TcpMsg[conIndex].DoIP_TcpTxPduRef == id) {
/* Match! */
break;
}
}
/** @req SWS_DoIP_00181*/
VALIDATE((conIndex != DOIP_TCP_CON_NUM), DOIP_SOAD_TP_TX_CONFIRMATION_SERVICE_ID, DOIP_E_INVALID_PDU_SDU_ID);
if (TRUE == DoIP_TcpConAdmin[conIndex].closeSocketIndication) {
/** @req SWS_DoIP_00058 */
(void)SoAd_GetSoConId(DoIP_ConfigPtr->DoIP_UdpMsg[conIndex].DoIP_UdpSoADTxPduRef, &SoConId);
(void)SoAd_CloseSoCon(SoConId, TRUE);
resetTcpConnection(conIndex);
} else {
SchM_Enter_DoIP_EA_0();
if (BUFFER_LOCK == DoIP_TcpConAdmin[conIndex].txBufferState) {
if (DoIP_TcpConAdmin[conIndex].txPduIdUnderProgress == id) {
chIndex = DoIP_TcpConAdmin[conIndex].channelIndex;
if (chIndex != INVALID_CHANNEL_INDEX) {
if (DoIP_ConfigPtr->DoIP_Channel[chIndex].DoIP_PduTransmitRef != NULL) {
pduRTxId = DoIP_ConfigPtr->DoIP_Channel[chIndex].DoIP_UpperLayerTxPduId;
/** @req SWS_DoIP_00232 */ /** @req SWS_DoIP_00233 */
PduR_DoIPTpTxConfirmation(pduRTxId, result);
if (TRUE == DoIP_TcpConAdmin[conIndex].uLMsgTxInProgress) {
DoIP_TcpConAdmin[conIndex].uLMsgTxInProgress = FALSE;
}
} else {
DOIP_DET_REPORTERROR(DOIP_HANDLE_VEHICLE_ID_REQ_ID, DOIP_E_INVALID_PDU_SDU_ID);
}
} else {
DOIP_DET_REPORTERROR(DOIP_CREATE_AND_SEND_NACK_ID, DOIP_E_INVALID_CH_INDEX);
}
}
}
/** @req SWS_DoIP_00229 */
freeTcpTxBuffer(conIndex);
SchM_Exit_DoIP_EA_0();
}
}
/**
* @brief The service DoIP_SoAdTpCopyRxData Provides the received data of an I-PDU segment (N-PDU) to the upper layer
* @note Reentrant
* @param[in] id - Identification of the transmitted I-PDU
* @param[in] info - Provides the source buffer and the number of bytes to be copied
* @param[out] bufferSizePtr - Available receive buffer after data has been copied
* @return Result of the function
*/
/** @req SWS_DoIP_00033 */ /** @req SWS_DoIP_00219 */
BufReq_ReturnType DoIP_SoAdTpCopyRxData(PduIdType id,const PduInfoType* info,PduLengthType* bufferSizePtr) {
static DoIPPayloadType payloadLength;
static DoIPPayloadType sduDataIndex;
PduLengthType sduLengthToProcess;
SoAd_SoConIdType conIndex;
BufReq_ReturnType ret;
Std_ReturnType protocolHeader;
/** @req SWS_DoIP_00183 */
VALIDATE_W_RV((DoIP_Status == DOIP_INIT), DOIP_SOAD_TP_COPY_RX_DATA_SERVICE_ID, DOIP_E_UNINIT, BUFREQ_E_NOT_OK);
for (conIndex = 0u; conIndex < DOIP_TCP_CON_NUM; conIndex++) {
if (DoIP_ConfigPtr->DoIP_TcpMsg[conIndex].DoIP_TcpRxPduRef == id) {
break;
}
}
/** @req SWS_DoIP_00036 */
VALIDATE_W_RV((conIndex != DOIP_TCP_CON_NUM), DOIP_SOAD_TP_COPY_RX_DATA_SERVICE_ID, DOIP_E_INVALID_PDU_SDU_ID, BUFREQ_E_NOT_OK);
/** @req SWS_DoIP_00184 */
VALIDATE_W_RV((bufferSizePtr != NULL_PTR), DOIP_SOAD_TP_COPY_RX_DATA_SERVICE_ID, DOIP_E_PARAM_POINTER, BUFREQ_E_NOT_OK);
VALIDATE_W_RV((info != NULL_PTR), DOIP_SOAD_TP_COPY_RX_DATA_SERVICE_ID, DOIP_E_PARAM_POINTER, BUFREQ_E_NOT_OK);
sduLengthToProcess = info->SduLength;
if ((BUFFER_IDLE == DoIP_TcpConRxBufferAdmin.bufferState) || \
((BUFFER_LOCK_START == DoIP_TcpConRxBufferAdmin.bufferState) && (id == DoIP_TcpConRxBufferAdmin.pduIdUnderProgress))) {
if (0 == sduLengthToProcess) {
/** @req SWS_DoIP_00208 */
*bufferSizePtr = TCP_RX_BUFF_SIZE;
ret = BUFREQ_OK;
} else {
if (sduLengthToProcess <= DoIP_TcpRxRemainingBufferSize) {
protocolHeader = E_OK;
if (TCP_RX_BUFF_SIZE == DoIP_TcpRxRemainingBufferSize) {
/** @req SWS_DoIP_00102 */
if ((PROTOCOL_VERSION == info->SduDataPtr[0u]) && (PROTOCOL_VERSION == (uint8)(~info->SduDataPtr[1u]))) {
protocolHeader = E_OK;
payloadLength = GET_PL_LEN_FROM_DOIP_MSG_PTR(info->SduDataPtr);
sduDataIndex = 0u;
} else {
protocolHeader = E_NOT_OK;
}
}
if (E_OK == protocolHeader) {
/** @req SWS_DoIP_00209 */ /** @req SWS_DoIP_00214 */
memcpy(&(DoIP_TcpConRxBufferAdmin.buffer[sduDataIndex]), &(info->SduDataPtr[0u]), sduLengthToProcess);
sduDataIndex = sduDataIndex + sduLengthToProcess;
if ((sduDataIndex - MSG_LEN_INCL_PL_LEN_FIELD) == payloadLength) {
handleTcpRx(conIndex, DoIP_TcpConRxBufferAdmin.buffer);
freeTcpRxBuffer();
sduDataIndex = 0u;
payloadLength = 0u;
DoIP_TcpRxRemainingBufferSize = TCP_RX_BUFF_SIZE ;
} else {
DoIP_TcpRxRemainingBufferSize = DoIP_TcpRxRemainingBufferSize - sduLengthToProcess;
*bufferSizePtr = (PduLengthType) DoIP_TcpRxRemainingBufferSize;
}
ret = BUFREQ_OK;
} else {
ret = BUFREQ_E_NOT_OK;
}
} else {
/** @req SWS_DoIP_00210 */
ret = BUFREQ_E_NOT_OK;
}
}
} else {
ret = BUFREQ_E_NOT_OK;
}
return ret;
}
/**
* @brief The service DoIP_SoAdTpStartOfReception Is called at the start of receiving an N-SDU
* @note Reentrant
* @param[in] id - Identification of the I-PDU.
* @param[in] info - Pointer to a PduInfoType structure containing the payload data and payload length of
* of the first frame or the single frame
* @param[in] TpSduLength - Total length of the N-SDU to be received
* @param[out] bufferSizePtr - Available receive buffer in the receiving module
* @return Result of the function
*/
/** @req SWS_DoIP_00037 */
BufReq_ReturnType DoIP_SoAdTpStartOfReception(PduIdType id, const PduInfoType* info, PduLengthType TpSduLength, PduLengthType* bufferSizePtr) {
SoAd_SoConIdType conIndex;
BufReq_ReturnType ret;
/** @req SWS_DoIP_00186 */
VALIDATE_W_RV(DoIP_Status == DOIP_INIT, DOIP_SOAD_TP_START_OF_RECEPTION_SERVICE_ID, DOIP_E_UNINIT, BUFREQ_E_NOT_OK);
/** @req SWS_DoIP_00187 */
for (conIndex = 0u; conIndex < DOIP_TCP_CON_NUM; conIndex++) {
if (DoIP_ConfigPtr->DoIP_TcpMsg[conIndex].DoIP_TcpRxPduRef == id) {
break;
}
}
VALIDATE_W_RV(conIndex != DOIP_TCP_CON_NUM, DOIP_SOAD_TP_START_OF_RECEPTION_SERVICE_ID, DOIP_E_INVALID_PDU_SDU_ID, BUFREQ_E_NOT_OK);
/** @req SWS_DoIP_00188 */
VALIDATE_W_RV((bufferSizePtr != NULL_PTR), DOIP_SOAD_TP_START_OF_RECEPTION_SERVICE_ID, DOIP_E_PARAM_POINTER, BUFREQ_E_NOT_OK);
/** @req SWS_DoIP_00189 */
VALIDATE_W_RV((TpSduLength != 0u), DOIP_SOAD_TP_START_OF_RECEPTION_SERVICE_ID, DOIP_E_INVALID_PARAMETER, BUFREQ_E_NOT_OK);
VALIDATE_W_RV((info != NULL_PTR), DOIP_SOAD_TP_START_OF_RECEPTION_SERVICE_ID, DOIP_E_PARAM_POINTER, BUFREQ_E_NOT_OK);
if (BUFFER_IDLE == DoIP_TcpConRxBufferAdmin.bufferState) {
/** @req SWS_DoIP_00004 */ /** @req SWS_DoIP_00005 */ /** @req SWS_DoIP_00006 */
if ((PROTOCOL_VERSION == info->SduDataPtr[0u]) && (PROTOCOL_VERSION == (uint8)(~info->SduDataPtr[1u]))) {
if (info->SduLength <= TCP_RX_BUFF_SIZE) {
/** @req SWS_DoIP_00207 */
DoIP_TcpConRxBufferAdmin.bufferState = BUFFER_LOCK_START;
DoIP_TcpConRxBufferAdmin.pduIdUnderProgress = id;
*bufferSizePtr = TCP_RX_BUFF_SIZE;
DoIP_TcpRxRemainingBufferSize = TCP_RX_BUFF_SIZE;
ret = BUFREQ_OK;
} else {
createAndSendNackTp(conIndex, ERROR_OUT_OF_MEMORY);
ret = BUFREQ_OVFL;
}
} else {
/** @req SWS_DoIP_00012 */ /** @req SWS_DoIP_00013 */
createAndSendNackTp(conIndex, ERROR_INCORRECT_PATTERN_FORMAT);
closeSocket(TCP_TYPE, conIndex, DoIP_ConfigPtr->DoIP_TcpMsg[conIndex].DoIP_TcpSoADTxPduRef);
ret = BUFREQ_NOT_OK;
}
}
else {
ret = BUFREQ_NOT_OK;
}
return ret;
}
/**
* @brief The service DoIP_SoAdTpRxIndication Is called after an I-PDU has been received via the TP API.
* @note Reentrant
* @param[in] id - Identification of the received I-PDU
* @param[in] result - Result of the reception
*/
/** @req SWS_DoIP_00038 */
void DoIP_SoAdTpRxIndication(PduIdType id, Std_ReturnType result) {
SoAd_SoConIdType conIndex;
/** @req SWS_DoIP_00190 */
VALIDATE((DoIP_Status == DOIP_INIT), DOIP_SOAD_TP_RX_INDICATION_SERVICE_ID, DOIP_E_UNINIT);
/** @req SWS_DoIP_00191 */
for (conIndex = 0u; conIndex < DOIP_TCP_CON_NUM; conIndex++) {
if (DoIP_ConfigPtr->DoIP_TcpMsg[conIndex].DoIP_TcpRxPduRef == id) {
break;
}
}
VALIDATE(conIndex != DOIP_TCP_CON_NUM, DOIP_SOAD_TP_RX_INDICATION_SERVICE_ID, DOIP_E_INVALID_PDU_SDU_ID);
/** @req SWS_DoIP_00200 */
freeTcpRxBuffer();
}
/**
* @brief The service DoIP_SoAdIfRxIndication Provides an indication of a received PDU from a lower layer communication interface module
* @note Reentrant for different PduIds. Non reentrant for the same PduId
* @param[in] RxPduId- ID of the received PDU
* @param[in] PduInfoPtr- Contains the length and a pointer to a buffer of the received PDU.
*/
/** @req SWS_DoIP_00244 */
/*lint -e{9011} MISRA:OTHER:more than one 'break' terminates loop:[MISRA 2012 Rule 15.4, advisory] */
void DoIP_SoAdIfRxIndication(PduIdType RxPduId,const PduInfoType* PduInfoPtr) {
DoIPPayloadType payloadLength;
DoIPPayloadType sduDataIndex;
DoIPPayloadType sduLengthToProcess;
SoAd_SoConIdType conIndex;
/* Check for DoIP initialization */
/** @req SWS_DoIP_00246 */
VALIDATE((DoIP_Status == DOIP_INIT), DOIP_SOAD_IF_RX_INDICATION_SERVICE_ID, DOIP_E_UNINIT);
/** @req SWS_DoIP_00247 */
for (conIndex = 0u; conIndex < DOIP_UDP_CON_NUM; conIndex++) {
if(DoIP_ConfigPtr->DoIP_UdpMsg[conIndex].DoIP_UdpRxPduRef == RxPduId) {
break;
}
}
VALIDATE((conIndex != DOIP_UDP_CON_NUM), DOIP_SOAD_IF_RX_INDICATION_SERVICE_ID, DOIP_E_INVALID_PDU_SDU_ID);
if (0u == PduInfoPtr->SduLength) {
DOIP_DET_REPORTERROR(DOIP_SOAD_IF_RX_INDICATION_SERVICE_ID, DOIP_E_INVALID_PARAMETER);
} else {
sduLengthToProcess = PduInfoPtr->SduLength;
sduDataIndex = 0u;
while (sduLengthToProcess > 0u) {
if ((DoIP_UdpConAdmin[conIndex].rxBufferStartIndex < DoIP_UdpConAdmin[conIndex].rxBufferEndIndex) ||
((uint8)(DoIP_UdpConAdmin[conIndex].rxBufferStartIndex - DoIP_UdpConAdmin[conIndex].rxBufferEndIndex) < (uint8)(DOIP_MAX_UDP_REQUEST_MESSAGE - 1u)) ||
((DoIP_UdpConAdmin[conIndex].rxBufferStartIndex == DoIP_UdpConAdmin[conIndex].rxBufferEndIndex) && (FALSE == DoIP_UdpConAdmin[conIndex].rxBufferPresent))) {
/** @req SWS_DoIP_00004 */ /** @req SWS_DoIP_00005 */ /** @req SWS_DoIP_00006 */ /** @req SWS_DoIP_00015 */
if ( ((PROTOCOL_VERSION == PduInfoPtr->SduDataPtr[sduDataIndex]) && (PROTOCOL_VERSION == (uint8)(~PduInfoPtr->SduDataPtr[sduDataIndex + 1u]))) ||
((PROTOCOL_VERSION_VID == PduInfoPtr->SduDataPtr[sduDataIndex]) && (PROTOCOL_VERSION_VID == (uint8)(~PduInfoPtr->SduDataPtr[sduDataIndex + 1u])))) {
payloadLength = GET_PL_LEN_FROM_DOIP_MSG_PTR(PduInfoPtr->SduDataPtr);
if ( (payloadLength + MSG_LEN_INCL_PL_LEN_FIELD) <= UDP_RX_BUFF_SIZE) {
DoIP_UdpConAdmin[conIndex].rxPduIdUnderProgress = RxPduId;
/** @req SWS_DoIP_00197 */
memcpy(&(DoIP_UdpConAdmin[conIndex].rxBuffer[DoIP_UdpConAdmin[conIndex].rxBufferStartIndex][0u]), &(PduInfoPtr->SduDataPtr[sduDataIndex]), (payloadLength + MSG_LEN_INCL_PL_LEN_FIELD));
if (DoIP_UdpConAdmin[conIndex].rxBufferStartIndex < (DOIP_MAX_UDP_REQUEST_MESSAGE - 1u)) {
DoIP_UdpConAdmin[conIndex].rxBufferStartIndex ++;
} else {
DoIP_UdpConAdmin[conIndex].rxBufferStartIndex = UDP_RX_BUFFER_RESET_INDEX;
}
if ((UDP_RX_BUFFER_RESET_INDEX == DoIP_UdpConAdmin[conIndex].rxBufferStartIndex) && (UDP_RX_BUFFER_RESET_INDEX == DoIP_UdpConAdmin[conIndex].rxBufferEndIndex)) {
DoIP_UdpConAdmin[conIndex].rxBufferPresent = TRUE;
}
sduDataIndex = sduDataIndex + (MSG_LEN_INCL_PL_LEN_FIELD + payloadLength);
sduLengthToProcess = sduLengthToProcess - (MSG_LEN_INCL_PL_LEN_FIELD + payloadLength);
} else {
createAndSendNackIf(conIndex, ERROR_MESSAGE_TOO_LARGE);
break;
}
} else {
/** @req SWS_DoIP_00012 */ /** @req SWS_DoIP_00013 */
createAndSendNackIf(conIndex, ERROR_INCORRECT_PATTERN_FORMAT);
closeSocket(UDP_TYPE, conIndex, DoIP_ConfigPtr->DoIP_UdpMsg[conIndex].DoIP_UdpSoADTxPduRef);
break;
}
} else {
/** @req SWS_DoIP_00004 */ /** @req SWS_DoIP_00005 */ /** @req SWS_DoIP_00006 */ /** @req SWS_DoIP_00015 */
if ( ((PROTOCOL_VERSION == PduInfoPtr->SduDataPtr[sduDataIndex]) && (PROTOCOL_VERSION == (uint8)(~PduInfoPtr->SduDataPtr[sduDataIndex + 1u]))) ||
((PROTOCOL_VERSION_VID == PduInfoPtr->SduDataPtr[sduDataIndex]) && (PROTOCOL_VERSION_VID == (uint8)(~PduInfoPtr->SduDataPtr[sduDataIndex + 1u])))) {
/** @req SWS_DoIP_00276 */
createAndSendNackIf(conIndex, ERROR_OUT_OF_MEMORY);
break;
}
}
}
}
}
/**
* @brief The service DoIP_SoAdIfTxConfirmation Confirms the transmission of a PDU, or the failure to transmit a PDU
* @note Reentrant for different PduIds. Non reentrant for the same PduId
* @param[in] TxPduId - ID of the PDU that has been transmitted
*/
/** @req SWS_DoIP_00245 */
void DoIP_SoAdIfTxConfirmation(PduIdType TxPduId) {
SoAd_SoConIdType conIndex;
/** @req SWS_DoIP_00249 */
VALIDATE((DoIP_Status == DOIP_INIT), DOIP_SOAD_IF_TX_CONFIRMATION_SERVICE_ID, DOIP_E_UNINIT);
/** @req SWS_DoIP_00250 */
for (conIndex = 0u; conIndex < DOIP_UDP_CON_NUM; conIndex++) {
if (DoIP_ConfigPtr->DoIP_UdpMsg[conIndex].DoIP_UdpTxPduRef == TxPduId) {
/* Match! */
break;
}
}
VALIDATE((conIndex != DOIP_UDP_CON_NUM), DOIP_SOAD_IF_TX_CONFIRMATION_SERVICE_ID, DOIP_E_INVALID_PDU_SDU_ID);
/** @req SWS_DoIP_00199 */
freeUdpTxBuffer(conIndex);
}
/**
* @brief The service DoIP_SoConModeChg Provides notification about a SoAd socket connection state change
* @note Reentrant for different SoConIds. Non reentrant for the same SoConId.
* @param[in] SoConId - socket connection index specifying the socket connection with the mode change
* @param[in] Mode - new mode
*/
/** @req SWS_DoIP_0039 */
void DoIP_SoConModeChg(SoAd_SoConIdType SoConId, SoAd_SoConModeType Mode) {
SoAd_SoConIdType conIndex;
Std_ReturnType ret;
DoIP_Internal_ConType con;
/** @req SWS_DoIP_00193 */
VALIDATE((DoIP_Status == DOIP_INIT), DOIP_SO_CON_MODE_CHG_SERVICE_ID, DOIP_E_UNINIT);
ret = getConTypeConIndexFromSoConId(SoConId, &con, &conIndex);
if (E_OK == ret) {
switch (Mode) {
case SOAD_SOCON_ONLINE:
case SOAD_SOCON_RECONNECT:
/* Note: Even though specification states if ONLINE is reported then connection has to
* be established. But SWS_SOAD_00686 states TCP always reports RECONNECT and
* UDP can report RECONNECT if either remote IP is 0.0.0.0 or remote port is 0.
* RECONNECT is equivalent to ONLINE.
*/
/** @req SWS_DoIP_00241 */
if (TCP_TYPE == con) {
DoIP_TcpConAdmin[conIndex].sockNr = SoConId;
/** @req SWS_DoIP_00143 */
DoIP_TcpConAdmin[conIndex].socketState = CONNECTION_INITIALIZED;
} else if (UDP_TYPE == con) {
DoIP_UdpConAdmin[conIndex].sockNr = SoConId;
DoIP_UdpConAdmin[conIndex].socketState = CONNECTION_INITIALIZED;
/** @req SWS_DoIP_00205 */
DoIP_UdpConAdmin[conIndex].vehicleAnnounceTgr = TRUE;
} else {
}
break;
case SOAD_SOCON_OFFLINE:
default:
/** @req SWS_DoIP_00243 */
if (TCP_TYPE == con) {
resetTcpConnection(conIndex);
} else {
resetUdpConnection(conIndex);
}
break;
}
}
}
/**
* @brief The service DoIP_LocalIpAddrAssignmentChg Is called by the SoAd if an IP address assignment related to a socket connection changes
* @note Reentrant for different SoConIds. Non reentrant for the same SoConId.
* @param[in] SoConId - socket connection index specifying the socket connection where the IP address assignment has changed
* @param[in] State - state of IP address assignment
*/
/** @req SWS_DoIP_00040 */
void DoIP_LocalIpAddrAssignmentChg(SoAd_SoConIdType SoConId, TcpIp_IpAddrStateType State) {
/** @req SWS_DoIP_00195 */
VALIDATE((DoIP_Status == DOIP_INIT), DOIP_LOCAL_IP_ADDR_ASSIGN_CHG_SERVICE_ID, DOIP_E_UNINIT);
/* Not implemented. Not supported in stack */
switch (State) {
case TCPIP_IPADDR_STATE_ASSIGNED:
break;
default:
break;
}
}
/**
* @brief The service DoIP_ActivationLineSwitchActive Is used to notify the DoIP on a switch of the DoIPActivationLine to active
* @note Non Reentrant
*/
/** @req SWS_DoIP_00251 */
void DoIP_ActivationLineSwitchActive(void) {
SoAd_SoConIdType SoConId;
SoAd_SoConIdType conIndex;
Std_ReturnType ret;
/** @req SWS_DoIP_00252 */
VALIDATE((DoIP_Status == DOIP_INIT), DOIP_ACTIVATION_LINE_SW_ACTIVE_SERVICE_ID, DOIP_E_UNINIT);
if (ACTIVATION_LINE_INACTIVE == DoIP_ActivationLineStatus) {
/** @req SWS_DoIP_00204 */
ret = SoAd_GetSoConId(DoIP_ConfigPtr->DoIP_UdpMsg[0].DoIP_UdpSoADTxPduRef, &SoConId);
if (E_OK == ret) {
#if (TCPIP_DHCP_CLIENT_ENABLED == STD_ON)
uint8 netmask = 0u;
TcpIp_SockAddrType DefaultRouter;
DefaultRouter.domain = TCPIP_AF_INET;
DefaultRouter.addr[0u] = 255u;
DefaultRouter.addr[1u] = 255u;
DefaultRouter.addr[2u] = 255u;
DefaultRouter.addr[3u] = 255u;
DefaultRouter.port = 13400u;
(void)SoAd_RequestIpAddrAssignment(SoConId, TCPIP_IPADDR_ASSIGNMENT_LINKLOCAL_DOIP, NULL_PTR, netmask, &DefaultRouter);
(void)SoAd_RequestIpAddrAssignment(SoConId, TCPIP_IPADDR_ASSIGNMENT_DHCP, NULL_PTR, netmask, &DefaultRouter);
#endif
for (conIndex = 0u; conIndex < DOIP_UDP_CON_NUM; conIndex++) {
ret = SoAd_GetSoConId(DoIP_ConfigPtr->DoIP_UdpMsg[conIndex].DoIP_UdpSoADTxPduRef, &SoConId);
if (E_OK == ret) {
/** @req SWS_DoIP_00003 */
if (E_OK == SoAd_OpenSoCon(SoConId)) {
/** @req SWS_DoIP_00201 */
DoIP_ActivationLineStatus = ACTIVATION_LINE_ACTIVE;
} else {
/** @req SWS_DoIP_00201 */
DoIP_ActivationLineStatus = ACTIVATION_LINE_INACTIVE;
}
} else {
/* Do nothing */
}
}
}
}
}
/**
* @brief The service DoIP_ActivationLineSwitchInactive used to notify the DoIP on a
* switch of the DoIPActivationLine to inactive. API is supported 4.3.0 onwards
* @note None Non Reentrant
*/
/** @req 4.3.1 SWS_DoIP_91001 */
void DoIP_ActivationLineSwitchInactive(void) {
SoAd_SoConIdType SoConId;
SoAd_SoConIdType conIndex;
/** @req 4.3.1 SWS_DoIP_00285 */
VALIDATE((DoIP_Status == DOIP_INIT), DOIP_ACTIVATION_LINE_SW_INACTIVE_SERVICE_ID, DOIP_E_UNINIT);
/** @req SWS_DoIP_00201 */
DoIP_ActivationLineStatus = ACTIVATION_LINE_INACTIVE;
#if (DOIPTGRGIDSYNCCALLBACK_CONFIGURED == TRUE) && (DOIP_VIN_GID_MASTER == STD_ON)
DoIP_GidSyncDone = FALSE;
#endif
/** @req SWS_DoIP_00234 */
for (conIndex = 0u; conIndex < DOIP_UDP_CON_NUM; conIndex++) {
closeSocket(UDP_TYPE, conIndex, DoIP_ConfigPtr->DoIP_UdpMsg[conIndex].DoIP_UdpSoADTxPduRef);
}
/** @req SWS_DoIP_00235*/
(void)SoAd_GetSoConId(DoIP_ConfigPtr->DoIP_UdpMsg[0].DoIP_UdpSoADTxPduRef, &SoConId);
(void)SoAd_ReleaseIpAddrAssignment(SoConId);
}
/**
* @brief The service DoIP_MainFunction Schedules the Diagnostic over IP module. (Entry point for scheduling)
* @param(in) None
* @param(out) None
* @return None
*/
/** @req SWS_DoIP_00041 */
void DoIP_MainFunction(void) {
PduInfoType tempPduInfo;
SoAd_SoConIdType conIndex;
boolean sendAnnouncement;
boolean handleTimeoutFlag = FALSE;
VALIDATE((DoIP_Status == DOIP_INIT), DOIP_MAIN_FUNCTION_SERVICE_ID, DOIP_E_UNINIT);
/** @req SWS_DoIP_00076 */
#if (DOIPTGRGIDSYNCCALLBACK_CONFIGURED == TRUE) && (DOIP_VIN_GID_MASTER == STD_ON)
if ((FALSE == DoIP_GidSyncDone) && (ACTIVATION_LINE_INACTIVE == DoIP_ActivationLineStatus)) {
if (E_OK == DOIP_GETTRIGGERGIDSYNCCALLBACK_FUNCTION()) {
DoIP_GidSyncDone = TRUE;
}
}
#endif
for (conIndex = 0u; conIndex < DOIP_UDP_CON_NUM; conIndex++) {
/** @req SWS_DoIP_00071 */
sendAnnouncement = FALSE;
if ((TRUE == DoIP_UdpConAdmin[conIndex].vehicleAnnounceTgr) || (TRUE == DoIP_UdpConAdmin[conIndex].vehicleAnnounceInProgress)) {
if (DoIP_UdpConAdmin[conIndex].vehicleAnnounceInitialTime < DOIP_INITIAL_VEHICLE_ANNOUNCEMENT_TIME) {
DoIP_UdpConAdmin[conIndex].vehicleAnnounceInitialTime += DOIP_MAIN_FUNCTION_PERIOD;
}else if (DoIP_UdpConAdmin[conIndex].vehicleAnnounceRepetition < DOIP_VEHICLE_ANNOUNCEMENT_REPETITION) {
if (TRUE == DoIP_UdpConAdmin[conIndex].vehicleAnnounceTgr) {
DoIP_UdpConAdmin[conIndex].vehicleAnnounceTgr = FALSE;
DoIP_UdpConAdmin[conIndex].vehicleAnnounceInProgress = TRUE;
sendAnnouncement = TRUE;
} else {
DoIP_UdpConAdmin[conIndex].vehicleAnnounceTimeInterval += DOIP_MAIN_FUNCTION_PERIOD;
if (DoIP_UdpConAdmin[conIndex].vehicleAnnounceTimeInterval >= DOIP_VEHICLE_ANNOUNCEMENT_INTERVAL) {
sendAnnouncement = TRUE;
}
}
if (TRUE == sendAnnouncement) {
sendVehicleAnnouncement(conIndex);
DoIP_UdpConAdmin[conIndex].vehicleAnnounceRepetition += 1u;
DoIP_UdpConAdmin[conIndex].vehicleAnnounceTimeInterval = 0u;
}
} else {
DoIP_UdpConAdmin[conIndex].vehicleAnnounceTgr = FALSE;
DoIP_UdpConAdmin[conIndex].vehicleAnnounceInProgress = FALSE;
DoIP_UdpConAdmin[conIndex].vehicleAnnounceInitialTime = 0u;
DoIP_UdpConAdmin[conIndex].vehicleAnnounceTimeInterval = 0u;
DoIP_UdpConAdmin[conIndex].vehicleAnnounceRepetition = 0u;
}
} else {
if ((DoIP_UdpConAdmin[conIndex].rxBufferStartIndex != DoIP_UdpConAdmin[conIndex].rxBufferEndIndex) ||
((DoIP_UdpConAdmin[conIndex].rxBufferStartIndex == DoIP_UdpConAdmin[conIndex].rxBufferEndIndex) && (TRUE == DoIP_UdpConAdmin[conIndex].rxBufferPresent))) {
handleUdpRx(conIndex, &(DoIP_UdpConAdmin[conIndex].rxBuffer[DoIP_UdpConAdmin[conIndex].rxBufferEndIndex][0]));
if (DoIP_UdpConAdmin[conIndex].rxBufferEndIndex < (DOIP_MAX_UDP_REQUEST_MESSAGE - 1u)) {
DoIP_UdpConAdmin[conIndex].rxBufferEndIndex ++;
} else {
DoIP_UdpConAdmin[conIndex].rxBufferEndIndex = UDP_RX_BUFFER_RESET_INDEX;
}
if ((UDP_RX_BUFFER_RESET_INDEX == DoIP_UdpConAdmin[conIndex].rxBufferEndIndex) && (UDP_RX_BUFFER_RESET_INDEX == DoIP_UdpConAdmin[conIndex].rxBufferEndIndex)) {
freeUdpRxBuffer(conIndex);
}
}
}
}
for (conIndex = 0u; conIndex < DOIP_TCP_CON_NUM; conIndex++) {
/* If buffer is Idle and the queue is not empty, then initiate transmission */
if ((TRUE == DoIP_TcpQueueAdmin[conIndex].diagAckQueueActive) && (BUFFER_IDLE == DoIP_TcpConAdmin[conIndex].txBufferState)) {
createAndSendDiagnosticAck(conIndex, DoIP_TcpQueueAdmin[conIndex].sa, DoIP_TcpQueueAdmin[conIndex].ta);
DoIP_TcpQueueAdmin[conIndex].diagAckQueueActive = FALSE;
} else if ((TRUE == DoIP_TcpQueueAdmin[conIndex].tpTransmitQueueActive) && (BUFFER_IDLE == DoIP_TcpConAdmin[conIndex].txBufferState)) {
tempPduInfo.SduDataPtr = DoIP_TcpQueueAdmin[conIndex].SduDataPtr;
tempPduInfo.SduLength = DoIP_TcpQueueAdmin[conIndex].SduLength;
(void)DoIP_TpTransmit(DoIP_TcpQueueAdmin[conIndex].txPduId, &tempPduInfo);
DoIP_TcpQueueAdmin[conIndex].tpTransmitQueueActive = FALSE;
} else {
/* Do nothing */
}
}
/* Handle DoIP connection timeouts */
for (conIndex = 0u; conIndex < DOIP_TCP_CON_NUM; conIndex++) {
/** @req SWS_DoIP_00143 */
if (CONNECTION_INITIALIZED == DoIP_TcpConAdmin[conIndex].socketState) {
/* Handle initial inactivity timeouts */
if (DoIP_TcpConAdmin[conIndex].initialInactivityTimer <= DOIP_GENERAL_INACTIVE_TIME) {
/* Note: Timer functionality is disabled */
/*DoIP_TcpConAdmin[conIndex].initialInactivityTimer += DOIP_MAIN_FUNCTION_PERIOD;*/
} else {
handleTimeoutFlag = TRUE;
}
} else if (CONNECTION_REGISTERED == DoIP_TcpConAdmin[conIndex].socketState) {
/* Handle Alive check timeouts */
if (TRUE == DoIP_TcpConAdmin[conIndex].awaitingAliveCheckResponse) {
if (DoIP_TcpConAdmin[conIndex].aliveCheckTimer < DOIP_ALIVE_CHECK_RESPONSE_TIMEOUT) {
/* Note: Timer functionality is disabled */
/*DoIP_TcpConAdmin[conIndex].aliveCheckTimer += DOIP_MAIN_FUNCTION_PERIOD;*/
} else {
handleTimeoutFlag = TRUE;
}
}
/* Handle general inactivity timeouts */
if (DoIP_TcpConAdmin[conIndex].generalInactivityTimer <= DOIP_GENERAL_INACTIVE_TIME) {
/* Note: Timer functionality is disabled */
/*DoIP_TcpConAdmin[conIndex].generalInactivityTimer += DOIP_MAIN_FUNCTION_PERIOD;*/
} else {
handleTimeoutFlag = TRUE;
}
} else {
}
if (TRUE == handleTimeoutFlag) {
handleTimeout(conIndex);
}
}
}
|
2301_81045437/classic-platform
|
communication/DoIP/src/DoIP.c
|
C
|
unknown
| 122,659
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
#include "DoIP.h"
Std_ReturnType DoIP_Arc_GetVin(uint8* Data, uint8 noOfBytes) {
for (uint8 i = 0u; i < noOfBytes; i++) {
Data[i] = 0x11u;
}
return E_OK;
}
/**
* @brief This callout is called from DoIP whenever a routing activation is successful
* @param id - Identifies the socket of the tcp connection */
void DoIP_Arc_TcpConnectionNotification(SoAd_SoConIdType id) {
(void) id;
}
|
2301_81045437/classic-platform
|
communication/DoIP/src/DoIP_Callout_Stubs.c
|
C
|
unknown
| 1,183
|
/*-------------------------------- 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 -----------------------------*/
/*
* NB! This file is for DOIP internal use only and may only be included from DOIP C-files!
*/
#ifndef DOIP_INTERNAL_H_
#define DOIP_INTERNAL_H_
#include "DoIP_Cfg.h"
/* Buffer Size */
#define UDP_RX_BUFF_SIZE 80
#define UDP_TX_BUFF_SIZE 40
#define TCP_TX_BUFF_SIZE 100u
#define TCP_RX_BUFF_SIZE 0x4010// 16 k buffer for reception of tcp message
#define TX_QUEUE_DEPTH 10
#define PROTOCOL_VERSION 0x02u
#define PROTOCOL_VERSION_VID 0xFFu
/* Payload types */
#define PL_TYPE_GENERIC_N_ACK 0x0000u
#define PL_TYPE_VID_RES 0x0004u
#define PL_TYPE_ROUT_ACTIV_RES 0x0006u
#define PL_TYPE_ALIVE_CHK_REQ 0x0007u
#define PL_TYPE_ENT_STATUS_RES 0x4002u
#define PL_TYPE_POWER_MODE_RES 0x4004u
#define PL_TYPE_DIAG_MSG_P_ACK 0x8002u
#define PL_TYPE_DIAG_MSG_N_ACK 0x8003u
#define PL_TYPE_VID_REQ 0x0001u
#define PL_TYPE_VID_EID_REQ 0x0002u
#define PL_TYPE_VID_VIN_REQ 0x0003u
#define PL_TYPE_ROUT_ACTIV_REQ 0x0005u
#define PL_TYPE_ALIVE_CHK_RES 0x0008u
#define PL_TYPE_ENT_STATUS_REQ 0x4001u
#define PL_TYPE_POWER_MODE_REQ 0x4003u
#define PL_TYPE_DIAG_MSG 0x8001u
/* Payload lengths */
#define PL_LEN_VID_REQ 0u
#define PL_LEN_VID_EID_REQ_RES 6u
#define PL_LEN_GID 6u
#define PL_LEN_VID_VIN_REQ_RES 17u
#define PL_LEN_ROUT_ACTIV_REQ 7u
#define PL_LEN_ROUT_ACTIV_OEM_REQ 11u
#define PL_LEN_DIAG_MIN_REQ 5u
#define PL_LEN_ALIVE_CHK_RES 2u
#define PL_LEN_ENT_STATUS_REQ 0u
#define PL_LEN_POWER_MODE_REQ 0u
#define PL_LEN_GENERIC_N_ACK 1u
#define PL_LEN_VID_RES 32u
#define PL_LEN_ROUT_ACTIV_RES 9u
#define PL_LEN_ALIVE_CHK_REQ 0u
#if(DOIP_ENTITY_MAX_BYTE_USE == STD_ON)
#define PL_LEN_ENT_STATUS_RES 7u
#else
#define PL_LEN_ENT_STATUS_RES 3u
#endif
#define PL_LEN_POWER_MODE_RES 1u
#define PL_LEN_DIAG_MSG_ACK 5u
#define MSG_LEN_INCL_PL_LEN_FIELD 8u
/* Index of the DoIP message fields */
#define PL_TYPE_INDEX 2u
#define PL_LEN_INDEX 4u
#define SA_INDEX 8u
#define TA_INDEX 10u
#define ROUT_ACTIV_TYPE_INDEX 10u
#define SA_AND_TA_LEN 4u
#define REQ_PAYLOAD_INDEX 8u
#define VID_VIN_INDEX 8u
#define VID_LA_INDEX 25u
#define VID_EID_INDEX 27u
#define VID_GID_INDEX 33u
#define VID_FUR_ACT_REQ_INDEX 39u
#define VID_VIN_GID_STS_INDEX 40u
#define SHIFT_BY_ONE_BYTE 8u
#define SHIFT_BY_TW0_BYTES 16u
#define SHIFT_BY_THREE_BYTES 24u
#define SHIFT_BY_FOUR_BYTES 32u
#define SHIFT_BY_FIVE_BYTES 40u
/* Diagnostic message negative acknowledge codes */
/* 0x00 and 0x01 Reserved by document */
#define ERROR_DIAG_INVALID_SA 0x02u /* Invalid Source Address */
#define ERROR_DIAG_UNKNOWN_TA 0x03u /* Unknown Target Address */
#define ERROR_DIAG_MESSAGE_TO_LARGE 0x04u /* Diagnostic Message too large */
#define ERROR_DIAG_OUT_OF_MEMORY 0x05u /* Out of memory */
#define ERROR_DIAG_TARGET_UNREACHABLE 0x06u /* Target unreachable */
#define ERROR_DIAG_UNKNOWN_NETWORK 0x07u /* Unknown network */
#define ERROR_DIAG_TP_ERROR 0x08u /* Transport protocol error */
/* Generic DoIP header negative acknowledge codes */
/** @req SWS_DoIP_00014 */
#define ERROR_INCORRECT_PATTERN_FORMAT 0x00u
/** @req SWS_DoIP_00016 */
#define ERROR_UNKNOWN_PAYLOAD_TYPE 0x01u
/** @req SWS_DoIP_00017 */
#define ERROR_MESSAGE_TOO_LARGE 0x02u
/** @req SWS_DoIP_00018 */
#define ERROR_OUT_OF_MEMORY 0x03u
/** @req SWS_DoIP_00019 */
#define ERROR_INVALID_PAYLOAD_LENGTH 0x04u
#define INVALID_PDU_ID DOIP_INVALID_PDU_ID
#define INVALID_SOCKET_NUMBER 0xFFFFu
#define INVALID_SOURCE_ADDRESS 0xFFu
#define INVALID_CHANNEL_INDEX 0xFFu
#define INVALID_CONNECTION_INDEX 0xFFFFu
#define INVALID_ROUTING_ACTIV_INDEX 0xFFFFu
#define INVALID_PENDING_ROUT_ACTIV 0xFFFFu
#define UDP_RX_BUFFER_RESET_INDEX 0u
#define DOIP_PORT_NUM 13400uL
typedef enum {
ID_REQUEST_ALL,
ID_REQUEST_BY_EID,
ID_REQUEST_BY_VIN,
} DoIP_Internal_VehReqType;
typedef enum {
TCP_TYPE,
TCP_FORCE_CLOSE_TYPE,
UDP_TYPE
} DoIP_Internal_ConType;
typedef enum {
SOCKET_ASSIGNMENT_FAILED,
SOCKET_ASSIGNMENT_SUCCESSFUL,
SOCKET_ASSIGNMENT_PENDING,
} DoIP_Internal_SockAssigResType;
typedef enum {
CONNECTION_INVALID,
CONNECTION_INITIALIZED,
CONNECTION_REGISTERED,
} DoIP_Internal_SocketStateType;
typedef enum {
BUFFER_IDLE,
BUFFER_LOCK_START,
BUFFER_LOCK,
} DoIP_Internal_BufferStateType;
typedef enum {
ACTIVATION_LINE_INACTIVE,
ACTIVATION_LINE_ACTIVE,
} DoIP_Internal_ActnLineStsType;
typedef enum {
LOOKUP_SA_TA_OK,
LOOKUP_SA_TA_TAUNKNOWN,
LOOKUP_SA_TA_SAERR,
LOOKUP_SA_TA_ROUTING_ERR,
} DoIP_Internal_LookupResType;
typedef enum {
DOIP_UNINIT,
DOIP_INIT
} DoIP_Internal_StatusType;
/** @req SWS_DoIP_00002 */ /** @req SWS_DoIP_00142 */
typedef struct {
uint32 initialInactivityTimer;
uint32 generalInactivityTimer;
uint32 aliveCheckTimer;
uint32 txBytesToTransmit;
uint32 txBytesCopied;
uint32 txBytesTransmitted;
PduIdType txPduIdUnderProgress;
SoAd_SoConIdType sockNr;
uint16 sa;
uint16 activationType;
DoIP_Internal_BufferStateType txBufferState;
DoIP_Internal_SocketStateType socketState;
uint8 txBuffer[TCP_TX_BUFF_SIZE];
uint8 channelIndex;
boolean authenticated;
boolean confirmed;
boolean awaitingAliveCheckResponse;
boolean closeSocketIndication;
boolean uLMsgTxInProgress;
} DoIP_Internal_TcpConAdminType;
typedef struct {
uint8 buffer[TCP_RX_BUFF_SIZE];
DoIP_Internal_BufferStateType bufferState;
PduIdType pduIdUnderProgress;
} DoIP_Internal_TcpConRxBufAdType;
typedef struct {
uint8 *SduDataPtr;
PduLengthType SduLength;
PduIdType txPduId;
uint16 sa;
uint16 ta;
boolean diagAckQueueActive;
boolean tpTransmitQueueActive;
} DoIP_Internal_TcpQueueAdminType;
/** @req SWS_DoIP_00001 */
typedef struct {
SoAd_SoConIdType sockNr;
PduIdType rxPduIdUnderProgress;
DoIP_Internal_SocketStateType socketState;
uint32 vehicleAnnounceInitialTime;
uint32 vehicleAnnounceTimeInterval;
DoIP_Internal_BufferStateType txBufferState;
uint8 vehicleAnnounceRepetition;
uint8 txBuffer[UDP_TX_BUFF_SIZE];
uint8 rxBuffer[DOIP_MAX_UDP_REQUEST_MESSAGE][UDP_RX_BUFF_SIZE];
uint8 rxBufferStartIndex;
uint8 rxBufferEndIndex;
boolean vehicleAnnounceTgr;
boolean vehicleAnnounceInProgress;
boolean rxBufferPresent;
} DoIP_Internal_UdpConAdminType;
#endif /* DOIP_INTERNAL_H_ */
|
2301_81045437/classic-platform
|
communication/DoIP/src/DoIP_Internal.h
|
C
|
unknown
| 9,151
|
# EthIF
obj-$(USE_ETHIF) += EthIf_Lcfg.o
obj-$(USE_ETHIF) += EthIf_PBcfg.o
obj-$(USE_ETHIF) += EthIf.o
vpath-$(USE_ETHIF) += $(ROOTDIR)/communication/EthIf/src
inc-$(USE_ETHIF) += $(ROOTDIR)/communication/EthIf/inc
inc-$(USE_ETHIF) += $(ROOTDIR)/mcal/Eth/inc
|
2301_81045437/classic-platform
|
communication/EthIf/EthIf.mod.mk
|
Makefile
|
unknown
| 266
|
/*-------------------------------- 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 ETHIF_H_
#define ETHIF_H_
#include "Eth_GeneralTypes.h" /* @req 4.2.2/SWS_EthIf_00152 */
#include "EcuM_Types.h"
#include "EthSM.h"
#include "EthSM_Cbk.h"
/* General requirements */
/* @req 4.2.2/SWS_EthIf_00011 */ /* header files shall not define global variables */
#define ETHIF_VENDOR_ID 60u
#define ETHIF_MODULE_ID 65u
/* @req 4.2.2/SWS_EthIf_00006 */
#define ETHIF_AR_RELEASE_MAJOR_VERSION 4u
#define ETHIF_AR_RELEASE_MINOR_VERSION 2u
#define ETHIF_AR_RELEASE_REVISION_VERSION 2u
#define ETHIF_AR_MAJOR_VERSION ETHIF_AR_RELEASE_MAJOR_VERSION
#define ETHIF_AR_MINOR_VERSION ETHIF_AR_RELEASE_MINOR_VERSION
#define ETHIF_AR_PATCH_VERSION ETHIF_AR_RELEASE_REVISION_VERSION
#define ETHIF_SW_MAJOR_VERSION 1u
#define ETHIF_SW_MINOR_VERSION 1u
#define ETHIF_SW_PATCH_VERSION 0u
#include "EthIf_Types.h"
#include "EthIf_Cfg.h"
/** Error IDs */
/* @req 4.2.2/SWS_EthIf_00017 */
#define ETHIF_E_INV_CTRL_IDX 1u
#define ETHIF_E_INV_TRCV_IDX 2u
#define ETHIF_E_NOT_INITIALIZED 3u
#define ETHIF_E_PARAM_POINTER 4u
#define ETHIF_E_INV_PARAM 5u
#define ETHIF_E_INIT_FAILED 6u
/** Service IDs */
#define ETHIF_SERVICE_ID_INIT 0x01u
#define ETHIF_SERVICE_ID_SET_CTRL_MODE 0x03u
#define ETHIF_SERVICE_ID_GET_CTRL_MODE 0x04u
#define ETHIF_SERVICE_ID_SET_TRCV_MODE 0x06u
#define ETHIF_SERVICE_ID_GET_TRCV_MODE 0x07u
#define ETHIF_SERVICE_ID_SET_TRCV_WAKEUP_MODE 0x2Eu
#define ETHIF_SERVICE_ID_GET_TRCV_WAKEUP_MODE 0x2Fu
#define ETHIF_SERVICE_ID_CHECK_WAKE_UP 0x30u
#define ETHIF_SERVICE_ID_GET_PHY_ADDR 0x08u
#define ETHIF_SERVICE_ID_SET_PHY_ADDR 0x0Du
#define ETHIF_SERVICE_ID_UPDATE_PHY_ADDR_FILTER 0x0Cu
#define ETHIF_SERVICE_ID_GET_PORT_MAC_ADDR 0x28u
#define ETHIF_SERVICE_ID_GET_ARL_TABEL 0x29u
#define ETHIF_SERVICE_ID_GET_BUF_LEVEL 0x2Au
#define ETHIF_SERVICE_ID_GET_DROP_COUNT 0x2Bu
#define ETHIF_SERVICE_ID_STORE_CONFIG 0x2Cu
#define ETHIF_SERVICE_ID_RESET_CONFIG 0x2Du
#define ETHIF_SERVICE_ID_GET_CURRENT_TIME 0x22u
#define ETHIF_SERVICE_ID_ENABLE_EGRESS_TIME_STAMP 0x23u
#define ETHIF_SERVICE_ID_GET_EGRESS_TIME_STAMP 0x24u
#define ETHIF_SERVICE_ID_GET_INGRESS_TIME_STAMP 0x25u
#define ETHIF_SERVICE_ID_SET_CORRECTION_TIME 0x26u
#define ETHIF_SERVICE_ID_SET_GLOBAL_TIME 0x27u
#define ETHIF_SERVICE_ID_PROVIDE_TX_BUFFER 0x09u
#define ETHIF_SERVICE_ID_TRANSMIT 0x0Au
#define ETHIF_SERVICE_ID_GET_VERSION_INFO 0x0Bu
/* Callback notifications function service Ids */
#define ETHIF_SERVICE_ID_RX_INDICATION 0x10u
#define ETHIF_SERVICE_ID_TX_CONFIRMATION 0x11u
#define ETHIF_SERVICE_ID_CTRL_MODE_INDICATION 0x0Eu
#define ETHIF_SERVICE_ID_TRCV_MODE_INDICATION 0x0Fu
/* Scheduled functions service IDs */
#define ETHIF_SERVICE_ID_MAIN_FUNCTION_RX 0x20u
#define ETHIF_SERVICE_ID_MAIN_FUNCTION_TX 0x21u
/**
* Function routine for ETH IF initialization, called first before calling any other of ETHIF functions.
*/
/* @req 4.2.2/SWS_EthIf_00024 */
void EthIf_Init( const EthIf_ConfigType* CfgPtr );/** Init function for ETHIF */
/* @req 4.2.2/SWS_EthIf_00034 */
Std_ReturnType EthIf_SetControllerMode( uint8 CtrlIdx, Eth_ModeType CtrlMode );
/* @req 4.2.2/SWS_EthIf_00039 */
Std_ReturnType EthIf_GetControllerMode( uint8 CtrlIdx, Eth_ModeType* CtrlModePtr );
/* @req 4.2.2/SWS_EthIf_00050 */
Std_ReturnType EthIf_SetTransceiverMode( uint8 TrcvIdx, EthTrcv_ModeType TrcvMode );
/* @req 4.2.2/SWS_EthIf_00055 */
Std_ReturnType EthIf_GetTransceiverMode( uint8 TrcvIdx, EthTrcv_ModeType* TrcvModePtr );
/* @req 4.2.2/SWS_EthIf_00233 */
Std_ReturnType EthIf_SetTransceiverWakeupMode( uint8 TrcvIdx, EthTrcv_WakeupModeType TrcvWakeupMode );
/* @req 4.2.2/SWS_EthIf_00238 */
Std_ReturnType EthIf_GetTransceiverWakeupMode( uint8 TrcvIdx, EthTrcv_WakeupModeType* TrcvWakeupModePtr );
/* @req 4.2.2/SWS_EthIf_00244 */
Std_ReturnType EthIf_CheckWakeup( EcuM_WakeupSourceType WakeupSource );
/* @req 4.2.2/SWS_EthIf_00061 */
void EthIf_GetPhysAddr( uint8 CtrlIdx, uint8* PhysAddrPtr );
/* @req 4.2.2/SWS_EthIf_00132 */
void EthIf_SetPhysAddr( uint8 CtrlIdx, const uint8* PhysAddrPtr );
/* @req 4.2.2/SWS_EthIf_00139 */
Std_ReturnType EthIf_UpdatePhysAddrFilter( uint8 CtrlIdx, const uint8* PhysAddrPtr, Eth_FilterActionType Action );
/* @req 4.2.2/SWS_EthIf_00190 */
Std_ReturnType EthIf_GetPortMacAddr( const uint8* MacAddrPtr, uint8* SwitchIdxPtr, uint8* PortIdxPtr );
/* @req 4.2.2/SWS_EthIf_00196 */
Std_ReturnType EthIf_GetArlTable( uint8 SwitchIdx, EthSwt_MacVlanType* ArlTable );
/* @req 4.2.2/SWS_EthIf_00202 */
Std_ReturnType EthIf_GetBufferLevel( uint8 SwitchIdx, uint32* SwitchBufferLevelPtr );
/* @req 4.2.2/SWS_EthIf_00208 */
Std_ReturnType EthIf_GetDropCount( uint8 SwitchIdx, uint32* DropCount );
/* @req 4.2.2/SWS_EthIf_00214 */
Std_ReturnType EthIf_StoreConfiguration( uint8 SwitchIdx );
/* @req 4.2.2/SWS_EthIf_00219 */
Std_ReturnType EthIf_ResetConfiguration( uint8 SwitchIdx );
/* @req 4.2.2/SWS_EthIf_00154 */
Std_ReturnType EthIf_GetCurrentTime( uint8 CtrlIdx, Eth_TimeStampQualType* timeQualPtr, Eth_TimeStampType* timeStampPtr );
/* @req 4.2.2/SWS_EthIf_00160 */
void EthIf_EnableEgressTimeStamp( uint8 CtrlIdx, Eth_BufIdxType BufIdx );
/* @req 4.2.2/SWS_EthIf_00166 */
void EthIf_GetEgressTimeStamp(uint8 CtrlIdx, Eth_BufIdxType BufIdx, Eth_TimeStampQualType* timeQualPtr, Eth_TimeStampType* timeStampPtr );
/* @req 4.2.2/SWS_EthIf_00172 */
void EthIf_GetIngressTimeStamp( uint8 CtrlIdx, Eth_DataType* DataPtr, Eth_TimeStampQualType* timeQualPtr, Eth_TimeStampType* timeStampPtr );
/* @req 4.2.2/SWS_EthIf_00178 */
void EthIf_SetCorrectionTime( uint8 CtrlIdx, const Eth_TimeIntDiffType* timeOffsetPtr, const Eth_RateRatioType* rateRatioPtr );
/* @req 4.2.2/SWS_EthIf_00184 */
Std_ReturnType EthIf_SetGlobalTime( uint8 CtrlIdx, const Eth_TimeStampType* timeStampPtr );
/* @req 4.2.2/SWS_EthIf_00067 */
BufReq_ReturnType EthIf_ProvideTxBuffer( uint8 CtrlIdx, Eth_FrameType FrameType, uint8 Priority, Eth_BufIdxType* BufIdxPtr, uint8** BufPtr, uint16* LenBytePtr );
/* @req 4.2.2/SWS_EthIf_00075 */
Std_ReturnType EthIf_Transmit( uint8 CtrlIdx, Eth_BufIdxType BufIdx, Eth_FrameType FrameType, boolean TxConfirmation, uint16 LenByte, const uint8* PhysAddrPtr );
/* @req 4.2.2/SWS_EthIf_00082 */
#if (ETHIF_VERSION_INFO_API == STD_ON)
#if (ETHIF_VERSION_INFO_API_MACRO == STD_ON)
#define EthIf_GetVersionInfo(_vi) STD_GET_VERSION_INFO(_vi,ETHIF) /* @req 4.2.2/SWS_EthIf_00127 */
#else
void EthIf_GetVersionInfo( Std_VersionInfoType* VersionInfoPtr );
#endif
#endif
/* @req 4.2.2/SWS_EthIf_00097 */
void EthIf_MainFunctionRx( void );
/* @req 4.2.2/SWS_EthIf_00113 */
void EthIf_MainFunctionTx( void );
#endif /* ETHIF_H_ */
|
2301_81045437/classic-platform
|
communication/EthIf/inc/EthIf.h
|
C
|
unknown
| 7,892
|
/*-------------------------------- 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 ETHIF_CBK_H_
#define ETHIF_CBK_H_
#include "ComStack_Types.h"
#include "EthIf_Types.h"
/* @req 4.2.2/SWS_EthIf_00085 */
void EthIf_RxIndication( uint8 CtrlIdx, Eth_FrameType FrameType, boolean IsBroadcast, const uint8* PhysAddrPtr, Eth_DataType* DataPtr, uint16 LenByte );
/* @req 4.2.2/SWS_EthIf_00091 */
void EthIf_TxConfirmation( uint8 CtrlIdx, Eth_BufIdxType BufIdx );
/* @req 4.2.2/SWS_EthIf_00231 */
void EthIf_CtrlModeIndication( uint8 CtrlIdx, Eth_ModeType CtrlMode );
/* @req 4.2.2/SWS_EthIf_00232 */
void EthIf_TrcvModeIndication( uint8 CtrlIdx, EthTrcv_ModeType TrcvMode );
#endif /* ETHIF_CBK_H_ */
|
2301_81045437/classic-platform
|
communication/EthIf/inc/EthIf_Cbk.h
|
C
|
unknown
| 1,388
|
/*-------------------------------- 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 ETHIF_TYPES_H_
#define ETHIF_TYPES_H_
#include "Eth_GeneralTypes.h" /* @req 4.2.2/SWS_EthIf_00153 */
/* @req 4.2.2/SWS_EthIf_00150 */
typedef enum {
ETHIF_STATE_UNINIT, /* Status of EthIf module before EthIf_Init function*/
ETHIF_STATE_INIT, /* Status of EthIf module after EthIf_Init function called*/
}EthIf_StateType;
typedef struct {
uint8 EthIfCtrlId; /* Index of the Ethernet controller within the context of the Ethernet Interface */
uint8 EthIfMaxTxBufsTotal; /* total number of transmit buffers. */
uint16 EthIfCtrlMtu; /* maximum Payload size */
uint8 EthIfEthCtrlId; /* Index of Eth controller within the context of the Ethernet Driver */
uint8 EthIfEthTrcvId; /* Index of Eth Trcv */
uint16 EthIfVlanId; /* 12 bit VLAN ID */
}EthIf_Controller_type;
/* Function pointer for User defined Tx Confirmation callback */
typedef void (*EthIfULTxConfirmationType) ( uint8 CtrlIdx, Eth_BufIdxType BufIdx );
/* Function pointer for User defined Rx Indication callback */
typedef void (*EthIfULRxIndicationType) ( uint8 CtrlIdx, Eth_FrameType FrameType, boolean IsBroadcast, const uint8* PhysAddrPtr, uint8* DataPtr, uint16 LenByte );
/* Function pointer for User defined TrcvLinkState callback */
typedef void (*EthIfTrcvLinkStateChgType) ( uint8 CtrlIdx, EthTrcv_LinkStateType TrcvLinkState );
typedef struct {
uint32 EthIfFrameType; /* Frame Type ex: ARP, iV4 */
uint8 EthIfRxIndicationHandle; /* RxIndication handle */
uint8 EthIfTxConfirmationHandle; /* TxConfirmation handle */
}EthIf_Frame_Owner_type;
typedef struct {
uint8 EthIfEthSwitchId; /* Index of Switches in context of Eth Interface*/
uint8 EthIfSwitchIdx; /* Index of Switches in context of Eth Switch module*/
}EthIf_Switch_Type;
/* @req 4.2.2/SWS_EthIf_00149 */
typedef struct {
const EthIf_Controller_type* EthIfCtrlCfg; /*pointer to hold controller config data*/
const EthIf_Frame_Owner_type* EthIfOwnerCfg; /* pointer to hold Owner config data */
const EthIf_Switch_Type* EthIfSwitchCfg; /* pointer to hold switches config data */
const EthIfULTxConfirmationType* EthIfULTxConfirmation; /* pointer to hold Tx confirmation functions list */
const EthIfULRxIndicationType * EthIfULRxIndication; /* Ptr to Rx indication function list */
/*const EthIfTrcvLinkStateChgType* EthIfTrcvLink; pointer to hold Trcv Link state functions list */
uint8 EthIfCtrlCount; /* No of Controllers configure */
uint8 EthIfTrcvCount; /* No of Trcv configured */
uint8 EthIfSwitchCount; /* No of Switches configured */
uint8 EthIfOwnersCount; /* No fo Owners configured */
}EthIf_ConfigType;
#endif /* ETHIF_TYPES_H_ */
|
2301_81045437/classic-platform
|
communication/EthIf/inc/EthIf_Types.h
|
C
|
unknown
| 3,683
|
/*-------------------------------- 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 "Eth.h"
#include "EthIf.h"
#include "SchM_EthIf.h"
#if (ETHIF_TRCV_SUPPORT == STD_ON)
#include "EthTrcv.h"
#endif
#if (ETHIF_SWITCH_SUPPORT == STD_ON)
#include "EthSwt.h"
#endif
#if (ETHIF_DEV_ERROR_DETECT == STD_ON)
#if defined(USE_DET)
#include "Det.h"
#else
#error "EthIf: DET must be used when Default error detect is enabled"
#endif
#endif
#include "EthIf_Cbk.h"
#include "EthIf_Cfg.h"
//lint -emacro(904,ETHIF_DET_REPORTERROR) //904 PC-Lint exception to MISRA 14.7 (validate DET macros).
/* Globally fulfilled requirements */
/* @req 4.2.2/SWS_EthIf_00010 */
/* @req 4.2.2/SWS_EthIf_00112 */
/* @req 4.2.2/SWS_EthIf_00003 */
#define ETH_FRAME_TYPE_VLAN 0x8100u
#define ETH_FRAME_VLAN_HI 0x81u
#define ETH_FRAME_VLAN_LOW 0x00u
#define PCP_SHIFT_BITS_5 5u
#define PCP_SHIFT_BITS_4 4u
#define VLAN_MASK_NIBBLE 0x0F00u
#define VLAN_MASK_BYTE 0x00FFu
#define SHIFT_EIGHT_BITS 8u
#define FRAME_MASK_HI 0xFF00u
#define FRAME_MASK_LOW 0x00FFu
#define VLAN_TAG_SIZE 4u
#define PRIORITY_SIZE 8u
#define ETHIF_VID_MASK 0x0FFFu
#define ETHIF_SHIFT_BYTE1 8u
#define ETHIF_BYTE_MASK 0xFFu
/*lint -esym(9003,EthIf_ConfigPointer )*/
const EthIf_ConfigType* EthIf_ConfigPointer;
/** Static declarations */
typedef struct {
uint32 frameType;
uint32 bufferIdx;
}EthIfRunTimeType;
typedef struct {
EthIf_StateType initStatus; /* var to hold EthIf module status */
EthIfRunTimeType ethIfRunTime[ETHIF_MAX_FRAME_OWNER_CFG]; /* Mapping from buffer index to Frame type*/
}EthIf_InternalType;
/*lint -esym(9003,EthIf_Internal )*//* @req 4.2.2/SWS_EthIf_00146*/
EthIf_InternalType EthIf_Internal = {
.initStatus = ETHIF_STATE_UNINIT,
};
/* @req 4.2.2/SWS_EthIf_00008 */
#if (ETHIF_DEV_ERROR_DETECT == STD_ON)
#define ETHIF_DET_REPORTERROR(_cond ,_api, _error, ...) \
if (!_cond) { \
(void)Det_ReportError(ETHIF_MODULE_ID, 0, _api, _error); \
return __VA_ARGS__; \
}
#else
#define ETHIF_DET_REPORTERROR(_cond ,_api, _error, ...) \
if (!_cond) { \
return __VA_ARGS__; \
}
#endif
#define INVALID_BUFFER_INDEX 0xFFFFFFFFUL
/** AUTOSAR APIs */
/**
* Init function for EthIf
* @param CfgPtr
*/
/* @req 4.2.2/SWS_EthIf_00024 */
void EthIf_Init( const EthIf_ConfigType* CfgPtr )
{
uint8 i;
/* @req 4.2.2/SWS_EthIf_00116 */
ETHIF_DET_REPORTERROR((NULL != CfgPtr),ETHIF_SERVICE_ID_INIT, ETHIF_E_INIT_FAILED);
/* @req 4.2.2/SWS_EthIf_00025 */ /* @req 4.2.2/SWS_EthIf_00014 */
EthIf_ConfigPointer = CfgPtr;
for (i=0; i < EthIf_ConfigPointer->EthIfOwnersCount; i++) {
EthIf_Internal.ethIfRunTime[i].frameType = EthIf_ConfigPointer->EthIfOwnerCfg[i].EthIfFrameType;
EthIf_Internal.ethIfRunTime[i].bufferIdx = INVALID_BUFFER_INDEX;
}
/* @req 4.2.2/SWS_EthIf_00114 */
EthIf_Internal.initStatus = ETHIF_STATE_INIT;
}
#if((ETHIF_VERSION_INFO_API == STD_ON) && (ETHIF_VERSION_INFO_API_MACRO == STD_OFF))
/**
* This service puts out the version information of this module
* @param VersionInfoPtr
*/
/* @req 4.2.2/SWS_EthIf_00082 */
void EthIf_GetVersionInfo( Std_VersionInfoType* VersionInfoPtr )
{
/* @req 4.2.2/SWS_EthIf_00127 */
ETHIF_DET_REPORTERROR((NULL != VersionInfoPtr),ETHIF_SERVICE_ID_GET_VERSION_INFO,ETHIF_E_PARAM_POINTER);
VersionInfoPtr->moduleID = ETHIF_MODULE_ID; /* Module ID of ETHIF */
VersionInfoPtr->vendorID = ETHIF_VENDOR_ID; /* Vendor Id (ARCCORE) */
/* return the Software Version numbers */
VersionInfoPtr->sw_major_version = ETHIF_SW_MAJOR_VERSION;
VersionInfoPtr->sw_minor_version = ETHIF_SW_MINOR_VERSION;
VersionInfoPtr->sw_patch_version = ETHIF_SW_PATCH_VERSION;
}
#endif
/**
*
* @param CtrlIdx
* @param CtrlMode
* @return
*/
/* @req 4.2.2/SWS_EthIf_00034 */
Std_ReturnType EthIf_SetControllerMode( uint8 CtrlIdx, Eth_ModeType CtrlMode )
{
Std_ReturnType ret;
/* @req 4.2.2/SWS_EthIf_00036 */
ETHIF_DET_REPORTERROR((ETHIF_STATE_INIT == EthIf_Internal.initStatus),ETHIF_SERVICE_ID_SET_CTRL_MODE, ETHIF_E_NOT_INITIALIZED, E_NOT_OK);
/* @req 4.2.2/SWS_EthIf_00037 */
ETHIF_DET_REPORTERROR((CtrlIdx < EthIf_ConfigPointer->EthIfCtrlCount),ETHIF_SERVICE_ID_SET_CTRL_MODE, ETHIF_E_INV_CTRL_IDX, E_NOT_OK);
/* @req 4.2.2/SWS_EthIf_00035 */
ret = Eth_SetControllerMode(EthIf_ConfigPointer->EthIfCtrlCfg[CtrlIdx].EthIfEthCtrlId, CtrlMode);
return ret;
}
/**
*
* @param CtrlIdx
* @param CtrlModePtr
* @return
*/
/* @req 4.2.2/SWS_EthIf_00039 */
Std_ReturnType EthIf_GetControllerMode( uint8 CtrlIdx, Eth_ModeType* CtrlModePtr )
{
Std_ReturnType ret;
/* @req 4.2.2/SWS_EthIf_00041 */
ETHIF_DET_REPORTERROR((ETHIF_STATE_INIT == EthIf_Internal.initStatus),ETHIF_SERVICE_ID_GET_CTRL_MODE, ETHIF_E_NOT_INITIALIZED, E_NOT_OK);
/* @req 4.2.2/SWS_EthIf_00042 */
ETHIF_DET_REPORTERROR((CtrlIdx < EthIf_ConfigPointer->EthIfCtrlCount),ETHIF_SERVICE_ID_GET_CTRL_MODE, ETHIF_E_INV_CTRL_IDX, E_NOT_OK);
/* @req 4.2.2/SWS_EthIf_00043 */
ETHIF_DET_REPORTERROR((NULL != CtrlModePtr),ETHIF_SERVICE_ID_GET_CTRL_MODE, ETHIF_E_PARAM_POINTER, E_NOT_OK);
/* @req 4.2.2/SWS_EthIf_00040 */
ret = Eth_GetControllerMode(EthIf_ConfigPointer->EthIfCtrlCfg[CtrlIdx].EthIfEthCtrlId, CtrlModePtr);
return ret;
}
/**
*
* @param CtrlIdx
* @param PhysAddrPtr
*/
/* @req 4.2.2/SWS_EthIf_00132 */
void EthIf_SetPhysAddr( uint8 CtrlIdx, const uint8* PhysAddrPtr )
{
/* @req 4.2.2/SWS_EthIf_00135 */
ETHIF_DET_REPORTERROR((ETHIF_STATE_INIT == EthIf_Internal.initStatus),ETHIF_SERVICE_ID_SET_PHY_ADDR, ETHIF_E_NOT_INITIALIZED);
/* @req 4.2.2/SWS_EthIf_00136 */
ETHIF_DET_REPORTERROR((CtrlIdx < EthIf_ConfigPointer->EthIfCtrlCount),ETHIF_SERVICE_ID_SET_PHY_ADDR, ETHIF_E_INV_CTRL_IDX);
/* @req 4.2.2/SWS_EthIf_00137 */
ETHIF_DET_REPORTERROR((NULL != PhysAddrPtr),ETHIF_SERVICE_ID_SET_PHY_ADDR, ETHIF_E_PARAM_POINTER);
/* @req 4.2.2/SWS_EthIf_00134 */
Eth_SetPhysAddr(EthIf_ConfigPointer->EthIfCtrlCfg[CtrlIdx].EthIfEthCtrlId, PhysAddrPtr);
}
/**
*
* @param CtrlIdx
* @param PhysAddrPtr
*/
/* @req 4.2.2/SWS_EthIf_00061 */
void EthIf_GetPhysAddr( uint8 CtrlIdx, uint8* PhysAddrPtr )
{
/* @req 4.2.2/SWS_EthIf_00063 */
ETHIF_DET_REPORTERROR((ETHIF_STATE_INIT == EthIf_Internal.initStatus),ETHIF_SERVICE_ID_GET_PHY_ADDR, ETHIF_E_NOT_INITIALIZED);
/* @req 4.2.2/SWS_EthIf_00064 */
ETHIF_DET_REPORTERROR((CtrlIdx < EthIf_ConfigPointer->EthIfCtrlCount),ETHIF_SERVICE_ID_GET_PHY_ADDR, ETHIF_E_INV_CTRL_IDX);
/* @req 4.2.2/SWS_EthIf_00065 */
ETHIF_DET_REPORTERROR((NULL != PhysAddrPtr),ETHIF_SERVICE_ID_GET_PHY_ADDR, ETHIF_E_PARAM_POINTER);
/* @req 4.2.2/SWS_EthIf_00062 */
Eth_GetPhysAddr(EthIf_ConfigPointer->EthIfCtrlCfg[CtrlIdx].EthIfEthCtrlId, PhysAddrPtr);
}
/**
*
* @param CtrlIdx
* @param PhysAddrPtr
* @param Action
* @return
*/
/* @req 4.2.2/SWS_EthIf_00139 */
Std_ReturnType EthIf_UpdatePhysAddrFilter( uint8 CtrlIdx, const uint8* PhysAddrPtr, Eth_FilterActionType Action )
{
Std_ReturnType ret;
/* @req 4.2.2/SWS_EthIf_00141 */
ETHIF_DET_REPORTERROR((ETHIF_STATE_INIT == EthIf_Internal.initStatus),ETHIF_SERVICE_ID_UPDATE_PHY_ADDR_FILTER, ETHIF_E_NOT_INITIALIZED, E_NOT_OK);
/* @req 4.2.2/SWS_EthIf_00142 */
ETHIF_DET_REPORTERROR((CtrlIdx < EthIf_ConfigPointer->EthIfCtrlCount),ETHIF_SERVICE_ID_UPDATE_PHY_ADDR_FILTER, ETHIF_E_INV_CTRL_IDX, E_NOT_OK);
/* @req 4.2.2/SWS_EthIf_00143 */
ETHIF_DET_REPORTERROR((NULL != PhysAddrPtr),ETHIF_SERVICE_ID_UPDATE_PHY_ADDR_FILTER, ETHIF_E_PARAM_POINTER, E_NOT_OK );
/* @req 4.2.2/SWS_EthIf_00140 */
#if (ETH_PHYS_ADRS_FILTER_API == STD_ON)
ret = Eth_UpdatePhysAddrFilter( EthIf_ConfigPointer->EthIfCtrlCfg[CtrlIdx].EthIfEthCtrlId, PhysAddrPtr, Action);
#else
(void)Action; /* To avoid PC lint error */
ret = E_NOT_OK;
#endif
return ret;
}
#if (ETHIF_GLOBAL_TIME_SUPPORT == STD_ON)
/* @req 4.2.2/SWS_EthIf_00158 */ /* @req 4.2.2/SWS_EthIf_00164 */ /* @req 4.2.2/SWS_EthIf_00170 */ /* @req 4.2.2/SWS_EthIf_00176 */
/* @req 4.2.2/SWS_EthIf_00182 */ /* @req 4.2.2/SWS_EthIf_00188 */
/**
*
* @param CtrlIdx
* @param timeQualPtr
* @param timeStampPtr
* @return
*/
/* @req 4.2.2/SWS_EthIf_00154 */
Std_ReturnType EthIf_GetCurrentTime( uint8 CtrlIdx, Eth_TimeStampQualType* timeQualPtr, Eth_TimeStampType* timeStampPtr )
{
Std_ReturnType ret;
/* @req 4.2.2/SWS_EthIf_00155 */
ETHIF_DET_REPORTERROR((ETHIF_STATE_INIT == EthIf_Internal.initStatus),ETHIF_SERVICE_ID_GET_CURRENT_TIME, ETHIF_E_NOT_INITIALIZED, E_NOT_OK);
/* @req 4.2.2/SWS_EthIf_00156 */
ETHIF_DET_REPORTERROR((CtrlIdx < EthIf_ConfigPointer->EthIfCtrlCount),ETHIF_SERVICE_ID_GET_CURRENT_TIME, ETHIF_E_INV_CTRL_IDX, E_NOT_OK);
/* @req 4.2.2/SWS_EthIf_00157 */
ETHIF_DET_REPORTERROR(((NULL != timeQualPtr) && (NULL != timeStampPtr)) ,ETHIF_SERVICE_ID_GET_CURRENT_TIME, ETHIF_E_PARAM_POINTER, E_NOT_OK );
ret = Eth_GetCurrentTime(EthIf_ConfigPointer->EthIfCtrlCfg[CtrlIdx].EthIfEthCtrlId, timeQualPtr, timeStampPtr );
return ret;
}
/**
*
* @param CtrlIdx
* @param BufIdx
*/
/* @req 4.2.2/SWS_EthIf_00160 */
void EthIf_EnableEgressTimeStamp( uint8 CtrlIdx, Eth_BufIdxType BufIdx )
{
/* @req 4.2.2/SWS_EthIf_00161 */
ETHIF_DET_REPORTERROR((ETHIF_STATE_INIT == EthIf_Internal.initStatus),ETHIF_SERVICE_ID_ENABLE_EGRESS_TIME_STAMP, ETHIF_E_NOT_INITIALIZED);
/* @req 4.2.2/SWS_EthIf_00162 */
ETHIF_DET_REPORTERROR((CtrlIdx < EthIf_ConfigPointer->EthIfCtrlCount),ETHIF_SERVICE_ID_ENABLE_EGRESS_TIME_STAMP, ETHIF_E_INV_CTRL_IDX);
Eth_EnableEgressTimeStamp(EthIf_ConfigPointer->EthIfCtrlCfg[CtrlIdx].EthIfEthCtrlId, BufIdx );
}
/**
*
* @param CtrlIdx
* @param BufIdx
* @param timeQualPtr
* @param timeStampPtr
*/
/* @req 4.2.2/SWS_EthIf_00166 */
void EthIf_GetEgressTimeStamp(uint8 CtrlIdx, Eth_BufIdxType BufIdx, Eth_TimeStampQualType* timeQualPtr, Eth_TimeStampType* timeStampPtr )
{
/* @req 4.2.2/SWS_EthIf_00167 */
ETHIF_DET_REPORTERROR((ETHIF_STATE_INIT == EthIf_Internal.initStatus),ETHIF_SERVICE_ID_GET_EGRESS_TIME_STAMP, ETHIF_E_NOT_INITIALIZED );
/* @req 4.2.2/SWS_EthIf_00168 */
ETHIF_DET_REPORTERROR((CtrlIdx < EthIf_ConfigPointer->EthIfCtrlCount),ETHIF_SERVICE_ID_GET_EGRESS_TIME_STAMP, ETHIF_E_INV_CTRL_IDX );
/* @req 4.2.2/SWS_EthIf_00169 */
ETHIF_DET_REPORTERROR(((NULL != timeQualPtr) && (NULL != timeStampPtr)) ,ETHIF_SERVICE_ID_GET_EGRESS_TIME_STAMP, ETHIF_E_PARAM_POINTER );
Eth_GetEgressTimeStamp(EthIf_ConfigPointer->EthIfCtrlCfg[CtrlIdx].EthIfEthCtrlId, BufIdx, timeQualPtr, timeStampPtr );
}
/**
*
* @param CtrlIdx
* @param DataPtr
* @param timeQualPtr
* @param timeStampPtr
*/
/* @req 4.2.2/SWS_EthIf_00172 */
void EthIf_GetIngressTimeStamp( uint8 CtrlIdx, Eth_DataType* DataPtr, Eth_TimeStampQualType* timeQualPtr, Eth_TimeStampType* timeStampPtr )
{
/* @req 4.2.2/SWS_EthIf_00173 */
ETHIF_DET_REPORTERROR((ETHIF_STATE_INIT == EthIf_Internal.initStatus),ETHIF_SERVICE_ID_GET_INGRESS_TIME_STAMP, ETHIF_E_NOT_INITIALIZED );
/* @req 4.2.2/SWS_EthIf_00174 */
ETHIF_DET_REPORTERROR((CtrlIdx < EthIf_ConfigPointer->EthIfCtrlCount),ETHIF_SERVICE_ID_GET_INGRESS_TIME_STAMP, ETHIF_E_INV_CTRL_IDX );
/* @req 4.2.2/SWS_EthIf_00175 */
ETHIF_DET_REPORTERROR(((NULL != timeQualPtr) && (NULL != timeStampPtr) && (NULL != DataPtr)) ,ETHIF_SERVICE_ID_GET_INGRESS_TIME_STAMP, ETHIF_E_PARAM_POINTER );
Eth_GetIngressTimeStamp(EthIf_ConfigPointer->EthIfCtrlCfg[CtrlIdx].EthIfEthCtrlId, DataPtr, timeQualPtr, timeStampPtr );
}
/**
*
* @param CtrlIdx
* @param timeOffsetPtr
* @param rateRatioPtr
*/
/* @req 4.2.2/SWS_EthIf_00178 */
void EthIf_SetCorrectionTime( uint8 CtrlIdx, const Eth_TimeIntDiffType* timeOffsetPtr, const Eth_RateRatioType* rateRatioPtr )
{
/* @req 4.2.2/SWS_EthIf_00179 */
ETHIF_DET_REPORTERROR((ETHIF_STATE_INIT == EthIf_Internal.initStatus),ETHIF_SERVICE_ID_SET_CORRECTION_TIME, ETHIF_E_NOT_INITIALIZED );
/* @req 4.2.2/SWS_EthIf_00180 */
ETHIF_DET_REPORTERROR((CtrlIdx < EthIf_ConfigPointer->EthIfCtrlCount),ETHIF_SERVICE_ID_SET_CORRECTION_TIME, ETHIF_E_INV_CTRL_IDX );
/* @req 4.2.2/SWS_EthIf_00181 */
ETHIF_DET_REPORTERROR(((NULL != timeOffsetPtr) && (NULL != rateRatioPtr)) ,ETHIF_SERVICE_ID_SET_CORRECTION_TIME, ETHIF_E_PARAM_POINTER );
Eth_SetCorrectionTime(EthIf_ConfigPointer->EthIfCtrlCfg[CtrlIdx].EthIfEthCtrlId, timeOffsetPtr, rateRatioPtr );
}
/**
*
* @param CtrlIdx
* @param timeStampPtr
* @return
*/
/* @req 4.2.2/SWS_EthIf_00184 */
Std_ReturnType EthIf_SetGlobalTime( uint8 CtrlIdx, const Eth_TimeStampType* timeStampPtr ) {
Std_ReturnType ret;
/* @req 4.2.2/SWS_EthIf_000185 */
ETHIF_DET_REPORTERROR((ETHIF_STATE_INIT == EthIf_Internal.initStatus),ETHIF_SERVICE_ID_SET_GLOBAL_TIME, ETHIF_E_NOT_INITIALIZED, E_NOT_OK);
/* @req 4.2.2/SWS_EthIf_000186 */
ETHIF_DET_REPORTERROR((CtrlIdx < EthIf_ConfigPointer->EthIfCtrlCount),ETHIF_SERVICE_ID_SET_GLOBAL_TIME, ETHIF_E_INV_CTRL_IDX, E_NOT_OK);
/* @req 4.2.2/SWS_EthIf_000187 */
ETHIF_DET_REPORTERROR((NULL != timeStampPtr),ETHIF_SERVICE_ID_SET_GLOBAL_TIME, ETHIF_E_PARAM_POINTER, E_NOT_OK);
ret = Eth_SetGlobalTime(EthIf_ConfigPointer->EthIfCtrlCfg[CtrlIdx].EthIfEthCtrlId, timeStampPtr);
return ret;
}
#endif
/**
*
* @param CtrlIdx
* @param BufIdx
*/
/* @req 4.2.2/SWS_EthIf_00091 */ /* @req 4.2.2/SWS_EthIf_00096 */
void EthIf_TxConfirmation( uint8 CtrlIdx, Eth_BufIdxType BufIdx ) {
uint8 i;
uint8 txhandle;
/* @req 4.2.2/SWS_EthIf_00092 */
ETHIF_DET_REPORTERROR((ETHIF_STATE_INIT == EthIf_Internal.initStatus),ETHIF_SERVICE_ID_TX_CONFIRMATION, ETHIF_E_NOT_INITIALIZED);
/* @req 4.2.2/SWS_EthIf_00093 */
ETHIF_DET_REPORTERROR((CtrlIdx < EthIf_ConfigPointer->EthIfCtrlCount),ETHIF_SERVICE_ID_TX_CONFIRMATION, ETHIF_E_INV_CTRL_IDX);
/* @req 4.2.2/SWS_EthIf_00094 */
ETHIF_DET_REPORTERROR((BufIdx < EthIf_ConfigPointer->EthIfCtrlCfg[CtrlIdx].EthIfMaxTxBufsTotal),ETHIF_SERVICE_ID_TX_CONFIRMATION, ETHIF_E_INV_PARAM);
/* TX Confirmation function to UL */
if(NULL != EthIf_ConfigPointer->EthIfULTxConfirmation)
{
for (i=0; i < EthIf_ConfigPointer->EthIfOwnersCount; i++) {
if (BufIdx == EthIf_Internal.ethIfRunTime[i].bufferIdx ) {
txhandle = EthIf_ConfigPointer->EthIfOwnerCfg[i].EthIfTxConfirmationHandle;
if (INVALID_ETHIF_HANDLE != txhandle) {
/* @req 4.2.2/SWS_EthIf_00125 */
EthIf_ConfigPointer->EthIfULTxConfirmation[txhandle]( CtrlIdx, BufIdx );
}
break;
}
}
}
}
/**
*
* @param CtrlIdx
* @param CtrlMode
*/
/* @req 4.2.2/SWS_EthIf_00231 */
void EthIf_CtrlModeIndication( uint8 CtrlIdx, Eth_ModeType CtrlMode ) {
/* @req 4.2.2/SWS_EthIf_00017 */
ETHIF_DET_REPORTERROR((ETHIF_STATE_INIT == EthIf_Internal.initStatus),ETHIF_SERVICE_ID_CTRL_MODE_INDICATION, ETHIF_E_NOT_INITIALIZED);
/* @req 4.2.2/SWS_EthIf_00017 */
ETHIF_DET_REPORTERROR((CtrlIdx < EthIf_ConfigPointer->EthIfCtrlCount),ETHIF_SERVICE_ID_CTRL_MODE_INDICATION, ETHIF_E_INV_CTRL_IDX);
/* @req 4.2.2/SWS_EthIf_00252 */
EthSM_CtrlModeIndication(EthIf_ConfigPointer->EthIfCtrlCfg[CtrlIdx].EthIfCtrlId, CtrlMode);
}
#if (ETHIF_ENABLE_RX_INTERRUPT == STD_OFF)
/* @req 4.2.2/SWS_EthIf_00099 */
/* @req 4.2.2/SWS_EthIf_00097 */
/* @req 4.2.2/SWS_EthIf_00004 */
void EthIf_MainFunctionRx( void ) {
Eth_RxStatusType RxStatusPtr;
RxStatusPtr = ETH_NOT_RECEIVED;
uint8 i;
uint8 CtrlIdx;
/* @req 4.2.2/SWS_EthIf_00098 */
ETHIF_DET_REPORTERROR((ETHIF_STATE_INIT == EthIf_Internal.initStatus),ETHIF_SERVICE_ID_MAIN_FUNCTION_RX, ETHIF_E_NOT_INITIALIZED);
for(CtrlIdx = 0u; CtrlIdx < ETHIF_CTRLS_CNT; CtrlIdx++)
{
Eth_Receive(EthIf_ConfigPointer->EthIfCtrlCfg[CtrlIdx].EthIfEthCtrlId, &RxStatusPtr);
for(i= 0; i < ETHIF_RX_INDICATION_ITERATIONS; i++)
{
if(RxStatusPtr == ETH_RECEIVED_MORE_DATA_AVAILABLE)
{
Eth_Receive(EthIf_ConfigPointer->EthIfCtrlCfg[CtrlIdx].EthIfEthCtrlId, &RxStatusPtr);
} else {
break;
}
}
}
}
#endif
#if (ETHIF_ENABLE_TX_INTERRUPT == STD_OFF)
/* @req 4.2.2/SWS_EthIf_00100 */
/* @req 4.2.2/SWS_EthIf_00004 */
/**
*
*/
/* @req 4.2.2/SWS_EthIf_00113 */
void EthIf_MainFunctionTx( void ){
uint8 CtrlIdx;
/* @req 4.2.2/SWS_EthIf_00124 */
ETHIF_DET_REPORTERROR((ETHIF_STATE_INIT == EthIf_Internal.initStatus),ETHIF_SERVICE_ID_MAIN_FUNCTION_TX, ETHIF_E_NOT_INITIALIZED);
for(CtrlIdx=0; CtrlIdx < ETHIF_CTRLS_CNT; CtrlIdx++)
{
/* @req 4.2.2/SWS_EthIf_00115 */
Eth_TxConfirmation( EthIf_ConfigPointer->EthIfCtrlCfg[CtrlIdx].EthIfEthCtrlId );
}
}
#endif
/**
* @param CtrlIdx
* @param FrameType
* @param Priority
* @param BufIdxPtr
* @param BufPtr
* @param LenBytePtr
* @return
*/
/* @req 4.2.2/SWS_EthIf_00067 */
BufReq_ReturnType EthIf_ProvideTxBuffer( uint8 CtrlIdx, Eth_FrameType FrameType, uint8 Priority, Eth_BufIdxType* BufIdxPtr, uint8** BufPtr, uint16* LenBytePtr ) {
BufReq_ReturnType ret;
uint8 * IntrnlBuf;
(void)FrameType;
/* @req 4.2.2/SWS_EthIf_00069 */
ETHIF_DET_REPORTERROR((ETHIF_STATE_INIT == EthIf_Internal.initStatus),ETHIF_SERVICE_ID_PROVIDE_TX_BUFFER, ETHIF_E_NOT_INITIALIZED, BUFREQ_NOT_OK);
/* @req 4.2.2/SWS_EthIf_00070 */
ETHIF_DET_REPORTERROR((CtrlIdx < EthIf_ConfigPointer->EthIfCtrlCount),ETHIF_SERVICE_ID_PROVIDE_TX_BUFFER, ETHIF_E_INV_CTRL_IDX, BUFREQ_NOT_OK);
/* @req 4.2.2/SWS_EthIf_00071 */
ETHIF_DET_REPORTERROR((NULL != BufIdxPtr),ETHIF_SERVICE_ID_PROVIDE_TX_BUFFER, ETHIF_E_PARAM_POINTER, BUFREQ_NOT_OK);
/* @req 4.2.2/SWS_EthIf_00072 */
ETHIF_DET_REPORTERROR((NULL != BufPtr),ETHIF_SERVICE_ID_PROVIDE_TX_BUFFER, ETHIF_E_PARAM_POINTER, BUFREQ_NOT_OK);
/* @req 4.2.2/SWS_EthIf_00073 */
ETHIF_DET_REPORTERROR((NULL != LenBytePtr),ETHIF_SERVICE_ID_PROVIDE_TX_BUFFER, ETHIF_E_PARAM_POINTER, BUFREQ_NOT_OK);
/* @req 4.2.2/SWS_EthIf_00146*/
if(INVALID_VLAN_ID == EthIf_ConfigPointer->EthIfCtrlCfg[CtrlIdx].EthIfVlanId)
{
if(EthIf_ConfigPointer->EthIfCtrlCfg[CtrlIdx].EthIfCtrlMtu >= *LenBytePtr)
{
/*@req 4.2.2/SWS_EthIf_00068 */
ret = Eth_ProvideTxBuffer(EthIf_ConfigPointer->EthIfCtrlCfg[CtrlIdx].EthIfEthCtrlId, BufIdxPtr, BufPtr, LenBytePtr);
} else {
ret = BUFREQ_NOT_OK;
}
}
/* @req 4.2.2/SWS_EthIf_00147*/ /* @req 4.2.2/SWS_EthIf_00128 */
else
{
/* @req 4.2.2/SWS_EthIf_00129 */ /* @req 4.2.2/SWS_EthIf_00130 */
if((EthIf_ConfigPointer->EthIfCtrlCfg[CtrlIdx].EthIfCtrlMtu >= *LenBytePtr) && (Priority < PRIORITY_SIZE))
{
*LenBytePtr= (*LenBytePtr + VLAN_TAG_SIZE);
/*@req 4.2.2/SWS_EthIf_00068 */
ret = Eth_ProvideTxBuffer(EthIf_ConfigPointer->EthIfCtrlCfg[CtrlIdx].EthIfEthCtrlId, BufIdxPtr, BufPtr, LenBytePtr);
IntrnlBuf = *BufPtr;
if (BUFREQ_OK == ret) {
IntrnlBuf[0] = (uint8)( Priority << PCP_SHIFT_BITS_5);
IntrnlBuf[0] &= (uint8)((~((uint8)1) << (PCP_SHIFT_BITS_4)));
IntrnlBuf[0] |= (uint8)((EthIf_ConfigPointer->EthIfCtrlCfg[CtrlIdx].EthIfVlanId & VLAN_MASK_NIBBLE) >> SHIFT_EIGHT_BITS);
IntrnlBuf[1] = (uint8)(EthIf_ConfigPointer->EthIfCtrlCfg[CtrlIdx].EthIfVlanId & VLAN_MASK_BYTE);
IntrnlBuf[2] = (uint8)((FrameType >> ETHIF_SHIFT_BYTE1) & ETHIF_BYTE_MASK);
IntrnlBuf[3] = (uint8)( FrameType & ETHIF_BYTE_MASK);
}
/*lint -e{438} */
*BufPtr = &IntrnlBuf[VLAN_TAG_SIZE];
*LenBytePtr = (*LenBytePtr - VLAN_TAG_SIZE);
}else {
ret = BUFREQ_NOT_OK;
}
}
return ret;
}
/**
*
* @param CtrlIdx
* @param BufIdx
* @param FrameType
* @param TxConfirmation
* @param LenByte
* @param PhysAddrPtr
* @return
*/
/* @req 4.2.2/SWS_EthIf_00075 */
Std_ReturnType EthIf_Transmit( uint8 CtrlIdx, Eth_BufIdxType BufIdx, Eth_FrameType FrameType, boolean TxConfirmation, uint16 LenByte, const uint8* PhysAddrPtr ) {
Std_ReturnType ret;
uint8 i;
/* @req 4.2.2/SWS_EthIf_00077 */
ETHIF_DET_REPORTERROR((ETHIF_STATE_INIT == EthIf_Internal.initStatus),ETHIF_SERVICE_ID_TRANSMIT, ETHIF_E_NOT_INITIALIZED, E_NOT_OK);
/* @req 4.2.2/SWS_EthIf_00078 */
ETHIF_DET_REPORTERROR((CtrlIdx < EthIf_ConfigPointer->EthIfCtrlCount),ETHIF_SERVICE_ID_TRANSMIT, ETHIF_E_INV_CTRL_IDX, E_NOT_OK);
/* @req 4.2.2/SWS_EthIf_00079 */
ETHIF_DET_REPORTERROR((BufIdx < EthIf_ConfigPointer->EthIfCtrlCfg[CtrlIdx].EthIfMaxTxBufsTotal),ETHIF_SERVICE_ID_TRANSMIT, ETHIF_E_INV_PARAM, E_NOT_OK);
/* @req 4.2.2/SWS_EthIf_00080 */
ETHIF_DET_REPORTERROR((NULL != PhysAddrPtr),ETHIF_SERVICE_ID_TRANSMIT, ETHIF_E_PARAM_POINTER, E_NOT_OK);
if(EthIf_ConfigPointer->EthIfCtrlCfg[CtrlIdx].EthIfCtrlMtu >= LenByte)
{
/* @req 4.2.2/SWS_EthIf_00250 */
if(INVALID_VLAN_ID != EthIf_ConfigPointer->EthIfCtrlCfg[CtrlIdx].EthIfVlanId)
{
/* @req 4.2.2/SWS_EthIf_00076 */
ret = Eth_Transmit(EthIf_ConfigPointer->EthIfCtrlCfg[CtrlIdx].EthIfEthCtrlId, BufIdx, ETH_FRAME_TYPE_VLAN, TxConfirmation, (LenByte + VLAN_TAG_SIZE), PhysAddrPtr);
}
else
{
/* @req 4.2.2/SWS_EthIf_00076 */
ret = Eth_Transmit(EthIf_ConfigPointer->EthIfCtrlCfg[CtrlIdx].EthIfEthCtrlId, BufIdx, FrameType, TxConfirmation, LenByte, PhysAddrPtr);
}
if ((E_OK == ret) && (EthIf_ConfigPointer->EthIfULTxConfirmation != NULL_PTR)){
for (i=0; i < EthIf_ConfigPointer->EthIfOwnersCount; i++) {
if ((FrameType == EthIf_Internal.ethIfRunTime[i].frameType)) {
if (TRUE == TxConfirmation) {
EthIf_Internal.ethIfRunTime[i].bufferIdx = BufIdx; /* Currently used buffer index stored for the requested frame type */
} else {
EthIf_Internal.ethIfRunTime[i].bufferIdx = INVALID_BUFFER_INDEX; /* Reset the buffer index when no TxConfirmation is requested */
}
break;
}
}
}
} else{
ret = E_NOT_OK;
}
return ret;
}
/**
*
* @param CtrlIdx
* @param FrameType
* @param IsBroadcast
* @param PhysAddrPtr
* @param DataPtr
* @param LenByte
*/
/* @req 4.2.2/SWS_EthIf_00085 */ /* @req 4.2.2/SWS_EthIf_00151 */
/* @req 4.2.2/SWS_EthIf_00090 */ /* EthIf_RxIndication function shall be callable on interrupt level.*/
void EthIf_RxIndication( uint8 CtrlIdx, Eth_FrameType FrameType, boolean IsBroadcast, const uint8* PhysAddrPtr, Eth_DataType* DataPtr, uint16 LenByte ) {
uint8 i;
uint8 handle;
Eth_FrameType adaptFrameType;
adaptFrameType = 0u;
Eth_DataType* adaptDataPtr;
adaptDataPtr = NULL_PTR;
uint16 adaptLenByte;
adaptLenByte = 0u;
boolean status;
status = TRUE;
/* @req 4.2.2/SWS_EthIf_00086 */
ETHIF_DET_REPORTERROR((ETHIF_STATE_INIT == EthIf_Internal.initStatus),ETHIF_SERVICE_ID_RX_INDICATION, ETHIF_E_NOT_INITIALIZED);
/* @req 4.2.2/SWS_EthIf_00087 */
ETHIF_DET_REPORTERROR((CtrlIdx < EthIf_ConfigPointer->EthIfCtrlCount),ETHIF_SERVICE_ID_RX_INDICATION, ETHIF_E_INV_CTRL_IDX);
/* @req 4.2.2/SWS_EthIf_00088 */
ETHIF_DET_REPORTERROR((NULL != DataPtr),ETHIF_SERVICE_ID_RX_INDICATION, ETHIF_E_PARAM_POINTER);
/* @req 4.2.2/SWS_EthIf_00145 */
if(INVALID_VLAN_ID == EthIf_ConfigPointer->EthIfCtrlCfg[CtrlIdx].EthIfVlanId){
adaptFrameType = FrameType;
adaptDataPtr = DataPtr;
adaptLenByte = LenByte;
}else {
if(FrameType == ETH_FRAME_TYPE_VLAN){
uint16 tCI = 0u;
tCI |= (uint16) DataPtr[0] << ETHIF_SHIFT_BYTE1;/*lint !e9033 no harm in shifting */
tCI |= (uint16) DataPtr[1];/*lint !e9033 no harm in taking the byte pointer*/
if((tCI & ETHIF_VID_MASK) != EthIf_ConfigPointer->EthIfCtrlCfg[CtrlIdx].EthIfVlanId ){
status = FALSE;
/* Error- no processing involved */
} else {
adaptFrameType = 0u;
adaptDataPtr = &DataPtr[VLAN_TAG_SIZE];
adaptLenByte = LenByte-VLAN_TAG_SIZE;
adaptFrameType |= (Eth_FrameType) DataPtr[2] << ETHIF_SHIFT_BYTE1; /*lint !e9033 no harm in shifting */
adaptFrameType |= (Eth_FrameType) DataPtr[3];/*lint !e9033 no harm in taking the byte pointer*/
}
}else{
status = FALSE;
/* Error- no processing involved */
}
}
if (status == TRUE) {
for(i =0 ; i < EthIf_ConfigPointer->EthIfOwnersCount; i ++){
if(adaptFrameType == EthIf_ConfigPointer->EthIfOwnerCfg[i].EthIfFrameType){
handle = EthIf_ConfigPointer->EthIfOwnerCfg[i].EthIfRxIndicationHandle;
if( handle != INVALID_ETHIF_HANDLE){
EthIf_ConfigPointer->EthIfULRxIndication[handle](CtrlIdx, adaptFrameType, IsBroadcast, PhysAddrPtr, adaptDataPtr, adaptLenByte);
}
}
}
}
}
#ifdef HOST_TEST
EthIf_StateType readinternal_ethif_status(void );
EthIf_StateType readinternal_ethif_status(void)
{
return EthIf_Internal.initStatus;
}
#endif
|
2301_81045437/classic-platform
|
communication/EthIf/src/EthIf.c
|
C
|
unknown
| 27,067
|
#Ethernet
obj-$(USE_ETHSM) += EthSM_Cfg.o
obj-$(USE_ETHSM) += EthSM.o
vpath-$(USE_ETHSM) += $(ROOTDIR)/communication/EthSM/src
inc-$(USE_ETHSM) += $(ROOTDIR)/communication/EthSM/inc
|
2301_81045437/classic-platform
|
communication/EthSM/EthSM.mod.mk
|
Makefile
|
unknown
| 189
|
/*-------------------------------- 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 -----------------------------*/
/* @req 4.2.2/SWS_EthSM_00004 */ /* The header file shall export EthSM module specific types and API´s */
#ifndef ETH_SM_H_
#define ETH_SM_H_
/* ASR does not mention these, but needed to be included */
#include "Eth_GeneralTypes.h"
#include "ComM.h"
#include "TcpIp_Types.h"
#define ETHSM_VENDOR_ID 60u
#define ETHSM_MODULE_ID 143u
#define ETHSM_AR_RELEASE_MAJOR_VERSION 4u
#define ETHSM_AR_RELEASE_MINOR_VERSION 2u
#define ETHSM_AR_RELEASE_PATCH_VERSION 2u
#define ETHSM_SW_MAJOR_VERSION 2u
#define ETHSM_SW_MINOR_VERSION 0u
#define ETHSM_SW_PATCH_VERSION 0u
/* Development errors */
#define ETHSM_E_INVALID_NETWORK_MODE 0x01u
#define ETHSM_E_UNINIT 0x02u
#define ETHSM_E_PARAM_POINTER 0x03u
#define ETHSM_E_INVALID_NETWORK_HANDLE 0x04u
#define ETHSM_E_INVALID_TCP_IP_MODE 0x05u
#define ETHSM_E_INVALID_TRCV_LINK_STATE 0x06u
#define ETHSM_E_PARAM_CONTROLLER 0x07u
/* ArcCore extra Error ids */
#define ETHSM_E_GET_ETH_MODE_RET_NOK 0x20u
#define ETHSM_E_GET_ETHTRCV_MODE_RET_NOK 0x21u
#define ETHSM_E_REQ_TCPIP_MODE_CHG_RET_NOK 0x22u
#define ETHSM_E_REQ_ETH_MODE_CHG_RET_NOK 0x23u
#define ETHSM_E_REQ_ETHTRCV_MODE_CHG_RET_NOK 0x24u
/* API ids */
#define ETHSM_MAINFUNCTION_ID 0x01u
#define ETHSM_GETVERSIONINFO_ID 0x02u
#define ETHSM_GETCURRENTINTERNALMODE_ID 0x03u
#define ETHSM_GETCURRENTCOMMODE_ID 0x04u
#define ETHSM_REQUESTCOMMODE_ID 0x05u
#define ETHSM_TRCVLINKSTATECHG_ID 0x06u
#define ETHSM_INIT_ID 0x07u
#define ETHSM_TCPIPMODEINDICATION_ID 0x08u
#define ETHSM_CTRLMODEINDICATION_ID 0x09u
#define ETHSM_TRCVMODEINDICATION_ID 0x10u
/* ArcCore extra API ids */
#define ETHSM_GLOBAL_ID 0x20u
/* @req 4.2.2/SWS_EthSM_00041 */
/* This type shall define the states of the network mode state machine */
typedef enum{
ETHSM_STATE_OFFLINE, /* EthSM is initialized in this state. */
ETHSM_STATE_WAIT_TRCVLINK, /* ComM requests COMM_FULL_COMMUNICATION in this state. Controller and transceiver will be initialized and set to ACTIVE. EthSM waits for transceiver link state (ACTIVE)*/
ETHSM_STATE_WAIT_ONLINE, /*Transceiver link state is ACTIVE EthSM waits for IP communication (TcpIP state = ONLINE) */
ETHSM_STATE_ONLINE, /* IP communication is available ComM state COMM_FULL_COMMUNICATION is reached */
ETHSM_STATE_ONHOLD, /* EthSM lost active transceiver link state, TcpIP state is still ONLINE */
ETHSM_STATE_WAIT_OFFLINE /* ComM requests COMM_NO_COMMUNICATION in this state. */
}EthSM_NetworkModeStateType;
#include "EthSM_Types.h"
#include "EthSM_Cfg.h"
/**
* Function routine for ETH SM initialization, called first before calling any other of ETHSM.
*/
void EthSM_Init( void );
/**
* Fetches version information of ETH SM module
* @param versioninfo - address to hold the version
* @return none
*/
void EthSM_GetVersionInfo( Std_VersionInfoType* versioninfo ); /* re-entrant */
/**
* Function routine to request communication mode (FULL or NO)
* @param NetworkHandle - Global Network handle
* @param ComM_Mode - requested node
* @return E_OK or E_NOT_OK
*/
Std_ReturnType EthSM_RequestComMode( NetworkHandleType NetworkHandle, ComM_ModeType ComM_Mode );
/**
* Function routine to read the current communication mode (FULL or NO)
* @param NetworkHandle - Global Network handle
* @param ComM_ModePtr - address to hold the mode
* @return E_OK or E_NOT_OK
*/
Std_ReturnType EthSM_GetCurrentComMode( NetworkHandleType NetworkHandle, ComM_ModeType* ComM_ModePtr );
/**
* Function routine to notice ETHSM about tranceiver link state changes
* @param CtrlIdx - controller id
* @param TransceiverLinkState - Trcv Link state
* @return none
*/
void EthSM_TrcvLinkStateChg( uint8 CtrlIdx, EthTrcv_LinkStateType TransceiverLinkState );
/**
* Function routine to get internal network mode of ETH SM
* @param NetworkHandle - Global Network handle
* @param EthSM_InternalMode - address to hold the internal mode
* @return E_OK or E_NOT_OK
*/
Std_ReturnType EthSM_GetCurrentInternalMode( NetworkHandleType NetworkHandle, EthSM_NetworkModeStateType* EthSM_InternalMode );
/**
* Main function to be called with a periodic time frame to carry out state FSM and others.
* @param none
* @return none
*/
void EthSM_MainFunction( void );
extern const EthSM_ConfigType EthSMConfig;
#endif /* ETH_SM_H_ */
|
2301_81045437/classic-platform
|
communication/EthSM/inc/EthSM.h
|
C
|
unknown
| 5,383
|
/*-------------------------------- 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 ETHSM_CBK_H_
#define ETHSM_CBK_H_
/* Function prototypes of the call back functions used from outside modules, but for ETHSM */
void EthSM_CtrlModeIndication ( uint8 CtrlIdx, Eth_ModeType CtrlMode );
void EthSM_TrcvModeIndication ( uint8 CtrlIdx, EthTrcv_ModeType TrcvMode );
/**
* Function routine to notice ETHSM about TCPIP state
* @param CtrlIdx - controller id
* @param TcpIpState - TCPIP Link state
* @return E_OK or E_NOT_OK
*/
Std_ReturnType EthSM_TcpIpModeIndication( uint8 CtrlIdx, TcpIp_StateType TcpIpState );
#endif /* ETHSM_CBK_H_ */
|
2301_81045437/classic-platform
|
communication/EthSM/inc/EthSM_Cbk.h
|
C
|
unknown
| 1,341
|
/*-------------------------------- 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 ETHSM_TYPES_H_
#define ETHSM_TYPES_H_
/* @req 4.2.2/SWS_EthSM_00006 *//*This header file EthSM_Types.h exports the EthSM specific types */
#if defined(USE_DEM)
#include "Dem.h"
#endif
/* Configuration Types are also included here */
typedef struct {
const uint8 EthIfControllerId; /* EthIf Controller Id */
const uint8 ComMNetworkHandle; /* ComM channel Id*/
const boolean EthTrcvAvailable; /* TRCV suppoerted */
#if defined(USE_DEM)
Dem_EventIdType ETHSM_E_LINK_DOWN; /* Reference to configured DEM event to report bus off errors for this Eth network.*/
#endif
}EthSM_NetworkConfigType;
typedef struct {
const EthSM_NetworkConfigType *Networks; /* Pointer to configured networks list */
uint8 NofNetworks; /* No of configured networks */
}EthSM_ConfigSetType;
typedef struct {
const EthSM_ConfigSetType *ConfigSet; /* pointer EthSM config data */
}EthSM_ConfigType;
typedef enum {
ETHSM_STATUS_UNINIT, /* EthSM is in this state before EthSM_init.*/
ETHSM_STATUS_INIT /* EthSM is initialized in this state after EthSM_init. */
} EthSM_Internal_InitStatusType;
typedef struct {
ComM_ModeType RequestedMode; /* holds network Request mode */
ComM_ModeType CurrentMode; /* holds current mode of network */
TcpIp_StateType TcpIpState; /* holds TCP/IP state of network */
EthTrcv_LinkStateType TrcvLinkState; /* holds Trcv Link state of network */
EthSM_NetworkModeStateType NetworkMode; /* states of the network mode of state machine */
Eth_ModeType CtrlMode; /* holds the Eth controller mode */
EthTrcv_ModeType TrcvMode; /* holds the EthTrcv mode */
uint8 RequestStream; /* holds request for network is done or not status*/
} EthSM_Internal_NetworkType;
typedef struct {
EthSM_Internal_InitStatusType InitStatus; /* Status of EthSM Module */
EthSM_Internal_NetworkType* Networks; /* pointer to hold internal states of networks */
const EthSM_ConfigType* SMConfig; /* pointer to hold configured data */
} EthSM_InternalType;
#endif /* ETHSM_TYPES_H_ */
|
2301_81045437/classic-platform
|
communication/EthSM/inc/EthSM_Types.h
|
C
|
unknown
| 3,032
|
/*-------------------------------- 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 -----------------------------*/
/* Globally fulfilled requirements */
/* General requirements */
/* @req 4.2.2/SWS_EthSM_00001 */ /* ETH SM is an abstract interface to ComM for COM control */
/* @req 4.2.2/SWS_EthSM_00002 */ /*The Ethernet SM doesn't directly access Ethernet hardware but by means of Eth_IF*/
/* @req 4.2.2/SWS_EthSM_00016 */ /* The state transition shall translate the request into a respective API call to control the assigned Ethernet peripherals*/
/* @req 4.2.2/SWS_EthSM_00019 */ /* assignment between network handles and transceivers is part of EthSM configuration*/
/* @req 4.2.2/SWS_EthSM_00020 */ /*EthSM controls the Ethernet transceivers depending on the state transitions*/
/* @req 4.2.2/SWS_EthSM_00021 */ /*EthSM will use the API of the EthIf for the control of the Ethernet transceiver modes*/
/* @req 4.2.2/SWS_EthSM_00022 */ /* EthSM controls the Ethernet controller modes of each Ethernet network*/
/* @req 4.2.2/SWS_EthSM_00023 */ /* EthSM shall use the API of the EthIf to control the operating modes of the Ethernet controllers*/
/* @req 4.2.2/SWS_EthSM_00078 */ /* Dummy mode requirement */
/* @req 4.2.2/SWS_EthSM_00085 */ /* If FULL_COMMUNICATION is requested then the Ethernet controller and the Ethernet transceiver are set to the state ACTIVE*/
/* @req 4.2.2/SWS_EthSM_00086 */ /* If NO_COMMUNICATION is requested then the Ethernet controller and the Ethernet transceiver are set to the state DOWN*/
/*==================[inclusions]==============================================*/
#include "ComStack_Types.h"
#include "EthSM.h" /* @req 4.2.2/SWS_EthSM_00007 */
#include "ComM.h" /* @req 4.2.2/SWS_EthSM_00189 */
#include "ComM_BusSM.h" /* @req 4.2.2/SWS_EthSM_00013 */
#if defined(USE_DEM)
#include "Dem.h"
#endif
#if ETHSM_DUMMY_MODE == STD_OFF
#include "EthIf.h" /* @req 4.2.2/SWS_EthSM_00010 */
#endif
#if defined(USE_BSWM)
#include "BswM_EthSM.h" /* @req 4.2.2/SWS_EthSM_00080 */
#endif
#include "TcpIp_EthSM.h" /* @req 4.2.2/SWS_EthSM_00106 */
#include "EthSM_Cbk.h" /* Non ASR include */
#include "MemMap.h"
//lint -emacro(904,ETHSM_VALIDATE_NO_RV,ETHSM_VALIDATE_RV) //904 PC-Lint exception to MISRA 14.7 (validate DET macros).
/*==================[Macros needed]===========================================*/
#if ( ETHSM_DEV_ERROR_DETECT == STD_ON )
/* @req 4.2.2/SWS_EthSM_00008 */
#if defined(USE_DET)
#include "Det.h"
#else
#error "EthSM: DET must be used when DEV error detect is enabled"
#endif /*USE_DET */
#define DET_REPORT_ERROR(_api,_err) (void)Det_ReportError(ETHSM_MODULE_ID,0,(_api),(_err))
#define ETHSM_VALIDATE_RV(_exp,_api,_err,_rv) \
if( !(_exp) ) { \
DET_REPORT_ERROR(_api,_err); \
return (_rv); \
}
#define ETHSM_VALIDATE_NO_RV(_exp,_api,_err) \
if( !(_exp) ) { \
DET_REPORT_ERROR(_api,_err); \
return; \
}
#define ETHSM_VALIDATE(expression, serviceId, errorId, ...) \
if (!(expression)) { \
ETHSM_DET_REPORTERROR(serviceId, errorId); \
return __VA_ARGS__; \
}
#else
#define DET_REPORT_ERROR(_api,_err)
#define ETHSM_VALIDATE_RV(_exp,_api,_err,_rv) \
if( !(_exp) ) { \
return (_rv); \
}
#define ETHSM_VALIDATE_NO_RV(_exp,_api,_err) \
if( !(_exp) ) { \
return; \
}
#endif /*ETHSM_DEV_ERROR_DETECT*/
#ifndef DEM_EVENT_ID_NULL
#define DEM_EVENT_ID_NULL 0u
#endif
#define ETHSM_INVALID_HANDLE 0xFFu
#define ETHSM_INVALID_CTRL 0xFFu
/********* Mode request owners ******************/
#define ETHSM_COMM_MODE_REQUEST 0u
#define ETHSM_ETHIF_ETH_MODE_REQUEST 1u
#define ETHSM_ETHIF_ETHTRCV_MODE_REQUEST 2u
#define ETHSM_TCPIP_MODE_REQUEST 3u
/********* Mode request owners ******************/
#define ETHSM_MODE_REQUEST_CLEAR(_handle, _owner) \
(EthSM_Internal.Networks[_handle].RequestStream &= (~(1u << _owner)))
#define ETHSM_MODE_REQUEST_SET(_handle, _owner ) \
(EthSM_Internal.Networks[_handle].RequestStream |= (1u << _owner))
#define ETHSM_MODE_POS(_owner ) (1u << _owner)
#define ETHSM_GET_CHANNEL(_handle ) \
(EthSM_Internal.SMConfig->ConfigSet->Networks[_handle].ComMNetworkHandle)
#define ETHSM_GET_CTRL_IDX(_handle ) \
(EthSM_Internal.SMConfig->ConfigSet->Networks[_handle].EthIfControllerId)
/*==================[external data]===========================================*/
/*==================[Static variables]===========================================*/
static EthSM_Internal_NetworkType EthSM_InternalNetworks[ETHSM_NETWORK_COUNT];
static EthSM_InternalType EthSM_Internal = {
.InitStatus = ETHSM_STATUS_UNINIT,
.Networks = EthSM_InternalNetworks,
.SMConfig = &EthSMConfig /* @req 4.2.2/SWS_EthSM_00061 */
};
/*==================[Static functions]===========================================*/
#if ETHSM_DUMMY_MODE != STD_ON
#if (ETHSM_ETH_TRCV_SUPPORT == STD_ON)
/**
* Function to Check Trcv link state Down/Active
* @param NetworkHandle
* @param LinkState
* @param Flag
* @return
*/
INLINE static boolean EthSM_Internal_CheckTrcvLink(NetworkHandleType NetworkHandle, EthTrcv_LinkStateType LinkState, boolean Active){
boolean ret;
if(TRUE == EthSMConfig.ConfigSet->Networks[NetworkHandle].EthTrcvAvailable){
if(LinkState == EthSM_Internal.Networks[NetworkHandle].TrcvLinkState ){
ret = TRUE;
}else{
ret = FALSE;
}
}else {
/*lint -e{731} */
if(TRUE == Active){
ret = TRUE; /* TRUE means By pass TRCV State making TRUE by default */
}else {
ret = FALSE; /* FALSE means no need to enter TRCV related state since no Support */
}
}
return ret;
}
/**
* Function to check Ctrl Mode Down/Active
* @param NetworkHandle
* @param Mode
* @return
*/
INLINE static boolean EthSM_Internal_CheckTrcvMode(NetworkHandleType NetworkHandle, EthTrcv_ModeType Mode){
boolean ret;
if(STD_ON == EthSMConfig.ConfigSet->Networks[NetworkHandle].EthTrcvAvailable){
if(Mode == EthSM_Internal.Networks[NetworkHandle].TrcvMode ){
ret = TRUE;
}else {
ret = FALSE;
}
}else {
ret = TRUE;
}
return ret;
}
#endif
#endif
/**
* Check Received CtrlIdx is configured in the configuration of the EthSM module
* @param CtrlIdx
* @return uint8
*/
static uint8 EthSM_Internal_CheckEthIfCtrl ( uint8 CtrlIdx){
uint8 status;
status = ETHSM_INVALID_CTRL;
for (uint8 i = 0; i < ETHSM_NETWORK_COUNT; i++) {
if(CtrlIdx == ETHSM_GET_CTRL_IDX(i)) {
status = CtrlIdx;
break;
}
}
return status;
}
/**
* Gives back with mapped Network handle of Ethernet interface controller index
* @param CtrlIdx
* @return NetworkHandleType
*/
static NetworkHandleType EthSM_Internal_GetNetworkHandleEth ( uint8 CtrlIdx){
NetworkHandleType networkHandle;
networkHandle = ETHSM_INVALID_HANDLE;
for (uint8 i = 0; i < ETHSM_NETWORK_COUNT; i++) {
if(CtrlIdx == ETHSM_GET_CTRL_IDX(i)) {
networkHandle = i;
break;
}
}return networkHandle;
}
/**
* Gives back with mapped Network handle of associated global network / ComM
* @param CtrlIdx
* @return NetworkHandleType
*/
static NetworkHandleType EthSM_Internal_GetNetworkHandleComM ( NetworkHandleType Channel){
NetworkHandleType status;
status = ETHSM_INVALID_HANDLE;
for (uint8 i = 0; i < ETHSM_NETWORK_COUNT; i++) {
if(Channel == ETHSM_GET_CHANNEL(i)){
status = (NetworkHandleType)i;
break;
}
}
return status;
}
/**
* Change State/mode and notify same to the clients if any
* @param NetworkHandle
* @param State
* @return None
*/
static void EthSM_Internal_ChangeNetworkModeState ( NetworkHandleType NetworkHandle,EthSM_NetworkModeStateType State){
EthSM_Internal.Networks[NetworkHandle].NetworkMode = State;
switch (EthSM_Internal.Networks[NetworkHandle].NetworkMode){
case ETHSM_STATE_OFFLINE:
case ETHSM_STATE_WAIT_TRCVLINK:
case ETHSM_STATE_WAIT_ONLINE:
EthSM_Internal.Networks[NetworkHandle].CurrentMode = COMM_NO_COMMUNICATION;
break;
case ETHSM_STATE_ONLINE:
case ETHSM_STATE_ONHOLD:
case ETHSM_STATE_WAIT_OFFLINE:
EthSM_Internal.Networks[NetworkHandle].CurrentMode = COMM_FULL_COMMUNICATION;
break;
default:
break;
}
#if defined(USE_BSWM)
BswM_EthSM_CurrentState(EthSM_Internal.SMConfig->ConfigSet->Networks[NetworkHandle].ComMNetworkHandle,State);
#endif
}
/**
* Enables or disables Ethernet controller and Ethernet tranciever,
* loop backed here if dummy mode is ON
* @param NetworkHandle
* @param ComM_Mode
* @return none
*/
static void EthSM_Internal_RequestEthIfModeChg(NetworkHandleType NetworkHandle) {
if(((EthSM_Internal.Networks[NetworkHandle].RequestStream & (ETHSM_MODE_POS(ETHSM_ETHIF_ETH_MODE_REQUEST))) != (ETHSM_MODE_POS(ETHSM_ETHIF_ETH_MODE_REQUEST))) &&
((EthSM_Internal.Networks[NetworkHandle].RequestStream & (ETHSM_MODE_POS(ETHSM_ETHIF_ETHTRCV_MODE_REQUEST))) != (ETHSM_MODE_POS(ETHSM_ETHIF_ETHTRCV_MODE_REQUEST)))){
ETHSM_MODE_REQUEST_SET(NetworkHandle,ETHSM_ETHIF_ETH_MODE_REQUEST);
#if (ETHSM_ETH_TRCV_SUPPORT == STD_ON)
if(STD_ON == EthSM_Internal.SMConfig->ConfigSet->Networks[NetworkHandle].EthTrcvAvailable ){
ETHSM_MODE_REQUEST_SET(NetworkHandle,ETHSM_ETHIF_ETHTRCV_MODE_REQUEST);
}
#endif
#if ETHSM_DUMMY_MODE != STD_ON
boolean status;
status = TRUE;
Std_ReturnType RetVal;
uint8 CtrlIdx;
Eth_ModeType CtrlMode;
CtrlMode = ETH_MODE_DOWN;
#if (ETHSM_ETH_TRCV_SUPPORT == STD_ON)
EthTrcv_ModeType TrcvMode;
TrcvMode = ETHTRCV_MODE_DOWN;
#endif
CtrlIdx = ETHSM_GET_CTRL_IDX(NetworkHandle);
switch (EthSM_Internal.Networks[NetworkHandle].RequestedMode) {
case COMM_NO_COMMUNICATION:
CtrlMode = ETH_MODE_DOWN;
#if (ETHSM_ETH_TRCV_SUPPORT == STD_ON)
TrcvMode = ETHTRCV_MODE_DOWN;
#endif
break;
case COMM_FULL_COMMUNICATION:
CtrlMode = ETH_MODE_ACTIVE;
#if (ETHSM_ETH_TRCV_SUPPORT == STD_ON)
TrcvMode = ETHTRCV_MODE_ACTIVE;
#endif
break;
default:
status = FALSE;
break;
}
if (status == TRUE) {
RetVal = EthIf_SetControllerMode (CtrlIdx,CtrlMode);
ETHSM_VALIDATE_NO_RV((RetVal == E_OK),ETHSM_GLOBAL_ID,ETHSM_E_REQ_ETH_MODE_CHG_RET_NOK);/* Retry in main loop is there */
#if (ETHSM_ETH_TRCV_SUPPORT == STD_ON)
if(STD_ON == EthSM_Internal.SMConfig->ConfigSet->Networks[NetworkHandle].EthTrcvAvailable ){
RetVal = EthIf_SetTransceiverMode(CtrlIdx,TrcvMode);
ETHSM_VALIDATE_NO_RV((RetVal == E_OK),ETHSM_GLOBAL_ID,ETHSM_E_REQ_ETHTRCV_MODE_CHG_RET_NOK);/* Retry in main loop is there */
}
#endif
}
#endif
}
}
/**
* Requests mode change of TcpIp module
* @param NetworkHandle
* @param State
* @return none
*/
static void EthSM_Internal_RequestTcpIpModeChg( NetworkHandleType NetworkHandle,TcpIp_StateType State){
if((EthSM_Internal.Networks[NetworkHandle].RequestStream & (ETHSM_MODE_POS(ETHSM_TCPIP_MODE_REQUEST))) != (ETHSM_MODE_POS(ETHSM_TCPIP_MODE_REQUEST))){
ETHSM_MODE_REQUEST_SET(NetworkHandle,ETHSM_TCPIP_MODE_REQUEST);
#if !defined(CFG_ETHSM_TCPIP_NO_SYNC)
Std_ReturnType RetVal;
RetVal = TcpIp_RequestComMode(ETHSM_GET_CTRL_IDX(NetworkHandle),State);
ETHSM_VALIDATE_NO_RV((RetVal == E_OK),ETHSM_GLOBAL_ID,ETHSM_E_REQ_TCPIP_MODE_CHG_RET_NOK);/* Retry in main loop is there */
#else
EthSM_Internal.Networks[NetworkHandle].TcpIpState = State;
#endif
}
}
/**
* Gets and updates the individual controller modes of mapped Ethernet interface
* @param NetworkHandle
* @return none
*/
static void EthSM_Internal_UpdateControllerMode(NetworkHandleType NetworkHandle){
#if ETHSM_DUMMY_MODE != STD_ON
uint8 CtrlIdx;
Std_ReturnType RetVal;
Eth_ModeType CtrlMode;
#if (ETHSM_ETH_TRCV_SUPPORT == STD_ON)
EthTrcv_ModeType TrcvMode;
#endif
CtrlIdx = ETHSM_GET_CTRL_IDX(NetworkHandle);
RetVal = EthIf_GetControllerMode(CtrlIdx,&CtrlMode);
if(RetVal == E_OK){
EthSM_Internal.Networks[NetworkHandle].CtrlMode = CtrlMode;
}else{
/*lint -e{506,774} */
DET_REPORT_ERROR(ETHSM_GLOBAL_ID,ETHSM_E_GET_ETH_MODE_RET_NOK);/* Retry in main loop is there */
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return;
}
#if (ETHSM_ETH_TRCV_SUPPORT == STD_ON)
if(STD_ON == EthSMConfig.ConfigSet->Networks[NetworkHandle].EthTrcvAvailable){
RetVal = EthIf_GetTransceiverMode(CtrlIdx,&TrcvMode);
if(RetVal == E_OK){
EthSM_Internal.Networks[NetworkHandle].TrcvMode = TrcvMode;
}else{
/*lint -e{506,774} */
DET_REPORT_ERROR(ETHSM_GLOBAL_ID,ETHSM_E_GET_ETHTRCV_MODE_RET_NOK);/* Retry in main loop is there */
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return;
}
}
#endif
#else
(void)NetworkHandle;
#endif
}
/**
* Sub Main function to carry out FULL communication WaitOnline finite state machine
* @param NetworkHandle
* @return none
*/
static void EthSM_Internal_FullComWaitOnlineSM(NetworkHandleType NetworkHandle){
boolean ret;
/* @req 4.2.2/SWS_EthSM_00136 */
/* @req 4.2.2/SWS_EthSM_00137 */
/* @req 4.2.2/SWS_EthSM_00138 */
#if ETHSM_DUMMY_MODE == STD_ON
ret = FALSE;
#endif
NetworkHandleType Channel = ETHSM_GET_CHANNEL(NetworkHandle);
#if ETHSM_DUMMY_MODE != STD_ON
#if (ETHSM_ETH_TRCV_SUPPORT == STD_ON)
ret = EthSM_Internal_CheckTrcvLink(NetworkHandle, ETHTRCV_LINK_STATE_DOWN, FALSE);
#else
ret = FALSE;
#endif
#endif
/*lint -e{731,774} */
if(TRUE == ret){
if(TCPIP_STATE_OFFLINE == EthSM_Internal.Networks[NetworkHandle].TcpIpState ){
EthSM_Internal_ChangeNetworkModeState(NetworkHandle,ETHSM_STATE_WAIT_TRCVLINK);
}else{
EthSM_Internal_RequestTcpIpModeChg(NetworkHandle,TCPIP_STATE_OFFLINE);
}
}
/* @req 4.2.2/SWS_EthSM_00146 */
/* @req 4.2.2/SWS_EthSM_00148 */
/* @req 4.2.2/SWS_EthSM_00150 */
else if(EthSM_Internal.Networks[NetworkHandle].TcpIpState == TCPIP_STATE_ONLINE){
EthSM_Internal_ChangeNetworkModeState(NetworkHandle,ETHSM_STATE_ONLINE);
ComM_BusSM_ModeIndication(Channel, &EthSM_Internal.Networks[NetworkHandle].CurrentMode);
}
else{
/* Do nothing */
}
}
/**
* Sub Main function to carry out FULL communication Online finite state machine
* @param NetworkHandle
* @return none
*/
static void EthSM_Internal_FullComOnlineSM(NetworkHandleType NetworkHandle){
/* @req 4.2.2/SWS_EthSM_00166 */
/* @req 4.2.2/SWS_EthSM_00167 */
/* @req 4.2.2/SWS_EthSM_00168 */
boolean ret;
#if ETHSM_DUMMY_MODE == STD_ON
ret = FALSE;
#endif
#if ETHSM_DUMMY_MODE != STD_ON
#if (ETHSM_ETH_TRCV_SUPPORT == STD_ON)
ret = EthSM_Internal_CheckTrcvLink(NetworkHandle, ETHTRCV_LINK_STATE_DOWN, FALSE);
#else
ret = FALSE;
#endif
#endif
NetworkHandleType Channel = ETHSM_GET_CHANNEL(NetworkHandle);
/*lint -e{731,774} */
if(TRUE == ret){
/* @req 4.2.2/SWS_EthSM_00188 */
#if defined(USE_DEM)
if(DEM_EVENT_ID_NULL != EthSM_Internal.SMConfig->ConfigSet->Networks[NetworkHandle].ETHSM_E_LINK_DOWN) {
Dem_ReportErrorStatus(EthSM_Internal.SMConfig->ConfigSet->Networks[NetworkHandle].ETHSM_E_LINK_DOWN, DEM_EVENT_STATUS_FAILED);
}
#endif
if(EthSM_Internal.Networks[NetworkHandle].TcpIpState == TCPIP_STATE_ONHOLD){
EthSM_Internal_ChangeNetworkModeState(NetworkHandle,ETHSM_STATE_ONHOLD);
}else{
EthSM_Internal_RequestTcpIpModeChg(NetworkHandle,TCPIP_STATE_ONHOLD);
}
}
/* @req 4.2.2/SWS_EthSM_00151 *//* @req 4.2.2/SWS_EthSM_00152 *//* @req 4.2.2/SWS_EthSM_00154 */
if(EthSM_Internal.Networks[NetworkHandle].TcpIpState == TCPIP_STATE_OFFLINE){
EthSM_Internal_ChangeNetworkModeState(NetworkHandle,ETHSM_STATE_WAIT_ONLINE);
/* @req 4.2.2/SWS_EthSM_00018 */
ComM_BusSM_ModeIndication(Channel, &EthSM_Internal.Networks[NetworkHandle].CurrentMode);
/* Note: The ntw state will reach ETHSM_STATE_WAIT_ONLINE, who will set up TCP active again?,
* no specification in Autosar, it will be hung in ETHSM_STATE_WAIT_ONLINE as long as link state is active */
}
else{
/* Do nothing */
}
}
/**
* Sub Main function to carry out FULL communication OnHold finite state machine
* @param NetworkHandle
* @return none
*/
static void EthSM_Internal_FullComOnHoldSM(NetworkHandleType NetworkHandle){
/* @req 4.2.2/SWS_EthSM_00174 */
/* @req 4.2.2/SWS_EthSM_00175 */
/* @req 4.2.2/SWS_EthSM_00177 */
boolean ret;
#if ETHSM_DUMMY_MODE == STD_ON
ret = TRUE;
#endif
#if ETHSM_DUMMY_MODE != STD_ON
#if (ETHSM_ETH_TRCV_SUPPORT == STD_ON)
ret = EthSM_Internal_CheckTrcvLink(NetworkHandle, ETHTRCV_LINK_STATE_ACTIVE, TRUE);
#else
ret = TRUE;
#endif
#endif
NetworkHandleType Channel = ETHSM_GET_CHANNEL(NetworkHandle);
if(EthSM_Internal.Networks[NetworkHandle].TcpIpState == TCPIP_STATE_OFFLINE){
EthSM_Internal_ChangeNetworkModeState(NetworkHandle,ETHSM_STATE_WAIT_TRCVLINK);
ComM_BusSM_ModeIndication(Channel, &EthSM_Internal.Networks[NetworkHandle].CurrentMode);
}
/*lint -e731 *//*lint -e774 */
else if (TRUE == ret){
/* @req 4.2.2/SWS_EthSM_00170 */
/* @req 4.2.2/SWS_EthSM_00171 */
/* @req 4.2.2/SWS_EthSM_00172 */
/* @req 4.2.2/SWS_EthSM_00196 */
#if defined(USE_DEM)
if(DEM_EVENT_ID_NULL != EthSM_Internal.SMConfig->ConfigSet->Networks[NetworkHandle].ETHSM_E_LINK_DOWN) {
Dem_ReportErrorStatus(EthSM_Internal.SMConfig->ConfigSet->Networks[NetworkHandle].ETHSM_E_LINK_DOWN, DEM_EVENT_STATUS_PASSED);
}
#endif
if(EthSM_Internal.Networks[NetworkHandle].TcpIpState == TCPIP_STATE_ONLINE){
EthSM_Internal_ChangeNetworkModeState(NetworkHandle,ETHSM_STATE_ONLINE);
}else{
EthSM_Internal_RequestTcpIpModeChg(NetworkHandle,TCPIP_STATE_ONLINE);
}
}
else{
/* Do nothing */
}
}
/*lint -save -e522 EthSM_Internal_UpdateControllerMode() gets compliant because of dummy mode */
/**
* Sub Main function to carry out FULL communication finite state machine
* @param NetworkHandle
* @param State
* @return none
*/
static void EthSM_Internal_FullComFSM(NetworkHandleType NetworkHandle){
boolean ret;
ret = TRUE;
switch (EthSM_Internal.Networks[NetworkHandle].NetworkMode){
case ETHSM_STATE_OFFLINE:
/* @req 4.2.2/SWS_EthSM_00026 */
/* @req 4.2.2/SWS_EthSM_00088 */
/* @req 4.2.2/SWS_EthSM_00089 */
/* @req 4.2.2/SWS_EthSM_00097 */
EthSM_Internal_UpdateControllerMode(NetworkHandle);
#if ETHSM_DUMMY_MODE != STD_ON
#if (ETHSM_ETH_TRCV_SUPPORT == STD_ON)
ret = EthSM_Internal_CheckTrcvMode(NetworkHandle, ETHTRCV_MODE_ACTIVE);
#else
ret = TRUE;
#endif
#endif
/*lint -e{731,774} */
if((TRUE == ret) && (EthSM_Internal.Networks[NetworkHandle].CtrlMode == ETH_MODE_ACTIVE)){
EthSM_Internal_ChangeNetworkModeState(NetworkHandle,ETHSM_STATE_WAIT_TRCVLINK);
}else{
EthSM_Internal_RequestEthIfModeChg(NetworkHandle);
}
break;
case ETHSM_STATE_WAIT_TRCVLINK:
/* @req 4.2.2/SWS_EthSM_00132 */
/* @req 4.2.2/SWS_EthSM_00133 */
/* @req 4.2.2/SWS_EthSM_00134 */
#if ETHSM_DUMMY_MODE != STD_ON
#if (ETHSM_ETH_TRCV_SUPPORT == STD_ON)
ret = EthSM_Internal_CheckTrcvLink(NetworkHandle, ETHTRCV_LINK_STATE_ACTIVE, TRUE);
#else
ret = TRUE;
#endif
#endif
/*lint -e{731,774} */
if(TRUE == ret){
if(EthSM_Internal.Networks[NetworkHandle].TcpIpState == TCPIP_STATE_ONLINE){
EthSM_Internal_ChangeNetworkModeState(NetworkHandle,ETHSM_STATE_WAIT_ONLINE);
}else{
EthSM_Internal_RequestTcpIpModeChg(NetworkHandle,TCPIP_STATE_ONLINE);
}
}
break;
case ETHSM_STATE_WAIT_ONLINE:
EthSM_Internal_FullComWaitOnlineSM(NetworkHandle);
break;
case ETHSM_STATE_ONLINE:
EthSM_Internal_FullComOnlineSM(NetworkHandle);
break;
case ETHSM_STATE_ONHOLD:
EthSM_Internal_FullComOnHoldSM(NetworkHandle);
break;
default:
break;
}
}
/**
* Sub Main function to transfer to offline mode
* @param NetworkHandle
* @return none
*/
static void EthSM_Internal_TransferOffline(NetworkHandleType NetworkHandle){
boolean ret;
#if ETHSM_DUMMY_MODE == STD_ON
ret = TRUE;
#endif
EthSM_Internal_UpdateControllerMode(NetworkHandle);
#if ETHSM_DUMMY_MODE != STD_ON
#if (ETHSM_ETH_TRCV_SUPPORT == STD_ON)
ret = EthSM_Internal_CheckTrcvMode(NetworkHandle, ETHTRCV_MODE_DOWN);
#else
ret = TRUE;
#endif
#endif
if(EthSM_Internal.Networks[NetworkHandle].TcpIpState == TCPIP_STATE_OFFLINE){
if((EthSM_Internal.Networks[NetworkHandle].CtrlMode == ETH_MODE_DOWN) &&
/*lint -e{731,774} */
(TRUE == ret)){
EthSM_Internal_ChangeNetworkModeState(NetworkHandle,ETHSM_STATE_OFFLINE);
}else{
EthSM_Internal_RequestEthIfModeChg(NetworkHandle);
}
}else{
EthSM_Internal_RequestTcpIpModeChg(NetworkHandle,TCPIP_STATE_OFFLINE);
}
}
/**
* Sub Main function to carry out NO communication finite state machine
* @param NetworkHandle
* @param State
* @return none
*/
static void EthSM_Internal_NoComFSM(NetworkHandleType NetworkHandle){
boolean ret;
NetworkHandleType Channel;
ret = TRUE;
Channel = ETHSM_GET_CHANNEL(NetworkHandle);
switch (EthSM_Internal.Networks[NetworkHandle].NetworkMode){
case ETHSM_STATE_WAIT_TRCVLINK:
/* @req 4.2.2/SWS_EthSM_00127 */
/* @req 4.2.2/SWS_EthSM_00128 */
/* @req 4.2.2/SWS_EthSM_00129 */
/* @req 4.2.2/SWS_EthSM_00130 */
EthSM_Internal_UpdateControllerMode(NetworkHandle);
#if ETHSM_DUMMY_MODE != STD_ON
#if (ETHSM_ETH_TRCV_SUPPORT == STD_ON)
ret = EthSM_Internal_CheckTrcvMode(NetworkHandle, ETHTRCV_MODE_DOWN);
#else
ret = TRUE;
#endif
#endif
if((EthSM_Internal.Networks[NetworkHandle].CtrlMode == ETH_MODE_DOWN) &&
/*lint -e{731,774} */
(TRUE == ret)){
EthSM_Internal_ChangeNetworkModeState(NetworkHandle,ETHSM_STATE_OFFLINE);
}else{
EthSM_Internal_RequestEthIfModeChg(NetworkHandle);
}
break;
case ETHSM_STATE_WAIT_ONLINE:
/* @req 4.2.2/SWS_EthSM_00140 */
/* @req 4.2.2/SWS_EthSM_00141 */
/* @req 4.2.2/SWS_EthSM_00142 */
/* @req 4.2.2/SWS_EthSM_00143 */
/* @req 4.2.2/SWS_EthSM_00144 */
EthSM_Internal_TransferOffline(NetworkHandle);
break;
case ETHSM_STATE_ONLINE:
/* @req 4.2.2/SWS_EthSM_00155 */
/* @req 4.2.2/SWS_EthSM_00157 */
/* @req 4.2.2/SWS_EthSM_00158 */
if(EthSM_Internal.Networks[NetworkHandle].TcpIpState == TCPIP_STATE_OFFLINE){
EthSM_Internal_ChangeNetworkModeState(NetworkHandle,ETHSM_STATE_WAIT_OFFLINE);
}else{
EthSM_Internal_RequestTcpIpModeChg(NetworkHandle,TCPIP_STATE_OFFLINE);
}
break;
case ETHSM_STATE_ONHOLD:
/* @req 4.2.2/SWS_EthSM_00178 */
/* @req 4.2.2/SWS_EthSM_00179 */
/* @req 4.2.2/SWS_EthSM_00180 */
/* @req 4.2.2/SWS_EthSM_00181 */
/* @req 4.2.2/SWS_EthSM_00182 */
/* @req 4.2.2/SWS_EthSM_00184 */
EthSM_Internal_TransferOffline(NetworkHandle);
if(EthSM_Internal.Networks[NetworkHandle].NetworkMode == ETHSM_STATE_ONHOLD){
ComM_BusSM_ModeIndication(Channel, &EthSM_Internal.Networks[NetworkHandle].CurrentMode);
}
break;
case ETHSM_STATE_WAIT_OFFLINE:
/* @req 4.2.2/SWS_EthSM_00160 */
/* @req 4.2.2/SWS_EthSM_00161 */
/* @req 4.2.2/SWS_EthSM_00162 */
/* @req 4.2.2/SWS_EthSM_00163 */
/* @req 4.2.2/SWS_EthSM_00165 */
EthSM_Internal_UpdateControllerMode(NetworkHandle);
#if ETHSM_DUMMY_MODE != STD_ON
#if (ETHSM_ETH_TRCV_SUPPORT == STD_ON)
ret = EthSM_Internal_CheckTrcvMode(NetworkHandle, ETHTRCV_MODE_DOWN);
#else
ret= TRUE;
#endif
#endif
if(EthSM_Internal.Networks[NetworkHandle].TcpIpState == TCPIP_STATE_OFFLINE){
if((EthSM_Internal.Networks[NetworkHandle].CtrlMode == ETH_MODE_DOWN) &&
/*lint -e{731,774} */
(TRUE == ret)){
EthSM_Internal_ChangeNetworkModeState(NetworkHandle,ETHSM_STATE_OFFLINE);
/* @req 4.2.2/SWS_EthSM_00018 */
ComM_BusSM_ModeIndication(Channel, &EthSM_Internal.Networks[NetworkHandle].CurrentMode);
}else{
EthSM_Internal_RequestEthIfModeChg(NetworkHandle);
}
}
break;
case ETHSM_STATE_OFFLINE:
break;
default:
break;
}
}
/*lint -restore*/
/*==================[AUTOSAR APIs]===========================================*/
/**
* Initializes the Ethernet State Manager
* @param void
* @return none
*/
/* @req 4.2.2/SWS_EthSM_00043 */
void EthSM_Init(void) {
/* @req 4.2.2/SWS_EthSM_00025 */
for (uint8 NetworkHandle = 0; NetworkHandle < ETHSM_NETWORK_COUNT; NetworkHandle++) {
EthSM_Internal.Networks[NetworkHandle].RequestedMode = COMM_NO_COMMUNICATION;
EthSM_Internal.Networks[NetworkHandle].CurrentMode = COMM_NO_COMMUNICATION;
EthSM_Internal.Networks[NetworkHandle].NetworkMode = ETHSM_STATE_OFFLINE;
EthSM_Internal.Networks[NetworkHandle].TrcvLinkState = ETHTRCV_LINK_STATE_DOWN;
EthSM_Internal.Networks[NetworkHandle].CtrlMode = ETH_MODE_DOWN;
EthSM_Internal.Networks[NetworkHandle].TrcvMode = ETHTRCV_MODE_DOWN;
EthSM_Internal.Networks[NetworkHandle].RequestStream = 0;
EthSM_Internal.Networks[NetworkHandle].TcpIpState = TCPIP_STATE_OFFLINE;
}
EthSM_Internal.InitStatus = ETHSM_STATUS_INIT;
}
/* @req 4.2.2/SWS_EthSM_00046*/
#if (ETHSM_VERSION_INFO_API == STD_ON)
/**
* Returns the version information of this module
* @param VersionInfoPtr
*/
void EthSM_GetVersionInfo(Std_VersionInfoType* VersionInfoPtr)
{
ETHSM_VALIDATE_NO_RV((NULL != VersionInfoPtr), ETHSM_GETVERSIONINFO_ID, ETHSM_E_PARAM_POINTER); /* not requested DET error */
/* Vendor and Module Id */
VersionInfoPtr->vendorID = ETHSM_VENDOR_ID;
VersionInfoPtr->moduleID = ETHSM_MODULE_ID;
/* software version */
VersionInfoPtr->sw_major_version = ETHSM_SW_MAJOR_VERSION;
VersionInfoPtr->sw_minor_version = ETHSM_SW_MINOR_VERSION;
VersionInfoPtr->sw_patch_version = ETHSM_SW_PATCH_VERSION;
}
#endif
/**
* Available to request corresponding network communication mode
* Depending up on the parameters handed over, ETHSM executes state machine change
* of the network
* @param NetworkHandle
* @param ComM_Mode
* @return E_OK or E_NOT_OK
*/
/* @req 4.2.2/SWS_EthSM_00050 */
/* @req 4.2.2/SWS_EthSM_00014 */
Std_ReturnType EthSM_RequestComMode( NetworkHandleType NetworkHandle, ComM_ModeType ComM_Mode ) {
/* @req 4.2.2/SWS_EthSM_00054 */
/* @req 4.2.2/SWS_EthSM_00087 */
NetworkHandleType EthSMNetworkHandle = EthSM_Internal_GetNetworkHandleComM(NetworkHandle);
ETHSM_VALIDATE_RV((EthSM_Internal.InitStatus == ETHSM_STATUS_INIT),ETHSM_REQUESTCOMMODE_ID,ETHSM_E_UNINIT, E_NOT_OK);
/* @req 4.2.2/SWS_EthSM_00051 */
/* @req 4.2.2/SWS_EthSM_00052 */
ETHSM_VALIDATE_RV((EthSMNetworkHandle < ETHSM_NETWORK_COUNT),ETHSM_REQUESTCOMMODE_ID,ETHSM_E_INVALID_NETWORK_HANDLE,E_NOT_OK);
/* @req 4.2.2/SWS_EthSM_00095 */
/* @req 4.2.2/SWS_EthSM_00199 */
ETHSM_VALIDATE_RV((ComM_Mode <= COMM_FULL_COMMUNICATION),ETHSM_REQUESTCOMMODE_ID,ETHSM_E_INVALID_NETWORK_MODE,E_NOT_OK);
/* @req 4.2.2/SWS_EthSM_00053 */
EthSM_Internal.Networks[EthSMNetworkHandle].RequestedMode = ComM_Mode;
/* @req 4.2.2/SWS_EthSM_00078 */
#if ETHSM_DUMMY_MODE == STD_ON /*IMPROVEMENT: Change these items later */
if(ComM_Mode == COMM_FULL_COMMUNICATION){
EthSM_Internal.Networks[EthSMNetworkHandle].CtrlMode = ETH_MODE_ACTIVE;
EthSM_Internal.Networks[EthSMNetworkHandle].TrcvMode = ETHTRCV_MODE_ACTIVE;
}else if(ComM_Mode == COMM_NO_COMMUNICATION){
EthSM_Internal.Networks[EthSMNetworkHandle].CtrlMode = ETH_MODE_DOWN;
EthSM_Internal.Networks[EthSMNetworkHandle].TrcvMode = ETHTRCV_MODE_DOWN;
}else{
/* Do nothing */
}
#endif
return E_OK;
}
/**
* Available to get the corresponding network communication mode
* @param NetworkHandle
* @param ComM_ModePtr
* @return E_OK or E_NOT_OK
*/
/* @req 4.2.2/SWS_EthSM_00055 */
/* @req 4.2.2/SWS_EthSM_00017 */
Std_ReturnType EthSM_GetCurrentComMode( NetworkHandleType NetworkHandle, ComM_ModeType* ComM_ModePtr ) {
NetworkHandleType EthSMNetworkHandle = EthSM_Internal_GetNetworkHandleComM(NetworkHandle);
/* @req 4.2.2/SWS_EthSM_00060 */
ETHSM_VALIDATE_RV((EthSM_Internal.InitStatus == ETHSM_STATUS_INIT),ETHSM_GETCURRENTCOMMODE_ID,ETHSM_E_UNINIT, E_NOT_OK);
/* @req 4.2.2/SWS_EthSM_00057 */
/* @req 4.2.2/SWS_EthSM_00058 */
ETHSM_VALIDATE_RV((EthSMNetworkHandle < ETHSM_NETWORK_COUNT),ETHSM_GETCURRENTCOMMODE_ID,ETHSM_E_INVALID_NETWORK_HANDLE,E_NOT_OK);
ETHSM_VALIDATE_RV((ComM_ModePtr != NULL),ETHSM_GETCURRENTCOMMODE_ID,ETHSM_E_PARAM_POINTER,E_NOT_OK);
/* @req 4.2.2/SWS_EthSM_00059 */
*ComM_ModePtr = EthSM_Internal.Networks[EthSMNetworkHandle].CurrentMode;
return E_OK;
}
#if ETHSM_DUMMY_MODE != STD_ON
/**
* Ethernet Interface reports a transceiver link state change.
* @param CtrlIdx
* @param TransceiverLinkState
* @return none
*/
/* @req 4.2.2/SWS_EthSM_00109*/
void EthSM_TrcvLinkStateChg( uint8 CtrlIdx,EthTrcv_LinkStateType TransceiverLinkState ){
/* @req 4.2.2/SWS_EthSM_00115*/
ETHSM_VALIDATE_NO_RV((EthSM_Internal.InitStatus == ETHSM_STATUS_INIT),ETHSM_TRCVLINKSTATECHG_ID,ETHSM_E_UNINIT);
/* @req 4.2.2/SWS_EthSM_00112*/
ETHSM_VALIDATE_NO_RV((ETHSM_INVALID_CTRL != EthSM_Internal_CheckEthIfCtrl(CtrlIdx)),ETHSM_TRCVLINKSTATECHG_ID,ETHSM_E_PARAM_CONTROLLER);
ETHSM_VALIDATE_NO_RV((TransceiverLinkState <= ETHTRCV_LINK_STATE_ACTIVE),ETHSM_TRCVLINKSTATECHG_ID, ETHSM_E_INVALID_TRCV_LINK_STATE);/*lint !e685 '<=' has no problem */
/* @req 4.2.2/SWS_EthSM_00114*/
EthSM_Internal.Networks[EthSM_Internal_GetNetworkHandleEth(CtrlIdx)].TrcvLinkState = TransceiverLinkState;
}
#endif
/**
* This service is called by the TcpIp to report the actual TcpIp state (e.g. online, offline).
* @param CtrlIdx
* @param TcpIpState
* @return E_OK or E_NOT_OK
*/
/* @req 4.2.2/SWS_EthSM_00110*/
Std_ReturnType EthSM_TcpIpModeIndication( uint8 CtrlIdx, TcpIp_StateType TcpIpState ){
NetworkHandleType NetworkHandle;
/* @req 4.2.2/SWS_EthSM_00120 */
ETHSM_VALIDATE_RV((EthSM_Internal.InitStatus == ETHSM_STATUS_INIT),ETHSM_TCPIPMODEINDICATION_ID,ETHSM_E_UNINIT, E_NOT_OK);
/* @req 4.2.2/SWS_EthSM_00116 */
ETHSM_VALIDATE_RV((ETHSM_INVALID_CTRL != EthSM_Internal_CheckEthIfCtrl(CtrlIdx)),ETHSM_TCPIPMODEINDICATION_ID,ETHSM_E_PARAM_CONTROLLER, E_NOT_OK);
/* @req 4.2.2/SWS_EthSM_00118 */
ETHSM_VALIDATE_RV((TcpIpState <= TCPIP_STATE_SHUTDOWN),ETHSM_TCPIPMODEINDICATION_ID,ETHSM_E_INVALID_TCP_IP_MODE, E_NOT_OK);
/* @req 4.2.2/SWS_EthSM_00119 */
NetworkHandle = EthSM_Internal_GetNetworkHandleEth(CtrlIdx);
ETHSM_MODE_REQUEST_CLEAR(NetworkHandle,ETHSM_TCPIP_MODE_REQUEST);
EthSM_Internal.Networks[NetworkHandle].TcpIpState = TcpIpState;
return E_OK;
}
/**
* This callback shall notify the EthSM module about a Ethernet controller mode change.
* @param CtrlIdx
* @param CtrlMode
* @return none
*/
/* @req 4.2.2/SWS_EthSM_00190*/
void EthSM_CtrlModeIndication(uint8 CtrlIdx, Eth_ModeType CtrlMode){
/* @req 4.2.2/SWS_EthSM_00192 */
ETHSM_VALIDATE_NO_RV((EthSM_Internal.InitStatus == ETHSM_STATUS_INIT),ETHSM_CTRLMODEINDICATION_ID,ETHSM_E_UNINIT);
/* @req 4.2.2/SWS_EthSM_00191 */
ETHSM_VALIDATE_NO_RV((ETHSM_INVALID_CTRL != EthSM_Internal_CheckEthIfCtrl(CtrlIdx)),ETHSM_CTRLMODEINDICATION_ID,ETHSM_E_PARAM_CONTROLLER);
NetworkHandleType NetworkHandle = EthSM_Internal_GetNetworkHandleEth(CtrlIdx);
ETHSM_MODE_REQUEST_CLEAR(NetworkHandle,ETHSM_ETHIF_ETH_MODE_REQUEST);
EthSM_Internal.Networks[NetworkHandle].CtrlMode = CtrlMode;
}
/**
* This callback shall notify the EthSM module about a Ethernet transceiver mode change.
* @param TrcvIdx
* @param TrcvMode
* @return none
*/
/* @req 4.2.2/SWS_EthSM_00193*/
void EthSM_TrcvModeIndication(uint8 CtrlIdx, EthTrcv_ModeType TrcvMode){
/* @req 4.2.2/SWS_EthSM_00195 */
ETHSM_VALIDATE_NO_RV((EthSM_Internal.InitStatus == ETHSM_STATUS_INIT),ETHSM_TRCVMODEINDICATION_ID,ETHSM_E_UNINIT);
/* @req 4.2.2/SWS_EthSM_00194 */
ETHSM_VALIDATE_NO_RV((ETHSM_INVALID_CTRL != EthSM_Internal_CheckEthIfCtrl(CtrlIdx)),ETHSM_TRCVMODEINDICATION_ID,ETHSM_E_PARAM_CONTROLLER);
NetworkHandleType NetworkHandle = EthSM_Internal_GetNetworkHandleEth(CtrlIdx);
ETHSM_MODE_REQUEST_CLEAR(NetworkHandle,ETHSM_ETHIF_ETHTRCV_MODE_REQUEST);
EthSM_Internal.Networks[NetworkHandle].TrcvMode = TrcvMode;
}
/**
* This service shall put out the current internal mode of a Ethernet network
* @param NetworkHandle
* @param EthSM_InternalMode
* @return E_OK or E_NOT_OK
*/
/* @req 4.2.2/SWS_EthSM_00121*/
/* @req 4.2.2/SWS_EthSM_00014 */
Std_ReturnType EthSM_GetCurrentInternalMode( NetworkHandleType NetworkHandle, EthSM_NetworkModeStateType* EthSM_InternalMode ){
NetworkHandleType EthSMNetworkHandle = EthSM_Internal_GetNetworkHandleComM(NetworkHandle);
/* @req 4.2.2/SWS_EthSM_00125 */
ETHSM_VALIDATE_RV((EthSM_Internal.InitStatus == ETHSM_STATUS_INIT),ETHSM_GETCURRENTINTERNALMODE_ID,ETHSM_E_UNINIT, E_NOT_OK);
/* @req 4.2.2/SWS_EthSM_00122 */
/* @req 4.2.2/SWS_EthSM_00123 */
ETHSM_VALIDATE_RV((EthSMNetworkHandle < ETHSM_NETWORK_COUNT),ETHSM_GETCURRENTINTERNALMODE_ID,ETHSM_E_INVALID_NETWORK_HANDLE,E_NOT_OK);
ETHSM_VALIDATE_RV((EthSM_InternalMode != NULL),ETHSM_GETCURRENTINTERNALMODE_ID,ETHSM_E_PARAM_POINTER,E_NOT_OK);
/* @req 4.2.2/SWS_EthSM_00124 */
*EthSM_InternalMode = EthSM_Internal.Networks[EthSMNetworkHandle].NetworkMode;
return E_OK;
}
/**
* Main function to be called with a periodic time frame
* @param none
* @return none
*/
/* @req 4.2.2/SWS_EthSM_00035*/
void EthSM_MainFunction(void) {
ETHSM_VALIDATE_NO_RV((EthSM_Internal.InitStatus == ETHSM_STATUS_INIT),ETHSM_MAINFUNCTION_ID,ETHSM_E_UNINIT);
/* @req 4.2.2/SWS_EthSM_00197 */
/* @req 4.2.2/SWS_EthSM_00198 */
/* @req 4.2.2/SWS_EthSM_00038 */
/* @req 4.2.2/SWS_EthSM_00083 */
/* @req 4.2.2/SWS_EthSM_00024 */
/* @req 4.2.2/SWS_EthSM_00015 */
for (NetworkHandleType NetworkHandle = 0; NetworkHandle < ETHSM_NETWORK_COUNT; NetworkHandle++) {
if(EthSM_Internal.Networks[NetworkHandle].RequestedMode == COMM_FULL_COMMUNICATION){
EthSM_Internal_FullComFSM(NetworkHandle);
}else if(EthSM_Internal.Networks[NetworkHandle].RequestedMode == COMM_NO_COMMUNICATION){
EthSM_Internal_NoComFSM(NetworkHandle);
}else{
/* Do nothing for COMM_SILENT_COMMUNICATION */
}
}
}
#ifdef HOST_TEST
EthSM_InternalType* readinternal_status(void );
EthSM_InternalType* readinternal_status(void)
{
return &EthSM_Internal;
}
#endif
/*==================[END]===========================================*/
|
2301_81045437/classic-platform
|
communication/EthSM/src/EthSM.c
|
C
|
unknown
| 37,899
|
#Ethernet
obj-$(USE_ETHTSYN) += EthTSyn_Cfg.o
obj-$(USE_ETHTSYN) += EthTSyn_Internal.o
obj-$(USE_ETHTSYN) += EthTSyn.o
inc-$(USE_ETHTSYN) += $(ROOTDIR)/include/rte
vpath-$(USE_ETHTSYN) += $(ROOTDIR)/communication/EthTSyn/src
inc-$(USE_ETHTSYN) += $(ROOTDIR)/communication/EthTSyn/inc
inc-$(USE_ETHTSYN) += $(ROOTDIR)/system/StbM/inc
|
2301_81045437/classic-platform
|
communication/EthTSyn/EthTSyn.mod.mk
|
Makefile
|
unknown
| 341
|
/*-------------------------------- 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 ETHTSYN_H_
#define ETHTSYN_H_
/* @req 4.2.2/SWS_EthTSyn_00031 */
#include "Eth_GeneralTypes.h"
#include "EthTSyn_Types.h"
#include "StbM.h"
#define ETHTSYN_VENDOR_ID 60u
#define ETHTSYN_MODULE_ID 164u
#define ETHTSYN_AR_RELEASE_MAJOR_VERSION 4u
#define ETHTSYN_AR_RELEASE_MINOR_VERSION 2u
#define ETHTSYN_AR_RELEASE_PATCH_VERSION 2u
#define ETHTSYN_SW_MAJOR_VERSION 1u
#define ETHTSYN_SW_MINOR_VERSION 1u
#define ETHTSYN_SW_PATCH_VERSION 0u
#include "EthIf.h"
/* Development errors */
/* @req 4.2.2/SWS_EthTSyn_00030 */
#define ETHTSYN_E_NOT_INITIALIZED 0x20u
/* ArcCore extra Error ids */
/* @req 4.2.2/SWS_EthTSyn_00029 */
#define ETHTSYN_E_INIT_FAILED 0x30u
#define ETHTSYN_E_PARAM_POINTER 0x31u
#define ETHTSYN_E_INVALID_TIMEBASE_ID 0X32u
#define ETHTSYN_E_INVALID_CTRL_ID 0X33u
#define ETHTSYN_E_INV_MODE 0x34u
/* API ids */
#define ETHTSYN_SERVICE_ID_INIT 0x01u
#define ETHTSYN_GETVERSIONINFO_ID 0x02u
#define ETHTSYN_GETCURRENTTIME_ID 0x03u
#define ETHTSYN_SETGLOBALTIME_ID 0x04u
#define ETHTSYN_SETTRANSMISSIONMODE_ID 0x05u
/* Call back Api Id */
#define ETHTSYN_RXINDICATION_ID 0x06u
#define ETHTSYN_TXCONFIRMATION_ID 0x07u
#define ETHTSYN_TRCVLINKSTATECHG_ID 0x08u
/* Schedule function API id */
#define ETHTSYN_MAINFUNCTION_ID 0x09u
#include "EthTSyn_Cfg.h"
/* API's prototype */
/* @req 4.2.2/SWS_EthTSyn_00035 */
void EthTSyn_Init( const EthTSyn_ConfigType* configPtr );
#if (ETHTSYN_GET_VERSION_INFO == STD_ON)
/* @req 4.2.2/SWS_EthTSyn_00036 */
void EthTSyn_GetVersionInfo( Std_VersionInfoType* versioninfo );
#endif
#if (ETHTSYN_HARDWARE_TIMESTAMP_SUPPORT == STD_ON)
/* @req 4.2.2/SWS_EthTSyn_00037 */
Std_ReturnType EthTSyn_GetCurrentTime( StbM_SynchronizedTimeBaseType timeBaseId, StbM_TimeStampType* timeStampPtr, EthTSyn_SyncStateType* syncState );
/* @req 4.2.2/SWS_EthTSyn_00038 */
Std_ReturnType EthTSyn_SetGlobalTime( StbM_SynchronizedTimeBaseType timeBaseId, const StbM_TimeStampType* timeStampPtr );
#endif
/* @req 4.2.2/SWS_EthTSyn_00039 */
void EthTSyn_SetTransmissionMode( uint8 CtrlIdx, EthTSyn_TransmissionModeType Mode );
/* @req 4.2.2/SWS_EthTSyn_00040 */
void EthTSyn_RxIndication( uint8 CtrlIdx, Eth_FrameType FrameType, boolean IsBroadcast, const uint8* PhysAddrPtr, uint8* DataPtr, uint16 LenByte );
/* @req 4.2.2/SWS_EthTSyn_00042 */
void EthTSyn_TxConfirmation( uint8 CtrlIdx, Eth_BufIdxType BufIdx );
/* @req 4.2.2/SWS_EthTSyn_00043 */
Std_ReturnType EthTSyn_TrcvLinkStateChg( uint8 CtrlIdx, EthTrcv_LinkStateType TrcvLinkState );
/* @req 4.2.2/SWS_EthTSyn_00044 */
void EthTSyn_MainFunction( void );
extern const EthTSyn_ConfigType EthTSynConfigData;
#endif /* ETHTSYN_H_ */
|
2301_81045437/classic-platform
|
communication/EthTSyn/inc/EthTSyn.h
|
C
|
unknown
| 3,682
|
/*-------------------------------- 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 ETHTSYN_TYPES_H_
#define ETHTSYN_TYPES_H_
/* @req 4.2.2/SWS_EthTSyn_00001 */
#include "ComStack_Types.h"
/* @req 4.2.2/SWS_EthTSyn_00033 */
typedef enum {
ETHTSYN_TX_OFF, /* Transmission Disabled */
ETHTSYN_TX_ON, /* Transmission Enabled */
}EthTSyn_TransmissionModeType;
/* @req 4.2.2/SWS_EthTSyn_00034 */
typedef enum {
ETHTSYN_SYNC, /* Ethernet time synchronous */
ETHTSYN_UNSYNC, /* Ethernet not time synchronous */
ETHTSYN_UNCERTAIN, /* Ethernet Sync state uncertain */
ETHTSYN_NEVERSYNC, /* No Sync message received between EthTSyn_Init() and current requested state. */
}EthTSyn_SyncStateType;
typedef enum {
PTP_SLAVE,
PTP_MASTER,
}EthTSyn_PtpType;
typedef struct {
uint32 EthTSynGlobalTimeTxFollowUpOffset; /* TX offset for Follow_Up / Pdelay_Resp_Follow_Up messages */
uint32 EthTSynGlobalTimeTxPdelayReqPeriod; /* TX period for Pdelay_Req messages */
uint32 EthTSynGlobalTimeTxPeriod; /* TX period */
uint32 EthTSynTimeHardwareCorrectionThreshold; /* maximum deviation between the local time and the time obtained from SYNC message */
uint8 EthTSynGlobalTimeEthIfId; /* reference to the Ethernet interface taken to fetch the global time information */
boolean EthTSynEthTrcvEnable; /* Flag indicating if transceiver is enabled for the related EthIf controller */
}EthTSyn_GlobalTimeType;
typedef struct{
uint32 EthTSynGlobalTimeFollowUpTimeout; /* EthTSyn Global Time FollowUp Timeout */
uint8 EthTSynSynchronizedTimeBaseRef; /* reference to the required synchronized time-base */
const EthTSyn_GlobalTimeType* EthTSynTimeDomain; /* Reference to configured time domains */
EthTSyn_PtpType EthTSynMasterFlag; /* Flag to differentiate Master and Slave */
}EthTSyn_GlobalTimeDomainType;
/* @req 4.2.2/SWS_EthTSyn_00032 */
typedef struct{
const EthTSyn_GlobalTimeDomainType* EthTSynGlobalTimeDomain; /* Refernce to global time domain */
uint8 EhtTSyn_GlobalTimeDomainCount; /* number of global time domain configuresd */
}EthTSyn_ConfigType;
#endif /* ETHTSYN_TYPES_H_ */
|
2301_81045437/classic-platform
|
communication/EthTSyn/inc/EthTSyn_Types.h
|
C
|
unknown
| 3,088
|
/*-------------------------------- 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 -----------------------------*/
/*-------------------------------- Note ------------------------------------
* Some additions that are outside the Autosar standard has been added.
* 1) We are able to send the announce message.
* This is regulated with a switch in EthTSyn_Cfg.h.
* The switch is ETHTSYN_SEND_ANNOUNCE_SUPPORT set it to STD_ON for the announce
* message to be transmitted.
* 2) We are able to receive multiple peer delay requests.
* If a switch is used that do not have support for peer delay request handling
* there will be multiple pdelay_req messages received to the master. Functionality
* has been added so these are identified as different requests and handled.
* Really this should not be necessary because this would essentially be a end to
* end system and we should instead accept multiple delay_req.
* Improvement: In future alter acceptance of multiple pdelay_req to accept multiple delay_req.
*-------------------------------- Note ------------------------------------*/
#include "EthTSyn.h"
#include "StbM.h"
#if (ETHTSYN_DEV_ERROR_DETECT == STD_ON)
#if defined(USE_DET)
#include "Det.h"
#else
#error "EthTSyn: DET must be used when Default error detect is enabled"
#endif
#endif
#include "EthIf.h"
#include "EthTSyn_Internal.h"
#include <string.h>
//lint -emacro(904,ETHTSYN_DET_REPORTERROR) //904 PC-Lint exception to MISRA 14.7 (validate DET macros).
#define ETHTSYN_INVALID_TIMEDOMAIN 0xFFu
#define ETHTSYN_INVALID_CTRLID 0xFFu
#define ETHTSYN_MESSAGE_TYPE 0x0Fu
const EthTSyn_ConfigType* EthTSyn_ConfigPointer;
/** Static declarations */
static EthTSyn_Internal_DomainType EthTSyn_InternalDomains[ETHTSYN_TIMEDOMAIN_COUNT];
/* @req 4.2.2/SWS_EthTSyn_00002 */
const uint8 EthTSyn_Internal_MulitCast_DestMACAddrs[6] = {0x01,0x80,0xc2,0x00,0x00,0x0E};/* Destination MAC address for PTP */
EthTSyn_InternalType EthTSyn_Internal = {
.initStatus = ETHTSYN_STATE_UNINIT,
.timeDomain = EthTSyn_InternalDomains,
};
/* @req 4.2.2/SWS_EthTSyn_00007 */
#if (ETHTSYN_DEV_ERROR_DETECT == STD_ON)
#define ETHTSYN_DET_REPORTERROR(_cond ,_api, _error, ...) \
if (!_cond) { \
(void)Det_ReportError(ETHTSYN_MODULE_ID, 0, _api, _error); \
return __VA_ARGS__; \
}
#else
#define ETHTSYN_DET_REPORTERROR(_cond ,_api, _error, ...) \
if (!_cond) { \
return __VA_ARGS__; \
}
#endif
#define ETHTSYN_GET_TIMEDOMAINID(_timedomain) \
(EthTSynConfigData.EthTSynGlobalTimeDomain[_timedomain].EthTSynSynchronizedTimeBaseRef)
#define ETHTSYN_GET_CTRL_IDX(_timedomain) \
(EthTSynConfigData.EthTSynGlobalTimeDomain[_timedomain].EthTSynTimeDomain->EthTSynGlobalTimeEthIfId)
#if (ETHTSYN_HARDWARE_TIMESTAMP_SUPPORT == STD_ON)
/**
* Gives back with mapped Time Domain ID
* @param TimeDomainId
* @return uint16
*/
static uint16 EthTSyn_Internal_GetTimeDomainStbm ( uint16 TimeDomainId){
uint16 status;
status = ETHTSYN_INVALID_TIMEDOMAIN;
for (uint8 i = 0; i < ETHTSYN_TIMEDOMAIN_COUNT; i++) {
if(TimeDomainId == ETHTSYN_GET_TIMEDOMAINID(i)){
status = TimeDomainId;
break;
}
}
return status;
}
#endif
/**
* Gives back with mapped Ethernet interface controller index
* @param CtrlIdx
* @return controller Id
*/
static uint8 EthTSyn_Internal_CheckEthIfCtrl ( uint8 CtrlIdx){
uint8 status;
status = (uint8)ETHTSYN_INVALID_CTRLID;
for (uint8 i = 0; i < ETHTSYN_TIMEDOMAIN_COUNT; i++) {
if(CtrlIdx == ETHTSYN_GET_CTRL_IDX(i) ) {
status = CtrlIdx;
break;
}
}
return status;
}
/**
* Gives back with mapped Time Domain ID of Ethernet interface controller index
* @param CtrlIdx
* @return uint16
*/
static uint16 EthTsyn_Internal_GetTimeDomainId ( uint8 CtrlIdx){
uint16 status;
status = ETHTSYN_INVALID_TIMEDOMAIN;
for (uint8 i = 0; i < ETHTSYN_TIMEDOMAIN_COUNT; i++) {
if(CtrlIdx == ETHTSYN_GET_CTRL_IDX(i) ) {
status = (uint16)i;
break;
}
}
return status;
}
/** AUTOSAR APIs */
/**
* Init function for EthTSyn
* @param configPtr
*/
/* @req 4.2.2/SWS_EthIf_00024 */
void EthTSyn_Init( const EthTSyn_ConfigType* configPtr )
{
uint8 i,j;
uint8 ctrlIdx;
ETHTSYN_DET_REPORTERROR((NULL != configPtr),ETHTSYN_SERVICE_ID_INIT, ETHTSYN_E_INIT_FAILED);
EthTSyn_ConfigPointer = configPtr;
/* @req 4.2.2/SWS_EthTSyn_00006 */ /* @req 4.2.2/SWS_EthTSyn_00008 */ /*@req 4.2.2/SWS_EthTSyn_00010 */
for(i =0 ; i < EthTSyn_ConfigPointer->EhtTSyn_GlobalTimeDomainCount; i ++){
/* Sync and Follow Up msg transmission related Variable init */
EthTSyn_Internal.timeDomain[i].ptpCfgData.syncSend_State = SEND_SYNC_MSG;
EthTSyn_Internal.timeDomain[i].ptpCfgData.sentSync = FALSE;
EthTSyn_Internal.timeDomain[i].ptpCfgData.txSyncTimePending = FALSE;
EthTSyn_Internal.timeDomain[i].ptpCfgData.last_sync_tx_sequence_number = 0;
EthTSyn_Internal.timeDomain[i].ptpCfgData.syncIntervalTimer = 0;
EthTSyn_Internal.timeDomain[i].ptpCfgData.syncIntervalTimerStarted = FALSE;
EthTSyn_Internal.timeDomain[i].ptpCfgData.syncIntervalTimeout = TRUE;
EthTSyn_Internal.timeDomain[i].ptpCfgData.syncfollowUpTimer = 0;
EthTSyn_Internal.timeDomain[i].ptpCfgData.syncfollowUpTimerStarted = FALSE;
EthTSyn_Internal.timeDomain[i].ptpCfgData.syncfollowUpTimerTimeout = FALSE;
EthTSyn_Internal.timeDomain[i].ptpCfgData.t1SyncTxTime = (Eth_TimeStampType){0};
#if (ETHTSYN_SEND_ANNOUNCE_SUPPORT == STD_ON)
EthTSyn_Internal.timeDomain[i].ptpCfgData.announceIntervalTimer = 0;
EthTSyn_Internal.timeDomain[i].ptpCfgData.announceIntervalTimerStarted = FALSE;
EthTSyn_Internal.timeDomain[i].ptpCfgData.announceIntervalTimeout = TRUE;
#endif
/* Sync and FUP Receive related variable init */
EthTSyn_Internal.timeDomain[i].ptpCfgData.syncReceive_State = DISCARD;
EthTSyn_Internal.timeDomain[i].ptpCfgData.rcvdSync = FALSE;
EthTSyn_Internal.timeDomain[i].ptpCfgData.rcvdFollowUp = FALSE;
EthTSyn_Internal.timeDomain[i].ptpCfgData.receptionTimeout = FALSE;
EthTSyn_Internal.timeDomain[i].ptpCfgData.parent_last_sync_sequence_number = 0;
EthTSyn_Internal.timeDomain[i].ptpCfgData.syncCorrection = 0;
EthTSyn_Internal.timeDomain[i].ptpCfgData.followupCorrection = 0;
EthTSyn_Internal.timeDomain[i].ptpCfgData.waitingForFollow = FALSE;
EthTSyn_Internal.timeDomain[i].ptpCfgData.RxFollowUpTimerStarted = FALSE;
EthTSyn_Internal.timeDomain[i].ptpCfgData.initSyncFollowReceived = FALSE;
EthTSyn_Internal.timeDomain[i].ptpCfgData.RxFollowUpTimer = 0;
EthTSyn_Internal.timeDomain[i].ptpCfgData.t2SyncReceiptTime = (Eth_TimeStampType){0};
EthTSyn_Internal.timeDomain[i].ptpCfgData.t2SyncReceiptTime_old = (Eth_TimeStampType){0};
EthTSyn_Internal.timeDomain[i].ptpCfgData.t1SyncOriginTime = (Eth_TimeStampType){0};
EthTSyn_Internal.timeDomain[i].ptpCfgData.t1SyncOriginTime_old = (Eth_TimeStampType){0};
/* Pdelay Req sent related variable init */
EthTSyn_Internal.timeDomain[i].ptpCfgData.pDelayReq_State = INITIAL_SEND_PDELAY_REQ;
EthTSyn_Internal.timeDomain[i].ptpCfgData.sentPdelayReq = FALSE;
EthTSyn_Internal.timeDomain[i].ptpCfgData.isMeasuringDelay = FALSE;
EthTSyn_Internal.timeDomain[i].ptpCfgData.pdelayTimerStarted = FALSE;
EthTSyn_Internal.timeDomain[i].ptpCfgData.pdelayIntervalTimer = 0;
EthTSyn_Internal.timeDomain[i].ptpCfgData.pdelayIntervalTimeout = FALSE;
EthTSyn_Internal.timeDomain[i].ptpCfgData.txPdelayReqTimePending = FALSE;
EthTSyn_Internal.timeDomain[i].ptpCfgData.initPdelayRespReceived = FALSE;
EthTSyn_Internal.timeDomain[i].ptpCfgData.t1PdelayReqTxTime = (Eth_TimeStampType){0};
EthTSyn_Internal.timeDomain[i].ptpCfgData.numPdelay_req = 0;
for (j=0; j<ETHTSYN_MAX_PDELAY_REQUEST; j++) {
EthTSyn_Internal.timeDomain[i].ptpCfgData.t2PdelayReqRxTime[j] = (Eth_TimeStampType){0};
}
/* Pdelay Resp and FUP sent related variable init */
for (j=0; j<ETHTSYN_MAX_PDELAY_REQUEST; j++) {
EthTSyn_Internal.timeDomain[i].ptpCfgData.pDelayResp_State[j] = INITIAL_WAITING_FOR_PDELAY_REQ;
EthTSyn_Internal.timeDomain[i].ptpCfgData.rcvdPdelayReq[j] = FALSE;
EthTSyn_Internal.timeDomain[i].ptpCfgData.pdelayRespTimerStarted[j] = FALSE;
EthTSyn_Internal.timeDomain[i].ptpCfgData.pdelayRespTimeout[j] = FALSE;
EthTSyn_Internal.timeDomain[i].ptpCfgData.pdelayRespIntervalTimer[j] = 0;
EthTSyn_Internal.timeDomain[i].ptpCfgData.txPdelayRespTimePending[j] = FALSE;
EthTSyn_Internal.timeDomain[i].ptpCfgData.t3PdelayRespTxTime[j] = (Eth_TimeStampType){0};
EthTSyn_Internal.timeDomain[i].ptpCfgData.pdelayRespfollowUpTimer[j] = 0;
EthTSyn_Internal.timeDomain[i].ptpCfgData.pdelayRespfollowUpTimerStarted[j] = FALSE;
EthTSyn_Internal.timeDomain[i].ptpCfgData.pdelayRespfollowUpTimerTimeout[j] = FALSE;
}
/* Pdelay Resp and FUP receive related variable init*/
for (j=0; j<ETHTSYN_MAX_PDELAY_REQUEST; j++) {
EthTSyn_Internal.timeDomain[i].ptpCfgData.rcvdPdelayResp = FALSE;
EthTSyn_Internal.timeDomain[i].ptpCfgData.rcvdPdelayRespFollowUp = FALSE;
EthTSyn_Internal.timeDomain[i].ptpCfgData.last_pdelay_resp_tx_sequence_number[j] = 0;
EthTSyn_Internal.timeDomain[i].ptpCfgData.requestingPortIdentity[j].portNumber = 1;
EthTSyn_Internal.timeDomain[i].ptpCfgData.t2PdelayRespTime[j] = (Eth_TimeStampType){0};
}
EthTSyn_Internal.timeDomain[i].ptpCfgData.last_pdelay_req_tx_sequence_number = 0; /* Any random Number */
EthTSyn_Internal.timeDomain[i].ptpCfgData.t3PdelayRespTime = (Eth_TimeStampType){0};
EthTSyn_Internal.timeDomain[i].ptpCfgData.t3PdelayRespRxTime_old = (Eth_TimeStampType){0};
EthTSyn_Internal.timeDomain[i].ptpCfgData.t4PdelayRespRxTime = (Eth_TimeStampType){0};
EthTSyn_Internal.timeDomain[i].ptpCfgData.t4PdelayRespRxTime_old = (Eth_TimeStampType){0};
/* General variable init */
EthTSyn_Internal.timeDomain[i].ptpCfgData.neighborRateRatioValid = FALSE;
EthTSyn_Internal.timeDomain[i].ptpCfgData.neighborRateRatio = 0;
EthTSyn_Internal.timeDomain[i].ptpCfgData.rateratio = (Eth_RateRatioType){{{0},0},{{0},0}}; /* @req 4.2.2/SWS_EthTSyn_00009 */
EthTSyn_Internal.timeDomain[i].ptpCfgData.syncReceivedOnceFlag=FALSE;
if (TRUE == EthTSyn_ConfigPointer->EthTSynGlobalTimeDomain[i].EthTSynTimeDomain->EthTSynEthTrcvEnable) {
EthTSyn_Internal.timeDomain[i].trcvActiveStateFlag = FALSE;
} else {
EthTSyn_Internal.timeDomain[i].trcvActiveStateFlag = TRUE; /* If transceiver is not supported assume Transceiver Active state is reached */
}
EthTSyn_Internal.timeDomain[i].transmissionMode = ETHTSYN_TX_OFF;
/* Generation of clock identity */
/* Get MAC Addres */
ctrlIdx = ETHTSYN_GET_CTRL_IDX(i);
EthIf_GetPhysAddr(ctrlIdx, EthTSyn_Internal.timeDomain[i].ptpCfgData.port_uuid_field);
/* Copy OUI field */
memcpy(EthTSyn_Internal.timeDomain[i].ptpCfgData.port_clock_identity, EthTSyn_Internal.timeDomain[i].ptpCfgData.port_uuid_field, 3);
/* IEEE EUI-48 (MAC address) to EUI-64 */
EthTSyn_Internal.timeDomain[i].ptpCfgData.port_clock_identity[3] = 0xFF;
EthTSyn_Internal.timeDomain[i].ptpCfgData.port_clock_identity[4] = 0xFE;
/* Copy remaining 3 bytes of MAC address */
memcpy(&EthTSyn_Internal.timeDomain[i].ptpCfgData.port_clock_identity[5], &EthTSyn_Internal.timeDomain[i].ptpCfgData.port_uuid_field[3], 3);
}
EthTSyn_Internal.initStatus = ETHTSYN_STATE_INIT;
}
#if(ETHTSYN_GET_VERSION_INFO == STD_ON)
/**
* This service puts out the version information of this module
* @param versioninfo
*/
void EthTSyn_GetVersionInfo( Std_VersionInfoType* versioninfo )
{
/* @req 4.2.2/SWS_EthIf_00127 */
ETHTSYN_DET_REPORTERROR((NULL != versioninfo),ETHTSYN_GETVERSIONINFO_ID,ETHTSYN_E_PARAM_POINTER);
versioninfo->moduleID = ETHTSYN_MODULE_ID; /* Module ID of ETHIF */
versioninfo->vendorID = ETHTSYN_VENDOR_ID; /* Vendor Id (ARCCORE) */
/* return the Software Version numbers */
versioninfo->sw_major_version = ETHTSYN_SW_MAJOR_VERSION;
versioninfo->sw_minor_version = ETHTSYN_SW_MINOR_VERSION;
versioninfo->sw_patch_version = ETHTSYN_SW_PATCH_VERSION;
}
#endif
#if (ETHTSYN_HARDWARE_TIMESTAMP_SUPPORT == STD_ON)
/**
*
* @param timeBaseId
* @param timeStampPtr
* @param syncState
* @return
*/
Std_ReturnType EthTSyn_GetCurrentTime( StbM_SynchronizedTimeBaseType timeBaseId, StbM_TimeStampType* timeStampPtr, EthTSyn_SyncStateType* syncState )
{
uint8 ctrlIdx;
Eth_TimeStampQualType timeEthIfQualPtr;
Eth_TimeStampType timeEthIfStampPtr;
Std_ReturnType retValue;
uint16 timeDomainId;
/* @req 4.2.2/SWS_EthTSyn_00007 */
ETHTSYN_DET_REPORTERROR((ETHTSYN_STATE_INIT == EthTSyn_Internal.initStatus), ETHTSYN_GETCURRENTTIME_ID, ETHTSYN_E_NOT_INITIALIZED, E_NOT_OK);
timeDomainId = EthTSyn_Internal_GetTimeDomainStbm(timeBaseId);
ETHTSYN_DET_REPORTERROR((ETHTSYN_INVALID_TIMEDOMAIN != timeDomainId),ETHTSYN_GETCURRENTTIME_ID,ETHTSYN_E_INVALID_TIMEBASE_ID,E_NOT_OK);
ETHTSYN_DET_REPORTERROR((NULL != timeStampPtr),ETHTSYN_GETCURRENTTIME_ID, ETHTSYN_E_PARAM_POINTER, E_NOT_OK);
ETHTSYN_DET_REPORTERROR((NULL != syncState),ETHTSYN_GETCURRENTTIME_ID, ETHTSYN_E_PARAM_POINTER, E_NOT_OK);
ctrlIdx = ETHTSYN_GET_CTRL_IDX(timeDomainId);
retValue = EthIf_GetCurrentTime(ctrlIdx, &timeEthIfQualPtr, &timeEthIfStampPtr);
if(E_OK == retValue){
if((EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.syncReceivedOnceFlag == FALSE)&&((PTP_SLAVE == EthTSyn_ConfigPointer->EthTSynGlobalTimeDomain[timeDomainId].EthTSynMasterFlag))){
*syncState = ETHTSYN_NEVERSYNC;
}else{
if(ETH_VALID == timeEthIfQualPtr){
*syncState = ETHTSYN_SYNC;
}else if(ETH_INVALID == timeEthIfQualPtr){
*syncState = ETHTSYN_UNSYNC;
}else {
*syncState = ETHTSYN_UNCERTAIN;
}
}
timeStampPtr->nanoseconds = timeEthIfStampPtr.nanoseconds;
timeStampPtr->seconds = timeEthIfStampPtr.seconds;
timeStampPtr->secondsHi = timeEthIfStampPtr.secondsHi;
}
return retValue;
}
/**
*
* @param timeBaseId
* @param timeStampPtr
* @return
*/
Std_ReturnType EthTSyn_SetGlobalTime( StbM_SynchronizedTimeBaseType timeBaseId, const StbM_TimeStampType* timeStampPtr )
{
uint8 ctrlIdx;
Eth_TimeStampType timeEthIfStampPtr;
Std_ReturnType retValue;
uint16 timeDomainId;
/* @req 4.2.2/SWS_EthTSyn_00007 */
ETHTSYN_DET_REPORTERROR((ETHTSYN_STATE_INIT == EthTSyn_Internal.initStatus), ETHTSYN_SETGLOBALTIME_ID, ETHTSYN_E_NOT_INITIALIZED, E_NOT_OK);
timeDomainId = EthTSyn_Internal_GetTimeDomainStbm(timeBaseId);
ETHTSYN_DET_REPORTERROR((ETHTSYN_INVALID_TIMEDOMAIN != timeDomainId), ETHTSYN_SETGLOBALTIME_ID,ETHTSYN_E_INVALID_TIMEBASE_ID,E_NOT_OK);
ETHTSYN_DET_REPORTERROR((NULL != timeStampPtr), ETHTSYN_SETGLOBALTIME_ID, ETHTSYN_E_PARAM_POINTER, E_NOT_OK);
timeEthIfStampPtr.nanoseconds = (*timeStampPtr).nanoseconds;
timeEthIfStampPtr.seconds = (*timeStampPtr).seconds;
timeEthIfStampPtr.secondsHi = (*timeStampPtr).secondsHi;
ctrlIdx = ETHTSYN_GET_CTRL_IDX(timeDomainId);
/* @req 4.2.2/SWS_EthTSyn_00015 */
retValue = EthIf_SetGlobalTime(ctrlIdx, &timeEthIfStampPtr);
return retValue;
}
#endif
/**
* API to turn on and off the TX capabilities of the EthTSyn
* @param CtrlIdx
* @param Mode
*/
void EthTSyn_SetTransmissionMode( uint8 CtrlIdx, EthTSyn_TransmissionModeType Mode )
{
EthTSyn_TimeDomainType timeDomainId;
timeDomainId = EthTsyn_Internal_GetTimeDomainId(CtrlIdx);
/* @req 4.2.2/SWS_EthTSyn_00007 */
ETHTSYN_DET_REPORTERROR((ETHTSYN_STATE_INIT == EthTSyn_Internal.initStatus), ETHTSYN_SETTRANSMISSIONMODE_ID, ETHTSYN_E_NOT_INITIALIZED);
ETHTSYN_DET_REPORTERROR((ETHTSYN_INVALID_CTRLID != EthTSyn_Internal_CheckEthIfCtrl(CtrlIdx)), ETHTSYN_SETTRANSMISSIONMODE_ID, ETHTSYN_E_INVALID_CTRL_ID);
ETHTSYN_DET_REPORTERROR(((ETHTSYN_TX_ON == Mode) ||(ETHTSYN_TX_OFF == Mode) ), ETHTSYN_SETTRANSMISSIONMODE_ID, ETHTSYN_E_INV_MODE);
EthTSyn_Internal.timeDomain[timeDomainId].transmissionMode = Mode;
}
/**
*
* @param CtrlIdx
* @param TrcvLinkState
* @return
*/
/* @req 4.2.2/SWS_EthTSyn_00043 */
Std_ReturnType EthTSyn_TrcvLinkStateChg( uint8 CtrlIdx, EthTrcv_LinkStateType TrcvLinkState )
{
Std_ReturnType retvalue;
uint16 timeDomainId;
uint8 i;
retvalue = E_OK;
timeDomainId = EthTsyn_Internal_GetTimeDomainId(CtrlIdx);
ETHTSYN_DET_REPORTERROR((ETHTSYN_STATE_INIT == EthTSyn_Internal.initStatus), ETHTSYN_TRCVLINKSTATECHG_ID, ETHTSYN_E_NOT_INITIALIZED, E_NOT_OK);
ETHTSYN_DET_REPORTERROR((ETHTSYN_INVALID_CTRLID != EthTSyn_Internal_CheckEthIfCtrl(CtrlIdx)), ETHTSYN_TRCVLINKSTATECHG_ID, ETHTSYN_E_INVALID_CTRL_ID, E_NOT_OK);
/* @req 4.2.2/SWS_EthTSyn_00019 */
if(ETHTRCV_LINK_STATE_DOWN == TrcvLinkState){
EthTSyn_Internal.timeDomain[timeDomainId].trcvActiveStateFlag = FALSE;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.txTime_pending = FALSE;
if(PTP_MASTER == EthTSyn_ConfigPointer->EthTSynGlobalTimeDomain[timeDomainId].EthTSynMasterFlag){
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.syncSend_State = SEND_SYNC_MSG;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.sentSync = FALSE;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.last_sync_tx_sequence_number = 0;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.txSyncTimePending = FALSE;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.syncIntervalTimerStarted = FALSE;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.syncIntervalTimeout = FALSE;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.syncfollowUpTimerStarted = FALSE;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.syncfollowUpTimerTimeout = FALSE;
for (i=0; i<ETHTSYN_MAX_PDELAY_REQUEST; i++) {
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.pDelayResp_State[i] = INITIAL_WAITING_FOR_PDELAY_REQ;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.rcvdPdelayReq[i] = FALSE;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.pdelayRespfollowUpTimerStarted[i] = FALSE;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.pdelayRespfollowUpTimerTimeout[i] = FALSE;
}
EthTSyn_Internal.timeDomain[timeDomainId].transmissionMode = ETHTSYN_TX_OFF;
#if (ETHTSYN_SEND_ANNOUNCE_SUPPORT == STD_ON)
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.announceIntervalTimerStarted = FALSE;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.announceIntervalTimeout = FALSE;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.last_announce_tx_sequence_number = 0;
#endif
}else{
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.syncReceive_State = DISCARD;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.rcvdSync = FALSE;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.rcvdFollowUp = FALSE;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.parent_last_sync_sequence_number = 0;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.sentPdelayReq = FALSE;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.pDelayReq_State = INITIAL_SEND_PDELAY_REQ;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.pdelayIntervalTimeout = FALSE;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.rcvdPdelayResp = FALSE;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.rcvdPdelayRespFollowUp = FALSE;
for ( i=0; i<ETHTSYN_MAX_PDELAY_REQUEST; i++) {
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.last_pdelay_resp_tx_sequence_number[i] = 0;
}
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.initPdelayRespReceived = FALSE;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.last_pdelay_req_tx_sequence_number = 0;
EthTSyn_Internal.timeDomain[timeDomainId].transmissionMode = ETHTSYN_TX_OFF;
}
}else{/* @req 4.2.2/SWS_EthTSyn_00020 */
EthTSyn_Internal.timeDomain[timeDomainId].trcvActiveStateFlag = TRUE;
}
return retvalue;
}
/**
* function to capture Ingress TimeStamp
* @param CtrlIdx
* @param timeDomainId
* @param timeStamp
* @param req_index
*/
/*lint -e{818} */
static void EthTSyn_Internal_IngressTimeStamp(uint8 CtrlIdx, EthTSyn_TimeDomainType timeDomainId, Eth_DataType* DataPtr,EthTSyn_Internal_MessageType messageType, uint8 req_index)
{
#if ETHTSYN_HARDWARE_TIMESTAMP_SUPPORT == STD_ON
Eth_TimeStampQualType timeQual;
Eth_TimeStampType timeStamp ;
#else
StbM_TimeStampType timeStampStbM;
StbM_UserDataType userData;
Std_ReturnType stbmretvalue;
userData = (StbM_UserDataType){0};
timeStampStbM = (StbM_TimeStampType){0,0,0,0};
(void)CtrlIdx;
(void)*DataPtr;
#endif
#if ETHTSYN_HARDWARE_TIMESTAMP_SUPPORT == STD_ON
EthIf_GetIngressTimeStamp(CtrlIdx, DataPtr, &timeQual, &timeStamp);
#else
uint8 timeBaseId = EthTSyn_ConfigPointer->EthTSynGlobalTimeDomain[timeDomainId].EthTSynSynchronizedTimeBaseRef;
stbmretvalue = StbM_GetCurrentTime(timeBaseId, &timeStampStbM, &userData );
#endif
/* Timestamp the received Sync msg */
if(RXSYNC == messageType){
#if ETHTSYN_HARDWARE_TIMESTAMP_SUPPORT == STD_ON
if(ETH_VALID == timeQual){
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.t2SyncReceiptTime.nanoseconds = timeStamp.nanoseconds;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.t2SyncReceiptTime.seconds = timeStamp.seconds;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.t2SyncReceiptTime.secondsHi = timeStamp.secondsHi;
}
#else
if(E_OK == stbmretvalue){
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.t2SyncReceiptTime.nanoseconds = timeStampStbM.nanoseconds;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.t2SyncReceiptTime.seconds = timeStampStbM.seconds;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.t2SyncReceiptTime.secondsHi = timeStampStbM.secondsHi;
}
#endif
}else if(RXPDELAY_REQ == messageType){ /* Timestamp the received Pdelay msg */
#if ETHTSYN_HARDWARE_TIMESTAMP_SUPPORT == STD_ON
if(ETH_VALID == timeQual){
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.t2PdelayReqRxTime[req_index].nanoseconds = timeStamp.nanoseconds;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.t2PdelayReqRxTime[req_index].seconds = timeStamp.seconds;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.t2PdelayReqRxTime[req_index].secondsHi = timeStamp.secondsHi;
}
#else
if(E_OK == stbmretvalue){
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.t2PdelayReqRxTime[req_index].nanoseconds = timeStampStbM.nanoseconds;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.t2PdelayReqRxTime[req_index].seconds = timeStampStbM.seconds;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.t2PdelayReqRxTime[req_index].secondsHi = timeStampStbM.secondsHi;
}else{
}
#endif
}else if (RXPDELAY_RESP == messageType){/* Timestamp the received Pdelay Resp msg */
#if ETHTSYN_HARDWARE_TIMESTAMP_SUPPORT == STD_ON
if(ETH_VALID == timeQual){
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.t4PdelayRespRxTime.nanoseconds = timeStamp.nanoseconds;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.t4PdelayRespRxTime.seconds = timeStamp.seconds;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.t4PdelayRespRxTime.secondsHi = timeStamp.secondsHi;
}
#else
if(E_OK == stbmretvalue){
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.t4PdelayRespRxTime.nanoseconds = timeStampStbM.nanoseconds;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.t4PdelayRespRxTime.seconds = timeStampStbM.seconds;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.t4PdelayRespRxTime.secondsHi = timeStampStbM.secondsHi;
}
#endif
}else {}
}
/**
* function to capture Egress TimeStamp
* @param CtrlIdx
* @param BufIdx
* @param timeDomainId
* @param timeStamp
* @param req_index
*/
static Std_ReturnType EthTSyn_Internal_EgressTimeStamp(uint8 CtrlIdx, Eth_BufIdxType BufIdx, EthTSyn_TimeDomainType timeDomainId, EthTSyn_Internal_MessageType messageType, uint8 req_index)
{
Std_ReturnType retvalue;
#if ETHTSYN_HARDWARE_TIMESTAMP_SUPPORT == STD_ON
Eth_TimeStampQualType timeQual;
Eth_TimeStampType timeStamp;
#else
StbM_TimeStampType timeStampStbM;
StbM_UserDataType userData;
Std_ReturnType stbmretvalue;
userData = (StbM_UserDataType){0};
timeStampStbM = (StbM_TimeStampType){0,0,0,0};
(void)CtrlIdx;
(void)BufIdx;
#endif
retvalue = E_NOT_OK;
#if ETHTSYN_HARDWARE_TIMESTAMP_SUPPORT == STD_ON
EthIf_GetEgressTimeStamp(CtrlIdx, BufIdx, &timeQual, &timeStamp);
#else
uint8 timeBaseId = EthTSyn_ConfigPointer->EthTSynGlobalTimeDomain[timeDomainId].EthTSynSynchronizedTimeBaseRef;
stbmretvalue = StbM_GetCurrentTime(timeBaseId, &timeStampStbM, &userData );
#endif
/* Timestamp the sent Sync msg */
if(TXSYNC == messageType){
#if ETHTSYN_HARDWARE_TIMESTAMP_SUPPORT == STD_ON
if(ETH_VALID == timeQual){
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.t1SyncTxTime.nanoseconds = timeStamp.nanoseconds;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.t1SyncTxTime.seconds = timeStamp.seconds;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.t1SyncTxTime.secondsHi = timeStamp.secondsHi;
retvalue = E_OK;
}else{
retvalue = E_NOT_OK;
}
#else
if(E_OK == stbmretvalue){
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.t1SyncTxTime.nanoseconds = timeStampStbM.nanoseconds;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.t1SyncTxTime.seconds = timeStampStbM.seconds;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.t1SyncTxTime.secondsHi = timeStampStbM.secondsHi;
retvalue = E_OK;
}else{
retvalue = E_NOT_OK;
}
#endif
}else if(TXPDELAY_REQ == messageType){/* Timestamp the sent Pdelay Req msg */
#if ETHTSYN_HARDWARE_TIMESTAMP_SUPPORT == STD_ON
if(ETH_VALID == timeQual){
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.t1PdelayReqTxTime.nanoseconds = timeStamp.nanoseconds;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.t1PdelayReqTxTime.seconds = timeStamp.seconds;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.t1PdelayReqTxTime.secondsHi = timeStamp.secondsHi;
retvalue = E_OK;
}else{
retvalue = E_NOT_OK;
}
#else
if(E_OK == stbmretvalue){
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.t1PdelayReqTxTime.nanoseconds = timeStampStbM.nanoseconds;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.t1PdelayReqTxTime.seconds = timeStampStbM.seconds;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.t1PdelayReqTxTime.secondsHi = timeStampStbM.secondsHi;
retvalue = E_OK;
}else{
retvalue = E_NOT_OK;
}
#endif
}else if(TXPDELAY_RESP == messageType){ /* Timestamp the sent Pdelay Resp msg */
#if ETHTSYN_HARDWARE_TIMESTAMP_SUPPORT == STD_ON
if(ETH_VALID == timeQual){
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.t3PdelayRespTxTime[req_index].nanoseconds = timeStamp.nanoseconds;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.t3PdelayRespTxTime[req_index].seconds = timeStamp.seconds;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.t3PdelayRespTxTime[req_index].secondsHi = timeStamp.secondsHi;
}
#else
if(E_OK == stbmretvalue){
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.t3PdelayRespTxTime[req_index].nanoseconds = timeStampStbM.nanoseconds;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.t3PdelayRespTxTime[req_index].seconds = timeStampStbM.seconds;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.t3PdelayRespTxTime[req_index].secondsHi = timeStampStbM.secondsHi;
retvalue = E_OK;
}else{
retvalue = E_NOT_OK;
}
#endif
}else{}
return retvalue;
}
/**
*
* @param CtrlIdx
* @param BufIdx
*/
void EthTSyn_TxConfirmation( uint8 CtrlIdx, Eth_BufIdxType BufIdx )
{
uint16 timeDomainId;
Std_ReturnType retval;
uint8 i;
timeDomainId = EthTsyn_Internal_GetTimeDomainId(CtrlIdx);
ETHTSYN_DET_REPORTERROR((ETHTSYN_STATE_INIT == EthTSyn_Internal.initStatus), ETHTSYN_TXCONFIRMATION_ID, ETHTSYN_E_NOT_INITIALIZED);
ETHTSYN_DET_REPORTERROR((ETHTSYN_INVALID_CTRLID != EthTSyn_Internal_CheckEthIfCtrl(CtrlIdx)), ETHTSYN_TXCONFIRMATION_ID, ETHTSYN_E_INVALID_CTRL_ID);
if (TRUE == EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.txTime_pending){
/* at least one tx timestamp pending */
/* Sync pending */ /* @req 4.2.2/SWS_EthTSyn_00017 */
if (TRUE == EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.txSyncTimePending){
/* If port is Master timestamp it */
if(PTP_MASTER == EthTSyn_ConfigPointer->EthTSynGlobalTimeDomain[timeDomainId].EthTSynMasterFlag){
retval = EthTSyn_Internal_EgressTimeStamp(CtrlIdx,BufIdx,timeDomainId,TXSYNC,0); /*@req 4.2.2/SWS_EthTSyn_00017 */
if(E_OK == retval){
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.sentSync = TRUE;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.txSyncTimePending = FALSE;
}else{
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.syncSend_State = SEND_SYNC_MSG;
}
}/*else {
Sync Tx pending is true, but we are no longer master time pending Flags
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.txSyncTimePending = FALSE;
}*/
}
/* @req 4.2.2/SWS_EthTSyn_00013 */
/* PDelay request pending */
if(TRUE == EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.txPdelayReqTimePending){
/* Pdelay Req sent and Time stamp T1 */
retval = EthTSyn_Internal_EgressTimeStamp(CtrlIdx,BufIdx,timeDomainId,TXPDELAY_REQ,0);
if(E_OK == retval){
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.sentPdelayReq = TRUE;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.txPdelayReqTimePending = FALSE;
}else{
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.pDelayReq_State = SEND_PDELAY_REQ;
}
}
/* PDelay response pending */
for (i=0; i < ETHTSYN_MAX_PDELAY_REQUEST; i++) {
if(TRUE == EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.txPdelayRespTimePending[i]){
/* Pdelay Resp sent and Time stamp T3 */
retval = EthTSyn_Internal_EgressTimeStamp(CtrlIdx,BufIdx,timeDomainId,TXPDELAY_RESP,i);
(void)retval;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.txPdelayRespTimePending[i] = FALSE;
}
}
}
}
/**
* function process received Sync message and time stamp ingress time
* @param CtrlIdx
* @param timeDomainId
* @param DataPtr
* @param LenByte
*/
static void EthTSyn_Internal_SyncReceive(uint8 CtrlIdx, EthTSyn_TimeDomainType timeDomainId, uint8* DataPtr, uint16 LenByte)
{
uint16 sequence_delta;
/*lint -e927 -e826 LenByte check below ensures addresses referenced by is pktPtr valid*/
const EthTsyn_Internal_MsgSync * pktPtr = (EthTsyn_Internal_MsgSync *)DataPtr;
sequence_delta = bswap16(pktPtr->headerMsg.sequenceId) - EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.parent_last_sync_sequence_number;
if((sequence_delta == 0) || (LenByte < V2_SYNC_LENGTH)){
/* Possible duplicate sequence received/short sync message, ignoring */
/*lint -e{904} Return statement is necessary to avoid multiple if loops and hence increase readability in case of argument check */
return;
}
if (sequence_delta != 1)
{
/* 1 or more sync Messages may have been lost/discarded */
}
/* Time stamp T2 */
EthTSyn_Internal_IngressTimeStamp(CtrlIdx,timeDomainId, DataPtr, RXSYNC, 0);
/* Store sequence id to check next time with followup seq id */
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.parent_last_sync_sequence_number = bswap16(pktPtr->headerMsg.sequenceId);
if(V2_TWO_STEP_FLAG == (pktPtr->headerMsg.flags[0] & V2_TWO_STEP_FLAG)){
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.waitingForFollow = TRUE;
/*Start Follow Up Timer */
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.RxFollowUpTimerStarted = TRUE;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.RxFollowUpTimer = 0;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.rcvdSync = TRUE;
}else
{
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.rcvdSync = FALSE;
}
}
/**
* function process received Sync FUP message and time stamp ingress time
* @param CtrlIdx
* @param timeDomainId
* @param DataPtr
* @param LenByte
*/
static void EthTSyn_Internal_SyncFollowUpReceive(uint8 CtrlIdx, EthTSyn_TimeDomainType timeDomainId, const uint8* DataPtr, uint16 LenByte)
{
/*lint -e927 -e826 LenByte check below ensures addresses referenced by is pktPtr valid*/
const EthTsyn_Internal_MsgFollowUp * pktPtr = (const EthTsyn_Internal_MsgFollowUp *)DataPtr;
if(LenByte < V2_FOLLOWUP_LENGTH){
/*lint -e{904} Return statement is necessary to avoid multiple if loops and hence increase readability in case of argument check */
return;
}
if((TRUE == EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.waitingForFollow)){
if(EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.parent_last_sync_sequence_number == bswap16(pktPtr->headerMsg.sequenceId)){
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.t1SyncOriginTime.nanoseconds = bswap32(pktPtr->preciseOriginTimestamp.nanoseconds);
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.t1SyncOriginTime.seconds = bswap32(pktPtr->preciseOriginTimestamp.seconds);
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.t1SyncOriginTime.secondsHi = bswap16(pktPtr->preciseOriginTimestamp.secondsHi);
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.waitingForFollow = FALSE;
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.rcvdFollowUp = TRUE;
/* Reset Sync interval timer */
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.RxFollowUpTimerStarted = FALSE;
}
}/* short sync FollowUp message */
(void)CtrlIdx;
}
/**
* function process received Pdelay Req message and time stamp ingress time
* @param CtrlIdx
* @param timeDomainId
* @param DataPtr
* @param LenByte
*/
static void EthTSyn_Internal_PdelayReqReceive(uint8 CtrlIdx, EthTSyn_TimeDomainType timeDomainId, uint8* DataPtr, uint16 LenByte)
{
uint8 i;
/*lint -e927 -e826 LenByte check below ensures addresses referenced by is pktPtr valid*/
const EthTsyn_Internal_MsgPDelayReq * pktPtr = (EthTsyn_Internal_MsgPDelayReq *)DataPtr;
if(LenByte < V2_PDELAY_REQ_LENGTH){
/*lint -e{904} Return statement is necessary to avoid multiple if loops and hence increase readability in case of argument check */
return;
}
/* Find index to requestingPortIdentity */
for (i=0; i<ETHTSYN_MAX_PDELAY_REQUEST; i++) {
if (memcmp(EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.requestingPortIdentity[i].clockIdentity,
pktPtr->headerMsg.sourcePortId.clockIdentity, CLOCK_IDENTITY_LENGTH) == 0) {
break;
}
}
if (i == ETHTSYN_MAX_PDELAY_REQUEST) {
/* First pdelay_req that is received take new index! */
if (EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.numPdelay_req < ETHTSYN_MAX_PDELAY_REQUEST ) {
i = EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.numPdelay_req;
memcpy(EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.requestingPortIdentity[i].clockIdentity, pktPtr->headerMsg.sourcePortId.clockIdentity, CLOCK_IDENTITY_LENGTH);
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.numPdelay_req++;
} else {
i = ETHTSYN_MAX_PDELAY_REQUEST-1; /* reuse the last index!!! */
memcpy(EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.requestingPortIdentity[i].clockIdentity, pktPtr->headerMsg.sourcePortId.clockIdentity, CLOCK_IDENTITY_LENGTH);
}
}
/* Time stamp T2 */
EthTSyn_Internal_IngressTimeStamp(CtrlIdx,timeDomainId,DataPtr, RXPDELAY_REQ, i);
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.last_pdelay_resp_tx_sequence_number[i] = bswap16(pktPtr->headerMsg.sequenceId);
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.requestingPortIdentity[i].portNumber = bswap16(pktPtr->headerMsg.sourcePortId.portNumber);
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.rcvdPdelayReq[i] = TRUE;
}
/**
* function process received Pdelay Resp message and time stamp ingress time
* @param CtrlIdx
* @param timeDomainId
* @param DataPtr
* @param LenByte
*/
static void EthTSyn_Internal_PdelayRespReceive(uint8 CtrlIdx, EthTSyn_TimeDomainType timeDomainId, uint8* DataPtr, uint16 LenByte)
{
/*lint -e927 -e826 LenByte check below ensures addresses referenced by is pktPtr valid*/
const EthTsyn_Internal_MsgPDelayResp * pktPtr = (EthTsyn_Internal_MsgPDelayResp *) DataPtr;
if(LenByte < V2_PDELAY_RESP_LENGTH){
/*lint -e{904} Return statement is necessary to avoid multiple if loops and hence increase readability in case of argument check */
return;
}
if (EthTSyn_ConfigPointer->EthTSynGlobalTimeDomain[timeDomainId].EthTSynMasterFlag == PTP_SLAVE) {
/* Time stamp T4 */
EthTSyn_Internal_IngressTimeStamp(CtrlIdx,timeDomainId,DataPtr,RXPDELAY_RESP,0);
/* Take T2 Copy from receiveTimestamp */
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.t2PdelayRespTime[0].nanoseconds = bswap32(pktPtr->receiveTimestamp.nanoseconds);
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.t2PdelayRespTime[0].seconds = bswap32(pktPtr->receiveTimestamp.seconds);
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.t2PdelayRespTime[0].secondsHi = bswap16(pktPtr->receiveTimestamp.secondsHi);
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.last_pdelay_resp_tx_sequence_number[0] = bswap16(pktPtr->headerMsg.sequenceId);
if((memcmp(EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.port_clock_identity, pktPtr->requestingPortId.clockIdentity, CLOCK_IDENTITY_LENGTH) == 0)
&& (bswap16(pktPtr->requestingPortId.portNumber) == DEFAULT_PORT_NUMBER)){
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.rcvdPdelayResp = TRUE;
}
}
}
/**
* function process received Pdelay Resp FUP message and time stamp ingress time
* @param CtrlIdx
* @param timeDomainId
* @param DataPtr
* @param LenByte
*/
static void EthTSyn_Internal_PdelayRespFollowUpReceive(uint8 CtrlIdx, EthTSyn_TimeDomainType timeDomainId, const uint8* DataPtr, uint16 LenByte)
{
/*lint -e927 -e826 LenByte check below ensures addresses referenced by is pktPtr valid*/
const EthTsyn_Internal_MsgPDelayRespFollowUp * pktPtr = (const EthTsyn_Internal_MsgPDelayRespFollowUp *) DataPtr;
if(LenByte < V2_PDELAY_RESP_FOLLOWUP_LENGTH){
/*lint -e{904} Return statement is necessary to avoid multiple if loops and hence increase readability in case of argument check */
return;
}
if (EthTSyn_ConfigPointer->EthTSynGlobalTimeDomain[timeDomainId].EthTSynMasterFlag == PTP_SLAVE) {
/* Time stamp T3 */
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.t3PdelayRespTime.nanoseconds = bswap32(pktPtr->responseOriginTimestamp.nanoseconds);
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.t3PdelayRespTime.seconds = bswap32(pktPtr->responseOriginTimestamp.seconds);
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.t3PdelayRespTime.secondsHi = bswap16(pktPtr->responseOriginTimestamp.secondsHi);
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.last_pdelay_resp_follow_tx_sequence_number[0] = bswap16(pktPtr->headerMsg.sequenceId);
if((memcmp(EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.port_clock_identity, pktPtr->requestingPortId.clockIdentity, CLOCK_IDENTITY_LENGTH) == 0)
&& (bswap16(pktPtr->requestingPortId.portNumber) == DEFAULT_PORT_NUMBER)){
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.rcvdPdelayRespFollowUp = TRUE;
}
}
(void)CtrlIdx;
}
/**
* function process received message and time stamp ingress time
* @param CtrlIdx
* @param FrameType
* @param IsBroadcast
* @param PhysAddrPtr
* @param DataPtr
* @param LenByte
*/
void EthTSyn_RxIndication( uint8 CtrlIdx, Eth_FrameType FrameType, boolean IsBroadcast, const uint8* PhysAddrPtr, uint8* DataPtr, uint16 LenByte )
{
EthTSyn_TimeDomainType timeDomainId;
timeDomainId = EthTsyn_Internal_GetTimeDomainId(CtrlIdx);
/*@req 4.2.2/SWS_EthTSyn_00041 */
ETHTSYN_DET_REPORTERROR((ETHTSYN_STATE_INIT == EthTSyn_Internal.initStatus), ETHTSYN_RXINDICATION_ID, ETHTSYN_E_NOT_INITIALIZED);
ETHTSYN_DET_REPORTERROR((ETHTSYN_INVALID_CTRLID != EthTSyn_Internal_CheckEthIfCtrl(CtrlIdx)), ETHTSYN_RXINDICATION_ID, ETHTSYN_E_INVALID_CTRL_ID);
if(ETH_FRAME_TYPE_TSYN == FrameType){
/*lint -e{9016,926} */
EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.msg_type = *(uint8*) (DataPtr + 0) & ETHTSYN_MESSAGE_TYPE ;
switch(EthTSyn_Internal.timeDomain[timeDomainId].ptpCfgData.msg_type){
case V2_SYNC_MESSAGE :
EthTSyn_Internal_SyncReceive(CtrlIdx, timeDomainId, DataPtr, LenByte); /* @req 4.2.2/SWS_EthTSyn_00024 */
break;
case V2_FOLLOWUP_MESSAGE :
EthTSyn_Internal_SyncFollowUpReceive(CtrlIdx, timeDomainId, DataPtr, LenByte);
break;
case V2_PDELAY_REQ_MESSAGE :
EthTSyn_Internal_PdelayReqReceive(CtrlIdx, timeDomainId, DataPtr, LenByte); /* @req 4.2.2/SWS_EthTSyn_00049 */
break;
case V2_PDELAY_RESP_MESSAGE:
EthTSyn_Internal_PdelayRespReceive(CtrlIdx, timeDomainId, DataPtr, LenByte); /* @req 4.2.2/SWS_EthTSyn_00049 */
break;
case V2_PDELAY_RESP_FOLLOWUP_MESSAGE:
EthTSyn_Internal_PdelayRespFollowUpReceive(CtrlIdx, timeDomainId, DataPtr, LenByte);
break;
default : /*@req 4.2.2/SWS_EthTSyn_00005 */
break;
}
}/* Frame invalid Ethertype (not 802.1AS PTP), ignore */
(void)IsBroadcast;
/*lint -e{920} */
(void)PhysAddrPtr;
/*lint -e{818} */
}
#if (ETHTSYN_SEND_ANNOUNCE_SUPPORT == STD_ON)
/**
* function transmit packet Announce message
* @param timeDomain
*/
static Std_ReturnType EthTSyn_Internal_SendAnnounce(uint8 timeDomain)
{
uint8 ctrlIdx;
Eth_BufIdxType bufIndex;
uint16 lenByte;
void* address;
EthTsyn_Internal_MsgAnnounce *announceMsg;
Std_ReturnType retValue;
BufReq_ReturnType retBufValue;
retValue = E_NOT_OK;
lenByte = V2_ANNOUNCE_LENGTH + 4 + V2_CLOCKPATH_TLV_LEN*1;
bufIndex = 0;
ctrlIdx = EthTSyn_ConfigPointer->EthTSynGlobalTimeDomain[timeDomain].EthTSynTimeDomain->EthTSynGlobalTimeEthIfId;
/*lint -e{929}*/
retBufValue = EthIf_ProvideTxBuffer(ctrlIdx, ETH_FRAME_TYPE_TSYN, 0, &bufIndex, (uint8 **)&address, &lenByte);
if(BUFREQ_OK == retBufValue){
/* Sequence Id increment */
++(EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.last_announce_tx_sequence_number);
announceMsg = (EthTsyn_Internal_MsgAnnounce *)address;
/* Prepare Sync Msg packet */
EthTSyn_Internal_MsgPackAnnounceMsg(announceMsg, timeDomain);
retValue = EthIf_Transmit(ctrlIdx, bufIndex, ETH_FRAME_TYPE_TSYN, TRUE, lenByte, EthTSyn_Internal_MulitCast_DestMACAddrs);
if(E_OK == retValue){
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.txSyncTimePending = FALSE;
}else{
/* Since Transmission is failed decrement Sequence Id */
--(EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.last_announce_tx_sequence_number);
}
}
return retValue;
}
#endif
/**
* function transmit packed Sync message and timestamp the egress time
* @param timeDomain
*/
static Std_ReturnType EthTSyn_Internal_SendSync(uint8 timeDomain)
{
uint8 ctrlIdx;
Eth_BufIdxType bufIndex;
uint16 lenByte;
void* address;
EthTsyn_Internal_MsgSync *syncMsg;
Std_ReturnType retValue;
BufReq_ReturnType retBufValue;
retValue = E_NOT_OK;
lenByte = V2_SYNC_LENGTH;
bufIndex = 0;
ctrlIdx = EthTSyn_ConfigPointer->EthTSynGlobalTimeDomain[timeDomain].EthTSynTimeDomain->EthTSynGlobalTimeEthIfId;
/*lint -e{929}*/
retBufValue = EthIf_ProvideTxBuffer(ctrlIdx, ETH_FRAME_TYPE_TSYN, 0, &bufIndex, (uint8 **)&address, &lenByte);
if(BUFREQ_OK == retBufValue){
#if (ETHTSYN_HARDWARE_TIMESTAMP_SUPPORT == STD_ON)
EthIf_EnableEgressTimeStamp(ctrlIdx, bufIndex);
#endif
/* Sequence Id increment */
++(EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.last_sync_tx_sequence_number);
syncMsg = (EthTsyn_Internal_MsgSync *)address;
/* Prepare Sync Msg packet */
EthTSyn_Internal_MsgPackSyncMsg(syncMsg, timeDomain);
retValue = EthIf_Transmit(ctrlIdx, bufIndex, ETH_FRAME_TYPE_TSYN, TRUE, lenByte, EthTSyn_Internal_MulitCast_DestMACAddrs);
if(E_OK == retValue){
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.txTime_pending = TRUE;
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.txSyncTimePending = TRUE;
}else{
/* Since Transmission is failed decrement Sequence Id */
--(EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.last_sync_tx_sequence_number);
}
}
return retValue;
}
/**
* function transmit packed Sync FUP message and timestamp the egress time
* @param timeDomain
*/
/* @req 4.2.2/SWS_EthTSyn_00018 */
static Std_ReturnType EthTSyn_Internal_SendSyncFollowUp(uint8 timeDomain)
{
Eth_BufIdxType bufIndex;
uint16 lenByte;
void* address;
EthTsyn_Internal_MsgFollowUp *syncFollowMsg;
uint8 ctrlIdx;
Std_ReturnType retValue;
BufReq_ReturnType retBufValue;
retValue = E_NOT_OK;
lenByte = V2_FOLLOWUP_LENGTH;
bufIndex = 0;
ctrlIdx = EthTSyn_ConfigPointer->EthTSynGlobalTimeDomain[timeDomain].EthTSynTimeDomain->EthTSynGlobalTimeEthIfId;
/*lint -e{929} */
retBufValue = EthIf_ProvideTxBuffer(ctrlIdx, ETH_FRAME_TYPE_TSYN, 0, &bufIndex, (uint8**)&address, &lenByte);
if(BUFREQ_OK == retBufValue){
syncFollowMsg = (EthTsyn_Internal_MsgFollowUp*)address;
EthTSyn_Internal_MsgPackSyncFollow(syncFollowMsg, timeDomain);
retValue = EthIf_Transmit(ctrlIdx, bufIndex, ETH_FRAME_TYPE_TSYN, TRUE, lenByte, EthTSyn_Internal_MulitCast_DestMACAddrs);
if(E_OK == retValue){
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.txSyncTimePending = FALSE;
}
}
return retValue;
}
/**
* function transmit packed Pdelay Req message and timestamp the egress time
* @param timeDomain
*/
static Std_ReturnType EthTSyn_Internal_SendPdelayReq(uint8 timeDomain)
{
uint8 ctrlIdx;
Eth_BufIdxType bufIndex;
uint16 lenByte;
void* address;
EthTsyn_Internal_MsgPDelayReq *PdelayReqMsg;
Std_ReturnType retValue;
BufReq_ReturnType retBufValue;
retValue = E_NOT_OK;
lenByte = V2_PDELAY_REQ_LENGTH;
bufIndex = 0;
ctrlIdx = EthTSyn_ConfigPointer->EthTSynGlobalTimeDomain[timeDomain].EthTSynTimeDomain->EthTSynGlobalTimeEthIfId;
/*lint -e{929} */
retBufValue = EthIf_ProvideTxBuffer(ctrlIdx, ETH_FRAME_TYPE_TSYN, 0, &bufIndex, (uint8**)&address, &lenByte);
if(BUFREQ_OK == retBufValue){
#if (ETHTSYN_HARDWARE_TIMESTAMP_SUPPORT == STD_ON)
EthIf_EnableEgressTimeStamp(ctrlIdx, bufIndex);
#endif
/* Sequence Id increment */
++(EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.last_pdelay_req_tx_sequence_number);
PdelayReqMsg = (EthTsyn_Internal_MsgPDelayReq*)address;
EthTSyn_Internal_MsgPackPdelayReqMsg(PdelayReqMsg, timeDomain);
retValue = EthIf_Transmit(ctrlIdx, bufIndex, ETH_FRAME_TYPE_TSYN, TRUE, lenByte, EthTSyn_Internal_MulitCast_DestMACAddrs);
if(E_OK == retValue){
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.txTime_pending = TRUE;
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.txPdelayReqTimePending = TRUE;
}else{
/* Since Transmission is failed decrement Sequence Id */
--(EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.last_pdelay_req_tx_sequence_number);
}
}
return retValue;
}
/**
* function transmit packed Pdelay Resp message and timestamp the egress time
* @param timeDomain
* @param req_index
*/
static Std_ReturnType EthTSyn_Internal_SendPdelayResp(uint8 timeDomain, uint8 req_index)
{
uint8 ctrlIdx;
Eth_BufIdxType bufIndex;
uint16 lenByte;
void* address;
EthTsyn_Internal_MsgPDelayResp *PdelayRespMsg;
Std_ReturnType retValue;
BufReq_ReturnType retBufValue;
retValue = E_NOT_OK;
lenByte = V2_PDELAY_RESP_LENGTH;
bufIndex = 0;
ctrlIdx = EthTSyn_ConfigPointer->EthTSynGlobalTimeDomain[timeDomain].EthTSynTimeDomain->EthTSynGlobalTimeEthIfId;
/*lint -e{929} */
retBufValue = EthIf_ProvideTxBuffer(ctrlIdx, ETH_FRAME_TYPE_TSYN, 0, &bufIndex, (uint8**)&address, &lenByte);
if(BUFREQ_OK == retBufValue){
#if (ETHTSYN_HARDWARE_TIMESTAMP_SUPPORT == STD_ON)
EthIf_EnableEgressTimeStamp(ctrlIdx, bufIndex);
#endif
PdelayRespMsg = (EthTsyn_Internal_MsgPDelayResp*)address;
EthTSyn_Internal_MsgPackPdelayRespMsg(PdelayRespMsg, timeDomain,req_index);
retValue = EthIf_Transmit(ctrlIdx, bufIndex, ETH_FRAME_TYPE_TSYN, TRUE, lenByte, EthTSyn_Internal_MulitCast_DestMACAddrs);
if(E_OK == retValue){
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.txTime_pending = TRUE;
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.txPdelayRespTimePending[req_index] = TRUE;
}
}
return retValue;
}
/**
* function transmit packed Pdelay Resp FUP message and timestamp the egress time
* @param timeDomain
* @param req_index
*/
/* @req 4.2.2/SWS_EthTSyn_00014 */
static void EthTSyn_Internal_SendPdelayRespFollowUp(uint8 timeDomain, uint8 req_index)
{
Eth_BufIdxType bufIndex;
uint16 lenByte;
void* address;
EthTsyn_Internal_MsgPDelayRespFollowUp *PdelayRespFollowMsg;
uint8 ctrlIdx;
Std_ReturnType retValue;
BufReq_ReturnType retBufValue;
lenByte = V2_PDELAY_RESP_FOLLOWUP_LENGTH;
bufIndex = 0;
ctrlIdx = EthTSyn_ConfigPointer->EthTSynGlobalTimeDomain[timeDomain].EthTSynTimeDomain->EthTSynGlobalTimeEthIfId;
/*lint -e{929} */
retBufValue = EthIf_ProvideTxBuffer(ctrlIdx, ETH_FRAME_TYPE_TSYN, 0, &bufIndex, (uint8**)&address, &lenByte);
if(BUFREQ_OK == retBufValue){
PdelayRespFollowMsg = (EthTsyn_Internal_MsgPDelayRespFollowUp*)address;
EthTSyn_Internal_MsgPackPdelayRespFollowUpMsg(PdelayRespFollowMsg, timeDomain, req_index);
retValue = EthIf_Transmit(ctrlIdx, bufIndex, ETH_FRAME_TYPE_TSYN, TRUE, lenByte, EthTSyn_Internal_MulitCast_DestMACAddrs);
if(E_OK == retValue){
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.pdelayRespTimerStarted[req_index] = FALSE;
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.pdelayRespTimeout[req_index] = FALSE;
}
}
}
/**
* function calculate neighbor RateRatio
* @param timeDomain
*/
/* @req 4.2.2/SWS_EthTSyn_00003 */
static void computePdelayRateRatio(uint8 timeDomain)
{
sint64 correctedResponderEventTimestamp_N;
sint64 correctedResponderEventTimestamp_0;
sint64 pdelayRespEventIngressTimestamp_N;
sint64 pdelayRespEventIngressTimestamp_0;
sint64 result_1;
sint64 result_2;
/* Store Pdelay Resp receipt timestamp */
pdelayRespEventIngressTimestamp_N = (sint64)convert_To_NanoSec(EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.t4PdelayRespRxTime);
pdelayRespEventIngressTimestamp_0 = (sint64)convert_To_NanoSec(EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.t4PdelayRespRxTime_old);
/* Store Pdelay Resp origin timestamp */
correctedResponderEventTimestamp_N = (sint64)convert_To_NanoSec(EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.t3PdelayRespTime);
correctedResponderEventTimestamp_0 = (sint64)convert_To_NanoSec(EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.t3PdelayRespRxTime_old);
/*Get Ingress time and Engress Time stamp of Pdelay Resp */
result_1 = (pdelayRespEventIngressTimestamp_N - pdelayRespEventIngressTimestamp_0);
result_2 = (correctedResponderEventTimestamp_N - correctedResponderEventTimestamp_0);
/* neighborRateRatio */
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.neighborRateRatio = (result_2 / result_1);
}
/**
* function to calculate peer mean path delay(link delay)
* @param timeDomain
*/
static void computePropTime(uint8 timeDomain)
{
sint64 pdelayRespEventIngressTimestamp;
sint64 pdelayReqEventEgressTimestamp;
sint64 requestReceiptTimestamp;
sint64 responseOriginTimestamp;
/* convert T1, T2, T3 and T4 into nanoseconds */
pdelayReqEventEgressTimestamp = (sint64)(convert_To_NanoSec(EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.t1PdelayReqTxTime));
requestReceiptTimestamp = (sint64)(convert_To_NanoSec(EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.t2PdelayRespTime[0]));
responseOriginTimestamp = (sint64)(convert_To_NanoSec(EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.t3PdelayRespTime));
pdelayRespEventIngressTimestamp = (sint64)(convert_To_NanoSec(EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.t4PdelayRespRxTime));
/* peer mean path delay value */
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.peer_mean_path_delay = (((pdelayRespEventIngressTimestamp - pdelayReqEventEgressTimestamp) - (responseOriginTimestamp - requestReceiptTimestamp))/2);
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.peer_mean_path_delay = EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.peer_mean_path_delay * EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.neighborRateRatio;
}
/**
* function to calculate offset from master to slave and sync with master
* @param timeDomain
*/
static void synchronize_clock(uint8 timeDomain)
{
sint64 t2Recv_time;
sint64 t1Send_time;
sint64 master_to_slave_delay;
#if (ETHTSYN_HARDWARE_TIMESTAMP_SUPPORT == STD_ON)
uint8 ctrlIdx;
Eth_TimeIntDiffType offset_From_Master;
EthTSyn_Internal_TimeNanoType tmp_Master_to_slave_delay;
#else
StbM_TimeStampType stbmTimeStamp;
uint64 updatedStbmTimeStamp;
StbM_UserDataType userData;
Std_ReturnType retVal;
sint64 stbmTime;
#endif
/* convert origintime at master port of sync msg into nano secs */
t1Send_time = (sint64)convert_To_NanoSec(EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.t1SyncOriginTime);
/* convert Receipt time of syncmsg at slave port into nano secs */
t2Recv_time = (sint64)convert_To_NanoSec(EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.t2SyncReceiptTime);
/* Calculate offset from master to slave port */
master_to_slave_delay = ((t2Recv_time - t1Send_time) - EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.peer_mean_path_delay);
/* master_to_slave_delay = (((((t2Recv_time - t1Send_time) - EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.syncCorrection) -
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.followupCorrection) - EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.peer_mean_path_delay ));*/
#if (ETHTSYN_HARDWARE_TIMESTAMP_SUPPORT == STD_ON)
/* Convert Offset calculation as per autosar req to send it as function parameter in EthIf_SetCorrectionTime and StbM_BusSetGlobalTime */
tmp_Master_to_slave_delay = absolute(master_to_slave_delay);
offset_From_Master.diff.secondsHi = (uint16)(((uint64)(tmp_Master_to_slave_delay.master_to_slave_delay/1000000000ULL)) >> 32u);
offset_From_Master.diff.seconds = (uint32)(tmp_Master_to_slave_delay.master_to_slave_delay/1000000000ULL);
offset_From_Master.diff.nanoseconds = (uint32)(tmp_Master_to_slave_delay.master_to_slave_delay % 1000000000ULL);
offset_From_Master.sign = tmp_Master_to_slave_delay.sign;
ctrlIdx = EthTSyn_ConfigPointer->EthTSynGlobalTimeDomain[timeDomain].EthTSynTimeDomain->EthTSynGlobalTimeEthIfId;
/* @req 4.2.2/SWS_EthTSyn_00026 */
/* Check Offset delay is exceeds config thresold delay */
if((0 == EthTSyn_ConfigPointer->EthTSynGlobalTimeDomain[timeDomain].EthTSynTimeDomain->EthTSynTimeHardwareCorrectionThreshold) ||
(tmp_Master_to_slave_delay.master_to_slave_delay > (EthTSyn_ConfigPointer->EthTSynGlobalTimeDomain[timeDomain].EthTSynTimeDomain->EthTSynTimeHardwareCorrectionThreshold))){
/* Sync port w.r.t Master */
EthIf_SetCorrectionTime(ctrlIdx, &offset_From_Master, &EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.rateratio);
}
#else
uint8 timeBaseId = EthTSyn_ConfigPointer->EthTSynGlobalTimeDomain[timeDomain].EthTSynSynchronizedTimeBaseRef;
retVal = StbM_GetCurrentTime(timeBaseId, &stbmTimeStamp, &userData );
if(E_OK == retVal){
stbmTime = (sint64)convert_To_NanoSec_Stbm(stbmTimeStamp);
/*lint -e{9033} */
updatedStbmTimeStamp = (uint64)(stbmTime + master_to_slave_delay);
/* Convert as per autosar std format to send it in StbM_BusSetGlobalTime function */
stbmTimeStamp.secondsHi = (uint16)(((uint64)(updatedStbmTimeStamp/1000000000ULL)) >> 32u);
stbmTimeStamp.seconds = (uint32)(updatedStbmTimeStamp/1000000000ULL);
stbmTimeStamp.nanoseconds = (uint32)(updatedStbmTimeStamp % 1000000000ULL);
/* @req 4.2.2/SWS_EthTSyn_00052 */
retVal = StbM_BusSetGlobalTime(timeDomain, &stbmTimeStamp, NULL, TRUE);
(void)retVal;
}
#endif
}
/**
* function to calculate Link delay rate ratio
* @param timeDomain
*/
static void EthTSyn_Internal_ComputeDelay(uint8 timeDomain)
{
/* compute rate ratio */
if(TRUE == EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.initPdelayRespReceived){
computePdelayRateRatio(timeDomain);
computePropTime(timeDomain);
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.isMeasuringDelay = TRUE;
}
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.t4PdelayRespRxTime_old = EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.t4PdelayRespRxTime;
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.t3PdelayRespRxTime_old = EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.t3PdelayRespTime;
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.initPdelayRespReceived = TRUE;
/* compute Link Delay ratio */
/* Check Pdelay Interval */
if(TRUE == EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.pdelayIntervalTimeout){
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.pDelayReq_State = SEND_PDELAY_REQ;
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.pdelayTimerStarted = FALSE;
}
}
static Std_ReturnType EthTSyn_Internal_Transmit_PdelayReq(uint8 timeDomain)
{
Std_ReturnType retValue;
retValue = E_NOT_OK;
if(FALSE == EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.sentPdelayReq){
/* @req 4.2.2/SWS_EthTSyn_00022 */
if(ETHTSYN_TX_ON == EthTSyn_Internal.timeDomain[timeDomain].transmissionMode){
retValue = EthTSyn_Internal_SendPdelayReq(timeDomain);
if(E_OK == retValue){
/* Pdelay Timer has started */
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.pdelayTimerStarted = TRUE;
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.pdelayIntervalTimer = 0;
}
}/* @req 4.2.2/SWS_EthTSyn_00021 */
}else{
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.pDelayReq_State = WAITING_FOR_PDELAY_RESP;
}
return retValue;
}
/**
* state machine to handle Pdelay Req sent and received Pdelay Resp, FUP msg
* @param timeDomain
*/
static void EthTSyn_Internal_PdelayReqStateMachine(uint8 timeDomain)
{
Std_ReturnType retValue;
//retValue = E_NOT_OK;
switch(EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.pDelayReq_State){
case INITIAL_SEND_PDELAY_REQ:
retValue = EthTSyn_Internal_Transmit_PdelayReq(timeDomain);
if(E_OK == retValue){
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.isMeasuringDelay = FALSE;
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.lostResponses = 0;
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.initPdelayRespReceived = FALSE;
}
break;
case SEND_PDELAY_REQ:
retValue = EthTSyn_Internal_Transmit_PdelayReq(timeDomain);
(void)retValue;
break;
case WAITING_FOR_PDELAY_RESP:
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.sentPdelayReq = FALSE; /* reset Pdelay req flag */
if((TRUE == EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.rcvdPdelayResp) &&
(EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.last_pdelay_resp_tx_sequence_number[0] == EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.last_pdelay_req_tx_sequence_number) ){
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.pDelayReq_State = WAITING_FOR_PDELAY_RESP_FOLLOW_UP;
}else if((TRUE == EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.pdelayIntervalTimeout) ||
((TRUE == EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.rcvdPdelayResp) && (EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.last_pdelay_resp_tx_sequence_number[0] != EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.last_pdelay_req_tx_sequence_number) )){
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.pdelayTimerStarted = FALSE;
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.initPdelayRespReceived = FALSE;
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.lostResponses += 1;
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.pDelayReq_State = SEND_PDELAY_REQ;
}else{}
break;
case WAITING_FOR_PDELAY_RESP_FOLLOW_UP:
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.rcvdPdelayResp = FALSE;
if((TRUE == EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.rcvdPdelayRespFollowUp) &&
((EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.last_pdelay_resp_follow_tx_sequence_number[0] == EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.last_pdelay_req_tx_sequence_number))){
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.pDelayReq_State = WAITING_FOR_PDELAY_INTERVAL_TIMER;
}else if((TRUE == EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.pdelayIntervalTimeout) ||
((TRUE == EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.rcvdPdelayRespFollowUp) && ((EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.last_pdelay_resp_follow_tx_sequence_number[0] != EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.last_pdelay_req_tx_sequence_number)))){
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.pdelayTimerStarted = FALSE;
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.initPdelayRespReceived = FALSE;
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.lostResponses += 1;
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.pDelayReq_State = SEND_PDELAY_REQ;
}else{}
break;
case WAITING_FOR_PDELAY_INTERVAL_TIMER: /*@req 4.2.2/SWS_EthTSyn_00004 */
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.rcvdPdelayRespFollowUp = FALSE;
if(TRUE == EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.pdelayIntervalTimeout){
/* compute rate ratio */
EthTSyn_Internal_ComputeDelay(timeDomain);
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.pDelayReq_State = SEND_PDELAY_REQ;
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.pdelayTimerStarted = FALSE;
}
break;
default:
break;
}
}
/**
* state machine to handle Pdelay Resp and follow up msg transimission
* @param timeDomain
*/
static void EthTSyn_Internal_PdelayRespStateMachine(uint8 timeDomain)
{
Std_ReturnType retValue;
uint8 i;
for (i=0; i < ETHTSYN_MAX_PDELAY_REQUEST; i++) {
switch(EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.pDelayResp_State[i]){
case INITIAL_WAITING_FOR_PDELAY_REQ:
if(TRUE == EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.rcvdPdelayReq[i]){
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.pDelayResp_State[i] = SENT_PDELAY_RESP_WAITING;
}
break;
case WAITING_FOR_PDELAY_REQ:
if(TRUE == EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.rcvdPdelayReq[i]){
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.pDelayResp_State[i] = SENT_PDELAY_RESP_WAITING;
}
break;
case SENT_PDELAY_RESP_WAITING:
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.rcvdPdelayReq[i] = FALSE;
if(ETHTSYN_TX_ON == EthTSyn_Internal.timeDomain[timeDomain].transmissionMode){
/* Send Pdelay Resp since Pdelay Req is received */
retValue = EthTSyn_Internal_SendPdelayResp(timeDomain, i);
if(E_OK == retValue){
/* Pdelay Resp FollowUp offset Timer has started */
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.pdelayRespTimerStarted[i] = TRUE;
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.pdelayRespIntervalTimer[i] = 0;
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.pDelayResp_State[i] = SENT_PDELAY_RESP_FOLLOWUP_WAITING;
}else{
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.pDelayResp_State[i] = WAITING_FOR_PDELAY_REQ;
}
}else{
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.pDelayResp_State[i] = WAITING_FOR_PDELAY_REQ;
}
break;
case SENT_PDELAY_RESP_FOLLOWUP_WAITING:
if(ETHTSYN_TX_ON == EthTSyn_Internal.timeDomain[timeDomain].transmissionMode){
if(TRUE == EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.pdelayRespTimeout[i]){
EthTSyn_Internal_SendPdelayRespFollowUp(timeDomain, i);
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.pdelayRespTimeout[i] = FALSE;
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.pDelayResp_State[i] = WAITING_FOR_PDELAY_REQ;
}
}else{
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.pDelayResp_State[i] = WAITING_FOR_PDELAY_REQ;
}
break;
default:
break;
}
}
}
/**
* state machine to handle Sync and Sync follow Up msg transmission
* @param timeDomain
*/
static void EthTSyn_Internal_SyncSendStateMachine(uint8 timeDomain)
{
Std_ReturnType retValue;
switch(EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.syncSend_State){
case SEND_SYNC_MSG:
if(TRUE == EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.syncIntervalTimeout){
retValue = EthTSyn_Internal_SendSync(timeDomain);
if(E_OK == retValue){
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.sentSync = FALSE;
/* Sync Interval timer started */
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.syncIntervalTimerStarted = TRUE;
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.syncIntervalTimer = 0;
/* Follow Up offset started */
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.syncfollowUpTimerStarted = TRUE;
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.syncfollowUpTimer = 0;
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.syncSend_State = SEND_FOLLOW_UP;
}
}
break;
case SEND_FOLLOW_UP:
/* In case of no successful Tx confirmation for sync message and sync interval time out expires
* reset the state to SEND_SYNC_MSG
*/
if ((FALSE == EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.sentSync) &&
(TRUE == EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.syncIntervalTimeout)) {
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.sentSync = FALSE;
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.syncfollowUpTimerStarted = FALSE;
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.syncfollowUpTimerTimeout = FALSE;
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.syncSend_State = SEND_SYNC_MSG;
}
/*@req 4.2.2/SWS_EthTSyn_00018 */
else if((TRUE == EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.sentSync) && (TRUE == EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.syncfollowUpTimerTimeout)){
retValue = EthTSyn_Internal_SendSyncFollowUp(timeDomain);
if(E_OK == retValue){
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.sentSync = FALSE;
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.syncfollowUpTimerStarted = FALSE;
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.syncfollowUpTimerTimeout = FALSE;
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.syncSend_State = SEND_SYNC_MSG;
}else{
if(TRUE == EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.syncIntervalTimeout){
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.syncSend_State = SEND_SYNC_MSG;
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.sentSync = FALSE;
}
}
} else {
/* Do nothing */
}
break;
default:
break;
}
}
/**
* state machine to handle Reception of Sync and Sync follow Up msg
* @param timeDomain
*/
static void EthTSyn_Internal_SyncReceiveStateMachine(uint8 timeDomain)
{
switch(EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.syncReceive_State){
case DISCARD:
if(TRUE == EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.rcvdSync){
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.syncReceive_State = WAITING_FOR_FOLLOW_UP;
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.syncReceivedOnceFlag = TRUE;
}
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.rcvdSync = FALSE;
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.rcvdFollowUp = FALSE;
break;
case WAITING_FOR_FOLLOW_UP:
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.rcvdSync = FALSE;
if((TRUE == EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.rcvdFollowUp)){
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.syncReceive_State = WAITING_FOR_SYNC;
}else if(TRUE == EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.receptionTimeout){
/*@req 4.2.2/SWS_EthTSyn_00025 */
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.syncReceive_State = DISCARD;
}else{}
break;
case WAITING_FOR_SYNC:
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.rcvdFollowUp = FALSE;
if(TRUE == EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.rcvdSync){
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.syncReceive_State = WAITING_FOR_FOLLOW_UP;
}
break;
default:
break;
}
}
/**
* function to calculate rate ratio w.r.t master clock
* @param timeDomain
*/
static void computeRateRatio(uint8 timeDomain)
{
sint64 syncOriginTime_N;
sint64 syncOriginTime_0;
sint64 syncReceiptTime_N;
sint64 syncReceiptTime_0;
sint64 result_1;
sint64 result_2;
EthTSyn_Internal_TimeNanoType IngressTimeStamp;
EthTSyn_Internal_TimeNanoType OriginTimeStamp;
/* convert reception timestamp of Sync msg at slave port into nanoseconds */
syncReceiptTime_N = (sint64)convert_To_NanoSec(EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.t2SyncReceiptTime);
syncReceiptTime_0 = (sint64)convert_To_NanoSec(EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.t2SyncReceiptTime_old);
/* convert origin timestamp of Sync msg at master port into nanoseconds */
syncOriginTime_N = (sint64)convert_To_NanoSec(EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.t1SyncOriginTime);
syncOriginTime_0 = (sint64)convert_To_NanoSec(EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.t1SyncOriginTime_old);
/*Get Ingress time and Engress Time stamp delta*/
result_1 = (syncReceiptTime_N - syncReceiptTime_0);
result_2 = (syncOriginTime_N - syncOriginTime_0);
/* Represent IngressTimeStamp Delta as per AutoSar format */
IngressTimeStamp = absolute(result_1);
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.rateratio.IngressTimeStampDelta.diff.secondsHi = (uint16)(((uint64)(IngressTimeStamp.master_to_slave_delay/1000000000ULL)) >> 32u);
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.rateratio.IngressTimeStampDelta.diff.seconds = (uint32)(IngressTimeStamp.master_to_slave_delay/1000000000ULL);
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.rateratio.IngressTimeStampDelta.diff.nanoseconds = (uint32)(IngressTimeStamp.master_to_slave_delay % 1000000000ULL);
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.rateratio.IngressTimeStampDelta.sign = IngressTimeStamp.sign;
/* Represent OriginTimeStampDelta Delta as per AutoSar format */
OriginTimeStamp = absolute(result_2);
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.rateratio.OriginTimeStampDelta.diff.secondsHi = (uint16)(((uint64)(OriginTimeStamp.master_to_slave_delay/1000000000ULL)) >> 32u);
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.rateratio.OriginTimeStampDelta.diff.seconds = (uint32)(OriginTimeStamp.master_to_slave_delay/1000000000ULL);
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.rateratio.OriginTimeStampDelta.diff.nanoseconds = (uint32)(OriginTimeStamp.master_to_slave_delay % 1000000000ULL);
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.rateratio.OriginTimeStampDelta.sign = OriginTimeStamp.sign;
}
/**
* function to calculate rate ratio w.r.t master clock
* @param timeDomain
*/
static void EthTSyn_Internal_Rate_Ratio(uint8 timeDomain)
{
if(TRUE == EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.initSyncFollowReceived){
computeRateRatio(timeDomain);
}
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.initSyncFollowReceived = TRUE;
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.t1SyncOriginTime_old = EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.t1SyncOriginTime;
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.t2SyncReceiptTime_old = EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.t2SyncReceiptTime;
}
/**
*
*/
/* @req 4.2.2/SWS_EthTSyn_00050 */
void EthTSyn_MainFunction(void){
uint8 timeDomain;
/* @req 4.2.2/SWS_EthTSyn_00046 */
ETHTSYN_DET_REPORTERROR((ETHTSYN_STATE_INIT == EthTSyn_Internal.initStatus), ETHTSYN_MAINFUNCTION_ID, ETHTSYN_E_NOT_INITIALIZED);
for(timeDomain =0 ; timeDomain < EthTSyn_ConfigPointer->EhtTSyn_GlobalTimeDomainCount; timeDomain ++){
if(TRUE == EthTSyn_Internal.timeDomain[timeDomain].trcvActiveStateFlag){
switch(EthTSyn_ConfigPointer->EthTSynGlobalTimeDomain[timeDomain].EthTSynMasterFlag){
case PTP_MASTER:
if(ETHTSYN_TX_ON == EthTSyn_Internal.timeDomain[timeDomain].transmissionMode){
#if (ETHTSYN_SEND_ANNOUNCE_SUPPORT == STD_ON)
Std_ReturnType retValue;
/* Check if it is time to transmit announce message */
if(TRUE == EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.announceIntervalTimeout){
retValue = EthTSyn_Internal_SendAnnounce(timeDomain);
if(E_OK == retValue){
/* Announce Interval timer started */
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.announceIntervalTimerStarted = TRUE;
EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.announceIntervalTimer = 0;
}
} else
#endif
{
/* Transmission - Send Sync and Follow Up msgs */
EthTSyn_Internal_SyncSendStateMachine(timeDomain); /* @req 4.2.2/SWS_EthTSyn_00016 */
}
}
/* Transmission - Pdelay Resp and Follow Up msg*/
EthTSyn_Internal_PdelayRespStateMachine(timeDomain); /* @req 4.2.2/SWS_EthTSyn_00012 */
break;
case PTP_SLAVE: /* @req 4.2.2/SWS_EthTSyn_00023 */
/* Reception of Sync and Follow Up msg */
EthTSyn_Internal_SyncReceiveStateMachine(timeDomain);
if(TRUE == EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.rcvdFollowUp){
EthTSyn_Internal_Rate_Ratio(timeDomain);
}
/* Transmission of Pdelay_Req and Reception of Pdelay_Resp and Pdelay_Resp_Follow_Up msg */
EthTSyn_Internal_PdelayReqStateMachine(timeDomain); /*@req 4.2.2/SWS_EthTSyn_00011 */
/* Sync Correction Calculation */
if(TRUE == EthTSyn_Internal.timeDomain[timeDomain].ptpCfgData.isMeasuringDelay){
synchronize_clock(timeDomain);
}
break;
default:
break;
}
EthTSyn_Internal_UpdateTimer(timeDomain);
}
}
}
#ifdef HOST_TEST
EthTSyn_InternalType* readinternal_EthTsynstatus(void );
EthTSyn_InternalType* readinternal_EthTsynstatus(void)
{
return &EthTSyn_Internal;
}
#endif
|
2301_81045437/classic-platform
|
communication/EthTSyn/src/EthTSyn.c
|
C
|
unknown
| 82,747
|
/*-------------------------------- 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 "EthTSyn.h"
#include "EthTSyn_Internal.h"
#include <string.h>
/* @req 4.2.2/SWS_EthTSyn_00028 */ /* Message format derived from IEEE 802.1As */
extern EthTSyn_InternalType EthTSyn_Internal;
#ifdef HOST_TEST
/*lint -esym(9003, testBuffers) */
EthTsyn_Internal_MsgSync testBuffers[2];
#endif
#define TWO_STEP_CLOCK 2u /* Follow up msg supported */
#define ANNOUNCE_LEAP59 4u /* if the last minute of the current UTC day,
relative to the current grandmaster, contains 59 s, */
#define ANNOUNCE_UTC_OFFSET_VALID 8u /* if currentUtcOffset relative to the current grandmaster,
is known to be correct */
#define TRANSPORT_SPECIFIC (1u << 4u) /* Set transportSpecific = 1 for 802.1AS */
extern const EthTSyn_ConfigType* EthTSyn_ConfigPointer;
/*lint -save -e572 -e778 -e9032 */
/**
*
* @param bufPtr
* @param timedomain
*/
void EthTSyn_Internal_MsgPackPdelayReqMsg(EthTsyn_Internal_MsgPDelayReq *bufPtr, uint8 timedomain)
{
/* PTP Header */
memset(bufPtr, 0, V2_PDELAY_REQ_LENGTH); /* Reset packet to all zeros */
/* Message type, length, flags, Sequence, Control, log mean message interval */
bufPtr->headerMsg.transportSpecificAndMessageType = TRANSPORT_SPECIFIC; /* Set transportSpecific = 1 and Clear previous Message type */
bufPtr->headerMsg.transportSpecificAndMessageType |= V2_PDELAY_REQ_MESSAGE;
bufPtr->headerMsg.reserved1AndVersionPTP = V2_VERSION_PTP;
bufPtr->headerMsg.messageLength = ETHTSYN_HEADER_PDELAY_REQ_LENGTH_BE;
memcpy(bufPtr->headerMsg.sourcePortId.clockIdentity, EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.port_clock_identity, CLOCK_IDENTITY_LENGTH);
bufPtr->headerMsg.sourcePortId.portNumber = ETHTSYN_HEADER_DEFAULT_PORT_NUMBER_BE; /* Ordinary clock so its 1 */
bufPtr->headerMsg.sequenceId = bswap16(EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.last_pdelay_req_tx_sequence_number) ;
bufPtr->headerMsg.control = V2_ALL_OTHERS_CONTROL;
bufPtr->headerMsg.logMeanMessageInterval = LOGMEAN_PDELAY_REQ;
#ifdef HOST_TEST
memcpy(&testBuffers[0], bufPtr, V2_PDELAY_REQ_LENGTH);
#endif
}
/**
*
* @param bufPtr
* @param timedomain
* @param req_index
*/
void EthTSyn_Internal_MsgPackPdelayRespMsg(EthTsyn_Internal_MsgPDelayResp *bufPtr, uint8 timedomain, uint8 req_index)
{
/* PTP Header */
memset(bufPtr, 0, V2_PDELAY_RESP_LENGTH);/* Reset packet to all zeros */
/* Message type, length, flags, Sequence, Control, log mean message interval */
bufPtr->headerMsg.transportSpecificAndMessageType = TRANSPORT_SPECIFIC; /* Set transportSpecific = 1 and Clear previous Message type */
bufPtr->headerMsg.transportSpecificAndMessageType |= V2_PDELAY_RESP_MESSAGE;
bufPtr->headerMsg.reserved1AndVersionPTP = V2_VERSION_PTP;
bufPtr->headerMsg.messageLength = ETHTSYN_HEADER_PDELAY_RESP_LENGTH_BE;
bufPtr->headerMsg.flags[0] = TWO_STEP_CLOCK;
memcpy(bufPtr->headerMsg.sourcePortId.clockIdentity, EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.port_clock_identity, CLOCK_IDENTITY_LENGTH);
bufPtr->headerMsg.sourcePortId.portNumber = ETHTSYN_HEADER_DEFAULT_PORT_NUMBER_BE; /* Ordinary clock so its 1 */
bufPtr->headerMsg.sequenceId = bswap16(EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.last_pdelay_resp_tx_sequence_number[req_index]);
bufPtr->headerMsg.control = V2_ALL_OTHERS_CONTROL;
bufPtr->headerMsg.logMeanMessageInterval = LOGMEAN_PDELAY_RESP;
bufPtr->receiveTimestamp.nanoseconds = bswap32(EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.t2PdelayReqRxTime[req_index].nanoseconds);
bufPtr->receiveTimestamp.seconds = bswap32(EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.t2PdelayReqRxTime[req_index].seconds);
bufPtr->receiveTimestamp.secondsHi = bswap16(EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.t2PdelayReqRxTime[req_index].secondsHi);
memcpy(bufPtr->requestingPortId.clockIdentity, EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.requestingPortIdentity[req_index].clockIdentity,CLOCK_IDENTITY_LENGTH);
bufPtr->requestingPortId.portNumber = bswap16(EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.requestingPortIdentity[req_index].portNumber);
#ifdef HOST_TEST
memcpy(&testBuffers[0], bufPtr, V2_PDELAY_RESP_LENGTH);
#endif
}
/**
*
* @param bufPtr
* @param timedomain
* @param req_index
*/
void EthTSyn_Internal_MsgPackPdelayRespFollowUpMsg(EthTsyn_Internal_MsgPDelayRespFollowUp *bufPtr, uint8 timedomain, uint8 req_index)
{
/* PTP Header */
memset(bufPtr, 0, V2_PDELAY_RESP_FOLLOWUP_LENGTH);/* Reset packet to all zeros */
/* Message type, length, flags, Sequence, Control, log mean message interval */
bufPtr->headerMsg.transportSpecificAndMessageType = TRANSPORT_SPECIFIC; /* Set transportSpecific = 1 and Clear previous Message type */
bufPtr->headerMsg.transportSpecificAndMessageType |= V2_PDELAY_RESP_FOLLOWUP_MESSAGE;
bufPtr->headerMsg.reserved1AndVersionPTP = V2_VERSION_PTP;
bufPtr->headerMsg.messageLength = ETHTSYN_HEADER_PDELAY_RESP_FOLLOWUP_LENGTH_BE;
memcpy(bufPtr->headerMsg.sourcePortId.clockIdentity, EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.port_clock_identity, CLOCK_IDENTITY_LENGTH);
bufPtr->headerMsg.sourcePortId.portNumber = ETHTSYN_HEADER_DEFAULT_PORT_NUMBER_BE; /* Ordinary clock so its 1 */
bufPtr->headerMsg.sequenceId = bswap16(EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.last_pdelay_resp_tx_sequence_number[req_index]);
bufPtr->headerMsg.control = V2_ALL_OTHERS_CONTROL;
bufPtr->headerMsg.logMeanMessageInterval = LOGMEAN_PDELAY_RESP_FOLLOWUP;
bufPtr->responseOriginTimestamp.nanoseconds = bswap32(EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.t3PdelayRespTxTime[req_index].nanoseconds);
bufPtr->responseOriginTimestamp.seconds = bswap32(EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.t3PdelayRespTxTime[req_index].seconds);
bufPtr->responseOriginTimestamp.secondsHi = bswap16(EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.t3PdelayRespTxTime[req_index].secondsHi);
memcpy(bufPtr->requestingPortId.clockIdentity, EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.requestingPortIdentity[req_index].clockIdentity,CLOCK_IDENTITY_LENGTH);
bufPtr->requestingPortId.portNumber = bswap16(EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.requestingPortIdentity[req_index].portNumber);
#ifdef HOST_TEST
memcpy(&testBuffers[0], bufPtr, V2_PDELAY_RESP_FOLLOWUP_LENGTH);
#endif
}
/**
*
* @param bufPtr
* @param timedomain
*/
void EthTSyn_Internal_MsgPackSyncMsg( EthTsyn_Internal_MsgSync *bufPtr, uint8 timedomain)
{
/* PTP Header */
memset(bufPtr, 0, V2_SYNC_LENGTH);/* Reset packet to all zeros */
/* Message type, length, flags, Sequence, Control, log mean message interval */
bufPtr->headerMsg.transportSpecificAndMessageType = TRANSPORT_SPECIFIC; /* Set transportSpecific = 1 and Clear previous Message type */
bufPtr->headerMsg.transportSpecificAndMessageType |= V2_SYNC_MESSAGE;
bufPtr->headerMsg.reserved1AndVersionPTP = V2_VERSION_PTP;
bufPtr->headerMsg.messageLength = ETHTSYN_HEADER_SYNC_LENGTH_BE;
bufPtr->headerMsg.flags[0] = TWO_STEP_CLOCK;
memcpy(bufPtr->headerMsg.sourcePortId.clockIdentity, EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.port_clock_identity, CLOCK_IDENTITY_LENGTH);
bufPtr->headerMsg.sourcePortId.portNumber = ETHTSYN_HEADER_DEFAULT_PORT_NUMBER_BE; /* Ordinary clock so its 1 */
bufPtr->headerMsg.sequenceId = bswap16(EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.last_sync_tx_sequence_number);
bufPtr->headerMsg.control = V2_SYNC_CONTROL;
/* bufPtr->headerMsg.logMeanMessageInterval = (sint8)log2f((float32)((float32)(EthTSyn_ConfigPointer->EthTSynGlobalTimeDomain[i].EthTSynTimeDomain->EthTSynGlobalTimeTxPeriod) * ETHTSYN_MAIN_FUNCTION_PERIOD_LOG)); */ /* Need to check */
bufPtr->headerMsg.logMeanMessageInterval = (sint8)EthTSyn_ConfigPointer->EthTSynGlobalTimeDomain[timedomain].EthTSynTimeDomain->EthTSynGlobalTimeTxPeriod * ETHTSYN_MAIN_FUNCTION_PERIOD_LOG; /* Need to check */
#ifdef HOST_TEST
memcpy(&testBuffers[0], bufPtr, V2_SYNC_LENGTH);
#endif
}
#if (ETHTSYN_SEND_ANNOUNCE_SUPPORT == STD_ON)
/**
*
* @param bufPtr
* @param timedomain
*/
void EthTSyn_Internal_MsgPackAnnounceMsg( EthTsyn_Internal_MsgAnnounce *bufPtr, uint8 timedomain)
{
/* PTP Header */
memset(bufPtr, 0, V2_ANNOUNCE_LENGTH);/* Reset packet to all zeros */
/* Message type, length, flags, Sequence, Control, log mean message interval */
bufPtr->headerMsg.transportSpecificAndMessageType = TRANSPORT_SPECIFIC; /* Set transportSpecific = 1 and Clear previous Message type */
bufPtr->headerMsg.transportSpecificAndMessageType |= V2_ANNOUNCE_MESSAGE;
bufPtr->headerMsg.reserved1AndVersionPTP = V2_VERSION_PTP;
bufPtr->headerMsg.messageLength = bswap16(V2_ANNOUNCE_LENGTH + 4 + V2_CLOCKPATH_TLV_LEN);
bufPtr->headerMsg.flags[1] = (ANNOUNCE_LEAP59 | ANNOUNCE_UTC_OFFSET_VALID);
/*bufPtr->headerMsg.correctionField is left as 0 */
memcpy(bufPtr->headerMsg.sourcePortId.clockIdentity, EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.port_clock_identity, CLOCK_IDENTITY_LENGTH);
bufPtr->headerMsg.sourcePortId.portNumber = ETHTSYN_HEADER_DEFAULT_PORT_NUMBER_BE; /* Ordinary clock so its 1 */
bufPtr->headerMsg.sequenceId = bswap16(EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.last_announce_tx_sequence_number);
bufPtr->headerMsg.control = V2_ALL_OTHERS_CONTROL;
bufPtr->headerMsg.logMeanMessageInterval = (sint8)EthTSyn_ConfigPointer->EthTSynGlobalTimeDomain[timedomain].EthTSynTimeDomain->EthTSynGlobalTimeTxPeriod * ETHTSYN_MAIN_FUNCTION_PERIOD_LOG * 2; /* */
bufPtr->currentUtcOffset = 0;
bufPtr->grandmasterPriority1 = 10; /* May be set 1-255, 255 for a not grandmaster capable system, 0 is for management use. */
bufPtr->grandmasterClockQuality = 0xF8FE4100u; /* Class - 248, Accuracy - 254 and Variance - 16640 */
bufPtr->grandmasterPriority2 = 12; /* May be set 1-255, 255 for a not grandmaster capable system, 0 is for management use. */
memcpy(bufPtr->grandmasterIdentity, EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.port_clock_identity, CLOCK_IDENTITY_LENGTH);
bufPtr->stepsRemoved = 0; /* We assume we are grandmaster capable, else this is the number of links in the path from the root to our network */
bufPtr->timeSource = 0xA0; /* Clock derived from internal oscillator */
bufPtr->clockpath.tlv = bswap16(V2_CLOCKPATH_TLV_ID);
bufPtr->clockpath.length = bswap16(V2_CLOCKPATH_TLV_LEN * 1);
memcpy(bufPtr->clockpath.clockIdentity, EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.port_clock_identity, CLOCK_IDENTITY_LENGTH);
#ifdef HOST_TEST
memcpy(&testBuffers[0], bufPtr, V2_ANNOUNCE_LENGTH);
#endif
}
#endif
/**
*
* @param bufPtr
* @param timedomain
*/
void EthTSyn_Internal_MsgPackSyncFollow(EthTsyn_Internal_MsgFollowUp *bufPtr, uint8 timedomain)
{
/* PTP Header */
memset(bufPtr, 0, V2_FOLLOWUP_LENGTH);/* Reset packet to all zeros */
/* Message type, length, flags, Sequence, Control, log mean message interval */
bufPtr->headerMsg.transportSpecificAndMessageType = TRANSPORT_SPECIFIC; /* Clear previous Message type */
bufPtr->headerMsg.transportSpecificAndMessageType |= V2_FOLLOWUP_MESSAGE;
bufPtr->headerMsg.reserved1AndVersionPTP = V2_VERSION_PTP;
bufPtr->headerMsg.messageLength = ETHTSYN_HEADER_FOLLOWUP_LENGTH_BE;
memcpy(bufPtr->headerMsg.sourcePortId.clockIdentity, EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.port_clock_identity, 8);
bufPtr->headerMsg.sourcePortId.portNumber = ETHTSYN_HEADER_DEFAULT_PORT_NUMBER_BE; /* Ordinary clock so its 1 */
bufPtr->headerMsg.sequenceId = bswap16(EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.last_sync_tx_sequence_number);
bufPtr->headerMsg.control = V2_FOLLOWUP_CONTROL;
/* bufPtr->headerMsg.logMeanMessageInterval = (sint8)log2f((float32)(((float32)EthTSyn_ConfigPointer->EthTSynGlobalTimeDomain[i].EthTSynTimeDomain->EthTSynGlobalTimeTxFollowUpOffset) * ETHTSYN_MAIN_FUNCTION_PERIOD_LOG) ); */ /* Need to check */;
bufPtr->headerMsg.logMeanMessageInterval = (sint8)EthTSyn_ConfigPointer->EthTSynGlobalTimeDomain[timedomain].EthTSynTimeDomain->EthTSynGlobalTimeTxFollowUpOffset * ETHTSYN_MAIN_FUNCTION_PERIOD_LOG;
bufPtr->preciseOriginTimestamp.nanoseconds = bswap32(EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.t1SyncTxTime.nanoseconds) ;
bufPtr->preciseOriginTimestamp.seconds = bswap32(EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.t1SyncTxTime.seconds);
bufPtr->preciseOriginTimestamp.secondsHi = bswap16(EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.t1SyncTxTime.secondsHi);
#ifdef HOST_TEST
memcpy(&testBuffers[0], bufPtr, V2_FOLLOWUP_LENGTH);
#endif
}
/**
*
* @param X
* @return
*/
uint64 convert_To_NanoSec(Eth_TimeStampType X)
{
uint64 result;
uint64 second48;
second48 = ((((uint64)X.secondsHi << 32u)) | X.seconds);
result = (1000000000 * second48) + X.nanoseconds;
return (result);
}
/**
*
* @param X
* @return
*/
uint64 convert_To_NanoSec_Stbm(StbM_TimeStampType X)
{
uint64 result;
uint64 second48;
second48 = ((((uint64)X.secondsHi << 32u)) | X.seconds);
result = (1000000000 * second48) + X.nanoseconds;
return (result);
}
/**
*
* @param value
* @return
*/
EthTSyn_Internal_TimeNanoType absolute(sint64 value) {
EthTSyn_Internal_TimeNanoType tmp_val;
if (value < 0) {
tmp_val.master_to_slave_delay = (uint64)-value;
tmp_val.sign = TRUE;
}
else {
tmp_val.master_to_slave_delay = (uint64)value;
tmp_val.sign = FALSE;
}
return tmp_val;
}
/**
*
* @param timedomain
*/
void EthTSyn_Internal_UpdateTimer(uint8 timedomain)
{
uint8 i;
boolean timerExpire;
/* For the timers started in EthTSyn_MainFunction() context (except RxFollowUpTimer):
* Timeout status is set one main function before than configured threshold by this function.This enables timeout status to be recognized in the next main function.
* Note: EthTSyn_Internal_UpdateTimer() is called at the end of EthTSyn_MainFunction() */
#if (ETHTSYN_SEND_ANNOUNCE_SUPPORT == STD_ON)
/* Announce Interval time counter */
if(TRUE == EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.announceIntervalTimerStarted){
timerExpire = ((EthTSyn_ConfigPointer->EthTSynGlobalTimeDomain[timedomain].EthTSynTimeDomain->EthTSynGlobalTimeTxPeriod == 0) ||
(EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.announceIntervalTimer >= (EthTSyn_ConfigPointer->EthTSynGlobalTimeDomain[timedomain].EthTSynTimeDomain->EthTSynGlobalTimeTxPeriod -1)));
if (FALSE == timerExpire){
EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.announceIntervalTimer++;
EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.announceIntervalTimeout = FALSE;
}else {
EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.announceIntervalTimeout = TRUE;
}
}
#endif
/* Follow Up Timer counter */
if(TRUE == EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.syncfollowUpTimerStarted){
timerExpire = ((EthTSyn_ConfigPointer->EthTSynGlobalTimeDomain[timedomain].EthTSynTimeDomain->EthTSynGlobalTimeTxFollowUpOffset == 0) ||
(EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.syncfollowUpTimer >= (EthTSyn_ConfigPointer->EthTSynGlobalTimeDomain[timedomain].EthTSynTimeDomain->EthTSynGlobalTimeTxFollowUpOffset -1)));
if (FALSE == timerExpire){
EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.syncfollowUpTimer++;
EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.syncfollowUpTimerTimeout = FALSE;
} else {
EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.syncfollowUpTimerTimeout = TRUE;
}
}
/* Sync Interval time counter */
if(TRUE == EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.syncIntervalTimerStarted){
timerExpire = ((EthTSyn_ConfigPointer->EthTSynGlobalTimeDomain[timedomain].EthTSynTimeDomain->EthTSynGlobalTimeTxPeriod == 0) ||
(EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.syncIntervalTimer >= (EthTSyn_ConfigPointer->EthTSynGlobalTimeDomain[timedomain].EthTSynTimeDomain->EthTSynGlobalTimeTxPeriod -1)));
if (FALSE == timerExpire){
EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.syncIntervalTimer++;
EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.syncIntervalTimeout = FALSE;
}else {
EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.syncIntervalTimeout = TRUE;
}
}
/* Reception Timeout counter */
if(TRUE == EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.RxFollowUpTimerStarted){
timerExpire = ((EthTSyn_ConfigPointer->EthTSynGlobalTimeDomain[timedomain].EthTSynGlobalTimeFollowUpTimeout == 0) ||
(EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.RxFollowUpTimer > (EthTSyn_ConfigPointer->EthTSynGlobalTimeDomain[timedomain].EthTSynGlobalTimeFollowUpTimeout - 1)));
if(FALSE == timerExpire){
EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.RxFollowUpTimer++;
EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.receptionTimeout = FALSE;
}else{
EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.receptionTimeout = TRUE;
}
}
/* Pdelay Req interval counter */
if(TRUE == EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.pdelayTimerStarted){
timerExpire = ((EthTSyn_ConfigPointer->EthTSynGlobalTimeDomain[timedomain].EthTSynTimeDomain->EthTSynGlobalTimeTxPdelayReqPeriod == 0) ||
(EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.pdelayIntervalTimer >= (EthTSyn_ConfigPointer->EthTSynGlobalTimeDomain[timedomain].EthTSynTimeDomain->EthTSynGlobalTimeTxPdelayReqPeriod - 1)));
if( FALSE == timerExpire){
EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.pdelayIntervalTimer++;
EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.pdelayIntervalTimeout = FALSE;
}else {
EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.pdelayIntervalTimeout = TRUE;
}
}
for (i = 0; i < ETHTSYN_MAX_PDELAY_REQUEST; i++) {
/* Pdelay Resp interval counter */
if((TRUE == EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.pdelayRespTimerStarted[i])){
timerExpire = ((EthTSyn_ConfigPointer->EthTSynGlobalTimeDomain[timedomain].EthTSynTimeDomain->EthTSynGlobalTimeTxFollowUpOffset == 0)||
(EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.pdelayRespIntervalTimer[i] >= (EthTSyn_ConfigPointer->EthTSynGlobalTimeDomain[timedomain].EthTSynTimeDomain->EthTSynGlobalTimeTxFollowUpOffset-1)));
if(FALSE == timerExpire){
EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.pdelayRespIntervalTimer[i]++;
EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.pdelayRespTimeout[i] = FALSE;
}else {
EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.pdelayRespTimeout[i] = TRUE;
}
}
/* Follow Up Timer counter */
if((TRUE == EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.pdelayRespfollowUpTimerStarted[i])){
timerExpire = ((EthTSyn_ConfigPointer->EthTSynGlobalTimeDomain[timedomain].EthTSynTimeDomain->EthTSynGlobalTimeTxFollowUpOffset == 0) ||
(EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.pdelayRespfollowUpTimer[i] >= (EthTSyn_ConfigPointer->EthTSynGlobalTimeDomain[timedomain].EthTSynTimeDomain->EthTSynGlobalTimeTxFollowUpOffset -1)));
if (FALSE == timerExpire){
EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.pdelayRespfollowUpTimer[i]++;
EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.pdelayRespfollowUpTimerTimeout[i] = FALSE;
} else {
EthTSyn_Internal.timeDomain[timedomain].ptpCfgData.pdelayRespfollowUpTimerTimeout[i] = TRUE;
}
}
}
}
/*lint -restore */
|
2301_81045437/classic-platform
|
communication/EthTSyn/src/EthTSyn_Internal.c
|
C
|
unknown
| 21,437
|
/*-------------------------------- 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 ETHTSYN_INTERNAL_H_
#define ETHTSYN_INTERNAL_H_
#include "EthTSyn_Types.h"
#include "Eth_GeneralTypes.h"
/*lint -e9045 */
#include "math.h"
/* Version 2 control field values */
#define V2_SYNC_CONTROL 0x00u
#define V2_FOLLOWUP_CONTROL 0x02u
#define V2_ALL_OTHERS_CONTROL 0x05u
/* General messages */
#define V2_PDELAY_REQ_LENGTH 54u
#define V2_ANNOUNCE_LENGTH (44u+20u)
#define V2_SYNC_LENGTH 44u
#define V2_FOLLOWUP_LENGTH 44u
#define V2_PDELAY_RESP_LENGTH 54u
#define V2_PDELAY_RESP_FOLLOWUP_LENGTH 54u
/* Event messages */
#define V2_SYNC_MESSAGE 0x0u
#define V2_PDELAY_REQ_MESSAGE 0x2u
#define V2_PDELAY_RESP_MESSAGE 0x3u
/* General messages */
#define V2_FOLLOWUP_MESSAGE 0x8u
#define V2_PDELAY_RESP_FOLLOWUP_MESSAGE 0xAu
#define V2_ANNOUNCE_MESSAGE 0xBu
#define V2_VERSION_PTP 0x02u
#define V2_CLOCKPATH_TLV_ID 0x08u
#define V2_CLOCKPATH_TLV_LEN 0x08u
#define TIME_DOMAIN_0 0u
#define LOGMEAN_PDELAY_REQ 0x7fu
#define LOGMEAN_PDELAY_RESP 0x7fu
#define LOGMEAN_PDELAY_RESP_FOLLOWUP 0x7fu
#define ETH_FRAME_TYPE_TSYN 0x88F7u
#define PTP_UUID_LENGTH 6u
#define CLOCK_IDENTITY_LENGTH 8u
#define V2_TWO_STEP_FLAG 0x02u /* Bit 1 */
#define DEFAULT_PORT_NUMBER 1u
#define ETHTSYN_MAX_PDELAY_REQUEST 6 /* The max number of peer delay requests this implementation will handle */
#if (CPU_BYTE_ORDER == LOW_BYTE_FIRST)
#define bswap32(x) (((uint32)(x) >> 24u) | (((uint32)(x) >> 8u) & 0xff00u) | (((uint32)(x) & 0xff00uL ) << 8u) | (((uint32)(x) & 0xffu) << 24u) )
#define bswap16(x) (((uint16)(x) >> 8u) | (((uint16)(x) & 0xffu) << 8u))
/* General messages */
#define ETHTSYN_HEADER_PDELAY_REQ_LENGTH_BE bswap16(V2_PDELAY_REQ_LENGTH)
#define ETHTSYN_HEADER_SYNC_LENGTH_BE bswap16(V2_SYNC_LENGTH)
#define ETHTSYN_HEADER_ANNOUNCE_LENGTH_BE bswap16(V2_ANNOUNCE_LENGTH)
#define ETHTSYN_HEADER_FOLLOWUP_LENGTH_BE bswap16(V2_FOLLOWUP_LENGTH)
#define ETHTSYN_HEADER_PDELAY_RESP_LENGTH_BE bswap16(V2_PDELAY_RESP_LENGTH)
#define ETHTSYN_HEADER_PDELAY_RESP_FOLLOWUP_LENGTH_BE bswap16(V2_PDELAY_RESP_FOLLOWUP_LENGTH)
#define ETHTSYN_HEADER_DEFAULT_PORT_NUMBER_BE bswap16(DEFAULT_PORT_NUMBER)
#else
#define bswap32(x) (x)
#define bswap16(x) (x)
#define ETHTSYN_HEADER_PDELAY_REQ_LENGTH_BE V2_PDELAY_REQ_LENGTH
#define ETHTSYN_HEADER_SYNC_LENGTH_BE V2_SYNC_LENGTH
#define ETHTSYN_HEADER_ANNOUNCE_LENGTH_BE V2_ANNOUNCE_LENGTH
#define ETHTSYN_HEADER_FOLLOWUP_LENGTH_BE V2_FOLLOWUP_LENGTH
#define ETHTSYN_HEADER_PDELAY_RESP_LENGTH_BE V2_PDELAY_RESP_LENGTH
#define ETHTSYN_HEADER_PDELAY_RESP_FOLLOWUP_LENGTH_BE V2_PDELAY_RESP_FOLLOWUP_LENGTH
#define ETHTSYN_HEADER_DEFAULT_PORT_NUMBER_BE DEFAULT_PORT_NUMBER
#endif
/* Internal type defined for Time Domain */
typedef uint16 EthTSyn_TimeDomainType;
typedef enum {
ETHTSYN_STATE_UNINIT, /* Status of EthTSyn module before EthIf_Init function*/
ETHTSYN_STATE_INIT, /* Status of EthTSyn module after EthIf_Init function called*/
}EthTSyn_Internal_StateType;
typedef struct
{
uint64 master_to_slave_delay; /* path delay */
boolean sign; /* +ve or -ve sign of delay */
}EthTSyn_Internal_TimeNanoType;
typedef struct __attribute__ ((packed))
{
uint8 clockIdentity[CLOCK_IDENTITY_LENGTH]; /* array formed by mapping an IEEE EUI-48 assigned to the time-aware system to IEEE EUI-64 format*/
uint16 portNumber; /* value = 1 for port on a time-aware end station and value = 1.2...n for multiport(bridge)*/
} PortIdentity;
/** IEEE 802.1AS PTP Version 2 common Message header structure */
/* @req 4.2.2/SWS_EthTSyn_00028 */
typedef struct __attribute__ ((packed))
{ // Offset Length (bytes)
uint8 transportSpecificAndMessageType; // 00 1 (2 4-bit fields)
uint8 reserved1AndVersionPTP; // 01 1 (2 4-bit fields)
uint16 messageLength; // 02 2
uint8 domainNumber; // 04 1
uint8 reserved2; // 05 1
uint8 flags[2]; // 06 2
sint64 correctionField; // 08 8
uint32 reserved3; // 16 4
PortIdentity sourcePortId; // 20 10
uint16 sequenceId; // 30 2
uint8 control; // 32 1
sint8 logMeanMessageInterval; // 33 1
} EthTsyn_Internal_MsgHeader;
/** PTP Version 2 Sync message structure */
typedef struct __attribute__ ((packed))
{
EthTsyn_Internal_MsgHeader headerMsg;
uint8 reserved[10];
} EthTsyn_Internal_MsgSync;
/** PTP Version 2 clock path message structure */
typedef struct __attribute__ ((packed))
{
uint16 tlv;
uint16 length;
uint8 clockIdentity[CLOCK_IDENTITY_LENGTH][1];
} EthTsyn_Internal_TlvClockPath;
/** PTP Version 2 Announce message structure */
typedef struct __attribute__ ((packed))
{
EthTsyn_Internal_MsgHeader headerMsg;
uint8 reserved[10];
uint16 currentUtcOffset;
uint8 reserved2;
uint8 grandmasterPriority1;
uint32 grandmasterClockQuality;
uint8 grandmasterPriority2;
uint8 grandmasterIdentity[CLOCK_IDENTITY_LENGTH];
uint16 stepsRemoved;
uint8 timeSource;
EthTsyn_Internal_TlvClockPath clockpath;
} EthTsyn_Internal_MsgAnnounce;
/** PTP Version 2 Follow Up message structure */
typedef struct __attribute__ ((packed))
{
EthTsyn_Internal_MsgHeader headerMsg;
Eth_TimeStampType preciseOriginTimestamp;
} EthTsyn_Internal_MsgFollowUp;
/** PTP Version 2 PDelay Resp message structure */
typedef struct __attribute__ ((packed))
{
EthTsyn_Internal_MsgHeader headerMsg;
Eth_TimeStampType receiveTimestamp;
PortIdentity requestingPortId;
} EthTsyn_Internal_MsgPDelayResp;
/** PTP Version 2 PDelay Req message structure */
typedef struct __attribute__ ((packed))
{
EthTsyn_Internal_MsgHeader headerMsg;
Eth_TimeStampType originTimestamp;
uint8 reserved[10];
} EthTsyn_Internal_MsgPDelayReq;
typedef struct __attribute__ ((packed))
{
EthTsyn_Internal_MsgHeader headerMsg;
Eth_TimeStampType responseOriginTimestamp;
PortIdentity requestingPortId;
} EthTsyn_Internal_MsgPDelayRespFollowUp;
typedef enum{
TXSYNC,
RXSYNC,
TXPDELAY_REQ,
RXPDELAY_REQ,
TXPDELAY_RESP,
RXPDELAY_RESP,
}EthTSyn_Internal_MessageType;
/* State for Sync Transmit */
typedef enum{
SEND_ANNOUNCE_MSG,
SEND_SYNC_MSG,
SEND_FOLLOW_UP,
}EthTSyn_Internal_SyncSend_StateMachineType;
/* states of Pdelay Req */
typedef enum{
INITIAL_SEND_PDELAY_REQ,
SEND_PDELAY_REQ,
WAITING_FOR_PDELAY_RESP,
WAITING_FOR_PDELAY_RESP_FOLLOW_UP,
WAITING_FOR_PDELAY_INTERVAL_TIMER,
}EthTSyn_Internal_Pdelay_StateMachineType;
/* states of Pdelay Resp and FollowUp */
typedef enum{
INITIAL_WAITING_FOR_PDELAY_REQ,
WAITING_FOR_PDELAY_REQ,
SENT_PDELAY_RESP_WAITING,
SENT_PDELAY_RESP_FOLLOWUP_WAITING,
}EthTSyn_Internal_Pdelay_Resp_StateMachineType;
/* states of Sync Receive */
typedef enum{
DISCARD,
WAITING_FOR_FOLLOW_UP,
WAITING_FOR_SYNC,
}EthTSyn_Internal_SyncReceive_StateMachineType;
/** Main program data structure for ptp msgs */
typedef struct {
/* Delay Request mechanism, version 1 and version 2 PTP */
/* Announce, Sync and Follow Up sent related Variable */
EthTSyn_Internal_SyncSend_StateMachineType syncSend_State;
boolean sentSync;
boolean txSyncTimePending;
uint16 last_sync_tx_sequence_number;
uint32 syncIntervalTimer;
boolean syncIntervalTimerStarted;
boolean syncIntervalTimeout;
uint32 syncfollowUpTimer;
boolean syncfollowUpTimerStarted;
boolean syncfollowUpTimerTimeout;
uint16 last_announce_tx_sequence_number;
uint32 announceIntervalTimer;
boolean announceIntervalTimerStarted;
boolean announceIntervalTimeout;
Eth_TimeStampType t1SyncTxTime;
/* Sync and FUP Receive related variable */
EthTSyn_Internal_SyncReceive_StateMachineType syncReceive_State;
boolean rcvdSync;
boolean rcvdFollowUp;
boolean receptionTimeout;
uint16 parent_last_sync_sequence_number;
sint64 syncCorrection; /* Receive Sync correction time */
sint64 followupCorrection; /* Receive Follow up correction time */
boolean waitingForFollow; /* Indicates two step Sync received, waiting for RX follow up */
boolean RxFollowUpTimerStarted;
uint32 RxFollowUpTimer;
Eth_TimeStampType t2SyncReceiptTime; /* Time at slave of inbound SYNC message */
Eth_TimeStampType t2SyncReceiptTime_old; /* Time at slave of inbound SYNC message */
Eth_TimeStampType t1SyncOriginTime; /* Time from master from SYNC */
Eth_TimeStampType t1SyncOriginTime_old; /* Time from master from SYNC */
boolean initSyncFollowReceived;
/* Pdelay Req sent/Receive related variable */
uint8 numPdelay_req;
EthTSyn_Internal_Pdelay_StateMachineType pDelayReq_State;
boolean sentPdelayReq;
uint16 lostResponses;
boolean isMeasuringDelay;
boolean pdelayTimerStarted;
boolean pdelayIntervalTimeout;
uint32 pdelayIntervalTimer;
boolean initPdelayRespReceived;
uint16 last_pdelay_req_tx_sequence_number;
boolean txPdelayReqTimePending;
Eth_TimeStampType t1PdelayReqTxTime; /* Time at requester of outbound PDELAY REQ */
Eth_TimeStampType t2PdelayReqRxTime[ETHTSYN_MAX_PDELAY_REQUEST]; /* Time from responder, reported in PDELAY RESP */
/* Pdelay Resp and FUP sent related variable */
EthTSyn_Internal_Pdelay_Resp_StateMachineType pDelayResp_State[ETHTSYN_MAX_PDELAY_REQUEST];
boolean rcvdPdelayReq[ETHTSYN_MAX_PDELAY_REQUEST];
boolean pdelayRespTimerStarted[ETHTSYN_MAX_PDELAY_REQUEST];
boolean pdelayRespTimeout[ETHTSYN_MAX_PDELAY_REQUEST];
uint32 pdelayRespIntervalTimer[ETHTSYN_MAX_PDELAY_REQUEST];
boolean txPdelayRespTimePending[ETHTSYN_MAX_PDELAY_REQUEST];
Eth_TimeStampType t3PdelayRespTxTime[ETHTSYN_MAX_PDELAY_REQUEST]; /* Time from responder, reported in PDELAY RESP FOLLOWUP */
uint32 pdelayRespfollowUpTimer[ETHTSYN_MAX_PDELAY_REQUEST];
boolean pdelayRespfollowUpTimerStarted[ETHTSYN_MAX_PDELAY_REQUEST];
boolean pdelayRespfollowUpTimerTimeout[ETHTSYN_MAX_PDELAY_REQUEST];
/* Pdelay Resp and FUP receive related variable */
boolean rcvdPdelayResp;
boolean rcvdPdelayRespFollowUp;
uint16 last_pdelay_resp_tx_sequence_number[ETHTSYN_MAX_PDELAY_REQUEST];
uint16 last_pdelay_resp_follow_tx_sequence_number[ETHTSYN_MAX_PDELAY_REQUEST];
PortIdentity requestingPortIdentity[ETHTSYN_MAX_PDELAY_REQUEST];
Eth_TimeStampType t2PdelayRespTime[ETHTSYN_MAX_PDELAY_REQUEST]; /* check! Time at responder of inbound of PDELAY REQ*/
Eth_TimeStampType t3PdelayRespTime; /* Time from responder, reported in PDELAY RESP FOLLOWUP */
Eth_TimeStampType t3PdelayRespRxTime_old; /* Time from responder, reported in PDELAY RESP FOLLOWUP */
Eth_TimeStampType t4PdelayRespRxTime; /* Time at requester */
Eth_TimeStampType t4PdelayRespRxTime_old; /* Time at requester */
/* General Variables */
sint64 peer_mean_path_delay;
boolean txTime_pending; /* Added to poll for HW transmit time */
uint8 msg_type;
boolean neighborRateRatioValid;
sint64 neighborRateRatio;
Eth_RateRatioType rateratio;
uint8 port_clock_identity[8]; /* V2 uses EUI-64 */
uint8 port_uuid_field[PTP_UUID_LENGTH];
boolean syncReceivedOnceFlag;
}EthTSyn_Internal_Ptp_Cfg;
typedef struct {
EthTSyn_TransmissionModeType transmissionMode; /* var to hold on/off of transmission */
boolean trcvActiveStateFlag;
EthTSyn_Internal_Ptp_Cfg ptpCfgData;
}EthTSyn_Internal_DomainType;
typedef struct {
EthTSyn_Internal_StateType initStatus; /* variable to hold EthTSyn module status */
EthTSyn_Internal_DomainType* timeDomain;
}EthTSyn_InternalType;
void EthTSyn_Internal_MsgPackSyncMsg(EthTsyn_Internal_MsgSync *bufPtr, uint8 timedomain);
void EthTSyn_Internal_MsgPackAnnounceMsg(EthTsyn_Internal_MsgAnnounce *bufPtr, uint8 timedomain);
void EthTSyn_Internal_MsgPackSyncFollow(EthTsyn_Internal_MsgFollowUp *bufPtr, uint8 timedomain);
void EthTSyn_Internal_MsgPackPdelayReqMsg(EthTsyn_Internal_MsgPDelayReq *bufPtr, uint8 timedomain);
void EthTSyn_Internal_MsgPackPdelayRespMsg(EthTsyn_Internal_MsgPDelayResp *bufPtr, uint8 timedomain, uint8 index);
void EthTSyn_Internal_MsgPackPdelayRespFollowUpMsg(EthTsyn_Internal_MsgPDelayRespFollowUp *bufPtr, uint8 timedomain, uint8 index);
void EthTSyn_Internal_UpdateTimer(uint8 timedomain);
uint64 convert_To_NanoSec(Eth_TimeStampType X);
uint64 convert_To_NanoSec_Stbm(StbM_TimeStampType X);
EthTSyn_Internal_TimeNanoType absolute(sint64 value);
#endif /* ETHTSYN_INTERNAL_H_ */
|
2301_81045437/classic-platform
|
communication/EthTSyn/src/EthTSyn_Internal.h
|
C
|
unknown
| 14,543
|
/*-------------------------------- 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 ETHTRCV_H_
#define ETHTRCV_H_
#include "EthTrcv_Types.h"
#include "EthTrcv_MemMap.h"
void EthTrcv_Init( const EthTrcv_ConfigType* CfgPtr );
Std_ReturnType EthTrcv_TransceiverInit( uint8 TrcvIdx, uint8 CfgIdx );
Std_ReturnType EthTrcv_SetTransceiverMode( uint8 TrcvIdx, EthTrcv_ModeType CtrlMode );
Std_ReturnType EthTrcv_GetTransceiverMode( uint8 TrcvIdx, EthTrcv_ModeType* TrcvModePtr );
Std_ReturnType EthTrcv_StartAutoNegotiation( uint8 TrcvIdx );
Std_ReturnType EthTrcv_GetLinkState( uint8 TrcvIdx, EthTrcv_LinkStateType* LinkStatePtr );
Std_ReturnType EthTrcv_GetBaudRate( uint8 TrcvIdx, EthTrcv_BaudRateType* BaudRatePtr );
Std_ReturnType EthTrcv_GetDuplexMode( uint8 TrcvIdx, EthTrcv_DuplexModeType* DuplexModePtr );
void EthTrcv_GetVersionInfo( Std_VersionInfoType* VersionInfoPtr );
#endif /* ETHTRCV_H_ */
|
2301_81045437/classic-platform
|
communication/EthTrcv/inc/EthTrcv.h
|
C
|
unknown
| 1,596
|
/*-------------------------------- 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 ETHTRCV_TYPES_H_
#define ETHTRCV_TYPES_H_
#include "Eth_GeneralTypes.h"
#if 0 /* Not available */
#include "EthTrcv_Cfg.h"
#endif
#endif /* ETHTRCV_TYPES_H_ */
|
2301_81045437/classic-platform
|
communication/EthTrcv/inc/EthTrcv_Types.h
|
C
|
unknown
| 935
|
/*-------------------------------- 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 "SchM_EthTrcv.h"
#include "EthTrcv.h"
#include "Det.h"
#include "Dem.h"
#include "EthTrcv_MemMap.h"
void EthTrcv_Init( const EthTrcv_ConfigType* CfgPtr );
Std_ReturnType EthTrcv_TransceiverInit( uint8 TrcvIdx, uint8 CfgIdx );
Std_ReturnType EthTrcv_SetTransceiverMode( uint8 TrcvIdx, EthTrcv_ModeType CtrlMode );
Std_ReturnType EthTrcv_GetTransceiverMode( uint8 TrcvIdx, EthTrcv_ModeType* TrcvModePtr );
Std_ReturnType EthTrcv_StartAutoNegotiation( uint8 TrcvIdx );
Std_ReturnType EthTrcv_GetLinkState( uint8 TrcvIdx, EthTrcv_LinkStateType* LinkStatePtr );
Std_ReturnType EthTrcv_GetBaudRate( uint8 TrcvIdx, EthTrcv_BaudRateType* BaudRatePtr );
Std_ReturnType EthTrcv_GetDuplexMode( uint8 TrcvIdx, EthTrcv_DuplexModeType* DuplexModePtr );
void EthTrcv_GetVersionInfo( Std_VersionInfoType* VersionInfoPtr );
|
2301_81045437/classic-platform
|
communication/EthTrcv/src/EthTrcv.c
|
C
|
unknown
| 1,582
|
#FrIf
obj-$(USE_FRIF) += FrIf.o
obj-$(USE_FRIF) += FrIf_Cfg.o
obj-$(USE_FRIF) += FrIf_Lcfg.o
obj-$(USE_FRIF) += FrIf_PBcfg.o
obj-$(USE_FRIF) += FrIf_Internal.o
vpath-$(USE_FRIF) += $(ROOTDIR)/communication/FrIf/src
inc-$(USE_FRIF) += $(ROOTDIR)/communication/FrIf/inc
|
2301_81045437/classic-platform
|
communication/FrIf/FrIf.mod.mk
|
Makefile
|
unknown
| 280
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
#ifndef FRIF_H_
#define FRIF_H_
/* @req FrIf05140a */ /* Module interface file */
/* @req FrIf05140b */ /* Type definitions and API declarations provided in this file */
/* @req FrIf05141 */ /* Precompile time config is provided by FrIf_Cfg.h */
/* @req FrIf05143 */ /* No global variables defined in header files */
/**
* Includes
*/
#include "Std_Types.h"
#include "ComStack_Types.h" /* @req FrIf05076g */
#include "MemMap.h" /* @req FrIf05076q */ /* @req FrIf05088 */
#include "Fr_GeneralTypes.h" /* @req FrIf05076f */
#include "FrIf_Types.h" /* @req FrIf05076r */
#include "Fr.h"
/**
* Defines and macros
*/
#define IDX_ERROR_UINT8 255
#define PDU_DATA_ENTRIES 256
/* @req FrIf05090 */
#define FRIF_VENDOR_ID 60u
#define FRIF_MODULE_ID 61u
#define FRIF_INSTANCE_ID 0u
/* vendor specific */
#define FRIF_SW_MAJOR_VERSION 2u
#define FRIF_SW_MINOR_VERSION 0u
#define FRIF_SW_PATCH_VERSION 0u
/* compliance with following autosar version */
#define FRIF_AR_MAJOR_VERSION 4u
#define FRIF_AR_MINOR_VERSION 0u
#define FRIF_AR_PATCH_VERSION 3u
#include "FrIf_Cfg.h" /* @req FrIf05076b */
/* API Service ID */
/* Note: The commented defines are not used at the time of writing. Uncomment them to use them. */
#define FRIF_INIT_API_ID 0x02u
#define FRIF_CONTROLLER_INIT_API_ID 0x03u
#define FRIF_START_COMMUNICATION_API_ID 0x04u
#define FRIF_HALT_COMMUNICATION_API_ID 0x05u
#define FRIF_ABORT_COMMUNICATION_API_ID 0x06u
#define FRIF_GET_STATE_API_ID 0x07u
#define FRIF_SET_STATE_API_ID 0x08u
#define FRIF_SET_WUP_CHANNEL_API_ID 0x09u
#define FRIF_SEND_WUP_API_ID 0x0Au
#define FRIF_GET_POC_STATUS_API_ID 0x0Du
#define FRIF_GET_GLOBAL_TIME_API_ID 0x0Eu
#define FRIF_ALLOW_COLD_START_API_ID 0x10u
#define FRIF_GET_MACROTICKS_PER_CYCLE_API_ID 0x11u
#define FRIF_GET_MACROTICKS_DUR_API_ID 0x31u
#define FRIF_TRANSMIT_API_ID 0x12u
#define FRIF_SET_TRCV_MODE_API_ID 0x13u
#define FRIF_GET_TRCV_MODE_API_ID 0x14u
#define FRIF_GET_TRCV_WU_REASON_API_ID 0x15u
#define FRIF_CLR_TRCV_WUP_API_ID 0x18u
#define FRIF_SET_ABSOLUTE_TIMER_API_ID 0x19u
#define FRIF_CANCEL_ABSOLUTE_TIMER_API_ID 0x1Bu
#define FRIF_ENABLE_ABSOLUTE_TIMER_IRQ_API_ID 0x1Du
#define FRIF_ACK_ABSOLUTE_TIMER_IRQ_API_ID 0x21u
#define FRIF_GET_ABSOLUTE_TIMER_IRQ_STATUS_API_ID 0x1Fu
#define FRIF_DISABLE_ABSOLUTE_TIMER_IRQ_API_ID 0x23u
#define FRIF_GET_CYCLE_LENGTH_API_ID 0x3Au
#define FRIF_ALL_SLOTS_API_ID 0x33u
#define FRIF_GET_CHNL_STATUS_API_ID 0x26u
#define FRIF_GET_CLK_CORRECTION_API_ID 0x29u
#define FRIF_GET_SYNC_FRAME_LIST_API_ID 0x2Au
#define FRIF_GET_NUM_STARTUP_FRAMES_API_ID 0x34u
#define FRIF_GET_WUP_RX_STATUS_API_ID 0x2Bu
#define FRIF_CANCEL_TRANSMIT_API_ID 0x30u
#define FRIF_DISABLE_LPDU_API_ID 0x28u
#define FRIF_GET_TRV_ERROR_API_ID 0x35u
#define FRIF_ENABLE_TRCV_BRANCH_API_ID 0x36u
#define FRIF_DISABLE_TRCV_BRANCH_API_ID 0x37u
#define FRIF_RECONFIG_LPDU_API_ID 0x00u
#define FRIF_GET_NM_VECTOR_API_ID 0x0Fu
#define FRIF_GET_VERSION_INFO_API_ID 0x01u
#define FRIF_READ_CC_CONFIG_API_ID 0x3Bu
#define FRIF_JOB_LIST_EXECUTE_API_ID 0x32u
#define FRIF_CHECK_WUP_BY_TRCV_API_ID 0x39u
#define FRIF_MAINFUNCTION_API_ID 0x27u
/* FlexRay Error Codes*/
/* @req FrIf05142 */
/* @req FrIf05145 */
#define FRIF_E_INV_POINTER 0x01u
#define FRIF_E_INV_CTRL_IDX 0x02u
#define FRIF_E_INV_CLST_IDX 0x03u
#define FRIF_E_INV_CHNL_IDX 0x04u
#define FRIF_E_INV_TIMER_IDX 0x05u
#define FRIF_E_INV_TXPDUID 0x06u
#define FRIF_E_INV_LPDU_IDX 0x07u
#define FRIF_E_NOT_INITIALIZED 0x08u
#define FRIF_E_JLE_SYNC 0x09u
#define FRIF_E_INV_FRAME_ID 0x0Bu
/* Channel status information bit mask */
#define CHNL_STATUS_VALID_FRAME 1u
#define CHNL_STATUS_SYNTAX_ERROR 2u
#define CHNL_STATUS_CONTENT_ERROR 4u
#define CHNL_STATUS_ADDITIONAL_COMMUNICATION 8u
#define CHNL_STATUS_B_VIOLATION 16u
#define CHNL_STATUS_TX_CONFLICT 32u
#define CHNL_ACS_ERROR_MASK (CHNL_STATUS_SYNTAX_ERROR|CHNL_STATUS_CONTENT_ERROR|CHNL_STATUS_B_VIOLATION|CHNL_STATUS_TX_CONFLICT)
#define SYMBOL_WINDOW_STATUS_VALID_MTS 256u
#define SYMBOL_WINDOW_STATUS_SYNTAX_ERROR 512u
#define SYMBOL_WINDOW_STATUS_B_VIOLATION 1024u
#define SYMBOL_WINDOW_STATUS_TX_CONFLICT 2048u
#define SW_ERROR_MASK (SYMBOL_WINDOW_STATUS_SYNTAX_ERROR | SYMBOL_WINDOW_STATUS_B_VIOLATION |SYMBOL_WINDOW_STATUS_TX_CONFLICT)
#define NIT_STATUS_SYNTAX_ERROR 4096u
#define NIT_STATUS_B_VIOLATION 8192u
#define NIT_ERROR_MASK (NIT_STATUS_SYNTAX_ERROR | NIT_STATUS_B_VIOLATION)
/* Invalid Dem Event parameter Reference */
#define FRIF_INVALID_DEM_EVENT_ID 0xFFFFu
/**
* Function declarations
*/
extern const FrIf_ConfigType FrIf_Config;
/* @req FrIf05003 */
void FrIf_Init(const FrIf_ConfigType* FrIf_ConfigPtr);
/* @req FrIf05004 */
Std_ReturnType FrIf_ControllerInit(uint8 FrIf_CtrlIdx);
/* @req FrIf05021 */
Std_ReturnType FrIf_SetAbsoluteTimer(uint8 FrIf_CtrlIdx, uint8 FrIf_AbsTimerIdx, uint8 FrIf_Cycle, uint16 FrIf_Offset);
/* @req FrIf05025 */
Std_ReturnType FrIf_EnableAbsoluteTimerIRQ(uint8 FrIf_CtrlIdx, uint8 FrIf_AbsTimerIdx);
/* @req FrIf05029 */
Std_ReturnType FrIf_AckAbsoluteTimerIRQ(uint8 FrIf_CtrlIdx, uint8 FrIf_AbsTimerIdx);
/* @req FrIf05005 */
Std_ReturnType FrIf_StartCommunication(uint8 FrIf_CtrlIdx);
/* @req FrIf05006 */
Std_ReturnType FrIf_HaltCommunication( uint8 FrIf_CtrlIdx );
/* @req FrIf05007 */
Std_ReturnType FrIf_AbortCommunication( uint8 FrIf_CtrlIdx );
/* @req FrIf05170 */
Std_ReturnType FrIf_GetState( uint8 FrIf_ClstIdx, FrIf_StateType* FrIf_StatePtr );
/* @req FrIf05174 */
Std_ReturnType FrIf_SetState(uint8 FrIf_ClstIdx, FrIf_StateTransitionType FrIf_StateTransition);
/* @req FrIf05010 */
Std_ReturnType FrIf_SetWakeupChannel( uint8 FrIf_CtrlIdx, Fr_ChannelType FrIf_ChnlIdx );
/* @req FrIf05011 */
Std_ReturnType FrIf_SendWUP( uint8 FrIf_CtrlIdx );
/* @req FrIf05014 */
Std_ReturnType FrIf_GetPOCStatus(uint8 FrIf_CtrlIdx, Fr_POCStatusType *FrIf_POCStatusPtr);
/* @req FrIf05015 */
Std_ReturnType FrIf_GetGlobalTime(uint8 FrIf_CtrlIdx, uint8 *FrIf_CyclePtr, uint16 *FrIf_MacroTickPtr);
/* @req FrIf05017 */
Std_ReturnType FrIf_AllowColdstart(uint8 Fr_CtrlIdx);
/* @req FrIf05018 */
uint16 FrIf_GetMacroticksPerCycle(uint8 FrIf_CtrlIdx);
/* @req FrIf05019 */
uint16 FrIf_GetMacrotickDuration( uint8 FrIf_CtrlIdx );
/* @req FrIf05033 */
Std_ReturnType FrIf_Transmit(PduIdType FrIf_TxPduId, const PduInfoType *FrIf_PduInfoPtr);
/* !req FrIf05034 */
Std_ReturnType FrIf_SetTransceiverMode( uint8 FrIf_CtrlIdx, Fr_ChannelType FrIf_ChnlIdx, FrTrcv_TrcvModeType FrIf_TrcvMode );
/* !req FrIf05035 */
Std_ReturnType FrIf_GetTransceiverMode( uint8 FrIf_CtrlIdx, Fr_ChannelType FrIf_ChnlIdx, FrTrcv_TrcvModeType* FrIf_TrcvModePtr );
/* !req FrIf05036 */
Std_ReturnType FrIf_GetTransceiverWUReason( uint8 FrIf_CtrlIdx, Fr_ChannelType FrIf_ChnlIdx, FrTrcv_TrcvWUReasonType* FrIf_TrcvWUReasonPtr );
/* !req FrIf05039 */
Std_ReturnType FrIf_ClearTransceiverWakeup( uint8 FrIf_CtrlIdx, Fr_ChannelType FrIf_ChnlIdx );
/* @req FrIf05023 */
Std_ReturnType FrIf_CancelAbsoluteTimer( uint8 FrIf_CtrlIdx, uint8 FrIf_AbsTimerIdx );
/* @req FrIf05027 */
Std_ReturnType FrIf_GetAbsoluteTimerIRQStatus( uint8 FrIf_CtrlIdx, uint8 FrIf_AbsTimerIdx, boolean* FrIf_IRQStatusPtr );
/* @req FrIf05031 */
Std_ReturnType FrIf_DisableAbsoluteTimerIRQ(uint8 FrIf_CtrlIdx, uint8 FrIf_AbsTimerIdx);
/* @req FrIf05239 */
uint32 FrIf_GetCycleLength( uint8 FrIf_CtrlIdx );
/** Optional APIs */
/* @req FrIf05412 */
#if (FRIF_ALL_SLOTS_SUPPORT == STD_ON)
/* @req FrIf05020 */
Std_ReturnType FrIf_AllSlots( uint8 FrIf_CtrlIdx );
#endif
/* @req FrIf05413 */
#if (FRIF_GET_CHNL_STATUS_SUPPORT == STD_ON)
/* @req FrIf05030 */
Std_ReturnType FrIf_GetChannelStatus( uint8 FrIf_CtrlIdx, uint16* FrIf_ChannelAStatusPtr, uint16* FrIf_ChannelBStatusPtr );
#endif
/* @req FrIf05414 */
#if (FRIF_GET_CLK_CORRECTION_SUPPORT == STD_ON)
/* @req FrIf05071 */
Std_ReturnType FrIf_GetClockCorrection( uint8 FrIf_CtrlIdx, sint16* FrIf_RateCorrectionPtr, sint32* FrIf_OffsetCorrectionPtr );
#endif
/* @req FrIf05415 */
#if (FRIF_GET_SYNC_FRAME_LIST_SUPPORT == STD_ON)
/* @req FrIf05072 */
Std_ReturnType FrIf_GetSyncFrameList( uint8 FrIf_CtrlIdx, uint8 FrIf_ListSize, uint16* FrIf_ChannelAEvenListPtr, uint16* FrIf_ChannelBEvenListPtr, uint16* FrIf_ChannelAOddListPtr, uint16* FrIf_ChannelBOddListPtr );
#endif
/* @req FrIf05416 */
#if (FRIF_GET_NUM_STARTUP_FRAMES_SUPPORT == STD_ON)
/* @req FrIf05073 */
Std_ReturnType FrIf_GetNumOfStartupFrames( uint8 FrIf_CtrlIdx, uint8* FrIf_NumOfStartupFramesPtr );
#endif
/* @req FrIf05417 */
#if (FRIF_GET_WUP_RX_STATUS_SUPPORT == STD_ON)
/* @req FrIf05102 */
Std_ReturnType FrIf_GetWakeupRxStatus( uint8 FrIf_CtrlIdx, uint8* FrIf_WakeupRxStatusPtr );
#endif
/* @req FrIf05713 */
#if (FRIF_CANCEL_TRANSMIT_SUPPORT == STD_ON)
/* !req FrIf05070 */
Std_ReturnType FrIf_CancelTransmit( PduIdType FrIf_TxPduId );
#endif
/* @req FrIf05418 */
#if (FRIF_DISABLE_LPDU_SUPPORT == STD_ON)
/* @req FrIf05710 */
Std_ReturnType FrIf_DisableLPdu( uint8 FrIf_CtrlIdx, uint16 FrIf_LPduIdx );
#endif
/* @req FrIf05419 */
#if (FRIF_GET_TRCV_ERROR_SUPPORT == STD_ON)
/* !req FrIf05032 */
Std_ReturnType FrIf_GetTransceiverError( uint8 FrIf_CtrlIdx, Fr_ChannelType FrIf_ChnlIdx, uint8 FrIf_BranchIdx, uint32* FrIf_BusErrorState );
#endif
/* @req FrIf05420 */
#if (FRIF_ENABLE_TRCV_BRANCH_SUPPORT == STD_ON)
/* !req FrIf05085 */
Std_ReturnType FrIf_EnableTransceiverBranch( uint8 FrIf_CtrlIdx, Fr_ChannelType FrIf_ChnlIdx, uint8 FrIf_BranchIdx );
#endif
/* @req FrIf05421 */
/* @req FrIf05425 */
#if (FRIF_DIABLE_TRCV_BRANCH_SUPPORT == STD_ON)
/* !req FrIf05028 */
Std_ReturnType FrIf_DisableTransceiverBranch( uint8 FrIf_CtrlIdx, Fr_ChannelType FrIf_ChnlIdx, uint8 FrIf_BranchIdx );
#endif
/* @req FrIf05422 */
#if (FRIF_RECONFIG_LPDU_SUPPORT == STD_ON)
/* @req FrIf05048 */
Std_ReturnType FrIf_ReconfigLPdu( uint8 FrIf_CtrlIdx, uint16 FrIf_LPduIdx, uint16 FrIf_FrameId, Fr_ChannelType FrIf_ChnlIdx,
uint8 FrIf_CycleRepetition, uint8 FrIf_CycleOffset, uint8 FrIf_PayloadLength, uint16 FrIf_HeaderCRC);
#endif
/* @req FrIf05423 */
#if (FRIF_GET_NM_VECTOR_SUPPORT == STD_ON)
/* !req FrIf05016 */
Std_ReturnType FrIf_GetNmVector( uint8 FrIf_CtrlIdx, uint8* FrIf_NmVectorPtr );
#endif
/* @req FrIf05153 */
#if (FRIF_VERSION_INFO_API == STD_ON)
/* @req FrIf05002 */
void FrIf_GetVersionInfo( Std_VersionInfoType* FrIf_VersionInfoPtr );
#endif
/* @req FrIf05313 */
Std_ReturnType FrIf_ReadCCConfig( uint8 FrIf_CtrlIdx, uint8 FrIf_ConfigParamIdx, uint32* FrIf_ConfigParamValuePtr );
/* !req FrIf05041 */
void FrIf_CheckWakeupByTransceiver( uint8 FrIf_CtrlIdx, Fr_ChannelType FrIf_ChnlIdx );
void FrIf_JobListExec(uint8 clstrIdx);
void FrIf_MainFunction(uint8 clstrIdx);
#endif /* FRIF_H_ */
|
2301_81045437/classic-platform
|
communication/FrIf/inc/FrIf.h
|
C
|
unknown
| 12,693
|
/*-------------------------------- 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 FRIF_TYPES_H_
#define FRIF_TYPES_H_
#if defined(USE_DEM)
#include "Dem.h"
#endif
#define FRIF_NO_FUNCTION_CALLOUT 0xFFu
/* @req FrIf05082 */ /* FrIf_camelCase naming convention used for types */
typedef enum {
PDU_OUTDATED,
PDU_UPDATED
} FrIf_PduUpdateBitType; /* Pdu status */
typedef enum {
T100NS = 1,
T200NS = 2,
T400NS = 4
} FrIf_BitTimeType; /* Bit timing type */
typedef enum {
FRIF_CHANNEL_A = FR_CHANNEL_A,
FRIF_CHANNEL_B = FR_CHANNEL_B,
FRIF_CHANNEL_AB = FR_CHANNEL_AB
} FrIf_ChannelType; /* FrIf channel types */
typedef enum {
T12_5NS = 12,
T25NS = 25,
T50NS = 50
} FrIf_ClockPeriodType; /* Clock period */
typedef enum {
DECOUPLED_TRANSMISSION,
PREPARE_LPDU,
RECEIVE_AND_INDICATE,
RECEIVE_AND_STORE,
RX_INDICATION,
TX_CONFIRMATION,
FREE_OP_A,
FREE_OP_B
} FrIf_CommunicationActionType; /* Job communication action */
typedef enum {
FRIF_BIG_ENDIAN,
FRIF_LITTLE_ENDIAN
} FrIf_ByteOrderType; /* Byte order */
/* Function pointers */
typedef void (*FrIf_RxIndicationType)(PduIdType pduId , PduInfoType* pduInfo);
typedef Std_ReturnType (*FrIf_TriggerTransmitType)(PduIdType pduId, PduInfoType* pduInfo);
typedef void (*FrIf_TxConfirmationType)(PduIdType pduId);
/**
* Structs
*/
#if 0
typedef struct {
FrIf_ChannelType FrIf_ClusterChannel;
const FrTrcvChannel * FrIf_FrTrcvChannelPtr;
} FrIf_TransceiverType;
#endif
/** FrIf Immediate TxPdu config */
typedef struct {
uint8 FrIf_FrCtrlIdx; /* Fr controller index */
uint16 Fr_Buffer; /* Reference to driver buffer */
}FrIf_ImmediateTxPduCfgType;
/** FrIfTxPdu container config structure */
typedef struct {
uint8 FrIf_UserTriggerTransmitHandle; /* Callback handle for TriggerTransmit */
uint8 FrIf_TxConfirmationHandle; /* Callback handle for transmit confirmation */
uint8 FrIf_TxLength; /* Transmit Pdu length */
uint8 FrIf_CounterLimit; /* Maximum limit of indication of ready PDU data to FrIf */
boolean FrIf_Confirm; /* Confirmation enabled or not */
boolean FrIf_Immediate; /* Immediate mode enabled or not */
uint8 FrIf_ImmediateTxCfgIdx; /* Index to immediate Tx configuration */
boolean FrIf_NoneMode; /* None mode set or not */
} FrIf_TxPduType;
/** FrIfRxPdu container config structure */
typedef struct {
uint8 FrIf_RxIndicationHandle; /* Callback handle for receive indication */
uint8 RxPduLength; /* Length of Pdu */
} FrIf_RxPduType;
/** FrIfPduDirection container config structure */
/*lint --e{9018} */
typedef union {
const FrIf_RxPduType * FrIf_RxPduPtr; /* Pointer to either Rx or Tx Pdu config structure */
const FrIf_TxPduType * FrIf_TxPduPtr;
} FrIf_PduDirectionType;
/** FrIPdu config */
typedef struct {
const FrIf_PduDirectionType * FrIf_PduDirectionPtr; /* Maps to one FrIfPduDirection config structure */
PduIdType FrIf_PduId; /* Pdu-Id */
PduIdType FrIf_UpperLayerPduId; /* Pdu Id of the upper layer*/
} FrIf_PduType;
/** FrIfPdusInFrame config structure */
typedef struct {
const FrIf_PduType * FrIf_Pdu; /* Reference to IPdu used by the frame */
sint16 FrIf_PduUpdateBitOffset; /* Update Bit Offset used */
uint8 FrIf_PduOffset; /* Offset of Pdu within the Frame */
} FrIf_PdusIn_FrameType;
/** FrIfFrameStructure config structure */
typedef struct {
const FrIf_PdusIn_FrameType * FrIf_PdusInFramePtr; /* Reference to collection of IPdu composition */
FrIf_ByteOrderType FrIf_ByteOrder; /* Byte Order used */
} FrIf_FrameStructureType;
/** FrIfFrameTriggering config structure*/
typedef struct {
const FrIf_FrameStructureType * FrIf_FrameStructureRef; /* Reference to FrIfFrameStructure */
/* uint16 FrIf_MessageId; Message Id if this Frame is used in a dynamic segment*/
uint16 FrIf_SlotId; /* Slot Id in which this Frame is Tx */
uint16 FrIf_NumberPdusInFrame; /* Number of IPdus part of a frame */
uint16 FrIf_LPduIdx; /* FrIf LPdu index */
uint8 FrIf_LSduLength; /* Total length of the Frame */
uint8 FrIf_BaseCycle; /* Base cycle used to transmit the frame */
uint8 FrIf_CycleRepetition; /* Flexray repetition cycle */
uint8 FrIf_FrameStructureIdx; /* Flexray frame structure index */
FrIf_ChannelType FrIf_Channel; /* Kind of channel on which this frame is transmitted A, B or AB */
/* boolean FrIf_PayloadPreamble; Indicates whether payload preamble is present or not */
/* boolean FrIf_AllowDynamicLSduLength; If dynamic frame length is supported */
boolean FrIf_AlwaysTransmit; /* Whether Fr API needs to be called everytime before transmission */
} FrIf_FrameTriggeringType;
/** FrIfLPdu config structure */
typedef struct {
const FrIf_FrameTriggeringType * FrIf_VBTriggeringRef; /* Reference to FrIfFrameTriggering config structure */
uint16 Fr_Buffer; /* Reference to driver buffer */
boolean FrIf_Reconfigurable; /* Determines whether this LPdu can be configured to map different FrIfFrameTriggering during run time */
} FrIf_LPduType;
/** FrIfController config structure */
typedef struct {
const FrIf_LPduType * FrIf_LpduPtr; /* Pointer to FrIfLPdu */
const FrIf_FrameTriggeringType * FrIf_FrameTriggeringPtr; /* Pointer to FrIfFrameTriggering config structure contained by corresponding controller */
//const FrIf_TransceiverType * FrIf_TransceiverPtr;
uint8 FrIf_FrCtrlIdx; /* Index of Fr controller */
uint8 FrIf_LPduCount; /* No. of LPdus */
uint8 FrIf_CtrlIdx; /* FrIf Ctrl id */
uint8 FrIf_ClstrRefIdx; /* Cluster Id */
} FrIf_ControllerType;
/** FrIfCommunicationOperation config structure */
typedef struct {
const FrIf_LPduType * FrIf_LPduIdxRef; /* Reference to the LPdu */
FrIf_CommunicationActionType FrIf_CommunicationAction; /* Communication Action */
uint16 FrIf_RxComOpMaxLoop; /* Maximum number of loops for receive & indicate */
uint8 FrIf_CtrlIdx; /* FrIf controller index */
uint8 FrIf_FrameConfigIdx; /* Reference to Frame structure */
uint8 FrIf_CommunicationOperationIdx; /* Index defining the order of Flexray communication operation */
} FrIf_CommunicationOperationType;
/** FrIfJob config structure */
typedef struct {
const FrIf_CommunicationOperationType * FrIf_CommunicationOperationPtr; /* Reference to communication operations */
uint32 FrIf_Macrotick; /* Macro tick offset */
uint32 FrIf_NbrOfOperations; /* No. of communication operations executed by the job */
uint8 FrIf_Cycle; /* Cycle in which communication operation is executed */
} FrIf_JobType;
/** FrIfJobList config structure */
typedef struct {
FrIf_JobType const* FrIf_JobPtr; /* Reference to FrIfJobs */
uint8 FrIf_NbrOfJobs; /* Number of FrIfJobs */
uint8 FrIf_FrAbsTimerIdx; /* Index of the Fr Absolute timer */
uint8 FrIf_AbsTimerIdx; /* Index of the FrIf Absolute timer */
} FrIf_JobListType;
#if defined(USE_DEM)
/** Dem Event parameter reference for Cluster */
typedef struct {
Dem_EventIdType FrIf_ACSEventRefChnlA; /* Chnl aggregated Error Chnl A */
Dem_EventIdType FrIf_ACSEventRefChnlB; /* Chnl aggregated Error Chnl B */
Dem_EventIdType FrIf_NITEventRefChnlA; /* NIT Error Chnl A */
Dem_EventIdType FrIf_NITEventRefChnlB; /* NIT Error Chnl B */
Dem_EventIdType FrIf_SWEventRefChnlA; /* Symbol window Error Chnl A */
Dem_EventIdType FrIf_SWEventRefChnlB; /* Symbol window Error Chnl B */
}FrIf_ClusterDemEventParamRefType;
#endif
/** FrIfCluster config structure */
typedef struct {
const FrIf_ControllerType * const * FrIf_ControllerPtr; /* Reference to FrIfControllerConfig structure */
const FrIf_JobListType * FrIf_JobListPtr; /* Reference to FrIfJobList config structure */
#if defined(USE_DEM)
const FrIf_ClusterDemEventParamRefType * FrIf_ClusterDemEventParamRef; /* Reference to FrIfClusterDemEventParameterRefs */
#endif
uint16 FrIf_GMacroPerCycle; /* No of macro ticks in one cycle */
uint32 FrIf_MainFunctionPeriod; /* Cycle time for FrIf main function */
uint32 FrIf_MaxIsrDelay; /* Max delay in macro ticks for execution of ISR job list execution after abs timer was triggered */
uint32 FrIf_GdCycle; /* Length of cycle in seconds*/
uint32 FrIf_GdMacrotick; /* Length of macro tick in seconds */
uint16 FrIf_GNumberOfStaticSlots; /* No. of static slots in static segment */
uint8 FrIf_ClstIdx; /* Cluster index */
uint8 FrIf_ControllerCount; /* No of controllers supported by cluster */
uint8 FrIf_GdStaticSlots; /* Duration of static slot */
/* boolean FrIf_DetectNITError; Indicates whether NIT error status of each cluster shall be detected or not */
/* Fr_ChannelType FrIf_GChannels; Channels used by the cluster */
/* uint8 FrIf_GColdStartAttempts; Maximum attempts by a node to start cluster by schedule synchronization */
/* uint8 FrIf_GCycleCountMax; Maximum cycle counter */
/* uint8 FrIf_GListenNoise; upper limit for startup listen timeout and wake up listen timeout */
/* uint8 FrIf_GMaxWithoutClockCorrectFatal; Threshold used by clockcorrectionfailed counter. Action when this value is reached normal active/passive to halt state*/
/* uint8 FrIf_GMaxWithoutClockCorrectPassive; Threshold used by clockcorrectionfailed counter. Action when this value is reached normal active to normal passive state */
/* uint8 FrIf_GNetworkManagementVectorLength; Length of NM vector length */
/* uint16 FrIf_GNumberOfMinislots; No. of mini slots in dynamic segment */
/* uint8 FrIf_GPayloadLengthStatic; Payload length of a static frame */
/* uint8 FrIf_GSyncFrameIDCountMax; Max number of sync frame Ids in a cluster */
/* uint8 FrIf_GdActionPointOffset; Offset from the beginning of static slot for action point (in macro tick) */
/* FrIf_BitTimeType FrIf_GdBit; Nominal bit time in seconds */
/* uint8 FrIf_GdCasRxLowMax; Upper limit for CAS acceptance window */
/* uint8 FrIf_GdDynamicSlotIdlePhase; Duration of idle phase within a dynamic slot */
/* uint8 FrIf_GdIgnoreAfterTx; Duration for which bit strobing is paused after Tx */
/* uint8 FrIf_GdMiniSlotActionPointOffset; Offset from the beginning of a mini slot for the action point (in macro ticks) */
/* uint8 FrIf_GdMinislot; Duraiton of Mini slot */
/* uint16 FrIf_GdNit; Duration of network idle time */
/* FrIf_ClockPeriodType FrIf_GdSampleClockPeriod; Sample clock period */
/* uint16 FrIf_GdSymbolWindow; Duration of symbol window */
/* uint8 FrIf_GdSymbolWindowActionPointOffset; Offset from the beginning of symbol window for the action poin (in macro tick) */
/* uint8 FrIf_GdTssTransmitter; No of bits in transmit start sequence */
/* uint8 FrIf_GdWakeupRxIdle; No. of bits used by node to test duration of idle or high phase of a received wake up */
/* uint8 FrIf_GdWakeupRxLow; No. of bits used by node to test duration of low phase of a received wake up */
/* uint16 FrIf_GdWakeupRxWindow; The size of window used to detect wakeups */
/* uint8 FrIf_GdWakeupTxActive; No. of bits used by the node to transmit Low phase of a wake up symbol and high and low phases of WUDOP */
/* uint8 FrIf_GdWakeupTxIdle; No. of bits used by the node to transmit idle part of a wake up symbol */
/* uint32 FrIf_SafetyMargin; Additional time span in macro ticks to set joblistpointer to next job when job list execution has been resynchronized */
} FrIf_ClusterType;
/** Function pointers each driver api's, refer to FrIf05079 and FrIf05382*/
typedef struct {
/* Controller Initialization */
Std_ReturnType (*Fr_ControllerInit)(uint8 Fr_CtrlIdx);
/* Communication Initialization */
Std_ReturnType (*Fr_StartCommunication)(uint8 Fr_CtrlIdx);
Std_ReturnType (*Fr_AllowColdstart)(uint8 Fr_CtrlIdx);
/* Transmit/Receive */
Std_ReturnType (*Fr_TransmitTxLPdu)(uint8 Fr_CtrlIdx, uint16 Fr_LPduIdx, const uint8* Fr_LSduPtr, uint8 Fr_LSduLength);
Std_ReturnType (*Fr_ReceiveRxLPdu)(uint8 Fr_CtrlIdx, uint16 Fr_LPduIdx, uint8* Fr_LSduPtr, Fr_RxLPduStatusType* Fr_RxLPduStatusPtr, uint8* Fr_LSduLengthPtr);
Std_ReturnType (*Fr_CheckTxLPduStatus)(uint8 Fr_CtrlIdx, uint16 Fr_LPduIdx, Fr_TxLPduStatusType* Fr_TxLPduStatusPtr);
Std_ReturnType (*Fr_PrepareLPdu)(uint8 Fr_CtrlIdx, uint16 Fr_LPduIdx);
/* Absolute Timers */
Std_ReturnType (*Fr_SetAbsoluteTimer)(uint8 Fr_CtrlIdx, uint8 Fr_AbsTimerIdx, uint8 Fr_Cycle, uint16 Fr_Offset);
Std_ReturnType (*Fr_EnableAbsoluteTimerIRQ)(uint8 Fr_CtrlIdx, uint8 Fr_AbsTimerIdx);
Std_ReturnType (*Fr_AckAbsoluteTimerIRQ)(uint8 Fr_CtrlIdx, uint8 Fr_AbsTimerIdx);
Std_ReturnType (*Fr_DisableAbsoluteTimerIRQ)(uint8 Fr_CtrlIdx, uint8 Fr_AbsTimerIdx);
Std_ReturnType (*Fr_CancelAbsoluteTimer)(uint8 Fr_CtrlIdx, uint8 Fr_AbsTimerIdx);
Std_ReturnType (*Fr_GetAbsoluteTimerIRQStatus)(uint8 Fr_CtrlIdx, uint8 Fr_AbsTimerIdx,boolean* FrIf_IRQStatusPtr);
/* Other */
Std_ReturnType (*Fr_GetGlobalTime)(uint8 Fr_CtrlIdx, uint8* Fr_CyclePtr, uint16* Fr_MacroTickPtr);
Std_ReturnType (*Fr_SetWakeupChannel)(uint8 Fr_CtrlIdx, Fr_ChannelType Fr_ChnlIdx);
Std_ReturnType (*Fr_GetPOCStatus)(uint8 Fr_CtrlIdx, Fr_POCStatusType *Fr_POCStatusPtr);
/* Halt communication */
Std_ReturnType (*Fr_HaltCommunication)(uint8 Fr_CtrlIdx);
/* Abort communication */
Std_ReturnType (*Fr_AbortCommunication)(uint8 Fr_CtrlIdx);
/* Send Wake Up */
Std_ReturnType (*Fr_SendWUP)(uint8 Fr_CtrlIdx);
} FrIf_FrAPIType;
/** Driver config */
typedef struct {
const FrIf_FrAPIType *FrIf_FrAPIPtr; /* this driver's api*/
uint8 FrIf_CCPerDriver; /* No. of CCs handled by a driver */
} FrIf_DriverConfigType;
typedef struct {
const FrIf_ClusterType * FrIf_ClusterPtr; /* Reference to cluster cfg */
const FrIf_ControllerType * FrIf_CtrlPtr; /* Reference to controller cfg */
const FrIf_DriverConfigType * Fr_Driver_ConfigPtr; /* Fr driver cfg */
const FrIf_TxPduType * FrIf_TxPduCfgPtr; /* Reference to Tx Pdu cfg */
const FrIf_RxPduType * FrIf_RxPduCfgPtr; /* Reference to Rx Pdu cfg */
const FrIf_RxIndicationType * FrIf_RxIndicationFncs; /* Reference to Cfg for Rx indication functions */
const FrIf_TriggerTransmitType * FrIf_TriggerTransmitFncs; /* Reference to Cfg for Trigger Tx functions */
const FrIf_TxConfirmationType * FrIf_TxConfirmationFncs; /* Reference to Cfg of Tx confirmation functions */
const FrIf_ImmediateTxPduCfgType * FrIf_ImmediateTxPduCfgPtr; /* Reference to immediate Tx cfg list */
uint8 FrIf_ClusterCount; /* No. of clusters */
uint8 FrIf_CtrlCount; /* No. of controllers */
uint8 FrIf_TxPduCount; /* No. of Tx Pdus */
uint8 FrIf_RxPduCount; /* No. of Rx Pdus */
} FrIf_ConfigType;
#endif /* FRIF_TYPES_H_ */
|
2301_81045437/classic-platform
|
communication/FrIf/inc/FrIf_Types.h
|
C
|
unknown
| 18,111
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/* General requirements tagging */
/* @req FrIf05074 */ /* Dependency on other modules */
/* @req FrIf05150 */ /* source in FrIf.c and precompile time config in FrIf_Cfg.c */
/* @req FrIf05081 */ /* Naming conventions for file FrIf_ */
/* @req FrIf05115 */ /* Two states defined - online & offline */
/* @req FrIf05096 */ /* FrIf executable code shall be independent of CC and Trcv */
/* @req FrIf05078 */ /* Apis should be implemented as C code */
/* @req FrIf05080 */ /* HIS subset MISRA C standard conformance */
/* @req FrIf05089 */ /* A xml file contains vendor specific information. This is a part of our modef */
/* @req FrIf05079 */ /* Generated files are in human readable format */
/* @req FrIf05121 */ /* A Fr frame consists of multiple I-Pdu */
/* @req FrIf05126 */ /* Update bits occupy arbitrary position */
/* @req FrIf05084 */ /* Det error reporting can be configurable */
/* @req FrIf05083 */ /* FrIf_camelCase naming convention used for global variables or Apis */
/* @req FrIf05001 */ /* Imported types used */
/* @req FrIf05043 */ /* Mandatory Fr interfaces */
/* @req FrIf05044 */ /* Optional Apis */
/* @req FrIf05045 */ /* Upper layer indications call-back */
/* @req FrIf05046 */ /* Upper layer tx confirmation call-back*/
/* @req FrIf05047 */ /* Upper layer trigger transmit call-back */
/* @req FrIf05282 */ /* VARIANT-PRE-COMPILE params are precompile time configurable */
/* @req FrIf06117 */ /* Published info */
/* @req FrIf05083 */ /* FrIf_camelCase naming convention used for global variables and Apis */
/* @req FrIf05060 */ /* Zero based index for Fr CC */
/* @req FrIf05053 */ /* Multiple FrIf Ctrl Idx is configurable*/
/* @req FrIf05112 */ /* Multiple FrIf clusters Idx are configurable*/
/* @req FrIf05113 */ /* Atleast one absolute timer is supported */
/* @req FrIf05129 */ /* If immediate transmission is allowed one Pdu per Frame */
/* @req FrIf05052 */ /* Zero based indexing for Fr Ctrl Id & Driver */
/* @req FrIf05077 */ /* configuration parameters are organized as containers with particular multiplicity */
/* @req FrIf05091c */ /* Dem configuration defines the Event Ids */
/* @req FrIf05091d */ /* Dem configuration generates Dem_IntErrId.h */
/* @req FrIf05297 */ /* Detection of production error codes cannot be switched off */
#include <string.h>
#include "Std_Types.h"
#include "FrIf.h"
#include "FrIf_Internal.h"
#include "Fr.h" /* @req FrIf05076d */
#include "PduR_FrIf.h" /* @req FrIf05076h */
/* @req FrIf05065 */
/* @req FrIf05076l */
#if (FRIF_DEV_ERROR_DETECT == STD_ON)
#include "Det.h"
#endif
/* @req FrIf05091a */
/* @req FrIf05091b */
/* @req FrIf05066 */
#if defined(USE_DEM)
#include "Dem.h"
#endif
#if defined (USE_FRNM)
#include "FrNm_Cbk.h" /* @req FrIf05076i */
#endif
#include "SchM_FrIf.h" /* @req FrIf05076m */ /* @req FrIf05087 */
/* pointer to main configuration */
const FrIf_ConfigType *FrIf_ConfigCachePtr;
/* Global runtime parameters */
FrIf_Internal_GlobalType FrIf_Internal_Global;
/** APIs */
/* @req FrIf05003 */
/**
*
* @param FrIf_ConfigPtr
*/
void FrIf_Init(const FrIf_ConfigType* FrIf_ConfigPtr)
{
uint8 txPduCnt;
uint8 i;
/* @req FrIf05155 */
FRIF_DET_REPORTERROR((FrIf_ConfigPtr != NULL),FRIF_INIT_API_ID,FRIF_E_INV_POINTER);
FrIf_ConfigCachePtr = FrIf_ConfigPtr;
/* @req FrIf05156 */
txPduCnt = FrIf_ConfigCachePtr->FrIf_TxPduCount;
for (i = 0; i < txPduCnt; i++) {
FrIf_Internal_Global.txPduStatistics[i].trigTxCounter = 0;
FrIf_Internal_Global.txPduStatistics[i].txConfCounter = 0;
}
for (i = 0; i < FrIf_ConfigCachePtr->FrIf_RxPduCount; i++) {
FrIf_Internal_Global.rxPduStatistics[i].pduUpdated = FALSE;
FrIf_Internal_Global.rxPduStatistics[i].pduRxLen = 0;
}
for (i = 0; i < FrIf_ConfigCachePtr->FrIf_ClusterCount; i++) {
/* @req FrIf05117 */
FrIf_Internal_Global.clstrRunTimeData[i].clstrState = FRIF_STATE_OFFLINE;
FrIf_Internal_Global.clstrRunTimeData[i].jobListCntr = 0;
FrIf_Internal_Global.clstrRunTimeData[i].jobListSyncLost = TRUE;
FrIf_Internal_Global.clstrRunTimeData[i].jobListExecLock = FALSE;
FrIf_Internal_Global.clstrRunTimeData[i].interruptEnableSts = FALSE;
}
memset(FrIf_Internal_Global.lSduBuffer,0,(FRIF_MAX_N_LPDU * FRIF_MAX_LPDU_LEN)); /* Reset LSdu buffer */
FrIf_Internal_Global.initDone = TRUE;
}
/* @req FrIf05004 */
/**
*
* @param FrIf_CtrlIdx
* @return
*/
Std_ReturnType FrIf_ControllerInit(uint8 FrIf_CtrlIdx)
{
uint8 frIdx;
const FrIf_FrAPIType *myFuncPtr;
Std_ReturnType ret;
ret = E_NOT_OK;
/* @req FrIf05298 */
/* @req FrIf05160 */
FRIF_DET_REPORTERROR((TRUE == FrIf_Internal_Global.initDone),FRIF_CONTROLLER_INIT_API_ID,FRIF_E_NOT_INITIALIZED,E_NOT_OK);
/* @req FrIf05158 */
FRIF_DET_REPORTERROR((FrIf_CtrlIdx < FrIf_ConfigCachePtr->FrIf_CtrlCount),FRIF_CONTROLLER_INIT_API_ID,FRIF_E_INV_CTRL_IDX,E_NOT_OK);
/* @req FrIf05159 */
/* 1) translate to Fr idx using FrIf idx */
frIdx = FrIf_ConfigCachePtr->FrIf_CtrlPtr[FrIf_CtrlIdx].FrIf_FrCtrlIdx;
/* 2) locate this driver api*/
myFuncPtr = (FrIf_ConfigCachePtr->Fr_Driver_ConfigPtr[FRIF_DRIVER_0].FrIf_FrAPIPtr);
if (myFuncPtr != NULL) {
/* 3) Call this driver Init-function passing correct config struct */
ret = (*myFuncPtr->Fr_ControllerInit)(frIdx);
}
return ret;
}
/**
*
* @param FrIf_CtrlIdx
* @param FrIf_AbsTimerIdx
* @param FrIf_Cycle
* @param FrIf_Offset
* @return
*/
/* @req FrIf05021 */
Std_ReturnType FrIf_SetAbsoluteTimer(uint8 FrIf_CtrlIdx, uint8 FrIf_AbsTimerIdx, uint8 FrIf_Cycle, uint16 FrIf_Offset)
{
const FrIf_JobListType * jobListCfg;
const FrIf_FrAPIType *myFuncPtr;
uint8 frIdx;
Std_ReturnType ret;
uint8 clstrIdx;
uint8 frAbsTimerIdx;
ret = E_NOT_OK;
/* @req FrIf05298 */
/* @req FrIf05236 */
FRIF_DET_REPORTERROR((TRUE == FrIf_Internal_Global.initDone),FRIF_SET_ABSOLUTE_TIMER_API_ID,FRIF_E_NOT_INITIALIZED,E_NOT_OK);
/* @req FrIf05234 */
FRIF_DET_REPORTERROR((FrIf_CtrlIdx < FrIf_ConfigCachePtr->FrIf_CtrlCount),FRIF_SET_ABSOLUTE_TIMER_API_ID,FRIF_E_INV_CTRL_IDX,E_NOT_OK);
FRIF_DET_REPORTERROR((FrIf_AbsTimerIdx < FRIF_MAX_ABSOLUTE_TIMER),FRIF_SET_ABSOLUTE_TIMER_API_ID,FRIF_E_INV_TIMER_IDX,E_NOT_OK);
/* @req FrIf05235 */
/* 1) translate to Fr idx using FrIf idx */
frIdx = FrIf_ConfigCachePtr->FrIf_CtrlPtr[FrIf_CtrlIdx].FrIf_FrCtrlIdx;
clstrIdx = FrIf_ConfigCachePtr->FrIf_CtrlPtr[FrIf_CtrlIdx].FrIf_ClstrRefIdx;
jobListCfg = FrIf_ConfigCachePtr->FrIf_ClusterPtr[clstrIdx].FrIf_JobListPtr;
FRIF_DET_REPORTERROR((jobListCfg->FrIf_AbsTimerIdx == FrIf_AbsTimerIdx),FRIF_SET_ABSOLUTE_TIMER_API_ID,FRIF_E_INV_TIMER_IDX,E_NOT_OK);
frAbsTimerIdx = jobListCfg->FrIf_FrAbsTimerIdx;
/* 2) locate driver api*/
myFuncPtr = (FrIf_ConfigCachePtr->Fr_Driver_ConfigPtr[FRIF_DRIVER_0].FrIf_FrAPIPtr);
if (myFuncPtr != NULL) {
/* 3) Call this driver set absolute timer api passing correct config struct */
ret = (*myFuncPtr->Fr_SetAbsoluteTimer)(frIdx, frAbsTimerIdx, FrIf_Cycle, FrIf_Offset);
}
return ret;
}
/**
*
* @param FrIf_CtrlIdx
* @param FrIf_AbsTimerIdx
* @return
*/
/* @req FrIf05025 */
Std_ReturnType FrIf_EnableAbsoluteTimerIRQ(uint8 FrIf_CtrlIdx, uint8 FrIf_AbsTimerIdx)
{
const FrIf_JobListType * jobListCfg;
const FrIf_FrAPIType *myFuncPtr;
uint8 frIdx;
Std_ReturnType ret;
uint8 clstrIdx;
uint8 frAbsTimerIdx;
ret = E_NOT_OK;
/* @req FrIf05298 */
/* @req FrIf05248 */
FRIF_DET_REPORTERROR((TRUE == FrIf_Internal_Global.initDone),FRIF_ENABLE_ABSOLUTE_TIMER_IRQ_API_ID,FRIF_E_NOT_INITIALIZED,E_NOT_OK);
/* @req FrIf05246 */
FRIF_DET_REPORTERROR((FrIf_CtrlIdx < FrIf_ConfigCachePtr->FrIf_CtrlCount),FRIF_ENABLE_ABSOLUTE_TIMER_IRQ_API_ID,FRIF_E_INV_CTRL_IDX,E_NOT_OK);
FRIF_DET_REPORTERROR((FrIf_AbsTimerIdx < FRIF_MAX_ABSOLUTE_TIMER),FRIF_ENABLE_ABSOLUTE_TIMER_IRQ_API_ID,FRIF_E_INV_TIMER_IDX,E_NOT_OK);
/* @req FrIf05247 */
/* 1) locate the FrIdx */
frIdx = FrIf_ConfigCachePtr->FrIf_CtrlPtr[FrIf_CtrlIdx].FrIf_FrCtrlIdx;
clstrIdx = FrIf_ConfigCachePtr->FrIf_CtrlPtr[FrIf_CtrlIdx].FrIf_ClstrRefIdx;
jobListCfg = FrIf_ConfigCachePtr->FrIf_ClusterPtr[clstrIdx].FrIf_JobListPtr;
FRIF_DET_REPORTERROR((jobListCfg->FrIf_AbsTimerIdx == FrIf_AbsTimerIdx),FRIF_ENABLE_ABSOLUTE_TIMER_IRQ_API_ID,FRIF_E_INV_TIMER_IDX,E_NOT_OK);
frAbsTimerIdx = jobListCfg->FrIf_FrAbsTimerIdx;
/* Check if interrupts are already enabled */
if (TRUE == FrIf_Internal_Global.clstrRunTimeData[clstrIdx].interruptEnableSts) {
ret = E_OK;
} else {
/* 2) locate driver api*/
myFuncPtr = (FrIf_ConfigCachePtr->Fr_Driver_ConfigPtr[FRIF_DRIVER_0].FrIf_FrAPIPtr);
if (myFuncPtr != NULL) {
/* 3) Call this driver enable absolute timer interrupt api passing correct config struct */
ret = (*myFuncPtr->Fr_EnableAbsoluteTimerIRQ)(frIdx, frAbsTimerIdx);
}
if (E_OK == ret) {
FrIf_Internal_Global.clstrRunTimeData[clstrIdx].interruptEnableSts = TRUE;
}
}
return ret;
}
/**
*
* @param FrIf_CtrlIdx
* @param FrIf_AbsTimerIdx
* @return
*/
/* @req FrIf05029 */
Std_ReturnType FrIf_AckAbsoluteTimerIRQ(uint8 FrIf_CtrlIdx, uint8 FrIf_AbsTimerIdx)
{
const FrIf_JobListType * jobListCfg;
const FrIf_FrAPIType *myFuncPtr;
uint8 frIdx;
Std_ReturnType ret;
uint8 clstrIdx;
uint8 frAbsTimerIdx;
ret = E_NOT_OK;
/* @req FrIf05298 */
/* @req FrIf05260 */
FRIF_DET_REPORTERROR((TRUE == FrIf_Internal_Global.initDone),FRIF_ACK_ABSOLUTE_TIMER_IRQ_API_ID,FRIF_E_NOT_INITIALIZED,E_NOT_OK);
/* @req FrIf05258 */
FRIF_DET_REPORTERROR((FrIf_CtrlIdx < FrIf_ConfigCachePtr->FrIf_CtrlCount),FRIF_ACK_ABSOLUTE_TIMER_IRQ_API_ID,FRIF_E_INV_CTRL_IDX,E_NOT_OK);
FRIF_DET_REPORTERROR((FrIf_AbsTimerIdx < FRIF_MAX_ABSOLUTE_TIMER),FRIF_ACK_ABSOLUTE_TIMER_IRQ_API_ID,FRIF_E_INV_TIMER_IDX,E_NOT_OK);
/* @req FrIf05259 */
/* 1) locate the FrIdx */
frIdx = FrIf_ConfigCachePtr->FrIf_CtrlPtr[FrIf_CtrlIdx].FrIf_FrCtrlIdx;
clstrIdx = FrIf_ConfigCachePtr->FrIf_CtrlPtr[FrIf_CtrlIdx].FrIf_ClstrRefIdx;
jobListCfg = FrIf_ConfigCachePtr->FrIf_ClusterPtr[clstrIdx].FrIf_JobListPtr;
FRIF_DET_REPORTERROR((jobListCfg->FrIf_AbsTimerIdx == FrIf_AbsTimerIdx),FRIF_ACK_ABSOLUTE_TIMER_IRQ_API_ID,FRIF_E_INV_TIMER_IDX,E_NOT_OK);
frAbsTimerIdx = jobListCfg->FrIf_FrAbsTimerIdx;
/* 2) locate this driver api*/
myFuncPtr = (FrIf_ConfigCachePtr->Fr_Driver_ConfigPtr[FRIF_DRIVER_0].FrIf_FrAPIPtr);
if (myFuncPtr != NULL) {
/* 3) Call this driver acknowledge absolute timer interrupt api passing correct config struct */
ret = (*myFuncPtr->Fr_AckAbsoluteTimerIRQ)(frIdx, frAbsTimerIdx);
}
return ret;
}
/* @req FrIf05005 */
/**
*
* @param FrIf_CtrlIdx
* @return
*/
Std_ReturnType FrIf_StartCommunication(uint8 FrIf_CtrlIdx)
{
Std_ReturnType ret;
uint8 frIdx;
const FrIf_FrAPIType *myFuncPtr;
ret = E_NOT_OK;
/* @req FrIf05298 */
/* @req FrIf05163 */
FRIF_DET_REPORTERROR((TRUE == FrIf_Internal_Global.initDone),FRIF_START_COMMUNICATION_API_ID,FRIF_E_NOT_INITIALIZED,E_NOT_OK);
/* @req FrIf05161 */
FRIF_DET_REPORTERROR((FrIf_CtrlIdx < FrIf_ConfigCachePtr->FrIf_CtrlCount),FRIF_START_COMMUNICATION_API_ID,FRIF_E_INV_CTRL_IDX,E_NOT_OK);
/* @req FrIf05162 */
/* 1) translate to Fr idx using FrIf idx */
frIdx = FrIf_ConfigCachePtr->FrIf_CtrlPtr[FrIf_CtrlIdx].FrIf_FrCtrlIdx;
/* 2) locate this driver api*/
myFuncPtr = (FrIf_ConfigCachePtr->Fr_Driver_ConfigPtr[FRIF_DRIVER_0].FrIf_FrAPIPtr);
if (myFuncPtr != NULL) {
/* 3) Call this driver start communication api passing correct config struct */
ret = (*myFuncPtr->Fr_StartCommunication)(frIdx);
}
return ret;
}
/* @req FrIf05006 */
/**
*
* @param FrIf_CtrlIdx
* @return
*/
Std_ReturnType FrIf_HaltCommunication( uint8 FrIf_CtrlIdx )
{
Std_ReturnType ret;
uint8 frIdx;
const FrIf_FrAPIType *myFuncPtr;
ret = E_NOT_OK;
/* @req FrIf05298 */
/* @req FrIf05166 */
FRIF_DET_REPORTERROR((TRUE == FrIf_Internal_Global.initDone),FRIF_HALT_COMMUNICATION_API_ID,FRIF_E_NOT_INITIALIZED,E_NOT_OK);
/* @req FrIf05164 */
FRIF_DET_REPORTERROR((FrIf_CtrlIdx < FrIf_ConfigCachePtr->FrIf_CtrlCount),FRIF_HALT_COMMUNICATION_API_ID,FRIF_E_INV_CTRL_IDX,E_NOT_OK);
/* @req FrIf05165 */
/* 1) translate to Fr idx using FrIf idx */
frIdx = FrIf_ConfigCachePtr->FrIf_CtrlPtr[FrIf_CtrlIdx].FrIf_FrCtrlIdx;
/* 2) locate this driver api*/
myFuncPtr = (FrIf_ConfigCachePtr->Fr_Driver_ConfigPtr[FRIF_DRIVER_0].FrIf_FrAPIPtr);
if (myFuncPtr != NULL) {
/* 3) Call this driver halt communication api passing correct config struct */
ret = (*myFuncPtr->Fr_HaltCommunication)(frIdx);
}
return ret;
}
/* @req FrIf05007 */
/**
*
* @param FrIf_CtrlIdx
* @return
*/
Std_ReturnType FrIf_AbortCommunication( uint8 FrIf_CtrlIdx )
{
Std_ReturnType ret;
uint8 frIdx;
const FrIf_FrAPIType *myFuncPtr;
ret = E_NOT_OK;
/* @req FrIf05298 */
/* @req FrIf05169 */
FRIF_DET_REPORTERROR((TRUE == FrIf_Internal_Global.initDone),FRIF_ABORT_COMMUNICATION_API_ID,FRIF_E_NOT_INITIALIZED,E_NOT_OK);
/* @req FrIf05167 */
FRIF_DET_REPORTERROR((FrIf_CtrlIdx < FrIf_ConfigCachePtr->FrIf_CtrlCount),FRIF_ABORT_COMMUNICATION_API_ID,FRIF_E_INV_CTRL_IDX,E_NOT_OK);
/* @req FrIf05168 */
/* 1) translate to Fr idx using FrIf idx */
frIdx = FrIf_ConfigCachePtr->FrIf_CtrlPtr[FrIf_CtrlIdx].FrIf_FrCtrlIdx;
/* 2) locate this driver api*/
myFuncPtr = (FrIf_ConfigCachePtr->Fr_Driver_ConfigPtr[FRIF_DRIVER_0].FrIf_FrAPIPtr);
if (myFuncPtr != NULL) {
/* 3) Call this driver abort communication api by passing correct config struct */
ret = (*myFuncPtr->Fr_AbortCommunication)(frIdx);
}
return ret;
}
/* @req FrIf05170 */
/**
*
* @param FrIf_ClstIdx
* @param FrIf_StatePtr
* @return
*/
Std_ReturnType FrIf_GetState( uint8 FrIf_ClstIdx, FrIf_StateType* FrIf_StatePtr )
{
/* @req FrIf05298 */
/* @req FrIf05173 */
FRIF_DET_REPORTERROR((TRUE == FrIf_Internal_Global.initDone),FRIF_GET_STATE_API_ID,FRIF_E_NOT_INITIALIZED,E_NOT_OK);
/* @req FrIf05171 */
FRIF_DET_REPORTERROR((FrIf_ClstIdx < FrIf_ConfigCachePtr->FrIf_ClusterCount),FRIF_GET_STATE_API_ID,FRIF_E_INV_CLST_IDX,E_NOT_OK);
/* @req FrIf05172 */
FRIF_DET_REPORTERROR((FrIf_StatePtr != NULL),FRIF_GET_STATE_API_ID,FRIF_E_INV_POINTER,E_NOT_OK);
*FrIf_StatePtr = FrIf_Internal_Global.clstrRunTimeData[FrIf_ClstIdx].clstrState;
return E_OK;
}
/* @req FrIf05174 */
/**
*
* @param FrIf_ClstIdx
* @param FrIf_StateTransition
* @return
*/
Std_ReturnType FrIf_SetState(uint8 FrIf_ClstIdx, FrIf_StateTransitionType FrIf_StateTransition)
{
Std_ReturnType ret;
ret = E_NOT_OK;
const FrIf_ClusterType * clstrCfg; /* Pointer to cluster cfg */
uint8 frIfIdx;
/* @req FrIf05298 */
/* @req FrIf05176 */
FRIF_DET_REPORTERROR((TRUE == FrIf_Internal_Global.initDone),FRIF_SET_STATE_API_ID,FRIF_E_NOT_INITIALIZED,E_NOT_OK);
/* @req FrIf05175 */
FRIF_DET_REPORTERROR((FrIf_ClstIdx < FrIf_ConfigCachePtr->FrIf_ClusterCount),FRIF_SET_STATE_API_ID,FRIF_E_INV_CLST_IDX,E_NOT_OK);
/* @req FrIf05118 */
if ((FrIf_StateTransition == FRIF_GOTO_ONLINE) && (FrIf_Internal_Global.clstrRunTimeData[FrIf_ClstIdx].clstrState == FRIF_STATE_OFFLINE)) {
FrIf_Internal_Global.clstrRunTimeData[FrIf_ClstIdx].clstrState = FRIF_STATE_ONLINE;
ret = E_OK;
} else if ((FrIf_StateTransition == FRIF_GOTO_OFFLINE) && (FrIf_Internal_Global.clstrRunTimeData[FrIf_ClstIdx].clstrState == FRIF_STATE_ONLINE)) {
clstrCfg = &FrIf_ConfigCachePtr->FrIf_ClusterPtr[FrIf_ClstIdx];
frIfIdx = clstrCfg->FrIf_ControllerPtr[FIRST_FRIF_CTRL_IDX]->FrIf_CtrlIdx; /* Find FrIf Controller Id for the first controller in the cluster */
/* Cancel timer */
(void)FrIf_CancelAbsoluteTimer(frIfIdx, clstrCfg->FrIf_JobListPtr->FrIf_AbsTimerIdx);
FrIf_Internal_Global.clstrRunTimeData[FrIf_ClstIdx].jobListSyncLost = TRUE;
FrIf_Internal_Global.clstrRunTimeData[FrIf_ClstIdx].clstrState = FRIF_STATE_OFFLINE;
ret = E_OK;
} else {
ret = E_NOT_OK;
}
return ret;
}
/* @req FrIf05010 */
/**
*
* @param FrIf_CtrlIdx
* @param FrIf_ChnlIdx
* @return
*/
Std_ReturnType FrIf_SetWakeupChannel(uint8 FrIf_CtrlIdx, Fr_ChannelType FrIf_ChnlIdx)
{
uint8 frIdx;
const FrIf_FrAPIType *myFuncPtr;
Std_ReturnType ret;
boolean tmp;
ret = E_NOT_OK;
/* @req FrIf05298 */
/* @req FrIf05179 */
FRIF_DET_REPORTERROR((TRUE == FrIf_Internal_Global.initDone),FRIF_SET_WUP_CHANNEL_API_ID,FRIF_E_NOT_INITIALIZED,E_NOT_OK);
/* @req FrIf05500 */
FRIF_DET_REPORTERROR((FrIf_CtrlIdx < FrIf_ConfigCachePtr->FrIf_CtrlCount),FRIF_SET_WUP_CHANNEL_API_ID,FRIF_E_INV_CTRL_IDX,E_NOT_OK);
/* @req FrIf05177 */
/* @req FrIf05264 */
tmp = (FrIf_ChnlIdx == FR_CHANNEL_A) || (FrIf_ChnlIdx == FR_CHANNEL_B);
FRIF_DET_REPORTERROR((TRUE == tmp ),FRIF_SET_WUP_CHANNEL_API_ID,FRIF_E_INV_CHNL_IDX,E_NOT_OK);
/* @req FrIf05178 */
/* 1) translate to Fr idx using FrIf idx */
frIdx = FrIf_ConfigCachePtr->FrIf_CtrlPtr[FrIf_CtrlIdx].FrIf_FrCtrlIdx;
/* 2) locate this driver api*/
myFuncPtr = (FrIf_ConfigCachePtr->Fr_Driver_ConfigPtr[FRIF_DRIVER_0].FrIf_FrAPIPtr);
if (myFuncPtr != NULL) {
/* 3) Call this driver function Fr_SetWakeupChannel() */
ret = (*myFuncPtr->Fr_SetWakeupChannel)(frIdx, FrIf_ChnlIdx);
}
return ret;
}
/* @req FrIf05011 */
/**
*
* @param FrIf_CtrlIdx
* @return
*/
Std_ReturnType FrIf_SendWUP( uint8 FrIf_CtrlIdx ) {
uint8 frIdx;
const FrIf_FrAPIType *myFuncPtr;
Std_ReturnType ret;
ret = E_NOT_OK;
/* @req FrIf05298 */
/* @req FrIf05182 */
FRIF_DET_REPORTERROR((TRUE == FrIf_Internal_Global.initDone),FRIF_SEND_WUP_API_ID,FRIF_E_NOT_INITIALIZED,E_NOT_OK);
/* @req FrIf05180 */
FRIF_DET_REPORTERROR((FrIf_CtrlIdx < FrIf_ConfigCachePtr->FrIf_CtrlCount),FRIF_SEND_WUP_API_ID,FRIF_E_INV_CTRL_IDX,E_NOT_OK);
/* @req FrIf05181 */
/* 1) translate to Fr idx using FrIf idx */
frIdx = FrIf_ConfigCachePtr->FrIf_CtrlPtr[FrIf_CtrlIdx].FrIf_FrCtrlIdx;
/* 2) locate this driver api*/
myFuncPtr = (FrIf_ConfigCachePtr->Fr_Driver_ConfigPtr[FRIF_DRIVER_0].FrIf_FrAPIPtr);
if (myFuncPtr != NULL) {
/* 3) Call this driver function Fr_SendWUP() */
ret = (*myFuncPtr->Fr_SendWUP)(frIdx);
}
return ret;
}
/* @req FrIf05014 */
/**
*
* @param FrIf_CtrlIdx
* @param FrIf_POCStatusPtr
* @return
*/
Std_ReturnType FrIf_GetPOCStatus(uint8 FrIf_CtrlIdx, Fr_POCStatusType *FrIf_POCStatusPtr)
{
uint8 frIdx;
const FrIf_FrAPIType *myFuncPtr;
Std_ReturnType ret;
ret = E_NOT_OK;
/* @req FrIf05298 */
/* @req FrIf05193 */
FRIF_DET_REPORTERROR((TRUE == FrIf_Internal_Global.initDone),FRIF_GET_POC_STATUS_API_ID,FRIF_E_NOT_INITIALIZED,E_NOT_OK);
/* @req FrIf05190 */
FRIF_DET_REPORTERROR((FrIf_CtrlIdx < FrIf_ConfigCachePtr->FrIf_CtrlCount),FRIF_GET_POC_STATUS_API_ID,FRIF_E_INV_CTRL_IDX,E_NOT_OK);
FRIF_DET_REPORTERROR((FrIf_POCStatusPtr != NULL),FRIF_GET_POC_STATUS_API_ID,FRIF_E_INV_POINTER,E_NOT_OK);
/* @req FrIf05192 */
/* 1) translate to Fr idx using FrIf idx */
frIdx = FrIf_ConfigCachePtr->FrIf_CtrlPtr[FrIf_CtrlIdx].FrIf_FrCtrlIdx;
/* 2) locate this driver api*/
myFuncPtr = (FrIf_ConfigCachePtr->Fr_Driver_ConfigPtr[FRIF_DRIVER_0].FrIf_FrAPIPtr);
if (myFuncPtr != NULL) {
/* 3) Call this driver Fr_GetPOCStatus api */
ret = (*myFuncPtr->Fr_GetPOCStatus)(frIdx, FrIf_POCStatusPtr);
}
return ret;
}
/* @req FrIf05015 */
/**
*
* @param FrIf_CtrlIdx
* @param FrIf_CyclePtr
* @param FrIf_MacroTickPtr
* @return
*/
Std_ReturnType FrIf_GetGlobalTime(uint8 FrIf_CtrlIdx, uint8 *FrIf_CyclePtr, uint16 *FrIf_MacroTickPtr)
{
uint8 frIdx;
const FrIf_FrAPIType *myFuncPtr;
Std_ReturnType ret;
ret = E_NOT_OK;
/* @req FrIf05298 */
/* @req FrIf05196 */
FRIF_DET_REPORTERROR((TRUE == FrIf_Internal_Global.initDone),FRIF_GET_GLOBAL_TIME_API_ID,FRIF_E_NOT_INITIALIZED,E_NOT_OK);
/* @req FrIf05194 */
FRIF_DET_REPORTERROR((FrIf_CtrlIdx < FrIf_ConfigCachePtr->FrIf_CtrlCount),FRIF_GET_GLOBAL_TIME_API_ID,FRIF_E_INV_CTRL_IDX,E_NOT_OK);
FRIF_DET_REPORTERROR(((FrIf_CyclePtr != NULL) && (FrIf_MacroTickPtr != NULL)),FRIF_GET_GLOBAL_TIME_API_ID,FRIF_E_INV_POINTER,E_NOT_OK);
/* @req FrIf05195 */
/* 1) translate to Fr idx using FrIf idx */
frIdx = FrIf_ConfigCachePtr->FrIf_CtrlPtr[FrIf_CtrlIdx].FrIf_FrCtrlIdx;
/* 2) locate this driver api*/
myFuncPtr = (FrIf_ConfigCachePtr->Fr_Driver_ConfigPtr[FRIF_DRIVER_0].FrIf_FrAPIPtr);
if (myFuncPtr != NULL) {
/* 3) Call this driver Fr_GetGlobalTime Api */
ret = (*myFuncPtr->Fr_GetGlobalTime)(frIdx, FrIf_CyclePtr, FrIf_MacroTickPtr);
}
return ret;
}
/* @req FrIf05017 */
/**
*
* @param FrIf_CtrlIdx
* @return
*/
Std_ReturnType FrIf_AllowColdstart(uint8 FrIf_CtrlIdx)
{
/* Variable containing the value to return when the function reaches it's end. */
Std_ReturnType ret;
uint8 frIdx;
const FrIf_FrAPIType *myFuncPtr;
ret = E_NOT_OK;
/* @req FrIf05298 */
/* @req FrIf05202 */
FRIF_DET_REPORTERROR((TRUE == FrIf_Internal_Global.initDone),FRIF_ALLOW_COLD_START_API_ID,FRIF_E_NOT_INITIALIZED,E_NOT_OK);
/* @req FrIf05200 */
FRIF_DET_REPORTERROR((FrIf_CtrlIdx < FrIf_ConfigCachePtr->FrIf_CtrlCount),FRIF_ALLOW_COLD_START_API_ID,FRIF_E_INV_CTRL_IDX,E_NOT_OK);
/* @req FrIf05201 */
/* Translate to Fr idx using FrIf idx */
frIdx = FrIf_ConfigCachePtr->FrIf_CtrlPtr[FrIf_CtrlIdx].FrIf_FrCtrlIdx;
/* Locate this driver's api */
myFuncPtr = (FrIf_ConfigCachePtr->Fr_Driver_ConfigPtr[FRIF_DRIVER_0].FrIf_FrAPIPtr);
if (myFuncPtr != NULL) {
/* Call the determined FlexRay Driver's Fr_AllowColdstart api */
ret = (*myFuncPtr->Fr_AllowColdstart)(frIdx);
}
return ret;
}
/* @req FrIf05018 */
/**
*
* @param FrIf_CtrlIdx
* @return
*/
uint16 FrIf_GetMacroticksPerCycle(uint8 FrIf_CtrlIdx)
{
uint8 clstrIdx;
/* @req FrIf05298 */
/* @req FrIf05204 */
FRIF_DET_REPORTERROR((TRUE == FrIf_Internal_Global.initDone),FRIF_GET_MACROTICKS_PER_CYCLE_API_ID,FRIF_E_NOT_INITIALIZED,0);
/* @req FrIf05203 */
FRIF_DET_REPORTERROR((FrIf_CtrlIdx < FrIf_ConfigCachePtr->FrIf_CtrlCount),FRIF_GET_MACROTICKS_PER_CYCLE_API_ID,FRIF_E_INV_CTRL_IDX,0);
clstrIdx = FrIf_ConfigCachePtr->FrIf_CtrlPtr[FrIf_CtrlIdx].FrIf_ClstrRefIdx;
return FrIf_ConfigCachePtr->FrIf_ClusterPtr[clstrIdx].FrIf_GMacroPerCycle;
}
/* @req FrIf05019 */
/**
*
* @param FrIf_CtrlIdx
* @return
*/
uint16 FrIf_GetMacrotickDuration( uint8 FrIf_CtrlIdx )
{
uint8 clstrIdx;
/* @req FrIf05298 */
FRIF_DET_REPORTERROR((TRUE == FrIf_Internal_Global.initDone),FRIF_GET_MACROTICKS_DUR_API_ID,FRIF_E_NOT_INITIALIZED,0);
/* @req FrIf05191 */
FRIF_DET_REPORTERROR((FrIf_CtrlIdx < FrIf_ConfigCachePtr->FrIf_CtrlCount),FRIF_GET_MACROTICKS_DUR_API_ID,FRIF_E_INV_CTRL_IDX,0);
clstrIdx = FrIf_ConfigCachePtr->FrIf_CtrlPtr[FrIf_CtrlIdx].FrIf_ClstrRefIdx;
return (uint16)FrIf_ConfigCachePtr->FrIf_ClusterPtr[clstrIdx].FrIf_GdMacrotick;
}
/* @req FrIf05033 */
/**
*
* @param FrIf_TxPduId
* @param FrIf_PduInfoPtr
* @return
*/
Std_ReturnType FrIf_Transmit(PduIdType FrIf_TxPduId, const PduInfoType *FrIf_PduInfoPtr)
{
const FrIf_TxPduType * frIfTxPduPtr;
const FrIf_FrAPIType *myFuncPtr;
const FrIf_ImmediateTxPduCfgType * immTxPduCfg;
const uint8* Fr_LSduPtr;
Std_ReturnType ret;
boolean resFlag;
#if (FRIF_BIG_ENDIAN_USED == STD_ON)
const FrIf_ControllerType * ctrlCfg;
const FrIf_FrameStructureType * frameStructureRef;
uint8 tempBuffForBigEndian[FLEXRAY_FRAME_LEN_MAX];
#endif
ret = E_NOT_OK;
/* @req FrIf05298 */
/* @req FrIf05209 */
FRIF_DET_REPORTERROR((TRUE == FrIf_Internal_Global.initDone),FRIF_TRANSMIT_API_ID,FRIF_E_NOT_INITIALIZED,E_NOT_OK);
/* @req FrIf05205 */
FRIF_DET_REPORTERROR((FrIf_TxPduId < FrIf_ConfigCachePtr->FrIf_TxPduCount),FRIF_TRANSMIT_API_ID,FRIF_E_INV_TXPDUID,E_NOT_OK);
/* @req FrIf05206 */
FRIF_DET_REPORTERROR((FrIf_PduInfoPtr != NULL),FRIF_TRANSMIT_API_ID,FRIF_E_INV_POINTER,E_NOT_OK);
/* @req FrIf05207 */
FRIF_DET_REPORTERROR((FrIf_PduInfoPtr->SduDataPtr != NULL),FRIF_TRANSMIT_API_ID,FRIF_E_INV_POINTER,E_NOT_OK);
frIfTxPduPtr = &FrIf_ConfigCachePtr->FrIf_TxPduCfgPtr[FrIf_TxPduId];
/* @req FrIf05208 */ /* @req FrIf05295a */
if (TRUE == frIfTxPduPtr->FrIf_Immediate) {
SchM_Enter_FrIf_EA_0(); /* @req FrIf05148 */ /* Data consistency of lower buffer is maintained by disabling interrupts */
/* @req FrIf05296 */
myFuncPtr = (FrIf_ConfigCachePtr->Fr_Driver_ConfigPtr[FRIF_DRIVER_0].FrIf_FrAPIPtr);
immTxPduCfg = &FrIf_ConfigCachePtr->FrIf_ImmediateTxPduCfgPtr[frIfTxPduPtr->FrIf_ImmediateTxCfgIdx];
Fr_LSduPtr = FrIf_PduInfoPtr->SduDataPtr;
#if (FRIF_BIG_ENDIAN_USED == STD_ON)
ctrlCfg = &FrIf_ConfigCachePtr->FrIf_CtrlPtr[immTxPduCfg->FrIf_FrCtrlIdx];
frameStructureRef = ctrlCfg->FrIf_LpduPtr[immTxPduCfg->Fr_Buffer].FrIf_VBTriggeringRef->FrIf_FrameStructureRef;
if (FRIF_BIG_ENDIAN == frameStructureRef->FrIf_ByteOrder) {
FrIf_Internal_SwapToBigEndian(FrIf_PduInfoPtr->SduDataPtr,tempBuffForBigEndian,(uint8)FrIf_PduInfoPtr->SduLength);
Fr_LSduPtr = &tempBuffForBigEndian[0];
}
#endif
if (myFuncPtr != NULL) {
ret = myFuncPtr->Fr_TransmitTxLPdu(immTxPduCfg->FrIf_FrCtrlIdx, immTxPduCfg->Fr_Buffer, Fr_LSduPtr, (uint8)FrIf_PduInfoPtr->SduLength);
}
if (E_OK == ret){
/* Remember that a transmission for this PDU is pending if transmission confirmation is needed */
resFlag = ((TRUE == frIfTxPduPtr->FrIf_Confirm) && (FrIf_Internal_Global.txPduStatistics[FrIf_TxPduId].txConfCounter
< frIfTxPduPtr->FrIf_CounterLimit));
if (TRUE == resFlag) {
/* Only increment if counter limit has not been reached */
FrIf_Internal_Global.txPduStatistics[FrIf_TxPduId].txConfCounter++;
}
}
SchM_Exit_FrIf_EA_0();
} else {
if ((FrIf_Internal_Global.txPduStatistics[FrIf_TxPduId].trigTxCounter > frIfTxPduPtr->FrIf_CounterLimit)
|| (FrIf_Internal_Global.txPduStatistics[FrIf_TxPduId].txConfCounter > frIfTxPduPtr->FrIf_CounterLimit)) {
ret = E_NOT_OK;
} else {
/* @req FrIf05124 */
FrIf_Internal_Global.txPduStatistics[FrIf_TxPduId].trigTxCounter++;
ret = E_OK;
}
}
return ret;
}
/* !req FrIf05034 */
/**
*
* @param FrIf_CtrlIdx
* @param FrIf_ChnlIdx
* @param FrIf_TrcvMode
* @return
*/
Std_ReturnType FrIf_SetTransceiverMode( uint8 FrIf_CtrlIdx, Fr_ChannelType FrIf_ChnlIdx, FrTrcv_TrcvModeType FrIf_TrcvMode )
{
/* @req FrIf05298 */
/* @req FrIf05213 */
FRIF_DET_REPORTERROR((TRUE == FrIf_Internal_Global.initDone),FRIF_SET_TRCV_MODE_API_ID,FRIF_E_NOT_INITIALIZED,E_NOT_OK);
/* @req FrIf05210 */
FRIF_DET_REPORTERROR((FrIf_CtrlIdx < FrIf_ConfigCachePtr->FrIf_CtrlCount),FRIF_SET_TRCV_MODE_API_ID,FRIF_E_INV_CTRL_IDX,E_NOT_OK);
/* @req FrIf05211 */
FRIF_DET_REPORTERROR(((FR_CHANNEL_A==FrIf_ChnlIdx)||(FR_CHANNEL_B==FrIf_ChnlIdx)),FRIF_SET_TRCV_MODE_API_ID,FRIF_E_INV_CHNL_IDX,E_NOT_OK);
/* !req FrIf05212 */
(void)FrIf_TrcvMode;
return E_NOT_OK;
}
/* !req FrIf05035 */
/**
*
* @param FrIf_CtrlIdx
* @param FrIf_ChnlIdx
* @param FrIf_TrcvModePtr
* @return
*/
/*lint --e{818} */
Std_ReturnType FrIf_GetTransceiverMode( uint8 FrIf_CtrlIdx, Fr_ChannelType FrIf_ChnlIdx, FrTrcv_TrcvModeType* FrIf_TrcvModePtr )
{
/* @req FrIf05298 */
/* @req FrIf05217 */
FRIF_DET_REPORTERROR((TRUE == FrIf_Internal_Global.initDone),FRIF_GET_TRCV_MODE_API_ID,FRIF_E_NOT_INITIALIZED,E_NOT_OK);
/* @req FrIf05214 */
FRIF_DET_REPORTERROR((FrIf_CtrlIdx < FrIf_ConfigCachePtr->FrIf_CtrlCount),FRIF_GET_TRCV_MODE_API_ID,FRIF_E_INV_CTRL_IDX,E_NOT_OK);
/* @req FrIf05215 */
FRIF_DET_REPORTERROR(((FR_CHANNEL_A==FrIf_ChnlIdx)||(FR_CHANNEL_B==FrIf_ChnlIdx)),FRIF_GET_TRCV_MODE_API_ID,FRIF_E_INV_CHNL_IDX,E_NOT_OK);
FRIF_DET_REPORTERROR((FrIf_TrcvModePtr != NULL_PTR),FRIF_GET_TRCV_MODE_API_ID,FRIF_E_INV_POINTER,E_NOT_OK);
/* !req FrIf05216 */
return E_NOT_OK;
}
/* !req FrIf05036 */
/**
*
* @param FrIf_CtrlIdx
* @param FrIf_ChnlIdx
* @param FrIf_TrcvWUReasonPtr
* @return
*/
/*lint --e{818} */
Std_ReturnType FrIf_GetTransceiverWUReason( uint8 FrIf_CtrlIdx, Fr_ChannelType FrIf_ChnlIdx, FrTrcv_TrcvWUReasonType* FrIf_TrcvWUReasonPtr )
{
/* @req FrIf05298 */
/* @req FrIf05221 */
FRIF_DET_REPORTERROR((TRUE == FrIf_Internal_Global.initDone),FRIF_GET_TRCV_WU_REASON_API_ID,FRIF_E_NOT_INITIALIZED,E_NOT_OK);
/* @req FrIf05218 */
FRIF_DET_REPORTERROR((FrIf_CtrlIdx < FrIf_ConfigCachePtr->FrIf_CtrlCount),FRIF_GET_TRCV_WU_REASON_API_ID,FRIF_E_INV_CTRL_IDX,E_NOT_OK);
/* @req FrIf05219 */
FRIF_DET_REPORTERROR(((FR_CHANNEL_A==FrIf_ChnlIdx)||(FR_CHANNEL_B==FrIf_ChnlIdx)),FRIF_GET_TRCV_WU_REASON_API_ID,FRIF_E_INV_CHNL_IDX,E_NOT_OK);
FRIF_DET_REPORTERROR((FrIf_TrcvWUReasonPtr != NULL_PTR),FRIF_GET_TRCV_WU_REASON_API_ID,FRIF_E_INV_POINTER,E_NOT_OK);
/* !req FrIf05220 */
return E_NOT_OK;
}
/* !req FrIf05039 */
/**
*
* @param FrIf_CtrlIdx
* @param FrIf_ChnlIdx
* @return
*/
Std_ReturnType FrIf_ClearTransceiverWakeup( uint8 FrIf_CtrlIdx, Fr_ChannelType FrIf_ChnlIdx )
{
/* @req FrIf05298 */
/* @req FrIf05233 */
FRIF_DET_REPORTERROR((TRUE == FrIf_Internal_Global.initDone),FRIF_CLR_TRCV_WUP_API_ID,FRIF_E_NOT_INITIALIZED,E_NOT_OK);
/* @req FrIf05230 */
FRIF_DET_REPORTERROR((FrIf_CtrlIdx < FrIf_ConfigCachePtr->FrIf_CtrlCount),FRIF_CLR_TRCV_WUP_API_ID,FRIF_E_INV_CTRL_IDX,E_NOT_OK);
/* @req FrIf05231 */
FRIF_DET_REPORTERROR(((FR_CHANNEL_A==FrIf_ChnlIdx)||(FR_CHANNEL_B==FrIf_ChnlIdx)),FRIF_CLR_TRCV_WUP_API_ID,FRIF_E_INV_CHNL_IDX,E_NOT_OK);
/* !req FrIf05232 */
return E_NOT_OK;
}
/* @req FrIf05023 */
/**
*
* @param FrIf_CtrlIdx
* @param FrIf_AbsTimerIdx
* @return
*/
Std_ReturnType FrIf_CancelAbsoluteTimer( uint8 FrIf_CtrlIdx, uint8 FrIf_AbsTimerIdx )
{
const FrIf_JobListType * jobListCfg;
const FrIf_FrAPIType *myFuncPtr;
uint8 frIdx;
Std_ReturnType ret;
uint8 clstrIdx;
uint8 frAbsTimerIdx;
ret = E_NOT_OK;
/* @req FrIf05298 */
/* @req FrIf05242 */
FRIF_DET_REPORTERROR((TRUE == FrIf_Internal_Global.initDone),FRIF_CANCEL_ABSOLUTE_TIMER_API_ID,FRIF_E_NOT_INITIALIZED,E_NOT_OK);
/* @req FrIf05240 */
FRIF_DET_REPORTERROR((FrIf_CtrlIdx < FrIf_ConfigCachePtr->FrIf_CtrlCount),FRIF_CANCEL_ABSOLUTE_TIMER_API_ID,FRIF_E_INV_CTRL_IDX,E_NOT_OK);
FRIF_DET_REPORTERROR((FrIf_AbsTimerIdx < FRIF_MAX_ABSOLUTE_TIMER),FRIF_CANCEL_ABSOLUTE_TIMER_API_ID,FRIF_E_INV_TIMER_IDX,E_NOT_OK);
/* @req FrIf05241 */
/* 1) translate to Fr idx using FrIf idx */
frIdx = FrIf_ConfigCachePtr->FrIf_CtrlPtr[FrIf_CtrlIdx].FrIf_FrCtrlIdx;
clstrIdx = FrIf_ConfigCachePtr->FrIf_CtrlPtr[FrIf_CtrlIdx].FrIf_ClstrRefIdx;
jobListCfg = FrIf_ConfigCachePtr->FrIf_ClusterPtr[clstrIdx].FrIf_JobListPtr;
FRIF_DET_REPORTERROR((jobListCfg->FrIf_AbsTimerIdx == FrIf_AbsTimerIdx),FRIF_CANCEL_ABSOLUTE_TIMER_API_ID,FRIF_E_INV_TIMER_IDX,E_NOT_OK);
frAbsTimerIdx = jobListCfg->FrIf_FrAbsTimerIdx;
/* 2) locate driver api*/
myFuncPtr = (FrIf_ConfigCachePtr->Fr_Driver_ConfigPtr[FRIF_DRIVER_0].FrIf_FrAPIPtr);
if (myFuncPtr != NULL) {
/* 3) Call this driver Fr_CancelAbsoluteTimer api */
ret = (*myFuncPtr->Fr_CancelAbsoluteTimer)(frIdx, frAbsTimerIdx);
}
return ret;
}
/* @req FrIf05027 */
/**
*
* @param FrIf_CtrlIdx
* @param FrIf_AbsTimerIdx
* @param FrIf_IRQStatusPtr
* @return
*/
Std_ReturnType FrIf_GetAbsoluteTimerIRQStatus( uint8 FrIf_CtrlIdx, uint8 FrIf_AbsTimerIdx, boolean* FrIf_IRQStatusPtr )
{
const FrIf_JobListType * jobListCfg;
const FrIf_FrAPIType *myFuncPtr;
uint8 frIdx;
Std_ReturnType ret;
uint8 clstrIdx;
uint8 frAbsTimerIdx;
ret = E_NOT_OK;
/* @req FrIf05298 */
/* @req FrIf05254 */
FRIF_DET_REPORTERROR((TRUE == FrIf_Internal_Global.initDone),FRIF_GET_ABSOLUTE_TIMER_IRQ_STATUS_API_ID,FRIF_E_NOT_INITIALIZED,E_NOT_OK);
/* @req FrIf05252 */
FRIF_DET_REPORTERROR((FrIf_CtrlIdx < FrIf_ConfigCachePtr->FrIf_CtrlCount),FRIF_GET_ABSOLUTE_TIMER_IRQ_STATUS_API_ID,FRIF_E_INV_CTRL_IDX,E_NOT_OK);
FRIF_DET_REPORTERROR((FrIf_IRQStatusPtr != NULL),FRIF_GET_ABSOLUTE_TIMER_IRQ_STATUS_API_ID,FRIF_E_INV_POINTER,E_NOT_OK);
FRIF_DET_REPORTERROR((FrIf_AbsTimerIdx < FRIF_MAX_ABSOLUTE_TIMER),FRIF_GET_ABSOLUTE_TIMER_IRQ_STATUS_API_ID,FRIF_E_INV_TIMER_IDX,E_NOT_OK);
/* @req FrIf05253 */
/* 1) translate to Fr idx using FrIf idx */
frIdx = FrIf_ConfigCachePtr->FrIf_CtrlPtr[FrIf_CtrlIdx].FrIf_FrCtrlIdx;
clstrIdx = FrIf_ConfigCachePtr->FrIf_CtrlPtr[FrIf_CtrlIdx].FrIf_ClstrRefIdx;
jobListCfg = FrIf_ConfigCachePtr->FrIf_ClusterPtr[clstrIdx].FrIf_JobListPtr;
FRIF_DET_REPORTERROR((jobListCfg->FrIf_AbsTimerIdx == FrIf_AbsTimerIdx),FRIF_GET_ABSOLUTE_TIMER_IRQ_STATUS_API_ID,FRIF_E_INV_TIMER_IDX,E_NOT_OK);
frAbsTimerIdx = jobListCfg->FrIf_FrAbsTimerIdx;
/* 2) locate driver api*/
myFuncPtr = (FrIf_ConfigCachePtr->Fr_Driver_ConfigPtr[FRIF_DRIVER_0].FrIf_FrAPIPtr);
if (myFuncPtr != NULL) {
/* 3) Call this driver FrIf_GetAbsoluteTimerIRQStatus api */
ret = (*myFuncPtr->Fr_GetAbsoluteTimerIRQStatus)(frIdx, frAbsTimerIdx,FrIf_IRQStatusPtr);
}
return ret;
}
/* @req FrIf05031 */
/**
*
* @param FrIf_CtrlIdx
* @param FrIf_AbsTimerIdx
* @return
*/
Std_ReturnType FrIf_DisableAbsoluteTimerIRQ(uint8 FrIf_CtrlIdx, uint8 FrIf_AbsTimerIdx)
{
const FrIf_JobListType * jobListCfg;
const FrIf_FrAPIType *myFuncPtr;
uint8 frIdx;
Std_ReturnType ret;
uint8 clstrIdx;
uint8 frAbsTimerIdx;
ret = E_NOT_OK;
/* @req FrIf05298 */
/* @req FrIf05266 */
FRIF_DET_REPORTERROR((TRUE == FrIf_Internal_Global.initDone),FRIF_DISABLE_ABSOLUTE_TIMER_IRQ_API_ID,FRIF_E_NOT_INITIALIZED,E_NOT_OK);
/* @req FrIf05264 */
FRIF_DET_REPORTERROR((FrIf_CtrlIdx < FrIf_ConfigCachePtr->FrIf_CtrlCount),FRIF_DISABLE_ABSOLUTE_TIMER_IRQ_API_ID,FRIF_E_INV_CTRL_IDX,E_NOT_OK);
FRIF_DET_REPORTERROR((FrIf_AbsTimerIdx < FRIF_MAX_ABSOLUTE_TIMER),FRIF_DISABLE_ABSOLUTE_TIMER_IRQ_API_ID,FRIF_E_INV_TIMER_IDX,E_NOT_OK);
/* 1) translate to Fr idx using FrIf idx */
frIdx = FrIf_ConfigCachePtr->FrIf_CtrlPtr[FrIf_CtrlIdx].FrIf_FrCtrlIdx;
clstrIdx = FrIf_ConfigCachePtr->FrIf_CtrlPtr[FrIf_CtrlIdx].FrIf_ClstrRefIdx;
jobListCfg = FrIf_ConfigCachePtr->FrIf_ClusterPtr[clstrIdx].FrIf_JobListPtr;
FRIF_DET_REPORTERROR((jobListCfg->FrIf_AbsTimerIdx == FrIf_AbsTimerIdx),FRIF_DISABLE_ABSOLUTE_TIMER_IRQ_API_ID,FRIF_E_INV_TIMER_IDX,E_NOT_OK);
frAbsTimerIdx = jobListCfg->FrIf_FrAbsTimerIdx;
/* Check if interrupts are already disabled */
if (FALSE == FrIf_Internal_Global.clstrRunTimeData[clstrIdx].interruptEnableSts) {
ret = E_OK;
} else {
/* 2) locate this driver api*/
myFuncPtr = (FrIf_ConfigCachePtr->Fr_Driver_ConfigPtr[FRIF_DRIVER_0].FrIf_FrAPIPtr);
if (myFuncPtr != NULL_PTR) {
/* 3) Call this driver Fr_DisableAbsoluteTimerIRQ api */
ret = (*myFuncPtr->Fr_DisableAbsoluteTimerIRQ)(frIdx, frAbsTimerIdx);
}
if (E_OK == ret ) {
FrIf_Internal_Global.clstrRunTimeData[clstrIdx].interruptEnableSts = FALSE;
}
}
return ret;
}
/* @req FrIf05239 */
/**
*
* @param FrIf_CtrlIdx
* @return
*/
uint32 FrIf_GetCycleLength( uint8 FrIf_CtrlIdx )
{
/* @req FrIf05298 */
/* @req FrIf05238 */
FRIF_DET_REPORTERROR((TRUE == FrIf_Internal_Global.initDone),FRIF_GET_CYCLE_LENGTH_API_ID,FRIF_E_NOT_INITIALIZED,0);
/* @req FrIf05237 */
FRIF_DET_REPORTERROR((FrIf_CtrlIdx < FrIf_ConfigCachePtr->FrIf_CtrlCount),FRIF_GET_CYCLE_LENGTH_API_ID,FRIF_E_INV_CTRL_IDX,0);
return FrIf_ConfigCachePtr->FrIf_ClusterPtr[FrIf_ConfigCachePtr->FrIf_CtrlPtr[FrIf_CtrlIdx].FrIf_ClstrRefIdx].FrIf_GdCycle;
}
/** Optional APIs */
/* @req FrIf05412 */
#if (FRIF_ALL_SLOTS_SUPPORT == STD_ON)
/* @req FrIf05707 */
/**
*
* @param FrIf_CtrlIdx
* @return
*/
Std_ReturnType FrIf_AllSlots( uint8 FrIf_CtrlIdx )
{
/* @req FrIf05298 */
/* @req FrIf05706 */
FRIF_DET_REPORTERROR((TRUE == FrIf_Internal_Global.initDone),FRIF_ALL_SLOTS_API_ID,FRIF_E_NOT_INITIALIZED,E_NOT_OK);
/* @req FrIf05707 */
FRIF_DET_REPORTERROR((FrIf_CtrlIdx < FrIf_ConfigCachePtr->FrIf_CtrlCount),FRIF_ALL_SLOTS_API_ID,FRIF_E_INV_CTRL_IDX,E_NOT_OK);
return Fr_AllSlots(FrIf_ConfigCachePtr->FrIf_CtrlPtr[FrIf_CtrlIdx].FrIf_FrCtrlIdx);
}
#endif
/* @req FrIf05413 */
#if (FRIF_GET_CHNL_STATUS_SUPPORT == STD_ON)
/* @req FrIf05030 */
/**
*
* @param FrIf_CtrlIdx
* @param FrIf_ChannelAStatusPtr
* @param FrIf_ChannelBStatusPtr
* @return
*/
Std_ReturnType FrIf_GetChannelStatus( uint8 FrIf_CtrlIdx, uint16* FrIf_ChannelAStatusPtr, uint16* FrIf_ChannelBStatusPtr )
{
uint8 frIdx;
Std_ReturnType ret;
/* @req FrIf05298 */
/* @req FrIf05708 */
FRIF_DET_REPORTERROR((TRUE == FrIf_Internal_Global.initDone),FRIF_GET_CHNL_STATUS_API_ID,FRIF_E_NOT_INITIALIZED,E_NOT_OK);
/* @req FrIf05709 */
FRIF_DET_REPORTERROR((FrIf_CtrlIdx < FrIf_ConfigCachePtr->FrIf_CtrlCount),FRIF_GET_CHNL_STATUS_API_ID,FRIF_E_INV_CTRL_IDX,E_NOT_OK);
FRIF_DET_REPORTERROR(((FrIf_ChannelAStatusPtr != NULL) && (FrIf_ChannelBStatusPtr != NULL)),FRIF_GET_CHNL_STATUS_API_ID,FRIF_E_INV_POINTER,E_NOT_OK);
frIdx = FrIf_ConfigCachePtr->FrIf_CtrlPtr[FrIf_CtrlIdx].FrIf_FrCtrlIdx;
ret = Fr_GetChannelStatus(frIdx,FrIf_ChannelAStatusPtr,FrIf_ChannelBStatusPtr);
if (E_OK == ret) {
#if defined(USE_DEM)
const FrIf_ClusterType * clstrCfg;
clstrCfg = &FrIf_ConfigCachePtr->FrIf_ClusterPtr[FrIf_ConfigCachePtr->FrIf_CtrlPtr[FrIf_CtrlIdx].FrIf_ClstrRefIdx];
/* @req FrIf05120b */
/* @req FrIf05120c */ /* @req FrIf05120d */ /* @req FrIf05120e */
/* @req FrIf05120f */ /* @req FrIf05120g */ /* @req FrIf05120h */
if (NULL != clstrCfg->FrIf_ClusterDemEventParamRef ) {
/* @req FrIf05300 */
FRIF_CLUSTER_DEM_REPORTING(A);
FRIF_CLUSTER_DEM_REPORTING(B);
}
#endif
} else {
ret = E_NOT_OK;
}
return ret;
}
#endif
/* @req FrIf05414 */
#if (FRIF_GET_CLK_CORRECTION_SUPPORT == STD_ON)
/* @req FrIf05071 */
/**
*
* @param FrIf_CtrlIdx
* @param FrIf_RateCorrectionPtr
* @param FrIf_OffsetCorrectionPtr
* @return
*/
Std_ReturnType FrIf_GetClockCorrection( uint8 FrIf_CtrlIdx, sint16* FrIf_RateCorrectionPtr, sint32* FrIf_OffsetCorrectionPtr )
{
uint8 frIdx;
/* @req FrIf05298 */
/* @req FrIf05711 */
FRIF_DET_REPORTERROR((TRUE == FrIf_Internal_Global.initDone),FRIF_GET_CLK_CORRECTION_API_ID,FRIF_E_NOT_INITIALIZED,E_NOT_OK);
/* @req FrIf05712 */
FRIF_DET_REPORTERROR((FrIf_CtrlIdx < FrIf_ConfigCachePtr->FrIf_CtrlCount),FRIF_GET_CLK_CORRECTION_API_ID,FRIF_E_INV_CTRL_IDX,E_NOT_OK);
FRIF_DET_REPORTERROR(((FrIf_RateCorrectionPtr != NULL) && (FrIf_OffsetCorrectionPtr != NULL)) ,FRIF_GET_CLK_CORRECTION_API_ID,FRIF_E_INV_POINTER,E_NOT_OK);
frIdx = FrIf_ConfigCachePtr->FrIf_CtrlPtr[FrIf_CtrlIdx].FrIf_FrCtrlIdx;
return Fr_GetClockCorrection(frIdx,FrIf_RateCorrectionPtr,FrIf_OffsetCorrectionPtr);
}
#endif
/* @req FrIf05415 */
#if (FRIF_GET_SYNC_FRAME_LIST_SUPPORT == STD_ON)
/* @req FrIf05072 */
/**
*
* @param FrIf_CtrlIdx
* @param FrIf_ListSize
* @param FrIf_ChannelAEvenListPtr
* @param FrIf_ChannelBEvenListPtr
* @param FrIf_ChannelAOddListPtr
* @param FrIf_ChannelBOddListPtr
* @return
*/
Std_ReturnType FrIf_GetSyncFrameList( uint8 FrIf_CtrlIdx, uint8 FrIf_ListSize, uint16* FrIf_ChannelAEvenListPtr, uint16* FrIf_ChannelBEvenListPtr, uint16* FrIf_ChannelAOddListPtr, uint16* FrIf_ChannelBOddListPtr )
{
uint8 frIdx;
boolean res;
/* @req FrIf05298 */
/* @req FrIf05715 */
FRIF_DET_REPORTERROR((TRUE == FrIf_Internal_Global.initDone),FRIF_GET_SYNC_FRAME_LIST_API_ID,FRIF_E_NOT_INITIALIZED,E_NOT_OK);
/* @req FrIf05716 */
FRIF_DET_REPORTERROR((FrIf_CtrlIdx < FrIf_ConfigCachePtr->FrIf_CtrlCount),FRIF_GET_SYNC_FRAME_LIST_API_ID,FRIF_E_INV_CTRL_IDX,E_NOT_OK);
res = (FrIf_ChannelAEvenListPtr != NULL) && (FrIf_ChannelBEvenListPtr != NULL) && (FrIf_ChannelAOddListPtr != NULL) && (FrIf_ChannelBOddListPtr != NULL);
FRIF_DET_REPORTERROR((TRUE == res),FRIF_GET_SYNC_FRAME_LIST_API_ID,FRIF_E_INV_POINTER,E_NOT_OK);
frIdx = FrIf_ConfigCachePtr->FrIf_CtrlPtr[FrIf_CtrlIdx].FrIf_FrCtrlIdx;
return Fr_GetSyncFrameList(frIdx,FrIf_ListSize,FrIf_ChannelAEvenListPtr,FrIf_ChannelBEvenListPtr,FrIf_ChannelAOddListPtr,FrIf_ChannelBOddListPtr);
}
#endif
/* @req FrIf05416 */
#if (FRIF_GET_NUM_STARTUP_FRAMES_SUPPORT == STD_ON)
/* @req FrIf05073 */
/**
*
* @param FrIf_CtrlIdx
* @param FrIf_NumOfStartupFramesPtr
* @return
*/
Std_ReturnType FrIf_GetNumOfStartupFrames( uint8 FrIf_CtrlIdx, uint8* FrIf_NumOfStartupFramesPtr )
{
uint8 frIdx;
/* @req FrIf05298 */
/* @req FrIf05721 */
FRIF_DET_REPORTERROR((TRUE == FrIf_Internal_Global.initDone),FRIF_GET_NUM_STARTUP_FRAMES_API_ID,FRIF_E_NOT_INITIALIZED,E_NOT_OK);
/* @req FrIf05722 */
FRIF_DET_REPORTERROR((FrIf_CtrlIdx < FrIf_ConfigCachePtr->FrIf_CtrlCount),FRIF_GET_NUM_STARTUP_FRAMES_API_ID,FRIF_E_INV_CTRL_IDX,E_NOT_OK);
FRIF_DET_REPORTERROR((FrIf_NumOfStartupFramesPtr != NULL),FRIF_GET_NUM_STARTUP_FRAMES_API_ID,FRIF_E_INV_POINTER,E_NOT_OK);
frIdx = FrIf_ConfigCachePtr->FrIf_CtrlPtr[FrIf_CtrlIdx].FrIf_FrCtrlIdx;
return Fr_GetNumOfStartupFrames(frIdx,FrIf_NumOfStartupFramesPtr);
}
#endif
/* @req FrIf05417 */
#if (FRIF_GET_WUP_RX_STATUS_SUPPORT == STD_ON)
/* @req FrIf05102 */
/**
*
* @param FrIf_CtrlIdx
* @param FrIf_WakeupRxStatusPtr
* @return
*/
Std_ReturnType FrIf_GetWakeupRxStatus( uint8 FrIf_CtrlIdx, uint8* FrIf_WakeupRxStatusPtr )
{
uint8 frIdx;
/* @req FrIf05298 */
/* @req FrIf05700 */
FRIF_DET_REPORTERROR((TRUE == FrIf_Internal_Global.initDone),FRIF_GET_WUP_RX_STATUS_API_ID,FRIF_E_NOT_INITIALIZED,E_NOT_OK);
/* @req FrIf05701 */
FRIF_DET_REPORTERROR((FrIf_CtrlIdx < FrIf_ConfigCachePtr->FrIf_CtrlCount),FRIF_GET_WUP_RX_STATUS_API_ID,FRIF_E_INV_CTRL_IDX,E_NOT_OK);
FRIF_DET_REPORTERROR((FrIf_WakeupRxStatusPtr != NULL),FRIF_GET_WUP_RX_STATUS_API_ID,FRIF_E_INV_POINTER,E_NOT_OK);
frIdx = FrIf_ConfigCachePtr->FrIf_CtrlPtr[FrIf_CtrlIdx].FrIf_FrCtrlIdx;
return Fr_GetWakeupRxStatus(frIdx,FrIf_WakeupRxStatusPtr);
}
#endif
/* @req FrIf05713 */
#if (FRIF_CANCEL_TRANSMIT_SUPPORT == STD_ON)
/* !req FrIf05070 */
/**
*
* @param FrIf_TxPduId
* @return
*/
Std_ReturnType FrIf_CancelTransmit( PduIdType FrIf_TxPduId )
{
/* @req FrIf05298 */
/* @req FrIf05703 */
FRIF_DET_REPORTERROR((TRUE == FrIf_Internal_Global.initDone),FRIF_CANCEL_TRANSMIT_API_ID,FRIF_E_NOT_INITIALIZED,E_NOT_OK);
/* @req FrIf05704 */
FRIF_DET_REPORTERROR((FrIf_TxPduId < FrIf_ConfigCachePtr->FrIf_TxPduCount),FRIF_CANCEL_TRANSMIT_API_ID,FRIF_E_INV_TXPDUID,E_NOT_OK);
/* !req FrIf05705 */
return E_NOT_OK;
}
#endif
/* @req FrIf05418 */
#if (FRIF_DISABLE_LPDU_SUPPORT == STD_ON)
/* @req FrIf05710 */
/**
*
* @param FrIf_CtrlIdx
* @param FrIf_LPduIdx
* @return
*/
Std_ReturnType FrIf_DisableLPdu( uint8 FrIf_CtrlIdx, uint16 FrIf_LPduIdx )
{
uint8 frIdx;
uint16 frLpduIdx;
/* @req FrIf05298 */
/* @req FrIf05717 */
FRIF_DET_REPORTERROR((TRUE == FrIf_Internal_Global.initDone),FRIF_DISABLE_LPDU_API_ID,FRIF_E_NOT_INITIALIZED,E_NOT_OK);
/* @req FrIf05714 */
FRIF_DET_REPORTERROR((FrIf_CtrlIdx < FrIf_ConfigCachePtr->FrIf_CtrlCount),FRIF_DISABLE_LPDU_API_ID,FRIF_E_INV_CTRL_IDX,E_NOT_OK);
FRIF_DET_REPORTERROR((FrIf_LPduIdx < FrIf_ConfigCachePtr->FrIf_CtrlPtr[FrIf_CtrlIdx].FrIf_LPduCount),FRIF_DISABLE_LPDU_API_ID,FRIF_E_INV_LPDU_IDX,E_NOT_OK);
frIdx = FrIf_ConfigCachePtr->FrIf_CtrlPtr[FrIf_CtrlIdx].FrIf_FrCtrlIdx;
frLpduIdx = FrIf_ConfigCachePtr->FrIf_CtrlPtr[FrIf_CtrlIdx].FrIf_LpduPtr[FrIf_LPduIdx].Fr_Buffer;
return Fr_DisableLPdu(frIdx,frLpduIdx);
}
#endif
/* @req FrIf05419 */
#if (FRIF_GET_TRCV_ERROR_SUPPORT == STD_ON)
/* !req FrIf05032 */
/**
*
* @param FrIf_CtrlIdx
* @param FrIf_ChnlIdx
* @param FrIf_BranchIdx
* @param FrIf_BusErrorState
* @return
*/
/*lint --e{818} */
Std_ReturnType FrIf_GetTransceiverError( uint8 FrIf_CtrlIdx, Fr_ChannelType FrIf_ChnlIdx, uint8 FrIf_BranchIdx, uint32* FrIf_BusErrorState )
{
/* @req FrIf05298 */
/* @req FrIf05718 */
FRIF_DET_REPORTERROR((TRUE == FrIf_Internal_Global.initDone),FRIF_GET_TRV_ERROR_API_ID,FRIF_E_NOT_INITIALIZED,E_NOT_OK);
/* @req FrIf05719 */
FRIF_DET_REPORTERROR((FrIf_CtrlIdx < FrIf_ConfigCachePtr->FrIf_CtrlCount),FRIF_GET_TRV_ERROR_API_ID,FRIF_E_INV_CTRL_IDX,E_NOT_OK);
/* @req FrIf05720 */
FRIF_DET_REPORTERROR(((FR_CHANNEL_A==FrIf_ChnlIdx)||(FR_CHANNEL_B==FrIf_ChnlIdx)),FRIF_GET_TRV_ERROR_API_ID,FRIF_E_INV_CHNL_IDX,E_NOT_OK);
FRIF_DET_REPORTERROR((FrIf_BusErrorState != NULL),FRIF_GET_TRV_ERROR_API_ID,FRIF_E_INV_POINTER,E_NOT_OK);
/* !req FrIf05728 */
(void)FrIf_BranchIdx;
return E_NOT_OK;
}
#endif
/* @req FrIf05420 */
#if (FRIF_ENABLE_TRCV_BRANCH_SUPPORT == STD_ON)
/* !req FrIf05085 */
/**
*
* @param FrIf_CtrlIdx
* @param FrIf_ChnlIdx
* @param FrIf_BranchIdx
* @return
*/
Std_ReturnType FrIf_EnableTransceiverBranch( uint8 FrIf_CtrlIdx, Fr_ChannelType FrIf_ChnlIdx, uint8 FrIf_BranchIdx )
{
/* @req FrIf05298 */
/* @req FrIf05307 */
FRIF_DET_REPORTERROR((TRUE == FrIf_Internal_Global.initDone),FRIF_ENABLE_TRCV_BRANCH_API_ID,FRIF_E_NOT_INITIALIZED,E_NOT_OK);
/* @req FrIf05302 */
FRIF_DET_REPORTERROR((FrIf_CtrlIdx < FrIf_ConfigCachePtr->FrIf_CtrlCount),FRIF_ENABLE_TRCV_BRANCH_API_ID,FRIF_E_INV_CTRL_IDX,E_NOT_OK);
/* @req FrIf05304 */
FRIF_DET_REPORTERROR(((FR_CHANNEL_A==FrIf_ChnlIdx)||(FR_CHANNEL_B==FrIf_ChnlIdx)),FRIF_ENABLE_TRCV_BRANCH_API_ID,FRIF_E_INV_CHNL_IDX,E_NOT_OK);
/* !req FrIf05306 */
(void)FrIf_BranchIdx;
return E_NOT_OK;
}
#endif
/* @req FrIf05421 */
/* @req FrIf05425 */
#if (FRIF_DIABLE_TRCV_BRANCH_SUPPORT == STD_ON)
/* !req FrIf05028 */
/**
*
* @param FrIf_CtrlIdx
* @param FrIf_ChnlIdx
* @param FrIf_BranchIdx
* @return
*/
Std_ReturnType FrIf_DisableTransceiverBranch( uint8 FrIf_CtrlIdx, Fr_ChannelType FrIf_ChnlIdx, uint8 FrIf_BranchIdx )
{
/* @req FrIf05298 */
/* @req FrIf05308 */
FRIF_DET_REPORTERROR((TRUE == FrIf_Internal_Global.initDone),FRIF_DISABLE_TRCV_BRANCH_API_ID,FRIF_E_NOT_INITIALIZED,E_NOT_OK);
/* @req FrIf05303 */
FRIF_DET_REPORTERROR((FrIf_CtrlIdx < FrIf_ConfigCachePtr->FrIf_CtrlCount),FRIF_DISABLE_TRCV_BRANCH_API_ID,FRIF_E_INV_CTRL_IDX,E_NOT_OK);
/* @req FrIf05243 */
FRIF_DET_REPORTERROR(((FR_CHANNEL_A==FrIf_ChnlIdx)||(FR_CHANNEL_B==FrIf_ChnlIdx)),FRIF_DISABLE_TRCV_BRANCH_API_ID,FRIF_E_INV_CHNL_IDX,E_NOT_OK);
/* !req FrIf05305 */
(void)FrIf_BranchIdx;
return E_NOT_OK;
}
#endif
/* @req FrIf05422 */
#if (FRIF_RECONFIG_LPDU_SUPPORT == STD_ON)
/* @req FrIf05048 */
/**
*
* @param FrIf_CtrlIdx
* @param FrIf_LPduIdx
* @param FrIf_FrameId
* @param FrIf_ChnlIdx
* @param FrIf_CycleRepetition
* @param FrIf_CycleOffset
* @param FrIf_PayloadLength
* @param FrIf_HeaderCRC
* @return
*/
Std_ReturnType FrIf_ReconfigLPdu( uint8 FrIf_CtrlIdx, uint16 FrIf_LPduIdx, uint16 FrIf_FrameId, Fr_ChannelType FrIf_ChnlIdx,
uint8 FrIf_CycleRepetition, uint8 FrIf_CycleOffset, uint8 FrIf_PayloadLength, uint16 FrIf_HeaderCRC)
{
const FrIf_ControllerType * ctrlCfg;
/* @req FrIf05298 */
FRIF_DET_REPORTERROR((TRUE == FrIf_Internal_Global.initDone),FRIF_RECONFIG_LPDU_API_ID,FRIF_E_NOT_INITIALIZED,E_NOT_OK);
/* @req FrIf05309 */
FRIF_DET_REPORTERROR((FrIf_CtrlIdx < FrIf_ConfigCachePtr->FrIf_CtrlCount),FRIF_RECONFIG_LPDU_API_ID,FRIF_E_INV_CTRL_IDX,E_NOT_OK);
/* @req FrIf05310 */
FRIF_DET_REPORTERROR(((FR_CHANNEL_A==FrIf_ChnlIdx)||(FR_CHANNEL_B==FrIf_ChnlIdx)),FRIF_RECONFIG_LPDU_API_ID,FRIF_E_INV_CHNL_IDX,E_NOT_OK);
ctrlCfg = &FrIf_ConfigCachePtr->FrIf_CtrlPtr[FrIf_CtrlIdx];
/* @req FrIf05311 */
FRIF_DET_REPORTERROR((FrIf_LPduIdx < ctrlCfg->FrIf_LPduCount),FRIF_RECONFIG_LPDU_API_ID,FRIF_E_INV_LPDU_IDX,E_NOT_OK);
FRIF_DET_REPORTERROR((TRUE == ctrlCfg->FrIf_LpduPtr[FrIf_LPduIdx].FrIf_Reconfigurable),FRIF_RECONFIG_LPDU_API_ID,FRIF_E_INV_LPDU_IDX,E_NOT_OK);
/* @req FrIf05312 */
FRIF_DET_REPORTERROR(((FrIf_FrameId >= FLEXRAY_FRAME_ID_MIN) && (FrIf_FrameId <= FLEXRAY_FRAME_ID_MAX)),FRIF_RECONFIG_LPDU_API_ID,FRIF_E_INV_FRAME_ID,E_NOT_OK);
return Fr_ReconfigLPdu(ctrlCfg->FrIf_FrCtrlIdx, ctrlCfg->FrIf_LpduPtr[FrIf_LPduIdx].Fr_Buffer, FrIf_FrameId, FrIf_ChnlIdx, FrIf_CycleRepetition, FrIf_CycleOffset, FrIf_PayloadLength, FrIf_HeaderCRC);
}
#endif
/* @req FrIf05423 */
#if (FRIF_GET_NM_VECTOR_SUPPORT == STD_ON)
/* !req FrIf05016 */
/**
*
* @param FrIf_CtrlIdx
* @param FrIf_NmVectorPtr
* @return
*/
/*lint --e{818} */
Std_ReturnType FrIf_GetNmVector( uint8 FrIf_CtrlIdx, uint8* FrIf_NmVectorPtr )
{
/* @req FrIf05298 */
/* @req FrIf05199 */
FRIF_DET_REPORTERROR((TRUE == FrIf_Internal_Global.initDone),FRIF_GET_NM_VECTOR_API_ID,FRIF_E_NOT_INITIALIZED,E_NOT_OK);
/* @req FrIf05197 */
FRIF_DET_REPORTERROR((FrIf_CtrlIdx < FrIf_ConfigCachePtr->FrIf_CtrlCount),FRIF_GET_NM_VECTOR_API_ID,FRIF_E_INV_CTRL_IDX,E_NOT_OK);
FRIF_DET_REPORTERROR((FrIf_NmVectorPtr != NULL),FRIF_GET_NM_VECTOR_API_ID,FRIF_E_INV_POINTER,E_NOT_OK);
/* !req FrIf05198 */
return E_NOT_OK;
}
#endif
/* @req FrIf05153 */ /* @req FrIf05154 */ /* @req FrIf05424 */
#if (FRIF_VERSION_INFO_API == STD_ON)
/* @req FrIf05002 */
/**
*
* @param FrIf_VersionInfoPtr
*/
void FrIf_GetVersionInfo( Std_VersionInfoType* FrIf_VersionInfoPtr )
{
/* @req FrIf05151 */
FRIF_DET_REPORTERROR((NULL != FrIf_VersionInfoPtr),FRIF_GET_VERSION_INFO_API_ID,FRIF_E_INV_POINTER);
/* @req FrIf05152 */
STD_GET_VERSION_INFO(FrIf_VersionInfoPtr, FRIF);
}
#endif
/* @req FrIf05313 */
/**
*
* @param FrIf_CtrlIdx
* @param FrIf_ConfigParamIdx
* @param FrIf_ConfigParamValuePtr
* @return
*/
Std_ReturnType FrIf_ReadCCConfig( uint8 FrIf_CtrlIdx, uint8 FrIf_ConfigParamIdx, uint32* FrIf_ConfigParamValuePtr )
{
uint8 frIdx;
/* @req FrIf05298 */
FRIF_DET_REPORTERROR((TRUE == FrIf_Internal_Global.initDone),FRIF_READ_CC_CONFIG_API_ID,FRIF_E_NOT_INITIALIZED,E_NOT_OK);
/* @req FrIf05315 */
FRIF_DET_REPORTERROR((FrIf_CtrlIdx < FrIf_ConfigCachePtr->FrIf_CtrlCount),FRIF_READ_CC_CONFIG_API_ID,FRIF_E_INV_CTRL_IDX,E_NOT_OK);
FRIF_DET_REPORTERROR((FrIf_ConfigParamValuePtr != NULL),FRIF_READ_CC_CONFIG_API_ID,FRIF_E_INV_POINTER,E_NOT_OK);
frIdx = FrIf_ConfigCachePtr->FrIf_CtrlPtr[FrIf_CtrlIdx].FrIf_FrCtrlIdx;
/* @req FrIf05314 */
return Fr_ReadCCConfig(frIdx,FrIf_ConfigParamIdx,FrIf_ConfigParamValuePtr);
}
/**
* @brief Handle Communication operation
* @param comOpPtr Pointer to Communication operation configuration
* @param frIfIdx Index of FrIf Ctrl
* @param Fr_LPduIdx LPdu index
* @param frameConfigIdx Frame configuration index
*/
static inline void comOperation(const FrIf_CommunicationOperationType * comOpPtr, uint8 frIfIdx,PduIdType Fr_LPduIdx, uint8 frameConfigIdx);
static inline void comOperation(const FrIf_CommunicationOperationType * comOpPtr, uint8 frIfIdx,PduIdType Fr_LPduIdx, uint8 frameConfigIdx)
{
switch (comOpPtr->FrIf_CommunicationAction) {
/* @req FrIf05063 */ /* @req FrIf05295a */
case DECOUPLED_TRANSMISSION:
FrIf_Internal_HandleDecoupledTransmission(frIfIdx,Fr_LPduIdx,frameConfigIdx);
break;
/* @req FrIf05064 */
case TX_CONFIRMATION:
FrIf_Internal_ProvideTxConfirmation(frIfIdx, Fr_LPduIdx, frameConfigIdx);
break;
/* @req FrIf05289 */
case RECEIVE_AND_STORE:
FrIf_Internal_HandleReceiveAndStore(frIfIdx,Fr_LPduIdx,frameConfigIdx);
break;
/* @req FrIf05292 */
case RECEIVE_AND_INDICATE:
FrIf_Internal_HandleReceiveAndIndicate(frIfIdx, Fr_LPduIdx, frameConfigIdx,
comOpPtr->FrIf_RxComOpMaxLoop);
break;
/* @req FrIf05062 */
case RX_INDICATION:
FrIf_Internal_ProvideRxIndication(frIfIdx, Fr_LPduIdx, frameConfigIdx);
break;
/* @req FrIf05061 */
case PREPARE_LPDU:
FrIf_Internal_PrepareLPdu(frIfIdx, Fr_LPduIdx);
break;
case FREE_OP_A:
case FREE_OP_B:
default:
/* Job operation is is invalid */
break;
}
}
/** ISRs */
/* @req FrIf05271 */
/**
* @brief Job list execution function handling all clusters
* @param clstrIdx
*/
void FrIf_JobListExec(uint8 clstrIdx) {
const FrIf_JobType * jobCfgPtr;
const FrIf_ClusterType * clstrCfg;
const FrIf_CommunicationOperationType * comOpPtr;
const FrIf_JobType * FrIf_NextJobConfigPtr;
uint16 macroTick;
PduIdType Fr_LPduIdx;
uint8 frIfCycle;
uint16 deviationFromGlobalTime=0;
uint8 i;
uint8 frameConfigIdx;
uint8 frIfIdx;
Std_ReturnType ret;
/* @req FrIf05298 */
/* @req FrIf05272 */
FRIF_DET_REPORTERROR((TRUE == FrIf_Internal_Global.initDone),FRIF_JOB_LIST_EXECUTE_API_ID,FRIF_E_NOT_INITIALIZED);
/* Data consistency of lower buffer is maintained by locking FrIf_JobListExec for one interrupt */
if (TRUE == FrIf_Internal_Global.clstrRunTimeData[clstrIdx].jobListExecLock ) {
/*lint -e{904} Return statement is necessary to avoid multiple if loops and hence increase readability in case of argument check */
return;
} else {
FrIf_Internal_Global.clstrRunTimeData[clstrIdx].jobListExecLock = TRUE;
}
clstrCfg = &FrIf_ConfigCachePtr->FrIf_ClusterPtr[clstrIdx];
frIfIdx = clstrCfg->FrIf_ControllerPtr[FIRST_FRIF_CTRL_IDX]->FrIf_CtrlIdx;
if(TRUE == FrIf_Internal_Global.clstrRunTimeData[clstrIdx].jobListSyncLost) {
FrIf_Internal_Global.clstrRunTimeData[clstrIdx].jobListExecLock = FALSE;
/* If synchronization is lost return */
} else {
/* @req FrIf05137 */ /* @req FrIf05138 */
if (FrIf_GetGlobalTime(frIfIdx, &frIfCycle, ¯oTick) == E_OK) {
ret = E_OK;
/* retrieve job cluster */
jobCfgPtr = &(clstrCfg->FrIf_JobListPtr->FrIf_JobPtr[FrIf_Internal_Global.clstrRunTimeData[clstrIdx].jobListCntr]);
/* check if synchronized to Global Time*/
if (macroTick > jobCfgPtr->FrIf_Macrotick) {
deviationFromGlobalTime = macroTick - (uint16)jobCfgPtr->FrIf_Macrotick;
} else {
deviationFromGlobalTime = (uint16)jobCfgPtr->FrIf_Macrotick - macroTick;
}
} else {
ret = E_NOT_OK;
}
/*lint -e{644} */
/* Check if not synchronized to Global time */
if ((ret != E_OK) || (deviationFromGlobalTime > clstrCfg->FrIf_MaxIsrDelay) || (frIfCycle != jobCfgPtr->FrIf_Cycle)) {
/* Set the flag */
FrIf_Internal_Global.clstrRunTimeData[clstrIdx].jobListSyncLost = TRUE;
/* Disable Absolute Timer interrupt */
(void)FrIf_CancelAbsoluteTimer(frIfIdx, clstrCfg->FrIf_JobListPtr->FrIf_AbsTimerIdx);
FrIf_Internal_Global.clstrRunTimeData[clstrIdx].jobListExecLock = FALSE;
FRIF_DET_REPORTERROR((FALSE == FrIf_Internal_Global.clstrRunTimeData[clstrIdx].jobListSyncLost),FRIF_JOB_LIST_EXECUTE_API_ID,FRIF_E_JLE_SYNC);
} else {
/* @req FrIf05133 */
/* Job is accomplished increase joblist counter*/
FrIf_Internal_Global.clstrRunTimeData[clstrIdx].jobListCntr = (FrIf_Internal_Global.clstrRunTimeData[clstrIdx].jobListCntr + 1)
%(clstrCfg->FrIf_JobListPtr->FrIf_NbrOfJobs);
/* get the start time of next job and set the CC timer */
FrIf_NextJobConfigPtr = &(clstrCfg->FrIf_JobListPtr->FrIf_JobPtr[FrIf_Internal_Global.clstrRunTimeData[clstrIdx].jobListCntr]);
/* re-trigg ISR timer to invoke next re-start of this joblist execution */
/* Acknowledge the absolute timer interrupts */
(void)FrIf_AckAbsoluteTimerIRQ(frIfIdx, clstrCfg->FrIf_JobListPtr->FrIf_AbsTimerIdx);
(void)FrIf_SetAbsoluteTimer(frIfIdx, clstrCfg->FrIf_JobListPtr->FrIf_AbsTimerIdx,
FrIf_NextJobConfigPtr->FrIf_Cycle, (uint16)FrIf_NextJobConfigPtr->FrIf_Macrotick);
/* @req FrIf05148 */
for (i = 0; i < jobCfgPtr->FrIf_NbrOfOperations; i++) {
/* get next operations in this job at correct start index in List of Operations */
comOpPtr = &(jobCfgPtr->FrIf_CommunicationOperationPtr[i]);
/* Retrieve Indexes for Controller and its Driver in order use appropriate FlexRay Driver */
frameConfigIdx = comOpPtr->FrIf_FrameConfigIdx;
Fr_LPduIdx = comOpPtr->FrIf_LPduIdxRef->Fr_Buffer;
if (FrIf_Internal_Global.clstrRunTimeData[clstrIdx].clstrState == FRIF_STATE_ONLINE) {
/* @req FrIf05050 */
/* @req FrIf05130 */
/* @req FrIf05134 */
frIfIdx = comOpPtr->FrIf_CtrlIdx; /* Get FrIf index for this communication operation */
comOperation(comOpPtr,frIfIdx,Fr_LPduIdx,frameConfigIdx);
}
}
}
FrIf_Internal_Global.clstrRunTimeData[clstrIdx].jobListExecLock = FALSE;
}
}
/* !req FrIf05041 */
/**
*
* @param FrIf_CtrlIdx
* @param FrIf_ChnlIdx
*/
void FrIf_CheckWakeupByTransceiver( uint8 FrIf_CtrlIdx, Fr_ChannelType FrIf_ChnlIdx )
{
/* @req FrIf05298 */
/* @req FrIf05277 */
FRIF_DET_REPORTERROR((TRUE == FrIf_Internal_Global.initDone),FRIF_CHECK_WUP_BY_TRCV_API_ID,FRIF_E_NOT_INITIALIZED);
/* @req FrIf05274 */
FRIF_DET_REPORTERROR((FrIf_CtrlIdx < FrIf_ConfigCachePtr->FrIf_CtrlCount),FRIF_CHECK_WUP_BY_TRCV_API_ID,FRIF_E_INV_CTRL_IDX);
/* @req FrIf05275 */
FRIF_DET_REPORTERROR(((FR_CHANNEL_A==FrIf_ChnlIdx)||(FR_CHANNEL_B==FrIf_ChnlIdx)),FRIF_CHECK_WUP_BY_TRCV_API_ID,FRIF_E_INV_CHNL_IDX);
/* !req FrIf05276 */
}
/** Scheduled APIs */
/**
* @brief Main function handling all cluster
* @param clstrIdx
*/
void FrIf_MainFunction(uint8 clstrIdx) {
const FrIf_ClusterType * clstrCfg; /* Pointer to cluster cfg */
const FrIf_JobType * jobCfgPtr=NULL;
uint32 jobExeTime;
uint32 currTime;
uint16 macroTicksPerCycle;
uint16 macroTick;
uint16 jitter;
uint8 job;
uint8 cycle;
uint8 timerIdx;
uint8 frIfIdx;
boolean foundNextJob;
/* @req FrIf05279 clstrIdx */
/* @req FrIf05298 */
/* @req FrIf05280 */
FRIF_DET_REPORTERROR((TRUE == FrIf_Internal_Global.initDone),FRIF_MAINFUNCTION_API_ID,FRIF_E_NOT_INITIALIZED);
clstrCfg = &FrIf_ConfigCachePtr->FrIf_ClusterPtr[clstrIdx];
frIfIdx = clstrCfg->FrIf_ControllerPtr[FIRST_FRIF_CTRL_IDX]->FrIf_CtrlIdx; /* Find FrIf Controller Id for the first controller in the cluster */
if (FrIf_Internal_Global.clstrRunTimeData[clstrIdx].clstrState == FRIF_STATE_ONLINE) {
/* @req FrIf05120a */
jitter = (clstrCfg->FrIf_GdStaticSlots * MIN_SLOT_DURATION_FOR_NEXT_JOB); /* slot duration offset for next job activation */
macroTicksPerCycle = clstrCfg->FrIf_GMacroPerCycle; /* macroticks per cycle */
foundNextJob = FALSE;
timerIdx = clstrCfg->FrIf_JobListPtr->FrIf_AbsTimerIdx;
if (TRUE == FrIf_Internal_Global.clstrRunTimeData[clstrIdx].jobListSyncLost) {
/* Find the next job */
/* @req FrIf05120i */
if (FrIf_GetGlobalTime(frIfIdx, &cycle, ¯oTick) == E_OK) {
for (job = 0; job < clstrCfg->FrIf_JobListPtr->FrIf_NbrOfJobs; job++) {
jobCfgPtr = &(clstrCfg->FrIf_JobListPtr->FrIf_JobPtr[job]);
jobExeTime = ((uint32)jobCfgPtr->FrIf_Cycle * macroTicksPerCycle) + jobCfgPtr->FrIf_Macrotick; /* Job execution absolute time */
currTime = ((uint32)cycle * macroTicksPerCycle) + macroTick; /* current absolute time */
/* Determine if there is sufficient time to schedule next job */
if (jobExeTime > (currTime + jitter)) {
FrIf_Internal_Global.clstrRunTimeData[clstrIdx].jobListCntr = job; /* Find next job */
foundNextJob = TRUE;
break;
}
}
if (FALSE == foundNextJob) {
/*No later job found, then begin with the first Job */
jobCfgPtr = &(clstrCfg->FrIf_JobListPtr->FrIf_JobPtr[FIRST_JOB_IDX]);
FrIf_Internal_Global.clstrRunTimeData[clstrIdx].jobListCntr = FIRST_JOB_IDX;
}
FrIf_Internal_Global.clstrRunTimeData[clstrIdx].jobListSyncLost = FALSE;
(void)FrIf_AckAbsoluteTimerIRQ(frIfIdx, timerIdx); /* Might be a interrupt waiting */
(void)FrIf_EnableAbsoluteTimerIRQ(frIfIdx, timerIdx); /* Enable absolute timer */
if(jobCfgPtr!=NULL){
(void)FrIf_SetAbsoluteTimer(frIfIdx, timerIdx, jobCfgPtr->FrIf_Cycle, (uint16)jobCfgPtr->FrIf_Macrotick); /* Set absolute timer */
}
}
}
}
}
|
2301_81045437/classic-platform
|
communication/FrIf/src/FrIf.c
|
C
|
unknown
| 65,003
|
/*-------------------------------- 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 "FrIf.h"
#include "FrIf_Internal.h"
extern FrIf_Internal_GlobalType FrIf_Internal_Global;
extern const FrIf_ConfigType *FrIf_ConfigCachePtr;
static void markUB(sint16 pduUBOffset, FrIf_PduUpdateBitType pduUBSts, uint8 *frSduPtr);
static FrIf_PduUpdateBitType readUB(sint16 pduUBOffset,const uint8 *frSduPtr);
/**
* @brief Mark Update bit as updated/out dated
* @param pduUBOffset Used to locate the update bit.
* @param pduUBSts Value of the update bit.
* @param frSduPtr Pointer to SDU.
*
*
*/
static void markUB(sint16 pduUBOffset, FrIf_PduUpdateBitType pduUBSts, uint8 *frSduPtr)
{
uint8 dataByte;
uint8 bytePos;
uint8 bitPos;
if (pduUBOffset > -1) {
bytePos = (uint8)((uint16)pduUBOffset / 8u);
bitPos = (uint16)pduUBOffset % 8u;
dataByte = frSduPtr[bytePos];
if (pduUBSts == PDU_UPDATED) {
/* set update bit as updated */
dataByte |= (uint8)(1u << bitPos);
} else {
/* set update bit as outdated */
dataByte = dataByte & ~(1u << bitPos);
}
/* write back Pdu update info */
frSduPtr[bytePos] = dataByte;
}
}
/**
* @brief Reads the Pdu Update Bit in the sdu.
* @param pduUBOffset Used to locate the update bit.
* @param frSduPtr Pointer to SDU.
*
*/
static FrIf_PduUpdateBitType readUB(sint16 pduUBOffset, const uint8 *frSduPtr)
{
uint8 dataByte;
uint8 bytePos;
uint8 bitPos;
FrIf_PduUpdateBitType ret;
if (pduUBOffset > -1) {
bytePos = (uint8)((uint16)pduUBOffset / 8u);
bitPos = (uint16)pduUBOffset % 8u;
dataByte = frSduPtr[bytePos];
if ((dataByte & (1u << bitPos)) > 0) {
ret = PDU_UPDATED;
} else {
ret = PDU_OUTDATED;
}
} else {
/* @req FrIf05128 */
ret = PDU_UPDATED;
}
return ret;
}
/**
* @brief Get the valid length of a received Pdu (Useful in the case of dynamic segment which can possibly receive LSdu length lesser than configured LSdu length)
* @param RxPduLength - Configured length of the composite Pdu in a LSdu
* @param pduOffset - Starting byte position of the composite Pdu
* @param pduUBOffset - Offset of Pdu UB position
* @param Fr_LSduLength - Total received LSdu
* @return Computed length of the composite Pdu (For Static segment it is RxPduLength because received LSdu length is equal to configured LSdu length)
*/
#if (FR_RX_STRINGENT_LENGTH_CHECK == STD_OFF)
uint8 getValidLength(uint8 rxPduLength, uint8 pduOffset, sint16 pduUBOffset, uint8 lSduLen);
uint8 getValidLength(uint8 rxPduLength, uint8 pduOffset, sint16 pduUBOffset, uint8 lSduLen) {
uint8 len;
if ((pduOffset + rxPduLength) <= lSduLen) {
len = rxPduLength;
} else if ((pduOffset < lSduLen) && (pduUBOffset < pduOffset)){
/* The UB position is either before the PduOffset or after an offset of PduLength. In
* this condition we expect it to before PduOffset */
len = lSduLen - pduOffset;
} else {
len = 0;
}
return len;
}
#endif
/**
* @brief Transmits FlexRay frame by getting desired Pdus from upper layer PDuR.
* @param frIfIdx FrIf Controller id.
* @param frLPduIdx Fr LPdu Index
* @param frameCfgIdx FrameTriggering id.
*
*
*/
void FrIf_Internal_HandleDecoupledTransmission(uint8 frIfIdx,PduIdType frLPduIdx, uint8 frameCfgIdx)
{
const FrIf_TxPduType * txPduCfgPtr; /* Pointer to Tx pdu cfg */
const FrIf_FrameTriggeringType * frameTrigCfgPtr; /* Frame Triggering cfg Ptr */
const FrIf_FrAPIType *myFuncPtr; /* Pointer to Fr driver cfg */
const FrIf_PdusIn_FrameType * pduInFramePtr; /* Pdus in Frame cfg ptr */
uint8 * tempBuffPtr; /* Buffer pointer to temporary data */
uint8 frCCIdx; /* Fr CC index */
uint8 frameStructIdx; /* Frame structure index */
FrIf_PduUpdateBitType pduSts; /* Base case if no PDU is updated */
sint16 pduUBOffset;
uint8 pduCnt;
PduIdType pduId;
uint8 pduOffset;
boolean resFlag;
Std_ReturnType ret;
PduInfoType pduInfo;
#if (FRIF_BIG_ENDIAN_USED == STD_ON)
uint8 tempBuffForBigEndian[FLEXRAY_FRAME_LEN_MAX] = {0};
uint8 pduLastByteIndex = 0;
#endif
frameTrigCfgPtr = &(FrIf_ConfigCachePtr->FrIf_CtrlPtr[frIfIdx].FrIf_FrameTriggeringPtr[frameCfgIdx]);
frameStructIdx = frameTrigCfgPtr->FrIf_FrameStructureIdx;
frCCIdx = FrIf_ConfigCachePtr->FrIf_CtrlPtr[frIfIdx].FrIf_FrCtrlIdx;
tempBuffPtr = FrIf_Internal_Global.lSduBuffer[frameStructIdx];
pduSts = PDU_OUTDATED; /* Set initial LSdu state has outdated */
/* @req FrIf05287 */
/* Iterate over all PDU's in the FrameStructure */
for (pduCnt = 0; pduCnt < frameTrigCfgPtr->FrIf_NumberPdusInFrame; pduCnt++) {
ret = E_OK;
pduInFramePtr = &(frameTrigCfgPtr->FrIf_FrameStructureRef->FrIf_PdusInFramePtr[pduCnt]);
pduId = pduInFramePtr->FrIf_Pdu->FrIf_PduId;
pduOffset = pduInFramePtr->FrIf_PduOffset; /* Determine Pdu's offset in frame */
pduUBOffset = pduInFramePtr->FrIf_PduUpdateBitOffset; /* @req FrIf05125 */ /* Determine bit to mark */
txPduCfgPtr = pduInFramePtr->FrIf_Pdu->FrIf_PduDirectionPtr->FrIf_TxPduPtr;
pduInfo.SduDataPtr = &tempBuffPtr[pduOffset];
#if (FRIF_BIG_ENDIAN_USED == STD_ON)
if (FRIF_BIG_ENDIAN == frameTrigCfgPtr->FrIf_FrameStructureRef->FrIf_ByteOrder){
pduInfo.SduDataPtr = & tempBuffForBigEndian[0]; /* re-ordering of buffer ptr to support big-endian */
pduLastByteIndex = txPduCfgPtr->FrIf_TxLength-1;
}
#endif
pduInfo.SduLength = txPduCfgPtr->FrIf_TxLength;
resFlag = ((FrIf_Internal_Global.txPduStatistics[pduId].trigTxCounter > 0)
|| (TRUE == pduInFramePtr->FrIf_Pdu->FrIf_PduDirectionPtr->FrIf_TxPduPtr->FrIf_NoneMode));
if (TRUE == resFlag) {
/* Start trigger transmit process */
if ((txPduCfgPtr->FrIf_UserTriggerTransmitHandle != FRIF_NO_FUNCTION_CALLOUT) &&
(NULL_PTR != FrIf_ConfigCachePtr->FrIf_TriggerTransmitFncs[txPduCfgPtr->FrIf_UserTriggerTransmitHandle]))
{
ret = FrIf_ConfigCachePtr->FrIf_TriggerTransmitFncs[txPduCfgPtr->FrIf_UserTriggerTransmitHandle](pduInFramePtr->FrIf_Pdu->FrIf_UpperLayerPduId, &pduInfo);
}
/* In case upper layer trigger transmit does not return E_OK reset the update-bit to "not updated" */
if (ret != E_OK) {
markUB(pduUBOffset, PDU_OUTDATED, tempBuffPtr);
} else {
#if (FRIF_BIG_ENDIAN_USED == STD_ON)
/*re-ordering is executed for big-endian format*/
if (FRIF_BIG_ENDIAN == frameTrigCfgPtr->FrIf_FrameStructureRef->FrIf_ByteOrder){
for(uint8 i=0; i<=pduLastByteIndex; i++){
tempBuffPtr[pduOffset+i] = tempBuffForBigEndian[pduLastByteIndex-i];
}
}
#endif
/* mark this Pdu as updated */
pduSts = PDU_UPDATED;
/* Set update bit if configured for this PDU */
markUB(pduUBOffset, PDU_UPDATED, tempBuffPtr);
}
} else {
/* Clear update bit for the pdu and proceed with the next PDU */
markUB(pduUBOffset, PDU_OUTDATED, tempBuffPtr);
}
}
/* At least one Pdu is updated or the frame should always be transmitted */
if ((pduSts == PDU_UPDATED) || (TRUE == frameTrigCfgPtr->FrIf_AlwaysTransmit)) {
/* locate this driver api*/
myFuncPtr = (FrIf_ConfigCachePtr->Fr_Driver_ConfigPtr[FRIF_DRIVER_0].FrIf_FrAPIPtr);
ret = (*myFuncPtr->Fr_TransmitTxLPdu)(frCCIdx, frLPduIdx, tempBuffPtr, frameTrigCfgPtr->FrIf_LSduLength);
/* If transmission is OK, update trigTxCounter and txConfCounter */
if (ret == E_OK) {
for (pduCnt = 0; pduCnt < frameTrigCfgPtr->FrIf_NumberPdusInFrame; pduCnt++) {
pduInFramePtr = &(frameTrigCfgPtr->FrIf_FrameStructureRef->FrIf_PdusInFramePtr[pduCnt]);
pduId = pduInFramePtr->FrIf_Pdu->FrIf_PduId;
/* @req FrIf05058 */ /* Decrement trigTxCounter only if trigTxCounter > 0 */
if (FrIf_Internal_Global.txPduStatistics[pduId].trigTxCounter > 0) {
FrIf_Internal_Global.txPduStatistics[pduId].trigTxCounter--;
}
/* Remember that a transmission for this PDU is pending if transmission confirmation is needed */
resFlag = ((TRUE == pduInFramePtr->FrIf_Pdu->FrIf_PduDirectionPtr->FrIf_TxPduPtr->FrIf_Confirm)
&& (FrIf_Internal_Global.txPduStatistics[pduId].txConfCounter
< pduInFramePtr->FrIf_Pdu->FrIf_PduDirectionPtr->FrIf_TxPduPtr->FrIf_CounterLimit));
if (TRUE == resFlag) {
/* Only increment if counter limit has not been reached */
FrIf_Internal_Global.txPduStatistics[pduId].txConfCounter++;
}
}
}
}
}
/**
* @brief Provides information about transmission status.
* @param frIfIdx FrIf Controller id.
* @param frLPduIdx LPdu id.
* @param frameCfgIdx Frame triggering id.
*
*/
void FrIf_Internal_ProvideTxConfirmation(uint8 frIfIdx, PduIdType frLPduIdx, uint8 frameCfgIdx)
{
const FrIf_TxPduType * txPduCfgPtr; /* Pointer to Tx pdu cfg */
const FrIf_FrameTriggeringType * frameTrigCfgPtr; /* Frame Triggering cfg Ptr */
const FrIf_FrAPIType *myFuncPtr; /* Pointer to Fr driver cfg */
const FrIf_PdusIn_FrameType * pduInFramePtr; /* Pdus in Frame cfg ptr */
uint8 frCCIdx; /* Fr CC index */
uint8 pduCnt;
PduIdType pduId;
Std_ReturnType ret;
Fr_TxLPduStatusType frTxLPduStsPtr;
frameTrigCfgPtr = &(FrIf_ConfigCachePtr->FrIf_CtrlPtr[frIfIdx].FrIf_FrameTriggeringPtr[frameCfgIdx]); /* Pointer to the Frame struct in the PB configuration file*/
frCCIdx = FrIf_ConfigCachePtr->FrIf_CtrlPtr[frIfIdx].FrIf_FrCtrlIdx;
/* @req FrIf05288 */
/* Locate this driver api */
myFuncPtr = (FrIf_ConfigCachePtr->Fr_Driver_ConfigPtr[FRIF_DRIVER_0].FrIf_FrAPIPtr);
ret = (*myFuncPtr->Fr_CheckTxLPduStatus)(frCCIdx, frLPduIdx, &frTxLPduStsPtr);
/* If output parameter is equal to FR_TRANSMITTED, iterate over all PDUs in the frame structure */
if ((E_OK == ret) && (frTxLPduStsPtr == FR_TRANSMITTED)) {
for (pduCnt = 0; pduCnt < frameTrigCfgPtr->FrIf_NumberPdusInFrame; pduCnt++) {
pduInFramePtr = &(frameTrigCfgPtr->FrIf_FrameStructureRef->FrIf_PdusInFramePtr[pduCnt]);
pduId = pduInFramePtr->FrIf_Pdu->FrIf_PduId;
if (FrIf_Internal_Global.txPduStatistics[pduId].txConfCounter == 0) {
/* Do nothing */
} else {
txPduCfgPtr = pduInFramePtr->FrIf_Pdu->FrIf_PduDirectionPtr->FrIf_TxPduPtr;
if (TRUE == txPduCfgPtr->FrIf_Confirm) {
/* Call upper layer Tx Confirmation */
if ((txPduCfgPtr->FrIf_TxConfirmationHandle != FRIF_NO_FUNCTION_CALLOUT) &&
(NULL_PTR != FrIf_ConfigCachePtr->FrIf_TxConfirmationFncs[txPduCfgPtr->FrIf_TxConfirmationHandle]))
{
FrIf_ConfigCachePtr->FrIf_TxConfirmationFncs[txPduCfgPtr->FrIf_TxConfirmationHandle](pduInFramePtr->FrIf_Pdu->FrIf_UpperLayerPduId);
}
/* Decrement txConfCounter */
FrIf_Internal_Global.txPduStatistics[pduId].txConfCounter--;
} else {
/* Do nothing */
}
}
}
}
}
/**
* @brief Receive a message and store it.
* @param frIfIdx FrIf controller id.
* @param frLPduIdx LPdu id.
* @param frameCfgIdx Frame triggering id.
*/
void FrIf_Internal_HandleReceiveAndStore(uint8 frIfIdx, PduIdType frLPduIdx, uint8 frameCfgIdx)
{
const FrIf_FrameTriggeringType * frameTrigCfgPtr; /* Frame Triggering cfg Ptr */
const FrIf_FrAPIType *myFuncPtr; /* Driver pointer */
const FrIf_PdusIn_FrameType * pduInFramePtr; /* Pdus in Frame cfg ptr */
const FrIf_RxPduType * rxPduCfgPtr; /* Pointer to Rx pdu cfg */
uint8 * tempBuffPtr; /* Pointer to temporary buffer */
PduIdType pduId;
sint16 pduUBOffset;
uint8 pduOffset;
Fr_RxLPduStatusType frRxLPduStsPtr; /* Declare the output parameter for Fr_ReceiveRxLPdu */
uint8 frameStructIdx; /* Frame structure index */
Std_ReturnType ret;
uint8 pduCnt;
uint8 frCCIdx; /* Fr CC index */
uint8 rxLen;
uint8 pduLen;
uint8 * sduBuffPtr;
/* @req FrIf05290 */
frameTrigCfgPtr = &(FrIf_ConfigCachePtr->FrIf_CtrlPtr[frIfIdx].FrIf_FrameTriggeringPtr[frameCfgIdx]);
frameStructIdx = frameTrigCfgPtr->FrIf_FrameStructureIdx;
frCCIdx = FrIf_ConfigCachePtr->FrIf_CtrlPtr[frIfIdx].FrIf_FrCtrlIdx;
myFuncPtr = (FrIf_ConfigCachePtr->Fr_Driver_ConfigPtr[FRIF_DRIVER_0].FrIf_FrAPIPtr); /* Locate this driver api */
sduBuffPtr = FrIf_Internal_Global.lSduBuffer[frameStructIdx];
tempBuffPtr = sduBuffPtr;
#if (FRIF_BIG_ENDIAN_USED == STD_ON)
uint8 tempBuffForBigEndian[FLEXRAY_FRAME_LEN_MAX];
if (frameTrigCfgPtr->FrIf_FrameStructureRef->FrIf_ByteOrder == FRIF_BIG_ENDIAN) {
tempBuffPtr = &tempBuffForBigEndian[0];
}
#endif
/* Call Driver's APT function */
ret = (*myFuncPtr->Fr_ReceiveRxLPdu)(frCCIdx, frLPduIdx, tempBuffPtr, &frRxLPduStsPtr, &rxLen);
/* If a LPDU was received iterate over all PDUs in the frame structure */
if ((E_OK == ret) && (frRxLPduStsPtr == FR_RECEIVED)) {
/* Iterate over all PDU's in the FrameStructure */
for (pduCnt = 0; pduCnt < frameTrigCfgPtr->FrIf_NumberPdusInFrame; pduCnt++) {
pduInFramePtr = &(frameTrigCfgPtr->FrIf_FrameStructureRef->FrIf_PdusInFramePtr[pduCnt]);
pduOffset = pduInFramePtr->FrIf_PduOffset; /* Determine Pdu's offset in frame */
pduId = pduInFramePtr->FrIf_Pdu->FrIf_PduId;/* Get the ID of the PDU in the frame */
/* @req FrIf05125 */
pduUBOffset = pduInFramePtr->FrIf_PduUpdateBitOffset; /* Determine UB pos */
rxPduCfgPtr = pduInFramePtr->FrIf_Pdu->FrIf_PduDirectionPtr->FrIf_RxPduPtr;
#if (FRIF_BIG_ENDIAN_USED == STD_ON)
if (frameTrigCfgPtr->FrIf_FrameStructureRef->FrIf_ByteOrder == FRIF_BIG_ENDIAN) {
FrIf_Internal_SwapToBigEndian(&tempBuffPtr[pduOffset],&sduBuffPtr[pduOffset], rxPduCfgPtr->RxPduLength);
}
#endif
#if (FR_RX_STRINGENT_LENGTH_CHECK == STD_OFF)
pduLen = getValidLength(rxPduCfgPtr->RxPduLength, pduOffset, pduUBOffset, rxLen);
#else
pduLen = rxPduCfgPtr->RxPduLength;
#endif
/* @req FrIf05056 */
if ((readUB(pduUBOffset, tempBuffPtr) == PDU_UPDATED) && (pduLen > 0)) {
/* Mark the PDU-related static buffer as up-to-date */
FrIf_Internal_Global.rxPduStatistics[pduId].pduUpdated = TRUE;
FrIf_Internal_Global.rxPduStatistics[pduId].pduRxLen = pduLen;
}
}
}
}
/**
* @brief Receives an FlexRay frame and indicates upper layer PduR by callback.
* @param frIfIdx FrIf Controller id
* @param frLPduIdx LPdu id
* @param frameCfgIdx Frame Triggering id
* @param maxLoop configured max number of loops for Receive and Indicate
*
*/
void FrIf_Internal_HandleReceiveAndIndicate(uint8 frIfIdx, PduIdType frLPduIdx, uint8 frameCfgIdx, uint16 maxLoop )
{
const FrIf_FrameTriggeringType * frameTrigCfgPtr; /* Frame Triggering cfg Ptr */
const FrIf_FrAPIType *myFuncPtr; /* Driver pointer */
const FrIf_PdusIn_FrameType * pduInFramePtr; /* Pdus in Frame cfg ptr */
const FrIf_RxPduType * rxPduCfgPtr; /* Pointer to Rx pdu cfg */
uint8 * tempBuffPtr; /* Pointer to temporary buffer */
uint16 ComOpLoopCounter; /* Loop counter */
sint16 pduUBOffset;
uint8 frameStructIdx; /* Frame structure index */
PduInfoType pduInfo;
Std_ReturnType ret;
uint8 pduCnt;
uint8 pduOffset;
Fr_RxLPduStatusType frRxLPduStsPtr; /* Declare the output parameter for Fr_ReceiveRxLPdu */
uint8 frCCIdx;
uint8 rxLen;
uint8 pduLen;
uint8 * sduBuffPtr;
uint16 ChannelAStatusPtr;
uint16 ChannelBStatusPtr;
frameTrigCfgPtr = &(FrIf_ConfigCachePtr->FrIf_CtrlPtr[frIfIdx].FrIf_FrameTriggeringPtr[frameCfgIdx]); /* Pointer to the Frame struct in the PB configuration file*/
frameStructIdx = frameTrigCfgPtr->FrIf_FrameStructureIdx;
frCCIdx = FrIf_ConfigCachePtr->FrIf_CtrlPtr[frIfIdx].FrIf_FrCtrlIdx;
sduBuffPtr = FrIf_Internal_Global.lSduBuffer[frameStructIdx];
tempBuffPtr = sduBuffPtr;
#if (FRIF_BIG_ENDIAN_USED == STD_ON)
uint8 tempBuffForBigEndian[FLEXRAY_FRAME_LEN_MAX];
if (frameTrigCfgPtr->FrIf_FrameStructureRef->FrIf_ByteOrder == FRIF_BIG_ENDIAN) {
tempBuffPtr = &tempBuffForBigEndian[0];
}
#endif
/* @req FrIf05293 */
/* Locate this driver api */
myFuncPtr = (FrIf_ConfigCachePtr->Fr_Driver_ConfigPtr[FRIF_DRIVER_0].FrIf_FrAPIPtr);
ComOpLoopCounter = 0;
do {
ret = (*myFuncPtr->Fr_ReceiveRxLPdu)(frCCIdx, frLPduIdx, tempBuffPtr, &frRxLPduStsPtr, &rxLen);
if ((E_OK == ret) && (frRxLPduStsPtr != FR_NOT_RECEIVED)) {
/* Iterate over all PDU's in the FrameStructure */
for (pduCnt = 0; pduCnt < frameTrigCfgPtr->FrIf_NumberPdusInFrame; pduCnt++) {
pduInFramePtr = &(frameTrigCfgPtr->FrIf_FrameStructureRef->FrIf_PdusInFramePtr[pduCnt]);
pduOffset = pduInFramePtr->FrIf_PduOffset; /* Determine Pdu's offset in frame */
/* @req FrIf05125 */
pduUBOffset = pduInFramePtr->FrIf_PduUpdateBitOffset; /* Determine UB pos */
rxPduCfgPtr = pduInFramePtr->FrIf_Pdu->FrIf_PduDirectionPtr->FrIf_RxPduPtr;
#if (FRIF_BIG_ENDIAN_USED == STD_ON)
if (frameTrigCfgPtr->FrIf_FrameStructureRef->FrIf_ByteOrder == FRIF_BIG_ENDIAN) {
FrIf_Internal_SwapToBigEndian(&tempBuffPtr[pduOffset],&sduBuffPtr[pduOffset], rxPduCfgPtr->RxPduLength);
}
#endif
#if (FR_RX_STRINGENT_LENGTH_CHECK == STD_OFF)
pduLen = getValidLength(rxPduCfgPtr->RxPduLength, pduOffset, pduUBOffset, rxLen);
#else
pduLen = rxPduCfgPtr->RxPduLength;
#endif
/* @req FrIf05056 */
if ((readUB(pduUBOffset, tempBuffPtr) == PDU_UPDATED) && (pduLen > 0)) {
pduInfo.SduDataPtr = &sduBuffPtr[pduOffset];
pduInfo.SduLength = pduLen;
if ((rxPduCfgPtr->FrIf_RxIndicationHandle != FRIF_NO_FUNCTION_CALLOUT) &&
(NULL_PTR != FrIf_ConfigCachePtr->FrIf_RxIndicationFncs[rxPduCfgPtr->FrIf_RxIndicationHandle]))
{
FrIf_ConfigCachePtr->FrIf_RxIndicationFncs[rxPduCfgPtr->FrIf_RxIndicationHandle](pduInFramePtr->FrIf_Pdu->FrIf_UpperLayerPduId, &pduInfo);
}
}
}
} else {
/* The communication operation is finished.*/
if (ret == E_NOT_OK) {
/* Recover from ACS (Aggregated Channel Status) errors.
* Fr_GetChannelStatus resets the ACS information */
(void) Fr_GetChannelStatus(frCCIdx, &ChannelAStatusPtr, &ChannelBStatusPtr);
}
break;
}
if (frRxLPduStsPtr == FR_RECEIVED_MORE_DATA_AVAILABLE) {
ComOpLoopCounter++;
} else {
/*lint -e{9011} we need to terminate loop*/
break;
}
} while (ComOpLoopCounter < maxLoop);
}
/**
* @brief Calls upper layer functions if there is an updated frame.
* @param frIfIdx FrIf Controller id.
* @param frLPduIdx LPdu id.
* @param frameCfgIdx Frame triggering id.
*/
void FrIf_Internal_ProvideRxIndication(uint8 frIfIdx, PduIdType frLPduIdx, uint8 frameCfgIdx )
{
const FrIf_FrameTriggeringType * frameTrigCfgPtr; /* Frame Triggering cfg Ptr */
const FrIf_PdusIn_FrameType * pduInFramePtr; /* Pdus in Frame cfg ptr */
const FrIf_RxPduType * rxPduCfgPtr; /* Pointer to Rx pdu cfg */
uint8 * tempBuffPtr; /* Pointer to temporary buffer */
uint8 frameStructIdx; /* Frame structure index */
PduIdType pduId;
uint8 pduOffset;
PduInfoType pduInfo;
uint8 pduCnt;
/* @req FrIf05291 */
frameTrigCfgPtr = &(FrIf_ConfigCachePtr->FrIf_CtrlPtr[frIfIdx].FrIf_FrameTriggeringPtr[frameCfgIdx]);
frameStructIdx = frameTrigCfgPtr->FrIf_FrameStructureIdx;
tempBuffPtr = FrIf_Internal_Global.lSduBuffer[frameStructIdx];
/* Iterate over all PDU's in the FrameStructure */
for (pduCnt = 0; pduCnt < frameTrigCfgPtr->FrIf_NumberPdusInFrame; pduCnt++) {
pduInFramePtr = &(frameTrigCfgPtr->FrIf_FrameStructureRef->FrIf_PdusInFramePtr[pduCnt]);
pduId = pduInFramePtr->FrIf_Pdu->FrIf_PduId;/* Get the ID of the PDU in the frame */
/* Check if static buffer is marked as outdated */
if (TRUE == FrIf_Internal_Global.rxPduStatistics[pduId].pduUpdated) {
pduOffset = pduInFramePtr->FrIf_PduOffset; /* Determine Pdu's offset in frame */
rxPduCfgPtr = pduInFramePtr->FrIf_Pdu->FrIf_PduDirectionPtr->FrIf_RxPduPtr;
pduInfo.SduDataPtr = &tempBuffPtr[pduOffset];
pduInfo.SduLength = FrIf_Internal_Global.rxPduStatistics[pduId].pduRxLen;
/* Call the upper layer's function <UL>_RxIndication */
if ((rxPduCfgPtr->FrIf_RxIndicationHandle != FRIF_NO_FUNCTION_CALLOUT) &&
(NULL_PTR != FrIf_ConfigCachePtr->FrIf_RxIndicationFncs[rxPduCfgPtr->FrIf_RxIndicationHandle]))
{
FrIf_ConfigCachePtr->FrIf_RxIndicationFncs[rxPduCfgPtr->FrIf_RxIndicationHandle](pduInFramePtr->FrIf_Pdu->FrIf_UpperLayerPduId, &pduInfo);
} else {
/* Do nothing */
}
/* Mark the PDU-related static buffer as outdated */
FrIf_Internal_Global.rxPduStatistics[pduId].pduUpdated = FALSE;
}
}
(void)frLPduIdx;
}
/**
* @brief wraps the Fr_PrepareLPdu
* @param frIfIdx FrIf Ctrl Idx
* @param frLPduIdx Fr LPdu Idx
*/
void FrIf_Internal_PrepareLPdu(uint8 frIfIdx, PduIdType frLPduIdx)
{
const FrIf_FrAPIType *myFuncPtr; /* Driver pointer */
uint8 frCCIdx; /* Fr CC index */
/* @req FrIf05294 */
/* Locate this driver api */
myFuncPtr = (FrIf_ConfigCachePtr->Fr_Driver_ConfigPtr[FRIF_DRIVER_0].FrIf_FrAPIPtr);
frCCIdx = FrIf_ConfigCachePtr->FrIf_CtrlPtr[frIfIdx].FrIf_FrCtrlIdx;
if (myFuncPtr->Fr_PrepareLPdu != NULL) {
(void)(*myFuncPtr->Fr_PrepareLPdu)(frCCIdx, frLPduIdx);
}
}
#ifdef HOST_TEST
FrIf_Internal_txPduStatisticsType readPduStatistics(PduIdType pduId)
{
return FrIf_Internal_Global.txPduStatistics[pduId];
}
#endif
#if (FRIF_BIG_ENDIAN_USED == STD_ON)
/**
* Used to swap the byte order.
* @param srcBuffer
* @param destBuffer
* @param length
*/
void FrIf_Internal_SwapToBigEndian(const uint8 *srcBuffer,uint8 *destBuffer, uint8 length) {
uint8 i;
for (i = 0; i < length; i++) {
destBuffer[i] = srcBuffer[(length - 1U)-i];
}
}
#endif
|
2301_81045437/classic-platform
|
communication/FrIf/src/FrIf_Internal.c
|
C
|
unknown
| 25,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 -----------------------------*/
#ifndef FRIF_INTERNAL_H_
#define FRIF_INTERNAL_H_
#include "FrIf.h"
//lint -emacro(904,FRIF_DET_REPORTERROR) //904 PC-Lint exception to MISRA 14.7 (validate DET macros).
/** PduInfo run time data */
typedef struct {
boolean pduUpdated; /* Rx update status */
uint8 pduRxLen; /* Length of latest Pdu received */
} FrIf_Internal_rxPduStatisticsType;
/** Cluster runtime properties */
typedef struct {
FrIf_StateType clstrState; /* Internal State Machine for each cluster*/
uint8 jobListCntr; /* Job list counter for each cluster */
boolean jobListSyncLost; /* Flag to indicate loss of joblist synchronization */
boolean jobListExecLock; /* Lock FrIf_JobListExec function for only one interrupt */
boolean interruptEnableSts; /* Flag to indicate if interrupts are enabled for job list function */
} FrIf_Internal_ClusterRuntimeType;
/** Call back functions */
typedef struct {
uint8 trigTxCounter; /* Tx tiggering counter */
uint8 txConfCounter; /* Tx confirmation*/
} FrIf_Internal_txPduStatisticsType;
typedef struct {
uint8 lSduBuffer[FRIF_MAX_N_LPDU][FRIF_MAX_LPDU_LEN]; /* LSdu buffers to hold each frame structure*/
FrIf_Internal_rxPduStatisticsType rxPduStatistics[FRIF_MAX_N_RX_PDU]; /* Pointer to run time Rx Pdu status */
FrIf_Internal_txPduStatisticsType txPduStatistics[FRIF_MAX_N_TX_PDU]; /* Pdu statistics for Tx LPdus*/
FrIf_Internal_ClusterRuntimeType clstrRunTimeData[FRIF_MAX_N_CLUSTER]; /* Runtime properties of cluster */
boolean initDone; /* Init status */
}FrIf_Internal_GlobalType;
#if (FRIF_DEV_ERROR_DETECT == STD_ON)/* @req FrIf05146 */
#define FRIF_DET_REPORTERROR(_cond ,_api, _error, ...) \
if (!_cond) { \
(void)Det_ReportError(FRIF_MODULE_ID, 0, _api, _error); /* @req FrIf05299 */ \
return __VA_ARGS__; \
}
#else
#define FRIF_DET_REPORTERROR(_cond ,_api, _error, ...) \
if (!_cond) { \
return __VA_ARGS__; \
}
#endif
/*lint -save -e9023 */
#if (FRIF_GET_CHNL_STATUS_SUPPORT == STD_ON)
#define FRIF_CLUSTER_DEM_REPORTING(_chnl) \
if (FRIF_INVALID_DEM_EVENT_ID != clstrCfg->FrIf_ClusterDemEventParamRef->FrIf_NITEventRefChnl##_chnl) { \
if ((*FrIf_Channel##_chnl##StatusPtr & NIT_ERROR_MASK) != 0) { \
Dem_ReportErrorStatus(clstrCfg->FrIf_ClusterDemEventParamRef->FrIf_NITEventRefChnl##_chnl, DEM_EVENT_STATUS_FAILED); \
} else { \
Dem_ReportErrorStatus(clstrCfg->FrIf_ClusterDemEventParamRef->FrIf_NITEventRefChnl##_chnl, DEM_EVENT_STATUS_PASSED); \
} \
} \
\
if (FRIF_INVALID_DEM_EVENT_ID != clstrCfg->FrIf_ClusterDemEventParamRef->FrIf_SWEventRefChnl##_chnl) { \
if ((*FrIf_Channel##_chnl##StatusPtr & SW_ERROR_MASK) != 0) { \
Dem_ReportErrorStatus(clstrCfg->FrIf_ClusterDemEventParamRef->FrIf_SWEventRefChnl##_chnl, DEM_EVENT_STATUS_FAILED); \
} else { \
Dem_ReportErrorStatus(clstrCfg->FrIf_ClusterDemEventParamRef->FrIf_SWEventRefChnl##_chnl, DEM_EVENT_STATUS_PASSED); \
}\
}\
\
if (FRIF_INVALID_DEM_EVENT_ID != clstrCfg->FrIf_ClusterDemEventParamRef->FrIf_ACSEventRefChnl##_chnl) { \
if ((*FrIf_Channel##_chnl##StatusPtr & CHNL_ACS_ERROR_MASK) != 0) { \
Dem_ReportErrorStatus(clstrCfg->FrIf_ClusterDemEventParamRef->FrIf_ACSEventRefChnl##_chnl, DEM_EVENT_STATUS_FAILED); \
} else { \
Dem_ReportErrorStatus(clstrCfg->FrIf_ClusterDemEventParamRef->FrIf_ACSEventRefChnl##_chnl, DEM_EVENT_STATUS_PASSED); \
}\
}
#endif
/*lint -restore */
#define FIRST_JOB_IDX 0u /* First job index in a cluster */
#define FIRST_FRIF_CTRL_IDX 0u /* First FrIf Controller index in a cluster */
#define MIN_SLOT_DURATION_FOR_NEXT_JOB 2uL /* Minimum time difference to activate the next job */
#define FLEXRAY_FRAME_ID_MIN 0x1u /* Minimum frame Id value */
#define FLEXRAY_FRAME_ID_MAX 0x7FFu /* Maximum frame Id value */
#define FLEXRAY_FRAME_LEN_MAX 0xFEu /* Maximum frame Len value */
/* Internal Functions */
void FrIf_Internal_HandleDecoupledTransmission(uint8 frIfIdx,PduIdType frLPduIdx, uint8 frameCfgIdx);
void FrIf_Internal_ProvideTxConfirmation(uint8 frIfIdx, PduIdType frLPduIdx, uint8 frameCfgIdx);
void FrIf_Internal_HandleReceiveAndStore(uint8 frIfIdx, PduIdType frLPduIdx, uint8 frameCfgIdx);
void FrIf_Internal_HandleReceiveAndIndicate(uint8 frIfIdx, PduIdType frLPduIdx, uint8 frameCfgIdx, uint16 maxLoop );
void FrIf_Internal_ProvideRxIndication(uint8 frIfIdx, PduIdType frLPduIdx, uint8 frameCfgIdx );
void FrIf_Internal_PrepareLPdu(uint8 frIfIdx, PduIdType frLPduIdx);
#if (FRIF_BIG_ENDIAN_USED == STD_ON)
void FrIf_Internal_SwapToBigEndian(const uint8 *srcBuffer,uint8 *destBuffer, uint8 length);
#endif
#ifdef HOST_TEST
FrIf_Internal_txPduStatisticsType readPduStatistics(PduIdType pduId);
#endif
#endif /* FRIF_INTERNAL_H_ */
|
2301_81045437/classic-platform
|
communication/FrIf/src/FrIf_Internal.h
|
C
|
unknown
| 6,346
|
#FrNm
obj-$(USE_FRNM) += FrNm.o
obj-$(USE_FRNM) += FrNm_Internal.o
obj-$(USE_FRNM) += FrNm_PBcfg.o
obj-$(USE_FRNM) += FrNm_Lcfg.o
vpath-$(USE_FRNM) += $(ROOTDIR)/communication/FrNm/src
inc-$(USE_FRNM) += $(ROOTDIR)/communication/FrNm/inc
inc-$(USE_FRNM) += $(ROOTDIR)/communication/FrNm/src
|
2301_81045437/classic-platform
|
communication/FrNm/FrNm.mod.mk
|
Makefile
|
unknown
| 299
|
/*-------------------------------- 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 FRNM_H_
#define FRNM_H_
/* @req FRNM065 */
#include "ComStack_Types.h"
#ifdef USE_COMM
#include "ComM.h"
#endif
#include "NmStack_Types.h"
#include "Nm.h" /* @req FRNM066 */
#include "FrNm_ConfigTypes.h"
#define FRNM_VENDOR_ID 60u
#define FRNM_MODULE_ID 32u
#define FRNM_AR_RELEASE_MAJOR_VERSION 4u
#define FRNM_AR_RELEASE_MINOR_VERSION 0u
#define FRNM_AR_RELEASE_REVISION_VERSION 3u
#define FRNM_AR_MAJOR_VERSION FRNM_AR_RELEASE_MAJOR_VERSION
#define FRNM_AR_MINOR_VERSION FRNM_AR_RELEASE_MINOR_VERSION
#define FRNM_AR_PATCH_VERSION FRNM_AR_RELEASE_REVISION_VERSION
#define FRNM_SW_MAJOR_VERSION 2u
#define FRNM_SW_MINOR_VERSION 0u
#define FRNM_SW_PATCH_VERSION 0u
#include "FrNm_Cfg.h" /* @req FRNM369 */
#include "FrIf.h"
/** Event IDs */ /* @req FRNM021 */ /* @req FRNM293 */
#define FRNM_E_UINIT 0x01u
#define FRNM_E_INVALID_CHANNEL 0x02u
#define FRNM_E_INVALID_POINTER 0x03u
#define FRNM_E_PDU_ID_INVALID 0x04u
/** Service IDs */
#define FRNM_SERVICE_ID_INIT 0x00u
#define FRNM_SERVICE_ID_PASSIVESTARTUP 0x01u
#define FRNM_SERVICE_ID_NETWORK_REQUEST 0x02u
#define FRNM_SERVICE_ID_NETWORK_RELEASE 0x03u
#define FRNM_SERVICE_ID_SETUSERDATA 0x06u
#define FRNM_SERVICE_ID_GETUSERDATA 0x07u
#define FRNM_SERVICE_ID_GETPDUDATA 0x08u
#define FRNM_SERVICE_ID_REPEATMSG_REQUEST 0x09u
#define FRNM_SERVICE_ID_GETNODE_ID 0x0Au
#define FRNM_SERVICE_ID_GETLOCAL_NODEID 0x0Bu
#define FRNM_SERVICE_ID_REQBUS_SYNC 0xC0u
#define FRNM_SERVICE_ID_CHKREMOTE_SLEEPIND 0x0Du
#define FRNM_SERVICE_ID_GETSTATE 0x0Eu
#define FRNM_SERVICE_ID_GETVERSIONINFO 0x0Fu
#define FRNM_SERVICE_ID_STARTUPERROR 0x10u
#define FRNM_SERVICE_ID_TRANSMIT 0x11u
#define FRNM_SERVICE_ID_ENABLECOMM 0x05u
#define FRNM_SERVICE_ID_DISABLECOMM 0x0Cu
#define FRNM_SERVICE_ID_SETSLEEP_READYBIT 0x12u
#define FRNM_SERVICE_ID_RX_INDICATION 0x42u
#define FRNM_SERVICE_ID_TRIGGER_TRANSMIT 0x41u
#define FRNM_SERVICE_ID_TX_CONFIRMATION 0x40u
#define FRNM_SERVICE_ID_MAIN_FUNCTION 0xF0u
#define FRNM_SOURCE_NODE_ID_POSITION 1u
#define FRNM_USRDATA_WITH_SOURCE_NODE_ID 2u
#define FRNM_USRDATA_WITHOUT_SOURCE_NODE_ID 1u
#define VOTE_INDEX 0u
#define VOTE_VALUE 0x80u
#define VOTE_PDU_LENGTH 1u
#define CBV_INDEX 0u
/* CBV repeat request bit */
#define FRNM_CBV_REPEAT_MESSAGE_REQUEST 0x01u
/* CBV NM Coordinator Sleep Ready Bit */
#define FRNM_CBV_NM_COORD_SLEEP_READY 0x08u
/* CBV Active wake up Bit */
#define FRNM_CBV_ACTIVE_WAKEUP 0x10u
/* CBV Cluster request information Bit */
#define FRNM_CBV_CLUSTER_REQ_INFO 0x40u
/* Max cycles supported in flexray */
#define FRNM_MAX_FLEXRAY_CYCLE_COUNT 64u
/* Publish the configuration */
extern const FrNm_ConfigType FrNmConfigData;
/** Initialize the complete FrNm module, i.e. all channels which are activated */
/** @req FRNM236 */
void FrNm_Init(const FrNm_ConfigType * const frnmConfigPtr);
/* @req FRNM238 */
Std_ReturnType FrNm_NetworkRequest( const NetworkHandleType NetworkHandle );
/* @req FRNM239 */
Std_ReturnType FrNm_NetworkRelease( const NetworkHandleType NetworkHandle );
/* This service returns the version information of this module. */
/* @req FRNM074 *//*@req FRNM249*/
#if ( FRNM_VERSION_INFO_API == STD_ON ) /* @req FRNM274 */
#define FrNm_GetVersionInfo(_vi) STD_GET_VERSION_INFO(_vi,FRNM) /*@req FRNM273*/ /*@req FRNM272*/
#endif /* FRNM_VERSION_INFO_API */
#if (FRNM_USER_DATA_ENABLED == STD_ON) /* @req FRNM263 *//* @req FRNM264 */
/* @req FRNM240 */
Std_ReturnType FrNm_SetUserData( const NetworkHandleType NetworkHandle, const uint8* const nmUserDataPtr );
/* @req FRNM241 */
Std_ReturnType FrNm_GetUserData(const NetworkHandleType NetworkHandle, uint8* const nmUserDataPtr );
#endif
#if(FRNM_CONTROL_BIT_VECTOR_ENABLED == STD_ON)||(FRNM_SOURCE_NODE_INDENTIFIER_ENABLED==STD_ON)||(FRNM_USER_DATA_ENABLED == STD_ON)
/* @req FRNM242 */
Std_ReturnType FrNm_GetPduData( const NetworkHandleType NetworkHandle, uint8* const nmPduData );
#endif
#if (FRNM_NODE_DETECTION_ENABLED == STD_ON) /* @req FRNM228 */
/* @req FRNM243 */
Std_ReturnType FrNm_RepeatMessageRequest( const NetworkHandleType NetworkHandle );
#endif
#if(FRNM_SOURCE_NODE_INDENTIFIER_ENABLED == STD_ON)/* @req FRNM267 *//* @req FRNM268 */
/* @req FRNM244 */
Std_ReturnType FrNm_GetNodeIdentifier( const NetworkHandleType NetworkHandle, uint8* const nmNodeIdPtr);
/* @req FRNM245 */
Std_ReturnType FrNm_GetLocalNodeIdentifier( const NetworkHandleType NetworkHandle, uint8* const nmNodeIdPtr );
#endif
#if (FRNM_BUS_SYNCHRONIZATION_ENABLED == STD_ON) /* @req FRNM269 */
/* @req FRNM246 */
Std_ReturnType FrNm_RequestBusSynchronization( const NetworkHandleType NetworkHandle );
#endif
/* req FRNM247 */
Std_ReturnType FrNm_CheckRemoteSleepIndication( const NetworkHandleType NetworkHandle, boolean* const nmRemoteSleepIndPtr );
/* @req FRNM248 */
Std_ReturnType FrNm_GetState( const NetworkHandleType NetworkHandle, Nm_StateType* const nmStatePtr, Nm_ModeType* const nmModePtr );
/* @req FRNM393 */
void FrNm_StartupError( const NetworkHandleType NetworkHandle );
/* @req FRNM359 */
Std_ReturnType FrNm_Transmit( PduIdType FrNmTxPduId, const PduInfoType* PduInfoPtr );
/* @req FRNM387*/
Std_ReturnType FrNm_EnableCommunication( const NetworkHandleType nmChannelHandle );
/* @req FRNM390*/
Std_ReturnType FrNm_DisableCommunication( const NetworkHandleType nmChannelHandle );
/* req FRNM237*/
Std_ReturnType FrNm_PassiveStartUp( const NetworkHandleType NetworkHandle );
/* @req FRNM*/
Std_ReturnType FrNm_SetSleepReadyBit( const NetworkHandleType nmChannelHandle, const boolean nmSleepReadyBit );
/* @req FRNM251*/
void FrNm_RxIndication( PduIdType RxPduId, PduInfoType* PduInfoPtr );
/* @req FRNM252*/
Std_ReturnType FrNm_TriggerTransmit( PduIdType TxPduId, PduInfoType* PduInfoPtr );
/* req FRNM460 in 4.2 spec*/
void FrNm_TxConfirmation( PduIdType TxPduId );
#ifdef HOST_TEST
void GetFrNmChannelRunTimeData( const NetworkHandleType NetworkHandle , boolean* repeatMessage, boolean* networkRequested);
#endif
#endif /* FRNM_H_ */
|
2301_81045437/classic-platform
|
communication/FrNm/inc/FrNm.h
|
C
|
unknown
| 7,377
|
/*-------------------------------- 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 FRNM_CBK_H_
#define FRNM_CBK_H_
/* @req FRNM368*/
/* @req FRNM251*/
void FrNm_RxIndication( PduIdType RxPduId, PduInfoType* PduInfoPtr);
/* @req FRNM252*/
Std_ReturnType FrNm_TriggerTransmit( PduIdType TxPduId, PduInfoType* PduInfoPtr );
/* req FRNM460*/
void FrNm_TxConfirmation( PduIdType TxPduId );
#endif /* FRNM_CBK_H_ */
|
2301_81045437/classic-platform
|
communication/FrNm/inc/FrNm_Cbk.h
|
C
|
unknown
| 1,109
|
/*-------------------------------- 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 FRNM_CONFIGTYPES_H_
#define FRNM_CONFIGTYPES_H_
#define FRNM_UNUSED_CHANNEL 0xFFu
typedef enum {
FRNM_PDU_SCHEDULE_VARIANT_1 = 0x00u,
FRNM_PDU_SCHEDULE_VARIANT_2 = 0x01u,
FRNM_PDU_SCHEDULE_VARIANT_3 = 0x02u,
FRNM_PDU_SCHEDULE_VARIANT_4 = 0x03u,
FRNM_PDU_SCHEDULE_VARIANT_5 = 0x04u,
FRNM_PDU_SCHEDULE_VARIANT_6 = 0x05u,
FRNM_PDU_SCHEDULE_VARIANT_7 = 0x06u
} FrNm_PduScheduleVariantType;
/* @req FRNM195 */ /* @req FRNM196 */
typedef enum {
FRNM_CYCLE_VALUE_1 = 1u,
FRNM_CYCLE_VALUE_2 = 2u,
FRNM_CYCLE_VALUE_4 = 4u,
FRNM_CYCLE_VALUE_8 = 8u,
FRNM_CYCLE_VALUE_16 = 16u,
FRNM_CYCLE_VALUE_32 = 32u,
FRNM_CYCLE_VALUE_64 = 64u
} FrNm_FrNmCycleType;
typedef struct {
const boolean FrNmRxContainsData;
const boolean FrNmRxConatainsVote;
const PduIdType FrNmRxPduId;
const uint8 FrNmRxPduLength;
}FrNm_RxPduConfigType;
typedef struct {
const boolean FrNmTxContainsData;
const boolean FrNmTxConatainsVote;
const PduIdType FrNmTxConfPduId;
const uint8 FrNmTxPduLength;
const PduIdType FrIfTxPduId;
}FrNm_TxPduConfigType;
typedef struct {
const PduIdType FrNmUserDataTxPduId;
const uint8 FrNmUserDataTxPduLength;
}FrNm_UserDataTxPduConfigType;
typedef struct {
const FrNm_RxPduConfigType *FrNmRxPduList;
const uint8 FrNmRxPduCount;
const uint8 FrNmRxPduLength;
const FrNm_TxPduConfigType *FrNmTxPduList;
const uint8 FrNmTxPduCount;
const uint8 FrNmTxPduLength;
const FrNm_UserDataTxPduConfigType *FrNmUserDataConfig;
const NetworkHandleType FrNmChannelHandle;
const NetworkHandleType FrNmComMNetworkHandleRef;
const boolean FrNmControlBitVectorActive;
const uint8 FrNmNodeId;
const FrNm_PduScheduleVariantType FrNmPduScheduleVariant;
const boolean FrNmRepeatMessageBitActive;
const boolean FrNmSyncPointEnabled;
const boolean FrNmPnEnabled;
}FrNm_ChannelIdentifiersInfoType;
typedef struct {
const FrNm_FrNmCycleType FrNmDataCycle; /* @req FRNM195 */
const uint32 FrNmMainFunctionPeriod;
const uint32 FrNmMsgTimeoutTime;
const uint16 FrNmReadySleepCnt; /* @req FRNM309 */
const uint32 FrNmRepeatMessageTime;
const FrNm_FrNmCycleType FrNmRepetitionCycle; /* @req FRNM195 */
const uint32 FrNmSyncLossTimer;
const boolean FrNmVoteInhibitionEnabled;
const FrNm_FrNmCycleType FrNmVotingCycle; /* @req FRNM195 */
}FrNm_ChannelTiminginfoType;
typedef struct {
const FrNm_ChannelIdentifiersInfoType *FrNmChannelIdentifiersConfig;
const FrNm_ChannelTiminginfoType *FrNmTimingConfig;
}FrNm_ChannelInfoType;
typedef struct {
uint8 FrNmPnInfoOffset; /* Offset Index */
PduLengthType FrNmPnInfoLen; /* PnInfo Length */
const uint8 *FrNmPnInfoMask; /* Pointer PNC mask bytes */
const uint8 *FrNmPnIndexToTimerMap; /* Mapping from PN index to reset timer index */
const uint8 *FrNmTimerIndexToPnMap; /* Mapping from timer index to PN index */
PduIdType FrNmEIRARxNSduId; /* SDU carrying EIRA */
}FrNm_PnInfoType;
typedef struct {
const FrNm_ChannelInfoType* FrNmChannels;
const uint8* FrNmChannelLookups; /* Pointer to lookup from NetworkHandle to index in FrNm channels */
const uint8 FrNmChnlCount; /* No. of FrNm Channels */
const uint8* FrNmChnlRxpduMaps;
const uint8* FrNmChnlTxpduMaps;
const uint8* FrNmChnlFrIfCtrlIdMap;
const FrNm_PnInfoType *FrNmPnInfo;
}FrNm_ConfigType;
#endif /* FRNM_CONFIGTYPES_H_ */
|
2301_81045437/classic-platform
|
communication/FrNm/inc/FrNm_ConfigTypes.h
|
C
|
unknown
| 4,321
|
/*-------------------------------- 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 -----------------------------*/
/* Globally fulfilled requirements */
/** @req FRNM102 */ /* FlexRay NM state machine shall contain states, transitions and triggers coordination algorithm from the point of view of one single node in the NM-cluster */
/** @req FRNM103 */ /* Transitions FlexRay NM state machine shall be triggered by calls interface functions or by the expiration of internal timers or counters.*/
/** @req FRNM177 */ /*FrNm module shall not use asynchronous NM-Task activation.*/
/** @req FRNM179 */ /*The AUTOSAR FlexRay NM algorithm shall support up to 64 nodes per NM-Cluster */
/** @req FRNM056 *//* if det enabled => parameter checking */
/** @req FRNM064 */ /** @req FRNM066 */
/** @req FRNM225 */ /* General requirement for NM coordination algorithm shall not rely on any processor specific hardware support*/
/** @req FRNM176*/ /* General requirement for FlexRay NM shall realize FlexRay NM functions for reception and for transmission of NM Messages */
/** @req FRNM196 */ /* This assumed integrator will configure FrNmRepetitionCycle will be an integer multiple of the NM Voting Cycle */
/** @req FRNM194 */ /** @req FRNM193 */ /* assumed FrNmDataCycle and FrNmVotingCycle is not in the scope of FRNM it should be at global level
* configured by integrator for FrIf or FrDrv, because FRNM has no information about segments and slots of transmission */
/** @req FRNM058 */ /* This is a general requirement as The FlexRay NM decisions shall be influenced by every received NM-Vote */
/** @req FRNM372 */ /* This is the global flexray cycle configuration requirement for cycle evaluation of FrNmMainAcrossFrCycle with respect to os scheduling */
#include "ComStack_Types.h"
#include "ComM.h"
#include "NmStack_Types.h"
#include "Nm.h"
#include "Nm_Cbk.h"/** @req FRNM064 */ /** @req FRNM368 */
#include "FrNm.h" /* @req FRNM064 */ /* @req FRNM367 */ /* @req FRNM065 */
#include "FrNm_Cbk.h" /* @req FRNM065 */
#include "PduR_FrNm.h"
#include "SchM_FrNm.h"
#include "FrNm_Internal.h"
#include <string.h>
#if (FRNM_DEV_ERROR_DETECT == STD_ON)/* @req FRNM049 */
#include "Det.h"
#endif
#if defined(USE_DEM)
#include "Dem.h"
#endif
const FrNm_ConfigType* FrNm_ConfigPtr;
/* @req FRNM071 */ /* @req FRNM421 */
FrNm_InternalType FrNm_Internal = {
.InitStatus = FRNM_STATUS_UNINIT,
};
/**
*
* @param frnmConfigPtr
*/
/* Initialize the complete FrNm module, i.e. all channels which are activated */
/* @req FRNM236 */
void FrNm_Init( const FrNm_ConfigType * const frnmConfigPtr ){
const FrNm_ChannelInfoType* FrNmChannelsconf;
FrNm_Internal_ChannelType* ChannelInternal;
#if (FRNM_PASSIVE_MODE_ENABLED == STD_OFF)
uint8* destUserData;
uint8 userDataLength;
uint8 txPduCount;
#endif
uint8 channel;
uint8 pdu;
uint8 rxPduCount;
/* @req FRNM395 */
FRNM_DET_REPORTERROR((NULL != frnmConfigPtr),FRNM_SERVICE_ID_INIT,FRNM_E_INVALID_POINTER);
FrNm_ConfigPtr = frnmConfigPtr; /* @req FRNM059 */
for (channel=0; channel < FrNm_ConfigPtr->FrNmChnlCount; channel++){
FrNmChannelsconf = &FrNm_ConfigPtr->FrNmChannels[channel];
ChannelInternal = &FrNm_Internal.FrNmChannels[channel];
/* @req FRNM030*/ /* @req FRNM307*/ /*if in any mode init is called will change to bus sleep*/
ChannelInternal->Mode = NM_MODE_BUS_SLEEP;
ChannelInternal->State = NM_STATE_BUS_SLEEP;
ChannelInternal->CommunicationEnabled = TRUE;
ChannelInternal->activeWakeup = FALSE;
/* @req FRNM136*/
ChannelInternal->FrNm_NetworkRequested = FALSE;
ChannelInternal->FrNm_RepeatMessage = FALSE;
rxPduCount = FrNmChannelsconf->FrNmChannelIdentifiersConfig->FrNmRxPduCount;
#if (FRNM_PASSIVE_MODE_ENABLED == STD_OFF)
txPduCount = FrNmChannelsconf->FrNmChannelIdentifiersConfig->FrNmTxPduCount;
for (pdu = 0; pdu<txPduCount; pdu++){
if(FrNmChannelsconf->FrNmChannelIdentifiersConfig->FrNmTxPduList[pdu].FrNmTxConatainsVote == STD_ON) {
/* @req FRNM042 */
ChannelInternal->FrNmTxVotePdu = 0x00;
} else {
/* @req FRNM042 */
ChannelInternal->FrNmTxVotePdu = 0x00;
}
if(FrNmChannelsconf->FrNmChannelIdentifiersConfig->FrNmTxPduList[pdu].FrNmTxContainsData == STD_ON) {
memset(ChannelInternal->FrNmTxDataPdu, 0x00, 8);
}
}
memset(ChannelInternal->FrNmTxUserdataMessagePdu, 0x00, 8);
destUserData = &ChannelInternal->FrNmTxDataPdu[FRNM_INTERNAL_GET_USER_DATA_OFFSET];
userDataLength = FrNmChannelsconf->FrNmChannelIdentifiersConfig->FrNmTxPduLength - FRNM_INTERNAL_GET_USER_DATA_OFFSET; /* @req FRNM155 */
/* @req FRNM045 */
memset(destUserData, 0xFF, userDataLength);
#endif
for (pdu = 0; pdu<rxPduCount; pdu++){
if(FrNmChannelsconf->FrNmChannelIdentifiersConfig->FrNmRxPduList[pdu].FrNmRxContainsData == STD_ON) {
memset(ChannelInternal->FrNmRxDataPdu, 0x00, 8);
}
}
/* @req FRNM222 */ /* @req FRNM037 */
#if (FRNM_SOURCE_NODE_INDENTIFIER_ENABLED == STD_ON)
ChannelInternal->FrNmTxDataPdu[FRNM_SOURCE_NODE_ID_POSITION] = FrNmChannelsconf->FrNmChannelIdentifiersConfig->FrNmNodeId;
#endif
ChannelInternal->MessageTimeoutTimeLeft = 0;
ChannelInternal->RepetitionCyclesLeft = (uint8)(FrNmChannelsconf->FrNmTimingConfig->FrNmRepetitionCycle);
ChannelInternal->DataCyclesLeft = (uint8)(FrNmChannelsconf->FrNmTimingConfig->FrNmDataCycle);
ChannelInternal->readySleepCntLeft = FrNmChannelsconf->FrNmTimingConfig->FrNmReadySleepCnt;
ChannelInternal->setUserDataEnable = FALSE;
}
/* Initialize the PN reset timer */
#if ((FRNM_PNC_EIRA_CALC_ENABLED == STD_ON) && (FRNM_PNC_COUNT > 0))
for (uint8 i = 0; i < FRNM_PNC_COUNT; i++) {
FrNm_Internal.pnEIRATimers[i].timerRunning = FALSE;
FrNm_Internal.pnEIRATimers[i].resetTimer = 0;
}
FrNm_Internal.pnEIRA.data = 0; /* reset EIRA */
#endif
/* @req FRNM073 */
FrNm_Internal.InitStatus = FRNM_STATUS_INIT;
/* @req FRNM028 */
}
/**
*
* @param NetworkHandle
* @return
*/
/* Initiates the Passive Startup of the FlexRay NM*/
/* @req FRNM237 */
Std_ReturnType FrNm_PassiveStartUp( const NetworkHandleType NetworkHandle ) {
/* This function full implementation currently in Not Supported requirements */
FrNm_Internal_ChannelType* ChannelInternal;
Std_ReturnType status;
uint8 channelIndex;
/* @req FRNM050 *//* @req FRNM032 */
FRNM_DET_REPORTERROR((FRNM_STATUS_INIT == FrNm_Internal.InitStatus),FRNM_SERVICE_ID_PASSIVESTARTUP,FRNM_E_UINIT, E_NOT_OK);
/* @req FRNM051 */ /* @req FRNM021 */
FRNM_VALIDATE_CHANNEL(NetworkHandle, FRNM_SERVICE_ID_PASSIVESTARTUP, E_NOT_OK);
/* @req FRNM258 */
status = E_OK;
channelIndex = FrNm_ConfigPtr->FrNmChannelLookups[NetworkHandle];
ChannelInternal = &FrNm_Internal.FrNmChannels[channelIndex];
if (ChannelInternal->Mode == NM_MODE_BUS_SLEEP) {
/* @req FRNM317*/
/* @req FRNM138*/
ChannelInternal->Mode = NM_MODE_SYNCHRONIZE;
ChannelInternal->State = NM_STATE_SYNCHRONIZE;
} else {
status = E_NOT_OK; /* @req FRNM260*/
}
return status;
}
/**
*
* @param NetworkHandle
* @return
*/
/* it for requesting the network communicate ECU on the bus. Update state to ‘requested’ */
/* @req FRNM238 */
#if(FRNM_PASSIVE_MODE_ENABLED == STD_OFF) /* @req FRNM261 */
Std_ReturnType FrNm_NetworkRequest( const NetworkHandleType NetworkHandle ) {
uint8 channelIndex;
const FrNm_ChannelInfoType* ChannelConf;
FrNm_Internal_ChannelType* ChannelInternal;
/* @req FRNM050 */ /* @req FRNM021 */ /* @req FRNM032 */
FRNM_DET_REPORTERROR((FRNM_STATUS_INIT == FrNm_Internal.InitStatus),FRNM_SERVICE_ID_NETWORK_REQUEST,FRNM_E_UINIT, E_NOT_OK);
/* @req FRNM051 */
FRNM_VALIDATE_CHANNEL(NetworkHandle, FRNM_SERVICE_ID_NETWORK_REQUEST, E_NOT_OK);
channelIndex = FrNm_ConfigPtr->FrNmChannelLookups[NetworkHandle];
ChannelConf = &FrNm_ConfigPtr->FrNmChannels[channelIndex];
ChannelInternal = &FrNm_Internal.FrNmChannels[channelIndex];
/* @req FRNM139*/
if (ChannelInternal->Mode == NM_MODE_BUS_SLEEP) {
/* @req FRNM316*/
ChannelInternal->Mode = NM_MODE_SYNCHRONIZE;
ChannelInternal->State = NM_STATE_SYNCHRONIZE;
ChannelInternal->FrNm_NetworkRequested = TRUE;
ChannelInternal->activeWakeup = TRUE;
ChannelInternal->RepetitionCyclesLeft = (uint8) ChannelConf->FrNmTimingConfig->FrNmRepetitionCycle;
ChannelInternal->RepeatMessageTimeLeft = ChannelConf->FrNmTimingConfig->FrNmRepeatMessageTime; /* @req FRNM117*/
} else if (ChannelInternal->Mode == NM_MODE_SYNCHRONIZE){
/* @req FRNM141*/
ChannelInternal->FrNm_NetworkRequested = TRUE;
} else if (ChannelInternal->Mode == NM_MODE_NETWORK){
/* @req FRNM113*/
ChannelInternal->FrNm_NetworkRequested = TRUE;
} else{
/*Nothing to be done */
}
return E_OK;
}
#endif
/**
*
* @param NetworkHandle
* @return
*/
/* it for requesting the network does not communicate ECU on the bus. Update state to ‘released’ */
/* @req FRNM239 */
#if(FRNM_PASSIVE_MODE_ENABLED == STD_OFF) /* @req FRNM262 */
Std_ReturnType FrNm_NetworkRelease( const NetworkHandleType NetworkHandle )
{
uint8 channelIndex;
FrNm_Internal_ChannelType* ChannelInternal;
/* @req FRNM050 */ /* @req FRNM032 */
FRNM_DET_REPORTERROR((FRNM_STATUS_INIT == FrNm_Internal.InitStatus),FRNM_SERVICE_ID_NETWORK_RELEASE,FRNM_E_UINIT, E_NOT_OK);
/* @req FRNM021 *//* @req FRNM051 */
FRNM_VALIDATE_CHANNEL(NetworkHandle, FRNM_SERVICE_ID_NETWORK_RELEASE, E_NOT_OK);
channelIndex = FrNm_ConfigPtr->FrNmChannelLookups[NetworkHandle];
ChannelInternal = &FrNm_Internal.FrNmChannels[channelIndex];
if((ChannelInternal->Mode == NM_MODE_SYNCHRONIZE)||(ChannelInternal->Mode == NM_MODE_NETWORK)){
/* @req FRNM142*/ /* @req FRNM114*/
ChannelInternal->FrNm_NetworkRequested = FALSE;
}
return E_OK;
}
#endif
/**
*
* @param NetworkHandle
* @param nmUserDataPtr
* @return
*/
/* This function sets user data for NM-Data transmitted next on the bus.*/
/* @req FRNM240 */
#if (FRNM_USER_DATA_ENABLED == STD_ON) /* @req FRNM263 */
Std_ReturnType FrNm_SetUserData( const NetworkHandleType NetworkHandle, const uint8* const nmUserDataPtr ) {
uint8 channelIndex;
const FrNm_ChannelInfoType* ChannelConf;
FrNm_Internal_ChannelType* ChannelInternal;
uint8* destUserData;
uint8 userDataLength;
/* @req FRNM050 */ /* @req FRNM032 */ /* @req FRNM021 */ /* @req FRNM319 */
FRNM_DET_REPORTERROR((FRNM_STATUS_INIT == FrNm_Internal.InitStatus),FRNM_SERVICE_ID_SETUSERDATA,FRNM_E_UINIT, E_NOT_OK);
/* @req FRNM051 */
FRNM_VALIDATE_CHANNEL(NetworkHandle, FRNM_SERVICE_ID_SETUSERDATA, E_NOT_OK);
FRNM_DET_REPORTERROR((NULL != nmUserDataPtr),FRNM_SERVICE_ID_SETUSERDATA,FRNM_E_INVALID_POINTER,E_NOT_OK);
channelIndex = FrNm_ConfigPtr->FrNmChannelLookups[NetworkHandle];
ChannelConf = &FrNm_ConfigPtr->FrNmChannels[channelIndex];
ChannelInternal = &FrNm_Internal.FrNmChannels[channelIndex];
/* @req FRNM043 */
destUserData = &ChannelInternal->FrNmTxDataPdu[FRNM_INTERNAL_GET_USER_DATA_OFFSET];
userDataLength = ChannelConf->FrNmChannelIdentifiersConfig->FrNmTxPduLength - FRNM_INTERNAL_GET_USER_DATA_OFFSET; /* @req FRNM155 */
memcpy(destUserData, nmUserDataPtr, userDataLength);
ChannelInternal->setUserDataEnable = TRUE;
return E_OK;
}
#endif
/**
*
* @param NetworkHandle
* @param nmUserDataPtr
* @return
*/
/* This function gets user data form the last successfully received NM message .*/
/* @req FRNM241 */
#if (FRNM_USER_DATA_ENABLED == STD_ON) /* @req FRNM264 */
Std_ReturnType FrNm_GetUserData(const NetworkHandleType NetworkHandle, uint8* const nmUserDataPtr ) {
uint8 channelIndex;
const FrNm_ChannelInfoType* ChannelConf;
const FrNm_Internal_ChannelType* ChannelInternal;
const uint8* sourceUserData;
uint8 userDataLength;
/* @req FRNM050 */ /* @req FRNM032 */ /* @req FRNM021 */
FRNM_DET_REPORTERROR((FRNM_STATUS_INIT == FrNm_Internal.InitStatus),FRNM_SERVICE_ID_GETUSERDATA,FRNM_E_UINIT, E_NOT_OK);
/* @req FRNM051 */
FRNM_VALIDATE_CHANNEL(NetworkHandle, FRNM_SERVICE_ID_GETUSERDATA, E_NOT_OK);
FRNM_DET_REPORTERROR((NULL != nmUserDataPtr),FRNM_SERVICE_ID_GETUSERDATA,FRNM_E_INVALID_POINTER,E_NOT_OK);
channelIndex = FrNm_ConfigPtr->FrNmChannelLookups[NetworkHandle];
ChannelConf = &FrNm_ConfigPtr->FrNmChannels[channelIndex];
ChannelInternal = &FrNm_Internal.FrNmChannels[channelIndex];
sourceUserData = &ChannelInternal->FrNmRxDataPdu[FRNM_INTERNAL_GET_USER_DATA_OFFSET];
userDataLength = ChannelConf->FrNmChannelIdentifiersConfig->FrNmRxPduLength - FRNM_INTERNAL_GET_USER_DATA_OFFSET; /* @req FRNM155 */
/* @req FRNM044 */
memcpy(nmUserDataPtr, sourceUserData, userDataLength);
return E_OK;
}
#endif
/**
*
* @param NetworkHandle
* @param nmPduData
* @return
*/
/* This function gets Gets PDU data form the last successfully received NM message .*/
/* @req FRNM242 */
#if(FRNM_CONTROL_BIT_VECTOR_ENABLED == STD_ON)||(FRNM_SOURCE_NODE_INDENTIFIER_ENABLED==STD_ON)||(FRNM_USER_DATA_ENABLED == STD_ON)/* @req FRNM266 */
Std_ReturnType FrNm_GetPduData( const NetworkHandleType NetworkHandle, uint8* const nmPduData ) {
uint8 channelIndex;
const FrNm_ChannelInfoType* ChannelConf;
const FrNm_Internal_ChannelType* ChannelInternal;
/* @req FRNM050 */ /* @req FRNM021 */
FRNM_DET_REPORTERROR((FRNM_STATUS_INIT == FrNm_Internal.InitStatus),FRNM_SERVICE_ID_GETPDUDATA,FRNM_E_UINIT, E_NOT_OK);
/* @req FRNM051 */
FRNM_VALIDATE_CHANNEL(NetworkHandle, FRNM_SERVICE_ID_GETPDUDATA, E_NOT_OK);
FRNM_DET_REPORTERROR((NULL != nmPduData),FRNM_SERVICE_ID_GETPDUDATA,FRNM_E_INVALID_POINTER,E_NOT_OK);
channelIndex = FrNm_ConfigPtr->FrNmChannelLookups[NetworkHandle];
ChannelConf = &FrNm_ConfigPtr->FrNmChannels[channelIndex];
ChannelInternal = &FrNm_Internal.FrNmChannels[channelIndex];
/* @req FRNM265 */
memcpy(nmPduData, ChannelInternal->FrNmRxDataPdu, ChannelConf->FrNmChannelIdentifiersConfig->FrNmRxPduLength);
return E_OK;
}
#endif
/**
*
* @param NetworkHandle
* @return
*/
/*This function causes a Repeat Message Request to be transmitted next on the bus*/
/* @req FRNM243 */
#if (FRNM_NODE_DETECTION_ENABLED == STD_ON) /* @req FRNM228 */
Std_ReturnType FrNm_RepeatMessageRequest( const NetworkHandleType NetworkHandle ){
uint8 channelIndex;
FrNm_Internal_ChannelType* ChannelInternal;
/* @req FRNM050 */ /* @req FRNM021 */
FRNM_DET_REPORTERROR((FRNM_STATUS_INIT == FrNm_Internal.InitStatus),FRNM_SERVICE_ID_REPEATMSG_REQUEST,FRNM_E_UINIT, E_NOT_OK);
/* @req FRNM051 */
FRNM_VALIDATE_CHANNEL(NetworkHandle, FRNM_SERVICE_ID_REPEATMSG_REQUEST, E_NOT_OK);
channelIndex = FrNm_ConfigPtr->FrNmChannelLookups[NetworkHandle];
ChannelInternal = &FrNm_Internal.FrNmChannels[channelIndex];
/* @req FRNM172*/ /* @req FRNM111*/
if (ChannelInternal->Mode == NM_MODE_NETWORK){
if ((ChannelInternal->State == NM_STATE_READY_SLEEP)||(ChannelInternal->State == NM_STATE_NORMAL_OPERATION)){
#if (FRNM_CONTROL_BIT_VECTOR_ENABLED == STD_OFF)/* @req FRNM324 */
ChannelInternal->FrNmTxDataPdu[CBV_INDEX] = 0x00; /* @req FRNM3829 */
#else
#if(FRNM_REPEAT_MESSAGE_BIT_ENABLED == STD_ON)
ChannelInternal->FrNmTxDataPdu[CBV_INDEX] |= FRNM_CBV_REPEAT_MESSAGE_REQUEST;
#endif
#endif
}
/* @req FRNM226*/
ChannelInternal->FrNm_RepeatMessage = TRUE;
}
return E_OK;
}
#endif
/**
*
* @param NetworkHandle
* @param nmNodeIdPtr
* @return
*/
/*This function gets the node identifier from the last successfully received NM-message*/
/* @req FRNM244 */
#if(FRNM_SOURCE_NODE_INDENTIFIER_ENABLED == STD_ON)/* @req FRNM267 */
Std_ReturnType FrNm_GetNodeIdentifier( const NetworkHandleType NetworkHandle, uint8* const nmNodeIdPtr){
uint8 channelIndex;
const FrNm_Internal_ChannelType* ChannelInternal;
/* @req FRNM050 */ /* @req FRNM021 */
FRNM_DET_REPORTERROR((FRNM_STATUS_INIT == FrNm_Internal.InitStatus),FRNM_SERVICE_ID_GETNODE_ID,FRNM_E_UINIT, E_NOT_OK);
/* @req FRNM051 */
FRNM_VALIDATE_CHANNEL(NetworkHandle, FRNM_SERVICE_ID_GETNODE_ID, E_NOT_OK);
FRNM_DET_REPORTERROR((NULL != nmNodeIdPtr),FRNM_SERVICE_ID_GETNODE_ID,FRNM_E_INVALID_POINTER,E_NOT_OK);
channelIndex = FrNm_ConfigPtr->FrNmChannelLookups[NetworkHandle];
ChannelInternal = &FrNm_Internal.FrNmChannels[channelIndex];
/* @req FRNM047 */
*nmNodeIdPtr = ChannelInternal->FrNmRxDataPdu[FRNM_SOURCE_NODE_ID_POSITION];
return E_OK;
}
#endif
/**
*
* @param NetworkHandle
* @param nmNodeIdPtr
* @return
*/
/*This function gets the node identifier configured for the local node.*/
/* @req FRNM245 */
#if(FRNM_SOURCE_NODE_INDENTIFIER_ENABLED == STD_ON)/* @req FRNM268 */
Std_ReturnType FrNm_GetLocalNodeIdentifier( const NetworkHandleType NetworkHandle, uint8* const nmNodeIdPtr ){
uint8 channelIndex;
const FrNm_ChannelInfoType* ChannelConf;
/* @req FRNM050 */ /* @req FRNM021 */
FRNM_DET_REPORTERROR((FRNM_STATUS_INIT == FrNm_Internal.InitStatus),FRNM_SERVICE_ID_GETLOCAL_NODEID,FRNM_E_UINIT, E_NOT_OK);
/* @req FRNM051 */
FRNM_VALIDATE_CHANNEL(NetworkHandle, FRNM_SERVICE_ID_GETLOCAL_NODEID, E_NOT_OK);
FRNM_DET_REPORTERROR((NULL != nmNodeIdPtr),FRNM_SERVICE_ID_GETLOCAL_NODEID,FRNM_E_INVALID_POINTER,E_NOT_OK);
channelIndex = FrNm_ConfigPtr->FrNmChannelLookups[NetworkHandle];
ChannelConf = &FrNm_ConfigPtr->FrNmChannels[channelIndex];
/* @req FRNM046 */
*nmNodeIdPtr = ChannelConf->FrNmChannelIdentifiersConfig->FrNmNodeId;
return E_OK;
}
#endif
/**
*
* @param NetworkHandle
* @return
*/
/*the service is provided only to be compatible to future extensions and to be compatible to the CAN-NM interface.*/
#if (FRNM_BUS_SYNCHRONIZATION_ENABLED == STD_ON) /* @req FRNM269 */
/* @req FRNM246 */
Std_ReturnType FrNm_RequestBusSynchronization( const NetworkHandleType NetworkHandle ){
/* @req FRNM050 */ /* @req FRNM021 */
FRNM_DET_REPORTERROR((FRNM_STATUS_INIT == FrNm_Internal.InitStatus),FRNM_SERVICE_ID_REQBUS_SYNC,FRNM_E_UINIT, E_NOT_OK);
/* @req FRNM051 */
FRNM_VALIDATE_CHANNEL(NetworkHandle, FRNM_SERVICE_ID_REQBUS_SYNC, E_NOT_OK);
/* @req FRNM174 */
return E_OK;
}
#endif
/**
*
* @param NetworkHandle
* @param nmRemoteSleepIndPtr
* @return
*/
/*This function checks if remote sleep indication has taken place or not.*/
/* req FRNM247 */
/*lint -e{818} Pointer parameter 'nmRemoteSleepIndPtr' (line 454) could be declared as pointing to const */
Std_ReturnType FrNm_CheckRemoteSleepIndication( const NetworkHandleType NetworkHandle, boolean* const nmRemoteSleepIndPtr ){
/* @req FRNM050 */ /* @req FRNM021 */
FRNM_DET_REPORTERROR((FRNM_STATUS_INIT == FrNm_Internal.InitStatus),FRNM_SERVICE_ID_CHKREMOTE_SLEEPIND,FRNM_E_UINIT, E_NOT_OK);
/* @req FRNM051 */
FRNM_VALIDATE_CHANNEL(NetworkHandle, FRNM_SERVICE_ID_CHKREMOTE_SLEEPIND, E_NOT_OK);
FRNM_DET_REPORTERROR((NULL != nmRemoteSleepIndPtr),FRNM_SERVICE_ID_CHKREMOTE_SLEEPIND,FRNM_E_INVALID_POINTER,E_NOT_OK);
return E_OK;
}
/**
*
* @param NetworkHandle
* @param nmStatePtr
* @param nmModePtr
* @return
*/
/*This function returns the state and the mode of the network management*/
/* @req FRNM248 */
Std_ReturnType FrNm_GetState( const NetworkHandleType NetworkHandle, Nm_StateType* const nmStatePtr, Nm_ModeType* const nmModePtr ){
uint8 channelIndex;
const FrNm_Internal_ChannelType* ChannelInternal;
/* @req FRNM050 */ /* @req FRNM021 */
FRNM_DET_REPORTERROR((FRNM_STATUS_INIT == FrNm_Internal.InitStatus),FRNM_SERVICE_ID_GETSTATE,FRNM_E_UINIT, E_NOT_OK);
/* @req FRNM051 */
FRNM_VALIDATE_CHANNEL(NetworkHandle, FRNM_SERVICE_ID_GETSTATE, E_NOT_OK);
FRNM_DET_REPORTERROR((NULL != nmStatePtr),FRNM_SERVICE_ID_GETSTATE,FRNM_E_INVALID_POINTER,E_NOT_OK);
FRNM_DET_REPORTERROR((NULL != nmModePtr),FRNM_SERVICE_ID_GETSTATE,FRNM_E_INVALID_POINTER,E_NOT_OK);
channelIndex = FrNm_ConfigPtr->FrNmChannelLookups[NetworkHandle];
ChannelInternal = &FrNm_Internal.FrNmChannels[channelIndex];
/* @req FRNM104 */
*nmStatePtr = ChannelInternal->State;
*nmModePtr = ChannelInternal->Mode;
return E_OK;
}
/**
*
* @param NetworkHandle
*/
/* FrSM when synchronization of the FlexRay cluster could not be achieved*/
/* @req FRNM393 */
void FrNm_StartupError( const NetworkHandleType NetworkHandle )
{
uint8 channelIndex;
const FrNm_ChannelInfoType* FrNmChannelsconf;
FrNm_Internal_ChannelType* ChannelInternal;
/* @req FRNM050 */ /* @req FRNM021 */
FRNM_DET_REPORTERROR((FRNM_STATUS_INIT == FrNm_Internal.InitStatus),FRNM_SERVICE_ID_STARTUPERROR,FRNM_E_UINIT);
/* @req FRNM051 */
FRNM_VALIDATE_CHANNEL(NetworkHandle, FRNM_SERVICE_ID_STARTUPERROR);
channelIndex = FrNm_ConfigPtr->FrNmChannelLookups[NetworkHandle];
FrNmChannelsconf = &FrNm_ConfigPtr->FrNmChannels[channelIndex];
ChannelInternal = &FrNm_Internal.FrNmChannels[channelIndex];
/* @req FRNM336 */ /* Go to bus sleep even when the FrNM Main function is no longer executing */
if(ChannelInternal->Mode == NM_MODE_SYNCHRONIZE ) {
if(ChannelInternal->FrNm_NetworkRequested == FALSE) {
/* @req FRNM376 */
ChannelInternal->State = NM_STATE_BUS_SLEEP;
ChannelInternal->Mode = NM_MODE_BUS_SLEEP;
FrNm_Internal_Resetvotedata(ChannelInternal);
/* @req FRNM134 */
#if ( FRNM_STATE_CHANGE_INDICATION_ENABLED == STD_ON) /* @req FRNM106 */
Nm_StateChangeNotification( FrNmChannelsconf->FrNmChannelIdentifiersConfig->FrNmComMNetworkHandleRef,NM_STATE_SYNCHRONIZE,NM_STATE_BUS_SLEEP);
#endif
Nm_BusSleepMode( FrNmChannelsconf->FrNmChannelIdentifiersConfig->FrNmComMNetworkHandleRef); /* @req FRNM135 */
ChannelInternal->FrNm_RepeatMessage = FALSE; /* @req FRNM320 */
} else {
/* @req FRNM340 */
/*No Changes remains in SYNCHRONIZE state */
}
} else if(ChannelInternal->Mode == NM_MODE_NETWORK) {
switch (ChannelInternal->State) {
case NM_STATE_REPEAT_MESSAGE:
/* @req FRNM383 */
#if (FRNM_CYCLE_COUNTER_EMULATION == STD_OFF)
ChannelInternal->Mode = NM_MODE_SYNCHRONIZE;
ChannelInternal->State = NM_STATE_SYNCHRONIZE;
FrNm_Internal_Resetvotedata(ChannelInternal);
#if ( FRNM_STATE_CHANGE_INDICATION_ENABLED == STD_ON) /* @req FRNM106 */
Nm_StateChangeNotification( FrNmChannelsconf->FrNmChannelIdentifiersConfig->FrNmComMNetworkHandleRef,NM_STATE_REPEAT_MESSAGE,NM_STATE_SYNCHRONIZE);
#endif
#else
/* @req FRNM385 */
ChannelInternal->Mode = NM_MODE_BUS_SLEEP;
ChannelInternal->State = NM_STATE_BUS_SLEEP;
FrNm_Internal_Resetvotedata(ChannelInternal);
/* @req FRNM134 */
#if ( FRNM_STATE_CHANGE_INDICATION_ENABLED == STD_ON) /* @req FRNM106 */
Nm_StateChangeNotification( FrNmChannelsconf->FrNmChannelIdentifiersConfig->FrNmComMNetworkHandleRef,NM_STATE_REPEAT_MESSAGE,NM_STATE_BUS_SLEEP);
#endif
Nm_BusSleepMode( FrNmChannelsconf->FrNmChannelIdentifiersConfig->FrNmComMNetworkHandleRef); /* @req FRNM135 */
ChannelInternal->FrNm_RepeatMessage = FALSE; /* @req FRNM320 */
#endif
break;
#if (FRNM_PASSIVE_MODE_ENABLED == STD_OFF)
case NM_STATE_NORMAL_OPERATION:
/* @req FRNM342*/
ChannelInternal->Mode = NM_MODE_SYNCHRONIZE;
ChannelInternal->State = NM_STATE_SYNCHRONIZE;
FrNm_Internal_Resetvotedata(ChannelInternal);
#if (FRNM_STATE_CHANGE_INDICATION_ENABLED == STD_ON) /* @req FRNM106 */
Nm_StateChangeNotification(FrNmChannelsconf->FrNmChannelIdentifiersConfig->FrNmComMNetworkHandleRef,NM_STATE_NORMAL_OPERATION, NM_STATE_SYNCHRONIZE);
#endif
break;
#endif
case NM_STATE_READY_SLEEP:
/* @req FRNM338 */
#if (FRNM_CYCLE_COUNTER_EMULATION == STD_OFF)
ChannelInternal->Mode = NM_MODE_SYNCHRONIZE;
ChannelInternal->State = NM_STATE_SYNCHRONIZE;
FrNm_Internal_Resetvotedata(ChannelInternal);
#if (FRNM_STATE_CHANGE_INDICATION_ENABLED == STD_ON)/* @req FRNM106 */
Nm_StateChangeNotification(FrNmChannelsconf->FrNmChannelIdentifiersConfig->FrNmComMNetworkHandleRef,NM_STATE_READY_SLEEP, NM_STATE_SYNCHRONIZE);
#endif
#else
ChannelInternal->Mode = NM_MODE_BUS_SLEEP;
ChannelInternal->State = NM_STATE_BUS_SLEEP;
FrNm_Internal_Resetvotedata(ChannelInternal);
/* @req FRNM134 */
#if ( FRNM_STATE_CHANGE_INDICATION_ENABLED == STD_ON) /* @req FRNM106 */
Nm_StateChangeNotification( FrNmChannelsconf->FrNmChannelIdentifiersConfig->FrNmComMNetworkHandleRef,NM_STATE_READY_SLEEP,NM_STATE_BUS_SLEEP);
#endif
Nm_BusSleepMode( FrNmChannelsconf->FrNmChannelIdentifiersConfig->FrNmComMNetworkHandleRef); /* @req FRNM135 */
ChannelInternal->FrNm_RepeatMessage = FALSE; /* @req FRNM320 */
#endif
break;
default:
/*Nothing to do */
break;
};
} else {
/*Nothing to do*/
}
}
/**
*
* @param FrNmTxPduId
* @param PduInfoPtr
* @return
*/
/*This function is used by the PduR to trigger a spontaneous transmission of an NM message with the provided NM User Data
* This function is only a dummy to avoid linker errors of the PduR */
/* @req FRNM359 */
Std_ReturnType FrNm_Transmit( PduIdType FrNmTxPduId, const PduInfoType* PduInfoPtr ){
(void)FrNmTxPduId;
(void)PduInfoPtr; /*lint !e920 pointer not used */
/* @req FRNM366 */
return E_OK;
}
/**
*
* @param nmChannelHandle
* @return
*/
/*Enable the NM PDU transmission ability due to a ISO14229 Communication Control (28hex) service*/
/* @req FRNM387*/
Std_ReturnType FrNm_EnableCommunication( const NetworkHandleType nmChannelHandle ) {
Std_ReturnType status;
/* @req FRNM050 *//* @req FRNM021 */
FRNM_DET_REPORTERROR((FRNM_STATUS_INIT == FrNm_Internal.InitStatus),FRNM_SERVICE_ID_ENABLECOMM,FRNM_E_UINIT, E_NOT_OK);
#if (FRNM_PASSIVE_MODE_ENABLED == STD_ON) /** @req FRNM389 */
(void)nmChannelHandle;
status = E_NOT_OK;
#else
status = E_OK;
uint8 channelIndex;
FrNm_Internal_ChannelType* ChannelInternal;
/* @req FRNM051 */
FRNM_VALIDATE_CHANNEL(nmChannelHandle, FRNM_SERVICE_ID_ENABLECOMM,E_NOT_OK);
channelIndex = FrNm_ConfigPtr->FrNmChannelLookups[nmChannelHandle];
ChannelInternal = &FrNm_Internal.FrNmChannels[channelIndex];
if(ChannelInternal->Mode != NM_MODE_NETWORK ) { /* @req FRNM388 */
status = E_NOT_OK ;
} else {
ChannelInternal->CommunicationEnabled = TRUE;
status = E_OK;
}
#endif
return status;
}
/**
*
* @param nmChannelHandle
* @return
*/
/*Disable the NM PDU transmission ability due to a ISO14229 Communication Control (28hex) service*/
/* @req FRNM390*/
Std_ReturnType FrNm_DisableCommunication( const NetworkHandleType nmChannelHandle ) {
/* @req FRNM050 */ /* @req FRNM021 */
Std_ReturnType status;
FRNM_DET_REPORTERROR((FRNM_STATUS_INIT == FrNm_Internal.InitStatus),FRNM_SERVICE_ID_DISABLECOMM,FRNM_E_UINIT, E_NOT_OK);
#if (FRNM_PASSIVE_MODE_ENABLED == STD_ON) /** @req FRNM392 */
(void)nmChannelHandle;
status = E_NOT_OK;
#else
status = E_OK;
uint8 channelIndex;
FrNm_Internal_ChannelType* ChannelInternal;
/* @req FRNM051 */
FRNM_VALIDATE_CHANNEL(nmChannelHandle, FRNM_SERVICE_ID_DISABLECOMM,E_NOT_OK);
channelIndex = FrNm_ConfigPtr->FrNmChannelLookups[nmChannelHandle];
ChannelInternal = &FrNm_Internal.FrNmChannels[channelIndex];
if(ChannelInternal->Mode != NM_MODE_NETWORK ) { /* @req FRNM391 */
status = E_NOT_OK;
} else {
ChannelInternal->CommunicationEnabled = FALSE;
status = E_OK;
}
#endif
return status;
}
/**
*
* @param nmChannelHandle
* @param nmSleepReadyBit
* @return
*/
/*
* Set the NM Coordinator Sleep Ready bit in the Control Bit Vector
* CURRENTLY UNSUPPORTED
*/
Std_ReturnType FrNm_SetSleepReadyBit( const NetworkHandleType nmChannelHandle, const boolean nmSleepReadyBit ){
/* @req FRNM050 */ /* @req FRNM021 */
FRNM_DET_REPORTERROR((FRNM_STATUS_INIT == FrNm_Internal.InitStatus),FRNM_SERVICE_ID_SETSLEEP_READYBIT,FRNM_E_UINIT, E_NOT_OK);
/* not supported */
(void)nmChannelHandle;
(void)nmSleepReadyBit;
return E_OK;
}
/** Functions called by Flexray Interface call back functions **/
/**
*
* @param RxPduId
* @param PduInfoPtr
*/
/*Indication of a received I-PDU from a lower layer communication module*/
/* @req FRNM251*/
/*lint -e{818} Pointer parameter 'PduInfoPtr' (line 717) could be declared as pointing to const */
void FrNm_RxIndication( PduIdType RxPduId, PduInfoType* PduInfoPtr ){
/* @req FRNM176*/ /* @req FRNM276*/
const FrNm_ChannelInfoType* FrNmChannelsconf;
FrNm_Internal_ChannelType* ChannelInternal;
uint8 pduIndex;
uint8 channelIndex;
uint8 cbv;
boolean repeatMessageBitIndication;
/* @req FRNM050 */ /* @req FRNM021 */ /* req FRNM361 */
FRNM_DET_REPORTERROR((FRNM_STATUS_INIT == FrNm_Internal.InitStatus),FRNM_SERVICE_ID_RX_INDICATION,FRNM_E_UINIT);
FRNM_DET_REPORTERROR((RxPduId < FRNM_RX_PDU_COUNT),FRNM_SERVICE_ID_RX_INDICATION,FRNM_E_PDU_ID_INVALID);
FRNM_DET_REPORTERROR((NULL != PduInfoPtr),FRNM_SERVICE_ID_RX_INDICATION,FRNM_E_INVALID_POINTER);
FRNM_DET_REPORTERROR((NULL != PduInfoPtr->SduDataPtr),FRNM_SERVICE_ID_RX_INDICATION,FRNM_E_INVALID_POINTER);
channelIndex = FrNm_ConfigPtr->FrNmChnlRxpduMaps[RxPduId];
FrNmChannelsconf = &FrNm_ConfigPtr->FrNmChannels[channelIndex];
ChannelInternal = &FrNm_Internal.FrNmChannels[channelIndex];
/* @req FRNM013 */
memcpy(ChannelInternal->FrNmRxDataPdu, PduInfoPtr->SduDataPtr, PduInfoPtr->SduLength);
cbv = ChannelInternal->FrNmRxDataPdu[CBV_INDEX];
repeatMessageBitIndication = cbv & FRNM_CBV_REPEAT_MESSAGE_REQUEST;
#if ((FRNM_PNC_EIRA_CALC_ENABLED == STD_ON) && (FRNM_PNC_COUNT > 0))
/* @req FRNM405 */ /* @req FRNM404 */ /* @req FRNM406 */ /* @req FRNM407 */ /* @req FRNM413 */
if (((cbv & FRNM_CBV_PNI) != 0) && (FrNmChannelsconf->FrNmChannelIdentifiersConfig->FrNmPnEnabled == STD_ON)) {
//Proces PN only if PNI information is available and PN is enabled
FrNm_Internal_RxProcess(ChannelInternal);
}
#endif
if (ChannelInternal->Mode == NM_MODE_BUS_SLEEP) {
/* Notify 'Network Start' */
/* @req FRNM175 */
Nm_NetworkStartIndication(FrNmChannelsconf->FrNmChannelIdentifiersConfig->FrNmComMNetworkHandleRef);
}else if(ChannelInternal->Mode == NM_MODE_NETWORK){
if(ChannelInternal->State == NM_STATE_NORMAL_OPERATION){
#if (FRNM_PASSIVE_MODE_ENABLED == STD_OFF)
if(TRUE == repeatMessageBitIndication){
FrNm_Internal_NormalOperation_to_RepeatMessage(FrNmChannelsconf, ChannelInternal);
}
#endif
}else if(ChannelInternal->State == NM_STATE_READY_SLEEP) {
for(pduIndex=0;pduIndex<FrNmChannelsconf->FrNmChannelIdentifiersConfig->FrNmRxPduCount;pduIndex++) {
if(RxPduId == FrNmChannelsconf->FrNmChannelIdentifiersConfig->FrNmRxPduList[pduIndex].FrNmRxPduId) {
if(FrNmChannelsconf->FrNmChannelIdentifiersConfig->FrNmRxPduList[pduIndex].FrNmRxConatainsVote == STD_ON) {
if((ChannelInternal->FrNmRxDataPdu[VOTE_INDEX] & VOTE_VALUE) == VOTE_VALUE) {
/* @req FRNM128 */ /* @req FRNM314 */
ChannelInternal->readySleepCntLeft = FrNmChannelsconf->FrNmTimingConfig->FrNmReadySleepCnt;
#if (FRNM_CYCLE_COUNTER_EMULATION ==STD_ON) /* @req FRNM378 */
ChannelInternal->syncLossTimerLeft = FrNmChannelsconf->FrNmTimingConfig->FrNmSyncLossTimer;
#endif
}
}
}
}
#if (FRNM_PASSIVE_MODE_ENABLED == STD_OFF)
if(TRUE == repeatMessageBitIndication){
FrNm_Internal_ReadySleep_to_RepeatMessage(FrNmChannelsconf, ChannelInternal);
}
#else
(void)repeatMessageBitIndication;
#endif
}else{
/*Nothing to do */
}
}else{
/*Nothing to do */
}
}
/**
*
* @param TxPduId
* @param PduInfoPtr
* @return
*/
/*The lower layer communication module requests the buffer of the SDU for transmission from the upper layer module*/
/* @req FRNM252*/
Std_ReturnType FrNm_TriggerTransmit( PduIdType TxPduId, PduInfoType* PduInfoPtr ){
#if (FRNM_PASSIVE_MODE_ENABLED == STD_ON)
(void)TxPduId;
(void)PduInfoPtr; /*lint !e920 Pointer unused */
return E_NOT_OK;
#else
uint8 pduIndex;
Std_ReturnType Status;
uint8 channelIndex;
const FrNm_ChannelInfoType* FrNmChannelsconf;
FrNm_Internal_ChannelType* ChannelInternal;
#if( FRNM_USER_DATA_ENABLED == STD_ON)
PduInfoType userData;
#endif
/* @req FRNM050 */ /* @req FRNM021 */
FRNM_DET_REPORTERROR((FRNM_STATUS_INIT == FrNm_Internal.InitStatus),FRNM_SERVICE_ID_TRIGGER_TRANSMIT,FRNM_E_UINIT,E_NOT_OK);
FRNM_DET_REPORTERROR((TxPduId < FRNM_TX_PDU_COUNT),FRNM_SERVICE_ID_TRIGGER_TRANSMIT,FRNM_E_PDU_ID_INVALID,E_NOT_OK);
FRNM_DET_REPORTERROR((NULL != PduInfoPtr),FRNM_SERVICE_ID_TRIGGER_TRANSMIT,FRNM_E_INVALID_POINTER,E_NOT_OK);
FRNM_DET_REPORTERROR((NULL != PduInfoPtr->SduDataPtr),FRNM_SERVICE_ID_TRIGGER_TRANSMIT,FRNM_E_INVALID_POINTER,E_NOT_OK);
if(FrNm_ConfigPtr->FrNmChnlTxpduMaps != NULL_PTR){
Status = E_OK;
/* @req FRNM277 */
channelIndex = FrNm_ConfigPtr->FrNmChnlTxpduMaps[TxPduId];
FrNmChannelsconf = &FrNm_ConfigPtr->FrNmChannels[channelIndex];
ChannelInternal = &FrNm_Internal.FrNmChannels[channelIndex];
for(pduIndex=0;pduIndex<FrNmChannelsconf->FrNmChannelIdentifiersConfig->FrNmTxPduCount;pduIndex++) {
if(FrNmChannelsconf->FrNmChannelIdentifiersConfig->FrNmTxPduList[pduIndex].FrNmTxConfPduId == TxPduId) {
if(((FrNmChannelsconf->FrNmChannelIdentifiersConfig->FrNmTxPduList[pduIndex].FrNmTxContainsData == STD_ON)
&&(FrNmChannelsconf->FrNmChannelIdentifiersConfig->FrNmTxPduList[pduIndex].FrNmTxConatainsVote == STD_ON))
||((FrNmChannelsconf->FrNmChannelIdentifiersConfig->FrNmTxPduList[pduIndex].FrNmTxContainsData == STD_ON)
&&(FrNmChannelsconf->FrNmChannelIdentifiersConfig->FrNmTxPduList[pduIndex].FrNmTxConatainsVote == STD_OFF))){
#if( FRNM_USER_DATA_ENABLED == STD_ON) /* @req FRNM362*/
if(NULL!=FrNmChannelsconf->FrNmChannelIdentifiersConfig->FrNmUserDataConfig){
userData.SduDataPtr = &ChannelInternal->FrNmTxDataPdu[FRNM_INTERNAL_GET_USER_DATA_OFFSET];
userData.SduLength = (PduLengthType)FrNmChannelsconf->FrNmChannelIdentifiersConfig->FrNmTxPduLength - FRNM_INTERNAL_GET_USER_DATA_OFFSET;
/* @req FRNM394 */ /* @req FRNM364 */
Status = PduR_FrNmTriggerTransmit(FrNmChannelsconf->FrNmChannelIdentifiersConfig->FrNmUserDataConfig->FrNmUserDataTxPduId,&userData);
if (Status == E_OK)
{
/* @req FRNM280 */
memcpy(PduInfoPtr->SduDataPtr, ChannelInternal->FrNmTxDataPdu, FrNmChannelsconf->FrNmChannelIdentifiersConfig->FrNmTxPduList[pduIndex].FrNmTxPduLength);
PduInfoPtr->SduLength = FrNmChannelsconf->FrNmChannelIdentifiersConfig->FrNmTxPduList[pduIndex].FrNmTxPduLength;
}
}
#else
memcpy(PduInfoPtr->SduDataPtr, ChannelInternal->FrNmTxDataPdu, FrNmChannelsconf->FrNmChannelIdentifiersConfig->FrNmTxPduList[pduIndex].FrNmTxPduLength);
PduInfoPtr->SduLength = FrNmChannelsconf->FrNmChannelIdentifiersConfig->FrNmTxPduList[pduIndex].FrNmTxPduLength;
#endif
}else if((FrNmChannelsconf->FrNmChannelIdentifiersConfig->FrNmTxPduList[pduIndex].FrNmTxContainsData == STD_OFF)
&&(FrNmChannelsconf->FrNmChannelIdentifiersConfig->FrNmTxPduList[pduIndex].FrNmTxConatainsVote == STD_ON)){
memcpy(PduInfoPtr->SduDataPtr, &ChannelInternal->FrNmTxVotePdu, FrNmChannelsconf->FrNmChannelIdentifiersConfig->FrNmTxPduList[pduIndex].FrNmTxPduLength);
PduInfoPtr->SduLength = FrNmChannelsconf->FrNmChannelIdentifiersConfig->FrNmTxPduList[pduIndex].FrNmTxPduLength;
}else{
/*Nothing to do */
}
}
}
}else{
Status = E_NOT_OK;
}
return Status;
#endif
}
/**
*
* @param TxPduId
*/
/*The lower layer communication module confirms the transmission of an I-PDU*/
/* req FRNM460 in 4.2 spec*/
void FrNm_TxConfirmation( PduIdType TxPduId ){
#if (FRNM_PASSIVE_MODE_ENABLED == STD_ON)
(void)TxPduId;
return;
#else
uint8 channelIndex;
FrNm_Internal_ChannelType* ChannelInternal;
const FrNm_ChannelInfoType* FrNmChannelsconf;
/* @req FRNM050 */ /* @req FRNM021 */
FRNM_DET_REPORTERROR((FRNM_STATUS_INIT == FrNm_Internal.InitStatus),FRNM_SERVICE_ID_TX_CONFIRMATION,FRNM_E_UINIT);
FRNM_DET_REPORTERROR((TxPduId < FRNM_TX_PDU_COUNT),FRNM_SERVICE_ID_TX_CONFIRMATION,FRNM_E_PDU_ID_INVALID);
if(FrNm_ConfigPtr->FrNmChnlTxpduMaps != NULL_PTR){
channelIndex = FrNm_ConfigPtr->FrNmChnlTxpduMaps[TxPduId];
ChannelInternal = &FrNm_Internal.FrNmChannels[channelIndex];
FrNmChannelsconf = &FrNm_ConfigPtr->FrNmChannels[channelIndex];
#if( FRNM_USER_DATA_ENABLED == STD_ON)
if(NULL!=FrNmChannelsconf->FrNmChannelIdentifiersConfig->FrNmUserDataConfig){
/* @req FRNM363 */ /* @req FRNM365 */
PduR_FrNmTxConfirmation(FrNmChannelsconf->FrNmChannelIdentifiersConfig->FrNmUserDataConfig->FrNmUserDataTxPduId);
}
#endif
ChannelInternal->MessageTimeoutTimeLeft = FrNmChannelsconf->FrNmTimingConfig->FrNmMsgTimeoutTime;
}
#endif
}
/* Scheduled main function */
/* ----------------------- */
/* Prototype right here because this function should not be exposed */
void FrNm_MainFunction(NetworkHandleType Channel);
/**
*
* @param Channel
*/
/*Main function of FlexRay NM*/
/* @req FRNM283 */
void FrNm_MainFunction(NetworkHandleType Channel){
/* @req FRNM356 */ /* @req FRNM168*/
uint8 channelIndex;
const FrNm_ChannelInfoType* FrNmChannelsconf;
FrNm_Internal_ChannelType* ChannelInternal;
uint8 FrIfCurrentCycle;
uint16 FrIfCurrentMacroTick;
uint8 FrIfCtrlID;
FrIfCurrentCycle =0;
FrIfCurrentMacroTick =0;
/* @req FRNM050 */ /* @req FRNM021 */ /* @req FRNM344*/
FRNM_DET_REPORTERROR((FRNM_STATUS_INIT == FrNm_Internal.InitStatus),(FRNM_SERVICE_ID_MAIN_FUNCTION+Channel),FRNM_E_UINIT);
/* @req FRNM051 */
FRNM_VALIDATE_CHANNEL(Channel, (FRNM_SERVICE_ID_MAIN_FUNCTION+Channel));
channelIndex = FrNm_ConfigPtr->FrNmChannelLookups[Channel];
FrNmChannelsconf = &FrNm_ConfigPtr->FrNmChannels[channelIndex];
ChannelInternal = &FrNm_Internal.FrNmChannels[channelIndex];
FrIfCtrlID = FrNm_ConfigPtr->FrNmChnlFrIfCtrlIdMap[channelIndex];
if(ChannelInternal->Mode != NM_MODE_BUS_SLEEP){
/* @req FRNM375 */
if (E_NOT_OK == FrIf_GetGlobalTime(FrIfCtrlID,&FrIfCurrentCycle,&FrIfCurrentMacroTick) ) {
FrNm_Internal_Globaltime_Error_Handling(FrNmChannelsconf, ChannelInternal);
}else{
if(ChannelInternal->Mode != NM_MODE_BUS_SLEEP){
FrNm_internal_CheckRepetitionCycles(FrNmChannelsconf, ChannelInternal, FrIfCurrentCycle);
}
#if (FRNM_HW_VOTE_ENABLE == STD_ON) /* @req FRNM169 */
uint8 frnmVectorDataPdu[8]= {0};
if(E_OK == FrIf_GetNmVector(FrIfCtrlID,frnmVectorDataPdu)) {
/* @req FRNM335 */
FrNm_Internal_Hardware_VectorData_Handling(frnmVectorDataPdu,FrNmChannelsconf, ChannelInternal);
}
#endif
if (ChannelInternal->Mode == NM_MODE_SYNCHRONIZE) {
if(ChannelInternal->repetitionCycleCompleted == TRUE) {
FrNm_Internal_Synchronize_to_RepeatMessage(FrNmChannelsconf, ChannelInternal);
}
}
if (ChannelInternal->Mode == NM_MODE_NETWORK) {
FrNm_Internal_TickRepeatMessageTime(FrNmChannelsconf, ChannelInternal );
#if (FRNM_PASSIVE_MODE_ENABLED == STD_OFF) /* Active mode handling */
FrNm_Internal_TickTxTimeout(FrNmChannelsconf, ChannelInternal);
if(ChannelInternal->repetitionCycleCompleted == TRUE) { /* @req FRNM115*/
if (ChannelInternal->State == NM_STATE_NORMAL_OPERATION){
if(ChannelInternal->FrNm_RepeatMessage == TRUE){
/* @req FRNM124*/
FrNm_Internal_NormalOperation_to_RepeatMessage(FrNmChannelsconf, ChannelInternal);
}else{
if(ChannelInternal->FrNm_NetworkRequested == FALSE)
{
/* @req FRNM125*/
FrNm_Internal_NormalOperation_to_ReadySleep(FrNmChannelsconf, ChannelInternal);
}
}
}else if (ChannelInternal->State == NM_STATE_READY_SLEEP){
FrNm_Internal_ReadySleepState_Handling(FrNmChannelsconf, ChannelInternal);
}else{
/* do nothing */
}
}
if ((ChannelInternal->State == NM_STATE_REPEAT_MESSAGE)||(ChannelInternal->State == NM_STATE_NORMAL_OPERATION)){
/* @req FRNM116*/ /* @req FRNM123*/
if (E_NOT_OK == FrNm_Internal_TransmitMessage(FrNmChannelsconf, ChannelInternal)){
/* do nothing added for lint warning */
}
}
#else /* Passive mode */
if((ChannelInternal->repetitionCycleCompleted == TRUE) &&
(ChannelInternal->State == NM_STATE_READY_SLEEP)){ /* @req FRNM115*/
FrNm_Internal_ReadySleepState_Handling(FrNmChannelsconf, ChannelInternal);
}
#endif
}
}
#if ((FRNM_PNC_EIRA_CALC_ENABLED == STD_ON) && (FRNM_PNC_COUNT > 0))
if (channelIndex == 0) { //Timer monitoring is done for the first channel
FrNm_Internal_TickPnEIRAResetTime(FrNmChannelsconf->FrNmTimingConfig->FrNmMainFunctionPeriod);
}
#endif
}
}
|
2301_81045437/classic-platform
|
communication/FrNm/src/FrNm.c
|
C
|
unknown
| 45,056
|
/*-------------------------------- 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 "FrNm.h"
#include "FrNm_Internal.h"
#include "PduR_FrNm.h"
#include "SchM_FrNm.h"
/*lint -esym(9003, FrNm_ConfigPtr) MISRA:OTHER:Readability:[MISRA 2012 Rule 8.9, advisory] */
extern const FrNm_ConfigType* FrNm_ConfigPtr ;
/*lint -esym(9003, FrNm_Internal) MISRA:OTHER:Readability:[MISRA 2012 Rule 8.9, advisory] */
extern FrNm_InternalType FrNm_Internal;
#define FRNM_LSBIT_MASK 0x1u
static inline void FrNm_Internal_ReadySleep_to_BusSleep( const FrNm_ChannelInfoType* ChannelConf, FrNm_Internal_ChannelType* ChannelInternal );
static inline void FrNm_Internal_RepeatMessage_to_ReadySleep( const FrNm_ChannelInfoType* ChannelConf, FrNm_Internal_ChannelType* ChannelInternal );
#if (FRNM_PASSIVE_MODE_ENABLED == STD_OFF)
static inline void FrNm_Internal_ReadySleep_to_NormalOperation( const FrNm_ChannelInfoType* ChannelConf, FrNm_Internal_ChannelType* ChannelInternal );
static inline void FrNm_Internal_RepeatMessage_to_NormalOperation( const FrNm_ChannelInfoType* ChannelConf, FrNm_Internal_ChannelType* ChannelInternal );
#endif /* FRNM_PASSIVE_MODE_ENABLED */
/**
* @brief Transition from Ready sleep state to Bus sleep state
* @param ChannelConf - Channel configuration data ptr
* @param ChannelInternal - Channel Internal runtime data ptr
* @return void
*/
static inline void FrNm_Internal_ReadySleep_to_BusSleep( const FrNm_ChannelInfoType* ChannelConf, FrNm_Internal_ChannelType* ChannelInternal ) {
/* @req FRNM129 */
ChannelInternal->Mode = NM_MODE_BUS_SLEEP;
ChannelInternal->State = NM_STATE_BUS_SLEEP;
ChannelInternal->MessageTimeoutTimeLeft = 0;
Nm_BusSleepMode( ChannelConf->FrNmChannelIdentifiersConfig->FrNmComMNetworkHandleRef); /* @req FRNM135 */
ChannelInternal->FrNm_RepeatMessage = FALSE; /* @req FRNM320 */
#if (FRNM_STATE_CHANGE_INDICATION_ENABLED == STD_ON) /* @req FRNM106 */
Nm_StateChangeNotification(ChannelConf->FrNmChannelIdentifiersConfig->FrNmComMNetworkHandleRef,NM_STATE_READY_SLEEP, NM_STATE_BUS_SLEEP);
#endif
}
/**
* @brief transit from Repeat message state to Ready sleep state in Network mode
* @param ChannelConf - Channel configuration data ptr
* @param ChannelInternal - Channel Internal runtime data ptr
* @return void
*/
static inline void FrNm_Internal_RepeatMessage_to_ReadySleep( const FrNm_ChannelInfoType* ChannelConf, FrNm_Internal_ChannelType* ChannelInternal ) {
ChannelInternal->Mode = NM_MODE_NETWORK;
ChannelInternal->State = NM_STATE_READY_SLEEP;
FrNm_Internal_Resetvotedata(ChannelInternal);
/* @req FRNM127 */
ChannelInternal->readySleepCntLeft = ChannelConf->FrNmTimingConfig->FrNmReadySleepCnt;
ChannelInternal->MessageTimeoutTimeLeft = 0 ;
#if (FRNM_STATE_CHANGE_INDICATION_ENABLED == STD_ON) /* @req FRNM106 */
Nm_StateChangeNotification(ChannelConf->FrNmChannelIdentifiersConfig->FrNmComMNetworkHandleRef, NM_STATE_REPEAT_MESSAGE, NM_STATE_READY_SLEEP);
#endif
#if (FRNM_CONTROL_BIT_VECTOR_ENABLED == STD_OFF)/* @req FRNM324 */
ChannelInternal->FrNmTxDataPdu[CBV_INDEX] = 0x00; /* @req FRNM3829 */
#else
#if(FRNM_REPEAT_MESSAGE_BIT_ENABLED == STD_ON)
ChannelInternal->FrNmTxDataPdu[CBV_INDEX] &=(uint8)~FRNM_CBV_REPEAT_MESSAGE_REQUEST;
#endif
#endif
}
#if (FRNM_PASSIVE_MODE_ENABLED == STD_OFF)
/**
* @brief Transition from Ready sleep state to Normal operation in Network mode
* @param ChannelConf - Channel configuration data ptr
* @param ChannelInternal - Channel Internal runtime data ptr
* @return void
*/
static inline void FrNm_Internal_ReadySleep_to_NormalOperation( const FrNm_ChannelInfoType* ChannelConf, FrNm_Internal_ChannelType* ChannelInternal ) {
ChannelInternal->Mode = NM_MODE_NETWORK;
ChannelInternal->State = NM_STATE_NORMAL_OPERATION;
ChannelInternal->MessageTimeoutTimeLeft = ChannelConf->FrNmTimingConfig->FrNmMsgTimeoutTime ;
#if (FRNM_STATE_CHANGE_INDICATION_ENABLED == STD_ON) /* @req FRNM106 */
Nm_StateChangeNotification(ChannelConf->FrNmChannelIdentifiersConfig->FrNmComMNetworkHandleRef, NM_STATE_READY_SLEEP, NM_STATE_NORMAL_OPERATION);
#endif
}
/**
* @brief Transit from Repeat message state to Normal operation state in Network mode
* @param ChannelConf - Channel configuration data ptr
* @param ChannelInternal - Channel Internal runtime data ptr
* @return void
*/
static inline void FrNm_Internal_RepeatMessage_to_NormalOperation( const FrNm_ChannelInfoType* ChannelConf, FrNm_Internal_ChannelType* ChannelInternal ) {
ChannelInternal->Mode = NM_MODE_NETWORK;
ChannelInternal->State = NM_STATE_NORMAL_OPERATION;
#if (FRNM_STATE_CHANGE_INDICATION_ENABLED == STD_ON) /* @req FRNM106 */
Nm_StateChangeNotification(ChannelConf->FrNmChannelIdentifiersConfig->FrNmComMNetworkHandleRef, NM_STATE_REPEAT_MESSAGE, NM_STATE_NORMAL_OPERATION);
#else
(void)*ChannelConf;
#endif
#if (FRNM_CONTROL_BIT_VECTOR_ENABLED == STD_OFF)/* @req FRNM324 */
ChannelInternal->FrNmTxDataPdu[CBV_INDEX] = 0x00; /* @req FRNM3829 */
#else
#if(FRNM_REPEAT_MESSAGE_BIT_ENABLED == STD_ON)
ChannelInternal->FrNmTxDataPdu[CBV_INDEX] &=(uint8)~FRNM_CBV_REPEAT_MESSAGE_REQUEST;
#endif
#endif
}
#endif /* FRNM_PASSIVE_MODE_ENABLED */
/**
* @brief Transit from Synchronize state to Normal operation state.
* @param ChannelConf - Channel configuration data ptr
* @param ChannelInternal - Channel Internal runtime data ptr
* @return void
*/
void FrNm_Internal_Synchronize_to_RepeatMessage( const FrNm_ChannelInfoType* ChannelConf, FrNm_Internal_ChannelType* ChannelInternal ) {
ChannelInternal->Mode = NM_MODE_NETWORK; /* @req FRNM143 */
ChannelInternal->State = NM_STATE_REPEAT_MESSAGE; /* @req FRNM108 */
/* @req FRNM119 */ /* @req FRNM117*/
ChannelInternal->RepeatMessageTimeLeft = ChannelConf->FrNmTimingConfig->FrNmRepeatMessageTime+ChannelConf->FrNmTimingConfig->FrNmMainFunctionPeriod;
/* @req FRNM109 */
ChannelInternal->FrNm_RepeatMessage = TRUE;
/* Notify 'Network Mode' */
Nm_NetworkMode(ChannelConf->FrNmChannelIdentifiersConfig->FrNmComMNetworkHandleRef); /* @req FRNM110 */
#if( FRNM_PASSIVE_MODE_ENABLED == STD_ON)
ChannelInternal->MessageTimeoutTimeLeft = 0; /* Disable timeout timer in passive mode*/
#else
ChannelInternal->MessageTimeoutTimeLeft = ChannelConf->FrNmTimingConfig->FrNmMsgTimeoutTime;
#endif
#if (FRNM_STATE_CHANGE_INDICATION_ENABLED == STD_ON) /* @req FRNM106 */
Nm_StateChangeNotification(ChannelConf->FrNmChannelIdentifiersConfig->FrNmComMNetworkHandleRef, NM_STATE_SYNCHRONIZE, NM_STATE_REPEAT_MESSAGE);
#endif
#if (FRNM_CONTROL_BIT_VECTOR_ENABLED == STD_OFF)/* @req FRNM324 */
ChannelInternal->FrNmTxDataPdu[CBV_INDEX] = 0x00; /* @req FRNM3829 */
#else
/* @req FRNM405 */
if (ChannelConf->FrNmChannelIdentifiersConfig->FrNmPnEnabled == STD_ON) {
ChannelInternal->FrNmTxDataPdu[CBV_INDEX] |= FRNM_CBV_PNI; /* @req FRNM404 */ /* @req FRNM409 */
} else {
ChannelInternal->FrNmTxDataPdu[CBV_INDEX] = 0;
}
#endif
if(ChannelInternal->activeWakeup == TRUE) {
#if (FRNM_CONTROL_BIT_VECTOR_ENABLED == STD_ON)
ChannelInternal->FrNmTxDataPdu[CBV_INDEX] |= (FRNM_CBV_ACTIVE_WAKEUP); /* @req FRNM297 */
#endif
/* Due to startup error transition to synchronize state flag is cleared */
ChannelInternal->activeWakeup = FALSE;
}
}
#if ((FRNM_PNC_EIRA_CALC_ENABLED == STD_ON) && (FRNM_PNC_COUNT > 0))
/**
* @brief restart PN timers
* @param pnIndex - Index of PNC
* @return void
*/
static inline void restartPnEiraTimer(uint8 pnIndex) {
uint8 timerIndex;
timerIndex = FrNm_ConfigPtr->FrNmPnInfo->FrNmPnIndexToTimerMap[pnIndex];
FrNm_Internal.pnEIRATimers[timerIndex].timerRunning = TRUE;
FrNm_Internal.pnEIRATimers[timerIndex].resetTimer = FRNM_PN_RESET_TIME;
}
/**
* @brief Identify the PN timer that needs to be restarted
* @param calcEIRA - EIRA of the new received/transmitted and filtered PDU
* @return void
*/
static void restartTimerForInternalExternalRequests(FrNm_Internal_RAType *calcEIRA) {
uint8 byteNo;
uint8 bit;
uint8 byteEIRA;
for (byteNo = 0; byteNo < FrNm_ConfigPtr->FrNmPnInfo->FrNmPnInfoLen; byteNo++) {
byteEIRA = calcEIRA->bytes[byteNo];
if ( byteEIRA > 0) {
for (bit = 0; bit < 8; bit++) {
if ((byteEIRA >> bit) & FRNM_LSBIT_MASK) {
restartPnEiraTimer((byteNo * 8) + bit);
} else {
/* Do nothing */
}
}
} else {
/* Do nothing */
}
}
}
/**
* @brief NM filtering process done for each reception
* @param ChannelConf - Channel configuration
* @param ChannelInternal - Channel internal runtime data
* @return reception valid or not
*
*/
void FrNm_Internal_RxProcess(FrNm_Internal_ChannelType* ChannelInternal ) {
FrNm_Internal_RAType calculatedEIRA = {0};
FrNm_Internal_RAType EIRAOld = {0};
PduInfoType pdu;
uint8 i;
uint8 offset;
boolean changed;
/* @req FRNM408 */
offset = FrNm_ConfigPtr->FrNmPnInfo->FrNmPnInfoOffset;
for (i = 0; i < FrNm_ConfigPtr->FrNmPnInfo->FrNmPnInfoLen; i++) {
/* Accumulate external requests *//* @req FRNM418 */ /* @req FRNM416 */ /* @req FRNM420 */ /* @req FRNM422 */
calculatedEIRA.bytes[i] = ChannelInternal->FrNmRxDataPdu[i + offset] & FrNm_ConfigPtr->FrNmPnInfo->FrNmPnInfoMask[i];
}
if (calculatedEIRA.data != 0){
SchM_Enter_FrNm_EA_0();
/* @req FRNM426 */
restartTimerForInternalExternalRequests(&calculatedEIRA);
EIRAOld.data = FrNm_Internal.pnEIRA.data;
FrNm_Internal.pnEIRA.data |= calculatedEIRA.data; /* @req FRNM423 */
changed = (EIRAOld.data != FrNm_Internal.pnEIRA.data) ? TRUE: FALSE;
SchM_Exit_FrNm_EA_0();
if (changed) {
pdu.SduDataPtr = &FrNm_Internal.pnEIRA.bytes[0];
pdu.SduLength = FrNm_ConfigPtr->FrNmPnInfo->FrNmPnInfoLen;
/* @req FRNM429 */
PduR_FrNmRxIndication(FrNm_ConfigPtr->FrNmPnInfo->FrNmEIRARxNSduId,&pdu);
}
}
}
/**
* @brief Determine internal requests from ComM and identify which PN timer has to be started
* @param pnInfo - Pn Info range of the transmitted PDU
* @return void
*/
void FrNm_Internal_ProcessTxPdu(uint8 *pnInfo) {
PduInfoType pdu;
FrNm_Internal_RAType calculatedEIRA = {0};
FrNm_Internal_RAType EIRAOld = {0};
uint8 byteNo;
boolean changed;
SchM_Enter_FrNm_EA_0();
for (byteNo = 0; byteNo < FrNm_ConfigPtr->FrNmPnInfo->FrNmPnInfoLen; byteNo++) {
/* @req FRNM418 FRNM416 FRNM420 FRNM422 */
calculatedEIRA.bytes[byteNo] = *(pnInfo + byteNo) & FrNm_ConfigPtr->FrNmPnInfo->FrNmPnInfoMask[byteNo]; /* Accumulate internal requests */
}
if (calculatedEIRA.data != 0) {
/* @req FRNM427 */
restartTimerForInternalExternalRequests(&calculatedEIRA);
EIRAOld.data = FrNm_Internal.pnEIRA.data;
FrNm_Internal.pnEIRA.data |= calculatedEIRA.data; /* @req FRNM424 */
changed = (EIRAOld.data != FrNm_Internal.pnEIRA.data) ? TRUE: FALSE;
if (changed) {
pdu.SduDataPtr = &FrNm_Internal.pnEIRA.bytes[0];
pdu.SduLength = FrNm_ConfigPtr->FrNmPnInfo->FrNmPnInfoLen;
/* @req FRNM429 */
PduR_FrNmRxIndication(FrNm_ConfigPtr->FrNmPnInfo->FrNmEIRARxNSduId,&pdu);
}
}
SchM_Exit_FrNm_EA_0();
}
/**
* @brief reset EIRA bits in case of timeout
* @param pnIndex - Indices of PNC which have timed out
* @param indexCount - No of PNC that have timed out
* @return void
*/
void FrNm_Internal_resetEIRAPNbits(uint8 *pnIndex, uint8 indexCount)
{
PduInfoType pdu;
uint8 byteNo;
uint8 bit;
uint8 idx;
for (idx=0;idx<indexCount;idx++)
{
byteNo = (*(pnIndex+idx))/8;
bit = (*(pnIndex+idx))%8;
FrNm_Internal.pnEIRA.bytes[byteNo] &= ~(1u<<bit); /* Reset PN bit */
}
pdu.SduDataPtr = &FrNm_Internal.pnEIRA.bytes[0];
pdu.SduLength = FrNm_ConfigPtr->FrNmPnInfo->FrNmPnInfoLen;
/* @req FRNM429 */
PduR_FrNmRxIndication(FrNm_ConfigPtr->FrNmPnInfo->FrNmEIRARxNSduId,&pdu);
}
/**
* @brief Run PN reset timers every main function cycle
* @param void
* @return void
*/
void FrNm_Internal_TickPnEIRAResetTime(uint32 mainFuncPeriod)
{
uint8 pncIndexReset[FRNM_PNC_COUNT]= {0};
uint8 len;
len = 0;
uint8 timerIdx;
SchM_Enter_FrNm_EA_0();
for (timerIdx=0; timerIdx<FRNM_PNC_COUNT;timerIdx++) {
if (FrNm_Internal.pnEIRATimers[timerIdx].timerRunning)
{
if (mainFuncPeriod >= FrNm_Internal.pnEIRATimers[timerIdx].resetTimer)
{
FrNm_Internal.pnEIRATimers[timerIdx].timerRunning = FALSE;
pncIndexReset[len] = FrNm_ConfigPtr->FrNmPnInfo->FrNmTimerIndexToPnMap[timerIdx];
len++;
} else {
FrNm_Internal.pnEIRATimers[timerIdx].resetTimer -= mainFuncPeriod;
}
}
}
if (len> 0)
{
/* @req FRNM428 */
FrNm_Internal_resetEIRAPNbits(pncIndexReset,len);
}
SchM_Exit_FrNm_EA_0();
}
#endif
/**
* @brief To handle cycles and time out of RepetitionCycles
* @param ChannelConf - Channel configuration data ptr
* @param ChannelInternal - Channel Internal runtime data ptr
* @param CurrentFlexrayCycle - Current flexray cycle received from FrIf and FrDrv
*/
void FrNm_internal_CheckRepetitionCycles(const FrNm_ChannelInfoType* ChannelConf, FrNm_Internal_ChannelType* ChannelInternal, uint8 CurrentFlexrayCycle ) {
#if (FRNM_MAIN_ACROSS_FRCYCLE == STD_ON)
if((CurrentFlexrayCycle%(uint8)ChannelConf->FrNmTimingConfig->FrNmRepetitionCycle) == 0) {
ChannelInternal->repetitionCycleCompleted = TRUE;
} else {
ChannelInternal->repetitionCycleCompleted = FALSE;
}
#else
if (((CurrentFlexrayCycle+1)%FRNM_MAX_FLEXRAY_CYCLE_COUNT)%ChannelConf->FrNmTimingConfig->FrNmRepetitionCycle == 0) {
ChannelInternal->repetitionCycleCompleted= TRUE;
} else {
ChannelInternal->repetitionCycleCompleted = FALSE;
}
#endif
}
/**
* @brief To handle ticks and time out of RepeatMessageTime
* @param ChannelConf - Channel configuration data ptr
* @param ChannelInternal - Channel Internal runtime data ptr
* @return void
*/
void FrNm_Internal_TickRepeatMessageTime( const FrNm_ChannelInfoType* ChannelConf, FrNm_Internal_ChannelType* ChannelInternal ) {
if(ChannelInternal->RepeatMessageTimeLeft != 0) {
if (ChannelConf->FrNmTimingConfig->FrNmMainFunctionPeriod >= ChannelInternal->RepeatMessageTimeLeft) {
ChannelInternal->RepeatMessageTimeLeft = 0;
/* @req FRNM120 */ /* @req FRNM112 */
ChannelInternal->FrNm_RepeatMessage = FALSE;
#if (FRNM_PASSIVE_MODE_ENABLED == STD_OFF)
if(ChannelInternal->FrNm_NetworkRequested == TRUE) {
/* @req FRNM121 */
FrNm_Internal_RepeatMessage_to_NormalOperation(ChannelConf, ChannelInternal);
}else
#endif
{
/* @req FRNM122 */
FrNm_Internal_RepeatMessage_to_ReadySleep(ChannelConf, ChannelInternal);
}
} else {
ChannelInternal->RepeatMessageTimeLeft -=(ChannelConf->FrNmTimingConfig->FrNmMainFunctionPeriod);
}
}
}
/**
* @brief Global time error states handling
* @param ChannelConf - Channel configuration data ptr
* @param ChannelInternal - Channel Internal runtime data ptr
* @return void
*/
void FrNm_Internal_Globaltime_Error_Handling( const FrNm_ChannelInfoType* ChannelConf, FrNm_Internal_ChannelType* ChannelInternal ) {
if(ChannelInternal->Mode == NM_MODE_NETWORK){
if(ChannelInternal->State == NM_STATE_REPEAT_MESSAGE){
/* @req FRNM386 */
#if (FRNM_CYCLE_COUNTER_EMULATION == STD_ON)
ChannelInternal->Mode = NM_MODE_BUS_SLEEP;
ChannelInternal->State = NM_STATE_BUS_SLEEP;
/* @req FRNM134 */
#if ( FRNM_STATE_CHANGE_INDICATION_ENABLED == STD_ON) /* @req FRNM106 */
Nm_StateChangeNotification( ChannelConf->FrNmChannelIdentifiersConfig->FrNmComMNetworkHandleRef, NM_STATE_REPEAT_MESSAGE,NM_STATE_BUS_SLEEP);
#endif
Nm_BusSleepMode( ChannelConf->FrNmChannelIdentifiersConfig->FrNmComMNetworkHandleRef); /* @req FRNM135 */
ChannelInternal->FrNm_RepeatMessage = FALSE; /* @req FRNM320 */
#else
/* @req FRNM384 */
ChannelInternal->Mode = NM_MODE_SYNCHRONIZE;
ChannelInternal->State = NM_STATE_SYNCHRONIZE;
#if ( FRNM_STATE_CHANGE_INDICATION_ENABLED == STD_ON) /* @req FRNM106 */
Nm_StateChangeNotification( ChannelConf->FrNmChannelIdentifiersConfig->FrNmComMNetworkHandleRef, NM_STATE_REPEAT_MESSAGE,NM_STATE_SYNCHRONIZE);
#endif
#endif
}else if(ChannelInternal->State == NM_STATE_NORMAL_OPERATION){
/* @req FRNM342*/
ChannelInternal->Mode = NM_MODE_SYNCHRONIZE;
ChannelInternal->State = NM_STATE_SYNCHRONIZE;
#if ( FRNM_STATE_CHANGE_INDICATION_ENABLED == STD_ON) /* @req FRNM106 */
Nm_StateChangeNotification( ChannelConf->FrNmChannelIdentifiersConfig->FrNmComMNetworkHandleRef, NM_STATE_NORMAL_OPERATION,NM_STATE_SYNCHRONIZE);
#else
(void)*ChannelConf;
#endif
}else if(ChannelInternal->State == NM_STATE_READY_SLEEP) {
#if (FRNM_CYCLE_COUNTER_EMULATION == STD_ON)
/* @req FRNM379*/
if (ChannelConf->FrNmTimingConfig->FrNmMainFunctionPeriod >= ChannelInternal->syncLossTimerLeft){
ChannelInternal->readySleepCntLeft--;
ChannelInternal->syncLossTimerLeft = ChannelConf->FrNmTimingConfig->FrNmSyncLossTimer;/* @req FRNM380*/
}
if(ChannelInternal->readySleepCntLeft<1){
/* As per 4.2.2 specification on below condition state should transit to BusSleep */
ChannelInternal->Mode = NM_MODE_BUS_SLEEP;
ChannelInternal->State = NM_STATE_BUS_SLEEP;
/* @req FRNM134 */
#if ( FRNM_STATE_CHANGE_INDICATION_ENABLED == STD_ON) /* @req FRNM106 */
Nm_StateChangeNotification( ChannelConf->FrNmChannelIdentifiersConfig->FrNmComMNetworkHandleRef, NM_STATE_READY_SLEEP,NM_STATE_BUS_SLEEP);
#endif
Nm_BusSleepMode( ChannelConf->FrNmChannelIdentifiersConfig->FrNmComMNetworkHandleRef); /* @req FRNM135 */
ChannelInternal->FrNm_RepeatMessage = FALSE; /* @req FRNM320 */
}
#endif
}else{
/* Do Nothing */
}
FrNm_Internal_Resetvotedata(ChannelInternal);
ChannelInternal->MessageTimeoutTimeLeft = 0;
#if (FRNM_CONTROL_BIT_VECTOR_ENABLED == STD_OFF)/* @req FRNM324 */
ChannelInternal->FrNmTxDataPdu[CBV_INDEX] = 0x00; /* @req FRNM3829 */
#else
/* due to startup error flags are reset */
ChannelInternal->FrNmTxDataPdu[CBV_INDEX] &= (uint8)~FRNM_CBV_ACTIVE_WAKEUP; /* @req FRNM298 */
ChannelInternal->FrNmTxDataPdu[CBV_INDEX] &= (uint8)~FRNM_CBV_REPEAT_MESSAGE_REQUEST;
#endif
}
}
#if (FRNM_PASSIVE_MODE_ENABLED == STD_OFF)
/**
* @brief Handle periodic NM message (vote, pdu and userdata) transmission
* @param ChannelConf - Channel configuration data ptr
* @param ChannelInternal - Channel Internal runtime data ptr
* @return void
*/
Std_ReturnType FrNm_Internal_TransmitMessage( const FrNm_ChannelInfoType* ChannelConf, FrNm_Internal_ChannelType* ChannelInternal ) {
/* @req FRNM148 */ /* @req FRNM151 */ /* @req FRNM100 */
Std_ReturnType Status;
PduInfoType datapdu= {
.SduDataPtr = &ChannelInternal->FrNmTxDataPdu[VOTE_INDEX],
.SduLength = ChannelConf->FrNmChannelIdentifiersConfig->FrNmTxPduLength,
};
PduInfoType votepdu= {
.SduDataPtr = &ChannelInternal->FrNmTxVotePdu,
.SduLength = VOTE_PDU_LENGTH,
};
PduIdType txdataPduId;
PduIdType txvotePduId;
/*This is only for initialization*/
txdataPduId = ChannelConf->FrNmChannelIdentifiersConfig->FrNmTxPduList->FrNmTxConfPduId;
txvotePduId = txdataPduId;
if (FALSE == ChannelInternal->CommunicationEnabled) {
/*lint -e{904} Return statement is necessary to avoid multiple if loops and hence increase readability in case of argument check */
return E_NOT_OK;
}
Status=E_NOT_OK;
/* @req FRNM160 */ /* @req FRNM337 */ /* @req FRNM147 */
if((ChannelConf->FrNmChannelIdentifiersConfig->FrNmPduScheduleVariant== FRNM_PDU_SCHEDULE_VARIANT_1)
||(ChannelConf->FrNmChannelIdentifiersConfig->FrNmPduScheduleVariant== FRNM_PDU_SCHEDULE_VARIANT_2)) {
if(E_OK == FrNm_Internal_Get_pdudataPtr_ForTx(ChannelConf, ChannelInternal,&datapdu,&txdataPduId)){
if(ChannelInternal->FrNm_NetworkRequested==TRUE){
/* @req FRNM055*/ /* @req FRNM156*/ /* @req FRNM215 */
ChannelInternal->FrNmTxDataPdu[VOTE_INDEX] |= VOTE_VALUE;
}else{
ChannelInternal->FrNmTxDataPdu[VOTE_INDEX] &= (uint8)~VOTE_VALUE;
}
Status = FrNm_Internal_Get_Userdata_ForTx(ChannelConf, ChannelInternal,&datapdu);
if(E_NOT_OK != Status){
Status = FrIf_Transmit(txdataPduId, &datapdu);/* @req FRNM010 */
}
}
} else if(ChannelConf->FrNmChannelIdentifiersConfig->FrNmPduScheduleVariant== FRNM_PDU_SCHEDULE_VARIANT_7) {/* @req FRNM160 */ /* @req FRNM337 */
if(E_OK == FrNm_Internal_Get_pduVote_ForTx(ChannelConf,&txvotePduId)){
if(ChannelInternal->FrNm_NetworkRequested==TRUE){
/* @req FRNM161*/ /* @req FRNM055*/ /* @req FRNM219 */ /* @req FRNM234 */ /* @req FRNM162 */
ChannelInternal->FrNmTxVotePdu = VOTE_VALUE|ChannelInternal->FrNmTxDataPdu[VOTE_INDEX];
}else{
ChannelInternal->FrNmTxVotePdu &= ((uint8)~VOTE_VALUE)|ChannelInternal->FrNmTxDataPdu[VOTE_INDEX];
}
Status = FrIf_Transmit(txvotePduId, &votepdu);/* @req FRNM147 */ /* @req FRNM010 */
}
if(Status == E_OK ){
Status =FrNm_Internal_Transmit_Nmpdudata(ChannelConf, ChannelInternal,&datapdu,&txdataPduId);
}
} else if((ChannelConf->FrNmChannelIdentifiersConfig->FrNmPduScheduleVariant== FRNM_PDU_SCHEDULE_VARIANT_3)
||(ChannelConf->FrNmChannelIdentifiersConfig->FrNmPduScheduleVariant== FRNM_PDU_SCHEDULE_VARIANT_4)
||(ChannelConf->FrNmChannelIdentifiersConfig->FrNmPduScheduleVariant== FRNM_PDU_SCHEDULE_VARIANT_5)
||(ChannelConf->FrNmChannelIdentifiersConfig->FrNmPduScheduleVariant== FRNM_PDU_SCHEDULE_VARIANT_6)){/* @req FRNM160 *//* @req FRNM337 */
if(E_OK == FrNm_Internal_Get_pduVote_ForTx(ChannelConf,&txvotePduId)){
if(ChannelInternal->FrNm_NetworkRequested==TRUE){
/* @req FRNM161*/ /* @req FRNM215 *//* @req FRNM216 */ /* @req FRNM218 */ /* @req FRNM219 */
ChannelInternal->FrNmTxVotePdu = VOTE_VALUE;
}else{
ChannelInternal->FrNmTxVotePdu &=(uint8)~VOTE_VALUE;
}
Status = FrIf_Transmit(txvotePduId, &votepdu); /* @req FRNM147 *//* @req FRNM010 */
}
if(Status == E_OK ){
Status =FrNm_Internal_Transmit_Nmpdudata(ChannelConf, ChannelInternal,&datapdu,&txdataPduId);
}
}else{
/*Nothing to do */
}
return Status;
}
/**
* @brief - To transmit pdu with user data to lower layers(FrIf).
* @param ChannelConf - Channel configuration data ptr
* @param ChannelInternal - Channel Internal runtime data ptr
* @param dataPduPtr - Transmission pdu data pointer
* @param dataPduId - FRIF pdu Id for transmission
* @return
*/
Std_ReturnType FrNm_Internal_Transmit_Nmpdudata(const FrNm_ChannelInfoType* ChannelConf, FrNm_Internal_ChannelType* ChannelInternal,PduInfoType* dataPduPtr, PduIdType* dataPduId){
Std_ReturnType Status;
Status = E_NOT_OK;
if(E_OK == FrNm_Internal_Get_pdudataPtr_ForTx(ChannelConf, ChannelInternal,dataPduPtr,dataPduId)){
/* @req FRNM214 */ /* @req FRNM157*/ /* @req FRNM161*/ /* @req FRNM055*/ /* @req FRNM156*/ /* @req FRNM216 */
ChannelInternal->FrNmTxDataPdu[VOTE_INDEX] &= (uint8)~VOTE_VALUE;
Status = FrNm_Internal_Get_Userdata_ForTx(ChannelConf, ChannelInternal,dataPduPtr);
if(E_NOT_OK != Status ){
/* @req FRNM147 */ /* @req FRNM010 */
Status = FrIf_Transmit(*dataPduId,dataPduPtr );
}
}
return Status;
}
/**
* @brief - To get the local vote data and Id for transmission.
* @param ChannelConf - Channel configuration data ptr
* @param ChannelInternal -Channel Internal local runtime data ptr
* @param dataPduId - FRIF vote pdu Id for transmission
* @return
*/
Std_ReturnType FrNm_Internal_Get_pduVote_ForTx( const FrNm_ChannelInfoType* ChannelConf,PduIdType* dataPduId ){
Std_ReturnType pdutxstatus;
uint8 pduIndex;
pdutxstatus = E_NOT_OK;
for(pduIndex=0;pduIndex<ChannelConf->FrNmChannelIdentifiersConfig->FrNmTxPduCount;pduIndex++) {
if(ChannelConf->FrNmChannelIdentifiersConfig->FrNmTxPduList[pduIndex].FrNmTxConatainsVote == STD_ON) {
*dataPduId = ChannelConf->FrNmChannelIdentifiersConfig->FrNmTxPduList[pduIndex].FrIfTxPduId;
pdutxstatus = E_OK;
}
}
return pdutxstatus;
}
/**
* @brief- To get the local User data and Id form upper layer transmission.
* @param ChannelConf - Channel configuration data ptr
* @param ChannelInternal -Channel Internal local runtime data ptr
* @param dataPduPtr - Transmission user data pointer
* @return
*/
Std_ReturnType FrNm_Internal_Get_Userdata_ForTx( const FrNm_ChannelInfoType* ChannelConf, FrNm_Internal_ChannelType* ChannelInternal, const PduInfoType* dataPduPtr ){
Std_ReturnType usrDataStatus;
usrDataStatus = E_OK;
if(ChannelInternal->setUserDataEnable == FALSE){
#if (FRNM_USER_DATA_ENABLED == STD_ON)
#if (FRNM_COM_USER_DATA_SUPPORT == STD_ON)
PduInfoType userData;
if(NULL!=ChannelConf->FrNmChannelIdentifiersConfig->FrNmUserDataConfig){
userData.SduDataPtr = &ChannelInternal->FrNmTxDataPdu[FRNM_INTERNAL_GET_USER_DATA_OFFSET];
userData.SduLength = dataPduPtr->SduLength - FRNM_INTERNAL_GET_USER_DATA_OFFSET;
/* IMPROVMENT: Add Det error when transmit is failing */
usrDataStatus = PduR_FrNmTriggerTransmit(ChannelConf->FrNmChannelIdentifiersConfig->FrNmUserDataConfig->FrNmUserDataTxPduId,&userData);
#if ((FRNM_PNC_EIRA_CALC_ENABLED == STD_ON) && (FRNM_PNC_COUNT > 0))
/* @req FRNM405 FRNM412 FRNM413 */
if (ChannelConf->FrNmChannelIdentifiersConfig->FrNmPnEnabled == STD_ON) {
FrNm_Internal_ProcessTxPdu(userData.SduDataPtr);
}
#endif
}
#endif
#endif
}else{
SchM_Enter_FrNm_EA_0();
ChannelInternal->setUserDataEnable = FALSE;
SchM_Exit_FrNm_EA_0();
}
return usrDataStatus;
}
/**
* @brief - To get the local pud data and Id for transmission.
* @param ChannelConf - Channel configuration data ptr
* @param ChannelInternal - Channel Internal runtime data ptr
* @param dataPduPtr - Transmission pdu data pointer
* @param dataPduId - FRIF pdu Id for transmission
* @return
*/
Std_ReturnType FrNm_Internal_Get_pdudataPtr_ForTx( const FrNm_ChannelInfoType* ChannelConf, FrNm_Internal_ChannelType* ChannelInternal, PduInfoType* dataPduPtr, PduIdType* dataPduId ){
Std_ReturnType pdutxstatus;
uint8 pduIndex;
pdutxstatus = E_NOT_OK;
for(pduIndex=0;pduIndex<ChannelConf->FrNmChannelIdentifiersConfig->FrNmTxPduCount;pduIndex++) {
if(ChannelConf->FrNmChannelIdentifiersConfig->FrNmTxPduList[pduIndex].FrNmTxContainsData == STD_ON) {
dataPduPtr->SduDataPtr = &ChannelInternal->FrNmTxDataPdu[VOTE_INDEX];
dataPduPtr->SduLength = ChannelConf->FrNmChannelIdentifiersConfig->FrNmTxPduList[pduIndex].FrNmTxPduLength;
*dataPduId = ChannelConf->FrNmChannelIdentifiersConfig->FrNmTxPduList[pduIndex].FrIfTxPduId;
pdutxstatus = E_OK;
}
}
return pdutxstatus;
}
/**
* @brief Tick timeout for Tx confirmation
* @param ChannelConf - Channel configuration data ptr
* @param ChannelInternal -Channel Internal local runtime data ptr
* @return void
*/
/* TxTimeout Processing */
void FrNm_Internal_TickTxTimeout( const FrNm_ChannelInfoType* ChannelConf, FrNm_Internal_ChannelType* ChannelInternal ){
if (0 != ChannelInternal->MessageTimeoutTimeLeft ) {
if (ChannelConf->FrNmTimingConfig->FrNmMainFunctionPeriod >= ChannelInternal->MessageTimeoutTimeLeft ) {
/** @req FRNM035 */
Nm_TxTimeoutException(ChannelConf->FrNmChannelIdentifiersConfig->FrNmComMNetworkHandleRef);
ChannelInternal->MessageTimeoutTimeLeft = ChannelConf->FrNmTimingConfig->FrNmMsgTimeoutTime ;
} else {
ChannelInternal->MessageTimeoutTimeLeft -= ChannelConf->FrNmTimingConfig->FrNmMainFunctionPeriod;
}
}
}
/**
* @brief Actions/Operation after entered in ReadySleepState
* @param ChannelConf - Channel configuration data ptr
* @param ChannelInternal -Channel Internal local runtime data ptr
*/
void FrNm_Internal_ReadySleepState_Handling(const FrNm_ChannelInfoType* ChannelConf, FrNm_Internal_ChannelType* ChannelInternal){
/* @req FRNM132 */ /* @req FRNM101 */
if(ChannelInternal->readySleepCntLeft>=1){
if(ChannelInternal->FrNm_RepeatMessage == TRUE){
/* @req FRNM130 */
FrNm_Internal_ReadySleep_to_RepeatMessage(ChannelConf, ChannelInternal);
}else{
/* @req FRNM131 */
if(ChannelInternal->FrNm_NetworkRequested == TRUE){
FrNm_Internal_ReadySleep_to_NormalOperation(ChannelConf, ChannelInternal);
}else {
ChannelInternal->readySleepCntLeft--;
}
}
}else if(ChannelInternal->readySleepCntLeft<1){
/* @req FRNM129 */ /* @req FRNM133 */
FrNm_Internal_ReadySleep_to_BusSleep(ChannelConf, ChannelInternal);
#if (FRNM_CONTROL_BIT_VECTOR_ENABLED == STD_OFF)/* @req FRNM324 */
ChannelInternal->FrNmTxDataPdu[CBV_INDEX] = 0x00; /* @req FRNM3829 */
#else
ChannelInternal->FrNmTxDataPdu[CBV_INDEX] &= (uint8)~FRNM_CBV_ACTIVE_WAKEUP; /* @req FRNM298 */
#endif
}else{
/* Nothing to do */
}
}
/**
* @brief Actions/Operations for reception when hardware vector data is enable
* @param HwvectorInfoPtr - Hardware vector pointer information
* @param ChannelConf - Channel configuration data ptr
* @param ChannelInternal -Channel Internal local runtime data ptr
*/
#if (FRNM_HW_VOTE_ENABLE == STD_ON)
void FrNm_Internal_Hardware_VectorData_Handling( const uint8* HwvectorInfoPtr, const FrNm_ChannelInfoType* ChannelConf, FrNm_Internal_ChannelType* ChannelInternal ) {
if(ChannelInternal->State == NM_STATE_READY_SLEEP) {
if((HwvectorInfoPtr[VOTE_INDEX] & VOTE_VALUE) == VOTE_VALUE) {
/* @req FRNM128 */ /* @req FRNM314 */
ChannelInternal->readySleepCntLeft = ChannelConf->FrNmTimingConfig->FrNmReadySleepCnt;
#if (FRNM_CYCLE_COUNTER_EMULATION ==STD_ON) /* @req FRNM378 */
ChannelInternal->syncLossTimerLeft = ChannelConf->FrNmTimingConfig->FrNmSyncLossTimer;
#endif
}
}
}
#endif
#else /* Passive mode */
/**
* @brief Actions/Operation after entered in ReadySleepState
* @param ChannelConf - Channel configuration data ptr
* @param ChannelInternal -Channel Internal local runtime data ptr
*/
void FrNm_Internal_ReadySleepState_Handling(const FrNm_ChannelInfoType* ChannelConf, FrNm_Internal_ChannelType* ChannelInternal){
ChannelInternal->readySleepCntLeft--;
if(ChannelInternal->readySleepCntLeft<1){
/* @req FRNM129 */ /* @req FRNM133 */
FrNm_Internal_ReadySleep_to_BusSleep(ChannelConf, ChannelInternal);
}
}
#endif
/**
* @brief To reset vote and pdu data in startup error, global time error and NM state machine
* @param ChannelInternal -Channel Internal local runtime data ptr
*/
void FrNm_Internal_Resetvotedata(FrNm_Internal_ChannelType* ChannelInternal){
#if (FRNM_PASSIVE_MODE_ENABLED == STD_OFF)
/* @req FRNM137 *//* @req FRNM308 */ /* @req FRNM126 */
ChannelInternal->FrNmTxVotePdu &=(uint8)~VOTE_VALUE;
ChannelInternal->FrNmTxDataPdu[VOTE_INDEX] &=(uint8)~VOTE_VALUE;
#else
(void)ChannelInternal; /*lint !e920 unused pointer*/
#endif
}
#ifdef HOST_TEST
/**
* * @brief - To compare the unit test cases result with internal data
*/
void GetFrNmChannelRunTimeData( const NetworkHandleType NetworkHandle , boolean* repeatMessage, boolean* networkRequested) {
uint8 channelIndex;
channelIndex = FrNm_ConfigPtr->FrNmChannelLookups[NetworkHandle];
const FrNm_Internal_ChannelType* ChannelInternal = &FrNm_Internal.FrNmChannels[channelIndex];
*repeatMessage = ChannelInternal->FrNm_RepeatMessage;
*networkRequested = ChannelInternal->FrNm_NetworkRequested;
}
#endif
|
2301_81045437/classic-platform
|
communication/FrNm/src/FrNm_Internal.c
|
C
|
unknown
| 34,627
|
/*-------------------------------- 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 FRNM_INTERNAL_H_
#define FRNM_INTERNAL_H_
//lint -emacro(904,FRNM_DET_REPORTERROR) //904 PC-Lint exception to MISRA 14.7 (validate DET macros).
#define FRNM_CBV_PNI 0x40u //CRI bit
typedef enum {
FRNM_STATUS_UNINIT,
FRNM_STATUS_INIT
}FrNm_Internal_InitStatusType;
/* @req FRNM425 */
typedef struct{
uint32 resetTimer;
boolean timerRunning;
}FrNm_Internal_PnTimerType;
/* Type used for both EIRA and ERA. */
typedef union {
uint64 data;
uint8 bytes[sizeof(uint64)];
}FrNm_Internal_RAType;
typedef struct{
Nm_ModeType Mode; /* @req FRNM105 */
Nm_StateType State; /* @req FRNM107 */
uint32 RepeatMessageTimeLeft;
uint32 MessageTimeoutTimeLeft;
uint32 syncLossTimerLeft;
uint16 readySleepCntLeft;
uint8 FrNmTxVotePdu;/* @req FRNM205 */ /* @req FRNM215 */
uint8 FrNmTxDataPdu[8];/* @req FRNM205 */ /* @req FRNM006 */
uint8 FrNmRxDataPdu[8]; /* @req FRNM205 */
uint8 FrNmTxUserdataMessagePdu[8];
uint8 RepetitionCyclesLeft;
uint8 DataCyclesLeft;
boolean repetitionCycleCompleted;
boolean CommunicationEnabled;
boolean activeWakeup;
boolean FrNm_NetworkRequested; /* @req FRNM167 */
boolean FrNm_RepeatMessage; /* @req FRNM118 */
boolean setUserDataEnable;
}FrNm_Internal_ChannelType;
typedef struct {
#if (FRNM_PNC_COUNT > 0)
FrNm_Internal_PnTimerType pnEIRATimers[FRNM_PNC_COUNT];
FrNm_Internal_RAType pnEIRA;
#endif
FrNm_Internal_InitStatusType InitStatus;
/*lint -e9038 Macro is well defined */
FrNm_Internal_ChannelType FrNmChannels[FRNM_NUMBER_OF_CLUSTERS];
}FrNm_InternalType;
#if (FRNM_DEV_ERROR_DETECT == STD_ON)/* @req FRNM022 */ /* @req FRNM049 */
#define FRNM_DET_REPORTERROR(_cond ,_api, _error, ...) \
if (!_cond) { \
(void)Det_ReportError(FRNM_MODULE_ID, 0, _api, _error); \
return __VA_ARGS__; \
}
#else
#define FRNM_DET_REPORTERROR(_cond ,_api, _error, ...) \
if (!_cond) { \
return __VA_ARGS__; \
}
#endif
#define FRNM_VALIDATE_CHANNEL(NetworkHandle, _api, ...) \
FRNM_DET_REPORTERROR(((NetworkHandle<COMM_CHANNEL_COUNT)&&(FrNm_ConfigPtr->FrNmChannelLookups[NetworkHandle]!=FRNM_UNUSED_CHANNEL)), _api, FRNM_E_INVALID_CHANNEL,__VA_ARGS__)
#if (FRNM_SOURCE_NODE_INDENTIFIER_ENABLED == STD_OFF)
#define FRNM_INTERNAL_GET_USER_DATA_OFFSET FRNM_USRDATA_WITHOUT_SOURCE_NODE_ID /* @req FRNM381 */
#else
#define FRNM_INTERNAL_GET_USER_DATA_OFFSET FRNM_USRDATA_WITH_SOURCE_NODE_ID /* @req FRNM222 */
#endif
void FrNm_Internal_Synchronize_to_RepeatMessage( const FrNm_ChannelInfoType* ChannelConf, FrNm_Internal_ChannelType* ChannelInternal );
void FrNm_Internal_TickRepeatMessageTime(const FrNm_ChannelInfoType* ChannelConf, FrNm_Internal_ChannelType* ChannelInternal );
void FrNm_internal_CheckRepetitionCycles(const FrNm_ChannelInfoType* ChannelConf, FrNm_Internal_ChannelType* ChannelInternal,uint8 CurrentFlexrayCycle);
void FrNm_Internal_Globaltime_Error_Handling( const FrNm_ChannelInfoType* ChannelConf, FrNm_Internal_ChannelType* ChannelInternal ) ;
#if (FRNM_PASSIVE_MODE_ENABLED == STD_OFF)
//inline void FrNm_Internal_NormalOperation_to_RepeatMessage( const FrNm_ChannelInfoType* ChannelConf, FrNm_Internal_ChannelType* ChannelInternal );
//inline void FrNm_Internal_NormalOperation_to_ReadySleep( const FrNm_ChannelInfoType* ChannelConf, FrNm_Internal_ChannelType* ChannelInternal );
Std_ReturnType FrNm_Internal_TransmitMessage( const FrNm_ChannelInfoType* ChannelConf, FrNm_Internal_ChannelType* ChannelInternal );
Std_ReturnType FrNm_Internal_Transmit_Nmpdudata(const FrNm_ChannelInfoType* ChannelConf, FrNm_Internal_ChannelType* ChannelInternal,PduInfoType* dataPduPtr, PduIdType* dataPduId);
Std_ReturnType FrNm_Internal_Get_pduVote_ForTx( const FrNm_ChannelInfoType* ChannelConf, PduIdType* dataPduId );
Std_ReturnType FrNm_Internal_Get_Userdata_ForTx( const FrNm_ChannelInfoType* ChannelConf, FrNm_Internal_ChannelType* ChannelInternal,const PduInfoType* dataPduPtr );
Std_ReturnType FrNm_Internal_Get_pdudataPtr_ForTx( const FrNm_ChannelInfoType* ChannelConf, FrNm_Internal_ChannelType* ChannelInternal, PduInfoType* dataPduPtr,PduIdType* dataPduId );
void FrNm_Internal_TickTxTimeout( const FrNm_ChannelInfoType* ChannelConf, FrNm_Internal_ChannelType* ChannelInternal );
//inline void FrNm_Internal_ReadySleep_to_RepeatMessage( const FrNm_ChannelInfoType* ChannelConf, FrNm_Internal_ChannelType* ChannelInternal );
#if (FRNM_HW_VOTE_ENABLE == STD_ON)
void FrNm_Internal_Hardware_VectorData_Handling( const uint8* HwvectorInfoPtr, const FrNm_ChannelInfoType* ChannelConf, FrNm_Internal_ChannelType* ChannelInternal );
#endif
#endif /* FRNM_PASSIVE_MODE_ENABLED */
void FrNm_Internal_Resetvotedata(FrNm_Internal_ChannelType* ChannelInternal);
void FrNm_Internal_ReadySleepState_Handling(const FrNm_ChannelInfoType* ChannelConf, FrNm_Internal_ChannelType* ChannelInternal);
#if ((FRNM_PNC_EIRA_CALC_ENABLED == STD_ON) && (FRNM_PNC_COUNT > 0))
void FrNm_Internal_RxProcess(FrNm_Internal_ChannelType* ChannelInternal );
void FrNm_Internal_TickPnEIRAResetTime(uint32 mainFuncPeriod);
void FrNm_Internal_resetEIRAPNbits(uint8 *pnIndex, uint8 indexCount);
void FrNm_Internal_ProcessTxPdu(uint8 *pnInfo);
#endif
#if (FRNM_PASSIVE_MODE_ENABLED == STD_OFF)
/**
* @brief Transit from Normal operation state to Repeat message state in Network mode
* @param ChannelConf - Channel configuration data ptr
* @param ChannelInternal - Channel Internal runtime data ptr
* @return void
*/
static inline void FrNm_Internal_NormalOperation_to_RepeatMessage( const FrNm_ChannelInfoType* ChannelConf, FrNm_Internal_ChannelType* ChannelInternal ) {
ChannelInternal->Mode = NM_MODE_NETWORK;
ChannelInternal->State = NM_STATE_REPEAT_MESSAGE;
/* @req FRNM117*/
ChannelInternal->RepeatMessageTimeLeft = ChannelConf->FrNmTimingConfig->FrNmRepeatMessageTime;
#if (FRNM_STATE_CHANGE_INDICATION_ENABLED == STD_ON) /* @req FRNM106 */
Nm_StateChangeNotification(ChannelConf->FrNmChannelIdentifiersConfig->FrNmComMNetworkHandleRef, NM_STATE_NORMAL_OPERATION, NM_STATE_REPEAT_MESSAGE);
#endif
}
/**
* @brief Transition from Normal operation state to Ready sleep in Network mode
* @param ChannelConf - Channel configuration data ptr
* @param ChannelInternal - Channel Internal runtime data ptr
* @return void
*/
static inline void FrNm_Internal_NormalOperation_to_ReadySleep( const FrNm_ChannelInfoType* ChannelConf, FrNm_Internal_ChannelType* ChannelInternal ) {
ChannelInternal->Mode = NM_MODE_NETWORK;
ChannelInternal->State = NM_STATE_READY_SLEEP;
FrNm_Internal_Resetvotedata(ChannelInternal);
/* @req FRNM127 */
ChannelInternal->readySleepCntLeft = ChannelConf->FrNmTimingConfig->FrNmReadySleepCnt;
ChannelInternal->MessageTimeoutTimeLeft = 0 ;
#if (FRNM_STATE_CHANGE_INDICATION_ENABLED == STD_ON) /* @req FRNM106 */
Nm_StateChangeNotification(ChannelConf->FrNmChannelIdentifiersConfig->FrNmComMNetworkHandleRef, NM_STATE_NORMAL_OPERATION, NM_STATE_READY_SLEEP);
#endif
}
/**
* @brief Transition from Ready sleep state to Repeat message state in Network mode
* @param ChannelConf - Channel configuration data ptr
* @param ChannelInternal - Channel Internal runtime data ptr
* @return void
*/
static inline void FrNm_Internal_ReadySleep_to_RepeatMessage( const FrNm_ChannelInfoType* ChannelConf, FrNm_Internal_ChannelType* ChannelInternal ) {
ChannelInternal->Mode = NM_MODE_NETWORK;
ChannelInternal->State = NM_STATE_REPEAT_MESSAGE;
/* @req FRNM117*/
ChannelInternal->RepeatMessageTimeLeft = ChannelConf->FrNmTimingConfig->FrNmRepeatMessageTime;
ChannelInternal->MessageTimeoutTimeLeft = ChannelConf->FrNmTimingConfig->FrNmMsgTimeoutTime ;
#if (FRNM_STATE_CHANGE_INDICATION_ENABLED == STD_ON) /* @req FRNM106 */
Nm_StateChangeNotification(ChannelConf->FrNmChannelIdentifiersConfig->FrNmComMNetworkHandleRef, NM_STATE_READY_SLEEP, NM_STATE_REPEAT_MESSAGE);
#endif
}
#endif
#endif /* FRNM_INTERNAL_H_ */
|
2301_81045437/classic-platform
|
communication/FrNm/src/FrNm_Internal.h
|
C
|
unknown
| 9,105
|