diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..2bb9647 --- /dev/null +++ b/.clang-format @@ -0,0 +1,41 @@ +AlignAfterOpenBracket: AlwaysBreak +AlignConsecutiveAssignments: true +AlignConsecutiveMacros: true +AllowAllArgumentsOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortIfStatementsOnASingleLine: Never +BinPackArguments: false +BinPackParameters: false +BreakBeforeBraces: Custom +BraceWrapping: + AfterCaseLabel: true + AfterClass: true + AfterControlStatement: true + AfterEnum: true + AfterFunction: true + AfterNamespace: true + AfterStruct: true + AfterUnion: true + BeforeCatch: true + BeforeElse: true + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: false + AfterExternBlock: false +ColumnLimit: 80 +ContinuationIndentWidth: 3 +IndentCaseLabels: false +IndentWidth: 3 +PenaltyBreakAssignment: 10 +PenaltyBreakBeforeFirstCallParameter: 30 +PenaltyBreakComment: 10 +PenaltyBreakString: 1000 +PenaltyExcessCharacter: 15 +PenaltyReturnTypeOnItsOwnLine: 100000 +PointerAlignment: Middle +SortIncludes: false +SpaceBeforeParens: NonEmptyParentheses +UseTab: Never diff --git a/include/iolink.h b/include/iolink.h index fee1e69..a3f3634 100644 --- a/include/iolink.h +++ b/include/iolink.h @@ -10,7 +10,6 @@ * See LICENSE file in the project root for full license information. ********************************************************************/ - #ifndef IOLINK_H #define IOLINK_H @@ -27,10 +26,13 @@ /* Assert that a compile-time constant expression is true. Trigger a compilation error otherwise. The only use of the first two macros is for the construction of the COMPILETIME_ASSERT() macro. */ -#define _COMPILETIME_ASSERT_SYMBOL_INNER(line_number) __COMPILETIME_ASSERT_ ## line_number -#define _COMPILETIME_ASSERT_SYMBOL(line_number) _COMPILETIME_ASSERT_SYMBOL_INNER(line_number) -#define COMPILETIME_ASSERT(constant_expression) \ - typedef char _COMPILETIME_ASSERT_SYMBOL(__LINE__) [ ((constant_expression) ? 1 : -1) ] +#define _COMPILETIME_ASSERT_SYMBOL_INNER(line_number) \ + __COMPILETIME_ASSERT_##line_number +#define _COMPILETIME_ASSERT_SYMBOL(line_number) \ + _COMPILETIME_ASSERT_SYMBOL_INNER (line_number) +#define COMPILETIME_ASSERT(constant_expression) \ + typedef char _COMPILETIME_ASSERT_SYMBOL ( \ + __LINE__)[((constant_expression) ? 1 : -1)] #endif #include @@ -45,8 +47,7 @@ #endif #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif /** @@ -55,14 +56,15 @@ extern "C" * */ -#define IOLINK_REVISION_1_1 0x11 +#define IOLINK_REVISION_1_1 0x11 -#define IOLINK_PD_MAX_SIZE 32 //!< Maximum number of bytes in Process Data +#define IOLINK_PD_MAX_SIZE 32 //!< Maximum number of bytes in Process Data typedef struct iolink_m_cfg iolink_m_cfg_t; typedef struct iolink_m iolink_m_t; -typedef uint8_t iolink_port_qualifier_info_t; //!< Port Qualifier Information (PQI) -typedef uint8_t iolink_port_quality_info_t; //!< Port Quality Information +typedef uint8_t iolink_port_qualifier_info_t; //!< Port Qualifier Information + //!< (PQI) +typedef uint8_t iolink_port_quality_info_t; //!< Port Quality Information /** * IO-Link PL modes @@ -105,33 +107,33 @@ typedef enum CC_PACKED_BEGIN typedef enum CC_PACKED iolink_arg_block_id { - IOLINK_ARG_BLOCK_ID_MASTERIDENT = 0x0001, - IOLINK_ARG_BLOCK_ID_FS_MASTER_ACCESS = 0x0100, - IOLINK_ARG_BLOCK_ID_W_MASTER_CFG = 0x0200, - IOLINK_ARG_BLOCK_ID_PD_IN = 0x1001, - IOLINK_ARG_BLOCK_ID_PD_OUT = 0x1002, - IOLINK_ARG_BLOCK_ID_PD_IN_OUT = 0x1003, - IOLINK_ARG_BLOCK_ID_SPDU_IN = 0x1101, - IOLINK_ARG_BLOCK_ID_SPDU_OUT = 0x1102, - IOLINK_ARG_BLOCK_ID_PD_IN_IQ = 0x1FFE, - IOLINK_ARG_BLOCK_ID_PD_OUT_IQ = 0x1FFF, - IOLINK_ARG_BLOCK_ID_OD_WR = 0x3000, - IOLINK_ARG_BLOCK_ID_OD_RD = 0x3001, - IOLINK_ARG_BLOCK_ID_DS_DATA = 0x7000, - IOLINK_ARG_BLOCK_ID_DEV_PAR_BAT = 0x7001, - IOLINK_ARG_BLOCK_ID_PORT_INXDEX_LIST = 0x7002, - IOLINK_ARG_BLOCK_ID_PORT_POWER = 0x7003, - IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST = 0x8000, - IOLINK_ARG_BLOCK_ID_FS_PORT_CFG_LIST = 0x8100, - IOLINK_ARG_BLOCK_ID_W_TRACK_CFG_LIST = 0x8200, - IOLINK_ARG_BLOCK_ID_PORT_STATUS_LIST = 0x9000, + IOLINK_ARG_BLOCK_ID_MASTERIDENT = 0x0001, + IOLINK_ARG_BLOCK_ID_FS_MASTER_ACCESS = 0x0100, + IOLINK_ARG_BLOCK_ID_W_MASTER_CFG = 0x0200, + IOLINK_ARG_BLOCK_ID_PD_IN = 0x1001, + IOLINK_ARG_BLOCK_ID_PD_OUT = 0x1002, + IOLINK_ARG_BLOCK_ID_PD_IN_OUT = 0x1003, + IOLINK_ARG_BLOCK_ID_SPDU_IN = 0x1101, + IOLINK_ARG_BLOCK_ID_SPDU_OUT = 0x1102, + IOLINK_ARG_BLOCK_ID_PD_IN_IQ = 0x1FFE, + IOLINK_ARG_BLOCK_ID_PD_OUT_IQ = 0x1FFF, + IOLINK_ARG_BLOCK_ID_OD_WR = 0x3000, + IOLINK_ARG_BLOCK_ID_OD_RD = 0x3001, + IOLINK_ARG_BLOCK_ID_DS_DATA = 0x7000, + IOLINK_ARG_BLOCK_ID_DEV_PAR_BAT = 0x7001, + IOLINK_ARG_BLOCK_ID_PORT_INXDEX_LIST = 0x7002, + IOLINK_ARG_BLOCK_ID_PORT_POWER = 0x7003, + IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST = 0x8000, + IOLINK_ARG_BLOCK_ID_FS_PORT_CFG_LIST = 0x8100, + IOLINK_ARG_BLOCK_ID_W_TRACK_CFG_LIST = 0x8200, + IOLINK_ARG_BLOCK_ID_PORT_STATUS_LIST = 0x9000, IOLINK_ARG_BLOCK_ID_FS_PORT_STATUS_LIST = 0x9100, IOLINK_ARG_BLOCK_ID_W_TRACK_STATUS_LIST = 0x9200, - IOLINK_ARG_BLOCK_ID_W_TRACK_SCAN_RES = 0x9201, - IOLINK_ARG_BLOCK_ID_DEV_EVENT = 0xA000, - IOLINK_ARG_BLOCK_ID_PORT_EVENT = 0xA001, - IOLINK_ARG_BLOCK_ID_VOID_BLOCK = 0xFFF0, - IOLINK_ARG_BLOCK_ID_JOB_ERROR = 0xFFFF, + IOLINK_ARG_BLOCK_ID_W_TRACK_SCAN_RES = 0x9201, + IOLINK_ARG_BLOCK_ID_DEV_EVENT = 0xA000, + IOLINK_ARG_BLOCK_ID_PORT_EVENT = 0xA001, + IOLINK_ARG_BLOCK_ID_VOID_BLOCK = 0xFFF0, + IOLINK_ARG_BLOCK_ID_JOB_ERROR = 0xFFFF, } iolink_arg_block_id_t; CC_PACKED_END @@ -143,36 +145,37 @@ CC_PACKED_END CC_PACKED_BEGIN typedef enum CC_PACKED iolink_eventcode { - IOLINK_EVENTCODE_NONE = 0x0000, - IOLINK_EVENTCODE_NO_DEV = 0x1800, - IOLINK_EVENTCODE_START_PARAM_ERR = 0x1801, - IOLINK_EVENTCODE_BAD_VID = 0x1802, - IOLINK_EVENTCODE_BAD_DID = 0x1803, - IOLINK_EVENTCODE_SHORT_CIR_CQ = 0x1804, - IOLINK_EVENTCODE_PHY_OVERTEMP = 0x1805, - IOLINK_EVENTCODE_SHORT_CIR_L = 0x1806, - IOLINK_EVENTCODE_OVERCUR_L = 0x1807, - IOLINK_EVENTCODE_DEV_EVENT_OVERF = 0x1808, + IOLINK_EVENTCODE_NONE = 0x0000, + IOLINK_EVENTCODE_NO_DEV = 0x1800, + IOLINK_EVENTCODE_START_PARAM_ERR = 0x1801, + IOLINK_EVENTCODE_BAD_VID = 0x1802, + IOLINK_EVENTCODE_BAD_DID = 0x1803, + IOLINK_EVENTCODE_SHORT_CIR_CQ = 0x1804, + IOLINK_EVENTCODE_PHY_OVERTEMP = 0x1805, + IOLINK_EVENTCODE_SHORT_CIR_L = 0x1806, + IOLINK_EVENTCODE_OVERCUR_L = 0x1807, + IOLINK_EVENTCODE_DEV_EVENT_OVERF = 0x1808, IOLINK_EVENTCODE_BACKUP_INCON_SIZE = 0x1809, - IOLINK_EVENTCODE_BACKUP_INCON_ID = 0x180A, - IOLINK_EVENTCODE_BACKUP_INCON = 0x180B, - IOLINK_EVENTCODE_BACKUP_INCON_UL = 0x180C, - IOLINK_EVENTCODE_BACKUP_INCON_DL = 0x180D, - IOLINK_EVENTCODE_P24 = 0x180E, - IOLINK_EVENTCODE_P24_SHORT_CIR = 0x180F, - IOLINK_EVENTCODE_SHORT_CIR_IQ = 0x1810, - IOLINK_EVENTCODE_SHORT_CIR_DO_CQ = 0x1811, - IOLINK_EVENTCODE_OVERCUR_IQ = 0x1812, - IOLINK_EVENTCODE_OVERCUR_CQ = 0x1813, + IOLINK_EVENTCODE_BACKUP_INCON_ID = 0x180A, + IOLINK_EVENTCODE_BACKUP_INCON = 0x180B, + IOLINK_EVENTCODE_BACKUP_INCON_UL = 0x180C, + IOLINK_EVENTCODE_BACKUP_INCON_DL = 0x180D, + IOLINK_EVENTCODE_P24 = 0x180E, + IOLINK_EVENTCODE_P24_SHORT_CIR = 0x180F, + IOLINK_EVENTCODE_SHORT_CIR_IQ = 0x1810, + IOLINK_EVENTCODE_SHORT_CIR_DO_CQ = 0x1811, + IOLINK_EVENTCODE_OVERCUR_IQ = 0x1812, + IOLINK_EVENTCODE_OVERCUR_CQ = 0x1813, IOLINK_EVENTCODE_INVAL_CYCTIME = 0x6000, - IOLINK_EVENTCODE_REV_FAULT = 0x6001, - IOLINK_EVENTCODE_ISDU_FAIL = 0x6002, + IOLINK_EVENTCODE_REV_FAULT = 0x6001, + IOLINK_EVENTCODE_ISDU_FAIL = 0x6002, IOLINK_EVENTCODE_PORT_STATUS_CHANGE = 0xFF26, - IOLINK_EVENTCODE_DS_UPLOAD_DONE = 0xFF27, + IOLINK_EVENTCODE_DS_UPLOAD_DONE = 0xFF27, - IOLINK_EVENTCODE_DEV_DS_UPLOAD_REQ = 0xFF91, /* From D.1 EventCodes for Devices */ + IOLINK_EVENTCODE_DEV_DS_UPLOAD_REQ = 0xFF91, /* From D.1 EventCodes for + Devices */ } iolink_eventcode_t; CC_PACKED_END @@ -183,10 +186,10 @@ CC_PACKED_BEGIN typedef enum CC_PACKED iolink_portmode { IOLINK_PORTMODE_DEACTIVE = 0, - IOLINK_PORTMODE_IOL_MAN = 1, + IOLINK_PORTMODE_IOL_MAN = 1, IOLINK_PORTMODE_IOL_AUTO = 2, - IOLINK_PORTMODE_DI_CQ = 3, - IOLINK_PORTMODE_DO_CQ = 4, + IOLINK_PORTMODE_DI_CQ = 3, + IOLINK_PORTMODE_DO_CQ = 4, } iolink_portmode_t; CC_PACKED_END @@ -196,11 +199,11 @@ CC_PACKED_END CC_PACKED_BEGIN typedef enum CC_PACKED iolink_validation_check { - IOLINK_VALIDATION_CHECK_NO = 0, - IOLINK_VALIDATION_CHECK_V10 = 1, - IOLINK_VALIDATION_CHECK_V11 = 2, + IOLINK_VALIDATION_CHECK_NO = 0, + IOLINK_VALIDATION_CHECK_V10 = 1, + IOLINK_VALIDATION_CHECK_V11 = 2, IOLINK_VALIDATION_CHECK_V11_BAK_RESTORE = 3, - IOLINK_VALIDATION_CHECK_V11_RESTORE = 4, + IOLINK_VALIDATION_CHECK_V11_RESTORE = 4, } iolink_validation_check_t; CC_PACKED_END @@ -208,23 +211,23 @@ CC_PACKED_BEGIN typedef enum CC_PACKED iolink_iq_behavior { IOLINK_IQ_BEHAVIOR_NO_SUPPORT = 0, - IOLINK_IQ_BEHAVIOR_DI = 1, - IOLINK_IQ_BEHAVIOR_DO = 2, - IOLINK_IQ_BEHAVIOR_RES1 = 3, - IOLINK_IQ_BEHAVIOR_RES2 = 4, - IOLINK_IQ_BEHAVIOR_POWER2 = 5, + IOLINK_IQ_BEHAVIOR_DI = 1, + IOLINK_IQ_BEHAVIOR_DO = 2, + IOLINK_IQ_BEHAVIOR_RES1 = 3, + IOLINK_IQ_BEHAVIOR_RES2 = 4, + IOLINK_IQ_BEHAVIOR_POWER2 = 5, } iolink_iq_behavior_t; CC_PACKED_END typedef enum { - IOLINK_PORT_TYPES_A = 0, - IOLINK_PORT_TYPES_A_POWER = 1, - IOLINK_PORT_TYPES_B = 2, + IOLINK_PORT_TYPES_A = 0, + IOLINK_PORT_TYPES_A_POWER = 1, + IOLINK_PORT_TYPES_B = 2, IOLINK_PORT_TYPES_FS_A_NO_OSSD = 3, - IOLINK_PORT_TYPES_FS_A_OSSD = 4, - IOLINK_PORT_TYPES_FS_B = 5, - IOLINK_PORT_TYPES_W_MASTER = 6, + IOLINK_PORT_TYPES_FS_A_OSSD = 4, + IOLINK_PORT_TYPES_FS_B = 5, + IOLINK_PORT_TYPES_W_MASTER = 6, } iolink_port_types_t; /** @@ -233,45 +236,45 @@ typedef enum CC_PACKED_BEGIN typedef enum CC_PACKED iolink_port_status_info { - IOLINK_PORT_STATUS_INFO_NO_DEV = 0, + IOLINK_PORT_STATUS_INFO_NO_DEV = 0, IOLINK_PORT_STATUS_INFO_DEACTIVATED = 1, - IOLINK_PORT_STATUS_INFO_PORT_DIAG = 2, - IOLINK_PORT_STATUS_INFO_PREOP = 3, - IOLINK_PORT_STATUS_INFO_OP = 4, - IOLINK_PORT_STATUS_INFO_DI = 5, - IOLINK_PORT_STATUS_INFO_DO = 6, - IOLINK_PORT_STATUS_INFO_POWER_OFF = 254, - IOLINK_PORT_STATUS_INFO_NOT_AVAIL = 255, + IOLINK_PORT_STATUS_INFO_PORT_DIAG = 2, + IOLINK_PORT_STATUS_INFO_PREOP = 3, + IOLINK_PORT_STATUS_INFO_OP = 4, + IOLINK_PORT_STATUS_INFO_DI = 5, + IOLINK_PORT_STATUS_INFO_DO = 6, + IOLINK_PORT_STATUS_INFO_POWER_OFF = 254, + IOLINK_PORT_STATUS_INFO_NOT_AVAIL = 255, } iolink_port_status_info_t; CC_PACKED_END /* Port Quality Info bits, iolink_port_quality_info_t */ /* PDIn bit0 */ -#define IOLINK_PORT_QUALITY_INFO_BIT 0 -#define IOLINK_PORT_QUALITY_INFO_VALID 0 +#define IOLINK_PORT_QUALITY_INFO_BIT 0 +#define IOLINK_PORT_QUALITY_INFO_VALID 0 #define IOLINK_PORT_QUALITY_INFO_INVALID BIT (IOLINK_PORT_QUALITY_INFO_BIT) /* PDOut bit1 */ -#define IOLINK_PORT_QUALITY_INFO_PDO_BIT 1 +#define IOLINK_PORT_QUALITY_INFO_PDO_BIT 1 #define IOLINK_PORT_QUALITY_INFO_PDO_VALID 0 -#define IOLINK_PORT_QUALITY_INFO_PDO_INVALID \ - BIT (IOLINK_PORT_QUALITY_INFO_PDO_BIT) +#define IOLINK_PORT_QUALITY_INFO_PDO_INVALID \ + BIT (IOLINK_PORT_QUALITY_INFO_PDO_BIT) /* Port Qualifier Information bits, iolink_port_qualifier_info_t */ /* DevCom bit5 */ -#define IOLINK_PORT_QUALIFIER_INFO_COM_BIT 5 +#define IOLINK_PORT_QUALIFIER_INFO_COM_BIT 5 #define IOLINK_PORT_QUALIFIER_INFO_COM_VALID 0 -#define IOLINK_PORT_QUALIFIER_INFO_COM_INVALID \ - BIT (IOLINK_PORT_QUALIFIER_INFO_COM_BIT) +#define IOLINK_PORT_QUALIFIER_INFO_COM_INVALID \ + BIT (IOLINK_PORT_QUALIFIER_INFO_COM_BIT) /* DevErr bit6 */ -#define IOLINK_PORT_QUALIFIER_INFO_ERR_BIT 6 +#define IOLINK_PORT_QUALIFIER_INFO_ERR_BIT 6 #define IOLINK_PORT_QUALIFIER_INFO_ERR_VALID 0 -#define IOLINK_PORT_QUALIFIER_INFO_ERR_INVALID \ - BIT (IOLINK_PORT_QUALIFIER_INFO_ERR_BIT) +#define IOLINK_PORT_QUALIFIER_INFO_ERR_INVALID \ + BIT (IOLINK_PORT_QUALIFIER_INFO_ERR_BIT) /* PQ bit7 */ -#define IOLINK_PORT_QUALIFIER_INFO_PQ_BIT 7 +#define IOLINK_PORT_QUALIFIER_INFO_PQ_BIT 7 #define IOLINK_PORT_QUALIFIER_INFO_PQ_VALID 0 -#define IOLINK_PORT_QUALIFIER_INFO_PQ_INVALID \ - BIT (IOLINK_PORT_QUALIFIER_INFO_PQ_BIT) //!< Port Qualifier bit in QPI +#define IOLINK_PORT_QUALIFIER_INFO_PQ_INVALID \ + BIT (IOLINK_PORT_QUALIFIER_INFO_PQ_BIT) //!< Port Qualifier bit in QPI /** * Transmission rates @@ -280,9 +283,9 @@ CC_PACKED_BEGIN typedef enum CC_PACKED iolink_transmission_rate { IOLINK_TRANSMISSION_RATE_NOT_DETECTED = 0, - IOLINK_TRANSMISSION_RATE_COM1 = 1, - IOLINK_TRANSMISSION_RATE_COM2 = 2, - IOLINK_TRANSMISSION_RATE_COM3 = 3, + IOLINK_TRANSMISSION_RATE_COM1 = 1, + IOLINK_TRANSMISSION_RATE_COM2 = 2, + IOLINK_TRANSMISSION_RATE_COM3 = 3, } iolink_transmission_rate_t; CC_PACKED_END @@ -296,39 +299,39 @@ typedef enum CC_PACKED iolink_smi_errortypes { IOLINK_SMI_ERRORTYPE_NONE = 0x0000, /* Table C.1 ErrorTypes */ - IOLINK_SMI_ERRORTYPE_APP_DEV = 0x8000, - IOLINK_SMI_ERRORTYPE_IDX_NOTAVAIL = 0x8011, - IOLINK_SMI_ERRORTYPE_SUBIDX_NOTAVAIL = 0x8012, - IOLINK_SMI_ERRORTYPE_SERV_NOTAVAIL = 0x8020, + IOLINK_SMI_ERRORTYPE_APP_DEV = 0x8000, + IOLINK_SMI_ERRORTYPE_IDX_NOTAVAIL = 0x8011, + IOLINK_SMI_ERRORTYPE_SUBIDX_NOTAVAIL = 0x8012, + IOLINK_SMI_ERRORTYPE_SERV_NOTAVAIL = 0x8020, IOLINK_SMI_ERRORTYPE_SERV_NOTAVAIL_LOCCTRL = 0x8021, IOLINK_SMI_ERRORTYPE_SERV_NOTAVAIL_DEVCTRL = 0x8022, - IOLINK_SMI_ERRORTYPE_IDX_NOT_ACCESSIBLE = 0x8023, - IOLINK_SMI_ERRORTYPE_PAR_VALOUTOFRNG = 0x8030, - IOLINK_SMI_ERRORTYPE_PAR_VALGTLIM = 0x8031, - IOLINK_SMI_ERRORTYPE_PAR_VALLTLIM = 0x8032, - IOLINK_SMI_ERRORTYPE_VAL_LENOVRRUN = 0x8033, /* Also in C.2 */ - IOLINK_SMI_ERRORTYPE_VAL_LENUNDRUN = 0x8034, - IOLINK_SMI_ERRORTYPE_FUNC_NOTAVAIL = 0x8035, - IOLINK_SMI_ERRORTYPE_FUNC_UNAVAILTEMP = 0x8036, - IOLINK_SMI_ERRORTYPE_PAR_SETINVALID = 0x8040, - IOLINK_SMI_ERRORTYPE_PAR_SETINCONSIST = 0x8041, - IOLINK_SMI_ERRORTYPE_APP_DEVNOTRDY = 0x8082, - IOLINK_SMI_ERRORTYPE_UNSPECIFIC = 0x8100, + IOLINK_SMI_ERRORTYPE_IDX_NOT_ACCESSIBLE = 0x8023, + IOLINK_SMI_ERRORTYPE_PAR_VALOUTOFRNG = 0x8030, + IOLINK_SMI_ERRORTYPE_PAR_VALGTLIM = 0x8031, + IOLINK_SMI_ERRORTYPE_PAR_VALLTLIM = 0x8032, + IOLINK_SMI_ERRORTYPE_VAL_LENOVRRUN = 0x8033, /* Also in C.2 */ + IOLINK_SMI_ERRORTYPE_VAL_LENUNDRUN = 0x8034, + IOLINK_SMI_ERRORTYPE_FUNC_NOTAVAIL = 0x8035, + IOLINK_SMI_ERRORTYPE_FUNC_UNAVAILTEMP = 0x8036, + IOLINK_SMI_ERRORTYPE_PAR_SETINVALID = 0x8040, + IOLINK_SMI_ERRORTYPE_PAR_SETINCONSIST = 0x8041, + IOLINK_SMI_ERRORTYPE_APP_DEVNOTRDY = 0x8082, + IOLINK_SMI_ERRORTYPE_UNSPECIFIC = 0x8100, /* Table C.2 Derivced ErrorTypes */ - IOLINK_SMI_ERRORTYPE_COM_ERR = 0x1000, + IOLINK_SMI_ERRORTYPE_COM_ERR = 0x1000, IOLINK_SMI_ERRORTYPE_I_SERVICE_TIMEOUT = 0x1100, - IOLINK_SMI_ERRORTYPE_M_ISDU_CHECKSUM = 0x5600, - IOLINK_SMI_ERRORTYPE_M_ISDU_ILLEGAL = 0x5700, + IOLINK_SMI_ERRORTYPE_M_ISDU_CHECKSUM = 0x5600, + IOLINK_SMI_ERRORTYPE_M_ISDU_ILLEGAL = 0x5700, /* Table C.3 SMI related ErrorTypes */ - IOLINK_SMI_ERRORTYPE_ARGBLOCK_NOT_SUPPORTED = 0x4001, - IOLINK_SMI_ERRORTYPE_ARGBLOCK_INCONSISTENT = 0x4002, - IOLINK_SMI_ERRORTYPE_DEV_NOT_ACCESSIBLE = 0x4003, - IOLINK_SMI_ERRORTYPE_SERVICE_NOT_SUPPORTED = 0x4004, - IOLINK_SMI_ERRORTYPE_DEV_NOT_IN_OPERATE = 0x4005, - IOLINK_SMI_ERRORTYPE_MEMORY_OVERRUN = 0x4006, - IOLINK_SMI_ERRORTYPE_PORT_NUM_INVALID = 0x4011, - IOLINK_SMI_ERRORTYPE_ARGBLOCK_LENGTH_INVALID = 0x4034, + IOLINK_SMI_ERRORTYPE_ARGBLOCK_NOT_SUPPORTED = 0x4001, + IOLINK_SMI_ERRORTYPE_ARGBLOCK_INCONSISTENT = 0x4002, + IOLINK_SMI_ERRORTYPE_DEV_NOT_ACCESSIBLE = 0x4003, + IOLINK_SMI_ERRORTYPE_SERVICE_NOT_SUPPORTED = 0x4004, + IOLINK_SMI_ERRORTYPE_DEV_NOT_IN_OPERATE = 0x4005, + IOLINK_SMI_ERRORTYPE_MEMORY_OVERRUN = 0x4006, + IOLINK_SMI_ERRORTYPE_PORT_NUM_INVALID = 0x4011, + IOLINK_SMI_ERRORTYPE_ARGBLOCK_LENGTH_INVALID = 0x4034, IOLINK_SMI_ERRORTYPE_SERVICE_TEMP_UNAVAILABLE = 0x4036, } iolink_smi_errortypes_t; CC_PACKED_END @@ -336,11 +339,11 @@ CC_PACKED_END CC_PACKED_BEGIN typedef enum CC_PACKED iolink_master_type { - IOLINK_MASTER_TYPE_UNSPEC = 0, - IOLINK_MASTER_TYPE_RESERVED = 1, + IOLINK_MASTER_TYPE_UNSPEC = 0, + IOLINK_MASTER_TYPE_RESERVED = 1, IOLINK_MASTER_TYPE_MASTER_ACC = 2, - IOLINK_MASTER_TYPE_FS = 3, - IOLINK_MASTER_TYPE_W = 4, + IOLINK_MASTER_TYPE_FS = 3, + IOLINK_MASTER_TYPE_W = 4, } iolink_master_type_t; CC_PACKED_END @@ -411,7 +414,8 @@ typedef struct CC_PACKED arg_block_pdinout /* data[0] = in_len * data[1] = in_data0, data[2] = in_data1 ... data[in_len] = in_dataN * data[in_len + 1] = out_len - * data[in_len + 2] = out_data0, data[in_len + 3] = out_data1 ... data[in_len + out_len = 1] = out_dataM + * data[in_len + 2] = out_data0, data[in_len + 3] = out_data1 ... data[in_len + * + out_len = 1] = out_dataM */ uint8_t data[1 + IOLINK_PD_MAX_SIZE + 1 + IOLINK_PD_MAX_SIZE]; } arg_block_pdinout_t; @@ -490,8 +494,8 @@ CC_PACKED_BEGIN typedef struct CC_PACKED arg_block_devevent { iolink_arg_block_id_t arg_block_id; // IOLINK_ARG_BLOCK_ID_DEV_EVENT - diag_entry_t diag_entry[6]; // TODO diag_entry_t diag_entry - uint8_t event_count; // TODO remove + diag_entry_t diag_entry[6]; // TODO diag_entry_t diag_entry + uint8_t event_count; // TODO remove } arg_block_devevent_t; CC_PACKED_END @@ -538,41 +542,52 @@ typedef struct CC_PACKED arg_block } arg_block_t; CC_PACKED_END -COMPILETIME_ASSERT (sizeof(iolink_portmode_t) == 1); -COMPILETIME_ASSERT (sizeof(iolink_validation_check_t) == 1); -COMPILETIME_ASSERT (sizeof(iolink_iq_behavior_t) == 1); -COMPILETIME_ASSERT (sizeof(iolink_arg_block_id_t) == 2); -COMPILETIME_ASSERT (sizeof(iolink_port_status_info_t) == 1); -COMPILETIME_ASSERT (sizeof(iolink_transmission_rate_t) == 1); - -COMPILETIME_ASSERT (sizeof(diag_entry_t) == 3); - -COMPILETIME_ASSERT (sizeof(arg_block_masterident_head_t) == 12); -COMPILETIME_ASSERT (sizeof(arg_block_masterident_t) == sizeof(arg_block_masterident_head_t) + sizeof(iolink_port_types_t) * IOLINK_NUM_PORTS); - -COMPILETIME_ASSERT (sizeof(arg_block_pdin_head_t) == 4); -COMPILETIME_ASSERT (sizeof(arg_block_pdin_t) == sizeof(arg_block_pdin_head_t) + IOLINK_PD_MAX_SIZE); - -COMPILETIME_ASSERT (sizeof(arg_block_pdout_head_t) == 4); -COMPILETIME_ASSERT (sizeof(arg_block_pdout_t) == sizeof(arg_block_pdout_head_t) + IOLINK_PD_MAX_SIZE); - -COMPILETIME_ASSERT (sizeof( arg_block_pdinout_head_t) == 4); -COMPILETIME_ASSERT (sizeof(arg_block_pdinout_t) == sizeof(arg_block_pdinout_head_t) + 2 + 2 * IOLINK_PD_MAX_SIZE); - -COMPILETIME_ASSERT (sizeof(arg_block_od_t) == 5); -COMPILETIME_ASSERT (sizeof(arg_block_ds_data_t) == 2 + 12); - -COMPILETIME_ASSERT (sizeof(portconfiglist_t) == 12); -COMPILETIME_ASSERT (sizeof(arg_block_portconfiglist_t) == 2 + sizeof(portconfiglist_t)); - -COMPILETIME_ASSERT (sizeof(arg_block_portstatuslist_t) == sizeof(diag_entry_t *) + 15); -COMPILETIME_ASSERT (sizeof(arg_block_devevent_t) == 3 + sizeof(diag_entry_t) * 6); -COMPILETIME_ASSERT (sizeof(arg_block_portevent_t) == 5); -COMPILETIME_ASSERT (sizeof(arg_block_void_t) == 2); -COMPILETIME_ASSERT (sizeof(arg_block_joberror_t) == 6); +COMPILETIME_ASSERT (sizeof (iolink_portmode_t) == 1); +COMPILETIME_ASSERT (sizeof (iolink_validation_check_t) == 1); +COMPILETIME_ASSERT (sizeof (iolink_iq_behavior_t) == 1); +COMPILETIME_ASSERT (sizeof (iolink_arg_block_id_t) == 2); +COMPILETIME_ASSERT (sizeof (iolink_port_status_info_t) == 1); +COMPILETIME_ASSERT (sizeof (iolink_transmission_rate_t) == 1); + +COMPILETIME_ASSERT (sizeof (diag_entry_t) == 3); + +COMPILETIME_ASSERT (sizeof (arg_block_masterident_head_t) == 12); +COMPILETIME_ASSERT ( + sizeof (arg_block_masterident_t) == + sizeof (arg_block_masterident_head_t) + + sizeof (iolink_port_types_t) * IOLINK_NUM_PORTS); + +COMPILETIME_ASSERT (sizeof (arg_block_pdin_head_t) == 4); +COMPILETIME_ASSERT ( + sizeof (arg_block_pdin_t) == + sizeof (arg_block_pdin_head_t) + IOLINK_PD_MAX_SIZE); + +COMPILETIME_ASSERT (sizeof (arg_block_pdout_head_t) == 4); +COMPILETIME_ASSERT ( + sizeof (arg_block_pdout_t) == + sizeof (arg_block_pdout_head_t) + IOLINK_PD_MAX_SIZE); + +COMPILETIME_ASSERT (sizeof (arg_block_pdinout_head_t) == 4); +COMPILETIME_ASSERT ( + sizeof (arg_block_pdinout_t) == + sizeof (arg_block_pdinout_head_t) + 2 + 2 * IOLINK_PD_MAX_SIZE); + +COMPILETIME_ASSERT (sizeof (arg_block_od_t) == 5); +COMPILETIME_ASSERT (sizeof (arg_block_ds_data_t) == 2 + 12); + +COMPILETIME_ASSERT (sizeof (portconfiglist_t) == 12); +COMPILETIME_ASSERT ( + sizeof (arg_block_portconfiglist_t) == 2 + sizeof (portconfiglist_t)); + +COMPILETIME_ASSERT ( + sizeof (arg_block_portstatuslist_t) == sizeof (diag_entry_t *) + 15); +COMPILETIME_ASSERT (sizeof (arg_block_devevent_t) == 3 + sizeof (diag_entry_t) * 6); +COMPILETIME_ASSERT (sizeof (arg_block_portevent_t) == 5); +COMPILETIME_ASSERT (sizeof (arg_block_void_t) == 2); +COMPILETIME_ASSERT (sizeof (arg_block_joberror_t) == 6); /* arg_block_pdinout_t is the largest ArgBlock we got */ -COMPILETIME_ASSERT (sizeof(arg_block_t) == sizeof(arg_block_pdinout_t)); +COMPILETIME_ASSERT (sizeof (arg_block_t) == sizeof (arg_block_pdinout_t)); typedef struct iolink_port_cfg { @@ -586,13 +601,19 @@ typedef struct iolink_m_cfg void * cb_arg; /* Callback opaque argument */ /* SMI cnf/ind callback */ - void (*cb_smi) (void * arg, uint8_t portnumber, - iolink_arg_block_id_t ref_arg_block_id, - uint16_t arg_block_len, arg_block_t * arg_block); + void (*cb_smi) ( + void * arg, + uint8_t portnumber, + iolink_arg_block_id_t ref_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block); /* Periodic data callback */ - void (*cb_pd) (uint8_t portnumber, void * arg, uint8_t data_len, - const uint8_t * data); + void (*cb_pd) ( + uint8_t portnumber, + void * arg, + uint8_t data_len, + const uint8_t * data); uint8_t port_cnt; const iolink_port_cfg_t * port_cfgs; @@ -616,83 +637,103 @@ iolink_m_t * iolink_m_init (const iolink_m_cfg_t * m_cfg); void iolink_m_deinit (iolink_m_t ** m); -uint8_t iolink_set_config (uint8_t portnumber, uint16_t vid, uint32_t did, - uint8_t cycle_time, iolink_portmode_t portmode, - iolink_validation_check_t validation, - char * serial_number); +uint8_t iolink_set_config ( + uint8_t portnumber, + uint16_t vid, + uint32_t did, + uint8_t cycle_time, + iolink_portmode_t portmode, + iolink_validation_check_t validation, + char * serial_number); uint8_t iolink_reset_events (uint8_t portnumber); -uint8_t iolink_get_events (uint8_t portnumber, uint8_t * diag_count, - diag_entry_t * diag_entry); - -iolink_error_t SMI_MasterIdentification_req (uint8_t portnumber, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, - arg_block_t * arg_block); - -iolink_error_t SMI_PortConfiguration_req (uint8_t portnumber, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, - arg_block_t * arg_block); - -iolink_error_t SMI_ReadbackPortConfiguration_req (uint8_t portnumber, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, - arg_block_t * arg_block); - -iolink_error_t SMI_PortStatus_req (uint8_t portnumber, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, - arg_block_t * arg_block); - -iolink_error_t SMI_DSToParServ_req (uint8_t portnumber, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, - arg_block_t * arg_block); - -iolink_error_t SMI_ParServToDS_req (uint8_t portnumber, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, - arg_block_t * arg_block); - -iolink_error_t SMI_DeviceRead_req (uint8_t portnumber, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, - arg_block_t * arg_block); - -iolink_error_t SMI_DeviceWrite_req (uint8_t portnumber, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, - arg_block_t * arg_block); - -iolink_error_t SMI_ParamReadBatch_req (uint8_t portnumber, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, - arg_block_t * arg_block); - -iolink_error_t SMI_ParamWriteBatch_req (uint8_t portnumber, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, - arg_block_t * arg_block); - -iolink_error_t SMI_PDIn_req (uint8_t portnumber, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, - arg_block_t * arg_block); - -iolink_error_t SMI_PDOut_req (uint8_t portnumber, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, - arg_block_t * arg_block); - -iolink_error_t SMI_PDInOut_req (uint8_t portnumber, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, - arg_block_t * arg_block); - -iolink_error_t SMI_ParServToDS_req (uint8_t portnumber, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, - arg_block_t * arg_block); +uint8_t iolink_get_events ( + uint8_t portnumber, + uint8_t * diag_count, + diag_entry_t * diag_entry); + +iolink_error_t SMI_MasterIdentification_req ( + uint8_t portnumber, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block); + +iolink_error_t SMI_PortConfiguration_req ( + uint8_t portnumber, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block); + +iolink_error_t SMI_ReadbackPortConfiguration_req ( + uint8_t portnumber, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block); + +iolink_error_t SMI_PortStatus_req ( + uint8_t portnumber, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block); + +iolink_error_t SMI_DSToParServ_req ( + uint8_t portnumber, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block); + +iolink_error_t SMI_ParServToDS_req ( + uint8_t portnumber, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block); + +iolink_error_t SMI_DeviceRead_req ( + uint8_t portnumber, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block); + +iolink_error_t SMI_DeviceWrite_req ( + uint8_t portnumber, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block); + +iolink_error_t SMI_ParamReadBatch_req ( + uint8_t portnumber, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block); + +iolink_error_t SMI_ParamWriteBatch_req ( + uint8_t portnumber, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block); + +iolink_error_t SMI_PDIn_req ( + uint8_t portnumber, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block); + +iolink_error_t SMI_PDOut_req ( + uint8_t portnumber, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block); + +iolink_error_t SMI_PDInOut_req ( + uint8_t portnumber, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block); + +iolink_error_t SMI_ParServToDS_req ( + uint8_t portnumber, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block); #ifdef __cplusplus } #endif diff --git a/include/iolink_max14819.h b/include/iolink_max14819.h index 76d0465..e0f4834 100644 --- a/include/iolink_max14819.h +++ b/include/iolink_max14819.h @@ -10,15 +10,13 @@ * See LICENSE file in the project root for full license information. ********************************************************************/ - #ifndef IOLINK_MAX14819_H #define IOLINK_MAX14819_H #include #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif /** @@ -45,7 +43,7 @@ typedef struct iolink_14819_cfg uint8_t DrvCurrLim; uint8_t Clock; unsigned int pin[2]; - void (*register_read_reg_fn)(void *read_reg_function); + void (*register_read_reg_fn) (void * read_reg_function); } iolink_14819_cfg_t; /** diff --git a/iol_osal/include/osal_drv.h b/iol_osal/include/osal_drv.h index 8eb9fb6..15df93f 100644 --- a/iol_osal/include/osal_drv.h +++ b/iol_osal/include/osal_drv.h @@ -17,8 +17,7 @@ #define OSAL_DRV_H #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif #include @@ -28,26 +27,24 @@ struct drv; typedef struct drv_ops { - int (*open) (struct drv * drv, const char * name, int flags, int mode); - int (*close) (struct drv * drv, void * arg); - ssize_t (*read) (struct drv * drv, void * arg, void * buf, - size_t nbytes); - ssize_t (*write) (struct drv * drv, void * arg, const void * buf, - size_t nbytes); - int (*ioctl) (struct drv * drv, void * arg, int req, void * req_arg); + int (*open) (struct drv * drv, const char * name, int flags, int mode); + int (*close) (struct drv * drv, void * arg); + ssize_t (*read) (struct drv * drv, void * arg, void * buf, size_t nbytes); + ssize_t (*write) (struct drv * drv, void * arg, const void * buf, size_t nbytes); + int (*ioctl) (struct drv * drv, void * arg, int req, void * req_arg); } drv_ops_t; typedef struct drv { char * name; - pthread_mutex_t *mtx; + pthread_mutex_t * mtx; const drv_ops_t * ops; } drv_t; -drv_t * fd_get_driver(int fd); -void * fd_get_arg(int fd); -int fd_set_driver(int fd, drv_t * drv, void * arg); -drv_t * find_driver_by_name(const char * name); +drv_t * fd_get_driver (int fd); +void * fd_get_arg (int fd); +int fd_set_driver (int fd, drv_t * drv, void * arg); +drv_t * find_driver_by_name (const char * name); #ifdef __cplusplus } diff --git a/iol_osal/include/osal_fileops.h b/iol_osal/include/osal_fileops.h index 2633506..9000108 100644 --- a/iol_osal/include/osal_fileops.h +++ b/iol_osal/include/osal_fileops.h @@ -17,11 +17,10 @@ #define OSAL_PL_HW_FILEOPS_H #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif -int _iolink_pl_hw_open ( const char * name); +int _iolink_pl_hw_open (const char * name); #ifdef __cplusplus } diff --git a/iol_osal/linux/osal_drv.c b/iol_osal/linux/osal_drv.c index db13005..201b16c 100644 --- a/iol_osal/linux/osal_drv.c +++ b/iol_osal/linux/osal_drv.c @@ -18,22 +18,23 @@ #include #define DRIVERS_SIZE 4 -typedef struct { - int fd; - drv_t *drv; - void * arg; +typedef struct +{ + int fd; + drv_t * drv; + void * arg; } drv_list_t; drv_list_t drivers[DRIVERS_SIZE] = {0}; -drv_t * fd_get_driver(int fd) +drv_t * fd_get_driver (int fd) { int i; for (i = 0; i < DRIVERS_SIZE; i++) { - if (drivers[i].fd == fd ) + if (drivers[i].fd == fd) { - return drivers[i].drv; + return drivers[i].drv; } else if (drivers[i].fd == 0) { @@ -43,14 +44,14 @@ drv_t * fd_get_driver(int fd) return NULL; } -void * fd_get_arg(int fd) +void * fd_get_arg (int fd) { int i; for (i = 0; i < DRIVERS_SIZE; i++) { - if (drivers[i].fd == fd ) + if (drivers[i].fd == fd) { - return drivers[i].arg; + return drivers[i].arg; } else if (drivers[i].fd == 0) { @@ -60,24 +61,24 @@ void * fd_get_arg(int fd) return NULL; } -int fd_set_driver(int fd, drv_t * drv, void * arg) +int fd_set_driver (int fd, drv_t * drv, void * arg) { int i; for (i = 0; i < DRIVERS_SIZE; i++) { - if ( drivers[i].fd == 0 ) + if (drivers[i].fd == 0) { - drivers[i].fd = fd; + drivers[i].fd = fd; drivers[i].drv = drv; drivers[i].arg = arg; - drv->mtx = os_mutex_create(); + drv->mtx = os_mutex_create(); return 0; } } return -1; } -drv_t * find_driver_by_name(const char * name) +drv_t * find_driver_by_name (const char * name) { int i; for (i = 0; i < DRIVERS_SIZE; i++) @@ -93,4 +94,3 @@ drv_t * find_driver_by_name(const char * name) } return NULL; } - diff --git a/iol_osal/linux/osal_fileops.c b/iol_osal/linux/osal_fileops.c index fb87d02..f6d0243 100644 --- a/iol_osal/linux/osal_fileops.c +++ b/iol_osal/linux/osal_fileops.c @@ -36,15 +36,15 @@ int _iolink_pl_hw_open (const char * name) strncpy (local_name, name, 100); - char *argp = strrchr(local_name, '/'); + char * argp = strrchr (local_name, '/'); if (argp == NULL) { - printf("%s: '/' not found in file name.\n", __func__); + printf ("%s: '/' not found in file name.\n", __func__); return 0; } - arg = atoi(argp + 1); - *argp = '\0'; + arg = atoi (argp + 1); + *argp = '\0'; int fd = open (local_name, O_RDWR, 0); if (fd < 1) @@ -52,17 +52,21 @@ int _iolink_pl_hw_open (const char * name) return -1; } - drv_t * drv = find_driver_by_name(local_name); + drv_t * drv = find_driver_by_name (local_name); - printf("%s: Driver %sfound for %lu: %s\n", __func__, - (drv == NULL) ? "NOT " : "", arg, local_name); + printf ( + "%s: Driver %sfound for %lu: %s\n", + __func__, + (drv == NULL) ? "NOT " : "", + arg, + local_name); if (drv == NULL) { return -1; } - fd_set_driver(fd, drv, (void *)arg); + fd_set_driver (fd, drv, (void *)arg); return fd; } diff --git a/sample_app/CMakeLists.txt b/sample_app/CMakeLists.txt index f969cb6..40a8d09 100644 --- a/sample_app/CMakeLists.txt +++ b/sample_app/CMakeLists.txt @@ -10,10 +10,6 @@ # See LICENSE file in the project root for full license information. #*******************************************************************/ -add_executable(spi_test - util/spidev_test.c - ) - add_executable(irq_test util/irq_test.c ) diff --git a/sample_app/iol_master_sample_app.c b/sample_app/iol_master_sample_app.c index c815d1c..1ae920b 100644 --- a/sample_app/iol_master_sample_app.c +++ b/sample_app/iol_master_sample_app.c @@ -26,14 +26,14 @@ #include "iolink_handler.h" #define SYSFS_GPIO_DIR "/sys/class/gpio" -#define MAX_BUF 64 +#define MAX_BUF 64 -#define IOLINK_MASTER_THREAD_STACK_SIZE (4 * 1024) -#define IOLINK_MASTER_THREAD_PRIO 6 -#define IOLINK_DL_THREAD_STACK_SIZE 1500 -#define IOLINK_DL_THREAD_PRIO (IOLINK_MASTER_THREAD_PRIO + 1) +#define IOLINK_MASTER_THREAD_STACK_SIZE (4 * 1024) +#define IOLINK_MASTER_THREAD_PRIO 6 +#define IOLINK_DL_THREAD_STACK_SIZE 1500 +#define IOLINK_DL_THREAD_PRIO (IOLINK_MASTER_THREAD_PRIO + 1) -typedef void(*isr_func_t)(void *); +typedef void (*isr_func_t) (void *); typedef struct { @@ -42,121 +42,121 @@ typedef struct isr_func_t isr_func; } irq_thread_t; -void *irq_thread(void *arg) +void * irq_thread (void * arg) { - irq_thread_t *irq = (irq_thread_t *)arg; + irq_thread_t * irq = (irq_thread_t *)arg; struct pollfd p_fd; char buf[MAX_BUF]; while (true) { - memset(&p_fd, 0, sizeof(p_fd)); + memset (&p_fd, 0, sizeof (p_fd)); - p_fd.fd = irq->irq_fd; + p_fd.fd = irq->irq_fd; p_fd.events = POLLPRI; - int rc = poll(&p_fd, 1, 5000); + int rc = poll (&p_fd, 1, 5000); if (rc < 0) - { - printf("\npoll() failed!\n"); + { + printf ("\npoll() failed!\n"); } else if (rc == 0) { - printf("."); + printf ("."); } else if (p_fd.revents & POLLPRI) { - lseek(p_fd.fd, 0, SEEK_SET); - if (read(p_fd.fd, buf, MAX_BUF) > 0) - { - irq->isr_func(&irq->spi_fd); - } + lseek (p_fd.fd, 0, SEEK_SET); + if (read (p_fd.fd, buf, MAX_BUF) > 0) + { + irq->isr_func (&irq->spi_fd); + } } - fflush(stdout); - } - close (irq->irq_fd); + fflush (stdout); + } + close (irq->irq_fd); } static pthread_t thread; -pthread_t *setup_int(unsigned int gpio_pin, isr_func_t isr_func, int spi_fd) +pthread_t * setup_int (unsigned int gpio_pin, isr_func_t isr_func, int spi_fd) { char buf[MAX_BUF]; pthread_attr_t attr; static irq_thread_t irqarg; // Add gpio_pin to exported pins - int fd = open(SYSFS_GPIO_DIR "/export", O_WRONLY); + int fd = open (SYSFS_GPIO_DIR "/export", O_WRONLY); if (fd < 0) { - perror("gpio/export"); + perror ("gpio/export"); return NULL; } - int n = write(fd, buf, snprintf(buf, sizeof(buf), "%d", gpio_pin)); - close(fd); + int n = write (fd, buf, snprintf (buf, sizeof (buf), "%d", gpio_pin)); + close (fd); if (n < 0) { - perror("setup_int(): Failed to write gpio_pin to gpio/export"); + perror ("setup_int(): Failed to write gpio_pin to gpio/export"); } // Set direction of pin to input - snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/direction", gpio_pin); - fd = open(buf, O_WRONLY); + snprintf (buf, sizeof (buf), SYSFS_GPIO_DIR "/gpio%d/direction", gpio_pin); + fd = open (buf, O_WRONLY); if (fd < 0) { - perror("gpio/direction"); + perror ("gpio/direction"); return NULL; } - n = write(fd, "in", sizeof("in") + 1); - close(fd); + n = write (fd, "in", sizeof ("in") + 1); + close (fd); if (n < 0) { - perror("write direction"); + perror ("write direction"); return NULL; } // Set edge detection to falling - snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/edge", gpio_pin); - fd = open(buf, O_WRONLY); + snprintf (buf, sizeof (buf), SYSFS_GPIO_DIR "/gpio%d/edge", gpio_pin); + fd = open (buf, O_WRONLY); if (fd < 0) { - perror("gpio/edge"); + perror ("gpio/edge"); return NULL; } - n = write(fd, "falling", sizeof("falling") + 1); - close(fd); + n = write (fd, "falling", sizeof ("falling") + 1); + close (fd); if (n < 0) { - perror("write edge"); + perror ("write edge"); return NULL; } // Open file and return file descriptor - snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/value", gpio_pin); - fd = open(buf, O_RDONLY | O_NONBLOCK); + snprintf (buf, sizeof (buf), SYSFS_GPIO_DIR "/gpio%d/value", gpio_pin); + fd = open (buf, O_RDONLY | O_NONBLOCK); if (fd < 0) { - perror("gpio/value"); + perror ("gpio/value"); } // Create isr service thread irqarg.isr_func = isr_func; - irqarg.spi_fd = spi_fd; - irqarg.irq_fd = fd; - pthread_attr_init(&attr); - pthread_create(&thread, &attr, irq_thread, &irqarg); + irqarg.spi_fd = spi_fd; + irqarg.irq_fd = fd; + pthread_attr_init (&attr); + pthread_create (&thread, &attr, irq_thread, &irqarg); return &thread; } @@ -164,22 +164,20 @@ pthread_t *setup_int(unsigned int gpio_pin, isr_func_t isr_func, int spi_fd) static iolink_pl_mode_t mode_ch_0 = iolink_mode_SDCI; static iolink_pl_mode_t mode_ch_1 = iolink_mode_INACTIVE; -int main (int argc, char **argv) +int main (int argc, char ** argv) { - iolink_14819_cfg_t iol_14819_cfg = - { - .chip_address = 0x00, - .spi_slave_name = "/dev/spidev0.0", - .CQCfgA = 0x22, - .LPCnfgA = 0x01, - .IOStCfgA = 0x05, - .DrvCurrLim = 0x00, - .Clock = 0x01, - .pin = {0, 0}, + iolink_14819_cfg_t iol_14819_cfg = { + .chip_address = 0x00, + .spi_slave_name = "/dev/spidev0.0", + .CQCfgA = 0x22, + .LPCnfgA = 0x01, + .IOStCfgA = 0x05, + .DrvCurrLim = 0x00, + .Clock = 0x01, + .pin = {0, 0}, }; - iolink_port_cfg_t port_cfgs [] = - { + iolink_port_cfg_t port_cfgs[] = { { .name = "/dev/spidev0.0/0", .mode = &mode_ch_0, @@ -190,33 +188,32 @@ int main (int argc, char **argv) }, }; - iolink_m_cfg_t iolink_cfg = - { - .cb_arg = NULL, - .cb_smi = NULL, - .cb_pd = NULL, - .port_cnt = NELEMENTS (port_cfgs), - .port_cfgs = port_cfgs, - .master_thread_prio = IOLINK_MASTER_THREAD_PRIO, + iolink_m_cfg_t iolink_cfg = { + .cb_arg = NULL, + .cb_smi = NULL, + .cb_pd = NULL, + .port_cnt = NELEMENTS (port_cfgs), + .port_cfgs = port_cfgs, + .master_thread_prio = IOLINK_MASTER_THREAD_PRIO, .master_thread_stack_size = IOLINK_MASTER_THREAD_STACK_SIZE, - .dl_thread_prio = IOLINK_DL_THREAD_PRIO, - .dl_thread_stack_size = IOLINK_DL_THREAD_STACK_SIZE, + .dl_thread_prio = IOLINK_DL_THREAD_PRIO, + .dl_thread_stack_size = IOLINK_DL_THREAD_STACK_SIZE, }; int fd = iolink_14819_init ("iolink", &iol_14819_cfg); if (fd < 0) { - printf("Failed to open SPI\n"); + printf ("Failed to open SPI\n"); return -1; } - if (setup_int(25, iolink_14819_isr, fd) == NULL) + if (setup_int (25, iolink_14819_isr, fd) == NULL) { - printf("Failed to setup interrupt\n"); + printf ("Failed to setup interrupt\n"); return -1; } - usleep(200 * 1000); + usleep (200 * 1000); iolink_handler (iolink_cfg); diff --git a/sample_app/iolink_handler.c b/sample_app/iolink_handler.c index d58c3fa..62c8a98 100644 --- a/sample_app/iolink_handler.c +++ b/sample_app/iolink_handler.c @@ -20,97 +20,130 @@ #include "iolink_handler.h" #include "iolink_ifm.h" -#define EVENT_PD_0 BIT(0) -#define EVENT_COMLOST_0 BIT(4) -#define EVENT_PORTE_0 BIT(8) -#define EVENT_RETRY_ESTCOM_0 BIT(12) - -#define VERIFY_ITEM(structure, item, portnumber, text) \ - if (structure->item != item) \ - { \ - LOG_WARNING(LOG_STATE_ON, \ - "%s: Port %u: Expected %s 0x%x, got 0x%x\n", \ - __func__, portnumber, text, (unsigned int)item, \ - (unsigned int)structure->item); \ - return 1; \ +#define EVENT_PD_0 BIT (0) +#define EVENT_COMLOST_0 BIT (4) +#define EVENT_PORTE_0 BIT (8) +#define EVENT_RETRY_ESTCOM_0 BIT (12) + +#define VERIFY_ITEM(structure, item, portnumber, text) \ + if (structure->item != item) \ + { \ + LOG_WARNING ( \ + LOG_STATE_ON, \ + "%s: Port %u: Expected %s 0x%x, got 0x%x\n", \ + __func__, \ + portnumber, \ + text, \ + (unsigned int)item, \ + (unsigned int)structure->item); \ + return 1; \ } -static void SMI_cnf_cb (void * arg, uint8_t portnumber, - iolink_arg_block_id_t ref_arg_block_id, - uint16_t arg_block_len, arg_block_t * arg_block); - -static uint8_t verify_smi_masterident (iolink_app_port_ctx_t * app_port, - uint16_t vendorid, uint32_t masterid) +static void SMI_cnf_cb ( + void * arg, + uint8_t portnumber, + iolink_arg_block_id_t ref_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block); + +static uint8_t verify_smi_masterident ( + iolink_app_port_ctx_t * app_port, + uint16_t vendorid, + uint32_t masterid) { arg_block_void_t arg_block_void; - bzero (&arg_block_void, sizeof(arg_block_void_t)); + bzero (&arg_block_void, sizeof (arg_block_void_t)); arg_block_void.arg_block_id = IOLINK_ARG_BLOCK_ID_VOID_BLOCK; - iolink_error_t err = SMI_MasterIdentification_req (app_port->portnumber, - IOLINK_ARG_BLOCK_ID_MASTERIDENT, - sizeof(arg_block_void_t), - (arg_block_t *)&arg_block_void); - if ((err != IOLINK_ERROR_NONE) || - (wait_for_cnf(app_port, SMI_MASTERIDENT_CNF, 1000) != IOLINK_SMI_ERRORTYPE_NONE)) + iolink_error_t err = SMI_MasterIdentification_req ( + app_port->portnumber, + IOLINK_ARG_BLOCK_ID_MASTERIDENT, + sizeof (arg_block_void_t), + (arg_block_t *)&arg_block_void); + if ( + (err != IOLINK_ERROR_NONE) || + (wait_for_cnf (app_port, SMI_MASTERIDENT_CNF, 1000) != + IOLINK_SMI_ERRORTYPE_NONE)) { return 1; } - VERIFY_ITEM(app_port->app_master, vendorid, app_port->portnumber, "vendorid"); - VERIFY_ITEM(app_port->app_master, masterid, app_port->portnumber, "masterid"); + VERIFY_ITEM (app_port->app_master, vendorid, app_port->portnumber, "vendorid"); + VERIFY_ITEM (app_port->app_master, masterid, app_port->portnumber, "masterid"); return 0; } -static void iolink_app_init_port (iolink_app_port_ctx_t * app_port, iolink_m_cfg_t * m_cfg, - const iolink_port_cfg_t * port_cfg) +static void iolink_app_init_port ( + iolink_app_port_ctx_t * app_port, + iolink_m_cfg_t * m_cfg, + const iolink_port_cfg_t * port_cfg) { - iolink_port_t * port = iolink_get_port (iolink_app_master.master, - app_port->portnumber); + iolink_port_t * port = + iolink_get_port (iolink_app_master.master, app_port->portnumber); - app_port->event_mtx = os_mutex_create(); + app_port->event_mtx = os_mutex_create(); app_port->status_mtx = os_mutex_create(); - app_port->pdout_mtx = os_mutex_create(); - iolink_dl_instantiate (port, port_cfg, m_cfg->dl_thread_prio, m_cfg->dl_thread_stack_size); + app_port->pdout_mtx = os_mutex_create(); + iolink_dl_instantiate ( + port, + port_cfg, + m_cfg->dl_thread_prio, + m_cfg->dl_thread_stack_size); app_port->allocated = 1; - app_port->event = os_event_create(); + app_port->event = os_event_create(); if (verify_smi_masterident (app_port, MASTER_VENDOR_ID, MASTER_ID) != 0) { - LOG_WARNING(LOG_STATE_ON, "%s: Verify MasterIdentification failed\n", __func__); + LOG_WARNING ( + LOG_STATE_ON, + "%s: Verify MasterIdentification failed\n", + __func__); } } -void iolink_common_config (arg_block_portconfiglist_t * port_cfg, uint16_t vid, - uint32_t did, uint8_t cycle_time, iolink_portmode_t portmode, - iolink_validation_check_t validation) +void iolink_common_config ( + arg_block_portconfiglist_t * port_cfg, + uint16_t vid, + uint32_t did, + uint8_t cycle_time, + iolink_portmode_t portmode, + iolink_validation_check_t validation) { - port_cfg->arg_block_id = IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST; - port_cfg->configlist.port_cycle_time = cycle_time; - port_cfg->configlist.vendorid = vid; - port_cfg->configlist.deviceid = did; - port_cfg->configlist.portmode = portmode; + port_cfg->arg_block_id = IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST; + port_cfg->configlist.port_cycle_time = cycle_time; + port_cfg->configlist.vendorid = vid; + port_cfg->configlist.deviceid = did; + port_cfg->configlist.portmode = portmode; port_cfg->configlist.validation_backup = validation; - port_cfg->configlist.iq_behavior = IOLINK_IQ_BEHAVIOR_NO_SUPPORT; + port_cfg->configlist.iq_behavior = IOLINK_IQ_BEHAVIOR_NO_SUPPORT; } static uint8_t iolink_config_port_sdci_auto (iolink_app_port_ctx_t * app_port) { arg_block_portconfiglist_t port_cfg; - iolink_common_config(&port_cfg, 0, 0, 0 /* AFAP (As fast as possible) */, - IOLINK_PORTMODE_IOL_AUTO, IOLINK_VALIDATION_CHECK_NO); + iolink_common_config ( + &port_cfg, + 0, + 0, + 0 /* AFAP (As fast as possible) */, + IOLINK_PORTMODE_IOL_AUTO, + IOLINK_VALIDATION_CHECK_NO); app_port->app_port_state = IOL_STATE_STARTING; - iolink_error_t err = SMI_PortConfiguration_req (app_port->portnumber, - IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - sizeof(arg_block_portconfiglist_t), - (arg_block_t *)&port_cfg); - if ((err != IOLINK_ERROR_NONE) || - (wait_for_cnf(app_port, SMI_PORTCFG_CNF, 1000) != IOLINK_SMI_ERRORTYPE_NONE)) + iolink_error_t err = SMI_PortConfiguration_req ( + app_port->portnumber, + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + sizeof (arg_block_portconfiglist_t), + (arg_block_t *)&port_cfg); + if ( + (err != IOLINK_ERROR_NONE) || + (wait_for_cnf (app_port, SMI_PORTCFG_CNF, 1000) != + IOLINK_SMI_ERRORTYPE_NONE)) { return 1; } @@ -122,18 +155,25 @@ static uint8_t iolink_config_port_dido (iolink_app_port_ctx_t * app_port, bool d { arg_block_portconfiglist_t port_cfg; - bzero (&port_cfg, sizeof(arg_block_portconfiglist_t)); - - iolink_common_config(&port_cfg, 0, 0, 0 /* AFAP (As fast as possible) */, - (di) ? IOLINK_PORTMODE_DI_CQ : IOLINK_PORTMODE_DO_CQ, - (di) ? IOLINK_IQ_BEHAVIOR_DI : IOLINK_IQ_BEHAVIOR_DO); - - iolink_error_t err = SMI_PortConfiguration_req (app_port->portnumber, - IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - sizeof(arg_block_portconfiglist_t), - (arg_block_t *)&port_cfg); - if ((err != IOLINK_ERROR_NONE) || - (wait_for_cnf(app_port, SMI_PORTCFG_CNF, 1000) != IOLINK_SMI_ERRORTYPE_NONE)) + bzero (&port_cfg, sizeof (arg_block_portconfiglist_t)); + + iolink_common_config ( + &port_cfg, + 0, + 0, + 0 /* AFAP (As fast as possible) */, + (di) ? IOLINK_PORTMODE_DI_CQ : IOLINK_PORTMODE_DO_CQ, + (di) ? IOLINK_IQ_BEHAVIOR_DI : IOLINK_IQ_BEHAVIOR_DO); + + iolink_error_t err = SMI_PortConfiguration_req ( + app_port->portnumber, + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + sizeof (arg_block_portconfiglist_t), + (arg_block_t *)&port_cfg); + if ( + (err != IOLINK_ERROR_NONE) || + (wait_for_cnf (app_port, SMI_PORTCFG_CNF, 1000) != + IOLINK_SMI_ERRORTYPE_NONE)) { return 1; } @@ -141,24 +181,25 @@ static uint8_t iolink_config_port_dido (iolink_app_port_ctx_t * app_port, bool d return 0; } -static uint8_t iolink_config_port (iolink_app_port_ctx_t * app_port, - iolink_pl_mode_t port_mode) +static uint8_t iolink_config_port ( + iolink_app_port_ctx_t * app_port, + iolink_pl_mode_t port_mode) { uint8_t res = 0; switch (port_mode) { - case iolink_mode_SDCI: - res = iolink_config_port_sdci_auto (app_port); - break; - case iolink_mode_DO: - res = iolink_config_port_dido (app_port, false); - break; - case iolink_mode_DI: - res = iolink_config_port_dido (app_port, true); - break; - case iolink_mode_INACTIVE: - break; + case iolink_mode_SDCI: + res = iolink_config_port_sdci_auto (app_port); + break; + case iolink_mode_DO: + res = iolink_config_port_dido (app_port, false); + break; + case iolink_mode_DI: + res = iolink_config_port_dido (app_port, true); + break; + case iolink_mode_INACTIVE: + break; } return res; @@ -168,15 +209,18 @@ uint8_t get_port_status (iolink_app_port_ctx_t * app_port) { arg_block_void_t arg_block_void; - bzero (&arg_block_void, sizeof(arg_block_void_t)); + bzero (&arg_block_void, sizeof (arg_block_void_t)); arg_block_void.arg_block_id = IOLINK_ARG_BLOCK_ID_VOID_BLOCK; - iolink_error_t err = SMI_PortStatus_req (app_port->portnumber, - IOLINK_ARG_BLOCK_ID_PORT_STATUS_LIST, - sizeof(arg_block_void_t), - (arg_block_t *)&arg_block_void); - if ((err != IOLINK_ERROR_NONE) || - (wait_for_cnf(app_port, SMI_PORTSTATUS_CNF, 1000) != IOLINK_SMI_ERRORTYPE_NONE)) + iolink_error_t err = SMI_PortStatus_req ( + app_port->portnumber, + IOLINK_ARG_BLOCK_ID_PORT_STATUS_LIST, + sizeof (arg_block_void_t), + (arg_block_t *)&arg_block_void); + if ( + (err != IOLINK_ERROR_NONE) || + (wait_for_cnf (app_port, SMI_PORTSTATUS_CNF, 1000) != + IOLINK_SMI_ERRORTYPE_NONE)) { return 1; } @@ -187,7 +231,7 @@ uint8_t get_port_status (iolink_app_port_ctx_t * app_port) static uint8_t iolink_start_port (iolink_app_port_ctx_t * app_port) { iolink_app_port_status_t * port_status = &app_port->status; - uint8_t portnumber = app_port->portnumber; + uint8_t portnumber = app_port->portnumber; if (get_port_status (app_port) != 0) { @@ -198,8 +242,12 @@ static uint8_t iolink_start_port (iolink_app_port_ctx_t * app_port) /* Verify port status data */ if (port_status->port_status_info != IOLINK_PORT_STATUS_INFO_OP) { - LOG_WARNING(LOG_STATE_ON, "%s: Port %u is not in state operational, port_status_info = %u\n", - __func__, portnumber, port_status->port_status_info); + LOG_WARNING ( + LOG_STATE_ON, + "%s: Port %u is not in state operational, port_status_info = %u\n", + __func__, + portnumber, + port_status->port_status_info); os_mutex_unlock (app_port->status_mtx); return 1; @@ -209,54 +257,70 @@ static uint8_t iolink_start_port (iolink_app_port_ctx_t * app_port) { switch (port_status->deviceid) { - case IFM_RFID_DEVICE_ID: - ifmrfid_setup (app_port); - break; - case IFM_HMI_DEVICE_ID: - ifmHMI_setup (app_port); - break; - default: - app_port->type = UNKNOWN; - app_port->app_port_state = IOL_STATE_RUNNING; - LOG_WARNING(LOG_STATE_ON, "%s: Port %u: Unknown iolink device 0x%06x for VID 0x%04x\n", - __func__, portnumber, (int)port_status->deviceid, port_status->vendorid); - break; + case IFM_RFID_DEVICE_ID: + ifmrfid_setup (app_port); + break; + case IFM_HMI_DEVICE_ID: + ifmHMI_setup (app_port); + break; + default: + app_port->type = UNKNOWN; + app_port->app_port_state = IOL_STATE_RUNNING; + LOG_WARNING ( + LOG_STATE_ON, + "%s: Port %u: Unknown iolink device 0x%06x for VID 0x%04x\n", + __func__, + portnumber, + (int)port_status->deviceid, + port_status->vendorid); + break; } } else { app_port->type = UNKNOWN; - LOG_WARNING(LOG_STATE_ON, "%s: Port %u: Unknown device: Vendor ID = 0x%04X, Device ID = 0x%06X\n", - __func__, portnumber, port_status->vendorid, (int)port_status->deviceid); + LOG_WARNING ( + LOG_STATE_ON, + "%s: Port %u: Unknown device: Vendor ID = 0x%04X, Device ID = " + "0x%06X\n", + __func__, + portnumber, + port_status->vendorid, + (int)port_status->deviceid); } - LOG_INFO(LOG_STATE_ON, "%s: Port %u: Start done!\n", __func__, portnumber); + LOG_INFO (LOG_STATE_ON, "%s: Port %u: Start done!\n", __func__, portnumber); os_mutex_unlock (app_port->status_mtx); return 0; } -static void PD_cb (uint8_t portnumber, void * arg, uint8_t data_len, const uint8_t * inputdata) +static void PD_cb ( + uint8_t portnumber, + void * arg, + uint8_t data_len, + const uint8_t * inputdata) { - uint8_t port_index = portnumber - 1; + uint8_t port_index = portnumber - 1; iolink_app_master_ctx_t * app_master = (iolink_app_master_ctx_t *)arg; iolink_app_port_ctx_t * app_port = &iolink_app_master.app_port[port_index]; os_event_set (app_master->app_event, EVENT_PD_0 << port_index); - memcpy(app_port->pdin.data, inputdata, data_len); + memcpy (app_port->pdin.data, inputdata, data_len); app_port->pdin.data_len = data_len; } -static void iolink_retry_estcom(os_timer_t *tmr, void * arg) +static void iolink_retry_estcom (os_timer_t * tmr, void * arg) { -#if (__SIZEOF_POINTER__ == 4) +#if (__SIZEOF_POINTER__ == 4) uint8_t port_idx = ((uint32_t)arg) & 0xFF; -#elif (__SIZEOF_POINTER__ == 8) +#elif (__SIZEOF_POINTER__ == 8) uint8_t port_idx = ((uint64_t)arg) & 0xFF; #endif - iolink_app_master.app_port[port_idx].app_port_state = IOL_STATE_WU_RETRY_WAIT_TSD; - os_event_set(iolink_app_master.app_event, EVENT_RETRY_ESTCOM_0 << port_idx); + iolink_app_master.app_port[port_idx].app_port_state = + IOL_STATE_WU_RETRY_WAIT_TSD; + os_event_set (iolink_app_master.app_event, EVENT_RETRY_ESTCOM_0 << port_idx); } void iolink_handler (iolink_m_cfg_t m_cfg) @@ -264,29 +328,30 @@ void iolink_handler (iolink_m_cfg_t m_cfg) long unsigned int i; os_event_t * app_event = os_event_create(); iolink_pl_mode_t port_mode[IOLINK_NUM_PORTS]; - os_timer_t *iolink_tsd_tmr[IOLINK_NUM_PORTS] = { NULL }; + os_timer_t * iolink_tsd_tmr[IOLINK_NUM_PORTS] = {NULL}; for (i = 0; i < IOLINK_NUM_PORTS; i++) { if (*m_cfg.port_cfgs[i].mode == iolink_mode_SDCI) { - iolink_tsd_tmr[i] = os_timer_create(1000 * 1000, iolink_retry_estcom, (void *)i, true); + iolink_tsd_tmr[i] = + os_timer_create (1000 * 1000, iolink_retry_estcom, (void *)i, true); } } - bzero (port_mode, sizeof(port_mode)); - bzero (&iolink_app_master, sizeof(iolink_app_master)); + bzero (port_mode, sizeof (port_mode)); + bzero (&iolink_app_master, sizeof (iolink_app_master)); iolink_app_master.app_event = app_event; m_cfg.cb_arg = &iolink_app_master; m_cfg.cb_smi = SMI_cnf_cb; - m_cfg.cb_pd = PD_cb; + m_cfg.cb_pd = PD_cb; iolink_m_t * master = iolink_m_init (&m_cfg); if (master == NULL) { - LOG_ERROR(LOG_STATE_ON, "%s: iolink_m_init() failed!\n", __func__); + LOG_ERROR (LOG_STATE_ON, "%s: iolink_m_init() failed!\n", __func__); CC_ASSERT (0); } @@ -296,11 +361,13 @@ void iolink_handler (iolink_m_cfg_t m_cfg) { if (*m_cfg.port_cfgs[i].mode != iolink_mode_INACTIVE) { - port_mode[i] = *m_cfg.port_cfgs[i].mode; + port_mode[i] = *m_cfg.port_cfgs[i].mode; iolink_app_master.app_port[i].portnumber = i + 1; iolink_app_master.app_port[i].app_master = &iolink_app_master; - iolink_app_init_port (&iolink_app_master.app_port[i], - &m_cfg, &m_cfg.port_cfgs[i]); + iolink_app_init_port ( + &iolink_app_master.app_port[i], + &m_cfg, + &m_cfg.port_cfgs[i]); } /* Config allocated port */ @@ -312,7 +379,11 @@ void iolink_handler (iolink_m_cfg_t m_cfg) if (iolink_config_port (app_port, port_mode[i]) != 0) { - LOG_WARNING(LOG_STATE_ON, "%s: Failed to config port %lu\n", __func__, i + 1); + LOG_WARNING ( + LOG_STATE_ON, + "%s: Failed to config port %lu\n", + __func__, + i + 1); } } } @@ -335,7 +406,7 @@ void iolink_handler (iolink_m_cfg_t m_cfg) { if (app_port->run_function != NULL) { - app_port->run_function(app_port); + app_port->run_function (app_port); } } } @@ -346,13 +417,21 @@ void iolink_handler (iolink_m_cfg_t m_cfg) { if (iolink_start_port (app_port) != 0) { - LOG_WARNING(LOG_STATE_ON, "%s: Failed to start port %lu\n", __func__, i + 1); + LOG_WARNING ( + LOG_STATE_ON, + "%s: Failed to start port %lu\n", + __func__, + i + 1); } } else if (app_port->app_port_state != IOL_STATE_STOPPING) { - LOG_WARNING(LOG_STATE_ON, "%s: EVENT_PORT for port %lu, when in port_state %u\n", - __func__, i + 1, app_port->app_port_state); + LOG_WARNING ( + LOG_STATE_ON, + "%s: EVENT_PORT for port %lu, when in port_state %u\n", + __func__, + i + 1, + app_port->app_port_state); } } @@ -360,28 +439,33 @@ void iolink_handler (iolink_m_cfg_t m_cfg) { if (app_port->app_port_state == IOL_STATE_WU_RETRY_WAIT_TSD) { - iolink_dl_reset (iolink_get_port (iolink_app_master.master, - app_port->portnumber)); + iolink_dl_reset (iolink_get_port ( + iolink_app_master.master, + app_port->portnumber)); if (iolink_config_port (app_port, port_mode[i]) != 0) { - LOG_WARNING(LOG_STATE_ON, "%s: Failed to config port %lu\n", __func__, i + 1); + LOG_WARNING ( + LOG_STATE_ON, + "%s: Failed to config port %lu\n", + __func__, + i + 1); } } } if (((EVENT_COMLOST_0 << i) & event_value) != 0) { - os_timer_stop(iolink_tsd_tmr[i]); + os_timer_stop (iolink_tsd_tmr[i]); if (app_port->app_port_state == IOL_STATE_STARTING) { /* Wait 500ms before sending new WURQ */ - os_timer_set(iolink_tsd_tmr[i], 500 * 1000); - os_timer_start(iolink_tsd_tmr[i]); + os_timer_set (iolink_tsd_tmr[i], 500 * 1000); + os_timer_start (iolink_tsd_tmr[i]); } else if (app_port->app_port_state != IOL_STATE_STOPPING) { /* Send WURQ immediately */ - iolink_retry_estcom(NULL, (void *)i); + iolink_retry_estcom (NULL, (void *)i); } else // (app_port->app_port_state == IOL_STATE_STOPPING) { @@ -393,8 +477,9 @@ void iolink_handler (iolink_m_cfg_t m_cfg) } } -static inline void handle_smi_deviceevent (iolink_app_port_ctx_t * app_port, - arg_block_devevent_t * arg_block_devevent) +static inline void handle_smi_deviceevent ( + iolink_app_port_ctx_t * app_port, + arg_block_devevent_t * arg_block_devevent) { if (app_port->type == GOLDEN) { @@ -403,41 +488,51 @@ static inline void handle_smi_deviceevent (iolink_app_port_ctx_t * app_port, os_mutex_lock (app_port->event_mtx); for (i = 0; i < arg_block_devevent->event_count; i++) { - uint8_t event_index = app_port->events.count++; + uint8_t event_index = app_port->events.count++; diag_entry_t * entry = &arg_block_devevent->diag_entry[i]; CC_ASSERT (event_index < PORT_EVENT_COUNT); - app_port->events.diag_entry[event_index].event_qualifier = entry->event_qualifier; + app_port->events.diag_entry[event_index].event_qualifier = + entry->event_qualifier; app_port->events.diag_entry[event_index].event_code = entry->event_code; } os_mutex_unlock (app_port->event_mtx); } } -static inline void handle_smi_portevent (iolink_app_port_ctx_t * app_port, - diag_entry_t * event) +static inline void handle_smi_portevent ( + iolink_app_port_ctx_t * app_port, + diag_entry_t * event) { - uint8_t portnumber = app_port->portnumber; + uint8_t portnumber = app_port->portnumber; iolink_app_master_ctx_t * app_master = app_port->app_master; - uint8_t port_index = portnumber - 1; + uint8_t port_index = portnumber - 1; - if (((app_port->type == GOLDEN) || (app_port->type == UNKNOWN)) && - event->event_code != IOLINK_EVENTCODE_NO_DEV) + if ( + ((app_port->type == GOLDEN) || (app_port->type == UNKNOWN)) && + event->event_code != IOLINK_EVENTCODE_NO_DEV) { uint8_t event_index; os_mutex_lock (app_port->event_mtx); event_index = app_port->events.count++; CC_ASSERT (event_index < PORT_EVENT_COUNT); - app_port->events.diag_entry[event_index].event_qualifier = event->event_qualifier; + app_port->events.diag_entry[event_index].event_qualifier = + event->event_qualifier; app_port->events.diag_entry[event_index].event_code = event->event_code; os_mutex_unlock (app_port->event_mtx); } if (event->event_code != IOLINK_EVENTCODE_NO_DEV) { - LOG_DEBUG(LOG_STATE_ON, "%s (%d): type = %d, event_code = 0x%04X, count = %d\n", - __func__, portnumber, app_port->type, event->event_code, app_port->events.count); + LOG_DEBUG ( + LOG_STATE_ON, + "%s (%d): type = %d, event_code = 0x%04X, count = %d\n", + __func__, + portnumber, + app_port->type, + event->event_code, + app_port->events.count); } switch (event->event_code) @@ -448,14 +543,22 @@ static inline void handle_smi_portevent (iolink_app_port_ctx_t * app_port, break; case IOLINK_EVENTCODE_BAD_DID: case IOLINK_EVENTCODE_BAD_VID: - LOG_WARNING(LOG_STATE_ON, "%s: Port %u: portevent bad vid/did.\n", __func__, portnumber); + LOG_WARNING ( + LOG_STATE_ON, + "%s: Port %u: portevent bad vid/did.\n", + __func__, + portnumber); /* Port status changed - Use SMI_PortStatus() for details */ os_event_set (app_master->app_event, (EVENT_PORTE_0 << port_index)); break; case IOLINK_EVENTCODE_NO_DEV: /* COMLOST */ if (app_port->app_port_state != IOL_STATE_STARTING) { - LOG_WARNING(LOG_STATE_ON, "%s: Port %u: portevent COMLOST\n", __func__, portnumber); + LOG_WARNING ( + LOG_STATE_ON, + "%s: Port %u: portevent COMLOST\n", + __func__, + portnumber); } os_event_set (app_master->app_event, (EVENT_COMLOST_0 << port_index)); @@ -467,22 +570,30 @@ static inline void handle_smi_portevent (iolink_app_port_ctx_t * app_port, case IOLINK_EVENTCODE_BACKUP_INCON_DL: break; default: - LOG_WARNING(LOG_STATE_ON, "%s: Port %u: Unknown SMI_PortEvent code 0x%04x\n", - __func__, portnumber, event->event_code); + LOG_WARNING ( + LOG_STATE_ON, + "%s: Port %u: Unknown SMI_PortEvent code 0x%04x\n", + __func__, + portnumber, + event->event_code); break; } } -static inline void handle_smi_joberror (iolink_app_port_ctx_t * app_port, - iolink_arg_block_id_t ref_arg_block_id, - arg_block_joberror_t * arg_block_err) +static inline void handle_smi_joberror ( + iolink_app_port_ctx_t * app_port, + iolink_arg_block_id_t ref_arg_block_id, + arg_block_joberror_t * arg_block_err) { app_port->errortype = arg_block_err->error; if (app_port->errortype == IOLINK_SMI_ERRORTYPE_ARGBLOCK_LENGTH_INVALID) { - LOG_WARNING(LOG_STATE_ON, "%s: Port %u: Read failed, buffer too small.\n", - __func__, app_port->portnumber); + LOG_WARNING ( + LOG_STATE_ON, + "%s: Port %u: Read failed, buffer too small.\n", + __func__, + app_port->portnumber); } switch (ref_arg_block_id) @@ -497,17 +608,25 @@ static inline void handle_smi_joberror (iolink_app_port_ctx_t * app_port, os_event_set (app_port->event, SMI_PARSERV_TO_DS_CNF); break; default: - LOG_WARNING(LOG_STATE_ON, "%s: Port %u: SMI failed! errortype = 0x%04x, ref = 0x%04x\n", - __func__, app_port->portnumber, app_port->errortype, ref_arg_block_id); + LOG_WARNING ( + LOG_STATE_ON, + "%s: Port %u: SMI failed! errortype = 0x%04x, ref = 0x%04x\n", + __func__, + app_port->portnumber, + app_port->errortype, + ref_arg_block_id); break; } } -static void SMI_cnf_cb (void * arg, uint8_t portnumber, - iolink_arg_block_id_t ref_arg_block_id, - uint16_t arg_block_len, arg_block_t * arg_block) +static void SMI_cnf_cb ( + void * arg, + uint8_t portnumber, + iolink_arg_block_id_t ref_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block) { - iolink_app_master_ctx_t * app_m = arg; + iolink_app_master_ctx_t * app_m = arg; iolink_app_port_ctx_t * app_port = &app_m->app_port[portnumber - 1]; bool match_found = true; @@ -517,57 +636,59 @@ static void SMI_cnf_cb (void * arg, uint8_t portnumber, switch (arg_block->void_block.arg_block_id) { case IOLINK_ARG_BLOCK_ID_JOB_ERROR: - handle_smi_joberror (app_port, ref_arg_block_id, - (arg_block_joberror_t *) arg_block); - LOG_DEBUG(LOG_STATE_ON, "%s: IOLINK_ARG_BLOCK_ID_JOB_ERROR\n", __func__); + handle_smi_joberror ( + app_port, + ref_arg_block_id, + (arg_block_joberror_t *)arg_block); + LOG_DEBUG (LOG_STATE_ON, "%s: IOLINK_ARG_BLOCK_ID_JOB_ERROR\n", __func__); break; case IOLINK_ARG_BLOCK_ID_PORT_STATUS_LIST: - { - iolink_app_port_status_t * port_status = &app_port->status; - arg_block_portstatuslist_t * port_status_list = - (arg_block_portstatuslist_t *)arg_block; - - port_status->port_status_info = port_status_list->port_status_info; - port_status->port_quality_info = port_status_list->port_quality_info; - port_status->revision_id = port_status_list->revision_id; - port_status->transmission_rate = port_status_list->transmission_rate; - port_status->master_cycle_time = port_status_list->master_cycle_time; - port_status->vendorid = port_status_list->vendorid; - port_status->deviceid = port_status_list->deviceid; - - /* SMI_PortStatus_cnf */ - os_event_set (app_port->event, SMI_PORTSTATUS_CNF); - break; - } + { + iolink_app_port_status_t * port_status = &app_port->status; + arg_block_portstatuslist_t * port_status_list = + (arg_block_portstatuslist_t *)arg_block; + + port_status->port_status_info = port_status_list->port_status_info; + port_status->port_quality_info = port_status_list->port_quality_info; + port_status->revision_id = port_status_list->revision_id; + port_status->transmission_rate = port_status_list->transmission_rate; + port_status->master_cycle_time = port_status_list->master_cycle_time; + port_status->vendorid = port_status_list->vendorid; + port_status->deviceid = port_status_list->deviceid; + + /* SMI_PortStatus_cnf */ + os_event_set (app_port->event, SMI_PORTSTATUS_CNF); + break; + } case IOLINK_ARG_BLOCK_ID_PORT_EVENT: /* SMI_PortEvent_ind */ - LOG_DEBUG(LOG_STATE_ON, "%s: IOLINK_ARG_BLOCK_ID_PORT_EVENT\n", __func__); + LOG_DEBUG (LOG_STATE_ON, "%s: IOLINK_ARG_BLOCK_ID_PORT_EVENT\n", __func__); handle_smi_portevent (app_port, &arg_block->port_event.event); break; case IOLINK_ARG_BLOCK_ID_DEV_EVENT: /* SMI_DeviceEvent_ind */ - LOG_DEBUG(LOG_STATE_ON, "%s: IOLINK_ARG_BLOCK_ID_DEV_EVENT\n", __func__); + LOG_DEBUG (LOG_STATE_ON, "%s: IOLINK_ARG_BLOCK_ID_DEV_EVENT\n", __func__); handle_smi_deviceevent (app_port, (arg_block_devevent_t *)arg_block); break; case IOLINK_ARG_BLOCK_ID_OD_RD: /* SMI_DeviceRead_cnf */ - LOG_DEBUG(LOG_STATE_ON, "%s: IOLINK_ARG_BLOCK_ID_OD_RD\n", __func__); - app_port->param_read.data_len = arg_block_len - sizeof(arg_block_od_t); + LOG_DEBUG (LOG_STATE_ON, "%s: IOLINK_ARG_BLOCK_ID_OD_RD\n", __func__); + app_port->param_read.data_len = arg_block_len - sizeof (arg_block_od_t); os_event_set (app_port->event, SMI_READ_CNF); break; case IOLINK_ARG_BLOCK_ID_PD_IN: /* SMI_PDIn_cnf */ memcpy (app_port->pdin.data, arg_block->pdin.data, arg_block->pdin.h.len); app_port->pdin.data_len = arg_block->pdin.h.len; - app_port->pdin.pqi = arg_block->pdin.h.port_qualifier_info; + app_port->pdin.pqi = arg_block->pdin.h.port_qualifier_info; break; case IOLINK_ARG_BLOCK_ID_PD_IN_OUT: /* SMI_PDInOut_cnf */ - LOG_DEBUG(LOG_STATE_ON, "%s: IOLINK_ARG_BLOCK_ID_PD_IN_OUT\n", __func__); + LOG_DEBUG (LOG_STATE_ON, "%s: IOLINK_ARG_BLOCK_ID_PD_IN_OUT\n", __func__); break; case IOLINK_ARG_BLOCK_ID_MASTERIDENT: /* SMI_MasterIdentification_cnf() */ - LOG_DEBUG(LOG_STATE_ON, "%s: IOLINK_ARG_BLOCK_ID_MASTERIDENT\n", __func__); + LOG_DEBUG (LOG_STATE_ON, "%s: IOLINK_ARG_BLOCK_ID_MASTERIDENT\n", __func__); app_m->vendorid = arg_block->masterident.h.vendorid; app_m->masterid = arg_block->masterident.h.masterid; os_event_set (app_port->event, SMI_MASTERIDENT_CNF); @@ -583,32 +704,44 @@ static void SMI_cnf_cb (void * arg, uint8_t portnumber, { case IOLINK_ARG_BLOCK_ID_PD_OUT: /* SMI_DeviceWrite_cnf */ - LOG_DEBUG(LOG_STATE_ON, "%s: IOLINK_ARG_BLOCK_ID_PD_OUT\n", __func__); + LOG_DEBUG (LOG_STATE_ON, "%s: IOLINK_ARG_BLOCK_ID_PD_OUT\n", __func__); break; case IOLINK_ARG_BLOCK_ID_DS_DATA: /* SMI_ParServToDS_cnf */ - LOG_DEBUG(LOG_STATE_ON, "%s: IOLINK_ARG_BLOCK_ID_DS_DATA\n", __func__); + LOG_DEBUG (LOG_STATE_ON, "%s: IOLINK_ARG_BLOCK_ID_DS_DATA\n", __func__); os_event_set (app_port->event, SMI_PARSERV_TO_DS_CNF); break; case IOLINK_ARG_BLOCK_ID_OD_WR: /* SMI_DeviceWrite_cnf */ - LOG_DEBUG(LOG_STATE_ON, "%s: IOLINK_ARG_BLOCK_ID_OD_WR\n", __func__); + LOG_DEBUG (LOG_STATE_ON, "%s: IOLINK_ARG_BLOCK_ID_OD_WR\n", __func__); os_event_set (app_port->event, SMI_WRITE_CNF); break; case IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST: /* SMI_PortConfiguration_cnf */ - LOG_DEBUG(LOG_STATE_ON, "%s: IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST\n", __func__); + LOG_DEBUG ( + LOG_STATE_ON, + "%s: IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST\n", + __func__); os_event_set (app_port->event, SMI_PORTCFG_CNF); break; default: - LOG_WARNING(LOG_STATE_ON, "%s: Port %u: Unexpected ref_arg_block_id 0x%04x and arg_block_id 0x%04x\n", - __func__, portnumber, ref_arg_block_id, arg_block->void_block.arg_block_id); + LOG_WARNING ( + LOG_STATE_ON, + "%s: Port %u: Unexpected ref_arg_block_id 0x%04x and arg_block_id " + "0x%04x\n", + __func__, + portnumber, + ref_arg_block_id, + arg_block->void_block.arg_block_id); break; } } } -iolink_smi_errortypes_t wait_for_cnf(iolink_app_port_ctx_t * app_port, uint32_t mask, uint32_t ms) +iolink_smi_errortypes_t wait_for_cnf ( + iolink_app_port_ctx_t * app_port, + uint32_t mask, + uint32_t ms) { uint32_t event_value; iolink_smi_errortypes_t errortype = IOLINK_SMI_ERRORTYPE_NONE; @@ -616,8 +749,12 @@ iolink_smi_errortypes_t wait_for_cnf(iolink_app_port_ctx_t * app_port, uint32_t /* Wait for SMI_xxx_cnf() */ if (os_event_wait (app_port->event, mask, &event_value, ms)) { - LOG_WARNING(LOG_STATE_ON, "%s: timeout for port %u (mask = 0x%X)\n", __func__, - app_port->portnumber, (unsigned int)mask); + LOG_WARNING ( + LOG_STATE_ON, + "%s: timeout for port %u (mask = 0x%X)\n", + __func__, + app_port->portnumber, + (unsigned int)mask); return IOLINK_SMI_ERRORTYPE_APP_DEV; // TODO } diff --git a/sample_app/iolink_handler.h b/sample_app/iolink_handler.h index 5204f48..9b07384 100644 --- a/sample_app/iolink_handler.h +++ b/sample_app/iolink_handler.h @@ -16,8 +16,8 @@ #include "sys/osal_sys.h" #include "iolink.h" -#define MASTER_VENDOR_ID 1171 -#define MASTER_ID 123 +#define MASTER_VENDOR_ID 1171 +#define MASTER_ID 123 typedef enum { @@ -95,7 +95,7 @@ typedef struct iolink_app_port_ctx { uint16_t data_len; } param_read; - os_mutex_t *pdout_mtx; + os_mutex_t * pdout_mtx; void (*run_function) (iolink_app_port_ctx_t * app_port); #ifdef __rtk__ bool alarm_active; @@ -115,8 +115,11 @@ iolink_app_master_ctx_t iolink_app_master; void iolink_handler (iolink_m_cfg_t m_cfg); -iolink_smi_errortypes_t wait_for_cnf(iolink_app_port_ctx_t * app_port, uint32_t mask, uint32_t ms); +iolink_smi_errortypes_t wait_for_cnf ( + iolink_app_port_ctx_t * app_port, + uint32_t mask, + uint32_t ms); uint8_t get_port_status (iolink_app_port_ctx_t * app_port); -#endif // IOLINK_HANDLER_H +#endif // IOLINK_HANDLER_H diff --git a/sample_app/iolink_ifm.c b/sample_app/iolink_ifm.c index e9cda20..a735976 100644 --- a/sample_app/iolink_ifm.c +++ b/sample_app/iolink_ifm.c @@ -18,7 +18,7 @@ #include "iolink_handler.h" #include "iolink_smi.h" -#define RFID_DATA_SIZE 8 +#define RFID_DATA_SIZE 8 static bool ifmrfid_get_tag_present (uint8_t * data) { @@ -49,50 +49,67 @@ static void ifmrfid_run (iolink_app_port_ctx_t * app_port) { uint8_t port_index = app_port->portnumber - 1; uint8_t pdata[IOLINK_NUM_PORTS][IOLINK_PD_MAX_SIZE]; - static bool tag_is_present[IOLINK_NUM_PORTS] = { false }; + static bool tag_is_present[IOLINK_NUM_PORTS] = {false}; if (do_smi_pdin (app_port, NULL, pdata[port_index]) != IOLINK_PD_MAX_SIZE) { - LOG_WARNING(LOG_STATE_ON, "%s: Failed to get PDIn (RFID port #%u)\n", - __func__, app_port->portnumber); + LOG_WARNING ( + LOG_STATE_ON, + "%s: Failed to get PDIn (RFID port #%u)\n", + __func__, + app_port->portnumber); return; } - uint8_t error_code = ifmrfid_get_error_code(pdata[port_index]); + uint8_t error_code = ifmrfid_get_error_code (pdata[port_index]); if (error_code != 0) { - LOG_ERROR(LOG_STATE_ON, "%s: Got error code %d (RFID port #%u)\n", - __func__, error_code, app_port->portnumber); + LOG_ERROR ( + LOG_STATE_ON, + "%s: Got error code %d (RFID port #%u)\n", + __func__, + error_code, + app_port->portnumber); return; } - if (ifmrfid_get_tag_present(pdata[port_index])) + if (ifmrfid_get_tag_present (pdata[port_index])) { - if (!tag_is_present[port_index]) // tagPresent transition from 0 to 1 + if (!tag_is_present[port_index]) // tagPresent transition from 0 to 1 { // check if UID is invalid, i.e. all zeroes (data starts at byte 2) - if (is_all_zeroes(&pdata[port_index][2], RFID_DATA_SIZE)) + if (is_all_zeroes (&pdata[port_index][2], RFID_DATA_SIZE)) { - LOG_ERROR(LOG_STATE_ON, "%s: Got tag_present with UID = 0 (RFID port #%u)\n", - __func__, app_port->portnumber); + LOG_ERROR ( + LOG_STATE_ON, + "%s: Got tag_present with UID = 0 (RFID port #%u)\n", + __func__, + app_port->portnumber); return; } tag_is_present[port_index] = true; char UUID[30]; - char *p = UUID; + char * p = UUID; int i; for (i = 0; i < RFID_DATA_SIZE; i++) { p += sprintf (p, "%02X", pdata[port_index][2 + i]); } - LOG_INFO(LOG_STATE_ON, "Port %u: RFID Tag data: %s\n", app_port->portnumber, UUID); + LOG_INFO ( + LOG_STATE_ON, + "Port %u: RFID Tag data: %s\n", + app_port->portnumber, + UUID); } } - else if (tag_is_present[port_index]) // tagPresent transition from 1 to 0 + else if (tag_is_present[port_index]) // tagPresent transition from 1 to 0 { tag_is_present[port_index] = false; - LOG_INFO(LOG_STATE_ON, "Port %u: RFID Tag not present\n", app_port->portnumber); + LOG_INFO ( + LOG_STATE_ON, + "Port %u: RFID Tag not present\n", + app_port->portnumber); } } @@ -100,14 +117,16 @@ void ifmrfid_setup (iolink_app_port_ctx_t * app_port) { uint8_t data[2] = {0, 0}; - LOG_INFO(LOG_STATE_ON, "Set up RFID on port %u\n", app_port->portnumber); + LOG_INFO (LOG_STATE_ON, "Set up RFID on port %u\n", app_port->portnumber); // Blocksize 4 data[0] = 4; if (do_smi_device_write (app_port, 1900, 0, 1, data) != IOLINK_ERROR_NONE) { - LOG_ERROR(LOG_STATE_ON, "Set up RFID blocksize failed on port %u\n", - app_port->portnumber); + LOG_ERROR ( + LOG_STATE_ON, + "Set up RFID blocksize failed on port %u\n", + app_port->portnumber); return; } @@ -115,8 +134,10 @@ void ifmrfid_setup (iolink_app_port_ctx_t * app_port) data[0] = 0; if (do_smi_device_write (app_port, 1901, 0, 1, data) != IOLINK_ERROR_NONE) { - LOG_ERROR(LOG_STATE_ON, "Set up RFID data order failed on port %u\n", - app_port->portnumber); + LOG_ERROR ( + LOG_STATE_ON, + "Set up RFID data order failed on port %u\n", + app_port->portnumber); return; } @@ -125,8 +146,10 @@ void ifmrfid_setup (iolink_app_port_ctx_t * app_port) data[1] = 50; if (do_smi_device_write (app_port, 1902, 0, 2, data) != IOLINK_ERROR_NONE) { - LOG_ERROR(LOG_STATE_ON, "Set up RFID data hold failed on port %u\n", - app_port->portnumber); + LOG_ERROR ( + LOG_STATE_ON, + "Set up RFID data hold failed on port %u\n", + app_port->portnumber); return; } @@ -134,8 +157,10 @@ void ifmrfid_setup (iolink_app_port_ctx_t * app_port) data[0] = 4; if (do_smi_device_write (app_port, 1904, 0, 1, data) != IOLINK_ERROR_NONE) { - LOG_ERROR(LOG_STATE_ON, "Set up RFID auto read/write failed on port %u\n", - app_port->portnumber); + LOG_ERROR ( + LOG_STATE_ON, + "Set up RFID auto read/write failed on port %u\n", + app_port->portnumber); return; } @@ -147,65 +172,80 @@ void ifmrfid_setup (iolink_app_port_ctx_t * app_port) } // ifmMHI Process data offsets -#define VALUE_LINE_1_MSB 0 -#define VALUE_LINE_1_LSB 1 -#define VALUE_LINE_2_MSB 2 -#define VALUE_LINE_2_LSB 3 -#define COLOR_LINE_1 8 -#define COLOR_LINE_2 9 -#define LEDS 12 -#define LAYOUT 13 +#define VALUE_LINE_1_MSB 0 +#define VALUE_LINE_1_LSB 1 +#define VALUE_LINE_2_MSB 2 +#define VALUE_LINE_2_LSB 3 +#define COLOR_LINE_1 8 +#define COLOR_LINE_2 9 +#define LEDS 12 +#define LAYOUT 13 // ifmMHI Process data values -#define DOWN_KEY_PRESSED BIT(0) -#define UP_KEY_PRESSED BIT(1) -#define ENTER_KEY_PRESSED BIT(2) -#define ESC_KEY_PRESSED BIT(3) -#define BLACK_WHITE 0 -#define RED 1 -#define GREEN 2 -#define YELLOW 3 -#define BLINK 40 -#define DISPLAY_TEXT 80 -#define LED_1_ON BIT(0) -#define LED_1_OFF 0 -#define LED_2_ON BIT(2) -#define LED_2_OFF 0 -#define ONE_LINE 1 -#define TWO_LINES 2 +#define DOWN_KEY_PRESSED BIT (0) +#define UP_KEY_PRESSED BIT (1) +#define ENTER_KEY_PRESSED BIT (2) +#define ESC_KEY_PRESSED BIT (3) +#define BLACK_WHITE 0 +#define RED 1 +#define GREEN 2 +#define YELLOW 3 +#define BLINK 40 +#define DISPLAY_TEXT 80 +#define LED_1_ON BIT (0) +#define LED_1_OFF 0 +#define LED_2_ON BIT (2) +#define LED_2_OFF 0 +#define ONE_LINE 1 +#define TWO_LINES 2 #define TEXT_ID(n) (n) -#define IFM_MHI_PD_SIZE 16 +#define IFM_MHI_PD_SIZE 16 static void ifmHMI_run (iolink_app_port_ctx_t * app_port) { - static uint32_t itr = 0; + static uint32_t itr = 0; static uint8_t prev_hmi_pdin = 0; - static uint8_t hmi_pdin = 0; - bool pdin_valid = false; + static uint8_t hmi_pdin = 0; + bool pdin_valid = false; itr++; if ((itr % 100) == 0) { - static uint8_t addr = 0; - static uint8_t data[12] = {'A', ' ', ' ', ' ', ' ', ' ', - ' ', ' ', ' ', ' ', ' ', ' ', }; + static uint8_t addr = 0; + static uint8_t data[12] = { + 'A', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + }; static uint8_t i = 0; /* 90 or 91, description of line 1 and 2 */ uint16_t index = 90 + (addr % 2); - if (do_smi_device_write (app_port, index, 0, sizeof(data), data) != IOLINK_ERROR_NONE) + if (do_smi_device_write (app_port, index, 0, sizeof (data), data) != IOLINK_ERROR_NONE) { - LOG_WARNING(LOG_STATE_ON, "%s: Failed to write on port %u\n", - __func__, app_port->portnumber); + LOG_WARNING ( + LOG_STATE_ON, + "%s: Failed to write on port %u\n", + __func__, + app_port->portnumber); } if (data[i] == 'Z') { i++; - i = i % 12; + i = i % 12; data[i] = 'A'; } else @@ -215,27 +255,35 @@ static void ifmHMI_run (iolink_app_port_ctx_t * app_port) addr++; } - if (do_smi_pdin (app_port, &pdin_valid, &hmi_pdin) != sizeof(hmi_pdin) != IOLINK_ERROR_NONE) + if (do_smi_pdin (app_port, &pdin_valid, &hmi_pdin) != sizeof (hmi_pdin) != IOLINK_ERROR_NONE) { - LOG_WARNING(LOG_STATE_ON, "%s: Failed to get PDIn from port %u\n", - __func__, app_port->portnumber); + LOG_WARNING ( + LOG_STATE_ON, + "%s: Failed to get PDIn from port %u\n", + __func__, + app_port->portnumber); } else { if (!pdin_valid) { - LOG_WARNING(LOG_STATE_ON, "%s: PDIn data is invalid for port %u\n", - __func__, app_port->portnumber); + LOG_WARNING ( + LOG_STATE_ON, + "%s: PDIn data is invalid for port %u\n", + __func__, + app_port->portnumber); } else { if (prev_hmi_pdin != hmi_pdin) { - LOG_INFO(LOG_STATE_ON, "\nUp: %u\nDown: %u\nEnter: %u\nEsc: %u\n\n", - hmi_pdin & UP_KEY_PRESSED ? 1 : 0, - hmi_pdin & DOWN_KEY_PRESSED ? 1 : 0, - hmi_pdin & ENTER_KEY_PRESSED ? 1 : 0, - hmi_pdin & ESC_KEY_PRESSED ? 1 : 0); + LOG_INFO ( + LOG_STATE_ON, + "\nUp: %u\nDown: %u\nEnter: %u\nEsc: %u\n\n", + hmi_pdin & UP_KEY_PRESSED ? 1 : 0, + hmi_pdin & DOWN_KEY_PRESSED ? 1 : 0, + hmi_pdin & ENTER_KEY_PRESSED ? 1 : 0, + hmi_pdin & ESC_KEY_PRESSED ? 1 : 0); prev_hmi_pdin = hmi_pdin; } } @@ -246,18 +294,18 @@ static void ifmHMI_run (iolink_app_port_ctx_t * app_port) static bool show_text = false; uint8_t data[IFM_MHI_PD_SIZE]; - bzero (data, sizeof(data)); + bzero (data, sizeof (data)); if (show_text) { - data[VALUE_LINE_1_LSB] = TEXT_ID(4); + data[VALUE_LINE_1_LSB] = TEXT_ID (4); data[COLOR_LINE_1] = YELLOW | DISPLAY_TEXT; data[LEDS] = LED_1_OFF | LED_2_ON; data[LAYOUT] = ONE_LINE; } else { - uint32_t val = itr - 512; + uint32_t val = itr - 512; data[VALUE_LINE_1_MSB] = val >> 8; data[VALUE_LINE_1_LSB] = val; data[VALUE_LINE_2_MSB] = val >> 18; @@ -268,7 +316,7 @@ static void ifmHMI_run (iolink_app_port_ctx_t * app_port) data[LAYOUT] = TWO_LINES; } - do_smi_pdout (app_port, true, sizeof(data), data); + do_smi_pdout (app_port, true, sizeof (data), data); show_text = !show_text; } @@ -276,8 +324,11 @@ static void ifmHMI_run (iolink_app_port_ctx_t * app_port) { if (do_smi_device_read (app_port, 90, 0, 17, NULL, NULL) != IOLINK_ERROR_NONE) { - LOG_WARNING(LOG_STATE_ON, "%s: Failed to read from port %u\n", - __func__, app_port->portnumber); + LOG_WARNING ( + LOG_STATE_ON, + "%s: Failed to read from port %u\n", + __func__, + app_port->portnumber); } } @@ -285,8 +336,11 @@ static void ifmHMI_run (iolink_app_port_ctx_t * app_port) { if (do_smi_pdinout (app_port) != IOLINK_ERROR_NONE) { - LOG_WARNING(LOG_STATE_ON, "%s: PDInOut failed on port %u\n", - __func__, app_port->portnumber); + LOG_WARNING ( + LOG_STATE_ON, + "%s: PDInOut failed on port %u\n", + __func__, + app_port->portnumber); } } } @@ -294,16 +348,16 @@ static void ifmHMI_run (iolink_app_port_ctx_t * app_port) void ifmHMI_setup (iolink_app_port_ctx_t * app_port) { uint8_t data[IFM_MHI_PD_SIZE]; - bzero (data, sizeof(data)); + bzero (data, sizeof (data)); - LOG_INFO(LOG_STATE_ON, "Set up HMI on port %u\n", app_port->portnumber); + LOG_INFO (LOG_STATE_ON, "Set up HMI on port %u\n", app_port->portnumber); - data[VALUE_LINE_1_LSB] = TEXT_ID(3); + data[VALUE_LINE_1_LSB] = TEXT_ID (3); data[COLOR_LINE_1] = BLACK_WHITE | DISPLAY_TEXT; data[LEDS] = LED_1_ON | LED_2_OFF; data[LAYOUT] = TWO_LINES; - do_smi_pdout (app_port, true, sizeof(data), data); + do_smi_pdout (app_port, true, sizeof (data), data); app_port->type = IFM_HMI; diff --git a/sample_app/iolink_ifm.h b/sample_app/iolink_ifm.h index e852e88..d3573fe 100644 --- a/sample_app/iolink_ifm.h +++ b/sample_app/iolink_ifm.h @@ -15,13 +15,13 @@ #include "iolink_handler.h" -#define IFM_VENDOR_ID 0x0136 +#define IFM_VENDOR_ID 0x0136 -#define IFM_RFID_DEVICE_ID 0x03C7 -#define IFM_HMI_DEVICE_ID 0x02A9 +#define IFM_RFID_DEVICE_ID 0x03C7 +#define IFM_HMI_DEVICE_ID 0x02A9 void ifmrfid_setup (iolink_app_port_ctx_t * app_port); void ifmHMI_setup (iolink_app_port_ctx_t * app_port); -#endif // IOLINK_IFM_H +#endif // IOLINK_IFM_H diff --git a/sample_app/iolink_smi.c b/sample_app/iolink_smi.c index 062efdd..20a2d30 100644 --- a/sample_app/iolink_smi.c +++ b/sample_app/iolink_smi.c @@ -18,67 +18,88 @@ #include "iolink_dl.h" #include "iolink_handler.h" -iolink_smi_errortypes_t do_smi_device_write (iolink_app_port_ctx_t * app_port, - uint16_t index, uint8_t subindex, - uint8_t len, const uint8_t * data) +iolink_smi_errortypes_t do_smi_device_write ( + iolink_app_port_ctx_t * app_port, + uint16_t index, + uint8_t subindex, + uint8_t len, + const uint8_t * data) { - uint8_t arg_block_len = sizeof(arg_block_od_t) + len; + uint8_t arg_block_len = sizeof (arg_block_od_t) + len; uint8_t buffer[arg_block_len]; arg_block_od_t * arg_block_od = (arg_block_od_t *)buffer; bzero (buffer, arg_block_len); arg_block_od->arg_block_id = IOLINK_ARG_BLOCK_ID_OD_WR; - arg_block_od->index = index; - arg_block_od->subindex = subindex; + arg_block_od->index = index; + arg_block_od->subindex = subindex; memcpy (arg_block_od->data, data, len); - iolink_error_t err = SMI_DeviceWrite_req (app_port->portnumber, - IOLINK_ARG_BLOCK_ID_VOID_BLOCK, arg_block_len, - (arg_block_t *)arg_block_od); + iolink_error_t err = SMI_DeviceWrite_req ( + app_port->portnumber, + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + arg_block_len, + (arg_block_t *)arg_block_od); if (err != IOLINK_ERROR_NONE) { - LOG_WARNING(LOG_STATE_ON, "%s failed (SMI_DeviceWrite_req returned %d) for port %u\n", - __func__, err, app_port->portnumber); - - return (err == IOLINK_ERROR_ODLENGTH) ? IOLINK_SMI_ERRORTYPE_VAL_LENOVRRUN : - IOLINK_SMI_ERRORTYPE_APP_DEV; // TODO + LOG_WARNING ( + LOG_STATE_ON, + "%s failed (SMI_DeviceWrite_req returned %d) for port %u\n", + __func__, + err, + app_port->portnumber); + + return (err == IOLINK_ERROR_ODLENGTH) + ? IOLINK_SMI_ERRORTYPE_VAL_LENOVRRUN + : IOLINK_SMI_ERRORTYPE_APP_DEV; // TODO } - return wait_for_cnf(app_port, SMI_WRITE_CNF, 10000); + return wait_for_cnf (app_port, SMI_WRITE_CNF, 10000); } -iolink_smi_errortypes_t do_smi_device_read (iolink_app_port_ctx_t * app_port, - uint16_t index, uint8_t subindex, - uint8_t len, uint8_t * data, - uint8_t * actual_len) +iolink_smi_errortypes_t do_smi_device_read ( + iolink_app_port_ctx_t * app_port, + uint16_t index, + uint8_t subindex, + uint8_t len, + uint8_t * data, + uint8_t * actual_len) { if (len == 0) { - LOG_WARNING(LOG_STATE_ON, "%s: len == 0 for port %u\n", __func__, - app_port->portnumber); + LOG_WARNING ( + LOG_STATE_ON, + "%s: len == 0 for port %u\n", + __func__, + app_port->portnumber); return IOLINK_SMI_ERRORTYPE_ARGBLOCK_INCONSISTENT; // TODO what to return? } - uint16_t arg_block_len = sizeof(arg_block_od_t) + len; + uint16_t arg_block_len = sizeof (arg_block_od_t) + len; uint8_t buffer[arg_block_len]; arg_block_od_t * arg_block_od = (arg_block_od_t *)buffer; bzero (buffer, arg_block_len); arg_block_od->arg_block_id = IOLINK_ARG_BLOCK_ID_OD_RD; - arg_block_od->index = index; - arg_block_od->subindex = subindex; + arg_block_od->index = index; + arg_block_od->subindex = subindex; iolink_smi_errortypes_t errortype = IOLINK_SMI_ERRORTYPE_NONE; - iolink_error_t err = SMI_DeviceRead_req (app_port->portnumber, - IOLINK_ARG_BLOCK_ID_OD_RD, - arg_block_len, - (arg_block_t *)arg_block_od); + iolink_error_t err = SMI_DeviceRead_req ( + app_port->portnumber, + IOLINK_ARG_BLOCK_ID_OD_RD, + arg_block_len, + (arg_block_t *)arg_block_od); if (err != IOLINK_ERROR_NONE) { - LOG_WARNING(LOG_STATE_ON, "%s failed (SMI_DeviceRead_req returned %d) for port %u\n", - __func__, err, app_port->portnumber); + LOG_WARNING ( + LOG_STATE_ON, + "%s failed (SMI_DeviceRead_req returned %d) for port %u\n", + __func__, + err, + app_port->portnumber); errortype = IOLINK_SMI_ERRORTYPE_APP_DEV; // TODO } @@ -91,8 +112,11 @@ iolink_smi_errortypes_t do_smi_device_read (iolink_app_port_ctx_t * app_port, { errortype = app_port->errortype; - LOG_WARNING(LOG_STATE_ON, "%s: timeout for port %u\n", __func__, - app_port->portnumber); + LOG_WARNING ( + LOG_STATE_ON, + "%s: timeout for port %u\n", + __func__, + app_port->portnumber); if (errortype != IOLINK_SMI_ERRORTYPE_NONE) { @@ -127,23 +151,27 @@ iolink_smi_errortypes_t do_smi_device_read (iolink_app_port_ctx_t * app_port, return errortype; } -uint8_t do_smi_pdout (iolink_app_port_ctx_t * app_port, bool output_enable, - uint8_t len, const uint8_t * data) +uint8_t do_smi_pdout ( + iolink_app_port_ctx_t * app_port, + bool output_enable, + uint8_t len, + const uint8_t * data) { - os_mutex_lock(app_port->pdout_mtx); + os_mutex_lock (app_port->pdout_mtx); arg_block_pdout_t arg_block_pdout; arg_block_pdout.h.arg_block_id = IOLINK_ARG_BLOCK_ID_PD_OUT; memcpy (arg_block_pdout.data, data, len); arg_block_pdout.h.len = len; - arg_block_pdout.h.oe = (output_enable) ? 1 : 0; + arg_block_pdout.h.oe = (output_enable) ? 1 : 0; - iolink_error_t err = SMI_PDOut_req (app_port->portnumber, - IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - sizeof(arg_block_pdout_head_t) + len, - (arg_block_t *)&arg_block_pdout); - os_mutex_unlock(app_port->pdout_mtx); + iolink_error_t err = SMI_PDOut_req ( + app_port->portnumber, + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + sizeof (arg_block_pdout_head_t) + len, + (arg_block_t *)&arg_block_pdout); + os_mutex_unlock (app_port->pdout_mtx); return (err == IOLINK_ERROR_NONE) ? 0 : 1; } @@ -153,13 +181,15 @@ int8_t do_smi_pdin (iolink_app_port_ctx_t * app_port, bool * valid, uint8_t * pd arg_block_void_t arg_block_void; int8_t len = 0; - bzero (&arg_block_void, sizeof(arg_block_void_t)); + bzero (&arg_block_void, sizeof (arg_block_void_t)); arg_block_void.arg_block_id = IOLINK_ARG_BLOCK_ID_VOID_BLOCK; - if (SMI_PDIn_req (app_port->portnumber, - IOLINK_ARG_BLOCK_ID_PD_IN, - sizeof(arg_block_void_t), - (arg_block_t *)&arg_block_void) == IOLINK_ERROR_NONE) + if ( + SMI_PDIn_req ( + app_port->portnumber, + IOLINK_ARG_BLOCK_ID_PD_IN, + sizeof (arg_block_void_t), + (arg_block_t *)&arg_block_void) == IOLINK_ERROR_NONE) { len = app_port->pdin.data_len; @@ -170,8 +200,8 @@ int8_t do_smi_pdin (iolink_app_port_ctx_t * app_port, bool * valid, uint8_t * pd *valid = !(app_port->pdin.pqi & IOLINK_PORT_QUALIFIER_INFO_PQ_INVALID); iolink_port_t * port = - iolink_get_port (iolink_app_master.master, app_port->portnumber); - iolink_get_dl_ctx(port)->pd_handler.pd_valid = *valid; + iolink_get_port (iolink_app_master.master, app_port->portnumber); + iolink_get_dl_ctx (port)->pd_handler.pd_valid = *valid; } } @@ -182,13 +212,14 @@ uint8_t do_smi_pdinout (iolink_app_port_ctx_t * app_port) { arg_block_void_t arg_block_void; - bzero (&arg_block_void, sizeof(arg_block_void_t)); + bzero (&arg_block_void, sizeof (arg_block_void_t)); arg_block_void.arg_block_id = IOLINK_ARG_BLOCK_ID_VOID_BLOCK; - iolink_error_t err = SMI_PDInOut_req (app_port->portnumber, - IOLINK_ARG_BLOCK_ID_PD_IN_OUT, - sizeof(arg_block_void_t), - (arg_block_t *)&arg_block_void); + iolink_error_t err = SMI_PDInOut_req ( + app_port->portnumber, + IOLINK_ARG_BLOCK_ID_PD_IN_OUT, + sizeof (arg_block_void_t), + (arg_block_t *)&arg_block_void); return (err == IOLINK_ERROR_NONE) ? 0 : 1; } diff --git a/sample_app/iolink_smi.h b/sample_app/iolink_smi.h index 593c573..43b3b37 100644 --- a/sample_app/iolink_smi.h +++ b/sample_app/iolink_smi.h @@ -16,20 +16,29 @@ #include "iolink.h" #include "iolink_handler.h" -iolink_smi_errortypes_t do_smi_device_write (iolink_app_port_ctx_t * app_port, - uint16_t index, uint8_t subindex, - uint8_t len, const uint8_t * data); - -iolink_smi_errortypes_t do_smi_device_read (iolink_app_port_ctx_t * app_port, - uint16_t index, uint8_t subindex, - uint8_t len, uint8_t * data, - uint8_t * actual_len); - -uint8_t do_smi_pdout (iolink_app_port_ctx_t * app_port, bool output_enable, - uint8_t len, const uint8_t * data); +iolink_smi_errortypes_t do_smi_device_write ( + iolink_app_port_ctx_t * app_port, + uint16_t index, + uint8_t subindex, + uint8_t len, + const uint8_t * data); + +iolink_smi_errortypes_t do_smi_device_read ( + iolink_app_port_ctx_t * app_port, + uint16_t index, + uint8_t subindex, + uint8_t len, + uint8_t * data, + uint8_t * actual_len); + +uint8_t do_smi_pdout ( + iolink_app_port_ctx_t * app_port, + bool output_enable, + uint8_t len, + const uint8_t * data); int8_t do_smi_pdin (iolink_app_port_ctx_t * app_port, bool * valid, uint8_t * pdin); uint8_t do_smi_pdinout (iolink_app_port_ctx_t * app_port); -#endif // IOLINK_SMI_H +#endif // IOLINK_SMI_H diff --git a/sample_app/util/irq_test.c b/sample_app/util/irq_test.c index 01abe98..31a0cb4 100644 --- a/sample_app/util/irq_test.c +++ b/sample_app/util/irq_test.c @@ -24,9 +24,9 @@ #include #define SYSFS_GPIO_DIR "/sys/class/gpio" -#define MAX_BUF 64 +#define MAX_BUF 64 -typedef void(*isr_func_t)(int pin); +typedef void (*isr_func_t) (int pin); typedef struct { @@ -36,49 +36,49 @@ typedef struct pthread_mutex_t mtx; } irq_thread_t; -void isr_func(int pin) +void isr_func (int pin) { - printf("\n%s: GPIO pin %d interrupt occurred\n", __func__, pin); + printf ("\n%s: GPIO pin %d interrupt occurred\n", __func__, pin); } -void *irq_thread(void *arg) +void * irq_thread (void * arg) { - irq_thread_t *irq = (irq_thread_t *)arg; + irq_thread_t * irq = (irq_thread_t *)arg; struct pollfd p_fd; char buf[MAX_BUF]; while (true) { - memset(&p_fd, 0, sizeof(p_fd)); + memset (&p_fd, 0, sizeof (p_fd)); - p_fd.fd = irq->fd; + p_fd.fd = irq->fd; p_fd.events = POLLPRI; - int rc = poll(&p_fd, 1, 5000); + int rc = poll (&p_fd, 1, 5000); if (rc < 0) { - printf("\npoll() failed!\n"); + printf ("\npoll() failed!\n"); } else if (rc == 0) { - printf("."); + printf ("."); } else if (p_fd.revents & POLLPRI) { - lseek(p_fd.fd, 0, SEEK_SET); - int len = read(p_fd.fd, buf, MAX_BUF); + lseek (p_fd.fd, 0, SEEK_SET); + int len = read (p_fd.fd, buf, MAX_BUF); (void)len; - irq->isr_func(irq->gpio); + irq->isr_func (irq->gpio); } - fflush(stdout); + fflush (stdout); } close (irq->fd); } -pthread_t *setup_int(unsigned int gpio_pin, isr_func_t isr_func) +pthread_t * setup_int (unsigned int gpio_pin, isr_func_t isr_func) { char buf[MAX_BUF]; pthread_attr_t attr; @@ -86,76 +86,76 @@ pthread_t *setup_int(unsigned int gpio_pin, isr_func_t isr_func) static irq_thread_t irqarg; // Add gpio_pin to exported pins - int fd = open(SYSFS_GPIO_DIR "/export", O_WRONLY); + int fd = open (SYSFS_GPIO_DIR "/export", O_WRONLY); if (fd < 0) { - perror("gpio/export"); + perror ("gpio/export"); return NULL; } - int n = write(fd, buf, snprintf(buf, sizeof(buf), "%d", gpio_pin)); - close(fd); + int n = write (fd, buf, snprintf (buf, sizeof (buf), "%d", gpio_pin)); + close (fd); if (n < 0) { - perror("setup_int(): Failed to write gpio_pin to gpio/export"); + perror ("setup_int(): Failed to write gpio_pin to gpio/export"); } // Set direction of pin to input - snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/direction", gpio_pin); - fd = open(buf, O_WRONLY); + snprintf (buf, sizeof (buf), SYSFS_GPIO_DIR "/gpio%d/direction", gpio_pin); + fd = open (buf, O_WRONLY); if (fd < 0) { - perror("gpio/direction"); + perror ("gpio/direction"); return NULL; } - n = write(fd, "in", sizeof("in") + 1); - close(fd); + n = write (fd, "in", sizeof ("in") + 1); + close (fd); if (n < 0) { - perror("write direction"); + perror ("write direction"); return NULL; } // Set edge detection to falling - snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/edge", gpio_pin); - fd = open(buf, O_WRONLY); + snprintf (buf, sizeof (buf), SYSFS_GPIO_DIR "/gpio%d/edge", gpio_pin); + fd = open (buf, O_WRONLY); if (fd < 0) { - perror("gpio/edge"); + perror ("gpio/edge"); return NULL; } - n = write(fd, "falling", sizeof("falling") + 1); - close(fd); + n = write (fd, "falling", sizeof ("falling") + 1); + close (fd); if (n < 0) { - perror("write edge"); + perror ("write edge"); return NULL; } // Open file and return file descriptor - snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/value", gpio_pin); - fd = open(buf, O_RDONLY | O_NONBLOCK); + snprintf (buf, sizeof (buf), SYSFS_GPIO_DIR "/gpio%d/value", gpio_pin); + fd = open (buf, O_RDONLY | O_NONBLOCK); if (fd < 0) { - perror("gpio/value"); + perror ("gpio/value"); return NULL; } // Create isr service thread irqarg.isr_func = isr_func; - irqarg.fd = fd; - irqarg.gpio = gpio_pin; - pthread_attr_init(&attr); - pthread_create(&thread, &attr, irq_thread, &irqarg); + irqarg.fd = fd; + irqarg.gpio = gpio_pin; + pthread_attr_init (&attr); + pthread_create (&thread, &attr, irq_thread, &irqarg); return &thread; } @@ -163,16 +163,17 @@ pthread_t *setup_int(unsigned int gpio_pin, isr_func_t isr_func) /**************************************************************** * Main ****************************************************************/ -int main(int argc, char **argv) +int main (int argc, char ** argv) { if (argc < 2) { - printf("Usage: %s \n\n", argv[0]); - printf("Waits for a change in the GPIO pin voltage level or input on stdin\n"); - exit(-1); + printf ("Usage: %s \n\n", argv[0]); + printf ("Waits for a change in the GPIO pin voltage level or input on " + "stdin\n"); + exit (-1); } - setup_int(atoi(argv[1]), isr_func); + setup_int (atoi (argv[1]), isr_func); while (true) { diff --git a/sample_app/util/max14819_dump_registers.py b/sample_app/util/max14819_dump_registers.py deleted file mode 100644 index af5f50f..0000000 --- a/sample_app/util/max14819_dump_registers.py +++ /dev/null @@ -1,70 +0,0 @@ -import subprocess - -max14819_registers = [ - {'regnr': 0x00, 'name': 'TxRxDataA', 'bits': ['D7A', 'D6A', 'D5A', 'D4A', 'D3A', 'D2A', 'D1A', 'D0A']}, - {'regnr': 0x01, 'name': 'TxRxDataB', 'bits': ['D7B', 'D6B', 'D5B', 'D4B', 'D3B', 'D2B', 'D1B', 'D0B']}, - {'regnr': 0x02, 'name': 'Interupt', 'bits': ['StatusErr', 'WURQErr', 'TxErrorB', 'TxErrorA', 'RxErrorB', 'RxErrorA', 'RxDataRdyB', 'RxDataRdyA']}, - {'regnr': 0x03, 'name': 'InteruptEn', 'bits': ['StatusIntEn', 'WURQErrEn', 'TxErrIntEnB', 'TxErrIntEnA', 'RxErrIntEnB', 'RxErrIntEnA', 'RDaRdyIntEnB', 'RDaRdyIntEnA']}, - {'regnr': 0x04, 'name': 'RxFIFOLvlA', 'bits': ['FifoLvl7A', 'FifoLvl6A', 'FifoLvl5A', 'FifoLvl4A', 'FifoLvl3A', 'FifoLvl2A', 'FifoLvl1A', 'FifoLvl0A']}, - {'regnr': 0x05, 'name': 'RxFIFOLvlB', 'bits': ['FifoLvl7B', 'FifoLvl6B', 'FifoLvl5B', 'FifoLvl4B', 'FifoLvl3B', 'FifoLvl2B', 'FifoLvl1B', 'FifoLvl0B']}, - {'regnr': 0x06, 'name': 'CQCntrolA', 'bits': ['ComRt1A', 'ComRt0A', 'EstComA', 'WuPulsA', 'TxFifoRstA', 'RxFifoRstA', 'CyclTmrEnA', 'CQSendA']}, - {'regnr': 0x07, 'name': 'CQCntrolB', 'bits': ['ComRt1B', 'ComRt0B', 'EstComB', 'WuPulsB', 'TxFifoRstB', 'RxFifoRstB', 'CyclTmrEnB', 'CQSendB']}, - {'regnr': 0x08, 'name': 'CQErrorA', 'bits': ['TransmErrA', 'TCyclErrA', 'TChksmErA', 'TSizeErrA', 'RChksmErA', 'RSizeErrA', 'FrameErrA', 'ParityErrA']}, - {'regnr': 0x09, 'name': 'CQErrorB', 'bits': ['TransmErrB', 'TCyclErrB', 'TChksmErB', 'TSizeErrB', 'RChksmErB', 'RSizeErrB', 'FrameErrB', 'ParityErrB']}, - {'regnr': 0x0A, 'name': 'MesgCntlA', 'bits': ['TxErDestroyA', 'SPIChksA', 'InsChksA', 'TSizeEnA', 'TxKeepMsgA', 'RChksEnA', 'RMessgRdyEnA', 'InvCQA']}, - {'regnr': 0x0B, 'name': 'MesgCntlB', 'bits': ['TxErDestroyB', 'SPIChksB', 'InsChksB', 'TSizeEnB', 'TxKeepMsgB', 'RChksEnB', 'RMessgRdyEnB', 'InvCQB']}, - {'regnr': 0x0C, 'name': 'ChanStatA', 'bits': ['RstA', 'FramerEnA', 'L+CLimErrA', 'UVL+ErrA', 'CQLimErrA', 'L+CLimA', 'UVL+A', 'CQLimA']}, - {'regnr': 0x0D, 'name': 'ChanStatB', 'bits': ['RstB', 'FramerEnB', 'L+CLimErrB', 'UVL+ErrB', 'CQLimErrB', 'L+CLimB', 'UVL+B', 'CQLimB']}, - {'regnr': 0x0E, 'name': 'LEDCntrl', 'bits': ['LEDEn2B', 'RxErrEnB', 'LEDEn1B', 'RxRdyEnB', 'LEDEn2A', 'RxErrEnA', 'LEDEn1A', 'RxRdyEnA']}, - {'regnr': 0x0F, 'name': 'Trigger', 'bits': ['-', '-', '-', '-', 'Trigger3', 'Trigger2', 'Trigger1', 'Trigger0']}, - {'regnr': 0x10, 'name': 'CQConfgA', 'bits': ['IEC3ThA', 'SorceSinkA', 'SinkSel1A', 'SinkSel0A', 'NPNA', 'PushPulA', 'DrvrDisA', 'RFilterEnA']}, - {'regnr': 0x11, 'name': 'CQConfgB', 'bits': ['IEC3ThB', 'SorceSinkB', 'SinkSel1B', 'SinkSel0B', 'NPNB', 'PushPulB', 'DrvrDisB', 'RFilterEnB']}, - {'regnr': 0x12, 'name': 'CyclTimeA', 'bits': ['TCycBsA1', 'TCycBsA0', 'TCycMA5', 'TCycMA4', 'TCycMA3', 'TCycMA2', 'TCycMA1', 'TCycMA0']}, - {'regnr': 0x13, 'name': 'CyclTimeB', 'bits': ['TCycBsB1', 'TCycBsB0', 'TCycMB5', 'TCycMB4', 'TCycMB3', 'TCycMB2', 'TCycMB1', 'TCycMB0']}, - {'regnr': 0x14, 'name': 'DevicDelyA', 'bits': ['DelayErrA', 'BDelay1A', 'BDelay0A', 'DDelay3A', 'DDelay2A', 'DDelay1A', 'DDelay0A', 'RspnsTmrEnA']}, - {'regnr': 0x15, 'name': 'DevicDelyB', 'bits': ['DelayErrB', 'BDelay1B', 'BDelay0B', 'DDelay3B', 'DDelay2B', 'DDelay1B', 'DDelay0B', 'RspnsTmrEnB']}, - {'regnr': 0x16, 'name': 'TrigAssgnA', 'bits': ['Trig3A', 'Trig2A', 'Trig1A', 'Trig0A', '-', '-', '-', 'TrigEnA']}, - {'regnr': 0x17, 'name': 'TrigAssgnB', 'bits': ['Trig3B', 'Trig2B', 'Trig1B', 'Trig0B', '-', '-', '-', 'TrigEnB']}, - {'regnr': 0x18, 'name': 'L+ConfigA', 'bits': ['L+RT1A', 'L+RT0A', 'L+DynBLA', 'L+BL1A', 'L+BL0A', 'L+CL2xA', 'L+CLimDisA', 'L+EnA']}, - {'regnr': 0x19, 'name': 'L+ConfigB', 'bits': ['L+RT1B', 'L+RT0B', 'L+DynBLB', 'L+BL1B', 'L+BL0B', 'L+CL2xB', 'L+CLimDisB', 'L+EnB']}, - {'regnr': 0x1A, 'name': 'IoStatCfgA', 'bits': ['DiLevelA', 'CQLevelA', 'TxEnA', 'TxA', 'DiFilterEnA', 'DiIEC3ThA', 'DiCSorceA', 'DiCSinkA']}, - {'regnr': 0x1B, 'name': 'IoStatCfgB', 'bits': ['DiLevelB', 'CQLevelB', 'TxEnB', 'TxB', 'DiFilterEnB', 'DiIEC3ThB', 'DiCSorceB', 'DiCSinkB']}, - {'regnr': 0x1C, 'name': 'DrvrCurLim', 'bits': ['CL1', 'CL0', 'CLDis', 'CLBL1', 'CLBL0', 'TAr1', 'TAr0', 'ArEn']}, - {'regnr': 0x1D, 'name': 'Clock', 'bits': ['VCCWEn', 'TxTxenDis', '-', 'ClkOEn', 'ClkDiv1', 'ClkDiv0', 'ExtClkEn', 'XtalEn']}, - {'regnr': 0x1E, 'name': 'Status', 'bits': ['ThrmShutErr', 'ThrmWarnErr', 'UVCCErr', 'VCCWarn', 'ThrmShut', 'TempWarn', 'UVCC', 'VCCWarn']}, - {'regnr': 0x1F, 'name': 'RevID', 'bits': ['-', '-', '-', '-', 'ID3', 'ID2', 'ID1', 'ID0']}] - -def max14819_read_register(chip_addr, register): - txbyte = 0x80 + (chip_addr << 5) + register - result = subprocess.run(['./spi_test', '-D', '/dev/spidev0.0', '-s', '4000000', - '-p', '\\x{0:02x}\\x00'.format(txbyte)], - capture_output=True) -# print('Args: {0}'.format(result.args)) -# print(result.stdout) - return str(result.stdout).split('\\n')[-2].split(' ')[2:4] - -def isbitset(val, bit): - return 1 if (val & (1 << bit) > 0) else 0 - -def register_details(chip_addr, register): - res = int(max14819_read_register(0, register['regnr'])[1], 16) - print('{0}: 0x{1:02x}. '.format(register['name'], res), end='') - for bitpos, bitname in enumerate(register['bits']): - if bitpos > 0: - print(', ', end='') - print('{0}: {1}'.format(bitname, isbitset(res, 7 - bitpos)), end='') - print('') - -def dump_registers(): - for reg in max14819_registers: - res = max14819_read_register(0, reg['regnr']) - print('{0}: {1}'.format(reg['name'].rjust(10), res[1])) - -def max1819_set_register(chip_addr, register, value): - txbyte = (chip_addr << 5) + register - result = subprocess.run(['./spi_test', '-D', '/dev/spidev0.0', '-s', '4000000', - '-p', '\\x{0:02x}\\x{1:02x}'.format(txbyte, value)]) - - -dump_registers() -#register_details(0, max14819_registers[0x0E]) diff --git a/sample_app/util/spidev_test.c b/sample_app/util/spidev_test.c deleted file mode 100644 index 135b3f5..0000000 --- a/sample_app/util/spidev_test.c +++ /dev/null @@ -1,318 +0,0 @@ -/* - * SPI testing utility (using spidev driver) - * - * Copyright (c) 2007 MontaVista Software, Inc. - * Copyright (c) 2007 Anton Vorontsov - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License. - * - * Cross-compile with cross-gcc -I/path/to/cross-kernel/include - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) - -static void pabort(const char *s) -{ - perror(s); - abort(); -} - -static const char *device = "/dev/spidev1.1"; -static uint32_t mode; -static uint8_t bits = 8; -static uint32_t speed = 500000; -static uint16_t delay; -static int verbose; - -uint8_t default_tx[] = { - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0x40, 0x00, 0x00, 0x00, 0x00, 0x95, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xF0, 0x0D, -}; - -uint8_t default_rx[ARRAY_SIZE(default_tx)] = {0, }; -char *input_tx; - -static void hex_dump(const void *src, size_t length, size_t line_size, char *prefix) -{ - int i = 0; - const unsigned char *address = src; - const unsigned char *line = address; - unsigned char c; - - printf("%s | ", prefix); - while (length-- > 0) { - printf("%02X ", *address++); - if (!(++i % line_size) || (length == 0 && i % line_size)) { - if (length == 0) { - while (i++ % line_size) - printf("__ "); - } - printf(" | "); /* right close */ - while (line < address) { - c = *line++; - printf("%c", (c < 33 || c == 255) ? 0x2E : c); - } - printf("\n"); - if (length > 0) - printf("%s | ", prefix); - } - } -} - -/* - * Unescape - process hexadecimal escape character - * converts shell input "\x23" -> 0x23 - */ -static int unescape(char *_dst, char *_src, size_t len) -{ - int ret = 0; - char *src = _src; - char *dst = _dst; - unsigned int ch; - - while (*src) { - if (*src == '\\' && *(src+1) == 'x') { - sscanf(src + 2, "%2x", &ch); - src += 4; - *dst++ = (unsigned char)ch; - } else { - *dst++ = *src++; - } - ret++; - } - return ret; -} - -static void transfer(int fd, uint8_t const *tx, uint8_t const *rx, size_t len) -{ - int ret; - - struct spi_ioc_transfer tr = { - .tx_buf = (unsigned long)tx, - .rx_buf = (unsigned long)rx, - .len = len, - .delay_usecs = delay, - .speed_hz = speed, - .bits_per_word = bits, - }; - - if (mode & SPI_TX_QUAD) - tr.tx_nbits = 4; - else if (mode & SPI_TX_DUAL) - tr.tx_nbits = 2; - if (mode & SPI_RX_QUAD) - tr.rx_nbits = 4; - else if (mode & SPI_RX_DUAL) - tr.rx_nbits = 2; - if (!(mode & SPI_LOOP)) { - if (mode & (SPI_TX_QUAD | SPI_TX_DUAL)) - tr.rx_buf = 0; - else if (mode & (SPI_RX_QUAD | SPI_RX_DUAL)) - tr.tx_buf = 0; - } - - ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr); - if (ret < 1) - pabort("can't send spi message"); - - if (verbose) - hex_dump(tx, len, 32, "TX"); - hex_dump(rx, len, 32, "RX"); -} - -static void print_usage(const char *prog) -{ - printf("Usage: %s [-DsbdlHOLC3]\n", prog); - puts(" -D --device device to use (default /dev/spidev1.1)\n" - " -s --speed max speed (Hz)\n" - " -d --delay delay (usec)\n" - " -b --bpw bits per word \n" - " -l --loop loopback\n" - " -H --cpha clock phase\n" - " -O --cpol clock polarity\n" - " -L --lsb least significant bit first\n" - " -C --cs-high chip select active high\n" - " -3 --3wire SI/SO signals shared\n" - " -v --verbose Verbose (show tx buffer)\n" - " -p Send data (e.g. \"1234\\xde\\xad\")\n" - " -N --no-cs no chip select\n" - " -R --ready slave pulls low to pause\n" - " -2 --dual dual transfer\n" - " -4 --quad quad transfer\n"); - exit(1); -} - -static void parse_opts(int argc, char *argv[]) -{ - while (1) { - static const struct option lopts[] = { - { "device", 1, 0, 'D' }, - { "speed", 1, 0, 's' }, - { "delay", 1, 0, 'd' }, - { "bpw", 1, 0, 'b' }, - { "loop", 0, 0, 'l' }, - { "cpha", 0, 0, 'H' }, - { "cpol", 0, 0, 'O' }, - { "lsb", 0, 0, 'L' }, - { "cs-high", 0, 0, 'C' }, - { "3wire", 0, 0, '3' }, - { "no-cs", 0, 0, 'N' }, - { "ready", 0, 0, 'R' }, - { "dual", 0, 0, '2' }, - { "verbose", 0, 0, 'v' }, - { "quad", 0, 0, '4' }, - { NULL, 0, 0, 0 }, - }; - int c; - - c = getopt_long(argc, argv, "D:s:d:b:lHOLC3NR24p:v", lopts, NULL); - - if (c == -1) - break; - - switch (c) { - case 'D': - device = optarg; - break; - case 's': - speed = atoi(optarg); - break; - case 'd': - delay = atoi(optarg); - break; - case 'b': - bits = atoi(optarg); - break; - case 'l': - mode |= SPI_LOOP; - break; - case 'H': - mode |= SPI_CPHA; - break; - case 'O': - mode |= SPI_CPOL; - break; - case 'L': - mode |= SPI_LSB_FIRST; - break; - case 'C': - mode |= SPI_CS_HIGH; - break; - case '3': - mode |= SPI_3WIRE; - break; - case 'N': - mode |= SPI_NO_CS; - break; - case 'v': - verbose = 1; - break; - case 'R': - mode |= SPI_READY; - break; - case 'p': - input_tx = optarg; - break; - case '2': - mode |= SPI_TX_DUAL; - break; - case '4': - mode |= SPI_TX_QUAD; - break; - default: - print_usage(argv[0]); - break; - } - } - if (mode & SPI_LOOP) { - if (mode & SPI_TX_DUAL) - mode |= SPI_RX_DUAL; - if (mode & SPI_TX_QUAD) - mode |= SPI_RX_QUAD; - } -} - -int main(int argc, char *argv[]) -{ - int ret = 0; - int fd; - uint8_t *tx; - uint8_t *rx; - int size; - - parse_opts(argc, argv); - - fd = open(device, O_RDWR); - if (fd < 0) - pabort("can't open device"); - - /* - * spi mode - */ - ret = ioctl(fd, SPI_IOC_WR_MODE32, &mode); - if (ret == -1) - pabort("can't set spi mode"); - - ret = ioctl(fd, SPI_IOC_RD_MODE32, &mode); - if (ret == -1) - pabort("can't get spi mode"); - - /* - * bits per word - */ - ret = ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits); - if (ret == -1) - pabort("can't set bits per word"); - - ret = ioctl(fd, SPI_IOC_RD_BITS_PER_WORD, &bits); - if (ret == -1) - pabort("can't get bits per word"); - - /* - * max speed hz - */ - ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed); - if (ret == -1) - pabort("can't set max speed hz"); - - ret = ioctl(fd, SPI_IOC_RD_MAX_SPEED_HZ, &speed); - if (ret == -1) - pabort("can't get max speed hz"); - - printf("spi mode: 0x%x\n", mode); - printf("bits per word: %d\n", bits); - printf("max speed: %d Hz (%d KHz)\n", speed, speed/1000); - - if (input_tx) { - size = strlen(input_tx+1); - tx = malloc(size); - rx = malloc(size); - size = unescape((char *)tx, input_tx, size); - transfer(fd, tx, rx, size); - free(rx); - free(tx); - } else { - transfer(fd, default_tx, default_rx, sizeof(default_tx)); - } - - close(fd); - - return ret; -} diff --git a/src/iolink_al.c b/src/iolink_al.c index 5e968a9..de99548 100644 --- a/src/iolink_al.c +++ b/src/iolink_al.c @@ -11,25 +11,25 @@ ********************************************************************/ #ifdef UNIT_TEST -#define DL_ReadParam_req mock_DL_ReadParam_req -#define DL_WriteParam_req mock_DL_WriteParam_req -#define DL_ISDUTransport_req mock_DL_ISDUTransport_req -#define DL_Control_req mock_DL_Control_req -#define DL_EventConf_req mock_DL_EventConf_req -#define DL_PDOutputGet_req mock_DL_PDOutputGet_req -#define DL_PDOutputUpdate_req mock_DL_PDOutputUpdate_req -#define AL_Event_ind mock_AL_Event_ind -#define AL_Control_ind mock_AL_Control_ind -#define AL_NewInput_ind mock_AL_NewInput_ind -#define iolink_post_job mock_iolink_post_job -#define iolink_fetch_avail_job mock_iolink_fetch_avail_job +#define DL_ReadParam_req mock_DL_ReadParam_req +#define DL_WriteParam_req mock_DL_WriteParam_req +#define DL_ISDUTransport_req mock_DL_ISDUTransport_req +#define DL_Control_req mock_DL_Control_req +#define DL_EventConf_req mock_DL_EventConf_req +#define DL_PDOutputGet_req mock_DL_PDOutputGet_req +#define DL_PDOutputUpdate_req mock_DL_PDOutputUpdate_req +#define AL_Event_ind mock_AL_Event_ind +#define AL_Control_ind mock_AL_Control_ind +#define AL_NewInput_ind mock_AL_NewInput_ind +#define iolink_post_job mock_iolink_post_job +#define iolink_fetch_avail_job mock_iolink_fetch_avail_job #define iolink_fetch_avail_api_job mock_iolink_fetch_avail_api_job #endif /* UNIT_TEST */ #include "iolink_al.h" #include "iolink_ds.h" /* DS_Upload */ #include "iolink_dl.h" /* DL_ReadParam_req, DL_WriteParam_req, DL_ISDUTransport_req, DL_Control_req, DL_EventConf_req, DL_PDOutputUpdate_req DL_PDOutputGet_req */ -#include "iolink_pde.h" /* AL_Control_ind, AL_NewInput_ind */ +#include "iolink_pde.h" /* AL_Control_ind, AL_NewInput_ind */ #include "iolink_main.h" /* iolink_fetch_avail_job, iolink_post_job, iolink_post_job_pd_event, iolink_get_portnumber */ #include "osal_log.h" @@ -42,16 +42,14 @@ * */ -const char * iolink_al_od_state_literals[] = -{ +const char * iolink_al_od_state_literals[] = { "OnReq_Idle", "Build_DL_Service", "Await_DL_param_cnf", "Await_DL_ISDU_cnf", }; -const char * iolink_al_od_event_literals[] = -{ +const char * iolink_al_od_event_literals[] = { "NONE", "service", /* T1", T16", T8 and T12 */ "arg_err", /* T2 */ @@ -68,8 +66,7 @@ const char * iolink_al_od_event_literals[] = "abort_port", /* T17 */ }; -const char * iolink_al_event_state_literals[] = -{ +const char * iolink_al_event_state_literals[] = { "Event_inactive", "Event_idle", "Read_Event_Set", @@ -77,8 +74,7 @@ const char * iolink_al_event_state_literals[] = "LAST", }; -const char * iolink_al_event_event_literals[] = -{ +const char * iolink_al_event_event_literals[] = { "NONE", "dl_event_ind_more", /* T3 or T4 */ "dl_event_ind_done", /* T5 or T3 + T5 */ @@ -91,8 +87,8 @@ typedef struct iolink_fsm_al_od_transition { iolink_fsm_al_od_event_t event; iolink_al_od_state_t next_state; - iolink_fsm_al_od_event_t (*action)(iolink_port_t * port, - iolink_fsm_al_od_event_t event); + iolink_fsm_al_od_event_t ( + *action) (iolink_port_t * port, iolink_fsm_al_od_event_t event); } iolink_fsm_al_od_transition_t; typedef struct iolink_fsm_al_od_state_transitions @@ -105,8 +101,8 @@ typedef struct iolink_fsm_al_event_transition { iolink_fsm_al_event_event_t event; iolink_al_event_state_t next_state; - iolink_fsm_al_event_event_t (*action)(iolink_port_t * port, - iolink_fsm_al_event_event_t event); + iolink_fsm_al_event_event_t ( + *action) (iolink_port_t * port, iolink_fsm_al_event_event_t event); } iolink_fsm_al_event_transition_t; typedef struct iolink_fsm_al_event_state_transitions @@ -115,12 +111,13 @@ typedef struct iolink_fsm_al_event_state_transitions const iolink_fsm_al_event_transition_t * transitions; } iolink_fsm_al_event_state_transitions_t; -static inline iolink_smi_errortypes_t al_err_to_errortype (iolink_al_port_t * al, - bool is_isdu) +static inline iolink_smi_errortypes_t al_err_to_errortype ( + iolink_al_port_t * al, + bool is_isdu) { iolink_rwdirection_t direction = al->service.direction; - iolink_status_t stat = al->service.errinfo; - iservice_t qualifier = al->service.qualifier; + iolink_status_t stat = al->service.errinfo; + iservice_t qualifier = al->service.qualifier; iolink_smi_errortypes_t errortype = IOLINK_SMI_ERRORTYPE_NONE; @@ -139,19 +136,23 @@ static inline iolink_smi_errortypes_t al_err_to_errortype (iolink_al_port_t * al { if (al->service.data_len == 2) { - errortype = al->service.data_read[0] << 8 | al->service.data_read[1]; + errortype = al->service.data_read[0] << 8 | + al->service.data_read[1]; } else { - errortype = IOLINK_SMI_ERRORTYPE_APP_DEV; // TODO how to know error type? + errortype = IOLINK_SMI_ERRORTYPE_APP_DEV; // TODO how to know + // error type? } break; } case IOL_ISERVICE_DEVICE_READ_RESPONSE_POS: break; /* ISDU read ok */ default: - LOG_ERROR (IOLINK_AL_LOG, - "AL: ISDU_read_cnf: Got unexpected qualifier 0x%02x\n", qualifier); + LOG_ERROR ( + IOLINK_AL_LOG, + "AL: ISDU_read_cnf: Got unexpected qualifier 0x%02x\n", + qualifier); errortype = IOLINK_SMI_ERRORTYPE_APP_DEV; break; } @@ -164,11 +165,13 @@ static inline iolink_smi_errortypes_t al_err_to_errortype (iolink_al_port_t * al { if (al->service.data_len == 2) { - errortype = al->service.data_read[0] << 8 | al->service.data_read[1]; + errortype = al->service.data_read[0] << 8 | + al->service.data_read[1]; } else { - errortype = IOLINK_SMI_ERRORTYPE_APP_DEV; // TODO how to know error type? + errortype = IOLINK_SMI_ERRORTYPE_APP_DEV; // TODO how to know + // error type? } break; } @@ -181,8 +184,10 @@ static inline iolink_smi_errortypes_t al_err_to_errortype (iolink_al_port_t * al } break; default: - LOG_DEBUG (IOLINK_AL_LOG, - "AL: ISDU_write_cnf: Got unexpected qualifier 0x%02x\n", qualifier); + LOG_DEBUG ( + IOLINK_AL_LOG, + "AL: ISDU_write_cnf: Got unexpected qualifier 0x%02x\n", + qualifier); break; } } @@ -207,7 +212,8 @@ static inline iolink_smi_errortypes_t al_err_to_errortype (iolink_al_port_t * al case IOLINK_STATUS_ISDU_NOT_SUPPORTED: case IOLINK_STATUS_VALUE_OUT_OF_RANGE: case IOLINK_STATUS_ISDU_ABORT: - errortype = IOLINK_SMI_ERRORTYPE_APP_DEV; // TODO how to know error type? + errortype = IOLINK_SMI_ERRORTYPE_APP_DEV; // TODO how to know error + // type? break; case IOLINK_STATUS_INVALID: /* No ISDU service */ @@ -229,21 +235,26 @@ static inline iolink_smi_errortypes_t al_err_to_errortype (iolink_al_port_t * al return errortype; } -static iolink_fsm_al_od_event_t al_od_busy (iolink_port_t * port, - iolink_fsm_al_od_event_t event) +static iolink_fsm_al_od_event_t al_od_busy ( + iolink_port_t * port, + iolink_fsm_al_od_event_t event) { iolink_al_port_t * al = iolink_get_al_ctx (port); - iolink_job_t * job = al->service.job_req; + iolink_job_t * job = al->service.job_req; switch (job->type) { case IOLINK_JOB_AL_READ_REQ: - job->al_read_req.al_read_cb (port, 0, NULL, - IOLINK_SMI_ERRORTYPE_SERVICE_TEMP_UNAVAILABLE); + job->al_read_req.al_read_cb ( + port, + 0, + NULL, + IOLINK_SMI_ERRORTYPE_SERVICE_TEMP_UNAVAILABLE); break; case IOLINK_JOB_AL_WRITE_REQ: - job->al_write_req.al_write_cb (port, - IOLINK_SMI_ERRORTYPE_SERVICE_TEMP_UNAVAILABLE); + job->al_write_req.al_write_cb ( + port, + IOLINK_SMI_ERRORTYPE_SERVICE_TEMP_UNAVAILABLE); break; default: CC_ASSERT (0); @@ -253,22 +264,23 @@ static iolink_fsm_al_od_event_t al_od_busy (iolink_port_t * port, return AL_OD_EVENT_NONE; } -static iolink_fsm_al_od_event_t al_od_build_dl_service (iolink_port_t * port, - iolink_fsm_al_od_event_t event) +static iolink_fsm_al_od_event_t al_od_build_dl_service ( + iolink_port_t * port, + iolink_fsm_al_od_event_t event) { - iolink_al_port_t * al = iolink_get_al_ctx (port); - iolink_job_t * job = al->service.job_req; - uint16_t index = 0; - bool isdu_flag = true; // TODO where do we get this from? + iolink_al_port_t * al = iolink_get_al_ctx (port); + iolink_job_t * job = al->service.job_req; + uint16_t index = 0; + bool isdu_flag = true; // TODO where do we get this from? iolink_fsm_al_od_event_t res_event = AL_OD_EVENT_arg_err; switch (job->type) { case IOLINK_JOB_AL_READ_REQ: al->service.data_len = 0; - index = al->service.index = job->al_read_req.index; - al->service.subindex = job->al_read_req.subindex; - al->service.direction = IOLINK_RWDIRECTION_READ; + index = al->service.index = job->al_read_req.index; + al->service.subindex = job->al_read_req.subindex; + al->service.direction = IOLINK_RWDIRECTION_READ; al->service.al_read_cnf_cb = job->al_read_req.al_read_cb; if (index <= 1) @@ -281,11 +293,11 @@ static iolink_fsm_al_od_event_t al_od_build_dl_service (iolink_port_t * port, } break; case IOLINK_JOB_AL_WRITE_REQ: - index = al->service.index = job->al_write_req.index; - al->service.subindex = job->al_write_req.subindex; - al->service.data_len = job->al_write_req.length; - al->service.direction = IOLINK_RWDIRECTION_WRITE; - al->service.data_write = job->al_write_req.data; + index = al->service.index = job->al_write_req.index; + al->service.subindex = job->al_write_req.subindex; + al->service.data_len = job->al_write_req.length; + al->service.direction = IOLINK_RWDIRECTION_WRITE; + al->service.data_write = job->al_write_req.data; al->service.al_write_cnf_cb = job->al_write_req.al_write_cb; if (index == 1) @@ -314,16 +326,18 @@ static iolink_fsm_al_od_event_t al_od_build_dl_service (iolink_port_t * port, return res_event; } -static iolink_fsm_al_od_event_t al_od_send_al_cnf (iolink_port_t * port, - iolink_fsm_al_od_event_t event) +static iolink_fsm_al_od_event_t al_od_send_al_cnf ( + iolink_port_t * port, + iolink_fsm_al_od_event_t event) { - iolink_al_port_t * al = iolink_get_al_ctx (port); + iolink_al_port_t * al = iolink_get_al_ctx (port); iolink_smi_errortypes_t errortype = IOLINK_SMI_ERRORTYPE_NONE; switch (event) { case AL_OD_EVENT_abort: /* T9 and T11, + T16 */ - // TODO All current DL service actions are abandoned.... -> and a negative AL service confirmation is prepared + // TODO All current DL service actions are abandoned.... -> and a negative + // AL service confirmation is prepared /* fall through */ case AL_OD_EVENT_arg_err: /* T2 + T16 */ errortype = al_err_to_errortype (al, false); @@ -340,8 +354,11 @@ static iolink_fsm_al_od_event_t al_od_send_al_cnf (iolink_port_t * port, break; case AL_OD_EVENT_readparam_cnf: /* T13 + T16 */ errortype = al_err_to_errortype (al, false); - al->service.al_read_cnf_cb (port, al->service.data_len, - al->service.data_read, errortype); + al->service.al_read_cnf_cb ( + port, + al->service.data_len, + al->service.data_read, + errortype); break; case AL_OD_EVENT_isdutransport_cnf: /* T15 + T16 */ { @@ -349,8 +366,11 @@ static iolink_fsm_al_od_event_t al_od_send_al_cnf (iolink_port_t * port, if (al->service.direction == IOLINK_RWDIRECTION_READ) { - al->service.al_read_cnf_cb (port, al->service.data_len, - al->service.data_read, errortype); + al->service.al_read_cnf_cb ( + port, + al->service.data_len, + al->service.data_read, + errortype); } else if (al->service.direction == IOLINK_RWDIRECTION_WRITE) { @@ -370,8 +390,9 @@ static iolink_fsm_al_od_event_t al_od_send_al_cnf (iolink_port_t * port, return AL_OD_EVENT_NONE; } -static iolink_fsm_al_od_event_t al_od_send_abort_al_cnf (iolink_port_t * port, - iolink_fsm_al_od_event_t event) +static iolink_fsm_al_od_event_t al_od_send_abort_al_cnf ( + iolink_port_t * port, + iolink_fsm_al_od_event_t event) { if (event == AL_OD_EVENT_abort_port) /* T17 */ { @@ -381,14 +402,16 @@ static iolink_fsm_al_od_event_t al_od_send_abort_al_cnf (iolink_port_t * port, return AL_OD_EVENT_NONE; } -static iolink_fsm_al_od_event_t al_od_isdu_read_write (iolink_port_t * port, - iolink_fsm_al_od_event_t event, iolink_rwdirection_t rwdirection) +static iolink_fsm_al_od_event_t al_od_isdu_read_write ( + iolink_port_t * port, + iolink_fsm_al_od_event_t event, + iolink_rwdirection_t rwdirection) { iolink_isdu_vl_t valuelist; iolink_al_port_t * al = iolink_get_al_ctx (port); - valuelist.index = al->service.index; - valuelist.subindex = al->service.subindex; + valuelist.index = al->service.index; + valuelist.subindex = al->service.subindex; valuelist.readwrite = rwdirection; if (rwdirection == IOLINK_RWDIRECTION_READ) @@ -403,27 +426,32 @@ static iolink_fsm_al_od_event_t al_od_isdu_read_write (iolink_port_t * port, if (DL_ISDUTransport_req (port, &valuelist) != IOLINK_ERROR_NONE) { - LOG_ERROR (IOLINK_AL_LOG, "AL: bad %s DL_ISDUTransport_req!\n", - (rwdirection == IOLINK_RWDIRECTION_READ) ? "Read" : "Write"); + LOG_ERROR ( + IOLINK_AL_LOG, + "AL: bad %s DL_ISDUTransport_req!\n", + (rwdirection == IOLINK_RWDIRECTION_READ) ? "Read" : "Write"); } return AL_OD_EVENT_NONE; } -static iolink_fsm_al_od_event_t al_od_isdu_read (iolink_port_t * port, - iolink_fsm_al_od_event_t event) +static iolink_fsm_al_od_event_t al_od_isdu_read ( + iolink_port_t * port, + iolink_fsm_al_od_event_t event) { - return al_od_isdu_read_write(port, event, IOLINK_RWDIRECTION_READ); + return al_od_isdu_read_write (port, event, IOLINK_RWDIRECTION_READ); } -static iolink_fsm_al_od_event_t al_od_isdu_write (iolink_port_t * port, - iolink_fsm_al_od_event_t event) +static iolink_fsm_al_od_event_t al_od_isdu_write ( + iolink_port_t * port, + iolink_fsm_al_od_event_t event) { - return al_od_isdu_read_write(port, event, IOLINK_RWDIRECTION_WRITE); + return al_od_isdu_read_write (port, event, IOLINK_RWDIRECTION_WRITE); } -static iolink_fsm_al_od_event_t al_od_param_read (iolink_port_t * port, - iolink_fsm_al_od_event_t event) +static iolink_fsm_al_od_event_t al_od_param_read ( + iolink_port_t * port, + iolink_fsm_al_od_event_t event) { iolink_al_port_t * al = iolink_get_al_ctx (port); @@ -434,8 +462,9 @@ static iolink_fsm_al_od_event_t al_od_param_read (iolink_port_t * port, return AL_OD_EVENT_NONE; } -static iolink_fsm_al_od_event_t al_od_param_write (iolink_port_t * port, - iolink_fsm_al_od_event_t event) +static iolink_fsm_al_od_event_t al_od_param_write ( + iolink_port_t * port, + iolink_fsm_al_od_event_t event) { iolink_al_port_t * al = iolink_get_al_ctx (port); @@ -459,70 +488,78 @@ static iolink_fsm_al_od_event_t al_od_param_write (iolink_port_t * port, return AL_OD_EVENT_NONE; } -static iolink_fsm_al_od_event_t al_od_param_next_rw (iolink_port_t * port, - iolink_fsm_al_od_event_t event) +static iolink_fsm_al_od_event_t al_od_param_next_rw ( + iolink_port_t * port, + iolink_fsm_al_od_event_t event) { - // TODO Call next DL_ReadParam or DL_WriteParam service, if not all OD are transferred + // TODO Call next DL_ReadParam or DL_WriteParam service, if not all OD are + // transferred return AL_OD_EVENT_NONE; } /* AL OD FSM state transitions, IO-Link Interface Spec v1.1.3 Chapter 8.3.2.1 */ -/* since we iterate through the list on events put the most likely in the top of the list. */ -static const iolink_fsm_al_od_transition_t al_od_trans_s0[] = -{ +/* since we iterate through the list on events put the most likely in the top of + * the list. */ +static const iolink_fsm_al_od_transition_t al_od_trans_s0[] = { /* OnReq_Idle_0 */ - { AL_OD_EVENT_service, AL_OD_STATE_Build_DL_Service, al_od_build_dl_service }, /* T1 */ - { AL_OD_EVENT_abort_port, AL_OD_STATE_OnReq_Idle, al_od_send_abort_al_cnf }, /* T17 */ + {AL_OD_EVENT_service, AL_OD_STATE_Build_DL_Service, al_od_build_dl_service}, /* T1 */ + {AL_OD_EVENT_abort_port, AL_OD_STATE_OnReq_Idle, al_od_send_abort_al_cnf}, /* T17 */ }; -static const iolink_fsm_al_od_transition_t al_od_trans_s1[] = -{ +static const iolink_fsm_al_od_transition_t al_od_trans_s1[] = { /* Build_DL_Service_1 */ - { AL_OD_EVENT_arg_err, AL_OD_STATE_OnReq_Idle, al_od_send_al_cnf }, /* T2 + T16 */ - { AL_OD_EVENT_param_read, AL_OD_STATE_Await_DL_param_cnf, al_od_param_read }, /* T3 */ - { AL_OD_EVENT_param_write_1, AL_OD_STATE_Await_DL_param_cnf, al_od_param_write }, /* T4 */ - { AL_OD_EVENT_param_write_2, AL_OD_STATE_Await_DL_param_cnf, al_od_param_write }, /* T5 */ - { AL_OD_EVENT_isdu_read, AL_OD_STATE_Await_DL_ISDU_cnf, al_od_isdu_read }, /* T6 */ - { AL_OD_EVENT_isdu_write, AL_OD_STATE_Await_DL_ISDU_cnf, al_od_isdu_write }, /* T7 */ + {AL_OD_EVENT_arg_err, AL_OD_STATE_OnReq_Idle, al_od_send_al_cnf}, /* T2 + T16 + */ + {AL_OD_EVENT_param_read, AL_OD_STATE_Await_DL_param_cnf, al_od_param_read}, /* T3 */ + {AL_OD_EVENT_param_write_1, + AL_OD_STATE_Await_DL_param_cnf, + al_od_param_write}, /* T4 */ + {AL_OD_EVENT_param_write_2, + AL_OD_STATE_Await_DL_param_cnf, + al_od_param_write}, /* T5 */ + {AL_OD_EVENT_isdu_read, AL_OD_STATE_Await_DL_ISDU_cnf, al_od_isdu_read}, /* T6 + */ + {AL_OD_EVENT_isdu_write, AL_OD_STATE_Await_DL_ISDU_cnf, al_od_isdu_write}, /* T7 */ }; -static const iolink_fsm_al_od_transition_t al_od_trans_s2[] = -{ +static const iolink_fsm_al_od_transition_t al_od_trans_s2[] = { /* Await_DL_Param_cnf_2 */ - { AL_OD_EVENT_service, AL_OD_STATE_Await_DL_param_cnf, al_od_busy }, /* T8 */ - { AL_OD_EVENT_abort, AL_OD_STATE_OnReq_Idle, al_od_send_al_cnf }, /* T9 + T16 */ - { AL_OD_EVENT_rwparam, AL_OD_STATE_Await_DL_param_cnf, al_od_param_next_rw }, /* T10 */ - { AL_OD_EVENT_readparam_cnf, AL_OD_STATE_OnReq_Idle, al_od_send_al_cnf }, /* T13 + T16 */ - { AL_OD_EVENT_writeparam_cnf, AL_OD_STATE_OnReq_Idle, al_od_send_al_cnf }, /* T14 + T16 */ + {AL_OD_EVENT_service, AL_OD_STATE_Await_DL_param_cnf, al_od_busy}, /* T8 */ + {AL_OD_EVENT_abort, AL_OD_STATE_OnReq_Idle, al_od_send_al_cnf}, /* T9 + T16 + */ + {AL_OD_EVENT_rwparam, AL_OD_STATE_Await_DL_param_cnf, al_od_param_next_rw}, /* T10 */ + {AL_OD_EVENT_readparam_cnf, AL_OD_STATE_OnReq_Idle, al_od_send_al_cnf}, /* T13 + + + T16 + */ + {AL_OD_EVENT_writeparam_cnf, AL_OD_STATE_OnReq_Idle, al_od_send_al_cnf}, /* T14 + + T16 */ }; -static const iolink_fsm_al_od_transition_t al_od_trans_s3[] = -{ +static const iolink_fsm_al_od_transition_t al_od_trans_s3[] = { /* Await_DL_ISDU_cnf_3 */ - { AL_OD_EVENT_abort, AL_OD_STATE_OnReq_Idle, al_od_send_al_cnf }, /* T11 + T16 */ - { AL_OD_EVENT_service, AL_OD_STATE_Await_DL_ISDU_cnf, al_od_busy }, /* T12 */ - { AL_OD_EVENT_isdutransport_cnf, AL_OD_STATE_OnReq_Idle, al_od_send_al_cnf }, /* T15 + T16 */ + {AL_OD_EVENT_abort, AL_OD_STATE_OnReq_Idle, al_od_send_al_cnf}, /* T11 + T16 + */ + {AL_OD_EVENT_service, AL_OD_STATE_Await_DL_ISDU_cnf, al_od_busy}, /* T12 */ + {AL_OD_EVENT_isdutransport_cnf, + AL_OD_STATE_OnReq_Idle, + al_od_send_al_cnf}, /* T15 + T16 */ }; /* The index is the state in this array */ -static const iolink_fsm_al_od_state_transitions_t iolink_al_od_fsm[] = -{ - { /* OnReq_Idle_0 */ - .number_of_trans = NELEMENTS (al_od_trans_s0), - .transitions = al_od_trans_s0 - }, - { /* Build_DL_Service_1 */ - .number_of_trans = NELEMENTS (al_od_trans_s1), - .transitions = al_od_trans_s1 - }, - { /* Await_DL_Param_cnf_2 */ - .number_of_trans = NELEMENTS (al_od_trans_s2), - .transitions = al_od_trans_s2 - }, - { /* Await_DL_ISDU_cnf_3 */ - .number_of_trans = NELEMENTS (al_od_trans_s3), - .transitions = al_od_trans_s3 - }, +static const iolink_fsm_al_od_state_transitions_t iolink_al_od_fsm[] = { + {/* OnReq_Idle_0 */ + .number_of_trans = NELEMENTS (al_od_trans_s0), + .transitions = al_od_trans_s0}, + {/* Build_DL_Service_1 */ + .number_of_trans = NELEMENTS (al_od_trans_s1), + .transitions = al_od_trans_s1}, + {/* Await_DL_Param_cnf_2 */ + .number_of_trans = NELEMENTS (al_od_trans_s2), + .transitions = al_od_trans_s2}, + {/* Await_DL_ISDU_cnf_3 */ + .number_of_trans = NELEMENTS (al_od_trans_s3), + .transitions = al_od_trans_s3}, }; /** @@ -538,7 +575,7 @@ static void iolink_al_od_event (iolink_port_t * port, iolink_fsm_al_od_event_t e do { int i; - iolink_al_port_t * al = iolink_get_al_ctx (port); + iolink_al_port_t * al = iolink_get_al_ctx (port); iolink_al_od_state_t previous = al->od_state; const iolink_fsm_al_od_transition_t * next_trans = NULL; @@ -555,34 +592,41 @@ static void iolink_al_od_event (iolink_port_t * port, iolink_fsm_al_od_event_t e } if (!next_trans) { - LOG_ERROR (IOLINK_AL_LOG, "AL OD (%u): next_trans == NULL: state %s - event %s\n", - iolink_get_portnumber (port), - iolink_al_od_state_literals[previous], - iolink_al_od_event_literals[event]); + LOG_ERROR ( + IOLINK_AL_LOG, + "AL OD (%u): next_trans == NULL: state %s - event %s\n", + iolink_get_portnumber (port), + iolink_al_od_state_literals[previous], + iolink_al_od_event_literals[event]); return; } /* Transition to next state */ al->od_state = next_trans->next_state; - LOG_DEBUG (IOLINK_AL_LOG, "AL OD (%u): event: %s, state transition: %s -> %s\n", - iolink_get_portnumber (port), iolink_al_od_event_literals[event], - iolink_al_od_state_literals[previous], - iolink_al_od_state_literals[al->od_state]); + LOG_DEBUG ( + IOLINK_AL_LOG, + "AL OD (%u): event: %s, state transition: %s -> %s\n", + iolink_get_portnumber (port), + iolink_al_od_event_literals[event], + iolink_al_od_state_literals[previous], + iolink_al_od_state_literals[al->od_state]); event = next_trans->action (port, event); } while (event != AL_OD_EVENT_NONE); } -static iolink_fsm_al_event_event_t al_event_wait_read (iolink_port_t * port, - iolink_fsm_al_event_event_t event) +static iolink_fsm_al_event_event_t al_event_wait_read ( + iolink_port_t * port, + iolink_fsm_al_event_event_t event) { /* Wait for more data */ return AL_EVENT_EVENT_NONE; } -static iolink_fsm_al_event_event_t al_event_du_handle (iolink_port_t * port, - iolink_fsm_al_event_event_t event) +static iolink_fsm_al_event_event_t al_event_du_handle ( + iolink_port_t * port, + iolink_fsm_al_event_event_t event) { iolink_al_port_t * al = iolink_get_al_ctx (port); @@ -591,8 +635,9 @@ static iolink_fsm_al_event_event_t al_event_du_handle (iolink_port_t * port, return AL_EVENT_EVENT_NONE; } -static iolink_fsm_al_event_event_t al_event_idle (iolink_port_t * port, - iolink_fsm_al_event_event_t event) +static iolink_fsm_al_event_event_t al_event_idle ( + iolink_port_t * port, + iolink_fsm_al_event_event_t event) { iolink_al_port_t * al = iolink_get_al_ctx (port); @@ -615,49 +660,53 @@ static iolink_fsm_al_event_event_t al_event_idle (iolink_port_t * port, return AL_EVENT_EVENT_NONE; } -/* AL Event FSM state transitions, IO-Link Interface Spec v1.1.3 Chapter 8.3.3.1 */ -/* since we iterate through the list on events put the most likely in the top of the list. */ -static const iolink_fsm_al_event_transition_t al_event_trans_s0[] = -{ +/* AL Event FSM state transitions, IO-Link Interface Spec v1.1.3 Chapter 8.3.3.1 + */ +/* since we iterate through the list on events put the most likely in the top of + * the list. */ +static const iolink_fsm_al_event_transition_t al_event_trans_s0[] = { /* Event_idle_1 */ - { AL_EVENT_EVENT_dl_event_ind_more, AL_EVENT_STATE_Read_Event_Set, al_event_wait_read }, /* T3 */ - { AL_EVENT_EVENT_dl_event_ind_done, AL_EVENT_STATE_DU_Event_handling, al_event_du_handle }, /* T3 + T5 */ - { AL_EVENT_EVENT_al_event_req, AL_EVENT_STATE_Event_idle, al_event_idle }, /* T7 */ + {AL_EVENT_EVENT_dl_event_ind_more, + AL_EVENT_STATE_Read_Event_Set, + al_event_wait_read}, /* T3 */ + {AL_EVENT_EVENT_dl_event_ind_done, + AL_EVENT_STATE_DU_Event_handling, + al_event_du_handle}, /* T3 + T5 */ + {AL_EVENT_EVENT_al_event_req, AL_EVENT_STATE_Event_idle, al_event_idle}, /* T7 + */ }; -static const iolink_fsm_al_event_transition_t al_event_trans_s1[] = -{ +static const iolink_fsm_al_event_transition_t al_event_trans_s1[] = { /* Read_Event_Set_2 */ - { AL_EVENT_EVENT_dl_event_ind_more, AL_EVENT_STATE_Read_Event_Set, al_event_wait_read }, /* T4 */ - { AL_EVENT_EVENT_dl_event_ind_done, AL_EVENT_STATE_DU_Event_handling, al_event_du_handle }, /* T5 */ + {AL_EVENT_EVENT_dl_event_ind_more, + AL_EVENT_STATE_Read_Event_Set, + al_event_wait_read}, /* T4 */ + {AL_EVENT_EVENT_dl_event_ind_done, + AL_EVENT_STATE_DU_Event_handling, + al_event_du_handle}, /* T5 */ }; -static const iolink_fsm_al_event_transition_t al_event_trans_s2[] = -{ +static const iolink_fsm_al_event_transition_t al_event_trans_s2[] = { /* DU_Event_handling_3 */ - { AL_EVENT_EVENT_al_event_rsp, AL_EVENT_STATE_Event_idle, al_event_idle }, /* T6 */ + {AL_EVENT_EVENT_al_event_rsp, AL_EVENT_STATE_Event_idle, al_event_idle}, /* T6 + */ }; /* The index is the state in this array */ -static const iolink_fsm_al_event_state_transitions_t iolink_al_event_fsm[] = -{ - - { /* Event_Inactive_0 */ - .number_of_trans = 0, - .transitions = NULL - }, - { /* Event_idle_1 */ - .number_of_trans = NELEMENTS (al_event_trans_s0), - .transitions = al_event_trans_s0 - }, - { /* Read_Event_Set_2 */ - .number_of_trans = NELEMENTS (al_event_trans_s1), - .transitions = al_event_trans_s1 - }, - { /* DU_Event_handling_3 */ - .number_of_trans = NELEMENTS (al_event_trans_s2), - .transitions = al_event_trans_s2 - }, +static const iolink_fsm_al_event_state_transitions_t iolink_al_event_fsm[] = { + + {/* Event_Inactive_0 */ + .number_of_trans = 0, + .transitions = NULL}, + {/* Event_idle_1 */ + .number_of_trans = NELEMENTS (al_event_trans_s0), + .transitions = al_event_trans_s0}, + {/* Read_Event_Set_2 */ + .number_of_trans = NELEMENTS (al_event_trans_s1), + .transitions = al_event_trans_s1}, + {/* DU_Event_handling_3 */ + .number_of_trans = NELEMENTS (al_event_trans_s2), + .transitions = al_event_trans_s2}, }; /** @@ -668,13 +717,14 @@ static const iolink_fsm_al_event_state_transitions_t iolink_al_event_fsm[] = * @param port Port handle * @param event AL Event event */ -static void iolink_al_event_event (iolink_port_t * port, - iolink_fsm_al_event_event_t event) +static void iolink_al_event_event ( + iolink_port_t * port, + iolink_fsm_al_event_event_t event) { do { int i; - iolink_al_port_t * al = iolink_get_al_ctx (port); + iolink_al_port_t * al = iolink_get_al_ctx (port); iolink_al_event_state_t previous = al->event_state; const iolink_fsm_al_event_transition_t * next_trans = NULL; @@ -691,20 +741,25 @@ static void iolink_al_event_event (iolink_port_t * port, } if (!next_trans) { - LOG_ERROR (IOLINK_AL_LOG, "AL Event (%u): next_trans == NULL: state %s - event %s\n", - iolink_get_portnumber (port), - iolink_al_event_state_literals[previous], - iolink_al_event_event_literals[event]); + LOG_ERROR ( + IOLINK_AL_LOG, + "AL Event (%u): next_trans == NULL: state %s - event %s\n", + iolink_get_portnumber (port), + iolink_al_event_state_literals[previous], + iolink_al_event_event_literals[event]); return; } /* Transition to next state */ al->event_state = next_trans->next_state; - LOG_DEBUG (IOLINK_AL_LOG, "AL Event (%u): event: %s, state transition: %s -> %s\n", - iolink_get_portnumber (port), iolink_al_event_event_literals[event], - iolink_al_event_state_literals[previous], - iolink_al_event_state_literals[al->event_state]); + LOG_DEBUG ( + IOLINK_AL_LOG, + "AL Event (%u): event: %s, state transition: %s -> %s\n", + iolink_get_portnumber (port), + iolink_al_event_event_literals[event], + iolink_al_event_state_literals[previous], + iolink_al_event_state_literals[al->event_state]); event = next_trans->action (port, event); } while (event != AL_EVENT_EVENT_NONE); @@ -713,7 +768,7 @@ static void iolink_al_event_event (iolink_port_t * port, /* AL job callback functions */ static void al_read_write_cb (iolink_job_t * job) { - iolink_port_t * port = job->port; + iolink_port_t * port = job->port; iolink_al_port_t * al = iolink_get_al_ctx (port); al->service.job_req = job; @@ -723,13 +778,13 @@ static void al_read_write_cb (iolink_job_t * job) static void al_dl_event_ind_cb (iolink_job_t * job) { iolink_fsm_al_event_event_t res_event; - iolink_port_t * port = job->port; + iolink_port_t * port = job->port; iolink_al_port_t * al = iolink_get_al_ctx (port); - diag_entry_t * evt = &(al->event.events[al->event.event_cnt]); + diag_entry_t * evt = &(al->event.events[al->event.event_cnt]); // Collect the complete set (1 to 6) of DL_Events of the current EventTrigger CC_ASSERT (al->event.event_cnt < 6); - memcpy (evt, &job->dl_event_ind.event, sizeof(diag_entry_t)); + memcpy (evt, &job->dl_event_ind.event, sizeof (diag_entry_t)); al->event.event_cnt++; if (job->dl_event_ind.eventsleft) @@ -754,23 +809,25 @@ static void al_dl_readparam_cnf_cb (iolink_job_t * job) iolink_al_port_t * al = iolink_get_al_ctx (job->port); al->service.data_read[al->service.data_len++] = job->dl_rw_cnf.val; - al->service.errinfo = job->dl_rw_cnf.stat; + al->service.errinfo = job->dl_rw_cnf.stat; iolink_al_od_event (job->port, AL_OD_EVENT_readparam_cnf); } static void al_dl_writeparam_cnf_cb (iolink_job_t * job) { - bool octets_left = false; + bool octets_left = false; iolink_fsm_al_od_event_t event = AL_OD_EVENT_writeparam_cnf; - iolink_al_port_t * al = iolink_get_al_ctx (job->port); + iolink_al_port_t * al = iolink_get_al_ctx (job->port); // TODO check job->dl_rw_cnf.stat; al->service.errinfo = job->dl_rw_cnf.stat; - if ((al->service.errinfo == IOLINK_STATUS_NO_ERROR) && - octets_left) // TODO increase write pointer + if ((al->service.errinfo == IOLINK_STATUS_NO_ERROR) && octets_left) // TODO + // increase + // write + // pointer { event = AL_OD_EVENT_rwparam; } @@ -780,10 +837,10 @@ static void al_dl_writeparam_cnf_cb (iolink_job_t * job) static void al_dl_isdu_transport_cnf_cb (iolink_job_t * job) { - iolink_port_t * port = job->port; + iolink_port_t * port = job->port; iolink_al_port_t * al = iolink_get_al_ctx (port); - al->service.errinfo = job->dl_rw_cnf.stat; + al->service.errinfo = job->dl_rw_cnf.stat; al->service.qualifier = job->dl_rw_cnf.qualifier; iolink_al_od_event (port, AL_OD_EVENT_isdutransport_cnf); } @@ -791,10 +848,10 @@ static void al_dl_isdu_transport_cnf_cb (iolink_job_t * job) static void al_abort_cb (iolink_job_t * job) { iolink_fsm_al_od_event_t event = AL_OD_EVENT_abort; - iolink_port_t * port = job->port; - iolink_al_port_t * al = iolink_get_al_ctx (port); + iolink_port_t * port = job->port; + iolink_al_port_t * al = iolink_get_al_ctx (port); - al->service.errinfo = IOLINK_STATUS_ISDU_ABORT; // TODO what to use here? + al->service.errinfo = IOLINK_STATUS_ISDU_ABORT; // TODO what to use here? al->service.data_len = 0; if (al->od_state == AL_OD_STATE_OnReq_Idle) @@ -820,45 +877,59 @@ void iolink_al_init (iolink_port_t * port) { iolink_al_port_t * al = iolink_get_al_ctx (port); - memset (al, 0, sizeof(iolink_al_port_t)); - al->mtx_pdin = os_mutex_create(); - al->od_state = AL_OD_STATE_OnReq_Idle; + memset (al, 0, sizeof (iolink_al_port_t)); + al->mtx_pdin = os_mutex_create(); + al->od_state = AL_OD_STATE_OnReq_Idle; al->event_state = AL_EVENT_STATE_Event_idle; } -iolink_error_t AL_Read_req (iolink_port_t * port, uint16_t index, - uint8_t subindex, - void (*al_read_cnf_cb)(iolink_port_t * port, - uint8_t len, const uint8_t * data, - iolink_smi_errortypes_t errortype)) +iolink_error_t AL_Read_req ( + iolink_port_t * port, + uint16_t index, + uint8_t subindex, + void (*al_read_cnf_cb) ( + iolink_port_t * port, + uint8_t len, + const uint8_t * data, + iolink_smi_errortypes_t errortype)) { - iolink_job_t * job = iolink_fetch_avail_job (port); - job->al_read_req.index = index; + iolink_job_t * job = iolink_fetch_avail_job (port); + job->al_read_req.index = index; job->al_read_req.subindex = subindex; CC_ASSERT (al_read_cnf_cb != NULL); job->al_read_req.al_read_cb = al_read_cnf_cb; - iolink_post_job_with_type_and_callback (port, job, IOLINK_JOB_AL_READ_REQ, al_read_write_cb); + iolink_post_job_with_type_and_callback ( + port, + job, + IOLINK_JOB_AL_READ_REQ, + al_read_write_cb); return IOLINK_ERROR_NONE; } /* Requirement: Changes to data is not allowed, until after al_Write_cnf_cb */ -iolink_error_t AL_Write_req (iolink_port_t * port, uint16_t index, - uint8_t subindex, uint8_t len, - const uint8_t * data, - void (*al_write_cnf_cb)(iolink_port_t * port, - iolink_smi_errortypes_t errortype)) +iolink_error_t AL_Write_req ( + iolink_port_t * port, + uint16_t index, + uint8_t subindex, + uint8_t len, + const uint8_t * data, + void (*al_write_cnf_cb) (iolink_port_t * port, iolink_smi_errortypes_t errortype)) { - iolink_job_t * job = iolink_fetch_avail_job (port); - job->al_write_req.index = index; + iolink_job_t * job = iolink_fetch_avail_job (port); + job->al_write_req.index = index; job->al_write_req.subindex = subindex; - job->al_write_req.length = len; - job->al_write_req.data = data; + job->al_write_req.length = len; + job->al_write_req.data = data; CC_ASSERT (al_write_cnf_cb != NULL); job->al_write_req.al_write_cb = al_write_cnf_cb; - iolink_post_job_with_type_and_callback (port, job, IOLINK_JOB_AL_WRITE_REQ, al_read_write_cb); + iolink_post_job_with_type_and_callback ( + port, + job, + IOLINK_JOB_AL_WRITE_REQ, + al_read_write_cb); return IOLINK_ERROR_NONE; } @@ -868,14 +939,12 @@ iolink_error_t AL_SetOutput_req (iolink_port_t * port, uint8_t * data) return DL_PDOutputUpdate_req (port, data); } -iolink_error_t AL_Control_req (iolink_port_t * port, - iolink_controlcode_t controlcode) +iolink_error_t AL_Control_req (iolink_port_t * port, iolink_controlcode_t controlcode) { return DL_Control_req (port, controlcode); } -iolink_error_t AL_GetInput_req (iolink_port_t * port, uint8_t * len, - uint8_t * data) +iolink_error_t AL_GetInput_req (iolink_port_t * port, uint8_t * len, uint8_t * data) { iolink_al_port_t * al = iolink_get_al_ctx (port); @@ -887,15 +956,17 @@ iolink_error_t AL_GetInput_req (iolink_port_t * port, uint8_t * len, return IOLINK_ERROR_NONE; } -iolink_error_t AL_GetInputOutput_req (iolink_port_t * port, uint8_t * len, - uint8_t * data) +iolink_error_t AL_GetInputOutput_req ( + iolink_port_t * port, + uint8_t * len, + uint8_t * data) { iolink_al_port_t * al = iolink_get_al_ctx (port); os_mutex_lock (al->mtx_pdin); /* PDIn data length */ uint8_t pdin_len = al->pdin_data_len; - data[0] = pdin_len; + data[0] = pdin_len; /* PDIn_data[0] */ uint8_t * pdin_data = &data[1]; memcpy (pdin_data, al->pdin_data, pdin_len); @@ -915,90 +986,127 @@ iolink_error_t AL_GetInputOutput_req (iolink_port_t * port, uint8_t * len, return error; } -void DL_Event_ind (iolink_port_t * port, uint16_t eventcode, - uint8_t event_qualifier, uint8_t eventsleft) +void DL_Event_ind ( + iolink_port_t * port, + uint16_t eventcode, + uint8_t event_qualifier, + uint8_t eventsleft) { - iolink_job_t * job = iolink_fetch_avail_job (port); - job->dl_event_ind.eventsleft = eventsleft; - job->dl_event_ind.event.event_code = eventcode; + iolink_job_t * job = iolink_fetch_avail_job (port); + job->dl_event_ind.eventsleft = eventsleft; + job->dl_event_ind.event.event_code = eventcode; job->dl_event_ind.event.event_qualifier = event_qualifier; - iolink_post_job_with_type_and_callback (port, job, IOLINK_JOB_DL_EVENT_IND, al_dl_event_ind_cb); + iolink_post_job_with_type_and_callback ( + port, + job, + IOLINK_JOB_DL_EVENT_IND, + al_dl_event_ind_cb); } void DL_Control_ind (iolink_port_t * port, iolink_controlcode_t controlcode) { // TODO check why this is called frequently - iolink_job_t * job = iolink_fetch_avail_job (port); + iolink_job_t * job = iolink_fetch_avail_job (port); job->dl_control_ind.controlcode = controlcode; - iolink_post_job_with_type_and_callback (port, job, IOLINK_JOB_DL_CONTROL_IND, dl_control_ind_cb); + iolink_post_job_with_type_and_callback ( + port, + job, + IOLINK_JOB_DL_CONTROL_IND, + dl_control_ind_cb); } -void DL_ReadParam_cnf (iolink_port_t * port, uint8_t value, - iolink_status_t errinfo) +void DL_ReadParam_cnf (iolink_port_t * port, uint8_t value, iolink_status_t errinfo) { - iolink_job_t * job = iolink_fetch_avail_job (port); - job->dl_rw_cnf.val = value; + iolink_job_t * job = iolink_fetch_avail_job (port); + job->dl_rw_cnf.val = value; job->dl_rw_cnf.stat = errinfo; - iolink_post_job_with_type_and_callback (port, job, IOLINK_JOB_DL_READPARAM_CNF, al_dl_readparam_cnf_cb); + iolink_post_job_with_type_and_callback ( + port, + job, + IOLINK_JOB_DL_READPARAM_CNF, + al_dl_readparam_cnf_cb); } void DL_WriteParam_cnf (iolink_port_t * port, iolink_status_t errinfo) { - iolink_job_t * job = iolink_fetch_avail_job (port); + iolink_job_t * job = iolink_fetch_avail_job (port); job->dl_rw_cnf.stat = errinfo; - iolink_post_job_with_type_and_callback (port, job, IOLINK_JOB_DL_WRITEPARAM_CNF, al_dl_writeparam_cnf_cb); + iolink_post_job_with_type_and_callback ( + port, + job, + IOLINK_JOB_DL_WRITEPARAM_CNF, + al_dl_writeparam_cnf_cb); } -void DL_ISDUTransport_cnf (iolink_port_t * port, uint8_t *data, uint8_t length, - iservice_t qualifier, iolink_status_t errinfo) +void DL_ISDUTransport_cnf ( + iolink_port_t * port, + uint8_t * data, + uint8_t length, + iservice_t qualifier, + iolink_status_t errinfo) { - iolink_job_t * job = iolink_fetch_avail_job (port); - job->dl_rw_cnf.stat = errinfo; + iolink_job_t * job = iolink_fetch_avail_job (port); + job->dl_rw_cnf.stat = errinfo; job->dl_rw_cnf.qualifier = qualifier; - iolink_al_port_t * al = iolink_get_al_ctx (port); + iolink_al_port_t * al = iolink_get_al_ctx (port); if (al->service.direction == IOLINK_RWDIRECTION_READ) { if (errinfo == IOLINK_STATUS_NO_ERROR) { - if ((data != NULL) && (length <= sizeof(al->service.data_read))) + if ((data != NULL) && (length <= sizeof (al->service.data_read))) { - // TODO can't we pass data_read pointer when we make the initial ISDUTransport_req call? + // TODO can't we pass data_read pointer when we make the initial + // ISDUTransport_req call? memcpy (al->service.data_read, data, length); al->service.data_len = length; } else { - LOG_ERROR (IOLINK_AL_LOG, - "%u: AL: %s, data = %p, length (%u) > %u\n", - iolink_get_portnumber (port), __func__, data, length, - (unsigned int)sizeof(al->service.data_read)); + LOG_ERROR ( + IOLINK_AL_LOG, + "%u: AL: %s, data = %p, length (%u) > %u\n", + iolink_get_portnumber (port), + __func__, + data, + length, + (unsigned int)sizeof (al->service.data_read)); } } } - else if ((al->service.direction == IOLINK_RWDIRECTION_WRITE) && - (qualifier == IOL_ISERVICE_DEVICE_WRITE_RESPONSE_NEG)) + else if ( + (al->service.direction == IOLINK_RWDIRECTION_WRITE) && + (qualifier == IOL_ISERVICE_DEVICE_WRITE_RESPONSE_NEG)) { - if (data && length <= sizeof(al->service.data_read)) + if (data && length <= sizeof (al->service.data_read)) { - // TODO can't we pass data_read pointer when we make the initial ISDUTransport_req call? + // TODO can't we pass data_read pointer when we make the initial + // ISDUTransport_req call? memcpy (al->service.data_read, data, length); al->service.data_len = length; } else { - LOG_ERROR (IOLINK_AL_LOG, - "%u: AL: %s, data = %p, length (%u) > %u\n", - iolink_get_portnumber (port), __func__, data, length, - (unsigned int)sizeof(al->service.data_read)); + LOG_ERROR ( + IOLINK_AL_LOG, + "%u: AL: %s, data = %p, length (%u) > %u\n", + iolink_get_portnumber (port), + __func__, + data, + length, + (unsigned int)sizeof (al->service.data_read)); } } - iolink_post_job_with_type_and_callback (port, job, IOLINK_JOB_DL_ISDU_TRANS_CNF, al_dl_isdu_transport_cnf_cb); + iolink_post_job_with_type_and_callback ( + port, + job, + IOLINK_JOB_DL_ISDU_TRANS_CNF, + al_dl_isdu_transport_cnf_cb); } void DL_PDInputTransport_ind (iolink_port_t * port, uint8_t * pdin_data, uint8_t length) @@ -1017,8 +1125,10 @@ void DL_PDInputTransport_ind (iolink_port_t * port, uint8_t * pdin_data, uint8_t #ifndef UNIT_TEST /* TODO move this to diagnosis unit? */ -__attribute__((weak)) void AL_Event_ind (iolink_port_t * port, uint8_t event_cnt, - diag_entry_t events[6]) +__attribute__ ((weak)) void AL_Event_ind ( + iolink_port_t * port, + uint8_t event_cnt, + diag_entry_t events[6]) { arg_block_devevent_t arg_block_devevent; uint8_t i; @@ -1037,19 +1147,21 @@ __attribute__((weak)) void AL_Event_ind (iolink_port_t * port, uint8_t event_cnt } } - memset (&arg_block_devevent, 0, sizeof(arg_block_devevent_t)); + memset (&arg_block_devevent, 0, sizeof (arg_block_devevent_t)); arg_block_devevent.arg_block_id = IOLINK_ARG_BLOCK_ID_DEV_EVENT; if (event_cnt > 6) { LOG_ERROR (IOLINK_AL_LOG, "event_cnt (%u) > 6\n", event_cnt); return; } - memcpy (arg_block_devevent.diag_entry, events, sizeof(diag_entry_t) * event_cnt); + memcpy (arg_block_devevent.diag_entry, events, sizeof (diag_entry_t) * event_cnt); arg_block_devevent.event_count = event_cnt; - iolink_smi_cnf (port, IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - sizeof(arg_block_devevent_t), - (arg_block_t *)&arg_block_devevent); + iolink_smi_cnf ( + port, + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + sizeof (arg_block_devevent_t), + (arg_block_t *)&arg_block_devevent); } #endif /* UNIT_TEST */ @@ -1058,7 +1170,11 @@ iolink_error_t AL_Abort (iolink_port_t * port) { iolink_job_t * job = iolink_fetch_avail_api_job (port); - iolink_post_job_with_type_and_callback (port, job, IOLINK_JOB_AL_ABORT, al_abort_cb); + iolink_post_job_with_type_and_callback ( + port, + job, + IOLINK_JOB_AL_ABORT, + al_abort_cb); return IOLINK_ERROR_NONE; } @@ -1067,7 +1183,11 @@ iolink_error_t AL_Event_rsp (iolink_port_t * port) { iolink_job_t * job = iolink_fetch_avail_job (port); - iolink_post_job_with_type_and_callback (port, job, IOLINK_JOB_AL_EVENT_RSP, al_event_rsp_cb); + iolink_post_job_with_type_and_callback ( + port, + job, + IOLINK_JOB_AL_EVENT_RSP, + al_event_rsp_cb); return IOLINK_ERROR_NONE; } @@ -1076,16 +1196,23 @@ iolink_error_t AL_Event_req (iolink_port_t * port /* TODO */) { iolink_job_t * job = iolink_fetch_avail_api_job (port); - iolink_post_job_with_type_and_callback (port, job, IOLINK_JOB_AL_EVENT_REQ, al_event_req_cb); + iolink_post_job_with_type_and_callback ( + port, + job, + IOLINK_JOB_AL_EVENT_REQ, + al_event_req_cb); return IOLINK_ERROR_NONE; } #ifdef UNIT_TEST -void iolink_post_job_with_type_and_callback(iolink_port_t * port, iolink_job_t * job, - iolink_job_type_t type, void (*callback)(struct iolink_job * job)) +void iolink_post_job_with_type_and_callback ( + iolink_port_t * port, + iolink_job_t * job, + iolink_job_type_t type, + void (*callback) (struct iolink_job * job)) { - job->type = type; + job->type = type; job->callback = callback; iolink_post_job (port, job); diff --git a/src/iolink_al.h b/src/iolink_al.h index 0f91e92..f651892 100644 --- a/src/iolink_al.h +++ b/src/iolink_al.h @@ -10,7 +10,6 @@ * See LICENSE file in the project root for full license information. ********************************************************************/ - #ifndef IOLINK_AL_H #define IOLINK_AL_H @@ -21,8 +20,7 @@ #include "osal.h" #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif typedef enum iolink_al_od_state @@ -64,11 +62,14 @@ typedef struct iolink_al_port iolink_job_t * job_req; union { - void (*al_read_cnf_cb)(iolink_port_t * port, uint8_t len, - const uint8_t * data, - iolink_smi_errortypes_t errortype); - void (*al_write_cnf_cb)(iolink_port_t * port, - iolink_smi_errortypes_t errortype); + void (*al_read_cnf_cb) ( + iolink_port_t * port, + uint8_t len, + const uint8_t * data, + iolink_smi_errortypes_t errortype); + void (*al_write_cnf_cb) ( + iolink_port_t * port, + iolink_smi_errortypes_t errortype); }; } service; @@ -118,45 +119,69 @@ typedef enum iolink_fsm_al_event_event AL_EVENT_EVENT_LAST } iolink_fsm_al_event_event_t; -iolink_error_t AL_Read_req (iolink_port_t * port, uint16_t index, - uint8_t subindex, - void (*al_read_cnf_cb)(iolink_port_t * port, - uint8_t len, const uint8_t * data, - iolink_smi_errortypes_t errortype)); -iolink_error_t AL_Write_req (iolink_port_t * port, uint16_t index, - uint8_t subindex, uint8_t len, - const uint8_t * data, - void (*al_write_cnf_cb)(iolink_port_t * port, - iolink_smi_errortypes_t errortype)); +iolink_error_t AL_Read_req ( + iolink_port_t * port, + uint16_t index, + uint8_t subindex, + void (*al_read_cnf_cb) ( + iolink_port_t * port, + uint8_t len, + const uint8_t * data, + iolink_smi_errortypes_t errortype)); +iolink_error_t AL_Write_req ( + iolink_port_t * port, + uint16_t index, + uint8_t subindex, + uint8_t len, + const uint8_t * data, + void (*al_write_cnf_cb) ( + iolink_port_t * port, + iolink_smi_errortypes_t errortype)); iolink_error_t AL_SetOutput_req (iolink_port_t * port, uint8_t * data); -iolink_error_t AL_Control_req (iolink_port_t * port, - iolink_controlcode_t controlcode); -iolink_error_t AL_GetInput_req (iolink_port_t * port, uint8_t * len, - uint8_t * data); -iolink_error_t AL_GetInputOutput_req (iolink_port_t * port, uint8_t * len, - uint8_t * data); -void DL_Event_ind (iolink_port_t * port, uint16_t eventcode, - uint8_t event_qualifier, uint8_t eventsleft); +iolink_error_t AL_Control_req ( + iolink_port_t * port, + iolink_controlcode_t controlcode); +iolink_error_t AL_GetInput_req (iolink_port_t * port, uint8_t * len, uint8_t * data); +iolink_error_t AL_GetInputOutput_req ( + iolink_port_t * port, + uint8_t * len, + uint8_t * data); +void DL_Event_ind ( + iolink_port_t * port, + uint16_t eventcode, + uint8_t event_qualifier, + uint8_t eventsleft); void DL_Control_ind (iolink_port_t * port, iolink_controlcode_t controlcode); -void DL_ReadParam_cnf (iolink_port_t * port, uint8_t value, - iolink_status_t errinfo); +void DL_ReadParam_cnf (iolink_port_t * port, uint8_t value, iolink_status_t errinfo); void DL_WriteParam_cnf (iolink_port_t * port, iolink_status_t errinfo); -void DL_ISDUTransport_cnf (iolink_port_t * port, uint8_t *data, uint8_t length, - iservice_t qualifier, iolink_status_t errinfo); -void DL_PDInputTransport_ind (iolink_port_t * port, uint8_t *inputdata, - uint8_t length); -void AL_Event_ind (iolink_port_t * port, uint8_t event_cnt, - diag_entry_t events[6]); // TODO where to put this? +void DL_ISDUTransport_cnf ( + iolink_port_t * port, + uint8_t * data, + uint8_t length, + iservice_t qualifier, + iolink_status_t errinfo); +void DL_PDInputTransport_ind ( + iolink_port_t * port, + uint8_t * inputdata, + uint8_t length); +void AL_Event_ind ( + iolink_port_t * port, + uint8_t event_cnt, + diag_entry_t events[6]); // TODO where to put this? iolink_error_t AL_Abort (iolink_port_t * port); iolink_error_t AL_Event_rsp (iolink_port_t * port); void iolink_al_init (iolink_port_t * port); #ifdef UNIT_TEST -// TODO: A more logical location for this function is in iolink_main, but for some +// TODO: A more logical location for this function is in iolink_main, but for +// some // unknown reason will some unit tests fail when placing it there?? -void iolink_post_job_with_type_and_callback(iolink_port_t * port, iolink_job_t * job, - iolink_job_type_t type, void (*callback)(struct iolink_job * job)); +void iolink_post_job_with_type_and_callback ( + iolink_port_t * port, + iolink_job_t * job, + iolink_job_type_t type, + void (*callback) (struct iolink_job * job)); #endif #ifdef __cplusplus @@ -164,4 +189,3 @@ void iolink_post_job_with_type_and_callback(iolink_port_t * port, iolink_job_t * #endif #endif /* IOLINK_AL_H */ - diff --git a/src/iolink_cm.c b/src/iolink_cm.c index 04e4ab3..ac810b6 100644 --- a/src/iolink_cm.c +++ b/src/iolink_cm.c @@ -11,27 +11,27 @@ ********************************************************************/ #ifdef UNIT_TEST -#define iolink_fetch_avail_job mock_iolink_fetch_avail_job +#define iolink_fetch_avail_job mock_iolink_fetch_avail_job #define iolink_fetch_avail_api_job mock_iolink_fetch_avail_api_job -#define iolink_post_job mock_iolink_post_job -#define SM_Operate mock_SM_Operate -#define SM_SetPortConfig_req mock_SM_SetPortConfig_req -#define DS_Delete mock_DS_Delete -#define DS_Startup mock_DS_Startup -#define OD_Start mock_OD_Start -#define OD_Stop mock_OD_Stop -#define PD_Start mock_PD_Start -#define PD_Stop mock_PD_Stop +#define iolink_post_job mock_iolink_post_job +#define SM_Operate mock_SM_Operate +#define SM_SetPortConfig_req mock_SM_SetPortConfig_req +#define DS_Delete mock_DS_Delete +#define DS_Startup mock_DS_Startup +#define OD_Start mock_OD_Start +#define OD_Stop mock_OD_Stop +#define PD_Start mock_PD_Start +#define PD_Stop mock_PD_Stop // TODO #define DU_Start mock_DU_Start // TODO #define DU_Stop mock_DU_Stop #endif /* UNIT_TEST */ #include "iolink_cm.h" -#include "iolink_ds.h" /* DS_Delete DS_Startup DS_Chk_Cfg DS_Init */ +#include "iolink_ds.h" /* DS_Delete DS_Startup DS_Chk_Cfg DS_Init */ #include "iolink_ode.h" /* OD_Start, OD_Stop */ #include "iolink_pde.h" /* PD_Start, PD_Stop */ -#include "iolink_sm.h" /* SM_Operate, SM_SetPortConfig_req */ +#include "iolink_sm.h" /* SM_Operate, SM_SetPortConfig_req */ #ifdef UNIT_TEST #include "iolink_al.h" #endif @@ -47,8 +47,7 @@ * */ -const char * iolink_cm_state_literals[] = -{ +const char * iolink_cm_state_literals[] = { "CheckPortMode", "SM_Startup", "DS_ParamManager", @@ -60,8 +59,7 @@ const char * iolink_cm_state_literals[] = "LAST", }; -const char * iolink_cm_event_literals[] = -{ +const char * iolink_cm_event_literals[] = { "NONE", "IOL_MANUAL", /* T1 */ "IOL_AUTOSTART", /* T2 */ @@ -85,8 +83,8 @@ typedef struct iolink_fsm_cm_transition { iolink_fsm_cm_event_t event; iolink_cm_state_t next_state; - iolink_fsm_cm_event_t (*action)(iolink_port_t * port, - iolink_fsm_cm_event_t event); + iolink_fsm_cm_event_t ( + *action) (iolink_port_t * port, iolink_fsm_cm_event_t event); } iolink_fsm_cm_transition_t; typedef struct iolink_fsm_cm_state_transitions @@ -102,8 +100,7 @@ typedef struct iolink_fsm_cm_state_transitions */ static void iolink_cm_event (iolink_port_t * port, iolink_fsm_cm_event_t event); -static iolink_sm_target_mode_t portmode_to_target_mode ( - iolink_portmode_t portmode) +static iolink_sm_target_mode_t portmode_to_target_mode (iolink_portmode_t portmode) { iolink_sm_target_mode_t target_mode = IOLINK_SMTARGET_MODE_INACTIVE; @@ -130,15 +127,16 @@ static iolink_sm_target_mode_t portmode_to_target_mode ( return target_mode; } -static void portconfiglist_to_parameterlist (const portconfiglist_t * cfg_list, - iolink_smp_parameterlist_t * paraml) +static void portconfiglist_to_parameterlist ( + const portconfiglist_t * cfg_list, + iolink_smp_parameterlist_t * paraml) { - memset (paraml, 0, sizeof(iolink_smp_parameterlist_t)); + memset (paraml, 0, sizeof (iolink_smp_parameterlist_t)); paraml->cycletime = cfg_list->port_cycle_time; - paraml->vendorid = cfg_list->vendorid; - paraml->deviceid = cfg_list->deviceid; - paraml->mode = portmode_to_target_mode (cfg_list->portmode); + paraml->vendorid = cfg_list->vendorid; + paraml->deviceid = cfg_list->deviceid; + paraml->mode = portmode_to_target_mode (cfg_list->portmode); switch (cfg_list->validation_backup) { @@ -147,22 +145,22 @@ static void portconfiglist_to_parameterlist (const portconfiglist_t * cfg_list, break; case IOLINK_VALIDATION_CHECK_V10: paraml->inspectionlevel = IOLINK_INSPECTIONLEVEL_IDENTICAL; - paraml->revisionid = IOL_DIR_PARAM_REV_V10; + paraml->revisionid = IOL_DIR_PARAM_REV_V10; break; case IOLINK_VALIDATION_CHECK_V11_BAK_RESTORE: case IOLINK_VALIDATION_CHECK_V11_RESTORE: case IOLINK_VALIDATION_CHECK_V11: paraml->inspectionlevel = IOLINK_INSPECTIONLEVEL_TYPE_COMP; - paraml->revisionid = IOL_DIR_PARAM_REV_V11; + paraml->revisionid = IOL_DIR_PARAM_REV_V11; break; default: CC_ASSERT (0); } } -static void set_port_config(iolink_port_t * port, bool ds_init) +static void set_port_config (iolink_port_t * port, bool ds_init) { - iolink_cm_port_t * cm = iolink_get_cm_ctx (port); + iolink_cm_port_t * cm = iolink_get_cm_ctx (port); portconfiglist_t * cfg_list = &cm->cfg_list; iolink_smp_parameterlist_t paraml; @@ -180,24 +178,25 @@ static void set_port_config(iolink_port_t * port, bool ds_init) SM_SetPortConfig_req (port, ¶ml); } -static iolink_fsm_cm_event_t cm_startup (iolink_port_t * port, - iolink_fsm_cm_event_t event) +static iolink_fsm_cm_event_t cm_startup ( + iolink_port_t * port, + iolink_fsm_cm_event_t event) { iolink_cm_port_t * cm = iolink_get_cm_ctx (port); - if (event == CM_EVENT_IOL_AUTOSTART || - !DS_Chk_Cfg (port, &cm->cfg_list)) /* CM_EVENT_IOL_MANUAL */ + if (event == CM_EVENT_IOL_AUTOSTART || !DS_Chk_Cfg (port, &cm->cfg_list)) /* CM_EVENT_IOL_MANUAL */ { DS_Delete (port); } - set_port_config(port, true); + set_port_config (port, true); return CM_EVENT_NONE; } -static iolink_fsm_cm_event_t cm_dido (iolink_port_t * port, - iolink_fsm_cm_event_t event) +static iolink_fsm_cm_event_t cm_dido ( + iolink_port_t * port, + iolink_fsm_cm_event_t event) { iolink_port_info_t * port_info = iolink_get_port_info (port); @@ -212,24 +211,25 @@ static iolink_fsm_cm_event_t cm_dido (iolink_port_t * port, DS_Delete (port); - port_info->revisionid = 0; + port_info->revisionid = 0; port_info->transmission_rate = 0; - port_info->vendorid = 0; - port_info->deviceid = 0; + port_info->vendorid = 0; + port_info->deviceid = 0; port_info->port_quality_info = IOLINK_PORT_QUALITY_INFO_INVALID; - set_port_config(port, true); + set_port_config (port, true); return CM_EVENT_NONE; } /* New port configuration or COMLOST */ -static iolink_fsm_cm_event_t cm_check_mode (iolink_port_t * port, - iolink_fsm_cm_event_t event) +static iolink_fsm_cm_event_t cm_check_mode ( + iolink_port_t * port, + iolink_fsm_cm_event_t event) { portconfiglist_t * cfg_list; iolink_fsm_cm_event_t res_event = CM_EVENT_NONE; - iolink_cm_port_t * cm = iolink_get_cm_ctx (port); + iolink_cm_port_t * cm = iolink_get_cm_ctx (port); if (event == CM_EVENT_CFG_CHANGE) { @@ -295,21 +295,24 @@ static iolink_fsm_cm_event_t cm_check_mode (iolink_port_t * port, if (event == CM_EVENT_CFG_CHANGE) { - iolink_cm_port_t * cm = iolink_get_cm_ctx (port); + iolink_cm_port_t * cm = iolink_get_cm_ctx (port); iolink_smi_service_req_t * smi_req = &cm->smi_req; iolink_arg_block_id_t ref_arg_block_id = - smi_req->arg_block->void_block.arg_block_id; + smi_req->arg_block->void_block.arg_block_id; if (res_event == CM_EVENT_UNKNOWN) { iolink_arg_block_id_t exp_arg_block_id = smi_req->exp_arg_block_id; - iolink_smi_joberror_ind (port, exp_arg_block_id, ref_arg_block_id, - IOLINK_SMI_ERRORTYPE_ARGBLOCK_INCONSISTENT); + iolink_smi_joberror_ind ( + port, + exp_arg_block_id, + ref_arg_block_id, + IOLINK_SMI_ERRORTYPE_ARGBLOCK_INCONSISTENT); } else { - memcpy (&cm->cfg_list, cfg_list, sizeof(portconfiglist_t)); + memcpy (&cm->cfg_list, cfg_list, sizeof (portconfiglist_t)); iolink_smi_voidblock_cnf (port, ref_arg_block_id); } } @@ -317,12 +320,13 @@ static iolink_fsm_cm_event_t cm_check_mode (iolink_port_t * port, return res_event; } -static inline void iolink_cm_do_smi_port_event (iolink_port_t * port, - iolink_eventcode_t eventcode) +static inline void iolink_cm_do_smi_port_event ( + iolink_port_t * port, + iolink_eventcode_t eventcode) { arg_block_portevent_t port_event; - memset (&port_event, 0, sizeof(arg_block_portevent_t)); + memset (&port_event, 0, sizeof (arg_block_portevent_t)); port_event.arg_block_id = IOLINK_ARG_BLOCK_ID_PORT_EVENT; port_event.event.event_qualifier |= IOLINK_EVENT_INSTANCE_APPLICATION; port_event.event.event_qualifier |= IOLINK_EVENT_SOURCE_MASTER << 3; @@ -332,12 +336,16 @@ static inline void iolink_cm_do_smi_port_event (iolink_port_t * port, port_event.event.event_code = eventcode; /* SMI_PortEvent_ind */ - iolink_smi_cnf (port, IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - sizeof(arg_block_portevent_t), (arg_block_t *)&port_event); + iolink_smi_cnf ( + port, + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + sizeof (arg_block_portevent_t), + (arg_block_t *)&port_event); } -static iolink_fsm_cm_event_t cm_comlost (iolink_port_t * port, - iolink_fsm_cm_event_t event) +static iolink_fsm_cm_event_t cm_comlost ( + iolink_port_t * port, + iolink_fsm_cm_event_t event) { iolink_port_info_t * port_info = iolink_get_port_info (port); @@ -348,8 +356,9 @@ static iolink_fsm_cm_event_t cm_comlost (iolink_port_t * port, return cm_check_mode (port, event); } -static iolink_fsm_cm_event_t cm_comlost_ignore (iolink_port_t * port, - iolink_fsm_cm_event_t event) +static iolink_fsm_cm_event_t cm_comlost_ignore ( + iolink_port_t * port, + iolink_fsm_cm_event_t event) { /* Ignore COMLOST when we are in state DS_ParamManager_2 * Let DS report the fault, then handle it as COMLOST @@ -358,8 +367,9 @@ static iolink_fsm_cm_event_t cm_comlost_ignore (iolink_port_t * port, return CM_EVENT_NONE; } -static iolink_fsm_cm_event_t cm_cfg_change_ignore (iolink_port_t * port, - iolink_fsm_cm_event_t event) +static iolink_fsm_cm_event_t cm_cfg_change_ignore ( + iolink_port_t * port, + iolink_fsm_cm_event_t event) { /* Ignore CFG_CHANGE when we are in state DS_ParamManager_2 * We cannot abort/stop @@ -368,37 +378,40 @@ static iolink_fsm_cm_event_t cm_cfg_change_ignore (iolink_port_t * port, return CM_EVENT_NONE; } -static iolink_fsm_cm_event_t cm_ds_change (iolink_port_t * port, - iolink_fsm_cm_event_t event) +static iolink_fsm_cm_event_t cm_ds_change ( + iolink_port_t * port, + iolink_fsm_cm_event_t event) { - set_port_config(port, false); + set_port_config (port, false); return CM_EVENT_NONE; } -static void init_port_info(iolink_port_t * port, - iolink_port_status_info_t port_status_info, - iolink_port_quality_info_t port_quality_info) +static void init_port_info ( + iolink_port_t * port, + iolink_port_status_info_t port_status_info, + iolink_port_quality_info_t port_quality_info) { iolink_port_info_t * port_info = iolink_get_port_info (port); - const iolink_smp_parameterlist_t * real_paramlist = iolink_get_paramlist (port); + const iolink_smp_parameterlist_t * real_paramlist = + iolink_get_paramlist (port); port_info->port_status_info = port_status_info; if (port_status_info != IOLINK_PORT_STATUS_INFO_DEACTIVATED) { - port_info->revisionid = real_paramlist->revisionid; + port_info->revisionid = real_paramlist->revisionid; port_info->transmission_rate = iolink_get_transmission_rate (port); - port_info->vendorid = real_paramlist->vendorid; - port_info->deviceid = real_paramlist->deviceid; + port_info->vendorid = real_paramlist->vendorid; + port_info->deviceid = real_paramlist->deviceid; } else { - port_info->revisionid = 0; + port_info->revisionid = 0; port_info->transmission_rate = IOLINK_TRANSMISSION_RATE_NOT_DETECTED; - port_info->vendorid = 0; - port_info->deviceid = 0; - port_info->cycletime = 0; + port_info->vendorid = 0; + port_info->deviceid = 0; + port_info->cycletime = 0; } port_info->port_quality_info = port_quality_info; @@ -409,27 +422,32 @@ static void init_port_info(iolink_port_t * port, } } -static iolink_fsm_cm_event_t cm_start_ds (iolink_port_t * port, - iolink_fsm_cm_event_t event) +static iolink_fsm_cm_event_t cm_start_ds ( + iolink_port_t * port, + iolink_fsm_cm_event_t event) { - init_port_info(port, IOLINK_PORT_STATUS_INFO_PREOP, - IOLINK_PORT_QUALITY_INFO_INVALID); + init_port_info ( + port, + IOLINK_PORT_STATUS_INFO_PREOP, + IOLINK_PORT_QUALITY_INFO_INVALID); DS_Startup (port); return CM_EVENT_NONE; } -static iolink_fsm_cm_event_t cm_ds_ready (iolink_port_t * port, - iolink_fsm_cm_event_t event) +static iolink_fsm_cm_event_t cm_ds_ready ( + iolink_port_t * port, + iolink_fsm_cm_event_t event) { SM_Operate (port); return CM_EVENT_NONE; } -static iolink_fsm_cm_event_t cm_ds_ready_ignore (iolink_port_t * port, - iolink_fsm_cm_event_t event) +static iolink_fsm_cm_event_t cm_ds_ready_ignore ( + iolink_port_t * port, + iolink_fsm_cm_event_t event) { /* Ignore DS_Ready when we are in state Port_Active_5, since this was * triggered by device DS_UPLOAD_REQ @@ -438,13 +456,13 @@ static iolink_fsm_cm_event_t cm_ds_ready_ignore (iolink_port_t * port, return CM_EVENT_NONE; } -static iolink_fsm_cm_event_t cm_sm_operate (iolink_port_t * port, - iolink_fsm_cm_event_t event) +static iolink_fsm_cm_event_t cm_sm_operate ( + iolink_port_t * port, + iolink_fsm_cm_event_t event) { // TODO Update parameter elements of PortStatusList // Port QualityINfo = x - init_port_info(port, IOLINK_PORT_STATUS_INFO_OP, - IOLINK_PORT_QUALITY_INFO_VALID); + init_port_info (port, IOLINK_PORT_STATUS_INFO_OP, IOLINK_PORT_QUALITY_INFO_VALID); OD_Start (port); PD_Start (port); @@ -456,8 +474,9 @@ static iolink_fsm_cm_event_t cm_sm_operate (iolink_port_t * port, return CM_EVENT_NONE; } -static iolink_fsm_cm_event_t cm_port_fault (iolink_port_t * port, - iolink_fsm_cm_event_t event) +static iolink_fsm_cm_event_t cm_port_fault ( + iolink_port_t * port, + iolink_fsm_cm_event_t event) { iolink_eventcode_t eventcode = IOLINK_EVENTCODE_NONE; @@ -471,20 +490,21 @@ static iolink_fsm_cm_event_t cm_port_fault (iolink_port_t * port, { return CM_EVENT_SM_COMLOST; } - else switch (cm->ds_fault) - { - case IOLINK_DS_FAULT_ID: - eventcode = IOLINK_EVENTCODE_BACKUP_INCON_ID; - break; - case IOLINK_DS_FAULT_SIZE: - eventcode = IOLINK_EVENTCODE_BACKUP_INCON_SIZE; - break; - case IOLINK_DS_FAULT_LOCK: - eventcode = IOLINK_EVENTCODE_BACKUP_INCON; - break; - default: - break; - } + else + switch (cm->ds_fault) + { + case IOLINK_DS_FAULT_ID: + eventcode = IOLINK_EVENTCODE_BACKUP_INCON_ID; + break; + case IOLINK_DS_FAULT_SIZE: + eventcode = IOLINK_EVENTCODE_BACKUP_INCON_SIZE; + break; + case IOLINK_DS_FAULT_LOCK: + eventcode = IOLINK_EVENTCODE_BACKUP_INCON; + break; + default: + break; + } // TODO DS storage failed. Rollback to previous parameter set break; } @@ -494,8 +514,10 @@ static iolink_fsm_cm_event_t cm_port_fault (iolink_port_t * port, CC_ASSERT (0); } - init_port_info(port, IOLINK_PORT_STATUS_INFO_PORT_DIAG, - IOLINK_PORT_QUALITY_INFO_INVALID); + init_port_info ( + port, + IOLINK_PORT_STATUS_INFO_PORT_DIAG, + IOLINK_PORT_QUALITY_INFO_INVALID); if (eventcode == IOLINK_EVENTCODE_NONE) { @@ -508,17 +530,20 @@ static iolink_fsm_cm_event_t cm_port_fault (iolink_port_t * port, return CM_EVENT_NONE; } -static iolink_fsm_cm_event_t cm_deactivate (iolink_port_t * port, - iolink_fsm_cm_event_t event) +static iolink_fsm_cm_event_t cm_deactivate ( + iolink_port_t * port, + iolink_fsm_cm_event_t event) { - iolink_cm_port_t * cm = iolink_get_cm_ctx (port); + iolink_cm_port_t * cm = iolink_get_cm_ctx (port); portconfiglist_t * cfg_list = &cm->cfg_list; iolink_smp_parameterlist_t paraml; - init_port_info(port, IOLINK_PORT_STATUS_INFO_DEACTIVATED, - IOLINK_PORT_QUALITY_INFO_INVALID); + init_port_info ( + port, + IOLINK_PORT_STATUS_INFO_DEACTIVATED, + IOLINK_PORT_QUALITY_INFO_INVALID); - memset (¶ml, 0, sizeof(iolink_smp_parameterlist_t)); + memset (¶ml, 0, sizeof (iolink_smp_parameterlist_t)); paraml.mode = portmode_to_target_mode (cfg_list->portmode); if (event == CM_EVENT_UNKNOWN) @@ -535,111 +560,102 @@ static iolink_fsm_cm_event_t cm_deactivate (iolink_port_t * port, } /* CM FSM state transitions, IO-Link Interface Spec v1.1.3 Chapter 11.3.2 */ -/* since we iterate through the list of events put the most likely in the top of the list. */ -static const iolink_fsm_cm_transition_t cm_trans_s0[] = -{ +/* since we iterate through the list of events put the most likely in the top of + * the list. */ +static const iolink_fsm_cm_transition_t cm_trans_s0[] = { /* CheckPortMode_0 */ - { CM_EVENT_IOL_MANUAL, CM_STATE_SM_Startup, cm_startup }, /* T1 */ - { CM_EVENT_IOL_AUTOSTART, CM_STATE_SM_Startup, cm_startup }, /* T2 */ - { CM_EVENT_DI_CQ, CM_STATE_Port_DIDO, cm_dido }, /* T9 */ - { CM_EVENT_DO_CQ, CM_STATE_Port_DIDO, cm_dido }, /* T10 */ - { CM_EVENT_DEACTIVATED, CM_STATE_Port_Deactivated, cm_deactivate }, /* T11 */ - { CM_EVENT_UNKNOWN, CM_STATE_Port_Deactivated, cm_deactivate }, /* T16 */ - - { CM_EVENT_CFG_CHANGE, CM_STATE_CheckPortMode, cm_check_mode }, /* Not in FSM */ - { CM_EVENT_SM_COMLOST, CM_STATE_CheckPortMode, cm_comlost }, /* Not in FSM */ + {CM_EVENT_IOL_MANUAL, CM_STATE_SM_Startup, cm_startup}, /* T1 */ + {CM_EVENT_IOL_AUTOSTART, CM_STATE_SM_Startup, cm_startup}, /* T2 */ + {CM_EVENT_DI_CQ, CM_STATE_Port_DIDO, cm_dido}, /* T9 */ + {CM_EVENT_DO_CQ, CM_STATE_Port_DIDO, cm_dido}, /* T10 */ + {CM_EVENT_DEACTIVATED, CM_STATE_Port_Deactivated, cm_deactivate}, /* T11 */ + {CM_EVENT_UNKNOWN, CM_STATE_Port_Deactivated, cm_deactivate}, /* T16 */ + + {CM_EVENT_CFG_CHANGE, CM_STATE_CheckPortMode, cm_check_mode}, /* Not in FSM + */ + {CM_EVENT_SM_COMLOST, CM_STATE_CheckPortMode, cm_comlost}, /* Not in FSM */ }; -static const iolink_fsm_cm_transition_t cm_trans_s1[] = -{ +static const iolink_fsm_cm_transition_t cm_trans_s1[] = { /* SM_Startup_1 */ - { CM_EVENT_SM_COMREADY, CM_STATE_DS_ParamManager, cm_start_ds }, /* T3 */ - { CM_EVENT_CFG_CHANGE, CM_STATE_CheckPortMode, cm_check_mode }, /* T13 */ - { CM_EVENT_SM_FAULT, CM_STATE_PortFault, cm_port_fault }, /* T4 */ - { CM_EVENT_SM_COMLOST, CM_STATE_CheckPortMode, cm_comlost }, /* T8 */ + {CM_EVENT_SM_COMREADY, CM_STATE_DS_ParamManager, cm_start_ds}, /* T3 */ + {CM_EVENT_CFG_CHANGE, CM_STATE_CheckPortMode, cm_check_mode}, /* T13 */ + {CM_EVENT_SM_FAULT, CM_STATE_PortFault, cm_port_fault}, /* T4 */ + {CM_EVENT_SM_COMLOST, CM_STATE_CheckPortMode, cm_comlost}, /* T8 */ }; -static const iolink_fsm_cm_transition_t cm_trans_s2[] = -{ +static const iolink_fsm_cm_transition_t cm_trans_s2[] = { /* DS_ParamManager_2 */ - { CM_EVENT_DS_Ready, CM_STATE_WaitingOnOperate, cm_ds_ready }, /* T5 */ - { CM_EVENT_DS_CHANGE, CM_STATE_SM_Startup, cm_ds_change }, /* T14 */ - { CM_EVENT_DS_Fault, CM_STATE_PortFault, cm_port_fault }, /* T6 */ - - { CM_EVENT_CFG_CHANGE, CM_STATE_DS_ParamManager, cm_cfg_change_ignore }, /* Not in spec */ - { CM_EVENT_SM_COMLOST, CM_STATE_DS_ParamManager, cm_comlost_ignore }, /* Not in spec */ + {CM_EVENT_DS_Ready, CM_STATE_WaitingOnOperate, cm_ds_ready}, /* T5 */ + {CM_EVENT_DS_CHANGE, CM_STATE_SM_Startup, cm_ds_change}, /* T14 */ + {CM_EVENT_DS_Fault, CM_STATE_PortFault, cm_port_fault}, /* T6 */ + + {CM_EVENT_CFG_CHANGE, CM_STATE_DS_ParamManager, cm_cfg_change_ignore}, /* Not + in + spec + */ + {CM_EVENT_SM_COMLOST, CM_STATE_DS_ParamManager, cm_comlost_ignore}, /* Not in + spec + */ }; -static const iolink_fsm_cm_transition_t cm_trans_s3[] = -{ +static const iolink_fsm_cm_transition_t cm_trans_s3[] = { /* PortFault_3 */ - { CM_EVENT_CFG_CHANGE, CM_STATE_CheckPortMode, cm_check_mode }, /* T13 */ - { CM_EVENT_DS_CHANGE, CM_STATE_SM_Startup, cm_ds_change }, /* T14 */ - { CM_EVENT_SM_COMLOST, CM_STATE_CheckPortMode, cm_comlost }, /* T8 */ + {CM_EVENT_CFG_CHANGE, CM_STATE_CheckPortMode, cm_check_mode}, /* T13 */ + {CM_EVENT_DS_CHANGE, CM_STATE_SM_Startup, cm_ds_change}, /* T14 */ + {CM_EVENT_SM_COMLOST, CM_STATE_CheckPortMode, cm_comlost}, /* T8 */ }; -static const iolink_fsm_cm_transition_t cm_trans_s4[] = -{ +static const iolink_fsm_cm_transition_t cm_trans_s4[] = { /* WaitingOnOperate_4 */ - { CM_EVENT_SM_OPERATE, CM_STATE_Port_Active, cm_sm_operate }, /* T7 */ - { CM_EVENT_CFG_CHANGE, CM_STATE_CheckPortMode, cm_check_mode }, /* T13 */ - { CM_EVENT_DS_CHANGE, CM_STATE_SM_Startup, cm_ds_change }, /* T14 */ - { CM_EVENT_SM_COMLOST, CM_STATE_CheckPortMode, cm_comlost }, /* T8 */ + {CM_EVENT_SM_OPERATE, CM_STATE_Port_Active, cm_sm_operate}, /* T7 */ + {CM_EVENT_CFG_CHANGE, CM_STATE_CheckPortMode, cm_check_mode}, /* T13 */ + {CM_EVENT_DS_CHANGE, CM_STATE_SM_Startup, cm_ds_change}, /* T14 */ + {CM_EVENT_SM_COMLOST, CM_STATE_CheckPortMode, cm_comlost}, /* T8 */ - { CM_EVENT_DS_Fault, CM_STATE_PortFault, cm_port_fault }, /* Not in spec. */ + {CM_EVENT_DS_Fault, CM_STATE_PortFault, cm_port_fault}, /* Not in spec. */ }; -static const iolink_fsm_cm_transition_t cm_trans_s5[] = -{ +static const iolink_fsm_cm_transition_t cm_trans_s5[] = { /* Port_Active_5 */ - { CM_EVENT_CFG_CHANGE, CM_STATE_CheckPortMode, cm_check_mode }, /* T13 */ - { CM_EVENT_DS_CHANGE, CM_STATE_SM_Startup, cm_ds_change }, /* T14 */ - { CM_EVENT_SM_COMLOST, CM_STATE_CheckPortMode, cm_comlost }, /* T8 */ + {CM_EVENT_CFG_CHANGE, CM_STATE_CheckPortMode, cm_check_mode}, /* T13 */ + {CM_EVENT_DS_CHANGE, CM_STATE_SM_Startup, cm_ds_change}, /* T14 */ + {CM_EVENT_SM_COMLOST, CM_STATE_CheckPortMode, cm_comlost}, /* T8 */ - { CM_EVENT_DS_Ready, CM_STATE_Port_Active, cm_ds_ready_ignore }, /* Not in spec */ - { CM_EVENT_DS_Fault, CM_STATE_PortFault, cm_port_fault }, /* Not in spec. */ + {CM_EVENT_DS_Ready, CM_STATE_Port_Active, cm_ds_ready_ignore}, /* Not in spec + */ + {CM_EVENT_DS_Fault, CM_STATE_PortFault, cm_port_fault}, /* Not in spec. */ }; -static const iolink_fsm_cm_transition_t cm_trans_s6[] = -{ +static const iolink_fsm_cm_transition_t cm_trans_s6[] = { /* Port_DIDO_6 */ - { CM_EVENT_CFG_CHANGE, CM_STATE_CheckPortMode, cm_check_mode }, /* T12 */ + {CM_EVENT_CFG_CHANGE, CM_STATE_CheckPortMode, cm_check_mode}, /* T12 */ }; -static const iolink_fsm_cm_transition_t cm_trans_s7[] = -{ +static const iolink_fsm_cm_transition_t cm_trans_s7[] = { /* Port_Deactivated_8 */ - { CM_EVENT_CFG_CHANGE, CM_STATE_CheckPortMode, cm_check_mode }, /* T15 */ + {CM_EVENT_CFG_CHANGE, CM_STATE_CheckPortMode, cm_check_mode}, /* T15 */ }; /* The index is the state in this array */ -static const iolink_fsm_cm_state_transitions_t iolink_cm_fsm[] = -{ - { /* CheckPortMode_0 */ - .number_of_trans = NELEMENTS (cm_trans_s0), - .transitions = cm_trans_s0 - }, - { /* SM_Startup_1 */ - .number_of_trans = NELEMENTS (cm_trans_s1), - .transitions = cm_trans_s1 - }, - { /* DS_ParamManager_2 */ - .number_of_trans = NELEMENTS (cm_trans_s2), - .transitions = cm_trans_s2 - }, - { /* PortFault_3 */ - .number_of_trans = NELEMENTS (cm_trans_s3), - .transitions = cm_trans_s3 - }, - { /* WaitingOnOperate_4 */ - .number_of_trans = NELEMENTS (cm_trans_s4), - .transitions = cm_trans_s4 - }, - { /* Port_Active_5 */ - .number_of_trans = NELEMENTS (cm_trans_s5), - .transitions = cm_trans_s5 - }, - { /* Port_DIDO_6 */ - .number_of_trans = NELEMENTS (cm_trans_s6), - .transitions = cm_trans_s6 - }, - { /* Port_Deactivated_8 */ - .number_of_trans = NELEMENTS (cm_trans_s7), - .transitions = cm_trans_s7 - }, +static const iolink_fsm_cm_state_transitions_t iolink_cm_fsm[] = { + {/* CheckPortMode_0 */ + .number_of_trans = NELEMENTS (cm_trans_s0), + .transitions = cm_trans_s0}, + {/* SM_Startup_1 */ + .number_of_trans = NELEMENTS (cm_trans_s1), + .transitions = cm_trans_s1}, + {/* DS_ParamManager_2 */ + .number_of_trans = NELEMENTS (cm_trans_s2), + .transitions = cm_trans_s2}, + {/* PortFault_3 */ + .number_of_trans = NELEMENTS (cm_trans_s3), + .transitions = cm_trans_s3}, + {/* WaitingOnOperate_4 */ + .number_of_trans = NELEMENTS (cm_trans_s4), + .transitions = cm_trans_s4}, + {/* Port_Active_5 */ + .number_of_trans = NELEMENTS (cm_trans_s5), + .transitions = cm_trans_s5}, + {/* Port_DIDO_6 */ + .number_of_trans = NELEMENTS (cm_trans_s6), + .transitions = cm_trans_s6}, + {/* Port_Deactivated_8 */ + .number_of_trans = NELEMENTS (cm_trans_s7), + .transitions = cm_trans_s7}, }; static void iolink_cm_event (iolink_port_t * port, iolink_fsm_cm_event_t event) @@ -647,8 +663,8 @@ static void iolink_cm_event (iolink_port_t * port, iolink_fsm_cm_event_t event) do { int i; - iolink_cm_port_t * cm = iolink_get_cm_ctx (port); - iolink_cm_state_t previous = cm->state; + iolink_cm_port_t * cm = iolink_get_cm_ctx (port); + iolink_cm_state_t previous = cm->state; const iolink_fsm_cm_transition_t * next_trans = NULL; for (i = 0; i < iolink_cm_fsm[previous].number_of_trans; i++) @@ -664,18 +680,24 @@ static void iolink_cm_event (iolink_port_t * port, iolink_fsm_cm_event_t event) } if (!next_trans) { - LOG_ERROR (IOLINK_CM_LOG, "CM (%u): next_trans == NULL: state %s - event %s\n", - iolink_get_portnumber (port), - iolink_cm_state_literals[previous], - iolink_cm_event_literals[event]); + LOG_ERROR ( + IOLINK_CM_LOG, + "CM (%u): next_trans == NULL: state %s - event %s\n", + iolink_get_portnumber (port), + iolink_cm_state_literals[previous], + iolink_cm_event_literals[event]); return; } /* Transition to next state */ cm->state = next_trans->next_state; - LOG_DEBUG (IOLINK_CM_LOG, "CM (%u): event: %s, state transition: %s -> %s\n", - iolink_get_portnumber (port), iolink_cm_event_literals[event], - iolink_cm_state_literals[previous], iolink_cm_state_literals[cm->state]); + LOG_DEBUG ( + IOLINK_CM_LOG, + "CM (%u): event: %s, state transition: %s -> %s\n", + iolink_get_portnumber (port), + iolink_cm_event_literals[event], + iolink_cm_state_literals[previous], + iolink_cm_state_literals[cm->state]); event = next_trans->action (port, event); } while (event != CM_EVENT_NONE); } @@ -684,7 +706,7 @@ static void iolink_cm_event (iolink_port_t * port, iolink_fsm_cm_event_t event) static void cm_sm_port_mode_ind_cb (iolink_job_t * job) { iolink_fsm_cm_event_t res_event = CM_EVENT_NONE; - iolink_port_t * port = job->port; + iolink_port_t * port = job->port; switch (job->sm_port_mode_ind.mode) { @@ -708,18 +730,17 @@ static void cm_sm_port_mode_ind_cb (iolink_job_t * job) res_event = CM_EVENT_SM_COMLOST; break; case IOLINK_SM_PORTMODE_INACTIVE: - { - iolink_port_info_t * port_info = iolink_get_port_info (port); + { + iolink_port_info_t * port_info = iolink_get_port_info (port); - if (port_info->port_status_info != IOLINK_PORT_STATUS_INFO_DEACTIVATED) - { - port_info->port_status_info = IOLINK_PORT_STATUS_INFO_DEACTIVATED; - /* SMI_PortEvent_ind */ - iolink_cm_do_smi_port_event (port, - IOLINK_EVENTCODE_PORT_STATUS_CHANGE); - } + if (port_info->port_status_info != IOLINK_PORT_STATUS_INFO_DEACTIVATED) + { + port_info->port_status_info = IOLINK_PORT_STATUS_INFO_DEACTIVATED; + /* SMI_PortEvent_ind */ + iolink_cm_do_smi_port_event (port, IOLINK_EVENTCODE_PORT_STATUS_CHANGE); } - break; + } + break; case IOLINK_SM_PORTMODE_DI: case IOLINK_SM_PORTMODE_DO: break; @@ -749,27 +770,36 @@ static void cm_ds_fault_cb (iolink_job_t * job) iolink_cm_event (job->port, CM_EVENT_DS_Fault); } -static bool check_arg_block(iolink_job_t * job, - iolink_arg_block_id_t cmp_ref_arg_block_id, uint16_t arg_block_len, - iolink_arg_block_id_t cmp_exp_arg_block_id, iolink_smi_errortypes_t errortype) +static bool check_arg_block ( + iolink_job_t * job, + iolink_arg_block_id_t cmp_ref_arg_block_id, + uint16_t arg_block_len, + iolink_arg_block_id_t cmp_exp_arg_block_id, + iolink_smi_errortypes_t errortype) { - iolink_port_t * port = job->port; + iolink_port_t * port = job->port; iolink_smi_service_req_t * job_smi_req = &job->smi_req; iolink_arg_block_id_t exp_arg_block_id = job_smi_req->exp_arg_block_id; iolink_arg_block_id_t ref_arg_block_id = - job_smi_req->arg_block->void_block.arg_block_id; + job_smi_req->arg_block->void_block.arg_block_id; if (ref_arg_block_id != cmp_ref_arg_block_id) { - iolink_smi_joberror_ind (port, exp_arg_block_id, ref_arg_block_id, - IOLINK_SMI_ERRORTYPE_ARGBLOCK_NOT_SUPPORTED); + iolink_smi_joberror_ind ( + port, + exp_arg_block_id, + ref_arg_block_id, + IOLINK_SMI_ERRORTYPE_ARGBLOCK_NOT_SUPPORTED); return false; } else if (job_smi_req->arg_block_len != arg_block_len) { - iolink_smi_joberror_ind (port, exp_arg_block_id, ref_arg_block_id, - IOLINK_SMI_ERRORTYPE_ARGBLOCK_LENGTH_INVALID); + iolink_smi_joberror_ind ( + port, + exp_arg_block_id, + ref_arg_block_id, + IOLINK_SMI_ERRORTYPE_ARGBLOCK_LENGTH_INVALID); return false; } @@ -777,8 +807,11 @@ static bool check_arg_block(iolink_job_t * job, { if (errortype != IOLINK_SMI_ERRORTYPE_NONE) { - iolink_smi_joberror_ind (port, exp_arg_block_id, ref_arg_block_id, - errortype); + iolink_smi_joberror_ind ( + port, + exp_arg_block_id, + ref_arg_block_id, + errortype); } else { @@ -793,28 +826,32 @@ static bool check_arg_block(iolink_job_t * job, static void cm_smi_masterident_cb (iolink_job_t * job) { - iolink_port_t * port = job->port; + iolink_port_t * port = job->port; iolink_smi_service_req_t * job_smi_req = &job->smi_req; iolink_arg_block_id_t ref_arg_block_id = - job_smi_req->arg_block->void_block.arg_block_id; - - if (check_arg_block(job, IOLINK_ARG_BLOCK_ID_VOID_BLOCK, sizeof(arg_block_void_t), - IOLINK_ARG_BLOCK_ID_MASTERIDENT, IOLINK_SMI_ERRORTYPE_NONE)) + job_smi_req->arg_block->void_block.arg_block_id; + + if (check_arg_block ( + job, + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + sizeof (arg_block_void_t), + IOLINK_ARG_BLOCK_ID_MASTERIDENT, + IOLINK_SMI_ERRORTYPE_NONE)) { arg_block_masterident_t master_ident; int i; uint8_t max_number_of_ports = iolink_get_port_cnt (port); - uint8_t arg_block_len = sizeof(arg_block_masterident_head_t) + - sizeof(iolink_port_types_t) * max_number_of_ports; + uint8_t arg_block_len = sizeof (arg_block_masterident_head_t) + + sizeof (iolink_port_types_t) * max_number_of_ports; - memset (&master_ident, 0, sizeof(arg_block_masterident_t)); + memset (&master_ident, 0, sizeof (arg_block_masterident_t)); - master_ident.h.arg_block_id = IOLINK_ARG_BLOCK_ID_MASTERIDENT; - master_ident.h.vendorid = 1171; // TODO - master_ident.h.masterid = 123; // TODO - master_ident.h.master_type = IOLINK_MASTER_TYPE_MASTER_ACC; - master_ident.h.features_1 = 0; - master_ident.h.features_2 = 0; + master_ident.h.arg_block_id = IOLINK_ARG_BLOCK_ID_MASTERIDENT; + master_ident.h.vendorid = 1171; // TODO + master_ident.h.masterid = 123; // TODO + master_ident.h.master_type = IOLINK_MASTER_TYPE_MASTER_ACC; + master_ident.h.features_1 = 0; + master_ident.h.features_2 = 0; master_ident.h.max_number_of_ports = max_number_of_ports; for (i = 0; i < max_number_of_ports; i++) @@ -822,29 +859,34 @@ static void cm_smi_masterident_cb (iolink_job_t * job) master_ident.port_types[i] = IOLINK_PORT_TYPES_A; // TODO correct? } - iolink_smi_cnf (port, ref_arg_block_id, arg_block_len, - (arg_block_t *)&master_ident); + iolink_smi_cnf ( + port, + ref_arg_block_id, + arg_block_len, + (arg_block_t *)&master_ident); } } static void cm_smi_portconfiguration_cb (iolink_job_t * job) { - iolink_port_t * port = job->port; + iolink_port_t * port = job->port; iolink_smi_service_req_t * job_smi_req = &job->smi_req; iolink_arg_block_id_t exp_arg_block_id = job_smi_req->exp_arg_block_id; - if (check_arg_block(job, IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST, - sizeof(arg_block_portconfiglist_t), - IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - IOLINK_SMI_ERRORTYPE_ARGBLOCK_INCONSISTENT)) + if (check_arg_block ( + job, + IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST, + sizeof (arg_block_portconfiglist_t), + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + IOLINK_SMI_ERRORTYPE_ARGBLOCK_INCONSISTENT)) { - iolink_cm_port_t * cm = iolink_get_cm_ctx (port); + iolink_cm_port_t * cm = iolink_get_cm_ctx (port); iolink_smi_service_req_t * smi_req = &cm->smi_req; - smi_req->result = IOLINK_SMI_ERRORTYPE_NONE; + smi_req->result = IOLINK_SMI_ERRORTYPE_NONE; smi_req->exp_arg_block_id = exp_arg_block_id; - smi_req->arg_block_len = job_smi_req->arg_block_len; - smi_req->arg_block = job_smi_req->arg_block; + smi_req->arg_block_len = job_smi_req->arg_block_len; + smi_req->arg_block = job_smi_req->arg_block; iolink_cm_event (port, CM_EVENT_CFG_CHANGE); } @@ -852,67 +894,82 @@ static void cm_smi_portconfiguration_cb (iolink_job_t * job) static void cm_smi_readbackportconfiguration_cb (iolink_job_t * job) { - iolink_port_t * port = job->port; + iolink_port_t * port = job->port; iolink_smi_service_req_t * job_smi_req = &job->smi_req; iolink_arg_block_id_t ref_arg_block_id = - job_smi_req->arg_block->void_block.arg_block_id; - - if (check_arg_block(job, IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - sizeof(arg_block_void_t), IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST, - IOLINK_SMI_ERRORTYPE_ARGBLOCK_INCONSISTENT)) + job_smi_req->arg_block->void_block.arg_block_id; + + if (check_arg_block ( + job, + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + sizeof (arg_block_void_t), + IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST, + IOLINK_SMI_ERRORTYPE_ARGBLOCK_INCONSISTENT)) { iolink_cm_port_t * cm = iolink_get_cm_ctx (port); arg_block_portconfiglist_t arg_block_portcfg; - memset (&arg_block_portcfg, 0, sizeof(arg_block_portconfiglist_t)); - memcpy (&arg_block_portcfg.configlist, &cm->cfg_list, - sizeof(portconfiglist_t)); + memset (&arg_block_portcfg, 0, sizeof (arg_block_portconfiglist_t)); + memcpy ( + &arg_block_portcfg.configlist, + &cm->cfg_list, + sizeof (portconfiglist_t)); arg_block_portcfg.arg_block_id = IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST; - iolink_smi_cnf (port, ref_arg_block_id, - sizeof(arg_block_portconfiglist_t), - (arg_block_t *)&arg_block_portcfg); + iolink_smi_cnf ( + port, + ref_arg_block_id, + sizeof (arg_block_portconfiglist_t), + (arg_block_t *)&arg_block_portcfg); } } static void cm_smi_portstatus_cb (iolink_job_t * job) { - iolink_port_t * port = job->port; + iolink_port_t * port = job->port; iolink_smi_service_req_t * job_smi_req = &job->smi_req; iolink_arg_block_id_t ref_arg_block_id = - job_smi_req->arg_block->void_block.arg_block_id; - - if (check_arg_block(job, IOLINK_ARG_BLOCK_ID_VOID_BLOCK, sizeof(arg_block_void_t), - IOLINK_ARG_BLOCK_ID_PORT_STATUS_LIST, IOLINK_SMI_ERRORTYPE_NONE)) + job_smi_req->arg_block->void_block.arg_block_id; + + if (check_arg_block ( + job, + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + sizeof (arg_block_void_t), + IOLINK_ARG_BLOCK_ID_PORT_STATUS_LIST, + IOLINK_SMI_ERRORTYPE_NONE)) { arg_block_portstatuslist_t port_status; iolink_port_info_t * port_info = iolink_get_port_info (port); - memset (&port_status, 0, sizeof(arg_block_portstatuslist_t)); - port_status.arg_block_id = IOLINK_ARG_BLOCK_ID_PORT_STATUS_LIST; - port_status.port_status_info = port_info->port_status_info; + memset (&port_status, 0, sizeof (arg_block_portstatuslist_t)); + port_status.arg_block_id = IOLINK_ARG_BLOCK_ID_PORT_STATUS_LIST; + port_status.port_status_info = port_info->port_status_info; port_status.transmission_rate = port_info->transmission_rate; - port_status.vendorid = port_info->vendorid; - port_status.deviceid = port_info->deviceid; - port_status.revision_id = port_info->revisionid; + port_status.vendorid = port_info->vendorid; + port_status.deviceid = port_info->deviceid; + port_status.revision_id = port_info->revisionid; // TODO how to handle master_cycle_time?! - if (port_status.port_status_info == IOLINK_PORT_STATUS_INFO_NO_DEV || - port_status.port_status_info == IOLINK_PORT_STATUS_INFO_DEACTIVATED || - port_status.port_status_info == IOLINK_PORT_STATUS_INFO_DI || - port_status.port_status_info == IOLINK_PORT_STATUS_INFO_DO) - port_status.master_cycle_time = 0; + if ( + port_status.port_status_info == IOLINK_PORT_STATUS_INFO_NO_DEV || + port_status.port_status_info == IOLINK_PORT_STATUS_INFO_DEACTIVATED || + port_status.port_status_info == IOLINK_PORT_STATUS_INFO_DI || + port_status.port_status_info == IOLINK_PORT_STATUS_INFO_DO) + port_status.master_cycle_time = 0; else - port_status.master_cycle_time = port_info->cycletime; + port_status.master_cycle_time = port_info->cycletime; port_status.port_quality_info = port_info->port_quality_info; - // TODO for each diag entry .. number_of_diags++ and append to diag_entries + // TODO for each diag entry .. number_of_diags++ and append to + // diag_entries port_status.number_of_diags = 0; - iolink_smi_cnf (port, ref_arg_block_id, - sizeof(arg_block_portstatuslist_t), - (arg_block_t *)&port_status); + iolink_smi_cnf ( + port, + ref_arg_block_id, + sizeof (arg_block_portstatuslist_t), + (arg_block_t *)&port_status); } } @@ -921,8 +978,10 @@ void iolink_cm_init (iolink_port_t * port) { iolink_cm_port_t * cm = iolink_get_cm_ctx (port); - init_port_info(port, IOLINK_PORT_STATUS_INFO_DEACTIVATED, - IOLINK_PORT_QUALITY_INFO_INVALID); + init_port_info ( + port, + IOLINK_PORT_STATUS_INFO_DEACTIVATED, + IOLINK_PORT_QUALITY_INFO_INVALID); cm->ds_fault = IOLINK_DS_FAULT_NONE; @@ -935,21 +994,33 @@ void SM_PortMode_ind (iolink_port_t * port, iolink_sm_portmode_t mode) job->sm_port_mode_ind.mode = mode; - iolink_post_job_with_type_and_callback (port, job, IOLINK_JOB_SM_PORT_MODE_IND, cm_sm_port_mode_ind_cb); + iolink_post_job_with_type_and_callback ( + port, + job, + IOLINK_JOB_SM_PORT_MODE_IND, + cm_sm_port_mode_ind_cb); } void DS_Ready (iolink_port_t * port) { iolink_job_t * job = iolink_fetch_avail_job (port); - iolink_post_job_with_type_and_callback (port, job, IOLINK_JOB_DS_READY, cm_ds_ready_cb); + iolink_post_job_with_type_and_callback ( + port, + job, + IOLINK_JOB_DS_READY, + cm_ds_ready_cb); } void DS_Change (iolink_port_t * port) { iolink_job_t * job = iolink_fetch_avail_job (port); - iolink_post_job_with_type_and_callback (port, job, IOLINK_JOB_DS_CHANGE, cm_ds_change_cb); + iolink_post_job_with_type_and_callback ( + port, + job, + IOLINK_JOB_DS_CHANGE, + cm_ds_change_cb); } void DS_Fault (iolink_port_t * port, iolink_ds_fault_t fault) @@ -958,55 +1029,87 @@ void DS_Fault (iolink_port_t * port, iolink_ds_fault_t fault) job->ds_fault.fault = fault; - iolink_post_job_with_type_and_callback (port, job, IOLINK_JOB_DS_FAULT, cm_ds_fault_cb); + iolink_post_job_with_type_and_callback ( + port, + job, + IOLINK_JOB_DS_FAULT, + cm_ds_fault_cb); } -static iolink_error_t init_and_post_job(iolink_port_t * port, iolink_job_type_t type, - void (*callback)(struct iolink_job * job), iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, arg_block_t * arg_block) +static iolink_error_t init_and_post_job ( + iolink_port_t * port, + iolink_job_type_t type, + void (*callback) (struct iolink_job * job), + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block) { - iolink_job_t * job = iolink_fetch_avail_api_job (port); + iolink_job_t * job = iolink_fetch_avail_api_job (port); job->smi_req.exp_arg_block_id = exp_arg_block_id; - job->smi_req.arg_block_len = arg_block_len; - job->smi_req.arg_block = arg_block; + job->smi_req.arg_block_len = arg_block_len; + job->smi_req.arg_block = arg_block; iolink_post_job_with_type_and_callback (port, job, type, callback); return IOLINK_ERROR_NONE; } -iolink_error_t cm_SMI_MasterIdentification_req (iolink_port_t * port, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, - arg_block_t * arg_block) +iolink_error_t cm_SMI_MasterIdentification_req ( + iolink_port_t * port, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block) { - return init_and_post_job(port, IOLINK_JOB_SMI_MASTERIDENT, - cm_smi_masterident_cb, exp_arg_block_id, arg_block_len, arg_block); + return init_and_post_job ( + port, + IOLINK_JOB_SMI_MASTERIDENT, + cm_smi_masterident_cb, + exp_arg_block_id, + arg_block_len, + arg_block); } -iolink_error_t cm_SMI_PortConfiguration_req (iolink_port_t * port, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, - arg_block_t * arg_block) +iolink_error_t cm_SMI_PortConfiguration_req ( + iolink_port_t * port, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block) { - return init_and_post_job(port, IOLINK_JOB_SMI_PORTCONFIGURATION, - cm_smi_portconfiguration_cb, exp_arg_block_id, arg_block_len, arg_block); + return init_and_post_job ( + port, + IOLINK_JOB_SMI_PORTCONFIGURATION, + cm_smi_portconfiguration_cb, + exp_arg_block_id, + arg_block_len, + arg_block); } -iolink_error_t cm_SMI_ReadbackPortConfiguration_req (iolink_port_t * port, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, - arg_block_t * arg_block) +iolink_error_t cm_SMI_ReadbackPortConfiguration_req ( + iolink_port_t * port, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block) { - return init_and_post_job(port, IOLINK_JOB_SMI_READBACKPORTCONFIGURATION, - cm_smi_readbackportconfiguration_cb, exp_arg_block_id, arg_block_len, arg_block); + return init_and_post_job ( + port, + IOLINK_JOB_SMI_READBACKPORTCONFIGURATION, + cm_smi_readbackportconfiguration_cb, + exp_arg_block_id, + arg_block_len, + arg_block); } -iolink_error_t cm_SMI_PortStatus_req (iolink_port_t * port, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, - arg_block_t * arg_block) +iolink_error_t cm_SMI_PortStatus_req ( + iolink_port_t * port, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block) { - return init_and_post_job(port, IOLINK_JOB_SMI_PORTSTATUS, - cm_smi_portstatus_cb, exp_arg_block_id, arg_block_len, arg_block); + return init_and_post_job ( + port, + IOLINK_JOB_SMI_PORTSTATUS, + cm_smi_portstatus_cb, + exp_arg_block_id, + arg_block_len, + arg_block); } diff --git a/src/iolink_cm.h b/src/iolink_cm.h index 51602c7..ee33ed5 100644 --- a/src/iolink_cm.h +++ b/src/iolink_cm.h @@ -17,8 +17,7 @@ #include "iolink_main.h" #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif /** @@ -53,21 +52,23 @@ typedef struct iolink_cm_port typedef enum iolink_fsm_cm_event { CM_EVENT_NONE, - CM_EVENT_IOL_MANUAL, /* T1 */ - CM_EVENT_IOL_AUTOSTART, /* T2 */ - CM_EVENT_SM_COMREADY, /* T3 */ - CM_EVENT_SM_FAULT, /* T4 */ - CM_EVENT_DS_Ready, /* T5 */ - CM_EVENT_DS_Fault, /* T6 */ - CM_EVENT_SM_OPERATE, /* T7 */ - CM_EVENT_SM_COMLOST, /* T8 */ - CM_EVENT_DI_CQ, /* T9 */ // TODO merge - CM_EVENT_DO_CQ, /* T10 */ // TODO merge + CM_EVENT_IOL_MANUAL, /* T1 */ + CM_EVENT_IOL_AUTOSTART, /* T2 */ + CM_EVENT_SM_COMREADY, /* T3 */ + CM_EVENT_SM_FAULT, /* T4 */ + CM_EVENT_DS_Ready, /* T5 */ + CM_EVENT_DS_Fault, /* T6 */ + CM_EVENT_SM_OPERATE, /* T7 */ + CM_EVENT_SM_COMLOST, /* T8 */ + CM_EVENT_DI_CQ, + /* T9 */ // TODO merge + CM_EVENT_DO_CQ, + /* T10 */ // TODO merge CM_EVENT_DEACTIVATED, /* T11 */ CM_EVENT_CFG_CHANGE, /* T12, T13 and T15 */ CM_EVENT_DS_CHANGE, /* T14 */ CM_EVENT_UNKNOWN, /* T16 */ - CM_EVENT_SM_COMLOST_DS, /* T8 */ + CM_EVENT_SM_COMLOST_DS, /* T8 */ CM_EVENT_LAST } iolink_fsm_cm_event_t; @@ -79,25 +80,29 @@ void DS_Ready (iolink_port_t * port); void DS_Change (iolink_port_t * port); void DS_Fault (iolink_port_t * port, iolink_ds_fault_t fault); -iolink_error_t cm_SMI_MasterIdentification_req (iolink_port_t * port, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, - arg_block_t * arg_block); +iolink_error_t cm_SMI_MasterIdentification_req ( + iolink_port_t * port, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block); -iolink_error_t cm_SMI_PortConfiguration_req (iolink_port_t * port, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, - arg_block_t * arg_block); +iolink_error_t cm_SMI_PortConfiguration_req ( + iolink_port_t * port, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block); -iolink_error_t cm_SMI_ReadbackPortConfiguration_req (iolink_port_t * port, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, - arg_block_t * arg_block); +iolink_error_t cm_SMI_ReadbackPortConfiguration_req ( + iolink_port_t * port, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block); -iolink_error_t cm_SMI_PortStatus_req (iolink_port_t * port, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, - arg_block_t * arg_block); +iolink_error_t cm_SMI_PortStatus_req ( + iolink_port_t * port, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block); #ifdef __cplusplus } diff --git a/src/iolink_dl.c b/src/iolink_dl.c index 3937a95..70e362c 100644 --- a/src/iolink_dl.c +++ b/src/iolink_dl.c @@ -30,12 +30,12 @@ #include "osal.h" #include /* memset */ -#include /* snprintf */ +#include /* snprintf */ #include -//TODO: Events in preop -//TODO: ISDU Timer -//TODO: Test doing a command while fetching an event +// TODO: Events in preop +// TODO: ISDU Timer +// TODO: Test doing a command while fetching an event /** * @file @@ -43,19 +43,18 @@ * */ -#define T_BIT_COM1_NS 208330 -#define T_BIT_COM2_NS 26040 -#define T_BIT_COM3_NS 4340 -#define IOLINK_ISDU_RESPONSE_TIME (5000 * 1000) +#define T_BIT_COM1_NS 208330 +#define T_BIT_COM2_NS 26040 +#define T_BIT_COM3_NS 4340 +#define IOLINK_ISDU_RESPONSE_TIME (5000 * 1000) #define IOLINK_MAX_RETRY 2 -#define IOLINK_DL_THREAD_NAME_LENGTH 12 +#define IOLINK_DL_THREAD_NAME_LENGTH 12 static char dl_thread_names[IOLINK_NUM_PORTS][IOLINK_DL_THREAD_NAME_LENGTH]; -static const char * iolink_dl_mh_st_literals[] = -{ +static const char * iolink_dl_mh_st_literals[] = { "INACTIVE_0", "AW_REPLY_1", "STARTUP_2", @@ -78,35 +77,57 @@ static const char * iolink_dl_mh_st_literals[] = static void iolink_dl_pd_h_sm (iolink_port_t * port); static void iolink_dl_isdu_h_sm (iolink_port_t * port); -static void iolink_dl_cmd_h_sm(iolink_port_t * port); +static void iolink_dl_cmd_h_sm (iolink_port_t * port); static void iolink_dl_ev_h_sm (iolink_port_t * port); static void iolink_dl_od_h_sm (iolink_port_t * port); -static iolink_error_t OD_req(iolink_dl_t *dl, iolink_rwdirection_t rwdirection, - iolink_comchannel_t comchannel, uint8_t addressctrl, - uint8_t length, uint8_t *data); -static iolink_error_t PD_req(iolink_dl_t *dl, uint8_t pdinaddress, uint8_t pdinlength, - uint8_t *pdout, uint8_t pdoutaddress, uint8_t pdoutlength); -static iolink_error_t OD_cnf(iolink_dl_t *dl, uint8_t *data, uint8_t length, iolink_status_t errorinfo); -static iolink_error_t PDInStatus_ind (iolink_port_t * port, iolink_controlcode_t status); -static iolink_error_t EventFlag_ind(iolink_dl_t *dl, bool eventflag); -static iolink_error_t MHInfo_ind(iolink_dl_t *dl, iolink_mhinfo_t mhinfo); - -static inline uint32_t get_T_initcyc(iolink_dl_t *dl) +static iolink_error_t OD_req ( + iolink_dl_t * dl, + iolink_rwdirection_t rwdirection, + iolink_comchannel_t comchannel, + uint8_t addressctrl, + uint8_t length, + uint8_t * data); +static iolink_error_t PD_req ( + iolink_dl_t * dl, + uint8_t pdinaddress, + uint8_t pdinlength, + uint8_t * pdout, + uint8_t pdoutaddress, + uint8_t pdoutlength); +static iolink_error_t OD_cnf ( + iolink_dl_t * dl, + uint8_t * data, + uint8_t length, + iolink_status_t errorinfo); +static iolink_error_t PDInStatus_ind ( + iolink_port_t * port, + iolink_controlcode_t status); +static iolink_error_t EventFlag_ind (iolink_dl_t * dl, bool eventflag); +static iolink_error_t MHInfo_ind (iolink_dl_t * dl, iolink_mhinfo_t mhinfo); + +static inline uint32_t get_T_initcyc (iolink_dl_t * dl) { uint32_t us = 0; switch (dl->baudrate) { - case IOLINK_BAUDRATE_COM1: us = 100 * T_BIT_COM1_NS; break; - case IOLINK_BAUDRATE_COM2: us = 100 * T_BIT_COM2_NS; break; - case IOLINK_BAUDRATE_COM3: us = 100 * T_BIT_COM3_NS; break; - default: break; + case IOLINK_BAUDRATE_COM1: + us = 100 * T_BIT_COM1_NS; + break; + case IOLINK_BAUDRATE_COM2: + us = 100 * T_BIT_COM2_NS; + break; + case IOLINK_BAUDRATE_COM3: + us = 100 * T_BIT_COM3_NS; + break; + default: + break; } return (us / 1000) + 1; } -static inline uint8_t calcCHKPDU(uint8_t *data, uint8_t length) +static inline uint8_t calcCHKPDU (uint8_t * data, uint8_t length) { uint8_t idx, chksum = 0; @@ -114,7 +135,7 @@ static inline uint8_t calcCHKPDU(uint8_t *data, uint8_t length) { chksum = data[0]; - for (idx = 1; idx < length; idx ++) + for (idx = 1; idx < length; idx++) { chksum ^= data[idx]; } @@ -123,35 +144,37 @@ static inline uint8_t calcCHKPDU(uint8_t *data, uint8_t length) return chksum; } -static inline iolink_controlcode_t getCKSPDIn(iolink_dl_t *dl) +static inline iolink_controlcode_t getCKSPDIn (iolink_dl_t * dl) { - return ((dl->message_handler.cks & BIT(6)) != 0) ? - IOLINK_CONTROLCODE_INVALID : IOLINK_CONTROLCODE_VALID; + return ((dl->message_handler.cks & BIT (6)) != 0) ? IOLINK_CONTROLCODE_INVALID + : IOLINK_CONTROLCODE_VALID; } -static inline bool getCKSEvFlag(iolink_dl_t *dl) +static inline bool getCKSEvFlag (iolink_dl_t * dl) { - return ((dl->message_handler.cks & BIT(7)) != 0); + return ((dl->message_handler.cks & BIT (7)) != 0); } -static inline bool valid_isdu_checksum(iolink_dl_t *dl) +static inline bool valid_isdu_checksum (iolink_dl_t * dl) { - return (calcCHKPDU(dl->isdu_handler.isdu_data, dl->isdu_handler.total_isdu_len) == 0); + return ( + calcCHKPDU (dl->isdu_handler.isdu_data, dl->isdu_handler.total_isdu_len) == + 0); } -static inline iservice_t get_isdu_iserv(iolink_dl_t *dl) +static inline iservice_t get_isdu_iserv (iolink_dl_t * dl) { return ((dl->isdu_handler.isdu_data[0] >> 4) & 0x0F); } -static inline uint8_t get_isdu_len(iolink_dl_t *dl) +static inline uint8_t get_isdu_len (iolink_dl_t * dl) { return (dl->isdu_handler.isdu_data[0] & 0x0F); } -static inline bool get_isdu_total_len(iolink_dl_t *dl, uint8_t *isdu_total_len) +static inline bool get_isdu_total_len (iolink_dl_t * dl, uint8_t * isdu_total_len) { - uint8_t len = get_isdu_len(dl); + uint8_t len = get_isdu_len (dl); if (len == 1) { @@ -168,17 +191,17 @@ static inline bool get_isdu_total_len(iolink_dl_t *dl, uint8_t *isdu_total_len) return true; } -static inline bool get_isdu_data_length(iolink_dl_t *dl, uint8_t *isdu_data_length) +static inline bool get_isdu_data_length (iolink_dl_t * dl, uint8_t * isdu_data_length) { uint8_t ohlen = 2; uint8_t isdu_tot_len; - if (!get_isdu_total_len(dl, &isdu_tot_len)) + if (!get_isdu_total_len (dl, &isdu_tot_len)) { return false; } - if (get_isdu_len(dl) == 1) + if (get_isdu_len (dl) == 1) { ohlen = 3; } @@ -188,40 +211,43 @@ static inline bool get_isdu_data_length(iolink_dl_t *dl, uint8_t *isdu_data_leng return true; } -static inline uint8_t *get_isdu_response_data(iolink_dl_t *dl) +static inline uint8_t * get_isdu_response_data (iolink_dl_t * dl) { - uint8_t offset = (get_isdu_len(dl) == 1) ? 2 : 1; + uint8_t offset = (get_isdu_len (dl) == 1) ? 2 : 1; return &dl->isdu_handler.isdu_data[offset]; } -static inline uint8_t get_isdu_total_segments(iolink_dl_t *dl) +static inline uint8_t get_isdu_total_segments (iolink_dl_t * dl) { - return (dl->isdu_handler.total_isdu_len + dl->message_handler.od_len - 1) / dl->message_handler.od_len; + return (dl->isdu_handler.total_isdu_len + dl->message_handler.od_len - 1) / + dl->message_handler.od_len; } -static inline bool valid_isdu_header(iolink_dl_t *dl) +static inline bool valid_isdu_header (iolink_dl_t * dl) { - iservice_t iserv = get_isdu_iserv(dl); - uint8_t len = get_isdu_len(dl); - bool result = false; + iservice_t iserv = get_isdu_iserv (dl); + uint8_t len = get_isdu_len (dl); + bool result = false; if (iserv == IOL_ISERVICE_DEVICE_NO_SERVICE) { result = (len > 1) ? false : true; } - else if ((iserv == IOL_ISERVICE_DEVICE_WRITE_RESPONSE_NEG) || - (iserv == IOL_ISERVICE_DEVICE_WRITE_RESPONSE_POS) || - (iserv == IOL_ISERVICE_DEVICE_READ_RESPONSE_NEG) || - (iserv == IOL_ISERVICE_DEVICE_READ_RESPONSE_POS)) - { - if (((len == 0) || (len > 15)) || - (dl->isdu_handler.data_dir_read && - ((iserv == IOL_ISERVICE_DEVICE_WRITE_RESPONSE_NEG) || - (iserv == IOL_ISERVICE_DEVICE_WRITE_RESPONSE_POS))) || - (!dl->isdu_handler.data_dir_read && - ((iserv == IOL_ISERVICE_DEVICE_READ_RESPONSE_NEG) || - (iserv == IOL_ISERVICE_DEVICE_READ_RESPONSE_POS)))) + else if ( + (iserv == IOL_ISERVICE_DEVICE_WRITE_RESPONSE_NEG) || + (iserv == IOL_ISERVICE_DEVICE_WRITE_RESPONSE_POS) || + (iserv == IOL_ISERVICE_DEVICE_READ_RESPONSE_NEG) || + (iserv == IOL_ISERVICE_DEVICE_READ_RESPONSE_POS)) + { + if ( + ((len == 0) || (len > 15)) || + (dl->isdu_handler.data_dir_read && + ((iserv == IOL_ISERVICE_DEVICE_WRITE_RESPONSE_NEG) || + (iserv == IOL_ISERVICE_DEVICE_WRITE_RESPONSE_POS))) || + (!dl->isdu_handler.data_dir_read && + ((iserv == IOL_ISERVICE_DEVICE_READ_RESPONSE_NEG) || + (iserv == IOL_ISERVICE_DEVICE_READ_RESPONSE_POS)))) { result = false; } @@ -234,31 +260,35 @@ static inline bool valid_isdu_header(iolink_dl_t *dl) return result; } -static inline void start_timer_initcyc(iolink_dl_t *dl) +static inline void start_timer_initcyc (iolink_dl_t * dl) { - uint32_t timer_val = get_T_initcyc(dl); - os_timer_stop(dl->timer); + uint32_t timer_val = get_T_initcyc (dl); + os_timer_stop (dl->timer); #ifdef __rtk__ if (timer_val < 1000) { // For COM3 will get_T_initcyc return 435, this is divided by 1000 -> 0 - LOG_DEBUG(IOLINK_DL_LOG, "%s: get_T_initcyc() < 1000 (%d)\n", __func__, (int)timer_val); + LOG_DEBUG ( + IOLINK_DL_LOG, + "%s: get_T_initcyc() < 1000 (%d)\n", + __func__, + (int)timer_val); timer_val = 1000; } #endif - os_timer_set(dl->timer, timer_val); + os_timer_set (dl->timer, timer_val); dl->timer_elapsed = false; - os_timer_start(dl->timer); + os_timer_start (dl->timer); dl->timer_type = IOL_DL_TIMER_TINITCYC_MH; } -static inline void isdu_timer_reset(iolink_dl_t *dl) +static inline void isdu_timer_reset (iolink_dl_t * dl) { dl->isdu_handler.isdu_timer = 0; } -static inline void isdu_timer_start(iolink_dl_t *dl) +static inline void isdu_timer_start (iolink_dl_t * dl) { dl->isdu_handler.isdu_timer = os_get_current_time_us(); @@ -269,19 +299,21 @@ static inline void isdu_timer_start(iolink_dl_t *dl) } } -static inline bool isdu_timer_elapsed(iolink_dl_t *dl) +static inline bool isdu_timer_elapsed (iolink_dl_t * dl) { - return (((os_get_current_time_us() - dl->isdu_handler.isdu_timer) > IOLINK_ISDU_RESPONSE_TIME) && - (dl->isdu_handler.isdu_timer != 0)); + return ( + ((os_get_current_time_us() - dl->isdu_handler.isdu_timer) > + IOLINK_ISDU_RESPONSE_TIME) && + (dl->isdu_handler.isdu_timer != 0)); } -static inline void interleave_reset_od_sizes(iolink_dl_t *dl) +static inline void interleave_reset_od_sizes (iolink_dl_t * dl) { dl->od_handler.od_rxlen = 0; dl->od_handler.od_txlen = 0; } -static inline void set_mseq_change(iolink_dl_t *dl) +static inline void set_mseq_change (iolink_dl_t * dl) { if (dl->message_handler.interleave != IOL_DL_INTERLEAVE_NONE) { @@ -301,25 +333,27 @@ static inline void set_mseq_change(iolink_dl_t *dl) { dl->pd_handler.pd_txlen = dl->message_handler.pd_txlen; dl->pd_handler.pd_rxlen = dl->message_handler.pd_rxlen; - dl->od_handler.odout_buffer = dl->pd_handler.pdout_buffer + dl->pd_handler.pd_txlen; + dl->od_handler.odout_buffer = + dl->pd_handler.pdout_buffer + dl->pd_handler.pd_txlen; } - if ((dl->message_handler.interleave != IOL_DL_INTERLEAVE_NONE) && - (dl->pd_handler.pd_rxlen == 0)) + if ( + (dl->message_handler.interleave != IOL_DL_INTERLEAVE_NONE) && + (dl->pd_handler.pd_rxlen == 0)) { // Start in pdout interleave, since no rx process data. dl->pd_handler.state = IOL_DL_PDH_ST_PDOUTINTERLEAVE_3; } - memset(dl->txbuffer, 0, IOLINK_RXTX_BUFFER_SIZE); + memset (dl->txbuffer, 0, IOLINK_RXTX_BUFFER_SIZE); } -static inline void CH_Conf(iolink_port_t * port, CHCmd_t cmd) +static inline void CH_Conf (iolink_port_t * port, CHCmd_t cmd) { iolink_dl_t * dl = iolink_get_dl_ctx (port); dl->cmd_handler.chcmd = cmd; - iolink_dl_cmd_h_sm(port); + iolink_dl_cmd_h_sm (port); } static inline void OH_Conf (iolink_port_t * port, OHCmd_t cmd) @@ -336,8 +370,9 @@ static inline void PH_Conf (iolink_port_t * port, PHCmd_t cmd) dl->pd_handler.phcmd = cmd; - dl->message_handler.interleave = - (cmd == IOL_PHCMD_INTERLEAVE) ? IOL_DL_INTERLEAVE_PD : IOL_DL_INTERLEAVE_NONE; + dl->message_handler.interleave = (cmd == IOL_PHCMD_INTERLEAVE) + ? IOL_DL_INTERLEAVE_PD + : IOL_DL_INTERLEAVE_NONE; iolink_dl_pd_h_sm (port); } @@ -358,7 +393,7 @@ static inline void EH_Conf (iolink_port_t * port, EHCmd_t cmd) iolink_dl_ev_h_sm (port); } -static inline void MH_Conf(iolink_dl_t *dl, MHCmd_t cmd) +static inline void MH_Conf (iolink_dl_t * dl, MHCmd_t cmd) { dl->message_handler.mhcmd = cmd; } @@ -376,41 +411,42 @@ static inline void iolink_dl_mode_h_sm_goto_operate (iolink_port_t * port) PH_Conf (port, IOL_PHCMD_INTERLEAVE); } - MH_Conf(dl, IOL_MHCMD_OPERATE); + MH_Conf (dl, IOL_MHCMD_OPERATE); DL_Mode_ind (port, IOLINK_MHMODE_OPERATE); - os_event_set(dl->event, IOLINK_DL_EVENT_MH); + os_event_set (dl->event, IOLINK_DL_EVENT_MH); dl->mode_handler.state = IOL_DL_MDH_ST_OPERATE_4; } -static void set_OH_IH_EH_Conf_active(iolink_port_t * port, bool active) +static void set_OH_IH_EH_Conf_active (iolink_port_t * port, bool active) { OH_Conf (port, (active) ? IOL_OHCMD_ACTIVE : IOL_OHCMD_INACTIVE); IH_Conf (port, (active) ? IOL_IHCMD_ACTIVE : IOL_IHCMD_INACTIVE); EH_Conf (port, (active) ? IOL_EHCMD_ACTIVE : IOL_EHCMD_INACTIVE); } -static inline void iolink_dl_mode_h_sm_goto_idle (iolink_port_t * port, - iolink_mhmode_t mode) +static inline void iolink_dl_mode_h_sm_goto_idle ( + iolink_port_t * port, + iolink_mhmode_t mode) { iolink_dl_t * dl = iolink_get_dl_ctx (port); - set_OH_IH_EH_Conf_active(port, false); - CH_Conf(port, IOL_CHCMD_INACTIVE); - MH_Conf(dl, IOL_MHCMD_INACTIVE); + set_OH_IH_EH_Conf_active (port, false); + CH_Conf (port, IOL_CHCMD_INACTIVE); + MH_Conf (dl, IOL_MHCMD_INACTIVE); DL_Mode_ind (port, mode); - os_event_set(dl->event, IOLINK_DL_EVENT_MH); + os_event_set (dl->event, IOLINK_DL_EVENT_MH); dl->mode_handler.mhinfo = IOLINK_MHINFO_NONE; - dl->mode_handler.state = IOL_DL_MDH_ST_IDLE_0; + dl->mode_handler.state = IOL_DL_MDH_ST_IDLE_0; } static inline void iolink_dl_mode_h_sm_goto_startup (iolink_port_t * port) { iolink_dl_t * dl = iolink_get_dl_ctx (port); - set_OH_IH_EH_Conf_active(port, false); - MH_Conf(dl, IOL_MHCMD_STARTUP); + set_OH_IH_EH_Conf_active (port, false); + MH_Conf (dl, IOL_MHCMD_STARTUP); DL_Mode_ind (port, IOLINK_MHMODE_STARTUP); - os_event_set(dl->event, IOLINK_DL_EVENT_MH); + os_event_set (dl->event, IOLINK_DL_EVENT_MH); dl->mode_handler.state = IOL_DL_MDH_ST_STARTUP_2; } @@ -432,15 +468,21 @@ static void iolink_dl_mode_h_sm (iolink_port_t * port) else { // TODO FIXME: handle this! - LOG_WARNING (IOLINK_DL_LOG, "%s (%u): Already waiting for init on the other port\n", - __func__, iolink_get_portnumber (port)); + LOG_WARNING ( + IOLINK_DL_LOG, + "%s (%u): Already waiting for init on the other port\n", + __func__, + iolink_get_portnumber (port)); } #endif } else if (dl->mode_handler.dl_mode != IOLINK_DLMODE_INACTIVE) { - LOG_WARNING(IOLINK_DL_LOG, "%s: IDLE_0: Unknown event triggered. Port %d\n", - __func__, iolink_get_portnumber (port)); + LOG_WARNING ( + IOLINK_DL_LOG, + "%s: IDLE_0: Unknown event triggered. Port %d\n", + __func__, + iolink_get_portnumber (port)); } break; case IOL_DL_MDH_ST_ESTCOM_1: @@ -452,18 +494,19 @@ static void iolink_dl_mode_h_sm (iolink_port_t * port) // TODO: Get ID from device if (dl->mode_handler.dl_mode == IOLINK_DLMODE_PREOPERATE) // T3 { - set_OH_IH_EH_Conf_active(port, true); - MH_Conf(dl, IOL_MHCMD_PREOPERATE); + set_OH_IH_EH_Conf_active (port, true); + MH_Conf (dl, IOL_MHCMD_PREOPERATE); DL_Mode_ind (port, IOLINK_MHMODE_PREOPERATE); - os_event_set(dl->event, IOLINK_DL_EVENT_MH); + os_event_set (dl->event, IOLINK_DL_EVENT_MH); dl->mode_handler.state = IOL_DL_MDH_ST_PREOPERATE_3; } else if (dl->mode_handler.dl_mode == IOLINK_DLMODE_OPERATE) // T5 { - set_OH_IH_EH_Conf_active(port, true); + set_OH_IH_EH_Conf_active (port, true); iolink_dl_mode_h_sm_goto_operate (port); } - else if (dl->mode_handler.dl_mode == IOLINK_DLMODE_INACTIVE) // Not in spec. + else if (dl->mode_handler.dl_mode == IOLINK_DLMODE_INACTIVE) // Not in + // spec. { iolink_dl_mode_h_sm_goto_idle (port, IOLINK_MHMODE_INACTIVE); } @@ -473,65 +516,78 @@ static void iolink_dl_mode_h_sm (iolink_port_t * port) } else { - LOG_WARNING(IOLINK_DL_LOG, "%s: STARTUP_2: Unknown event triggered. Port %d\n", - __func__, iolink_get_portnumber (port)); + LOG_WARNING ( + IOLINK_DL_LOG, + "%s: STARTUP_2: Unknown event triggered. Port %d\n", + __func__, + iolink_get_portnumber (port)); } break; case IOL_DL_MDH_ST_PREOPERATE_3: if (dl->mode_handler.dl_mode == IOLINK_DLMODE_STARTUP) // T6 { - CH_Conf(port, IOL_CHCMD_INACTIVE); - iolink_dl_mode_h_sm_goto_startup(port); + CH_Conf (port, IOL_CHCMD_INACTIVE); + iolink_dl_mode_h_sm_goto_startup (port); } - else if (dl->mode_handler.dl_mode == IOLINK_DLMODE_INACTIVE) // SDCI_TC_0214 + else if (dl->mode_handler.dl_mode == IOLINK_DLMODE_INACTIVE) // SDCI_TC_0214 { - MH_Conf(dl, IOL_MHCMD_OPERATE); - os_event_set(dl->event, IOLINK_DL_EVENT_MH); + MH_Conf (dl, IOL_MHCMD_OPERATE); + os_event_set (dl->event, IOLINK_DL_EVENT_MH); } else if (dl->mode_handler.mhinfo == IOLINK_MHINFO_COMLOST) // T9 { iolink_dl_mode_h_sm_goto_idle (port, IOLINK_MHMODE_COMLOST); } - else if (dl->mode_handler.dl_mode == IOLINK_DLMODE_OPERATE) // T10 { + else if (dl->mode_handler.dl_mode == IOLINK_DLMODE_OPERATE) // T10 { { iolink_dl_mode_h_sm_goto_operate (port); } else { - LOG_WARNING(IOLINK_DL_LOG, "%s: PREOPERATE_3: Unknown event triggered. Port %d\n", - __func__, iolink_get_portnumber (port)); + LOG_WARNING ( + IOLINK_DL_LOG, + "%s: PREOPERATE_3: Unknown event triggered. Port %d\n", + __func__, + iolink_get_portnumber (port)); } break; case IOL_DL_MDH_ST_OPERATE_4: if (dl->mode_handler.dl_mode == IOLINK_DLMODE_STARTUP) // T12 { PH_Conf (port, IOL_PHCMD_INACTIVE); - iolink_dl_mode_h_sm_goto_startup(port); + iolink_dl_mode_h_sm_goto_startup (port); } - else if ((dl->mode_handler.dl_mode == IOLINK_DLMODE_INACTIVE) || // T13 - (dl->mode_handler.mhinfo == IOLINK_MHINFO_COMLOST)) // T14 + else if ( + (dl->mode_handler.dl_mode == IOLINK_DLMODE_INACTIVE) || // T13 + (dl->mode_handler.mhinfo == IOLINK_MHINFO_COMLOST)) // T14 { PH_Conf (port, IOL_PHCMD_INACTIVE); - iolink_dl_mode_h_sm_goto_idle (port, (dl->mode_handler.dl_mode == IOLINK_DLMODE_INACTIVE) ? - IOLINK_MHMODE_INACTIVE : IOLINK_MHMODE_COMLOST); + iolink_dl_mode_h_sm_goto_idle ( + port, + (dl->mode_handler.dl_mode == IOLINK_DLMODE_INACTIVE) + ? IOLINK_MHMODE_INACTIVE + : IOLINK_MHMODE_COMLOST); } else if (dl->mode_handler.dl_mode != IOLINK_DLMODE_OPERATE) { - LOG_WARNING(IOLINK_DL_LOG, "%s: OPERATE_4: Unknown event triggered. Port %d\n", - __func__, iolink_get_portnumber (port)); + LOG_WARNING ( + IOLINK_DL_LOG, + "%s: OPERATE_4: Unknown event triggered. Port %d\n", + __func__, + iolink_get_portnumber (port)); } break; } } -static void write_master_command(iolink_port_t * port, iolink_status_t errorinfo) +static void write_master_command (iolink_port_t * port, iolink_status_t errorinfo) { iolink_dl_t * dl = iolink_get_dl_ctx (port); - os_mutex_lock(dl->mtx); - uint8_t master_command = dl->cmd_handler.master_command; + os_mutex_lock (dl->mtx); + uint8_t master_command = dl->cmd_handler.master_command; dl->cmd_handler.master_command = 0; - os_mutex_unlock(dl->mtx); + os_mutex_unlock (dl->mtx); switch (master_command) { @@ -539,32 +595,36 @@ static void write_master_command(iolink_port_t * port, iolink_status_t errorinfo case IOL_MASTERCMD_DEVICE_OPERATE: case IOL_MASTERCMD_DEVICE_PREOP: case IOL_MASTERCMD_FALLBACK: - DL_Write_Devicemode_cnf (port, errorinfo, - master_command); /* Not in spec. */ + DL_Write_Devicemode_cnf (port, errorinfo, master_command); /* Not in spec. + */ break; default: break; } } -static void iolink_dl_mh_handle_com_lost(iolink_port_t * port) +static void iolink_dl_mh_handle_com_lost (iolink_port_t * port) { iolink_dl_t * dl = iolink_get_dl_ctx (port); dl->timer_type = IOL_DL_TIMER_NONE; - MHInfo_ind(dl, IOLINK_MHINFO_COMLOST); + MHInfo_ind (dl, IOLINK_MHINFO_COMLOST); dl->message_handler.rwcmd = IOL_MHRW_NONE; - LOG_ERROR (IOLINK_DL_LOG, "%s: Communication lost on port %d (MH state: %s)\n", __func__, - iolink_get_portnumber (port), iolink_dl_mh_st_literals[dl->message_handler.state]); + LOG_ERROR ( + IOLINK_DL_LOG, + "%s: Communication lost on port %d (MH state: %s)\n", + __func__, + iolink_get_portnumber (port), + iolink_dl_mh_st_literals[dl->message_handler.state]); dl->message_handler.state = IOL_DL_MH_ST_INACTIVE_0; - os_event_set(dl->event, IOLINK_DL_EVENT_MDH); + os_event_set (dl->event, IOLINK_DL_EVENT_MDH); } static void iolink_dl_message_h_sm (iolink_port_t * port) { - iolink_dl_t * dl = iolink_get_dl_ctx (port); + iolink_dl_t * dl = iolink_get_dl_ctx (port); dl_mh_st_t previous = dl->message_handler.state; switch (dl->message_handler.state) @@ -591,35 +651,42 @@ static void iolink_dl_message_h_sm (iolink_port_t * port) case IOL_DL_MH_ST_STARTUP_2: if (dl->message_handler.mhcmd == IOL_MHCMD_PREOPERATE) // T12 { - set_mseq_change(dl); + set_mseq_change (dl); dl->message_handler.state = IOL_DL_MH_ST_PREOPERATE_6; } else if (dl->message_handler.mhcmd == IOL_MHCMD_OPERATE) // T39 { - start_timer_initcyc(dl); - set_mseq_change(dl); + start_timer_initcyc (dl); + set_mseq_change (dl); dl->message_handler.state = IOL_DL_MH_ST_OPERATE_12; } - else if ((dl->message_handler.rwcmd == IOL_MHRW_READ) || - (dl->message_handler.rwcmd == IOL_MHRW_WRITE)) + else if ( + (dl->message_handler.rwcmd == IOL_MHRW_READ) || + (dl->message_handler.rwcmd == IOL_MHRW_WRITE)) { dl->message_handler.retry = 0; - dl->dataready = false; + dl->dataready = false; #if IOLINK_HW == IOLINK_HW_MAX14819 if (dl->tinitcyc++ < 4) { - os_usleep((get_T_initcyc(dl) + 4000) / 2); + os_usleep ((get_T_initcyc (dl) + 4000) / 2); } - PL_Transfer_req (port, dl->od_handler.od_rxlen + 1, // T5, T6 - dl->od_handler.od_txlen + 2, - dl->txbuffer); + PL_Transfer_req ( + port, + dl->od_handler.od_rxlen + 1, // T5, T6 + dl->od_handler.od_txlen + 2, + dl->txbuffer); #endif dl->message_handler.state = IOL_DL_MH_ST_RESPONSE_3; } else if (dl->message_handler.mhcmd != IOL_MHCMD_INACTIVE) { - LOG_ERROR(IOLINK_DL_LOG, "%s: %s: unknown event triggered. Port %d\n", __func__, - iolink_dl_mh_st_literals[dl->message_handler.state], iolink_get_portnumber (port)); + LOG_ERROR ( + IOLINK_DL_LOG, + "%s: %s: unknown event triggered. Port %d\n", + __func__, + iolink_dl_mh_st_literals[dl->message_handler.state], + iolink_get_portnumber (port)); } break; case IOL_DL_MH_ST_RESPONSE_3: @@ -641,25 +708,30 @@ static void iolink_dl_message_h_sm (iolink_port_t * port) DL_Write_cnf (port, IOLINK_STATUS_NO_ERROR); } } - else if ((dl->rxtimeout) || // T7 - (dl->rxerror)) // T8 + else if ( + (dl->rxtimeout) || // T7 + (dl->rxerror)) // T8 { - start_timer_initcyc(dl); + start_timer_initcyc (dl); dl->message_handler.state = IOL_DL_MH_ST_ERRORHANDLING_5; } else { - LOG_ERROR(IOLINK_DL_LOG, "%s: %s: unknown event triggered. Port %d\n", __func__, - iolink_dl_mh_st_literals[dl->message_handler.state], iolink_get_portnumber (port)); + LOG_ERROR ( + IOLINK_DL_LOG, + "%s: %s: unknown event triggered. Port %d\n", + __func__, + iolink_dl_mh_st_literals[dl->message_handler.state], + iolink_get_portnumber (port)); } break; case IOL_DL_MH_ST_ERRORHANDLING_5: if (dl->message_handler.retry >= IOLINK_MAX_RETRY) // T11 { dl->timer_type = IOL_DL_TIMER_NONE; - MHInfo_ind(dl, IOLINK_MHINFO_COMLOST); + MHInfo_ind (dl, IOLINK_MHINFO_COMLOST); dl->message_handler.state = IOL_DL_MH_ST_INACTIVE_0; - os_event_set(dl->event, IOLINK_DL_EVENT_MDH); + os_event_set (dl->event, IOLINK_DL_EVENT_MDH); if (dl->message_handler.rwcmd == IOL_MHRW_READ) { @@ -677,67 +749,83 @@ static void iolink_dl_message_h_sm (iolink_port_t * port) #if IOLINK_HW == IOLINK_HW_MAX14819 PL_Resend (port); #endif - dl->message_handler.retry ++; + dl->message_handler.retry++; dl->message_handler.state = IOL_DL_MH_ST_AW_REPLY_4; } else { - LOG_ERROR(IOLINK_DL_LOG, "%s: %s: unknown event triggered. Port %d\n", __func__, - iolink_dl_mh_st_literals[dl->message_handler.state], iolink_get_portnumber (port)); + LOG_ERROR ( + IOLINK_DL_LOG, + "%s: %s: unknown event triggered. Port %d\n", + __func__, + iolink_dl_mh_st_literals[dl->message_handler.state], + iolink_get_portnumber (port)); } break; case IOL_DL_MH_ST_PREOPERATE_6: if (dl->message_handler.mhcmd == IOL_MHCMD_OPERATE) // T26 { - start_timer_initcyc(dl); - set_mseq_change(dl); + start_timer_initcyc (dl); + set_mseq_change (dl); dl->message_handler.state = IOL_DL_MH_ST_OPERATE_12; break; } else if (dl->message_handler.mhcmd == IOL_MHCMD_STARTUP) // T37 { - set_mseq_change(dl); + set_mseq_change (dl); dl->message_handler.state = IOL_DL_MH_ST_STARTUP_2; break; } else if (dl->message_handler.mhcmd == IOL_MHCMD_INACTIVE) // T36 { - MHInfo_ind(dl, IOLINK_MHINFO_COMLOST); - os_event_set(dl->event, IOLINK_DL_EVENT_MDH); + MHInfo_ind (dl, IOLINK_MHINFO_COMLOST); + os_event_set (dl->event, IOLINK_DL_EVENT_MDH); #if IOLINK_HW == IOLINK_HW_MAX14819 - PL_Transfer_req (port, dl->od_handler.od_rxlen + 1, - dl->od_handler.od_txlen + 2, dl->txbuffer); + PL_Transfer_req ( + port, + dl->od_handler.od_rxlen + 1, + dl->od_handler.od_txlen + 2, + dl->txbuffer); #endif dl->message_handler.state = IOL_DL_MH_ST_INACTIVE_0; break; } - else if ((dl->message_handler.rwcmd == IOL_MHRW_READPARAM) || - (dl->message_handler.rwcmd == IOL_MHRW_WRITEPARAM) || - (dl->message_handler.rwcmd == IOL_MHRW_ISDUTRANSPORT) || - (dl->cmd_handler.master_command == IOL_MASTERCMD_DEVICE_OPERATE) || - dl->event_handler.event_flag) + else if ( + (dl->message_handler.rwcmd == IOL_MHRW_READPARAM) || + (dl->message_handler.rwcmd == IOL_MHRW_WRITEPARAM) || + (dl->message_handler.rwcmd == IOL_MHRW_ISDUTRANSPORT) || + (dl->cmd_handler.master_command == IOL_MASTERCMD_DEVICE_OPERATE) || + dl->event_handler.event_flag) { dl->message_handler.retry = 0; // OD_Trig - dl->od_handler.trigger = IOL_TRIGGERED_MASTER_MESSAGE; - dl->message_handler.state = IOL_DL_MH_ST_GETOD_7; // T13, T14, T15, T17, T16 - start_timer_initcyc(dl); + dl->od_handler.trigger = IOL_TRIGGERED_MASTER_MESSAGE; + dl->message_handler.state = IOL_DL_MH_ST_GETOD_7; // T13, T14, T15, + // T17, T16 + start_timer_initcyc (dl); } else { - LOG_ERROR(IOLINK_DL_LOG, "%s: %s: unknown event triggered. Port %d\n", __func__, - iolink_dl_mh_st_literals[dl->message_handler.state], iolink_get_portnumber (port)); + LOG_ERROR ( + IOLINK_DL_LOG, + "%s: %s: unknown event triggered. Port %d\n", + __func__, + iolink_dl_mh_st_literals[dl->message_handler.state], + iolink_get_portnumber (port)); } break; case IOL_DL_MH_ST_GETOD_7: iolink_dl_od_h_sm (port); dl->message_handler.retry = 0; - dl->dataready = false; - //start_timer_initcyc(dl); + dl->dataready = false; + // start_timer_initcyc(dl); #if IOLINK_HW == IOLINK_HW_MAX14819 - PL_Transfer_req (port, dl->od_handler.od_rxlen + 1, - dl->od_handler.od_txlen + 2, dl->txbuffer); - LOG_DEBUG(IOLINK_DL_LOG, "%s: Message sent (PreOp)\n", __func__); + PL_Transfer_req ( + port, + dl->od_handler.od_rxlen + 1, + dl->od_handler.od_txlen + 2, + dl->txbuffer); + LOG_DEBUG (IOLINK_DL_LOG, "%s: Message sent (PreOp)\n", __func__); dl->message_handler.state = IOL_DL_MH_ST_RESPONSE_8; // T18 #endif break; @@ -746,45 +834,56 @@ static void iolink_dl_message_h_sm (iolink_port_t * port) case IOL_DL_MH_ST_AW_REPLY_9: if (dl->dataready) { - OD_cnf(dl, &dl->rxbuffer[0], dl->od_handler.od_rxlen, IOLINK_STATUS_NO_ERROR); + OD_cnf ( + dl, + &dl->rxbuffer[0], + dl->od_handler.od_rxlen, + IOLINK_STATUS_NO_ERROR); // ODTrig dl->od_handler.trigger = IOL_TRIGGERED_DEVICE_MESSAGE; - EventFlag_ind(dl, getCKSEvFlag(dl)); + EventFlag_ind (dl, getCKSEvFlag (dl)); iolink_dl_od_h_sm (port); if (dl->isdu_handler.state == IOL_DL_ISDUH_ST_IDLE_1) { if (dl->message_handler.mhcmd == IOL_MHCMD_OPERATE) { - start_timer_initcyc(dl); - dl->message_handler.state = IOL_DL_MH_ST_AW_REPLY_16; // SDCI_TC_0196 + start_timer_initcyc (dl); + dl->message_handler.state = + IOL_DL_MH_ST_AW_REPLY_16; // SDCI_TC_0196 } else if (!dl->event_handler.event_flag) { - os_timer_stop(dl->timer); - dl->message_handler.state = IOL_DL_MH_ST_PREOPERATE_6; // T23, T25 + os_timer_stop (dl->timer); + dl->message_handler.state = IOL_DL_MH_ST_PREOPERATE_6; // T23, + // T25 } } else { - start_timer_initcyc(dl); - dl->od_handler.trigger = IOL_TRIGGERED_MASTER_MESSAGE; + start_timer_initcyc (dl); + dl->od_handler.trigger = IOL_TRIGGERED_MASTER_MESSAGE; dl->message_handler.state = IOL_DL_MH_ST_GETOD_7; // T23, T24 } } - else if (dl->rxtimeout || // T19 - dl->rxerror) // T20 + else if ( + dl->rxtimeout || // T19 + dl->rxerror) // T20 { - start_timer_initcyc(dl); - dl->rxtimeout = false; - dl->rxerror = false; + start_timer_initcyc (dl); + dl->rxtimeout = false; + dl->rxerror = false; dl->message_handler.state = IOL_DL_MH_ST_ERRORHANDLING_10; } else { - LOG_ERROR(IOLINK_DL_LOG, "%s: %s: unknown event triggered. Port %d\n", __func__, - iolink_dl_mh_st_literals[dl->message_handler.state], iolink_get_portnumber (port)); - dl->cqerr = 0; + LOG_ERROR ( + IOLINK_DL_LOG, + "%s: %s: unknown event triggered. Port %d\n", + __func__, + iolink_dl_mh_st_literals[dl->message_handler.state], + iolink_get_portnumber (port)); + dl->cqerr = 0; dl->devdly = 0; iolink_pl_get_error (port, &dl->cqerr, &dl->devdly); } @@ -792,7 +891,7 @@ static void iolink_dl_message_h_sm (iolink_port_t * port) case IOL_DL_MH_ST_ERRORHANDLING_10: if (dl->message_handler.retry >= IOLINK_MAX_RETRY) // T22 { - write_master_command(port, IOLINK_STATUS_NO_COMM); + write_master_command (port, IOLINK_STATUS_NO_COMM); switch (dl->message_handler.rwcmd) { @@ -812,20 +911,24 @@ static void iolink_dl_message_h_sm (iolink_port_t * port) break; } - iolink_dl_mh_handle_com_lost(port); + iolink_dl_mh_handle_com_lost (port); } else if (dl->timer_elapsed && (dl->timer_type == IOL_DL_TIMER_TINITCYC_MH)) // T9 { #if IOLINK_HW == IOLINK_HW_MAX14819 PL_Resend (port); #endif - dl->message_handler.retry ++; + dl->message_handler.retry++; dl->message_handler.state = IOL_DL_MH_ST_AW_REPLY_9; // T21 } else { - LOG_ERROR(IOLINK_DL_LOG, "%s: %s: unknown event triggered. Port %d\n", __func__, - iolink_dl_mh_st_literals[dl->message_handler.state], iolink_get_portnumber (port)); + LOG_ERROR ( + IOLINK_DL_LOG, + "%s: %s: unknown event triggered. Port %d\n", + __func__, + iolink_dl_mh_st_literals[dl->message_handler.state], + iolink_get_portnumber (port)); } break; case IOL_DL_MH_ST_CHECKHANDLER_11: @@ -837,21 +940,22 @@ static void iolink_dl_message_h_sm (iolink_port_t * port) #if IOLINK_HW == IOLINK_HW_MAX14819 PL_DisableCycleTimer (port); #endif - set_mseq_change(dl); + set_mseq_change (dl); dl->message_handler.state = IOL_DL_MH_ST_STARTUP_2; break; } else if (dl->message_handler.mhcmd == IOL_MHCMD_INACTIVE) // T35 { - MHInfo_ind(dl, IOLINK_MHINFO_COMLOST); - os_event_set(dl->event, IOLINK_DL_EVENT_MDH); + MHInfo_ind (dl, IOLINK_MHINFO_COMLOST); + os_event_set (dl->event, IOLINK_DL_EVENT_MDH); #if IOLINK_HW == IOLINK_HW_MAX14819 PL_DisableCycleTimer (port); #endif dl->message_handler.state = IOL_DL_MH_ST_INACTIVE_0; break; } - else if (dl->timer_elapsed) // Initial waiting time before starting PD cycle + else if (dl->timer_elapsed) // Initial waiting time before starting PD + // cycle { // PD Trig dl->pd_handler.trigger = IOL_TRIGGERED_MASTER_MESSAGE; @@ -872,14 +976,15 @@ static void iolink_dl_message_h_sm (iolink_port_t * port) iolink_dl_od_h_sm (port); } dl->message_handler.retry = 0; - dl->dataready = false; + dl->dataready = false; #if IOLINK_HW == IOLINK_HW_MAX14819 PL_EnableCycleTimer (port); - PL_Transfer_req (port, - dl->od_handler.od_rxlen + dl->pd_handler.pd_rxlen + 1, - dl->od_handler.od_txlen + dl->pd_handler.pd_txlen + 2, - dl->txbuffer); - LOG_DEBUG(IOLINK_DL_LOG, "%s: Message sent\n", __func__); + PL_Transfer_req ( + port, + dl->od_handler.od_rxlen + dl->pd_handler.pd_rxlen + 1, + dl->od_handler.od_txlen + dl->pd_handler.pd_txlen + 2, + dl->txbuffer); + LOG_DEBUG (IOLINK_DL_LOG, "%s: Message sent\n", __func__); #endif dl->message_handler.state = IOL_DL_MH_ST_RESPONSE_15; // T29 break; @@ -892,31 +997,34 @@ static void iolink_dl_message_h_sm (iolink_port_t * port) #if IOLINK_HW == IOLINK_HW_MAX14819 PL_DisableCycleTimer (port); #endif - set_mseq_change(dl); + set_mseq_change (dl); dl->message_handler.state = IOL_DL_MH_ST_STARTUP_2; break; } else if (dl->message_handler.mhcmd == IOL_MHCMD_INACTIVE) // T35 { - MHInfo_ind(dl, IOLINK_MHINFO_COMLOST); - os_event_set(dl->event, IOLINK_DL_EVENT_MDH); + MHInfo_ind (dl, IOLINK_MHINFO_COMLOST); + os_event_set (dl->event, IOLINK_DL_EVENT_MDH); #if IOLINK_HW == IOLINK_HW_MAX14819 PL_DisableCycleTimer (port); #endif dl->message_handler.state = IOL_DL_MH_ST_INACTIVE_0; break; } - else if (dl->message_handler.rwcmd == IOL_MHRW_WRITEPARAM) // SDCI_TC_0196 + else if (dl->message_handler.rwcmd == IOL_MHRW_WRITEPARAM) // SDCI_TC_0196 { dl->od_handler.trigger = IOL_TRIGGERED_MASTER_MESSAGE; iolink_dl_od_h_sm (port); dl->message_handler.retry = 0; - dl->dataready = false; + dl->dataready = false; #if IOLINK_HW == IOLINK_HW_MAX14819 - os_mutex_lock(dl->mtx); - PL_MessageDownload_req (port, dl->od_handler.od_rxlen + dl->pd_handler.pd_rxlen + 1, - dl->od_handler.od_txlen + dl->pd_handler.pd_txlen + 2, dl->txbuffer); - os_mutex_unlock(dl->mtx); + os_mutex_lock (dl->mtx); + PL_MessageDownload_req ( + port, + dl->od_handler.od_rxlen + dl->pd_handler.pd_rxlen + 1, + dl->od_handler.od_txlen + dl->pd_handler.pd_txlen + 2, + dl->txbuffer); + os_mutex_unlock (dl->mtx); #endif dl->message_handler.state = IOL_DL_MH_ST_AW_REPLY_9; break; @@ -924,9 +1032,10 @@ static void iolink_dl_message_h_sm (iolink_port_t * port) if (dl->dataready) { - dl->message_handler.cks = dl->rxbuffer[dl->od_handler.od_rxlen + dl->pd_handler.pd_rxlen]; - EventFlag_ind(dl, getCKSEvFlag(dl)); - PDInStatus_ind (port, getCKSPDIn(dl)); + dl->message_handler.cks = + dl->rxbuffer[dl->od_handler.od_rxlen + dl->pd_handler.pd_rxlen]; + EventFlag_ind (dl, getCKSEvFlag (dl)); + PDInStatus_ind (port, getCKSPDIn (dl)); if (dl->message_handler.interleave != IOL_DL_INTERLEAVE_OD) { @@ -960,38 +1069,48 @@ static void iolink_dl_message_h_sm (iolink_port_t * port) dl->od_handler.trigger = IOL_TRIGGERED_MASTER_MESSAGE; iolink_dl_od_h_sm (port); #if IOLINK_HW == IOLINK_HW_MAX14819 - os_mutex_lock(dl->mtx); - PL_MessageDownload_req (port, - dl->od_handler.od_rxlen + dl->pd_handler.pd_rxlen + 1, - dl->od_handler.od_txlen + dl->pd_handler.pd_txlen + 2, - dl->txbuffer); - os_mutex_unlock(dl->mtx); + os_mutex_lock (dl->mtx); + PL_MessageDownload_req ( + port, + dl->od_handler.od_rxlen + dl->pd_handler.pd_rxlen + 1, + dl->od_handler.od_txlen + dl->pd_handler.pd_txlen + 2, + dl->txbuffer); + os_mutex_unlock (dl->mtx); #endif dl->message_handler.state = IOL_DL_MH_ST_AW_REPLY_16; // T34 - dl->dataready = false; + dl->dataready = false; } - else if (dl->rxtimeout || // T30 - dl->rxerror) // T31 + else if ( + dl->rxtimeout || // T30 + dl->rxerror) // T31 { - LOG_ERROR(IOLINK_DL_LOG, "%s: %s: %s on Port %d\n", __func__, - iolink_dl_mh_st_literals[dl->message_handler.state], - (dl->rxtimeout) ? "RXTimeout" : "RXError", iolink_get_portnumber (port)); + LOG_ERROR ( + IOLINK_DL_LOG, + "%s: %s: %s on Port %d\n", + __func__, + iolink_dl_mh_st_literals[dl->message_handler.state], + (dl->rxtimeout) ? "RXTimeout" : "RXError", + iolink_get_portnumber (port)); dl->rxtimeout = false; - dl->rxerror = false; + dl->rxerror = false; if (dl->message_handler.retry >= IOLINK_MAX_RETRY) // T33 { - iolink_dl_mh_handle_com_lost(port); + iolink_dl_mh_handle_com_lost (port); } - dl->message_handler.retry ++; + dl->message_handler.retry++; } else { - LOG_ERROR(IOLINK_DL_LOG, "%s: %s: unknown event triggered. Port %d\n", __func__, - iolink_dl_mh_st_literals[dl->message_handler.state], iolink_get_portnumber (port)); - dl->cqerr = 0; + LOG_ERROR ( + IOLINK_DL_LOG, + "%s: %s: unknown event triggered. Port %d\n", + __func__, + iolink_dl_mh_st_literals[dl->message_handler.state], + iolink_get_portnumber (port)); + dl->cqerr = 0; dl->devdly = 0; iolink_pl_get_error (port, &dl->cqerr, &dl->devdly); } @@ -999,38 +1118,46 @@ static void iolink_dl_message_h_sm (iolink_port_t * port) case IOL_DL_MH_ST_ERRORHANDLING_17: if (dl->message_handler.retry >= IOLINK_MAX_RETRY) // T33 { - iolink_dl_mh_handle_com_lost(port); + iolink_dl_mh_handle_com_lost (port); } else if (dl->timer_tcyc_elapsed) // T32 { #if IOLINK_HW == IOLINK_HW_MAX14819 PL_Resend (port); #endif - dl->message_handler.retry ++; + dl->message_handler.retry++; dl->message_handler.state = IOL_DL_MH_ST_AW_REPLY_16; } else { if (dl->dataready) { - LOG_ERROR(IOLINK_DL_LOG, "%s: %s: Rxdata arrived too late. Trying to recover. Port %d\n", - __func__, iolink_dl_mh_st_literals[dl->message_handler.state], - iolink_get_portnumber (port)); - dl->message_handler.cks = dl->rxbuffer[dl->od_handler.od_rxlen + dl->pd_handler.pd_rxlen]; - PDInStatus_ind (port, getCKSPDIn(dl)); + LOG_ERROR ( + IOLINK_DL_LOG, + "%s: %s: Rxdata arrived too late. Trying to recover. Port %d\n", + __func__, + iolink_dl_mh_st_literals[dl->message_handler.state], + iolink_get_portnumber (port)); + dl->message_handler.cks = + dl->rxbuffer[dl->od_handler.od_rxlen + dl->pd_handler.pd_rxlen]; + PDInStatus_ind (port, getCKSPDIn (dl)); // PD Trig dl->pd_handler.trigger = IOL_TRIGGERED_DEVICE_MESSAGE; iolink_dl_pd_h_sm (port); // OD Trig dl->od_handler.trigger = IOL_TRIGGERED_DEVICE_MESSAGE; - EventFlag_ind(dl, getCKSEvFlag(dl)); + EventFlag_ind (dl, getCKSEvFlag (dl)); iolink_dl_od_h_sm (port); dl->message_handler.state = IOL_DL_MH_ST_OPERATE_12; // T34 } else { - LOG_ERROR(IOLINK_DL_LOG, "%s: %s: unknown event triggered. Port %d\n", __func__, - iolink_dl_mh_st_literals[dl->message_handler.state], iolink_get_portnumber (port)); + LOG_ERROR ( + IOLINK_DL_LOG, + "%s: %s: unknown event triggered. Port %d\n", + __func__, + iolink_dl_mh_st_literals[dl->message_handler.state], + iolink_get_portnumber (port)); } } break; @@ -1038,8 +1165,12 @@ static void iolink_dl_message_h_sm (iolink_port_t * port) if (dl->message_handler.state != previous) { - LOG_DEBUG(IOLINK_DL_LOG, "%s: state change: %s -> %s\n", __func__, - iolink_dl_mh_st_literals[previous], iolink_dl_mh_st_literals[dl->message_handler.state]); + LOG_DEBUG ( + IOLINK_DL_LOG, + "%s: state change: %s -> %s\n", + __func__, + iolink_dl_mh_st_literals[previous], + iolink_dl_mh_st_literals[dl->message_handler.state]); } } @@ -1056,29 +1187,41 @@ static void iolink_dl_pd_h_sm (iolink_port_t * port) } else if (dl->pd_handler.phcmd == IOL_PHCMD_INTERLEAVE) { - dl->pd_handler.state = IOL_DL_PDH_ST_PDININTERLEAVE_2; // T4 + dl->pd_handler.state = IOL_DL_PDH_ST_PDININTERLEAVE_2; // T4 } else if (dl->pd_handler.trigger != IOL_TRIGGERED_NONE) // T1 { dl->pd_handler.trigger = IOL_TRIGGERED_NONE; - PD_req(dl, 0, 0, NULL, 0, 0); + PD_req (dl, 0, 0, NULL, 0, 0); } else { - LOG_ERROR(IOLINK_DL_LOG, "%s: INACTIVE_0: unknown event triggered. Port %d\n", - __func__, iolink_get_portnumber (port)); + LOG_ERROR ( + IOLINK_DL_LOG, + "%s: INACTIVE_0: unknown event triggered. Port %d\n", + __func__, + iolink_get_portnumber (port)); } break; case IOL_DL_PDH_ST_PDSINGLE_1: if (dl->pd_handler.trigger == IOL_TRIGGERED_MASTER_MESSAGE) // T3 { dl->pd_handler.trigger = IOL_TRIGGERED_NONE; - PD_req(dl, 0, dl->pd_handler.pd_rxlen, dl->pd_handler.pdoutdata, 0, dl->pd_handler.pd_txlen); + PD_req ( + dl, + 0, + dl->pd_handler.pd_rxlen, + dl->pd_handler.pdoutdata, + 0, + dl->pd_handler.pd_txlen); } else if (dl->pd_handler.trigger == IOL_TRIGGERED_DEVICE_MESSAGE) // T3 { dl->pd_handler.trigger = IOL_TRIGGERED_NONE; - DL_PDInputTransport_ind (port, &dl->rxbuffer[dl->od_handler.od_rxlen], dl->pd_handler.pd_rxlen); + DL_PDInputTransport_ind ( + port, + &dl->rxbuffer[dl->od_handler.od_rxlen], + dl->pd_handler.pd_rxlen); } else if (dl->pd_handler.phcmd == IOL_PHCMD_INACTIVE) { @@ -1086,8 +1229,13 @@ static void iolink_dl_pd_h_sm (iolink_port_t * port) } else { - LOG_ERROR(IOLINK_DL_LOG, "%s: PDSINGLE_1: unknown event triggered (t:%d, c:%d). Port %d\n", - __func__, dl->pd_handler.trigger, dl->pd_handler.phcmd, iolink_get_portnumber (port)); + LOG_ERROR ( + IOLINK_DL_LOG, + "%s: PDSINGLE_1: unknown event triggered (t:%d, c:%d). Port %d\n", + __func__, + dl->pd_handler.trigger, + dl->pd_handler.phcmd, + iolink_get_portnumber (port)); } break; case IOL_DL_PDH_ST_PDININTERLEAVE_2: @@ -1098,18 +1246,30 @@ static void iolink_dl_pd_h_sm (iolink_port_t * port) else if (dl->pd_handler.trigger == IOL_TRIGGERED_MASTER_MESSAGE) // T5 { dl->pd_handler.trigger = IOL_TRIGGERED_NONE; - OD_req(dl, IOLINK_RWDIRECTION_READ, IOLINK_COMCHANNEL_PROCESS, dl->pd_handler.pd_address, 0, NULL); - interleave_reset_od_sizes(dl); + OD_req ( + dl, + IOLINK_RWDIRECTION_READ, + IOLINK_COMCHANNEL_PROCESS, + dl->pd_handler.pd_address, + 0, + NULL); + interleave_reset_od_sizes (dl); } else if (dl->pd_handler.trigger == IOL_TRIGGERED_DEVICE_MESSAGE) { - memcpy(&dl->pd_handler.pdindata[dl->pd_handler.pd_address], dl->rxbuffer, 2); + memcpy ( + &dl->pd_handler.pdindata[dl->pd_handler.pd_address], + dl->rxbuffer, + 2); dl->pd_handler.pd_address += 2; if (dl->pd_handler.pd_address >= dl->pd_handler.pd_rxlen) { dl->pd_handler.pd_address = 0; - DL_PDInputTransport_ind (port, dl->pd_handler.pdindata, dl->pd_handler.pd_rxlen); + DL_PDInputTransport_ind ( + port, + dl->pd_handler.pdindata, + dl->pd_handler.pd_rxlen); // Stay in PDININTERLEAVE since no tx-data if (dl->pd_handler.pd_txlen > 0) @@ -1120,8 +1280,11 @@ static void iolink_dl_pd_h_sm (iolink_port_t * port) } else { - LOG_ERROR(IOLINK_DL_LOG, "%s: PDININTERLEAVE_2: unknown event triggered. Port %d\n", - __func__, iolink_get_portnumber (port)); + LOG_ERROR ( + IOLINK_DL_LOG, + "%s: PDININTERLEAVE_2: unknown event triggered. Port %d\n", + __func__, + iolink_get_portnumber (port)); } break; case IOL_DL_PDH_ST_PDOUTINTERLEAVE_3: @@ -1132,9 +1295,15 @@ static void iolink_dl_pd_h_sm (iolink_port_t * port) else if (dl->pd_handler.trigger == IOL_TRIGGERED_MASTER_MESSAGE) // T7 { dl->pd_handler.trigger = IOL_TRIGGERED_NONE; - PD_req(dl, 0, 0, dl->pd_handler.pdoutdata, dl->pd_handler.pd_address, 2); - OD_req(dl, IOLINK_RWDIRECTION_WRITE, IOLINK_COMCHANNEL_PROCESS, dl->pd_handler.pd_address, 0, NULL); - interleave_reset_od_sizes(dl); + PD_req (dl, 0, 0, dl->pd_handler.pdoutdata, dl->pd_handler.pd_address, 2); + OD_req ( + dl, + IOLINK_RWDIRECTION_WRITE, + IOLINK_COMCHANNEL_PROCESS, + dl->pd_handler.pd_address, + 0, + NULL); + interleave_reset_od_sizes (dl); dl->pd_handler.pd_address += 2; } else if (dl->pd_handler.trigger == IOL_TRIGGERED_DEVICE_MESSAGE) @@ -1158,8 +1327,11 @@ static void iolink_dl_pd_h_sm (iolink_port_t * port) } else { - LOG_ERROR(IOLINK_DL_LOG, "%s: PDOUTINTERLEAVE_3: unknown event triggered. Port %d\n", - __func__, iolink_get_portnumber (port)); + LOG_ERROR ( + IOLINK_DL_LOG, + "%s: PDOUTINTERLEAVE_3: unknown event triggered. Port %d\n", + __func__, + iolink_get_portnumber (port)); } break; } @@ -1176,12 +1348,18 @@ static void iolink_dl_isdu_h_sm_isduerror4 (iolink_port_t * port) else { dl->isdu_handler.total_isdu_seg = 0; - OD_req(dl, IOLINK_RWDIRECTION_READ, IOLINK_COMCHANNEL_ISDU, IOLINK_FLOWCTRL_ABORT, 0, NULL); - - iservice_t qualifier = IOL_ISERVICE_MASTER_NO_SERVICE; + OD_req ( + dl, + IOLINK_RWDIRECTION_READ, + IOLINK_COMCHANNEL_ISDU, + IOLINK_FLOWCTRL_ABORT, + 0, + NULL); + + iservice_t qualifier = IOL_ISERVICE_MASTER_NO_SERVICE; iolink_status_t errinfo = IOLINK_STATUS_INVALID; - if (isdu_timer_elapsed(dl)) + if (isdu_timer_elapsed (dl)) { errinfo = IOLINK_STATUS_ISDU_TIMEOUT; } @@ -1193,16 +1371,16 @@ static void iolink_dl_isdu_h_sm_isduerror4 (iolink_port_t * port) { errinfo = IOLINK_STATUS_ISDU_ABORT; } - else if (!valid_isdu_header(dl)) + else if (!valid_isdu_header (dl)) { - qualifier = get_isdu_iserv(dl); - errinfo = IOLINK_STATUS_ISDU_ILLEGAL_SERVICE_PRIMITIVE; + qualifier = get_isdu_iserv (dl); + errinfo = IOLINK_STATUS_ISDU_ILLEGAL_SERVICE_PRIMITIVE; } DL_ISDUTransport_cnf (port, NULL, 0, qualifier, errinfo); dl->message_handler.rwcmd = IOL_MHRW_NONE; - dl->isdu_handler.state = IOL_DL_ISDUH_ST_IDLE_1; // T11 + dl->isdu_handler.state = IOL_DL_ISDUH_ST_IDLE_1; // T11 } } @@ -1213,8 +1391,9 @@ static void iolink_dl_isdu_h_sm_enter_isduerror4 (iolink_port_t * port) if (dl->isdu_handler.ihcmd == IOL_IHCMD_INACTIVE) { dl->isdu_handler.total_isdu_seg = 0; - DL_ISDUTransport_cnf (port, NULL, 0, 0, IOLINK_STATUS_NO_COMM); // Not in spec - dl->isdu_handler.state = IOL_DL_ISDUH_ST_INACTIVE_0; // T15 + DL_ISDUTransport_cnf (port, NULL, 0, 0, IOLINK_STATUS_NO_COMM); // Not in + // spec + dl->isdu_handler.state = IOL_DL_ISDUH_ST_INACTIVE_0; // T15 } else { @@ -1234,27 +1413,38 @@ static void iolink_dl_isdu_h_sm_reception_complete (iolink_port_t * port) iolink_dl_t * dl = iolink_get_dl_ctx (port); uint8_t isdu_data_length; - if (!get_isdu_data_length(dl, &isdu_data_length)) + if (!get_isdu_data_length (dl, &isdu_data_length)) { - DL_ISDUTransport_cnf (port, get_isdu_response_data(dl), 0, get_isdu_iserv(dl), IOLINK_STATUS_INVALID); + DL_ISDUTransport_cnf ( + port, + get_isdu_response_data (dl), + 0, + get_isdu_iserv (dl), + IOLINK_STATUS_INVALID); } else { iolink_status_t errinfo = IOLINK_STATUS_NO_ERROR; - if (!valid_isdu_checksum(dl)) + if (!valid_isdu_checksum (dl)) { - // Checksum error. Signal to AL, but continue without sending ABORT to device + // Checksum error. Signal to AL, but continue without sending ABORT to + // device errinfo = IOLINK_STATUS_ISDU_CHECKSUM_ERROR; } - DL_ISDUTransport_cnf (port, get_isdu_response_data(dl), isdu_data_length, get_isdu_iserv(dl), errinfo); + DL_ISDUTransport_cnf ( + port, + get_isdu_response_data (dl), + isdu_data_length, + get_isdu_iserv (dl), + errinfo); } dl->isdu_handler.current_isdu_seg = 0; - dl->isdu_handler.total_isdu_seg = 0; - dl->message_handler.rwcmd = IOL_MHRW_NONE; - dl->isdu_handler.state = IOL_DL_ISDUH_ST_IDLE_1; // T8 + dl->isdu_handler.total_isdu_seg = 0; + dl->message_handler.rwcmd = IOL_MHRW_NONE; + dl->isdu_handler.state = IOL_DL_ISDUH_ST_IDLE_1; // T8 } static void iolink_dl_isdu_h_sm (iolink_port_t * port) @@ -1266,14 +1456,17 @@ static void iolink_dl_isdu_h_sm (iolink_port_t * port) case IOL_DL_ISDUH_ST_INACTIVE_0: if (dl->isdu_handler.ihcmd == IOL_IHCMD_ACTIVE) { - dl->isdu_handler.total_isdu_seg = 0; + dl->isdu_handler.total_isdu_seg = 0; dl->isdu_handler.current_isdu_seg = 0; - dl->isdu_handler.state = IOL_DL_ISDUH_ST_IDLE_1; // T1 + dl->isdu_handler.state = IOL_DL_ISDUH_ST_IDLE_1; // T1 } else if (dl->isdu_handler.ihcmd != IOL_IHCMD_INACTIVE) { - LOG_ERROR(IOLINK_DL_LOG, "%s: INACTIVE_0: unknown event triggered. Port %d\n", - __func__, iolink_get_portnumber (port)); + LOG_ERROR ( + IOLINK_DL_LOG, + "%s: INACTIVE_0: unknown event triggered. Port %d\n", + __func__, + iolink_get_portnumber (port)); } break; case IOL_DL_ISDUH_ST_IDLE_1: @@ -1292,20 +1485,42 @@ static void iolink_dl_isdu_h_sm (iolink_port_t * port) switch (dl->message_handler.rwcmd) { case IOL_MHRW_ISDUTRANSPORT: - OD_req(dl, IOLINK_RWDIRECTION_WRITE, IOLINK_COMCHANNEL_ISDU, IOLINK_FLOWCTRL_START, - dl->message_handler.od_len, dl->isdu_handler.isdu_data); + OD_req ( + dl, + IOLINK_RWDIRECTION_WRITE, + IOLINK_COMCHANNEL_ISDU, + IOLINK_FLOWCTRL_START, + dl->message_handler.od_len, + dl->isdu_handler.isdu_data); dl->isdu_handler.current_isdu_seg = 1; dl->isdu_handler.state = IOL_DL_ISDUH_ST_ISDUREQUEST_2; // T2 break; case IOL_MHRW_READPARAM: // T13 - OD_req(dl, IOLINK_RWDIRECTION_READ, IOLINK_COMCHANNEL_PAGE, dl->od_handler.data_addr, 0, 0); + OD_req ( + dl, + IOLINK_RWDIRECTION_READ, + IOLINK_COMCHANNEL_PAGE, + dl->od_handler.data_addr, + 0, + 0); break; case IOL_MHRW_WRITEPARAM: // T13 - OD_req(dl, IOLINK_RWDIRECTION_WRITE, IOLINK_COMCHANNEL_PAGE, dl->od_handler.data_addr, - 1, &dl->od_handler.data_value); + OD_req ( + dl, + IOLINK_RWDIRECTION_WRITE, + IOLINK_COMCHANNEL_PAGE, + dl->od_handler.data_addr, + 1, + &dl->od_handler.data_value); break; default: // T14 - OD_req(dl, IOLINK_RWDIRECTION_READ, IOLINK_COMCHANNEL_ISDU, IOLINK_FLOWCTRL_IDLE_1, 0, 0); + OD_req ( + dl, + IOLINK_RWDIRECTION_READ, + IOLINK_COMCHANNEL_ISDU, + IOLINK_FLOWCTRL_IDLE_1, + 0, + 0); break; } } @@ -1327,28 +1542,37 @@ static void iolink_dl_isdu_h_sm (iolink_port_t * port) } else { - LOG_ERROR(IOLINK_DL_LOG, "%s: IDLE_1: unknown event triggered. Port %d\n", - __func__, iolink_get_portnumber (port)); + LOG_ERROR ( + IOLINK_DL_LOG, + "%s: IDLE_1: unknown event triggered. Port %d\n", + __func__, + iolink_get_portnumber (port)); } break; case IOL_DL_ISDUH_ST_ISDUREQUEST_2: - if ((dl->message_handler.rwcmd == IOL_MHRW_ISDUABORT) || - (dl->mode_handler.mhinfo == IOLINK_MHINFO_COMLOST)) + if ( + (dl->message_handler.rwcmd == IOL_MHRW_ISDUABORT) || + (dl->mode_handler.mhinfo == IOLINK_MHINFO_COMLOST)) { iolink_dl_isdu_h_sm_enter_isduerror4 (port); // T12 and T19 } else if (dl->od_handler.trigger == IOL_TRIGGERED_MASTER_MESSAGE) { - OD_req(dl, IOLINK_RWDIRECTION_WRITE, IOLINK_COMCHANNEL_ISDU, dl->isdu_handler.current_isdu_seg % 16, - dl->message_handler.od_len, - &dl->isdu_handler.isdu_data[dl->message_handler.od_len * dl->isdu_handler.current_isdu_seg]); - dl->isdu_handler.current_isdu_seg ++; // T3 + OD_req ( + dl, + IOLINK_RWDIRECTION_WRITE, + IOLINK_COMCHANNEL_ISDU, + dl->isdu_handler.current_isdu_seg % 16, + dl->message_handler.od_len, + &dl->isdu_handler.isdu_data + [dl->message_handler.od_len * dl->isdu_handler.current_isdu_seg]); + dl->isdu_handler.current_isdu_seg++; // T3 } else if (dl->od_handler.trigger == IOL_TRIGGERED_DEVICE_MESSAGE) { if (dl->isdu_handler.current_isdu_seg >= dl->isdu_handler.total_isdu_seg) { - isdu_timer_start(dl); + isdu_timer_start (dl); dl->isdu_handler.current_isdu_seg = 0; dl->isdu_handler.state = IOL_DL_ISDUH_ST_ISDUWAIT_3; // T4 } @@ -1359,30 +1583,42 @@ static void iolink_dl_isdu_h_sm (iolink_port_t * port) } else { - LOG_ERROR(IOLINK_DL_LOG, "%s: IOL_DL_ISDUH_ST_ISDUREQUEST_2: unknown event triggered." - " Port %d\n", __func__, iolink_get_portnumber (port)); + LOG_ERROR ( + IOLINK_DL_LOG, + "%s: IOL_DL_ISDUH_ST_ISDUREQUEST_2: unknown event triggered." + " Port %d\n", + __func__, + iolink_get_portnumber (port)); } break; case IOL_DL_ISDUH_ST_ISDUWAIT_3: if (dl->message_handler.rwcmd == IOL_MHRW_ISDUABORT) { - isdu_timer_reset(dl); + isdu_timer_reset (dl); iolink_dl_isdu_h_sm_enter_isduerror4 (port); // T17 } - else if (isdu_timer_elapsed(dl) || (dl->mode_handler.mhinfo == IOLINK_MHINFO_COMLOST)) + else if (isdu_timer_elapsed (dl) || (dl->mode_handler.mhinfo == IOLINK_MHINFO_COMLOST)) { iolink_dl_isdu_h_sm_enter_isduerror4 (port); // T9 } else if (dl->od_handler.trigger == IOL_TRIGGERED_MASTER_MESSAGE) { - OD_req(dl, IOLINK_RWDIRECTION_READ, IOLINK_COMCHANNEL_ISDU, IOLINK_FLOWCTRL_START, - dl->message_handler.od_len, dl->isdu_handler.isdu_data);// T5 + OD_req ( + dl, + IOLINK_RWDIRECTION_READ, + IOLINK_COMCHANNEL_ISDU, + IOLINK_FLOWCTRL_START, + dl->message_handler.od_len, + dl->isdu_handler.isdu_data); // T5 // T5 } else if (dl->od_handler.trigger == IOL_TRIGGERED_DEVICE_MESSAGE) { - memcpy(&dl->isdu_handler.isdu_data[dl->isdu_handler.current_isdu_seg * dl->message_handler.od_len], - dl->rxbuffer, dl->message_handler.od_len); + memcpy ( + &dl->isdu_handler.isdu_data + [dl->isdu_handler.current_isdu_seg * dl->message_handler.od_len], + dl->rxbuffer, + dl->message_handler.od_len); if (dl->isdu_handler.isdu_data[0] == ((IOL_ISERVICE_DEVICE_NO_SERVICE << 4) | 0x01)) { @@ -1392,26 +1628,26 @@ static void iolink_dl_isdu_h_sm (iolink_port_t * port) else if (dl->isdu_handler.isdu_data[0] == 0) { // No service - LOG_INFO(IOLINK_DL_LOG, "%s: ISDUWait. No service!\n", __func__); - isdu_timer_reset(dl); + LOG_INFO (IOLINK_DL_LOG, "%s: ISDUWait. No service!\n", __func__); + isdu_timer_reset (dl); iolink_dl_isdu_h_sm_enter_isduerror4 (port); // T9 } else { - if (!valid_isdu_header(dl)) + if (!valid_isdu_header (dl)) { - isdu_timer_reset(dl); + isdu_timer_reset (dl); iolink_dl_isdu_h_sm_enter_isduerror4 (port); // T9 } else { uint8_t isdu_total_len = 0; - get_isdu_total_len(dl, &isdu_total_len); - dl->isdu_handler.total_isdu_len = isdu_total_len; + get_isdu_total_len (dl, &isdu_total_len); + dl->isdu_handler.total_isdu_len = isdu_total_len; dl->isdu_handler.current_isdu_seg = 1; - dl->isdu_handler.total_isdu_seg = get_isdu_total_segments(dl); + dl->isdu_handler.total_isdu_seg = get_isdu_total_segments (dl); - isdu_timer_reset(dl); + isdu_timer_reset (dl); if (dl->isdu_handler.current_isdu_seg >= dl->isdu_handler.total_isdu_seg) { @@ -1426,35 +1662,48 @@ static void iolink_dl_isdu_h_sm (iolink_port_t * port) } else { - LOG_ERROR(IOLINK_DL_LOG, "%s: IOL_DL_ISDUH_ST_ISDUWAIT_3: unknown event triggered." - " Port %d\n", __func__, iolink_get_portnumber (port)); + LOG_ERROR ( + IOLINK_DL_LOG, + "%s: IOL_DL_ISDUH_ST_ISDUWAIT_3: unknown event triggered." + " Port %d\n", + __func__, + iolink_get_portnumber (port)); } break; case IOL_DL_ISDUH_ST_ISDUERROR_4: iolink_dl_isdu_h_sm_isduerror4 (port); break; case IOL_DL_ISDUH_ST_ISDURESPONSE_5: - if ((dl->message_handler.rwcmd == IOL_MHRW_ISDUABORT) || // T18 - (dl->mode_handler.mhinfo == IOLINK_MHINFO_COMLOST)) // T10 + if ( + (dl->message_handler.rwcmd == IOL_MHRW_ISDUABORT) || // T18 + (dl->mode_handler.mhinfo == IOLINK_MHINFO_COMLOST)) // T10 { iolink_dl_isdu_h_sm_enter_isduerror4 (port); } else if (dl->od_handler.trigger == IOL_TRIGGERED_MASTER_MESSAGE) { - OD_req(dl, IOLINK_RWDIRECTION_READ, IOLINK_COMCHANNEL_ISDU, dl->isdu_handler.current_isdu_seg % 16, - dl->message_handler.od_len, - &dl->isdu_handler.isdu_data[dl->message_handler.od_len * dl->isdu_handler.current_isdu_seg]); + OD_req ( + dl, + IOLINK_RWDIRECTION_READ, + IOLINK_COMCHANNEL_ISDU, + dl->isdu_handler.current_isdu_seg % 16, + dl->message_handler.od_len, + &dl->isdu_handler.isdu_data + [dl->message_handler.od_len * dl->isdu_handler.current_isdu_seg]); // T7 } else if (dl->od_handler.trigger == IOL_TRIGGERED_DEVICE_MESSAGE) { uint8_t isdu_total_len = 0; - get_isdu_total_len(dl, &isdu_total_len); + get_isdu_total_len (dl, &isdu_total_len); dl->isdu_handler.total_isdu_len = isdu_total_len; - dl->isdu_handler.total_isdu_seg = get_isdu_total_segments(dl); - memcpy(&dl->isdu_handler.isdu_data[dl->isdu_handler.current_isdu_seg * dl->message_handler.od_len], - dl->rxbuffer, dl->message_handler.od_len); - dl->isdu_handler.current_isdu_seg ++; // T7 response + dl->isdu_handler.total_isdu_seg = get_isdu_total_segments (dl); + memcpy ( + &dl->isdu_handler.isdu_data + [dl->isdu_handler.current_isdu_seg * dl->message_handler.od_len], + dl->rxbuffer, + dl->message_handler.od_len); + dl->isdu_handler.current_isdu_seg++; // T7 response if (dl->isdu_handler.current_isdu_seg >= dl->isdu_handler.total_isdu_seg) { @@ -1463,14 +1712,18 @@ static void iolink_dl_isdu_h_sm (iolink_port_t * port) } else { - LOG_ERROR(IOLINK_DL_LOG, "%s: IOL_DL_ISDUH_ST_ISDURESPONSE_5: unknown event triggered." - " Port %d\n", __func__, iolink_get_portnumber (port)); + LOG_ERROR ( + IOLINK_DL_LOG, + "%s: IOL_DL_ISDUH_ST_ISDURESPONSE_5: unknown event triggered." + " Port %d\n", + __func__, + iolink_get_portnumber (port)); } break; } } -static void iolink_dl_cmd_h_sm(iolink_port_t * port) +static void iolink_dl_cmd_h_sm (iolink_port_t * port) { iolink_dl_t * dl = iolink_get_dl_ctx (port); @@ -1484,8 +1737,11 @@ static void iolink_dl_cmd_h_sm(iolink_port_t * port) } else if (dl->cmd_handler.chcmd != IOL_CHCMD_INACTIVE) { - LOG_ERROR(IOLINK_DL_LOG, "%s: INACTIVE_0: unknown event triggered. Port %d\n", - __func__, iolink_get_portnumber (port)); + LOG_ERROR ( + IOLINK_DL_LOG, + "%s: INACTIVE_0: unknown event triggered. Port %d\n", + __func__, + iolink_get_portnumber (port)); } break; case IOL_DL_CMDH_ST_IDLE_1: @@ -1493,13 +1749,16 @@ static void iolink_dl_cmd_h_sm(iolink_port_t * port) { dl->cmd_handler.state = IOL_DL_CMDH_ST_INACTIVE_0; // T6 } - else if ((dl->cmd_handler.control_code == IOLINK_CONTROLCODE_PDOUTVALID) || - (dl->cmd_handler.control_code == IOLINK_CONTROLCODE_PDOUTINVALID)) + else if ( + (dl->cmd_handler.control_code == IOLINK_CONTROLCODE_PDOUTVALID) || + (dl->cmd_handler.control_code == IOLINK_CONTROLCODE_PDOUTINVALID)) { - os_mutex_lock(dl->mtx); - dl->cmd_handler.master_command = (dl->cmd_handler.control_code == IOLINK_CONTROLCODE_PDOUTVALID) ? - IOL_MASTERCMD_DEVICE_PD_OUT_OP : IOL_MASTERCMD_DEVICE_OPERATE; - os_mutex_unlock(dl->mtx); + os_mutex_lock (dl->mtx); + dl->cmd_handler.master_command = + (dl->cmd_handler.control_code == IOLINK_CONTROLCODE_PDOUTVALID) + ? IOL_MASTERCMD_DEVICE_PD_OUT_OP + : IOL_MASTERCMD_DEVICE_OPERATE; + os_mutex_unlock (dl->mtx); dl->cmd_handler.state = IOL_DL_CMDH_ST_MASTERCOMMAND_2; // T3 } else if (dl->cmd_handler.control_code == IOLINK_CONTROLCODE_DEVICEMODE) @@ -1509,14 +1768,23 @@ static void iolink_dl_cmd_h_sm(iolink_port_t * port) } else { - LOG_ERROR(IOLINK_DL_LOG, "%s: IDLE_1: unknown event triggered. Port %d\n", - __func__, iolink_get_portnumber (port)); + LOG_ERROR ( + IOLINK_DL_LOG, + "%s: IDLE_1: unknown event triggered. Port %d\n", + __func__, + iolink_get_portnumber (port)); } break; case IOL_DL_CMDH_ST_MASTERCOMMAND_2: - OD_req(dl, IOLINK_RWDIRECTION_WRITE, IOLINK_COMCHANNEL_PAGE, 0, 1, &dl->cmd_handler.master_command); + OD_req ( + dl, + IOLINK_RWDIRECTION_WRITE, + IOLINK_COMCHANNEL_PAGE, + 0, + 1, + &dl->cmd_handler.master_command); dl->cmd_handler.control_code = IOLINK_CONTROLCODE_NONE; - dl->cmd_handler.state = IOL_DL_CMDH_ST_IDLE_1; // T5 + dl->cmd_handler.state = IOL_DL_CMDH_ST_IDLE_1; // T5 break; } } @@ -1534,8 +1802,11 @@ static void iolink_dl_ev_h_sm (iolink_port_t * port) } else if (dl->event_handler.ehcmd != IOL_EHCMD_INACTIVE) { - LOG_ERROR(IOLINK_DL_LOG, "%s: INACTIVE_0: unknown event triggered. Port %d\n", - __func__, iolink_get_portnumber (port)); + LOG_ERROR ( + IOLINK_DL_LOG, + "%s: INACTIVE_0: unknown event triggered. Port %d\n", + __func__, + iolink_get_portnumber (port)); } break; case IOL_DL_EVH_ST_IDLE_1: @@ -1547,7 +1818,10 @@ static void iolink_dl_ev_h_sm (iolink_port_t * port) { if (dl->event_handler.event_confirmation) { - LOG_DEBUG(IOLINK_DL_LOG, "%s: IOL_DL_EVH_ST_IDLE_1: Event confirmation.\n", __func__); + LOG_DEBUG ( + IOLINK_DL_LOG, + "%s: IOL_DL_EVH_ST_IDLE_1: Event confirmation.\n", + __func__); dl->event_handler.state = IOL_DL_EVH_ST_EVENTCONFIRMATION_4; // T7 if (dl->mode_handler.mhinfo == IOLINK_MHINFO_COMLOST) @@ -1556,27 +1830,49 @@ static void iolink_dl_ev_h_sm (iolink_port_t * port) } else { - LOG_DEBUG(IOLINK_DL_LOG, "%s: IOL_DL_EVH_ST_IDLE_1: Written %d to StatusCode.\n", - __func__, dl->txbuffer[0]); - OD_req(dl, IOLINK_RWDIRECTION_WRITE, IOLINK_COMCHANNEL_DIAGNOSIS, 0, 1, dl->txbuffer); + LOG_DEBUG ( + IOLINK_DL_LOG, + "%s: IOL_DL_EVH_ST_IDLE_1: Written %d to StatusCode.\n", + __func__, + dl->txbuffer[0]); + OD_req ( + dl, + IOLINK_RWDIRECTION_WRITE, + IOLINK_COMCHANNEL_DIAGNOSIS, + 0, + 1, + dl->txbuffer); dl->event_handler.event_confirmation = false; dl->event_handler.state = IOL_DL_EVH_ST_IDLE_1; // T8 } } else { - dl->event_handler.ev_addr = 0; + dl->event_handler.ev_addr = 0; dl->event_handler.num_entries = 0; - dl->event_handler.ev_current = 0; - memset(dl->event_handler.events, 0, sizeof(event_t) * IOLINK_MAX_EVENTS); - OD_req(dl, IOLINK_RWDIRECTION_READ, IOLINK_COMCHANNEL_DIAGNOSIS, dl->event_handler.ev_addr, 0, 0); + dl->event_handler.ev_current = 0; + memset ( + dl->event_handler.events, + 0, + sizeof (event_t) * IOLINK_MAX_EVENTS); + OD_req ( + dl, + IOLINK_RWDIRECTION_READ, + IOLINK_COMCHANNEL_DIAGNOSIS, + dl->event_handler.ev_addr, + 0, + 0); dl->event_handler.state = IOL_DL_EVH_ST_READEVENT_2; // T2 } } else { - LOG_ERROR(IOLINK_DL_LOG, "%s: IOL_DL_EVH_ST_IDLE_1: unknown event triggered." - " Trigger: %d.\n", __func__, dl->od_handler.trigger); + LOG_ERROR ( + IOLINK_DL_LOG, + "%s: IOL_DL_EVH_ST_IDLE_1: unknown event triggered." + " Trigger: %d.\n", + __func__, + dl->od_handler.trigger); } break; case IOL_DL_EVH_ST_READEVENT_2: @@ -1586,9 +1882,18 @@ static void iolink_dl_ev_h_sm (iolink_port_t * port) } else if (dl->od_handler.trigger == IOL_TRIGGERED_MASTER_MESSAGE) // T3 { - LOG_DEBUG(IOLINK_DL_LOG, "%s: IOL_DL_EVH_ST_READEVENT_2: Issue read address %d.\n", - __func__, dl->event_handler.ev_addr); - OD_req(dl, IOLINK_RWDIRECTION_READ, IOLINK_COMCHANNEL_DIAGNOSIS, dl->event_handler.ev_addr, 0, 0); + LOG_DEBUG ( + IOLINK_DL_LOG, + "%s: IOL_DL_EVH_ST_READEVENT_2: Issue read address %d.\n", + __func__, + dl->event_handler.ev_addr); + OD_req ( + dl, + IOLINK_RWDIRECTION_READ, + IOLINK_COMCHANNEL_DIAGNOSIS, + dl->event_handler.ev_addr, + 0, + 0); } else if (dl->od_handler.trigger == IOL_TRIGGERED_DEVICE_MESSAGE) // T3 { @@ -1596,10 +1901,14 @@ static void iolink_dl_ev_h_sm (iolink_port_t * port) { dl->event_handler.status_code = dl->rxbuffer[0]; - if (dl->event_handler.status_code & 0x80) // Details (StatusCode type 2) + if (dl->event_handler.status_code & 0x80) // Details (StatusCode + // type 2) { - LOG_DEBUG(IOLINK_DL_LOG, "%s: IOL_DL_EVH_ST_READEVENT_2: Read address %d.\n", - __func__, dl->event_handler.ev_addr); + LOG_DEBUG ( + IOLINK_DL_LOG, + "%s: IOL_DL_EVH_ST_READEVENT_2: Read address %d.\n", + __func__, + dl->event_handler.ev_addr); // Event details for (dl->event_handler.ev_cnt = 0; dl->event_handler.ev_cnt < IOLINK_MAX_EVENTS; @@ -1611,7 +1920,8 @@ static void iolink_dl_ev_h_sm (iolink_port_t * port) if (dl->event_handler.ev_addr == 0) { - dl->event_handler.ev_addr = 1 + dl->event_handler.ev_cnt * 3; + dl->event_handler.ev_addr = + 1 + dl->event_handler.ev_cnt * 3; } } } @@ -1619,16 +1929,20 @@ static void iolink_dl_ev_h_sm (iolink_port_t * port) } else // No details (StatusCode type 1) { - LOG_DEBUG(IOLINK_DL_LOG, "%s: No details event (StatusCode: 0x%X)\n", - __func__, dl->event_handler.status_code); + LOG_DEBUG ( + IOLINK_DL_LOG, + "%s: No details event (StatusCode: 0x%X)\n", + __func__, + dl->event_handler.status_code); - dl->pd_handler.pd_valid = ((dl->event_handler.status_code & BIT(6)) == 0); + dl->pd_handler.pd_valid = + ((dl->event_handler.status_code & BIT (6)) == 0); // Note: There are only 5 events for type 1 uint8_t i; for (i = 0; i < IOLINK_MAX_EVENTS - 1; i++) { - if ((dl->event_handler.status_code & BIT(i)) != 0) + if ((dl->event_handler.status_code & BIT (i)) != 0) { dl->event_handler.num_entries++; } @@ -1640,28 +1954,32 @@ static void iolink_dl_ev_h_sm (iolink_port_t * port) iolink_event_type_t type; } event_info_t; - const event_info_t event_info[] = - { { 0xFF80, IOLINK_EVENT_TYPE_NOTIFICATION }, - { 0xFF80, IOLINK_EVENT_TYPE_WARNING }, - { 0x6320, IOLINK_EVENT_TYPE_ERROR }, - { 0xFF80, IOLINK_EVENT_TYPE_ERROR }, - { 0xFF10, IOLINK_EVENT_TYPE_ERROR } }; + const event_info_t event_info[] = { + {0xFF80, IOLINK_EVENT_TYPE_NOTIFICATION}, + {0xFF80, IOLINK_EVENT_TYPE_WARNING}, + {0x6320, IOLINK_EVENT_TYPE_ERROR}, + {0xFF80, IOLINK_EVENT_TYPE_ERROR}, + {0xFF10, IOLINK_EVENT_TYPE_ERROR}}; for (i = 0; i < IOLINK_MAX_EVENTS - 1; i++) { - if ((dl->event_handler.status_code & BIT(i)) != 0) + if ((dl->event_handler.status_code & BIT (i)) != 0) { dl->event_handler.num_entries--; - uint8_t event_qualifier = IOLINK_EVENT_INSTANCE_APPLICATION | - (IOLINK_EVENT_SOURCE_DEVICE << 3) | - (event_info[i].type << 4) | - (IOLINK_EVENT_MODE_SINGLE_SHOT << 6); - DL_Event_ind (port, event_info[i].code, event_qualifier, - dl->event_handler.num_entries); + uint8_t event_qualifier = + IOLINK_EVENT_INSTANCE_APPLICATION | + (IOLINK_EVENT_SOURCE_DEVICE << 3) | + (event_info[i].type << 4) | + (IOLINK_EVENT_MODE_SINGLE_SHOT << 6); + DL_Event_ind ( + port, + event_info[i].code, + event_qualifier, + dl->event_handler.num_entries); } } dl->event_handler.event_confirmation = true; - dl->event_handler.state = IOL_DL_EVH_ST_IDLE_1; //T4 + T5 + dl->event_handler.state = IOL_DL_EVH_ST_IDLE_1; // T4 + T5 } } else @@ -1669,22 +1987,34 @@ static void iolink_dl_ev_h_sm (iolink_port_t * port) switch (dl->event_handler.ev_addr - (dl->event_handler.ev_cnt * 3)) { case 1: - LOG_DEBUG(IOLINK_DL_LOG, "%s: IOL_DL_EVH_ST_READEVENT_2: Read qualifier: %d\n", - __func__, dl->rxbuffer[0]); - dl->event_handler.events[dl->event_handler.ev_current].event_qualifier = dl->rxbuffer[0]; + LOG_DEBUG ( + IOLINK_DL_LOG, + "%s: IOL_DL_EVH_ST_READEVENT_2: Read qualifier: %d\n", + __func__, + dl->rxbuffer[0]); + dl->event_handler.events[dl->event_handler.ev_current] + .event_qualifier = dl->rxbuffer[0]; dl->event_handler.ev_addr++; break; case 2: - LOG_DEBUG(IOLINK_DL_LOG, "%s: IOL_DL_EVH_ST_READEVENT_2: Read MSB: %d\n", - __func__, dl->rxbuffer[0]); - dl->event_handler.events[dl->event_handler.ev_current].event_code_msb = dl->rxbuffer[0]; + LOG_DEBUG ( + IOLINK_DL_LOG, + "%s: IOL_DL_EVH_ST_READEVENT_2: Read MSB: %d\n", + __func__, + dl->rxbuffer[0]); + dl->event_handler.events[dl->event_handler.ev_current] + .event_code_msb = dl->rxbuffer[0]; dl->event_handler.ev_addr++; break; case 3: - LOG_DEBUG(IOLINK_DL_LOG, "%s: IOL_DL_EVH_ST_READEVENT_2: Read LSB: %d\n", - __func__, dl->rxbuffer[0]); - dl->event_handler.events[dl->event_handler.ev_current].event_code_lsb = dl->rxbuffer[0]; - dl->event_handler.ev_current ++; + LOG_DEBUG ( + IOLINK_DL_LOG, + "%s: IOL_DL_EVH_ST_READEVENT_2: Read LSB: %d\n", + __func__, + dl->rxbuffer[0]); + dl->event_handler.events[dl->event_handler.ev_current] + .event_code_lsb = dl->rxbuffer[0]; + dl->event_handler.ev_current++; while (dl->event_handler.ev_cnt < IOLINK_MAX_EVENTS) { @@ -1699,31 +2029,44 @@ static void iolink_dl_ev_h_sm (iolink_port_t * port) if (dl->event_handler.ev_cnt >= (IOLINK_MAX_EVENTS)) { - LOG_DEBUG(IOLINK_DL_LOG, "%s: IOL_DL_EVH_ST_READEVENT_2: Signal events\n", __func__); + LOG_DEBUG ( + IOLINK_DL_LOG, + "%s: IOL_DL_EVH_ST_READEVENT_2: Signal events\n", + __func__); dl->event_handler.state = IOL_DL_EVH_ST_SIGNALEVENT_3; // T4 if (dl->event_handler.ev_current != dl->event_handler.num_entries) { - LOG_ERROR(IOLINK_DL_LOG, "%s: IOL_DL_EVH_ST_READEVENT_2:" - " Mismatch between number of events indicated and read. Port %d\n", - __func__, iolink_get_portnumber (port)); + LOG_ERROR ( + IOLINK_DL_LOG, + "%s: IOL_DL_EVH_ST_READEVENT_2:" + " Mismatch between number of events indicated and " + "read. Port %d\n", + __func__, + iolink_get_portnumber (port)); } dl->event_handler.ev_current = 0; for (dl->event_handler.ev_current = 0; - dl->event_handler.ev_current < dl->event_handler.num_entries; + dl->event_handler.ev_current < + dl->event_handler.num_entries; dl->event_handler.ev_current++) { - event_t * event = &dl->event_handler.events[dl->event_handler.ev_current]; - - DL_Event_ind (port, - event->event_code_lsb + - (event->event_code_msb << 8), - event->event_qualifier, - dl->event_handler.num_entries - dl->event_handler.ev_current - 1); + event_t * event = + &dl->event_handler.events[dl->event_handler.ev_current]; + + DL_Event_ind ( + port, + event->event_code_lsb + (event->event_code_msb << 8), + event->event_qualifier, + dl->event_handler.num_entries - + dl->event_handler.ev_current - 1); } - LOG_DEBUG(IOLINK_DL_LOG, "%s: IOL_DL_EVH_ST_READEVENT_2: Return to IDLE\n", __func__); + LOG_DEBUG ( + IOLINK_DL_LOG, + "%s: IOL_DL_EVH_ST_READEVENT_2: Return to IDLE\n", + __func__); dl->event_handler.event_confirmation = true; dl->event_handler.state = IOL_DL_EVH_ST_IDLE_1; // T5 } @@ -1733,16 +2076,24 @@ static void iolink_dl_ev_h_sm (iolink_port_t * port) } else { - LOG_ERROR(IOLINK_DL_LOG, "%s: IOL_DL_EVH_ST_READEVENT_2: unknown event triggered." - " Port %d\n", __func__, iolink_get_portnumber (port)); + LOG_ERROR ( + IOLINK_DL_LOG, + "%s: IOL_DL_EVH_ST_READEVENT_2: unknown event triggered." + " Port %d\n", + __func__, + iolink_get_portnumber (port)); } break; case IOL_DL_EVH_ST_SIGNALEVENT_3: case IOL_DL_EVH_ST_EVENTCONFIRMATION_4: // Not used. Inlined - LOG_ERROR(IOLINK_DL_LOG, "%s: IOL_DL_EVH_ST_%s: State not used, yet entered.\n", __func__, - (dl->event_handler.state == IOL_DL_EVH_ST_SIGNALEVENT_3) ? - "SIGNALEVENT_3" : "EVENTCONFIRMATION_4"); + LOG_ERROR ( + IOLINK_DL_LOG, + "%s: IOL_DL_EVH_ST_%s: State not used, yet entered.\n", + __func__, + (dl->event_handler.state == IOL_DL_EVH_ST_SIGNALEVENT_3) + ? "SIGNALEVENT_3" + : "EVENTCONFIRMATION_4"); break; } } @@ -1760,8 +2111,11 @@ static void iolink_dl_od_h_sm (iolink_port_t * port) } else if (dl->od_handler.ohcmd != IOL_OHCMD_INACTIVE) { - LOG_ERROR(IOLINK_DL_LOG, "%s: INACTIVE_0: unknown event triggered. Port %d\n", - __func__, iolink_get_portnumber (port)); + LOG_ERROR ( + IOLINK_DL_LOG, + "%s: INACTIVE_0: unknown event triggered. Port %d\n", + __func__, + iolink_get_portnumber (port)); } break; case IOL_DL_ODH_ST_ISDU_1: @@ -1769,10 +2123,11 @@ static void iolink_dl_od_h_sm (iolink_port_t * port) { dl->od_handler.state = IOL_DL_ODH_ST_INACTIVE_0; // T13 } - else if ((dl->cmd_handler.control_code != IOLINK_CONTROLCODE_NONE) && - (dl->od_handler.trigger == IOL_TRIGGERED_MASTER_MESSAGE)) + else if ( + (dl->cmd_handler.control_code != IOLINK_CONTROLCODE_NONE) && + (dl->od_handler.trigger == IOL_TRIGGERED_MASTER_MESSAGE)) { - iolink_dl_cmd_h_sm(port); + iolink_dl_cmd_h_sm (port); dl->od_handler.state = IOL_DL_ODH_ST_COMMAND_2; // T3 } else if (dl->event_handler.event_flag) @@ -1787,8 +2142,11 @@ static void iolink_dl_od_h_sm (iolink_port_t * port) } else { - LOG_ERROR(IOLINK_DL_LOG, "%s: IOL_DL_ODH_ST_ISDU_1: unknown event triggered. Trigger: %d.\n", - __func__, dl->od_handler.trigger); + LOG_ERROR ( + IOLINK_DL_LOG, + "%s: IOL_DL_ODH_ST_ISDU_1: unknown event triggered. Trigger: %d.\n", + __func__, + dl->od_handler.trigger); } break; case IOL_DL_ODH_ST_COMMAND_2: @@ -1802,7 +2160,7 @@ static void iolink_dl_od_h_sm (iolink_port_t * port) if (dl->cmd_handler.control_code == IOLINK_CONTROLCODE_NONE) { - write_master_command(port, IOLINK_STATUS_NO_ERROR); + write_master_command (port, IOLINK_STATUS_NO_ERROR); if (dl->event_handler.event_flag) { @@ -1816,8 +2174,12 @@ static void iolink_dl_od_h_sm (iolink_port_t * port) } else { - LOG_ERROR(IOLINK_DL_LOG, "%s: IOL_DL_ODH_ST_COMMAND_2: unknown event triggered. Trigger: %d.\n", - __func__, dl->od_handler.trigger); + LOG_ERROR ( + IOLINK_DL_LOG, + "%s: IOL_DL_ODH_ST_COMMAND_2: unknown event triggered. Trigger: " + "%d.\n", + __func__, + dl->od_handler.trigger); } break; case IOL_DL_ODH_ST_EVENT_3: @@ -1825,16 +2187,20 @@ static void iolink_dl_od_h_sm (iolink_port_t * port) { dl->od_handler.state = IOL_DL_ODH_ST_INACTIVE_0; // T12 } - else if ((dl->cmd_handler.control_code != IOLINK_CONTROLCODE_NONE) && - (dl->od_handler.trigger == IOL_TRIGGERED_MASTER_MESSAGE)) + else if ( + (dl->cmd_handler.control_code != IOLINK_CONTROLCODE_NONE) && + (dl->od_handler.trigger == IOL_TRIGGERED_MASTER_MESSAGE)) { - iolink_dl_cmd_h_sm(port); + iolink_dl_cmd_h_sm (port); dl->od_handler.state = IOL_DL_ODH_ST_COMMAND_2; // T7 } else if (!dl->event_handler.event_flag) { - LOG_DEBUG(IOLINK_DL_LOG, "%s: Event ended. Back to ISDU. Trigger: %d\n", - __func__, dl->od_handler.trigger); + LOG_DEBUG ( + IOLINK_DL_LOG, + "%s: Event ended. Back to ISDU. Trigger: %d\n", + __func__, + dl->od_handler.trigger); dl->od_handler.state = IOL_DL_ODH_ST_ISDU_1; // T6 } else if (dl->od_handler.trigger != IOL_TRIGGERED_NONE) // T10 @@ -1844,8 +2210,12 @@ static void iolink_dl_od_h_sm (iolink_port_t * port) } else { - LOG_ERROR(IOLINK_DL_LOG, "%s: IOL_DL_ODH_ST_EVENT_3: unknown event triggered. Trigger: %d.\n", - __func__, dl->od_handler.trigger); + LOG_ERROR ( + IOLINK_DL_LOG, + "%s: IOL_DL_ODH_ST_EVENT_3: unknown event triggered. Trigger: " + "%d.\n", + __func__, + dl->od_handler.trigger); } break; } @@ -1854,30 +2224,43 @@ static void iolink_dl_od_h_sm (iolink_port_t * port) /* * DL-A services */ -static iolink_error_t OD_req(iolink_dl_t *dl, iolink_rwdirection_t rwdirection, - iolink_comchannel_t comchannel, uint8_t addressctrl, - uint8_t length, uint8_t *data) +static iolink_error_t OD_req ( + iolink_dl_t * dl, + iolink_rwdirection_t rwdirection, + iolink_comchannel_t comchannel, + uint8_t addressctrl, + uint8_t length, + uint8_t * data) { if (length > 32) { - LOG_ERROR(IOLINK_DL_LOG, "%s: length not valid: %d\n", __func__, length); + LOG_ERROR (IOLINK_DL_LOG, "%s: length not valid: %d\n", __func__, length); return IOLINK_ERROR_ODLENGTH; } if (addressctrl > 31) { - LOG_ERROR(IOLINK_DL_LOG, "%s: address not valid: %d\n", __func__, addressctrl); + LOG_ERROR ( + IOLINK_DL_LOG, + "%s: address not valid: %d\n", + __func__, + addressctrl); return IOLINK_ERROR_ADDRESS_INVALID; } - if ((comchannel != IOLINK_COMCHANNEL_DIAGNOSIS) && - (comchannel != IOLINK_COMCHANNEL_PAGE) && - (comchannel != IOLINK_COMCHANNEL_ISDU) && - (comchannel != IOLINK_COMCHANNEL_PROCESS)) + if ( + (comchannel != IOLINK_COMCHANNEL_DIAGNOSIS) && + (comchannel != IOLINK_COMCHANNEL_PAGE) && + (comchannel != IOLINK_COMCHANNEL_ISDU) && + (comchannel != IOLINK_COMCHANNEL_PROCESS)) { - LOG_ERROR(IOLINK_DL_LOG, "%s: com channel not valid: %d\n", __func__, comchannel); + LOG_ERROR ( + IOLINK_DL_LOG, + "%s: com channel not valid: %d\n", + __func__, + comchannel); return IOLINK_ERROR_COMCHANNEL_INVALID; } @@ -1892,15 +2275,18 @@ static iolink_error_t OD_req(iolink_dl_t *dl, iolink_rwdirection_t rwdirection, { dl->od_handler.od_txlen = dl->message_handler.od_len; dl->od_handler.od_rxlen = 0; - os_mutex_lock(dl->mtx); - memcpy(dl->od_handler.odout_buffer, data, length); + os_mutex_lock (dl->mtx); + memcpy (dl->od_handler.odout_buffer, data, length); if (length < dl->message_handler.od_len) { - memset(&dl->od_handler.odout_buffer[length], 0, dl->message_handler.od_len - length); + memset ( + &dl->od_handler.odout_buffer[length], + 0, + dl->message_handler.od_len - length); } - os_mutex_unlock(dl->mtx); + os_mutex_unlock (dl->mtx); } else if (rwdirection == IOLINK_RWDIRECTION_READ) { @@ -1912,26 +2298,39 @@ static iolink_error_t OD_req(iolink_dl_t *dl, iolink_rwdirection_t rwdirection, return IOLINK_ERROR_NONE; } -static iolink_error_t PD_req(iolink_dl_t *dl, uint8_t pdinaddress, uint8_t pdinlength, - uint8_t *pdout, uint8_t pdoutaddress, uint8_t pdoutlength) +static iolink_error_t PD_req ( + iolink_dl_t * dl, + uint8_t pdinaddress, + uint8_t pdinlength, + uint8_t * pdout, + uint8_t pdoutaddress, + uint8_t pdoutlength) { if (pdinlength > 32) { - LOG_ERROR(IOLINK_DL_LOG, "%s: pdinlength not valid: %d\n", __func__, pdinlength); + LOG_ERROR ( + IOLINK_DL_LOG, + "%s: pdinlength not valid: %d\n", + __func__, + pdinlength); return IOLINK_ERROR_PDINLENGTH; } else if (pdoutlength > 32) { - LOG_ERROR(IOLINK_DL_LOG, "%s: pdoutlength not valid: %d\n", __func__, pdoutlength); + LOG_ERROR ( + IOLINK_DL_LOG, + "%s: pdoutlength not valid: %d\n", + __func__, + pdoutlength); return IOLINK_ERROR_PDOUTLENGTH; } else if (pdout != NULL) { - os_mutex_lock(dl->mtx); - memcpy(dl->pd_handler.pdout_buffer, &pdout[pdoutaddress], pdoutlength); - os_mutex_unlock(dl->mtx); + os_mutex_lock (dl->mtx); + memcpy (dl->pd_handler.pdout_buffer, &pdout[pdoutaddress], pdoutlength); + os_mutex_unlock (dl->mtx); } return IOLINK_ERROR_NONE; @@ -1940,19 +2339,24 @@ static iolink_error_t PD_req(iolink_dl_t *dl, uint8_t pdinaddress, uint8_t pdinl /* * DL-B services */ -static iolink_error_t OD_cnf(iolink_dl_t *dl, uint8_t *data, uint8_t length, iolink_status_t errorinfo) +static iolink_error_t OD_cnf ( + iolink_dl_t * dl, + uint8_t * data, + uint8_t length, + iolink_status_t errorinfo) { return IOLINK_ERROR_NONE; } -static iolink_error_t PDInStatus_ind (iolink_port_t * port, iolink_controlcode_t status) +static iolink_error_t PDInStatus_ind ( + iolink_port_t * port, + iolink_controlcode_t status) { if (status == IOLINK_CONTROLCODE_NONE) { return IOLINK_ERROR_NONE; } - else if ((status == IOLINK_CONTROLCODE_VALID) || - (status == IOLINK_CONTROLCODE_INVALID)) // cmdh_T2 + else if ((status == IOLINK_CONTROLCODE_VALID) || (status == IOLINK_CONTROLCODE_INVALID)) // cmdh_T2 { DL_Control_ind (port, status); @@ -1962,30 +2366,38 @@ static iolink_error_t PDInStatus_ind (iolink_port_t * port, iolink_controlcode_t return IOLINK_ERROR_STATUS_INVALID; } -static iolink_error_t EventFlag_ind(iolink_dl_t *dl, bool eventflag) +static iolink_error_t EventFlag_ind (iolink_dl_t * dl, bool eventflag) { dl->event_handler.event_flag = eventflag; return IOLINK_ERROR_NONE; } -static iolink_error_t MHInfo_ind(iolink_dl_t *dl, iolink_mhinfo_t mhinfo) +static iolink_error_t MHInfo_ind (iolink_dl_t * dl, iolink_mhinfo_t mhinfo) { dl->mode_handler.mhinfo = mhinfo; - LOG_DEBUG(IOLINK_DL_LOG, "%s: Mode H triggered by MHInfo\n", __func__); - os_event_set(dl->event, IOLINK_DL_EVENT_MDH); + LOG_DEBUG (IOLINK_DL_LOG, "%s: Mode H triggered by MHInfo\n", __func__); + os_event_set (dl->event, IOLINK_DL_EVENT_MDH); return IOLINK_ERROR_NONE; } -static iolink_error_t DL_ReadWrite_req (iolink_port_t * port, uint8_t address, uint8_t value, bool write) +static iolink_error_t DL_ReadWrite_req ( + iolink_port_t * port, + uint8_t address, + uint8_t value, + bool write) { iolink_dl_t * dl = iolink_get_dl_ctx (port); if (dl->message_handler.state != IOL_DL_MH_ST_STARTUP_2) { - LOG_ERROR(IOLINK_DL_LOG, "%s (%s): State not valid: %d\n", __func__, (write) ? "Write" : "Read", - dl->message_handler.state); + LOG_ERROR ( + IOLINK_DL_LOG, + "%s (%s): State not valid: %d\n", + __func__, + (write) ? "Write" : "Read", + dl->message_handler.state); if (write) { @@ -2000,8 +2412,12 @@ static iolink_error_t DL_ReadWrite_req (iolink_port_t * port, uint8_t address, u } else if (address > 15) { - LOG_ERROR(IOLINK_DL_LOG, "%s (%s): Address not valid. Must be 15 or less: %d\n", __func__, - (write) ? "Write" : "Read", address); + LOG_ERROR ( + IOLINK_DL_LOG, + "%s (%s): Address not valid. Must be 15 or less: %d\n", + __func__, + (write) ? "Write" : "Read", + address); if (write) { @@ -2018,7 +2434,8 @@ static iolink_error_t DL_ReadWrite_req (iolink_port_t * port, uint8_t address, u #if IOLINK_HW == IOLINK_HW_MAX14819 if (!write) { - /* MAX14819 will make the initial read of MIN_CYCL. Hence, ignore this first read req. */ + /* MAX14819 will make the initial read of MIN_CYCL. Hence, ignore this + * first read req. */ if (address == IOL_DIR_PARAMA_MIN_CYCL) { if (dl->first_read_min_cycl) @@ -2032,8 +2449,9 @@ static iolink_error_t DL_ReadWrite_req (iolink_port_t * port, uint8_t address, u } #endif /* IOLINK_HW_MAX14819 */ - dl->txbuffer[0] = ((write) ? IOLINK_RWDIRECTION_WRITE : IOLINK_RWDIRECTION_READ) | - IOLINK_COMCHANNEL_PAGE | address; + dl->txbuffer[0] = + ((write) ? IOLINK_RWDIRECTION_WRITE : IOLINK_RWDIRECTION_READ) | + IOLINK_COMCHANNEL_PAGE | address; dl->txbuffer[1] = (IOLINK_MSEQTYPE_TYPE_0 & 0xF0) << 2; if (write) @@ -2041,11 +2459,12 @@ static iolink_error_t DL_ReadWrite_req (iolink_port_t * port, uint8_t address, u dl->txbuffer[2] = value; } - dl->od_handler.od_rxlen = (write) ? 0 : 1; - dl->od_handler.od_txlen = (write) ? 1 : 0; + dl->od_handler.od_rxlen = (write) ? 0 : 1; + dl->od_handler.od_txlen = (write) ? 1 : 0; dl->message_handler.rwcmd = (write) ? IOL_MHRW_WRITE : IOL_MHRW_READ; - //LOG_DEBUG(IOLINK_DL_LOG, "Message H triggered by DL_%s\n", (write) ? "Write" : "Read"); - os_event_set(dl->event, IOLINK_DL_EVENT_MH); + // LOG_DEBUG(IOLINK_DL_LOG, "Message H triggered by DL_%s\n", (write) ? + // "Write" : "Read"); + os_event_set (dl->event, IOLINK_DL_EVENT_MH); return IOLINK_ERROR_NONE; } @@ -2060,23 +2479,25 @@ iolink_error_t DL_Write_req (iolink_port_t * port, uint8_t address, uint8_t valu return DL_ReadWrite_req (port, address, value, true); } -iolink_error_t DL_SetMode_req (iolink_port_t * port, iolink_dl_mode_t mode, iolink_mode_vl_t *valuelist) +iolink_error_t DL_SetMode_req ( + iolink_port_t * port, + iolink_dl_mode_t mode, + iolink_mode_vl_t * valuelist) { iolink_dl_t * dl = iolink_get_dl_ctx (port); - if ((mode != IOLINK_DLMODE_INACTIVE) && - (mode != IOLINK_DLMODE_STARTUP) && - (mode != IOLINK_DLMODE_PREOPERATE) && - (mode != IOLINK_DLMODE_OPERATE)) + if ( + (mode != IOLINK_DLMODE_INACTIVE) && (mode != IOLINK_DLMODE_STARTUP) && + (mode != IOLINK_DLMODE_PREOPERATE) && (mode != IOLINK_DLMODE_OPERATE)) { - LOG_ERROR(IOLINK_DL_LOG, "%s: Mode not valid: %d\n", __func__, mode); + LOG_ERROR (IOLINK_DL_LOG, "%s: Mode not valid: %d\n", __func__, mode); return IOLINK_ERROR_MODE_INVALID; } dl->mode_handler.dl_mode = mode; - dl->mseq = valuelist->type; - dl->cycbyte = valuelist->time; + dl->mseq = valuelist->type; + dl->cycbyte = valuelist->time; /* Don't assign the message_handler members if we switch to inactive. * When we switch to inactive, the communication is still active while we @@ -2088,26 +2509,40 @@ iolink_error_t DL_SetMode_req (iolink_port_t * port, iolink_dl_mode_t mode, ioli { dl->message_handler.pd_rxlen = valuelist->pdinputlength; dl->message_handler.pd_txlen = valuelist->pdoutputlength; - dl->message_handler.od_len = valuelist->onreqdatalengthpermessage; + dl->message_handler.od_len = valuelist->onreqdatalengthpermessage; } - LOG_DEBUG(IOLINK_DL_LOG, "%s: Mode H triggered by DL_SetMode (mode = %d)\n", __func__, mode); - os_event_set(dl->event, IOLINK_DL_EVENT_MDH); + LOG_DEBUG ( + IOLINK_DL_LOG, + "%s: Mode H triggered by DL_SetMode (mode = %d)\n", + __func__, + mode); + os_event_set (dl->event, IOLINK_DL_EVENT_MDH); return IOLINK_ERROR_NONE; } -static iolink_error_t DL_ReadWriteParam_req (iolink_port_t * port, uint8_t address, uint8_t value, bool write) +static iolink_error_t DL_ReadWriteParam_req ( + iolink_port_t * port, + uint8_t address, + uint8_t value, + bool write) { iolink_dl_t * dl = iolink_get_dl_ctx (port); - dl->message_handler.rwcmd = (write) ? IOL_MHRW_WRITEPARAM : IOL_MHRW_READPARAM; + dl->message_handler.rwcmd = (write) ? IOL_MHRW_WRITEPARAM + : IOL_MHRW_READPARAM; - if ((dl->message_handler.state != IOL_DL_MH_ST_PREOPERATE_6) && - (dl->message_handler.state != IOL_DL_MH_ST_AW_REPLY_16)) + if ( + (dl->message_handler.state != IOL_DL_MH_ST_PREOPERATE_6) && + (dl->message_handler.state != IOL_DL_MH_ST_AW_REPLY_16)) { - LOG_ERROR(IOLINK_DL_LOG, "%s (%s): State not valid: %d\n", __func__, (write) ? "Write" : "Read", - dl->message_handler.state); + LOG_ERROR ( + IOLINK_DL_LOG, + "%s (%s): State not valid: %d\n", + __func__, + (write) ? "Write" : "Read", + dl->message_handler.state); if (write) { @@ -2122,8 +2557,12 @@ static iolink_error_t DL_ReadWriteParam_req (iolink_port_t * port, uint8_t addre } else if (address > 31) { - LOG_ERROR(IOLINK_DL_LOG, "%s (%s): Address not valid. Must be 31 or less: %d\n", __func__, - (write) ? "Write" : "Read", address); + LOG_ERROR ( + IOLINK_DL_LOG, + "%s (%s): Address not valid. Must be 31 or less: %d\n", + __func__, + (write) ? "Write" : "Read", + address); if (write) { @@ -2137,7 +2576,7 @@ static iolink_error_t DL_ReadWriteParam_req (iolink_port_t * port, uint8_t addre return IOLINK_ERROR_ADDRESS_INVALID; } - os_mutex_lock(dl->mtx); + os_mutex_lock (dl->mtx); dl->od_handler.data_addr = address; if (write) @@ -2145,11 +2584,11 @@ static iolink_error_t DL_ReadWriteParam_req (iolink_port_t * port, uint8_t addre dl->od_handler.data_value = value; } - os_mutex_unlock(dl->mtx); + os_mutex_unlock (dl->mtx); if (dl->mode_handler.state == IOL_DL_MDH_ST_PREOPERATE_3) { - os_event_set(dl->event, IOLINK_DL_EVENT_MH); + os_event_set (dl->event, IOLINK_DL_EVENT_MH); } return IOLINK_ERROR_NONE; @@ -2157,25 +2596,28 @@ static iolink_error_t DL_ReadWriteParam_req (iolink_port_t * port, uint8_t addre iolink_error_t DL_ReadParam_req (iolink_port_t * port, uint8_t address) { - return DL_ReadWriteParam_req(port, address, 0, false); + return DL_ReadWriteParam_req (port, address, 0, false); } iolink_error_t DL_WriteParam_req (iolink_port_t * port, uint8_t address, uint8_t value) { - return DL_ReadWriteParam_req(port, address, value, true); + return DL_ReadWriteParam_req (port, address, value, true); } -iolink_error_t DL_ISDUTransport_req (iolink_port_t * port, iolink_isdu_vl_t *valuelist) +iolink_error_t DL_ISDUTransport_req ( + iolink_port_t * port, + iolink_isdu_vl_t * valuelist) { iolink_dl_t * dl = iolink_get_dl_ctx (port); - uint8_t iserv = 0; - uint8_t length = 0; + uint8_t iserv = 0; + uint8_t length = 0; uint8_t overheadlen = 0; - uint8_t dataoffset = 1; + uint8_t dataoffset = 1; - if ((dl->mode_handler.state == IOL_DL_MDH_ST_IDLE_0) || - (dl->mode_handler.state == IOL_DL_MDH_ST_ESTCOM_1)) + if ( + (dl->mode_handler.state == IOL_DL_MDH_ST_IDLE_0) || + (dl->mode_handler.state == IOL_DL_MDH_ST_ESTCOM_1)) { DL_ISDUTransport_cnf (port, 0, 0, 0, IOLINK_STATUS_NO_COMM); @@ -2199,7 +2641,7 @@ iolink_error_t DL_ISDUTransport_req (iolink_port_t * port, iolink_isdu_vl_t *val if (valuelist->readwrite == IOLINK_RWDIRECTION_READ) { dl->isdu_handler.data_dir_read = true; - iserv = 0x08; + iserv = 0x08; } if (valuelist->index < 256) @@ -2221,8 +2663,8 @@ iolink_error_t DL_ISDUTransport_req (iolink_port_t * port, iolink_isdu_vl_t *val overheadlen = 5; } - os_mutex_lock(dl->mtx); - memset(dl->isdu_handler.isdu_data, 0, IOLINK_OD_MAX_SIZE); + os_mutex_lock (dl->mtx); + memset (dl->isdu_handler.isdu_data, 0, IOLINK_OD_MAX_SIZE); if (valuelist->length <= 15 - overheadlen) { @@ -2231,9 +2673,9 @@ iolink_error_t DL_ISDUTransport_req (iolink_port_t * port, iolink_isdu_vl_t *val else { length = 1; - overheadlen ++; + overheadlen++; dl->isdu_handler.isdu_data[1] = valuelist->length + overheadlen; - dataoffset = 2; + dataoffset = 2; } dl->isdu_handler.isdu_data[0] = (iserv << 4) | (length & 0x0F); @@ -2248,28 +2690,35 @@ iolink_error_t DL_ISDUTransport_req (iolink_port_t * port, iolink_isdu_vl_t *val else { dl->isdu_handler.isdu_data[dataoffset] = (valuelist->index) & 0xFF; - dataoffset ++; + dataoffset++; if (valuelist->subindex > 0) { dl->isdu_handler.isdu_data[dataoffset] = valuelist->subindex; - dataoffset ++; + dataoffset++; } } - memcpy(&dl->isdu_handler.isdu_data[dataoffset], valuelist->data_write, valuelist->length); + memcpy ( + &dl->isdu_handler.isdu_data[dataoffset], + valuelist->data_write, + valuelist->length); dataoffset += valuelist->length; - dl->isdu_handler.isdu_data[dataoffset] = calcCHKPDU(dl->isdu_handler.isdu_data, dataoffset); - memset(&dl->isdu_handler.isdu_data[dataoffset + 1], 0, IOLINK_ISDU_MAX_SIZE - (dataoffset + 1)); - dl->isdu_handler.total_isdu_len = valuelist->length + overheadlen; - dl->isdu_handler.total_isdu_seg = get_isdu_total_segments(dl); + dl->isdu_handler.isdu_data[dataoffset] = + calcCHKPDU (dl->isdu_handler.isdu_data, dataoffset); + memset ( + &dl->isdu_handler.isdu_data[dataoffset + 1], + 0, + IOLINK_ISDU_MAX_SIZE - (dataoffset + 1)); + dl->isdu_handler.total_isdu_len = valuelist->length + overheadlen; + dl->isdu_handler.total_isdu_seg = get_isdu_total_segments (dl); dl->isdu_handler.current_isdu_seg = 0; - dl->message_handler.rwcmd = IOL_MHRW_ISDUTRANSPORT; - os_mutex_unlock(dl->mtx); + dl->message_handler.rwcmd = IOL_MHRW_ISDUTRANSPORT; + os_mutex_unlock (dl->mtx); if (dl->mode_handler.state == IOL_DL_MDH_ST_PREOPERATE_3) { - os_event_set(dl->event, IOLINK_DL_EVENT_MH); + os_event_set (dl->event, IOLINK_DL_EVENT_MH); } return IOLINK_ERROR_NONE; @@ -2279,36 +2728,43 @@ iolink_error_t DL_Control_req (iolink_port_t * port, iolink_controlcode_t contro { iolink_dl_t * dl = iolink_get_dl_ctx (port); - if ((controlcode != IOLINK_CONTROLCODE_VALID) && - (controlcode != IOLINK_CONTROLCODE_INVALID) && - (controlcode != IOLINK_CONTROLCODE_PDOUTVALID) && - (controlcode != IOLINK_CONTROLCODE_PDOUTINVALID)) + if ( + (controlcode != IOLINK_CONTROLCODE_VALID) && + (controlcode != IOLINK_CONTROLCODE_INVALID) && + (controlcode != IOLINK_CONTROLCODE_PDOUTVALID) && + (controlcode != IOLINK_CONTROLCODE_PDOUTINVALID)) { return IOLINK_ERROR_CONTROLCODE_INVALID; } dl->cmd_handler.control_code = controlcode; - iolink_dl_cmd_h_sm(port); + iolink_dl_cmd_h_sm (port); return IOLINK_ERROR_NONE; } -iolink_error_t DL_Write_Devicemode_req (iolink_port_t * port, - iolink_dl_mode_t devicemode) +iolink_error_t DL_Write_Devicemode_req ( + iolink_port_t * port, + iolink_dl_mode_t devicemode) { iolink_dl_t * dl = iolink_get_dl_ctx (port); if (dl->mode_handler.state == IOL_DL_MDH_ST_STARTUP_2) { - LOG_ERROR(IOLINK_DL_LOG, "%s: State not valid: %d\n", __func__, - dl->mode_handler.state); - DL_Write_Devicemode_cnf (port, IOLINK_STATUS_STATE_CONFLICT, - IOL_MASTERCMD_NONE); /* Not in spec. */ + LOG_ERROR ( + IOLINK_DL_LOG, + "%s: State not valid: %d\n", + __func__, + dl->mode_handler.state); + DL_Write_Devicemode_cnf ( + port, + IOLINK_STATUS_STATE_CONFLICT, + IOL_MASTERCMD_NONE); /* Not in spec. */ return IOLINK_ERROR_STATE_INVALID; } - os_mutex_lock(dl->mtx); + os_mutex_lock (dl->mtx); switch (devicemode) { @@ -2325,14 +2781,14 @@ iolink_error_t DL_Write_Devicemode_req (iolink_port_t * port, dl->cmd_handler.master_command = IOL_MASTERCMD_DEVICE_OPERATE; break; default: - os_mutex_unlock(dl->mtx); + os_mutex_unlock (dl->mtx); return IOLINK_ERROR_INCORRECT_DATA; // TODO correct error? } - os_mutex_unlock(dl->mtx); + os_mutex_unlock (dl->mtx); dl->cmd_handler.control_code = IOLINK_CONTROLCODE_DEVICEMODE; - iolink_dl_cmd_h_sm(port); + iolink_dl_cmd_h_sm (port); if (dl->mode_handler.state == IOL_DL_MDH_ST_PREOPERATE_3) { @@ -2341,13 +2797,18 @@ iolink_error_t DL_Write_Devicemode_req (iolink_port_t * port, /* Respond with Fallback when we request INACTIVE and we are in preop * Problem seen after TC_0276 */ - DL_Write_Devicemode_cnf (port, IOLINK_STATUS_NO_ERROR, - IOL_MASTERCMD_FALLBACK); /* Not in spec. */ + DL_Write_Devicemode_cnf ( + port, + IOLINK_STATUS_NO_ERROR, + IOL_MASTERCMD_FALLBACK); /* Not in spec. */ } else { - LOG_DEBUG(IOLINK_DL_LOG, "%s: Message H triggered by DL_Write_Devicemode_req\n", __func__); - os_event_set(dl->event, IOLINK_DL_EVENT_MH); + LOG_DEBUG ( + IOLINK_DL_LOG, + "%s: Message H triggered by DL_Write_Devicemode_req\n", + __func__); + os_event_set (dl->event, IOLINK_DL_EVENT_MH); } } @@ -2367,15 +2828,15 @@ iolink_error_t DL_PDOutputGet_req (iolink_port_t * port, uint8_t * len, uint8_t { iolink_dl_t * dl = iolink_get_dl_ctx (port); - os_mutex_lock(dl->mtx); - memcpy(data, dl->pd_handler.pdoutdata, dl->pd_handler.pd_txlen); + os_mutex_lock (dl->mtx); + memcpy (data, dl->pd_handler.pdoutdata, dl->pd_handler.pd_txlen); *len = dl->pd_handler.pd_txlen; - os_mutex_unlock(dl->mtx); + os_mutex_unlock (dl->mtx); return IOLINK_ERROR_NONE; } -iolink_error_t DL_PDOutputUpdate_req (iolink_port_t * port, uint8_t *outputdata) +iolink_error_t DL_PDOutputUpdate_req (iolink_port_t * port, uint8_t * outputdata) { iolink_dl_t * dl = iolink_get_dl_ctx (port); @@ -2384,55 +2845,56 @@ iolink_error_t DL_PDOutputUpdate_req (iolink_port_t * port, uint8_t *outputdata) return IOLINK_ERROR_CONDITIONS_NOT_CORRECT; } - os_mutex_lock(dl->mtx); - memcpy(dl->pd_handler.pdoutdata, outputdata, dl->pd_handler.pd_txlen); + os_mutex_lock (dl->mtx); + memcpy (dl->pd_handler.pdoutdata, outputdata, dl->pd_handler.pd_txlen); - if ((dl->pd_handler.pd_txlen & 1) == 1) // Odd number of bytes, add additional 0 - { // (needed for interleaved communication) + if ((dl->pd_handler.pd_txlen & 1) == 1) // Odd number of bytes, add + // additional 0 + { // (needed for interleaved communication) dl->pd_handler.pdoutdata[dl->pd_handler.pd_txlen] = 0; } - os_mutex_unlock(dl->mtx); + os_mutex_unlock (dl->mtx); return IOLINK_ERROR_NONE; } -static void dl_timer_timeout(os_timer_t *timer, void *arg) +static void dl_timer_timeout (os_timer_t * timer, void * arg) { - os_timer_stop(timer); + os_timer_stop (timer); - iolink_dl_t *dl = (iolink_dl_t *)arg; - os_event_set(dl->event, IOLINK_DL_EVENT_TIMEOUT); + iolink_dl_t * dl = (iolink_dl_t *)arg; + os_event_set (dl->event, IOLINK_DL_EVENT_TIMEOUT); } -static void dl_timer_tcyc_timeout(os_timer_t *timer, void *arg) +static void dl_timer_tcyc_timeout (os_timer_t * timer, void * arg) { - os_timer_stop(timer); + os_timer_stop (timer); - iolink_dl_t *dl = (iolink_dl_t *)arg; - os_event_set(dl->event, IOLINK_DL_EVENT_TIMEOUT_TCYC); + iolink_dl_t * dl = (iolink_dl_t *)arg; + os_event_set (dl->event, IOLINK_DL_EVENT_TIMEOUT_TCYC); } static inline void iolink_dl_wurq_recv (iolink_port_t * port) { iolink_dl_t * dl = iolink_get_dl_ctx (port); - dl->baudrate = iolink_pl_get_baudrate (port); + dl->baudrate = iolink_pl_get_baudrate (port); if (dl->baudrate == IOLINK_BAUDRATE_NONE) { // WURQ Failed - dl->mode_handler.state = IOL_DL_MDH_ST_IDLE_0; // mdh_T5 + dl->mode_handler.state = IOL_DL_MDH_ST_IDLE_0; // mdh_T5 dl->mode_handler.mhinfo = IOLINK_MHINFO_NONE; DL_Mode_ind (port, IOLINK_MHMODE_INACTIVE); return; } - dl->cycbyte = iolink_pl_get_cycletime (port); - dl->mode_handler.state = IOL_DL_MDH_ST_STARTUP_2; // mdh_T2/T3/T4 + dl->cycbyte = iolink_pl_get_cycletime (port); + dl->mode_handler.state = IOL_DL_MDH_ST_STARTUP_2; // mdh_T2/T3/T4 dl->message_handler.state = IOL_DL_MH_ST_AW_REPLY_1; // mh_T1 iolink_dl_message_h_sm (port); - CH_Conf(port, IOL_CHCMD_ACTIVE); + CH_Conf (port, IOL_CHCMD_ACTIVE); DL_Mode_ind (port, IOLINK_MHMODE_STARTUP); switch (dl->baudrate) @@ -2447,16 +2909,20 @@ static inline void iolink_dl_wurq_recv (iolink_port_t * port) DL_Mode_ind_baud (port, IOLINK_MHMODE_COM3); break; default: - LOG_ERROR(IOLINK_DL_LOG, "%s: Baudrate not valid: %d\n", __func__, dl->baudrate); + LOG_ERROR ( + IOLINK_DL_LOG, + "%s: Baudrate not valid: %d\n", + __func__, + dl->baudrate); DL_Mode_ind_baud (port, IOLINK_MHMODE_INACTIVE); - dl->mode_handler.state = IOL_DL_MDH_ST_IDLE_0; + dl->mode_handler.state = IOL_DL_MDH_ST_IDLE_0; dl->message_handler.state = IOL_DL_MH_ST_INACTIVE_0; - CH_Conf(port, IOL_CHCMD_INACTIVE); + CH_Conf (port, IOL_CHCMD_INACTIVE); break; } iolink_pl_get_error (port, &dl->cqerr, &dl->devdly); - os_event_set(dl->event, IOLINK_DL_EVENT_MH); + os_event_set (dl->event, IOLINK_DL_EVENT_MH); } static inline void iolink_dl_handle_error (iolink_port_t * port) @@ -2466,12 +2932,12 @@ static inline void iolink_dl_handle_error (iolink_port_t * port) iolink_pl_get_error (port, &dl->cqerr, &dl->devdly); - if ((dl->devdly & BIT(7)) != 0) // DelayErr + if ((dl->devdly & BIT (7)) != 0) // DelayErr { dl->rxtimeout = true; iolink_dl_message_h_sm (port); } - else if ((dl->cqerr & (BIT(3) | BIT(1) | BIT(0))) != 0) // RChksmEr/FrameErr/ParityErr + else if ((dl->cqerr & (BIT (3) | BIT (1) | BIT (0))) != 0) // RChksmEr/FrameErr/ParityErr { dl->rxerror = true; iolink_dl_message_h_sm (port); @@ -2482,13 +2948,14 @@ static inline void iolink_dl_handle_error (iolink_port_t * port) /* * Thread handling one DL and associated PL */ -static void dl_main(void *arg) +static void dl_main (void * arg) { iolink_port_t * port = arg; - iolink_dl_t * dl = iolink_get_dl_ctx (port); + iolink_dl_t * dl = iolink_get_dl_ctx (port); - uint32_t mask = IOLINK_PL_EVENT | IOLINK_PL_EVENT_RXRDY | IOLINK_PL_EVENT_RXERR | - IOLINK_PL_EVENT_TXERR | IOLINK_PL_EVENT_WURQ | IOLINK_DL_EVENT_MDH | + uint32_t mask = IOLINK_PL_EVENT | IOLINK_PL_EVENT_RXRDY | + IOLINK_PL_EVENT_RXERR | IOLINK_PL_EVENT_TXERR | + IOLINK_PL_EVENT_WURQ | IOLINK_DL_EVENT_MDH | IOLINK_DL_EVENT_MH | IOLINK_DL_EVENT_TIMEOUT | IOLINK_DL_EVENT_TIMEOUT_TCYC; uint32_t event_timeout = (uint32_t)-1; @@ -2498,7 +2965,7 @@ static void dl_main(void *arg) { if (!os_event_wait (dl->event, mask, &dl->triggered_events, event_timeout)) { - os_event_clr(dl->event, dl->triggered_events); + os_event_clr (dl->event, dl->triggered_events); if (dl->triggered_events & IOLINK_PL_EVENT) { @@ -2509,8 +2976,10 @@ static void dl_main(void *arg) if (dl->triggered_events & IOLINK_PL_EVENT_RXRDY) { // Event handler for data ready - iolink_pl_get_data (port, dl->rxbuffer, - dl->message_handler.od_len + dl->message_handler.pd_rxlen + 1); + iolink_pl_get_data ( + port, + dl->rxbuffer, + dl->message_handler.od_len + dl->message_handler.pd_rxlen + 1); dl->dataready = true; iolink_dl_message_h_sm (port); } @@ -2550,13 +3019,16 @@ static void dl_main(void *arg) if (dl->triggered_events & IOLINK_DL_EVENT_TIMEOUT) { // Timer timeout - os_event_clr(dl->event, IOLINK_DL_EVENT_TIMEOUT); + os_event_clr (dl->event, IOLINK_DL_EVENT_TIMEOUT); switch (dl->timer_type) { case IOL_DL_TIMER_TINITCYC_MH: - LOG_DEBUG(IOLINK_DL_LOG, "%s: TInitcyc timed out. IOL_DL_MH state: %s\n", - __func__, iolink_dl_mh_st_literals[dl->message_handler.state]); + LOG_DEBUG ( + IOLINK_DL_LOG, + "%s: TInitcyc timed out. IOL_DL_MH state: %s\n", + __func__, + iolink_dl_mh_st_literals[dl->message_handler.state]); dl->timer_elapsed = true; iolink_dl_message_h_sm (port); dl->timer_elapsed = false; @@ -2573,63 +3045,74 @@ static void dl_main(void *arg) void iolink_dl_reset (iolink_port_t * port) { - LOG_DEBUG(IOLINK_DL_LOG, "%s\n", __func__); + LOG_DEBUG (IOLINK_DL_LOG, "%s\n", __func__); iolink_dl_t * dl = iolink_get_dl_ctx (port); - memset(&dl->mode_handler, 0, sizeof(mode_h_t)); - memset(&dl->message_handler, 0, sizeof(message_h_t)); - memset(&dl->pd_handler, 0, sizeof(pd_handler_t)); - memset(&dl->od_handler, 0, sizeof(od_handler_t)); - memset(&dl->cmd_handler, 0, sizeof(command_h_t)); - memset(&dl->isdu_handler, 0, sizeof(isdu_h_t)); - memset(&dl->event_handler, 0, sizeof(event_h_t)); + memset (&dl->mode_handler, 0, sizeof (mode_h_t)); + memset (&dl->message_handler, 0, sizeof (message_h_t)); + memset (&dl->pd_handler, 0, sizeof (pd_handler_t)); + memset (&dl->od_handler, 0, sizeof (od_handler_t)); + memset (&dl->cmd_handler, 0, sizeof (command_h_t)); + memset (&dl->isdu_handler, 0, sizeof (isdu_h_t)); + memset (&dl->event_handler, 0, sizeof (event_h_t)); dl->pd_handler.pdout_buffer = &dl->txbuffer[2]; dl->od_handler.odout_buffer = &dl->txbuffer[2]; - dl->baudrate = IOLINK_BAUDRATE_NONE; - dl->cycbyte = iolink_pl_get_cycletime (port); - dl->mseq = IOLINK_MSEQTYPE_TYPE_0; - dl->triggered_events = 0; - dl->timer_type = IOL_DL_TIMER_NONE; - dl->timer_elapsed = false; - dl->timer_tcyc_elapsed = false; - dl->dataready = false; - dl->rxerror = false; - dl->rxtimeout = false; - dl->devdly = 0; - dl->cqerr = 0; - dl->first_read_min_cycl = true; + dl->baudrate = IOLINK_BAUDRATE_NONE; + dl->cycbyte = iolink_pl_get_cycletime (port); + dl->mseq = IOLINK_MSEQTYPE_TYPE_0; + dl->triggered_events = 0; + dl->timer_type = IOL_DL_TIMER_NONE; + dl->timer_elapsed = false; + dl->timer_tcyc_elapsed = false; + dl->dataready = false; + dl->rxerror = false; + dl->rxtimeout = false; + dl->devdly = 0; + dl->cqerr = 0; + dl->first_read_min_cycl = true; if (dl->timer_tcyc != NULL) { - os_timer_stop(dl->timer_tcyc); + os_timer_stop (dl->timer_tcyc); } if (dl->timer != NULL) { - os_timer_stop(dl->timer); + os_timer_stop (dl->timer); } } /* * Instantiates a specific port object (DL and PL) */ -void iolink_dl_instantiate (iolink_port_t * port, const iolink_port_cfg_t * port_cfg, - unsigned int thread_prio, size_t thread_stack_size) +void iolink_dl_instantiate ( + iolink_port_t * port, + const iolink_port_cfg_t * port_cfg, + unsigned int thread_prio, + size_t thread_stack_size) { - iolink_dl_reset(port); + iolink_dl_reset (port); iolink_dl_t * dl = iolink_get_dl_ctx (port); - dl->mtx = os_mutex_create(); - dl->event = os_event_create(); - dl->timer = os_timer_create(1000, dl_timer_timeout, dl, true); - dl->timer_tcyc = os_timer_create(1000, dl_timer_tcyc_timeout, dl, true); + dl->mtx = os_mutex_create(); + dl->event = os_event_create(); + dl->timer = os_timer_create (1000, dl_timer_timeout, dl, true); + dl->timer_tcyc = os_timer_create (1000, dl_timer_tcyc_timeout, dl, true); uint8_t portnumber = iolink_get_portnumber (port); - snprintf(dl_thread_names[portnumber - 1], IOLINK_DL_THREAD_NAME_LENGTH, "iolport%d", portnumber); - dl->thread = os_thread_create(dl_thread_names[portnumber - 1], thread_prio, - thread_stack_size, dl_main, port); + snprintf ( + dl_thread_names[portnumber - 1], + IOLINK_DL_THREAD_NAME_LENGTH, + "iolport%d", + portnumber); + dl->thread = os_thread_create ( + dl_thread_names[portnumber - 1], + thread_prio, + thread_stack_size, + dl_main, + port); iolink_configure_pl_event (port, dl->event, IOLINK_PL_EVENT); } diff --git a/src/iolink_dl.h b/src/iolink_dl.h index 727e21b..cb3a54d 100644 --- a/src/iolink_dl.h +++ b/src/iolink_dl.h @@ -16,8 +16,7 @@ #include #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif typedef struct iolink_dl iolink_dl_t; @@ -30,18 +29,18 @@ typedef struct iolink_dl iolink_dl_t; * */ -#define IOLINK_PL_EVENT BIT(0) -#define IOLINK_PL_EVENT_RXRDY BIT(1) -#define IOLINK_PL_EVENT_RXERR BIT(2) -#define IOLINK_PL_EVENT_TXERR BIT(3) -#define IOLINK_PL_EVENT_WURQ BIT(4) -#define IOLINK_PL_EVENT_STATUS BIT(5) -#define IOLINK_DL_EVENT_TIMEOUT BIT(10) -#define IOLINK_DL_EVENT_TIMEOUT_TCYC BIT(11) +#define IOLINK_PL_EVENT BIT (0) +#define IOLINK_PL_EVENT_RXRDY BIT (1) +#define IOLINK_PL_EVENT_RXERR BIT (2) +#define IOLINK_PL_EVENT_TXERR BIT (3) +#define IOLINK_PL_EVENT_WURQ BIT (4) +#define IOLINK_PL_EVENT_STATUS BIT (5) +#define IOLINK_DL_EVENT_TIMEOUT BIT (10) +#define IOLINK_DL_EVENT_TIMEOUT_TCYC BIT (11) //#define IOLINK_DL_EVENT_ODH BIT(12) //#define IOLINK_DL_EVENT_PDH BIT(13) -#define IOLINK_DL_EVENT_MDH BIT(14) -#define IOLINK_DL_EVENT_MH BIT(15) +#define IOLINK_DL_EVENT_MDH BIT (14) +#define IOLINK_DL_EVENT_MH BIT (15) typedef enum { @@ -206,126 +205,126 @@ typedef enum typedef struct { - dl_pdh_st_t state; - PHCmd_t phcmd; - iol_trigger_t trigger; - uint8_t pd_address; - uint8_t pd_rxlen; - uint8_t pd_txlen; - uint8_t pdoutdata[IOLINK_PD_MAX_SIZE]; - uint8_t pdindata[IOLINK_PD_MAX_SIZE]; - uint8_t *pdout_buffer; - bool pd_valid; + dl_pdh_st_t state; + PHCmd_t phcmd; + iol_trigger_t trigger; + uint8_t pd_address; + uint8_t pd_rxlen; + uint8_t pd_txlen; + uint8_t pdoutdata[IOLINK_PD_MAX_SIZE]; + uint8_t pdindata[IOLINK_PD_MAX_SIZE]; + uint8_t * pdout_buffer; + bool pd_valid; } pd_handler_t; typedef struct { - dl_odh_st_t state; - OHCmd_t ohcmd; - iol_trigger_t trigger; - uint8_t od_rxlen; - uint8_t od_txlen; - uint8_t data_addr; - uint8_t data_value; - uint8_t *odout_buffer; + dl_odh_st_t state; + OHCmd_t ohcmd; + iol_trigger_t trigger; + uint8_t od_rxlen; + uint8_t od_txlen; + uint8_t data_addr; + uint8_t data_value; + uint8_t * odout_buffer; } od_handler_t; typedef struct { - dl_mh_st_t state; - MHCmd_t mhcmd; - MHRWCmd rwcmd; - uint8_t pd_rxlen; - uint8_t pd_txlen; - uint8_t od_len; - uint8_t cks; - uint8_t retry; - dl_interleave_t interleave; + dl_mh_st_t state; + MHCmd_t mhcmd; + MHRWCmd rwcmd; + uint8_t pd_rxlen; + uint8_t pd_txlen; + uint8_t od_len; + uint8_t cks; + uint8_t retry; + dl_interleave_t interleave; } message_h_t; typedef struct { - dl_mdh_st_t state; - iolink_dl_mode_t dl_mode; - iolink_mhinfo_t mhinfo; + dl_mdh_st_t state; + iolink_dl_mode_t dl_mode; + iolink_mhinfo_t mhinfo; } mode_h_t; typedef struct { - dl_cmdh_st_t state; - CHCmd_t chcmd; + dl_cmdh_st_t state; + CHCmd_t chcmd; iolink_controlcode_t control_code; - uint8_t master_command; + uint8_t master_command; } command_h_t; typedef struct { - dl_isduh_st_t state; - IHCmd_t ihcmd; - uint8_t total_isdu_len; - uint8_t current_isdu_seg; - uint8_t total_isdu_seg; - uint8_t isdu_data[IOLINK_ISDU_MAX_SIZE]; - uint32_t isdu_timer; - bool data_dir_read; + dl_isduh_st_t state; + IHCmd_t ihcmd; + uint8_t total_isdu_len; + uint8_t current_isdu_seg; + uint8_t total_isdu_seg; + uint8_t isdu_data[IOLINK_ISDU_MAX_SIZE]; + uint32_t isdu_timer; + bool data_dir_read; } isdu_h_t; typedef struct { - uint8_t event_qualifier; - uint8_t event_code_msb; - uint8_t event_code_lsb; + uint8_t event_qualifier; + uint8_t event_code_msb; + uint8_t event_code_lsb; } event_t; typedef struct { - dl_evh_st_t state; - EHCmd_t ehcmd; - bool event_flag; - bool event_confirmation; - uint8_t ev_addr; - uint8_t status_code; - uint8_t num_entries; - uint8_t ev_cnt; - uint8_t ev_current; - event_t events[IOLINK_MAX_EVENTS]; + dl_evh_st_t state; + EHCmd_t ehcmd; + bool event_flag; + bool event_confirmation; + uint8_t ev_addr; + uint8_t status_code; + uint8_t num_entries; + uint8_t ev_cnt; + uint8_t ev_current; + event_t events[IOLINK_MAX_EVENTS]; } event_h_t; typedef struct iolink_dl { - mode_h_t mode_handler; - message_h_t message_handler; - pd_handler_t pd_handler; - od_handler_t od_handler; - command_h_t cmd_handler; - isdu_h_t isdu_handler; - event_h_t event_handler; + mode_h_t mode_handler; + message_h_t message_handler; + pd_handler_t pd_handler; + od_handler_t od_handler; + command_h_t cmd_handler; + isdu_h_t isdu_handler; + event_h_t event_handler; iolink_baudrate_t baudrate; - uint8_t cycbyte; + uint8_t cycbyte; iolink_msequencetype_t mseq; - os_mutex_t *mtx; - os_thread_t *thread; - os_event_t *event; - uint32_t triggered_events; - os_timer_t *timer; - dl_timer_t timer_type; - bool timer_elapsed; - os_timer_t *timer_tcyc; - bool timer_tcyc_elapsed; + os_mutex_t * mtx; + os_thread_t * thread; + os_event_t * event; + uint32_t triggered_events; + os_timer_t * timer; + dl_timer_t timer_type; + bool timer_elapsed; + os_timer_t * timer_tcyc; + bool timer_tcyc_elapsed; - bool dataready; - bool rxerror; - bool rxtimeout; + bool dataready; + bool rxerror; + bool rxtimeout; #if IOLINK_HW == IOLINK_HW_MAX14819 - bool first_read_min_cycl; - uint8_t devdly; - uint8_t cqerr; - uint8_t txbuffer[IOLINK_RXTX_BUFFER_SIZE]; - uint8_t rxbuffer[IOLINK_RXTX_BUFFER_SIZE]; - uint8_t tinitcyc; + bool first_read_min_cycl; + uint8_t devdly; + uint8_t cqerr; + uint8_t txbuffer[IOLINK_RXTX_BUFFER_SIZE]; + uint8_t rxbuffer[IOLINK_RXTX_BUFFER_SIZE]; + uint8_t tinitcyc; #endif } iolink_dl_t; @@ -334,15 +333,30 @@ typedef struct iolink_dl */ iolink_error_t DL_Read_req (iolink_port_t * port, uint8_t address); iolink_error_t DL_Write_req (iolink_port_t * port, uint8_t address, uint8_t value); -iolink_error_t DL_SetMode_req (iolink_port_t * port, iolink_dl_mode_t mode, iolink_mode_vl_t *valuelist); -iolink_error_t DL_Write_Devicemode_req (iolink_port_t * port, iolink_dl_mode_t devicemode); +iolink_error_t DL_SetMode_req ( + iolink_port_t * port, + iolink_dl_mode_t mode, + iolink_mode_vl_t * valuelist); +iolink_error_t DL_Write_Devicemode_req ( + iolink_port_t * port, + iolink_dl_mode_t devicemode); iolink_error_t DL_ReadParam_req (iolink_port_t * port, uint8_t address); -iolink_error_t DL_WriteParam_req (iolink_port_t * port, uint8_t address, uint8_t value); -iolink_error_t DL_ISDUTransport_req (iolink_port_t * port, iolink_isdu_vl_t *valuelist); -iolink_error_t DL_Control_req (iolink_port_t * port, iolink_controlcode_t controlcode); +iolink_error_t DL_WriteParam_req ( + iolink_port_t * port, + uint8_t address, + uint8_t value); +iolink_error_t DL_ISDUTransport_req ( + iolink_port_t * port, + iolink_isdu_vl_t * valuelist); +iolink_error_t DL_Control_req ( + iolink_port_t * port, + iolink_controlcode_t controlcode); iolink_error_t DL_EventConf_req (iolink_port_t * port); -iolink_error_t DL_PDOutputUpdate_req (iolink_port_t * port, uint8_t *outputdata); -iolink_error_t DL_PDOutputGet_req (iolink_port_t * port, uint8_t * len, uint8_t * data); +iolink_error_t DL_PDOutputUpdate_req (iolink_port_t * port, uint8_t * outputdata); +iolink_error_t DL_PDOutputGet_req ( + iolink_port_t * port, + uint8_t * len, + uint8_t * data); /* * Function interface @@ -357,8 +371,11 @@ iolink_error_t DL_PDOutputGet_req (iolink_port_t * port, uint8_t * len, uint8_t * @param thread_prio Priority of the thread * @param thread_stack_size Stack size of the thread */ -void iolink_dl_instantiate (iolink_port_t * port, const iolink_port_cfg_t * port_cfg, - unsigned int thread_prio, size_t thread_stack_size); +void iolink_dl_instantiate ( + iolink_port_t * port, + const iolink_port_cfg_t * port_cfg, + unsigned int thread_prio, + size_t thread_stack_size); /** * This function resets the data link layer for one port to an initial state. * diff --git a/src/iolink_ds.c b/src/iolink_ds.c index 27f78b6..1c0d596 100644 --- a/src/iolink_ds.c +++ b/src/iolink_ds.c @@ -12,17 +12,17 @@ #ifdef UNIT_TEST #define iolink_fetch_avail_job mock_iolink_fetch_avail_job -#define iolink_post_job mock_iolink_post_job -#define DS_Ready mock_DS_Ready -#define DS_Change mock_DS_Change -#define DS_Fault mock_DS_Fault -#define AL_Read_req mock_AL_Read_req -#define AL_Write_req mock_AL_Write_req +#define iolink_post_job mock_iolink_post_job +#define DS_Ready mock_DS_Ready +#define DS_Change mock_DS_Change +#define DS_Fault mock_DS_Fault +#define AL_Read_req mock_AL_Read_req +#define AL_Write_req mock_AL_Write_req #endif /* UNIT_TEST */ -#define DS_INDEX_LIST_MAX_ENTRIES 70 +#define DS_INDEX_LIST_MAX_ENTRIES 70 -#define DS_PARAM_INDEX 3 +#define DS_PARAM_INDEX 3 #define DS_PARAM_SUBINDEX_CMD 1 #define DS_PARAM_SUBINDEX_STATE 2 @@ -45,8 +45,7 @@ * */ -const char * iolink_ds_state_literals[] = -{ +const char * iolink_ds_state_literals[] = { "CheckActivationState", "WaitingOnDSActivity", "Off", @@ -71,38 +70,36 @@ const char * iolink_ds_state_literals[] = "LAST", }; -const char * iolink_ds_event_literals[] = -{ - "NONE", - "ENABLE", /* T1 */ - "STARTUP", /* T2 or T14 */ - "READY", /* T25, T26 or T27; + T3 */ - "UPLOAD", /* T4 or T13 */ - "FAULT_DONE", /* T5 */ - "FAULT_ID", /* T15 */ - "FAULT_SIZE", /* T17 */ - "FAULT_UL", /* T23 */ - "FAULT_DL", /* T28 */ - "FAULT_LOCK", /* T29 */ - "ENABLE_COM", /* T6 */ - "CLR_DISA", /* T7 */ - "ENABLE_NO_C", /* T8 */ - "DELETE", /* T9 or T11 */ - "CLEAR", /* T11 */ - "DISABLE", /* T12 */ - "PASSED", /* T16, T18 or T22 */ - "DO_UPLOAD", /* T19 or T21 */ - "NO_UPLOAD", /* T20 or T43 */ - "DOWNLOAD", /* T24 */ - "MORE_DATA", /* T30 or T37 */ - "READ_DONE", /* T31 */ - "STORE_DATA", /* T35 */ - "UL_DONE", /* T26 */ - "DEV_ERR", /* T32 or T39 */ - "COM_ERR", /* T33, T34, T36, T40 or T42 */ - "WR_DONE", /* T38 */ - "DL_DONE", /* T41 */ - "INIT", /* Not in spec. */ +const char * iolink_ds_event_literals[] = { + "NONE", "ENABLE", /* T1 */ + "STARTUP", /* T2 or T14 */ + "READY", /* T25, T26 or T27; + T3 */ + "UPLOAD", /* T4 or T13 */ + "FAULT_DONE", /* T5 */ + "FAULT_ID", /* T15 */ + "FAULT_SIZE", /* T17 */ + "FAULT_UL", /* T23 */ + "FAULT_DL", /* T28 */ + "FAULT_LOCK", /* T29 */ + "ENABLE_COM", /* T6 */ + "CLR_DISA", /* T7 */ + "ENABLE_NO_C", /* T8 */ + "DELETE", /* T9 or T11 */ + "CLEAR", /* T11 */ + "DISABLE", /* T12 */ + "PASSED", /* T16, T18 or T22 */ + "DO_UPLOAD", /* T19 or T21 */ + "NO_UPLOAD", /* T20 or T43 */ + "DOWNLOAD", /* T24 */ + "MORE_DATA", /* T30 or T37 */ + "READ_DONE", /* T31 */ + "STORE_DATA", /* T35 */ + "UL_DONE", /* T26 */ + "DEV_ERR", /* T32 or T39 */ + "COM_ERR", /* T33, T34, T36, T40 or T42 */ + "WR_DONE", /* T38 */ + "DL_DONE", /* T41 */ + "INIT", /* Not in spec. */ "LAST", }; @@ -110,8 +107,8 @@ typedef struct iolink_fsm_ds_transition { iolink_fsm_ds_event_t event; iolink_ds_state_t next_state; - iolink_fsm_ds_event_t (*action)(iolink_port_t * port, - iolink_fsm_ds_event_t event); + iolink_fsm_ds_event_t ( + *action) (iolink_port_t * port, iolink_fsm_ds_event_t event); } iolink_fsm_ds_transition_t; typedef struct iolink_fsm_ds_state_transitions @@ -123,87 +120,107 @@ typedef struct iolink_fsm_ds_state_transitions typedef struct iolink_fsm_ds { iolink_ds_state_t next; - iolink_fsm_ds_event_t (*action)(iolink_port_t * port, - iolink_fsm_ds_event_t event); + iolink_fsm_ds_event_t ( + *action) (iolink_port_t * port, iolink_fsm_ds_event_t event); } iolink_fsm_ds_t; -static void ds_AL_Write_cnf (iolink_port_t * port, - iolink_smi_errortypes_t errortype); -static void ds_AL_Read_cnf (iolink_port_t * port, uint8_t len, - const uint8_t * data, - iolink_smi_errortypes_t errortype); +static void ds_AL_Write_cnf ( + iolink_port_t * port, + iolink_smi_errortypes_t errortype); +static void ds_AL_Read_cnf ( + iolink_port_t * port, + uint8_t len, + const uint8_t * data, + iolink_smi_errortypes_t errortype); -static inline void ds_AL_Read_req (iolink_port_t * port, uint16_t index, - uint8_t subindex) +static inline void ds_AL_Read_req ( + iolink_port_t * port, + uint16_t index, + uint8_t subindex) { iolink_ds_port_t * ds = iolink_get_ds_ctx (port); - ds->current_index = index; + ds->current_index = index; ds->current_subindex = subindex; AL_Read_req (port, index, subindex, ds_AL_Read_cnf); } -static inline void ds_AL_Write_ds_cmd_req (iolink_port_t * port, - iolink_ds_command_t cmd) +static inline void ds_AL_Write_ds_cmd_req ( + iolink_port_t * port, + iolink_ds_command_t cmd) { iolink_ds_port_t * ds = iolink_get_ds_ctx (port); - ds->current_index = DS_PARAM_INDEX; + ds->current_index = DS_PARAM_INDEX; ds->current_subindex = DS_PARAM_SUBINDEX_CMD; - ds->command = cmd; - AL_Write_req (port, ds->current_index, ds->current_subindex, 1, - (uint8_t *)&ds->command, ds_AL_Write_cnf); + ds->command = cmd; + AL_Write_req ( + port, + ds->current_index, + ds->current_subindex, + 1, + (uint8_t *)&ds->command, + ds_AL_Write_cnf); } -static iolink_fsm_ds_event_t ds_delete (iolink_port_t * port, - iolink_fsm_ds_event_t event) +static iolink_fsm_ds_event_t ds_delete ( + iolink_port_t * port, + iolink_fsm_ds_event_t event) { iolink_ds_port_t * ds = iolink_get_ds_ctx (port); - ds->master_ds.vid = 0; - ds->master_ds.did = 0; - ds->master_ds.cs = 0; + ds->master_ds.vid = 0; + ds->master_ds.did = 0; + ds->master_ds.cs = 0; ds->master_ds.valid = false; - ds->master_ds.pos = 0; + ds->master_ds.pos = 0; return DS_EVENT_NONE; } -static iolink_fsm_ds_event_t ds_todo (iolink_port_t * port, - iolink_fsm_ds_event_t event) +static iolink_fsm_ds_event_t ds_todo ( + iolink_port_t * port, + iolink_fsm_ds_event_t event) { CC_ASSERT (0); return DS_EVENT_NONE; } -static iolink_fsm_ds_event_t ds_ul_fault (iolink_port_t * port, - iolink_fsm_ds_event_t event) +static iolink_fsm_ds_event_t ds_ul_fault ( + iolink_port_t * port, + iolink_fsm_ds_event_t event) { return DS_EVENT_FAULT_UL; } -static iolink_fsm_ds_event_t ds_dl_fault (iolink_port_t * port, - iolink_fsm_ds_event_t event) +static iolink_fsm_ds_event_t ds_dl_fault ( + iolink_port_t * port, + iolink_fsm_ds_event_t event) { return DS_EVENT_FAULT_DL; } -static iolink_fsm_ds_event_t ds_fault (iolink_port_t * port, - iolink_fsm_ds_event_t event) +static iolink_fsm_ds_event_t ds_fault ( + iolink_port_t * port, + iolink_fsm_ds_event_t event) { iolink_fsm_ds_event_t res = DS_EVENT_NONE; - iolink_ds_port_t * ds = iolink_get_ds_ctx (port); + iolink_ds_port_t * ds = iolink_get_ds_ctx (port); switch (event) { case DS_EVENT_FAULT_ID: case DS_EVENT_FAULT_SIZE: - DS_Fault (port, (event == DS_EVENT_FAULT_ID) ? IOLINK_DS_FAULT_ID : IOLINK_DS_FAULT_SIZE); + DS_Fault ( + port, + (event == DS_EVENT_FAULT_ID) ? IOLINK_DS_FAULT_ID + : IOLINK_DS_FAULT_SIZE); res = DS_EVENT_FAULT_DONE; /* T5 */ break; case DS_EVENT_FAULT_UL: case DS_EVENT_FAULT_DL: - ds->fault = (event == DS_EVENT_FAULT_UL) ? IOLINK_DS_FAULT_UP : IOLINK_DS_FAULT_DOWN; + ds->fault = (event == DS_EVENT_FAULT_UL) ? IOLINK_DS_FAULT_UP + : IOLINK_DS_FAULT_DOWN; ds_AL_Write_ds_cmd_req (port, DS_CMD_BREAK); /* T5 */ break; case DS_EVENT_FAULT_LOCK: @@ -218,8 +235,7 @@ static iolink_fsm_ds_event_t ds_fault (iolink_port_t * port, return res; } -static iolink_fsm_ds_event_t ds_off (iolink_port_t * port, - iolink_fsm_ds_event_t event) +static iolink_fsm_ds_event_t ds_off (iolink_port_t * port, iolink_fsm_ds_event_t event) { if (event == DS_EVENT_STARTUP) /* T14 */ { @@ -237,11 +253,11 @@ static iolink_fsm_ds_event_t ds_off (iolink_port_t * port, static bool ds_check_vid_did (iolink_port_t * port) { iolink_port_info_t * port_info = iolink_get_port_info (port); - iolink_ds_port_t * ds = iolink_get_ds_ctx (port); + iolink_ds_port_t * ds = iolink_get_ds_ctx (port); - if ((ds->master_ds.vid == 0) || - ((ds->master_ds.vid == port_info->vendorid) && - (ds->master_ds.did == port_info->deviceid))) + if ( + (ds->master_ds.vid == 0) || ((ds->master_ds.vid == port_info->vendorid) && + (ds->master_ds.did == port_info->deviceid))) { return true; } @@ -249,8 +265,9 @@ static bool ds_check_vid_did (iolink_port_t * port) return false; } -static iolink_fsm_ds_event_t ds_chk_id (iolink_port_t * port, - iolink_fsm_ds_event_t event) +static iolink_fsm_ds_event_t ds_chk_id ( + iolink_port_t * port, + iolink_fsm_ds_event_t event) { iolink_fsm_ds_event_t res; @@ -273,10 +290,11 @@ static iolink_fsm_ds_event_t ds_chk_id (iolink_port_t * port, return res; } -static iolink_fsm_ds_event_t ds_chk_mem_size (iolink_port_t * port, - iolink_fsm_ds_event_t event) +static iolink_fsm_ds_event_t ds_chk_mem_size ( + iolink_port_t * port, + iolink_fsm_ds_event_t event) { - iolink_ds_port_t * ds = iolink_get_ds_ctx (port); + iolink_ds_port_t * ds = iolink_get_ds_ctx (port); iolink_fsm_ds_event_t res = DS_EVENT_NONE; if (ds->master_ds.size_max < ds->device_ds.size_max) @@ -291,15 +309,16 @@ static iolink_fsm_ds_event_t ds_chk_mem_size (iolink_port_t * port, return res; } -static iolink_fsm_ds_event_t ds_chk_upload (iolink_port_t * port, - iolink_fsm_ds_event_t event) +static iolink_fsm_ds_event_t ds_chk_upload ( + iolink_port_t * port, + iolink_fsm_ds_event_t event) { iolink_fsm_ds_event_t res = DS_EVENT_NONE; - iolink_ds_port_t * ds = iolink_get_ds_ctx (port); - bool upload_flag = ds->device_ds.state_property & DS_STATE_PROPERTY_UPLOAD_REQ; + iolink_ds_port_t * ds = iolink_get_ds_ctx (port); + bool upload_flag = ds->device_ds.state_property & + DS_STATE_PROPERTY_UPLOAD_REQ; - if ((ds->device_ds.state_property & DS_STATE_PROPERTY_STATE_MASK) == - DS_STATE_PROPERTY_STATE_LOCKED) + if ((ds->device_ds.state_property & DS_STATE_PROPERTY_STATE_MASK) == DS_STATE_PROPERTY_STATE_LOCKED) { res = DS_EVENT_FAULT_LOCK; /* T29 */ } @@ -326,19 +345,20 @@ static iolink_fsm_ds_event_t ds_chk_upload (iolink_port_t * port, return res; } -static iolink_fsm_ds_event_t ds_upload (iolink_port_t * port, - iolink_fsm_ds_event_t event) +static iolink_fsm_ds_event_t ds_upload ( + iolink_port_t * port, + iolink_fsm_ds_event_t event) { iolink_fsm_ds_event_t res = DS_EVENT_NONE; - iolink_ds_port_t * ds = iolink_get_ds_ctx (port); + iolink_ds_port_t * ds = iolink_get_ds_ctx (port); if (event == DS_EVENT_DO_UPLOAD) { - ds->master_ds.pos = 0; - ds->index_list.pos = 0; - ds->current_index = DS_PARAM_INDEX; + ds->master_ds.pos = 0; + ds->index_list.pos = 0; + ds->current_index = DS_PARAM_INDEX; ds->current_subindex = DS_PARAM_SUBINDEX_INDEX_LIST; - res = DS_EVENT_MORE_DATA; /* T30 */ + res = DS_EVENT_MORE_DATA; /* T30 */ } else if (event == DS_EVENT_READ_DONE) { @@ -346,9 +366,9 @@ static iolink_fsm_ds_event_t ds_upload (iolink_port_t * port, { /* More data */ ds_index_list_entry_t * il_entry = - &ds->index_list.entries[ds->index_list.pos]; + &ds->index_list.entries[ds->index_list.pos]; - ds->current_index = il_entry->index; + ds->current_index = il_entry->index; ds->current_subindex = il_entry->subindex; ds->index_list.pos++; res = DS_EVENT_MORE_DATA; /* T30 */ @@ -367,10 +387,11 @@ static iolink_fsm_ds_event_t ds_upload (iolink_port_t * port, return res; } -static iolink_fsm_ds_event_t ds_chk_validity (iolink_port_t * port, - iolink_fsm_ds_event_t event) +static iolink_fsm_ds_event_t ds_chk_validity ( + iolink_port_t * port, + iolink_fsm_ds_event_t event) { - iolink_ds_port_t * ds = iolink_get_ds_ctx (port); + iolink_ds_port_t * ds = iolink_get_ds_ctx (port); iolink_fsm_ds_event_t res = DS_EVENT_NONE; if (ds->master_ds.valid) @@ -385,8 +406,9 @@ static iolink_fsm_ds_event_t ds_chk_validity (iolink_port_t * port, return res; } -static iolink_fsm_ds_event_t ds_chk_csum (iolink_port_t * port, - iolink_fsm_ds_event_t event) +static iolink_fsm_ds_event_t ds_chk_csum ( + iolink_port_t * port, + iolink_fsm_ds_event_t event) { iolink_fsm_ds_event_t res; iolink_ds_port_t * ds = iolink_get_ds_ctx (port); @@ -403,8 +425,9 @@ static iolink_fsm_ds_event_t ds_chk_csum (iolink_port_t * port, return res; } -static iolink_fsm_ds_event_t ds_write_param (iolink_port_t * port, - iolink_fsm_ds_event_t event) +static iolink_fsm_ds_event_t ds_write_param ( + iolink_port_t * port, + iolink_fsm_ds_event_t event) { iolink_ds_port_t * ds = iolink_get_ds_ctx (port); @@ -419,7 +442,7 @@ static iolink_fsm_ds_event_t ds_write_param (iolink_port_t * port, uint8_t * data = &ds->master_ds.data[ds->master_ds.pos]; ds->master_ds.pos += len; - ds->current_index = DS_PARAM_INDEX; + ds->current_index = DS_PARAM_INDEX; ds->current_subindex = subindex; AL_Write_req (port, index, subindex, len, data, ds_AL_Write_cnf); @@ -427,22 +450,25 @@ static iolink_fsm_ds_event_t ds_write_param (iolink_port_t * port, return DS_EVENT_NONE; } -static iolink_fsm_ds_event_t ds_wait_ds_act (iolink_port_t * port, - iolink_fsm_ds_event_t event) +static iolink_fsm_ds_event_t ds_wait_ds_act ( + iolink_port_t * port, + iolink_fsm_ds_event_t event) { return DS_EVENT_NONE; } -static iolink_fsm_ds_event_t ds_dl_done (iolink_port_t * port, - iolink_fsm_ds_event_t event) +static iolink_fsm_ds_event_t ds_dl_done ( + iolink_port_t * port, + iolink_fsm_ds_event_t event) { ds_AL_Write_ds_cmd_req (port, DS_CMD_DL_END); /* T41 */ return DS_EVENT_NONE; } -static iolink_fsm_ds_event_t ds_readparam (iolink_port_t * port, - iolink_fsm_ds_event_t event) +static iolink_fsm_ds_event_t ds_readparam ( + iolink_port_t * port, + iolink_fsm_ds_event_t event) { iolink_ds_port_t * ds = iolink_get_ds_ctx (port); @@ -451,25 +477,28 @@ static iolink_fsm_ds_event_t ds_readparam (iolink_port_t * port, return DS_EVENT_NONE; } -static iolink_fsm_ds_event_t ds_store_data (iolink_port_t * port, - iolink_fsm_ds_event_t event) +static iolink_fsm_ds_event_t ds_store_data ( + iolink_port_t * port, + iolink_fsm_ds_event_t event) { /* Wait for Read Parameter Checksum */ return DS_EVENT_NONE; } -static iolink_fsm_ds_event_t ds_ready (iolink_port_t * port, - iolink_fsm_ds_event_t event) +static iolink_fsm_ds_event_t ds_ready ( + iolink_port_t * port, + iolink_fsm_ds_event_t event) { DS_Ready (port); return DS_EVENT_READY; } -static iolink_fsm_ds_event_t ds_decompose_set (iolink_port_t * port, - iolink_fsm_ds_event_t event) +static iolink_fsm_ds_event_t ds_decompose_set ( + iolink_port_t * port, + iolink_fsm_ds_event_t event) { - iolink_ds_port_t * ds = iolink_get_ds_ctx (port); + iolink_ds_port_t * ds = iolink_get_ds_ctx (port); iolink_fsm_ds_event_t res = DS_EVENT_NONE; if (event == DS_EVENT_DOWNLOAD) @@ -489,16 +518,18 @@ static iolink_fsm_ds_event_t ds_decompose_set (iolink_port_t * port, return res; } -static iolink_fsm_ds_event_t ds_init_dl (iolink_port_t * port, - iolink_fsm_ds_event_t event) +static iolink_fsm_ds_event_t ds_init_dl ( + iolink_port_t * port, + iolink_fsm_ds_event_t event) { ds_AL_Write_ds_cmd_req (port, DS_CMD_DL_START); /* T24 */ return DS_EVENT_NONE; } -static iolink_fsm_ds_event_t ds_reinit (iolink_port_t * port, - iolink_fsm_ds_event_t event) +static iolink_fsm_ds_event_t ds_reinit ( + iolink_port_t * port, + iolink_fsm_ds_event_t event) { iolink_ds_port_t * ds = iolink_get_ds_ctx (port); @@ -513,211 +544,178 @@ static iolink_fsm_ds_event_t ds_reinit (iolink_port_t * port, } /* DS FSM state transitions, IO-Link Interface Spec v1.1.3 Chapter 11.4.4 */ -/* since we iterate through the list on events put the most likely in the top of the list. */ -static const iolink_fsm_ds_transition_t ds_trans_s0[] = -{ +/* since we iterate through the list on events put the most likely in the top of + * the list. */ +static const iolink_fsm_ds_transition_t ds_trans_s0[] = { /* CheckActivationState_0 */ - { DS_EVENT_ENABLE, DS_STATE_WaitingOnDSActivity, ds_wait_ds_act }, /* T1 */ - { DS_EVENT_CLR_DISA, DS_STATE_Off, ds_off }, /* T7 */ + {DS_EVENT_ENABLE, DS_STATE_WaitingOnDSActivity, ds_wait_ds_act}, /* T1 */ + {DS_EVENT_CLR_DISA, DS_STATE_Off, ds_off}, /* T7 */ - { DS_EVENT_DELETE, DS_STATE_CheckActivationState, ds_delete }, /* Not in spec. */ - { DS_EVENT_INIT, DS_STATE_CheckActivationState, ds_reinit }, /* Not in spec. */ + {DS_EVENT_DELETE, DS_STATE_CheckActivationState, ds_delete}, /* Not in spec. + */ + {DS_EVENT_INIT, DS_STATE_CheckActivationState, ds_reinit}, /* Not in spec. */ }; -static const iolink_fsm_ds_transition_t ds_trans_s1[] = -{ +static const iolink_fsm_ds_transition_t ds_trans_s1[] = { /* WaitingOnDsActivity_1 */ - { DS_EVENT_STARTUP, DS_STATE_CheckIdentity, ds_chk_id }, /* T2 */ - { DS_EVENT_UPLOAD, DS_STATE_CheckIdentity, ds_chk_id }, /* T4 */ - { DS_EVENT_DELETE, DS_STATE_WaitingOnDSActivity, ds_delete }, /* T9 */ - { DS_EVENT_CLEAR, DS_STATE_Off, ds_todo }, /* T11 */ - { DS_EVENT_DISABLE, DS_STATE_Off, ds_todo }, /* T12 */ + {DS_EVENT_STARTUP, DS_STATE_CheckIdentity, ds_chk_id}, /* T2 */ + {DS_EVENT_UPLOAD, DS_STATE_CheckIdentity, ds_chk_id}, /* T4 */ + {DS_EVENT_DELETE, DS_STATE_WaitingOnDSActivity, ds_delete}, /* T9 */ + {DS_EVENT_CLEAR, DS_STATE_Off, ds_todo}, /* T11 */ + {DS_EVENT_DISABLE, DS_STATE_Off, ds_todo}, /* T12 */ - { DS_EVENT_INIT, DS_STATE_CheckActivationState, ds_reinit }, /* Not in spec. */ + {DS_EVENT_INIT, DS_STATE_CheckActivationState, ds_reinit}, /* Not in spec. */ }; -static const iolink_fsm_ds_transition_t ds_trans_s2[] = -{ +static const iolink_fsm_ds_transition_t ds_trans_s2[] = { /* Off_3 */ - { DS_EVENT_ENABLE_COM, DS_STATE_CheckIdentity, ds_todo }, /* T6 */ - { DS_EVENT_ENABLE_NO_C, DS_STATE_WaitingOnDSActivity, ds_todo }, /* T8 */ - { DS_EVENT_DELETE, DS_STATE_Off, ds_delete }, /* T10 */ - { DS_EVENT_UPLOAD, DS_STATE_Off, ds_off }, /* T13 */ - { DS_EVENT_STARTUP, DS_STATE_Off, ds_off }, /* T14 */ + {DS_EVENT_ENABLE_COM, DS_STATE_CheckIdentity, ds_todo}, /* T6 */ + {DS_EVENT_ENABLE_NO_C, DS_STATE_WaitingOnDSActivity, ds_todo}, /* T8 */ + {DS_EVENT_DELETE, DS_STATE_Off, ds_delete}, /* T10 */ + {DS_EVENT_UPLOAD, DS_STATE_Off, ds_off}, /* T13 */ + {DS_EVENT_STARTUP, DS_STATE_Off, ds_off}, /* T14 */ - { DS_EVENT_INIT, DS_STATE_CheckActivationState, ds_reinit }, /* Not in spec. */ + {DS_EVENT_INIT, DS_STATE_CheckActivationState, ds_reinit}, /* Not in spec. */ }; -static const iolink_fsm_ds_transition_t ds_trans_s3[] = -{ +static const iolink_fsm_ds_transition_t ds_trans_s3[] = { /* CheckIdentity_4 */ - { DS_EVENT_PASSED, DS_STATE_CheckMemSize, ds_chk_mem_size }, /* T16 */ - { DS_EVENT_FAULT_ID, DS_STATE_DS_Fault, ds_fault }, /* T15 */ + {DS_EVENT_PASSED, DS_STATE_CheckMemSize, ds_chk_mem_size}, /* T16 */ + {DS_EVENT_FAULT_ID, DS_STATE_DS_Fault, ds_fault}, /* T15 */ - { DS_EVENT_INIT, DS_STATE_CheckActivationState, ds_reinit }, /* Not in spec. */ + {DS_EVENT_INIT, DS_STATE_CheckActivationState, ds_reinit}, /* Not in spec. */ }; -static const iolink_fsm_ds_transition_t ds_trans_s4[] = -{ +static const iolink_fsm_ds_transition_t ds_trans_s4[] = { /* CheckMemSize_5 */ - { DS_EVENT_PASSED, DS_STATE_CheckUpload, ds_chk_upload }, /* T18 */ - { DS_EVENT_FAULT_SIZE, DS_STATE_DS_Fault, ds_fault }, /* T17 */ + {DS_EVENT_PASSED, DS_STATE_CheckUpload, ds_chk_upload}, /* T18 */ + {DS_EVENT_FAULT_SIZE, DS_STATE_DS_Fault, ds_fault}, /* T17 */ - { DS_EVENT_INIT, DS_STATE_CheckActivationState, ds_reinit }, /* Not in spec. */ + {DS_EVENT_INIT, DS_STATE_CheckActivationState, ds_reinit}, /* Not in spec. */ }; -static const iolink_fsm_ds_transition_t ds_trans_s5[] = -{ +static const iolink_fsm_ds_transition_t ds_trans_s5[] = { /* CheckUpload_6 */ - { DS_EVENT_DO_UPLOAD, DS_STATE_Decompose_IL, ds_upload }, /* T19 */ - { DS_EVENT_NO_UPLOAD, DS_STATE_CheckDSValidity, ds_chk_validity }, /* T20 or T43 */ - { DS_EVENT_FAULT_LOCK, DS_STATE_DS_Fault, ds_fault }, /* T29 */ + {DS_EVENT_DO_UPLOAD, DS_STATE_Decompose_IL, ds_upload}, /* T19 */ + {DS_EVENT_NO_UPLOAD, DS_STATE_CheckDSValidity, ds_chk_validity}, /* T20 or + T43 */ + {DS_EVENT_FAULT_LOCK, DS_STATE_DS_Fault, ds_fault}, /* T29 */ }; -static const iolink_fsm_ds_transition_t ds_trans_s6[] = -{ +static const iolink_fsm_ds_transition_t ds_trans_s6[] = { /* CheckDSValidity_8 */ - { DS_EVENT_DO_UPLOAD, DS_STATE_Decompose_IL, ds_upload }, /* T21 */ - { DS_EVENT_PASSED, DS_STATE_CheckChecksum, ds_chk_csum }, /* T22 */ + {DS_EVENT_DO_UPLOAD, DS_STATE_Decompose_IL, ds_upload}, /* T21 */ + {DS_EVENT_PASSED, DS_STATE_CheckChecksum, ds_chk_csum}, /* T22 */ }; -static const iolink_fsm_ds_transition_t ds_trans_s7[] = -{ +static const iolink_fsm_ds_transition_t ds_trans_s7[] = { /* CheckChecksum_9 */ - { DS_EVENT_DOWNLOAD, DS_STATE_Decompose_Set, ds_init_dl }, /* T24 */ - { DS_EVENT_READY, DS_STATE_DS_Ready, ds_ready }, /* T25 + T3 */ + {DS_EVENT_DOWNLOAD, DS_STATE_Decompose_Set, ds_init_dl}, /* T24 */ + {DS_EVENT_READY, DS_STATE_DS_Ready, ds_ready}, /* T25 + T3 */ }; -static const iolink_fsm_ds_transition_t ds_trans_s8[] = -{ +static const iolink_fsm_ds_transition_t ds_trans_s8[] = { /* DS_Ready_11 */ - { DS_EVENT_READY, DS_STATE_WaitingOnDSActivity, ds_wait_ds_act }, /* T3 */ + {DS_EVENT_READY, DS_STATE_WaitingOnDSActivity, ds_wait_ds_act}, /* T3 */ }; -static const iolink_fsm_ds_transition_t ds_trans_s9[] = -{ +static const iolink_fsm_ds_transition_t ds_trans_s9[] = { /* DS_Fault_12 */ - { DS_EVENT_FAULT_DONE, DS_STATE_WaitingOnDSActivity, ds_wait_ds_act }, /* T5 */ - { DS_EVENT_COM_ERR, DS_STATE_WaitingOnDSActivity, ds_wait_ds_act }, /* Not in spec. */ // TODO need to call DS_Fault()? + {DS_EVENT_FAULT_DONE, DS_STATE_WaitingOnDSActivity, ds_wait_ds_act}, /* T5 */ + {DS_EVENT_COM_ERR, DS_STATE_WaitingOnDSActivity, ds_wait_ds_act}, + /* Not in spec. */ // TODO need to call DS_Fault()? }; -static const iolink_fsm_ds_transition_t ds_trans_s10[] = -{ +static const iolink_fsm_ds_transition_t ds_trans_s10[] = { /* Upload_7 + Decompose_IL_13 */ - { DS_EVENT_MORE_DATA, DS_STATE_ReadParameter, ds_readparam }, /* T30 */ - { DS_EVENT_STORE_DATA, DS_STATE_StoreDataSet, ds_store_data }, /* T35 */ - { DS_EVENT_COM_ERR, DS_STATE_UploadFault, ds_ul_fault }, /* T34 */ + {DS_EVENT_MORE_DATA, DS_STATE_ReadParameter, ds_readparam}, /* T30 */ + {DS_EVENT_STORE_DATA, DS_STATE_StoreDataSet, ds_store_data}, /* T35 */ + {DS_EVENT_COM_ERR, DS_STATE_UploadFault, ds_ul_fault}, /* T34 */ }; -static const iolink_fsm_ds_transition_t ds_trans_s11[] = -{ +static const iolink_fsm_ds_transition_t ds_trans_s11[] = { /* Upload_7 + ReadParameter_14 */ - { DS_EVENT_READ_DONE, DS_STATE_Decompose_IL, ds_upload }, /* T31 */ - { DS_EVENT_DEV_ERR, DS_STATE_UploadFault, ds_ul_fault }, /* T32 */ - { DS_EVENT_COM_ERR, DS_STATE_UploadFault, ds_ul_fault }, /* T33 */ + {DS_EVENT_READ_DONE, DS_STATE_Decompose_IL, ds_upload}, /* T31 */ + {DS_EVENT_DEV_ERR, DS_STATE_UploadFault, ds_ul_fault}, /* T32 */ + {DS_EVENT_COM_ERR, DS_STATE_UploadFault, ds_ul_fault}, /* T33 */ }; -static const iolink_fsm_ds_transition_t ds_trans_s12[] = -{ +static const iolink_fsm_ds_transition_t ds_trans_s12[] = { /* Upload_7 + StoreDataSet_15 */ - { DS_EVENT_UL_DONE, DS_STATE_DS_Ready, ds_ready }, /* T26 + T3 */ - { DS_EVENT_COM_ERR, DS_STATE_UploadFault, ds_ul_fault }, /* T36 */ + {DS_EVENT_UL_DONE, DS_STATE_DS_Ready, ds_ready}, /* T26 + T3 */ + {DS_EVENT_COM_ERR, DS_STATE_UploadFault, ds_ul_fault}, /* T36 */ }; -static const iolink_fsm_ds_transition_t ds_trans_s13[] = -{ +static const iolink_fsm_ds_transition_t ds_trans_s13[] = { /* Upload_7 + Upload_Fault_16 */ - { DS_EVENT_FAULT_UL, DS_STATE_DS_Fault, ds_fault }, /* T23 */ + {DS_EVENT_FAULT_UL, DS_STATE_DS_Fault, ds_fault}, /* T23 */ }; -static const iolink_fsm_ds_transition_t ds_trans_s14[] = -{ +static const iolink_fsm_ds_transition_t ds_trans_s14[] = { /* Download_10 + Decompose_Set_17 */ - { DS_EVENT_MORE_DATA, DS_STATE_Write_Parameter, ds_write_param }, /* T37 */ - { DS_EVENT_DOWNLOAD, DS_STATE_Decompose_Set, ds_decompose_set }, /* T24 */ - { DS_EVENT_DL_DONE, DS_STATE_Download_Done, ds_dl_done }, /* T41 */ + {DS_EVENT_MORE_DATA, DS_STATE_Write_Parameter, ds_write_param}, /* T37 */ + {DS_EVENT_DOWNLOAD, DS_STATE_Decompose_Set, ds_decompose_set}, /* T24 */ + {DS_EVENT_DL_DONE, DS_STATE_Download_Done, ds_dl_done}, /* T41 */ }; -static const iolink_fsm_ds_transition_t ds_trans_s15[] = -{ +static const iolink_fsm_ds_transition_t ds_trans_s15[] = { /* Download_10 + Write_Parameter_18 */ - { DS_EVENT_WR_DONE, DS_STATE_Decompose_Set, ds_decompose_set }, /* T38 */ - { DS_EVENT_DEV_ERR, DS_STATE_Download_Fault, ds_dl_fault }, /* T39 */ - { DS_EVENT_COM_ERR, DS_STATE_Download_Fault, ds_dl_fault }, /* T40 */ + {DS_EVENT_WR_DONE, DS_STATE_Decompose_Set, ds_decompose_set}, /* T38 */ + {DS_EVENT_DEV_ERR, DS_STATE_Download_Fault, ds_dl_fault}, /* T39 */ + {DS_EVENT_COM_ERR, DS_STATE_Download_Fault, ds_dl_fault}, /* T40 */ }; -static const iolink_fsm_ds_transition_t ds_trans_s16[] = -{ +static const iolink_fsm_ds_transition_t ds_trans_s16[] = { /* Download_10 + Download_Done_19 */ - { DS_EVENT_READY, DS_STATE_DS_Ready, ds_ready }, /* T27 + T3 */ - { DS_EVENT_COM_ERR, DS_STATE_Download_Fault, ds_dl_fault }, /* T42 */ + {DS_EVENT_READY, DS_STATE_DS_Ready, ds_ready}, /* T27 + T3 */ + {DS_EVENT_COM_ERR, DS_STATE_Download_Fault, ds_dl_fault}, /* T42 */ }; -static const iolink_fsm_ds_transition_t ds_trans_s17[] = -{ +static const iolink_fsm_ds_transition_t ds_trans_s17[] = { /* Download_10 + Download_Fault_20 */ - { DS_EVENT_FAULT_DL, DS_STATE_DS_Fault, ds_fault }, /* T28 */ + {DS_EVENT_FAULT_DL, DS_STATE_DS_Fault, ds_fault}, /* T28 */ }; /* The index is the state in this array */ -static const iolink_fsm_ds_state_transitions_t iolink_ds_fsm[] = -{ - { /* CheckActivationState_0 */ - .number_of_trans = NELEMENTS (ds_trans_s0), - .transitions = ds_trans_s0 - }, - { /* WaitingOnDsActivity_1 */ - .number_of_trans = NELEMENTS (ds_trans_s1), - .transitions = ds_trans_s1 - }, - { /* Off_3 */ - .number_of_trans = NELEMENTS (ds_trans_s2), - .transitions = ds_trans_s2 - }, - { /* CheckIdentity_4 */ - .number_of_trans = NELEMENTS (ds_trans_s3), - .transitions = ds_trans_s3 - }, - { /* CheckMemSize_5 */ - .number_of_trans = NELEMENTS (ds_trans_s4), - .transitions = ds_trans_s4 - }, - { /* CheckUpload_6 */ - .number_of_trans = NELEMENTS (ds_trans_s5), - .transitions = ds_trans_s5 - }, - { /* CheckDSValidity_8 */ - .number_of_trans = NELEMENTS (ds_trans_s6), - .transitions = ds_trans_s6 - }, - { /* CheckChecksum_9 */ - .number_of_trans = NELEMENTS (ds_trans_s7), - .transitions = ds_trans_s7 - }, - { /* DS_Ready_11 */ - .number_of_trans = NELEMENTS (ds_trans_s8), - .transitions = ds_trans_s8 - }, - { /* DS_Fault_12 */ - .number_of_trans = NELEMENTS (ds_trans_s9), - .transitions = ds_trans_s9 - }, - { /* Upload_7 + Decompose_IL_13 */ - .number_of_trans = NELEMENTS (ds_trans_s10), - .transitions = ds_trans_s10 - }, - { /* Upload_7 + ReadParameter_14 */ - .number_of_trans = NELEMENTS (ds_trans_s11), - .transitions = ds_trans_s11 - }, - { /* Upload_7 + StoreDataSet_15 */ - .number_of_trans = NELEMENTS (ds_trans_s12), - .transitions = ds_trans_s12 - }, - { /* Upload_7 + Upload_Fault_16 */ - .number_of_trans = NELEMENTS (ds_trans_s13), - .transitions = ds_trans_s13 - }, - { /* Download_10 + Decompose_Set_17 */ - .number_of_trans = NELEMENTS (ds_trans_s14), - .transitions = ds_trans_s14 - }, - { /* Download_10 + Write_Parameter_18 */ - .number_of_trans = NELEMENTS (ds_trans_s15), - .transitions = ds_trans_s15 - }, - { /* Download_10 + Download_Done_19 */ - .number_of_trans = NELEMENTS (ds_trans_s16), - .transitions = ds_trans_s16 - }, - { /* Download_10 + Download_Fault_20 */ - .number_of_trans = NELEMENTS (ds_trans_s17), - .transitions = ds_trans_s17 - }, +static const iolink_fsm_ds_state_transitions_t iolink_ds_fsm[] = { + {/* CheckActivationState_0 */ + .number_of_trans = NELEMENTS (ds_trans_s0), + .transitions = ds_trans_s0}, + {/* WaitingOnDsActivity_1 */ + .number_of_trans = NELEMENTS (ds_trans_s1), + .transitions = ds_trans_s1}, + {/* Off_3 */ + .number_of_trans = NELEMENTS (ds_trans_s2), + .transitions = ds_trans_s2}, + {/* CheckIdentity_4 */ + .number_of_trans = NELEMENTS (ds_trans_s3), + .transitions = ds_trans_s3}, + {/* CheckMemSize_5 */ + .number_of_trans = NELEMENTS (ds_trans_s4), + .transitions = ds_trans_s4}, + {/* CheckUpload_6 */ + .number_of_trans = NELEMENTS (ds_trans_s5), + .transitions = ds_trans_s5}, + {/* CheckDSValidity_8 */ + .number_of_trans = NELEMENTS (ds_trans_s6), + .transitions = ds_trans_s6}, + {/* CheckChecksum_9 */ + .number_of_trans = NELEMENTS (ds_trans_s7), + .transitions = ds_trans_s7}, + {/* DS_Ready_11 */ + .number_of_trans = NELEMENTS (ds_trans_s8), + .transitions = ds_trans_s8}, + {/* DS_Fault_12 */ + .number_of_trans = NELEMENTS (ds_trans_s9), + .transitions = ds_trans_s9}, + {/* Upload_7 + Decompose_IL_13 */ + .number_of_trans = NELEMENTS (ds_trans_s10), + .transitions = ds_trans_s10}, + {/* Upload_7 + ReadParameter_14 */ + .number_of_trans = NELEMENTS (ds_trans_s11), + .transitions = ds_trans_s11}, + {/* Upload_7 + StoreDataSet_15 */ + .number_of_trans = NELEMENTS (ds_trans_s12), + .transitions = ds_trans_s12}, + {/* Upload_7 + Upload_Fault_16 */ + .number_of_trans = NELEMENTS (ds_trans_s13), + .transitions = ds_trans_s13}, + {/* Download_10 + Decompose_Set_17 */ + .number_of_trans = NELEMENTS (ds_trans_s14), + .transitions = ds_trans_s14}, + {/* Download_10 + Write_Parameter_18 */ + .number_of_trans = NELEMENTS (ds_trans_s15), + .transitions = ds_trans_s15}, + {/* Download_10 + Download_Done_19 */ + .number_of_trans = NELEMENTS (ds_trans_s16), + .transitions = ds_trans_s16}, + {/* Download_10 + Download_Fault_20 */ + .number_of_trans = NELEMENTS (ds_trans_s17), + .transitions = ds_trans_s17}, }; static void iolink_ds_event (iolink_port_t * port, iolink_fsm_ds_event_t event) @@ -725,8 +723,8 @@ static void iolink_ds_event (iolink_port_t * port, iolink_fsm_ds_event_t event) do { int i; - iolink_ds_port_t * ds = iolink_get_ds_ctx (port); - iolink_ds_state_t previous = ds->state; + iolink_ds_port_t * ds = iolink_get_ds_ctx (port); + iolink_ds_state_t previous = ds->state; const iolink_fsm_ds_transition_t * next_trans = NULL; for (i = 0; i < iolink_ds_fsm[previous].number_of_trans; i++) @@ -742,18 +740,24 @@ static void iolink_ds_event (iolink_port_t * port, iolink_fsm_ds_event_t event) } if (!next_trans) { - LOG_ERROR (IOLINK_DS_LOG, "%u: next_trans == NULL: DS state %s - DS event %s\n", - iolink_get_portnumber (port), - iolink_ds_state_literals[previous], - iolink_ds_event_literals[event]); + LOG_ERROR ( + IOLINK_DS_LOG, + "%u: next_trans == NULL: DS state %s - DS event %s\n", + iolink_get_portnumber (port), + iolink_ds_state_literals[previous], + iolink_ds_event_literals[event]); return; } /* Transition to next state */ ds->state = next_trans->next_state; - LOG_DEBUG (IOLINK_DS_LOG, "DS (%u): event: %s, state transition: %s -> %s\n", - iolink_get_portnumber (port), iolink_ds_event_literals[event], - iolink_ds_state_literals[previous], iolink_ds_state_literals[ds->state]); + LOG_DEBUG ( + IOLINK_DS_LOG, + "DS (%u): event: %s, state transition: %s -> %s\n", + iolink_get_portnumber (port), + iolink_ds_event_literals[event], + iolink_ds_state_literals[previous], + iolink_ds_state_literals[ds->state]); event = next_trans->action (port, event); } while (event != DS_EVENT_NONE); } @@ -761,7 +765,7 @@ static void iolink_ds_event (iolink_port_t * port, iolink_fsm_ds_event_t event) /* DS AL_Read_cnf() and AL_Write_cnf functions */ static void ds_read_cnf_cb (iolink_job_t * job) { - iolink_port_t * port = job->port; + iolink_port_t * port = job->port; iolink_ds_port_t * ds = iolink_get_ds_ctx (port); if (job->al_read_cnf.errortype == IOLINK_SMI_ERRORTYPE_COM_ERR) @@ -774,30 +778,33 @@ static void ds_read_cnf_cb (iolink_job_t * job) switch (ds->state) { case DS_STATE_CheckIdentity: - if (job->al_read_cnf.errortype != IOLINK_SMI_ERRORTYPE_NONE || - job->al_read_cnf.data_len < sizeof(uint32_t)) + if ( + job->al_read_cnf.errortype != IOLINK_SMI_ERRORTYPE_NONE || + job->al_read_cnf.data_len < sizeof (uint32_t)) { iolink_ds_event (port, DS_EVENT_FAULT_ID); /* T15 */ } else { - ds->device_ds.size_max = (job->al_read_cnf.data[0] << 24) + - (job->al_read_cnf.data[1] << 16) + - (job->al_read_cnf.data[2] << 8) + - job->al_read_cnf.data[3]; + ds->device_ds.size_max = + (job->al_read_cnf.data[0] << 24) + (job->al_read_cnf.data[1] << 16) + + (job->al_read_cnf.data[2] << 8) + job->al_read_cnf.data[3]; if (ds->device_ds.size_max > IOLINK_DS_MAX_SIZE) { - LOG_DEBUG (IOLINK_DS_LOG, "%u: DS: Maximum size is %u, got %lu\n", - iolink_get_portnumber (port), - IOLINK_DS_MAX_SIZE, - (long unsigned int)ds->device_ds.size_max); + LOG_DEBUG ( + IOLINK_DS_LOG, + "%u: DS: Maximum size is %u, got %lu\n", + iolink_get_portnumber (port), + IOLINK_DS_MAX_SIZE, + (long unsigned int)ds->device_ds.size_max); } iolink_ds_event (port, DS_EVENT_PASSED); } break; case DS_STATE_CheckMemSize: - if (job->al_read_cnf.errortype != IOLINK_SMI_ERRORTYPE_NONE || - job->al_read_cnf.data_len != sizeof(uint8_t)) + if ( + job->al_read_cnf.errortype != IOLINK_SMI_ERRORTYPE_NONE || + job->al_read_cnf.data_len != sizeof (uint8_t)) { iolink_ds_event (port, DS_EVENT_FAULT_SIZE); /* T17 */ } @@ -814,10 +821,11 @@ static void ds_read_cnf_cb (iolink_job_t * job) } else { - if ((ds->current_index == DS_PARAM_INDEX) && - (ds->current_subindex == DS_PARAM_SUBINDEX_INDEX_LIST)) + if ( + (ds->current_index == DS_PARAM_INDEX) && + (ds->current_subindex == DS_PARAM_SUBINDEX_INDEX_LIST)) { - uint8_t i = 0; + uint8_t i = 0; uint16_t read_data_pos = 0; while (i < DS_INDEX_LIST_MAX_ENTRIES) @@ -837,7 +845,7 @@ static void ds_read_cnf_cb (iolink_job_t * job) uint8_t subindex = job->al_read_cnf.data[read_data_pos]; read_data_pos++; - ds->index_list.entries[i].index = index; + ds->index_list.entries[i].index = index; ds->index_list.entries[i].subindex = subindex; } i++; @@ -857,17 +865,22 @@ static void ds_read_cnf_cb (iolink_job_t * job) ds->master_ds.pos++; ds->master_ds.data[ds->master_ds.pos] = len; ds->master_ds.pos++; - memcpy (&ds->master_ds.data[ds->master_ds.pos], - job->al_read_cnf.data, len); + memcpy ( + &ds->master_ds.data[ds->master_ds.pos], + job->al_read_cnf.data, + len); ds->master_ds.pos += len; } else { - LOG_DEBUG (IOLINK_DS_LOG, - "%u: DS: not enough space in data store, max_size = %lu, pos = %u, len = %u\n", - iolink_get_portnumber (port), - (unsigned long)ds->master_ds.size_max, - ds->master_ds.pos, len); + LOG_DEBUG ( + IOLINK_DS_LOG, + "%u: DS: not enough space in data store, max_size = %lu, pos " + "= %u, len = %u\n", + iolink_get_portnumber (port), + (unsigned long)ds->master_ds.size_max, + ds->master_ds.pos, + len); } } iolink_ds_event (port, DS_EVENT_READ_DONE); @@ -875,39 +888,36 @@ static void ds_read_cnf_cb (iolink_job_t * job) break; case DS_STATE_CheckUpload: /* Checksum */ - if (job->al_read_cnf.data_len < sizeof(uint32_t)) + if (job->al_read_cnf.data_len < sizeof (uint32_t)) { iolink_ds_event (port, DS_EVENT_COM_ERR); /* T36 */ } - ds->device_ds.cs = (job->al_read_cnf.data[0] << 24) + - (job->al_read_cnf.data[1] << 16) + - (job->al_read_cnf.data[2] << 8) + - job->al_read_cnf.data[3]; + ds->device_ds.cs = + (job->al_read_cnf.data[0] << 24) + (job->al_read_cnf.data[1] << 16) + + (job->al_read_cnf.data[2] << 8) + job->al_read_cnf.data[3]; iolink_ds_event (port, DS_EVENT_NO_UPLOAD); /* T20 or T43 */ break; case DS_STATE_StoreDataSet: /* Checksum */ - if (job->al_read_cnf.data_len < sizeof(uint32_t)) + if (job->al_read_cnf.data_len < sizeof (uint32_t)) { iolink_ds_event (port, DS_EVENT_COM_ERR); /* T36 */ } - ds->device_ds.cs = (job->al_read_cnf.data[0] << 24) + - (job->al_read_cnf.data[1] << 16) + - (job->al_read_cnf.data[2] << 8) + - job->al_read_cnf.data[3]; + ds->device_ds.cs = + (job->al_read_cnf.data[0] << 24) + (job->al_read_cnf.data[1] << 16) + + (job->al_read_cnf.data[2] << 8) + job->al_read_cnf.data[3]; ds_AL_Write_ds_cmd_req (port, DS_CMD_UL_END); /* T26 */ break; case DS_STATE_Download_Done: /* Checksum */ - if (job->al_read_cnf.data_len < sizeof(uint32_t)) + if (job->al_read_cnf.data_len < sizeof (uint32_t)) { iolink_ds_event (port, DS_EVENT_COM_ERR); /* T42 */ } - ds->device_ds.cs = (job->al_read_cnf.data[0] << 24) + - (job->al_read_cnf.data[1] << 16) + - (job->al_read_cnf.data[2] << 8) + - job->al_read_cnf.data[3]; + ds->device_ds.cs = + (job->al_read_cnf.data[0] << 24) + (job->al_read_cnf.data[1] << 16) + + (job->al_read_cnf.data[2] << 8) + job->al_read_cnf.data[3]; iolink_ds_event (port, DS_EVENT_READY); /* T41 */ break; @@ -918,7 +928,7 @@ static void ds_read_cnf_cb (iolink_job_t * job) static void ds_write_cnf_cb (iolink_job_t * job) { - iolink_port_t * port = job->port; + iolink_port_t * port = job->port; iolink_ds_port_t * ds = iolink_get_ds_ctx (port); if (job->al_write_cnf.errortype != IOLINK_SMI_ERRORTYPE_NONE) @@ -929,17 +939,17 @@ static void ds_write_cnf_cb (iolink_job_t * job) { switch (ds->state) { - case DS_STATE_CheckUpload: /* T19 */ - case DS_STATE_CheckDSValidity: /* T21 */ + case DS_STATE_CheckUpload: /* T19 */ + case DS_STATE_CheckDSValidity: /* T21 */ iolink_ds_event (port, DS_EVENT_DO_UPLOAD); /* T19 */ break; case DS_STATE_Write_Parameter: iolink_ds_event (port, DS_EVENT_WR_DONE); break; case DS_STATE_StoreDataSet: - ds->master_ds.vid = ds->pending_id.vendorid; - ds->master_ds.did = ds->pending_id.deviceid; - ds->master_ds.cs = ds->device_ds.cs; + ds->master_ds.vid = ds->pending_id.vendorid; + ds->master_ds.did = ds->pending_id.deviceid; + ds->master_ds.cs = ds->device_ds.cs; ds->master_ds.valid = true; iolink_ds_event (port, DS_EVENT_UL_DONE); /* T26 */ break; @@ -960,27 +970,36 @@ static void ds_write_cnf_cb (iolink_job_t * job) } } -static void ds_AL_Read_cnf (iolink_port_t * port, uint8_t len, - const uint8_t * data, - iolink_smi_errortypes_t errortype) +static void ds_AL_Read_cnf ( + iolink_port_t * port, + uint8_t len, + const uint8_t * data, + iolink_smi_errortypes_t errortype) { iolink_job_t * job = iolink_fetch_avail_job (port); - job->al_read_cnf.data = data; - job->al_read_cnf.data_len = len; + job->al_read_cnf.data = data; + job->al_read_cnf.data_len = len; job->al_read_cnf.errortype = errortype; - iolink_post_job_with_type_and_callback (port, job, IOLINK_JOB_AL_READ_CNF, ds_read_cnf_cb); + iolink_post_job_with_type_and_callback ( + port, + job, + IOLINK_JOB_AL_READ_CNF, + ds_read_cnf_cb); } -static void ds_AL_Write_cnf (iolink_port_t * port, - iolink_smi_errortypes_t errortype) +static void ds_AL_Write_cnf (iolink_port_t * port, iolink_smi_errortypes_t errortype) { iolink_job_t * job = iolink_fetch_avail_job (port); job->al_write_cnf.errortype = errortype; - iolink_post_job_with_type_and_callback (port, job, IOLINK_JOB_AL_WRITE_CNF, ds_write_cnf_cb); + iolink_post_job_with_type_and_callback ( + port, + job, + IOLINK_JOB_AL_WRITE_CNF, + ds_write_cnf_cb); } /* DS job callback functions */ @@ -996,13 +1015,13 @@ static void ds_delete_cb (iolink_job_t * job) static void ds_init_cb (iolink_job_t * job) { - iolink_port_t * port = job->port; - iolink_ds_port_t * ds = iolink_get_ds_ctx (port); + iolink_port_t * port = job->port; + iolink_ds_port_t * ds = iolink_get_ds_ctx (port); portconfiglist_t * cfg_list = &job->ds_init.portcfg; - ds->ds_upload = false; + ds->ds_upload = false; ds->ds_download = false; - ds->fault = IOLINK_DS_FAULT_NONE; + ds->fault = IOLINK_DS_FAULT_NONE; if (cfg_list->portmode == IOLINK_PORTMODE_IOL_MAN) { @@ -1013,7 +1032,7 @@ static void ds_init_cb (iolink_job_t * job) /* fall through */ case IOLINK_VALIDATION_CHECK_V11_RESTORE: /* only download */ ds->ds_download = true; - ds->ds_enable = true; + ds->ds_enable = true; break; case IOLINK_VALIDATION_CHECK_V11: break; @@ -1030,7 +1049,7 @@ static void ds_init_cb (iolink_job_t * job) static void ds_upload_cb (iolink_job_t * job) { - iolink_ds_event (job->port, DS_EVENT_UPLOAD); + iolink_ds_event (job->port, DS_EVENT_UPLOAD); } /* Stack internal API */ @@ -1038,7 +1057,7 @@ void iolink_ds_init (iolink_port_t * port) { iolink_ds_port_t * ds = iolink_get_ds_ctx (port); - memset (ds, 0, sizeof(iolink_ds_port_t)); + memset (ds, 0, sizeof (iolink_ds_port_t)); ds->state = DS_STATE_CheckActivationState; @@ -1049,7 +1068,11 @@ iolink_error_t DS_Delete (iolink_port_t * port) { iolink_job_t * job = iolink_fetch_avail_job (port); - iolink_post_job_with_type_and_callback (port, job, IOLINK_JOB_DS_DELETE, ds_delete_cb); + iolink_post_job_with_type_and_callback ( + port, + job, + IOLINK_JOB_DS_DELETE, + ds_delete_cb); return IOLINK_ERROR_NONE; } @@ -1058,7 +1081,11 @@ iolink_error_t DS_Startup (iolink_port_t * port) { iolink_job_t * job = iolink_fetch_avail_job (port); - iolink_post_job_with_type_and_callback (port, job, IOLINK_JOB_DS_STARTUP, ds_startup_cb); + iolink_post_job_with_type_and_callback ( + port, + job, + IOLINK_JOB_DS_STARTUP, + ds_startup_cb); return IOLINK_ERROR_NONE; } @@ -1067,19 +1094,26 @@ iolink_error_t DS_Upload (iolink_port_t * port) { iolink_job_t * job = iolink_fetch_avail_job (port); - iolink_post_job_with_type_and_callback (port, job, IOLINK_JOB_DS_UPLOAD, ds_upload_cb); + iolink_post_job_with_type_and_callback ( + port, + job, + IOLINK_JOB_DS_UPLOAD, + ds_upload_cb); return IOLINK_ERROR_NONE; } -iolink_error_t DS_Init (iolink_port_t * port, - const portconfiglist_t * cfg_list) +iolink_error_t DS_Init (iolink_port_t * port, const portconfiglist_t * cfg_list) { iolink_job_t * job = iolink_fetch_avail_job (port); - memcpy (&job->ds_init.portcfg, cfg_list, sizeof(portconfiglist_t)); + memcpy (&job->ds_init.portcfg, cfg_list, sizeof (portconfiglist_t)); - iolink_post_job_with_type_and_callback (port, job, IOLINK_JOB_DS_STARTUP, ds_init_cb); + iolink_post_job_with_type_and_callback ( + port, + job, + IOLINK_JOB_DS_STARTUP, + ds_init_cb); return IOLINK_ERROR_NONE; } @@ -1088,9 +1122,9 @@ bool DS_Chk_Cfg (iolink_port_t * port, const portconfiglist_t * cfg_list) { iolink_ds_port_t * ds = iolink_get_ds_ctx (port); - if ((ds->master_ds.vid) && - (ds->master_ds.vid == cfg_list->vendorid) && - (ds->master_ds.did == cfg_list->deviceid)) + if ( + (ds->master_ds.vid) && (ds->master_ds.vid == cfg_list->vendorid) && + (ds->master_ds.did == cfg_list->deviceid)) { return true; } @@ -1098,45 +1132,44 @@ bool DS_Chk_Cfg (iolink_port_t * port, const portconfiglist_t * cfg_list) return false; } -iolink_error_t ds_SMI_ParServToDS_req (iolink_port_t * port, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, - arg_block_t * arg_block) +iolink_error_t ds_SMI_ParServToDS_req ( + iolink_port_t * port, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block) { iolink_arg_block_id_t ref_arg_block_id = arg_block->void_block.arg_block_id; iolink_error_t error; - iolink_ds_port_t * ds = iolink_get_ds_ctx (port); - uint8_t arg_block_ds_data_len = arg_block_len - sizeof(arg_block_ds_data_t); + iolink_ds_port_t * ds = iolink_get_ds_ctx (port); + uint8_t arg_block_ds_data_len = arg_block_len - sizeof (arg_block_ds_data_t); iolink_smi_errortypes_t smi_error; - if (exp_arg_block_id != IOLINK_ARG_BLOCK_ID_VOID_BLOCK || - ref_arg_block_id != IOLINK_ARG_BLOCK_ID_DS_DATA) + if (exp_arg_block_id != IOLINK_ARG_BLOCK_ID_VOID_BLOCK || ref_arg_block_id != IOLINK_ARG_BLOCK_ID_DS_DATA) { - smi_error = IOLINK_SMI_ERRORTYPE_ARGBLOCK_NOT_SUPPORTED; // TODO what to use? - iolink_smi_joberror_ind (port, exp_arg_block_id, ref_arg_block_id, - smi_error); + smi_error = IOLINK_SMI_ERRORTYPE_ARGBLOCK_NOT_SUPPORTED; // TODO what to + // use? + iolink_smi_joberror_ind (port, exp_arg_block_id, ref_arg_block_id, smi_error); error = IOLINK_ERROR_PARAMETER_CONFLICT; } else if (arg_block_ds_data_len > ds->master_ds.size_max) { - smi_error = IOLINK_SMI_ERRORTYPE_ARGBLOCK_INCONSISTENT; // TODO what to use? - iolink_smi_joberror_ind (port, exp_arg_block_id, ref_arg_block_id, - smi_error); + smi_error = IOLINK_SMI_ERRORTYPE_ARGBLOCK_INCONSISTENT; // TODO what to + // use? + iolink_smi_joberror_ind (port, exp_arg_block_id, ref_arg_block_id, smi_error); error = IOLINK_ERROR_PARAMETER_CONFLICT; } else { arg_block_ds_data_t * arg_block_ds_data = &arg_block->ds_data; - memcpy (ds->master_ds.data, arg_block_ds_data->ds_data, - arg_block_ds_data_len); + memcpy (ds->master_ds.data, arg_block_ds_data->ds_data, arg_block_ds_data_len); - ds->master_ds.cs = 0; // TODO? - ds->master_ds.vid = arg_block_ds_data->vid; - ds->master_ds.did = arg_block_ds_data->did; - ds->master_ds.fid = arg_block_ds_data->fid; + ds->master_ds.cs = 0; // TODO? + ds->master_ds.vid = arg_block_ds_data->vid; + ds->master_ds.did = arg_block_ds_data->did; + ds->master_ds.fid = arg_block_ds_data->fid; ds->master_ds.valid = true; - ds->master_ds.size = arg_block_ds_data_len; + ds->master_ds.size = arg_block_ds_data_len; iolink_smi_voidblock_cnf (port, ref_arg_block_id); diff --git a/src/iolink_ds.h b/src/iolink_ds.h index 256ffa3..d90d213 100644 --- a/src/iolink_ds.h +++ b/src/iolink_ds.h @@ -19,26 +19,25 @@ #include "sys/osal_cc.h" #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif #define IOLINK_DS_MAX_SIZE 2048 -#define DS_STATE_PROPERTY_STATE_MASK (3 << 1) -#define DS_STATE_PROPERTY_STATE_UPLOAD (1 << 1) +#define DS_STATE_PROPERTY_STATE_MASK (3 << 1) +#define DS_STATE_PROPERTY_STATE_UPLOAD (1 << 1) #define DS_STATE_PROPERTY_STATE_DOWNLOAD (2 << 1) -#define DS_STATE_PROPERTY_STATE_LOCKED (3 << 1) -#define DS_STATE_PROPERTY_UPLOAD_REQ BIT(7) +#define DS_STATE_PROPERTY_STATE_LOCKED (3 << 1) +#define DS_STATE_PROPERTY_UPLOAD_REQ BIT (7) typedef enum iolink_ds_command { - DS_CMD_RES = 0x00, + DS_CMD_RES = 0x00, DS_CMD_UL_START = 0x01, - DS_CMD_UL_END = 0x02, + DS_CMD_UL_END = 0x02, DS_CMD_DL_START = 0x03, - DS_CMD_DL_END = 0x04, - DS_CMD_BREAK = 0x05, + DS_CMD_DL_END = 0x04, + DS_CMD_BREAK = 0x05, } iolink_ds_command_t; typedef enum iolink_ds_state @@ -150,16 +149,16 @@ typedef enum iolink_fsm_ds_event DS_EVENT_NO_UPLOAD, /* T20 or T43 */ DS_EVENT_DOWNLOAD, /* T24 */ - DS_EVENT_MORE_DATA, /* T30 or T37 */ - DS_EVENT_READ_DONE, /* T31 */ - DS_EVENT_STORE_DATA, /* T35 */ - DS_EVENT_UL_DONE, /* T26 */ - DS_EVENT_DEV_ERR, /* T32 or T39 */ - DS_EVENT_COM_ERR, /* T33, T34, T36, T40 or T42 */ + DS_EVENT_MORE_DATA, /* T30 or T37 */ + DS_EVENT_READ_DONE, /* T31 */ + DS_EVENT_STORE_DATA, /* T35 */ + DS_EVENT_UL_DONE, /* T26 */ + DS_EVENT_DEV_ERR, /* T32 or T39 */ + DS_EVENT_COM_ERR, /* T33, T34, T36, T40 or T42 */ - DS_EVENT_WR_DONE, /* T38 */ - DS_EVENT_DL_DONE, /* T41 */ - DS_EVENT_INIT, /* Not in spec. */ + DS_EVENT_WR_DONE, /* T38 */ + DS_EVENT_DL_DONE, /* T41 */ + DS_EVENT_INIT, /* Not in spec. */ DS_EVENT_LAST, } iolink_fsm_ds_event_t; @@ -171,20 +170,23 @@ iolink_error_t DS_Startup (iolink_port_t * port); iolink_error_t DS_Upload (iolink_port_t * port); -iolink_error_t DS_Init (iolink_port_t * port, // Not in spec - const portconfiglist_t * cfg_list); +iolink_error_t DS_Init ( + iolink_port_t * port, // Not in spec + const portconfiglist_t * cfg_list); bool DS_Chk_Cfg (iolink_port_t * port, const portconfiglist_t * cfg_list); -iolink_error_t ds_SMI_ParServToDS_req (iolink_port_t * port, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, - arg_block_t * arg_block); - -iolink_error_t ds_SMI_DSToParServ_req (iolink_port_t * port, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, - arg_block_t * arg_block); +iolink_error_t ds_SMI_ParServToDS_req ( + iolink_port_t * port, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block); + +iolink_error_t ds_SMI_DSToParServ_req ( + iolink_port_t * port, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block); #ifdef __cplusplus } #endif diff --git a/src/iolink_main.c b/src/iolink_main.c index 138e7bc..36396be 100644 --- a/src/iolink_main.c +++ b/src/iolink_main.c @@ -10,19 +10,18 @@ * See LICENSE file in the project root for full license information. ********************************************************************/ - #ifdef UNIT_TEST #define iolink_pl_init mock_iolink_pl_init #endif /* UNIT_TEST */ #include "iolink_main.h" -#include "iolink_al.h" /* iolink_al_init */ -#include "iolink_cm.h" /* iolink_cm_init */ -#include "iolink_ds.h" /* iolink_ds_init ds_SMI_ParServToDS_req */ +#include "iolink_al.h" /* iolink_al_init */ +#include "iolink_cm.h" /* iolink_cm_init */ +#include "iolink_ds.h" /* iolink_ds_init ds_SMI_ParServToDS_req */ #include "iolink_ode.h" /* iolink_ode_init */ #include "iolink_pde.h" /* iolink_pde_init */ -#include "iolink_pl.h" /* iolink_pl_init */ -#include "iolink_sm.h" /* iolink_sm_init */ +#include "iolink_pl.h" /* iolink_pl_init */ +#include "iolink_sm.h" /* iolink_sm_init */ #include "osal.h" @@ -34,7 +33,7 @@ * */ -#define IOLINK_MASTER_JOB_CNT 40 +#define IOLINK_MASTER_JOB_CNT 40 #define IOLINK_MASTER_JOB_API_CNT 10 typedef struct iolink_port @@ -56,22 +55,28 @@ typedef struct iolink_port typedef struct iolink_m { os_thread_t * thread; - os_mbox_t * mbox; /* Mailbox for job submission */ - os_mbox_t * mbox_avail; /* Mailbox for available jobs */ - os_mbox_t * mbox_api_avail; /* Mailbox for available API (external) jobs */ + os_mbox_t * mbox; /* Mailbox for job submission */ + os_mbox_t * mbox_avail; /* Mailbox for available jobs */ + os_mbox_t * mbox_api_avail; /* Mailbox for available API (external) jobs */ iolink_job_t job[IOLINK_MASTER_JOB_CNT]; iolink_job_t job_api[IOLINK_MASTER_JOB_API_CNT]; void * cb_arg; /* Callback opaque argument */ /* SMI cnf/ind callback */ - void (*cb_smi) (void * arg, uint8_t portnumber, - iolink_arg_block_id_t ref_arg_block_id, - uint16_t arg_block_len, arg_block_t * arg_block); + void (*cb_smi) ( + void * arg, + uint8_t portnumber, + iolink_arg_block_id_t ref_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block); /* Periodic data callback */ - void (*cb_pd) (uint8_t portnumber, void * arg, uint8_t data_len, - const uint8_t * data); + void (*cb_pd) ( + uint8_t portnumber, + void * arg, + uint8_t data_len, + const uint8_t * data); uint8_t port_cnt; struct iolink_port ports[]; @@ -80,7 +85,7 @@ typedef struct iolink_m static iolink_m_t * the_master = NULL; static inline iolink_transmission_rate_t mhmode_to_transmission_rate ( - iolink_mhmode_t mhmode) + iolink_mhmode_t mhmode) { iolink_transmission_rate_t res = IOLINK_TRANSMISSION_RATE_NOT_DETECTED; @@ -102,8 +107,9 @@ static inline iolink_transmission_rate_t mhmode_to_transmission_rate ( return res; } -static inline iolink_error_t portnumber_to_iolinkport (uint8_t portnumber, - iolink_port_t ** port) +static inline iolink_error_t portnumber_to_iolinkport ( + uint8_t portnumber, + iolink_port_t ** port) { uint8_t port_index = portnumber - 1; @@ -114,8 +120,7 @@ static inline iolink_error_t portnumber_to_iolinkport (uint8_t portnumber, return IOLINK_ERROR_STATE_INVALID; } - if ((portnumber == 0) || - (port_index > the_master->port_cnt)) + if ((portnumber == 0) || (port_index > the_master->port_cnt)) { return IOLINK_ERROR_PARAMETER_CONFLICT; } @@ -125,9 +130,10 @@ static inline iolink_error_t portnumber_to_iolinkport (uint8_t portnumber, return IOLINK_ERROR_NONE; } -static inline iolink_error_t common_smi_check (uint8_t portnumber, - arg_block_t * arg_block, - iolink_port_t ** port) +static inline iolink_error_t common_smi_check ( + uint8_t portnumber, + arg_block_t * arg_block, + iolink_port_t ** port) { iolink_error_t error = portnumber_to_iolinkport (portnumber, port); @@ -163,10 +169,13 @@ static void iolink_main (void * arg) case IOLINK_JOB_PD_EVENT: if (master->cb_pd) { - master->cb_pd (iolink_get_portnumber (job->port), master->cb_arg, - job->pd_event.data_len, job->pd_event.data); + master->cb_pd ( + iolink_get_portnumber (job->port), + master->cb_arg, + job->pd_event.data_len, + job->pd_event.data); } - job->type = IOLINK_JOB_NONE; + job->type = IOLINK_JOB_NONE; job->callback = NULL; os_mbox_post (master->mbox_avail, job, 0); break; @@ -202,7 +211,7 @@ static void iolink_main (void * arg) { job->callback (job); } - job->type = IOLINK_JOB_NONE; + job->type = IOLINK_JOB_NONE; job->callback = NULL; os_mbox_post (master->mbox_avail, job, 0); break; @@ -219,7 +228,7 @@ static void iolink_main (void * arg) { job->callback (job); } - job->type = IOLINK_JOB_NONE; + job->type = IOLINK_JOB_NONE; job->callback = NULL; os_mbox_post (master->mbox_api_avail, job, 0); break; @@ -240,8 +249,8 @@ iolink_job_t * iolink_fetch_avail_job (iolink_port_t * port) #ifdef __rtk__ // TODO make this generic /* Make sure internal API is not used from any other thread */ - CC_ASSERT (task_self() == port->master->thread || - task_self() == port->dl.thread); + CC_ASSERT ( + task_self() == port->master->thread || task_self() == port->dl.thread); #endif /* __rtk__ */ if (os_mbox_fetch (port->master->mbox_avail, (void **)&job, 0)) @@ -260,8 +269,8 @@ iolink_job_t * iolink_fetch_avail_api_job (iolink_port_t * port) #ifdef __rtk__ // TODO make this generic /* Make sure the external API is not used within the stack */ - CC_ASSERT (task_self() != port->master->thread && - task_self() != port->dl.thread); + CC_ASSERT ( + task_self() != port->master->thread && task_self() != port->dl.thread); #endif /* __rtk__ */ if (os_mbox_fetch (port->master->mbox_api_avail, (void **)&job, 0)) @@ -284,10 +293,13 @@ bool iolink_post_job (iolink_port_t * port, iolink_job_t * job) return res; } #else -void iolink_post_job_with_type_and_callback(iolink_port_t * port, iolink_job_t * job, - iolink_job_type_t type, void (*callback)(struct iolink_job * job)) +void iolink_post_job_with_type_and_callback ( + iolink_port_t * port, + iolink_job_t * job, + iolink_job_type_t type, + void (*callback) (struct iolink_job * job)) { - job->type = type; + job->type = type; job->callback = callback; bool res = os_mbox_post (port->master->mbox, job, 0); @@ -295,17 +307,20 @@ void iolink_post_job_with_type_and_callback(iolink_port_t * port, iolink_job_t * } #endif -bool iolink_post_job_pd_event (iolink_port_t * port, uint32_t timeout, - uint8_t data_len, const uint8_t * data) +bool iolink_post_job_pd_event ( + iolink_port_t * port, + uint32_t timeout, + uint8_t data_len, + const uint8_t * data) { iolink_job_t * job; os_mbox_fetch (port->master->mbox_avail, (void **)&job, OS_WAIT_FOREVER); - job->port = port; - job->type = IOLINK_JOB_PD_EVENT; + job->port = port; + job->type = IOLINK_JOB_PD_EVENT; job->pd_event.data_len = data_len; - job->pd_event.data = data; + job->pd_event.data = data; bool res = os_mbox_post (port->master->mbox, job, timeout); CC_ASSERT (!res); // TODO how to handle this!?! @@ -313,48 +328,62 @@ bool iolink_post_job_pd_event (iolink_port_t * port, uint32_t timeout, return res; } -void iolink_smi_cnf (iolink_port_t * port, - iolink_arg_block_id_t ref_arg_block_id, - uint16_t arg_block_len, arg_block_t * arg_block) +void iolink_smi_cnf ( + iolink_port_t * port, + iolink_arg_block_id_t ref_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block) { if (port->master->cb_smi) { - port->master->cb_smi (port->master->cb_arg, iolink_get_portnumber (port), - ref_arg_block_id, arg_block_len, arg_block); + port->master->cb_smi ( + port->master->cb_arg, + iolink_get_portnumber (port), + ref_arg_block_id, + arg_block_len, + arg_block); } } -void iolink_smi_voidblock_cnf (iolink_port_t * port, - iolink_arg_block_id_t ref_arg_block_id) +void iolink_smi_voidblock_cnf ( + iolink_port_t * port, + iolink_arg_block_id_t ref_arg_block_id) { if (port->master->cb_smi) { arg_block_void_t arg_block_void; - memset (&arg_block_void, 0, sizeof(arg_block_void_t)); + memset (&arg_block_void, 0, sizeof (arg_block_void_t)); arg_block_void.arg_block_id = IOLINK_ARG_BLOCK_ID_VOID_BLOCK; - port->master->cb_smi (port->master->cb_arg, iolink_get_portnumber (port), - ref_arg_block_id, sizeof(arg_block_void_t), - (arg_block_t *)&arg_block_void); + port->master->cb_smi ( + port->master->cb_arg, + iolink_get_portnumber (port), + ref_arg_block_id, + sizeof (arg_block_void_t), + (arg_block_t *)&arg_block_void); } } -void iolink_smi_joberror_ind (iolink_port_t * port, - iolink_arg_block_id_t exp_arg_block_id, - iolink_arg_block_id_t ref_arg_block_id, - iolink_smi_errortypes_t error) +void iolink_smi_joberror_ind ( + iolink_port_t * port, + iolink_arg_block_id_t exp_arg_block_id, + iolink_arg_block_id_t ref_arg_block_id, + iolink_smi_errortypes_t error) { if (port->master->cb_smi) { arg_block_joberror_t arg_block_error; - memset (&arg_block_error, 0, sizeof(arg_block_joberror_t)); - arg_block_error.arg_block_id = IOLINK_ARG_BLOCK_ID_JOB_ERROR; + memset (&arg_block_error, 0, sizeof (arg_block_joberror_t)); + arg_block_error.arg_block_id = IOLINK_ARG_BLOCK_ID_JOB_ERROR; arg_block_error.exp_arg_block_id = exp_arg_block_id; - arg_block_error.error = error; - port->master->cb_smi (port->master->cb_arg, iolink_get_portnumber (port), - ref_arg_block_id, sizeof(arg_block_joberror_t), - (arg_block_t *)&arg_block_error); + arg_block_error.error = error; + port->master->cb_smi ( + port->master->cb_arg, + iolink_get_portnumber (port), + ref_arg_block_id, + sizeof (arg_block_joberror_t), + (arg_block_t *)&arg_block_error); } } @@ -362,8 +391,7 @@ iolink_port_t * iolink_get_port (iolink_m_t * master, uint8_t portnumber) { uint8_t port_index = portnumber - 1; - if ((portnumber == 0) || - (port_index > master->port_cnt)) + if ((portnumber == 0) || (port_index > master->port_cnt)) { return NULL; } @@ -452,16 +480,17 @@ iolink_m_t * iolink_m_init (const iolink_m_cfg_t * m_cfg) return NULL; } - iolink_m_t * master = calloc (1, sizeof(iolink_m_t) + sizeof(iolink_port_t) * m_cfg->port_cnt); + iolink_m_t * master = + calloc (1, sizeof (iolink_m_t) + sizeof (iolink_port_t) * m_cfg->port_cnt); if (master == NULL) { return NULL; } master->port_cnt = m_cfg->port_cnt; - master->cb_arg = m_cfg->cb_arg; - master->cb_smi = m_cfg->cb_smi; - master->cb_pd = m_cfg->cb_pd; + master->cb_arg = m_cfg->cb_arg; + master->cb_smi = m_cfg->cb_smi; + master->cb_pd = m_cfg->cb_pd; for (i = 0; i < master->port_cnt; i++) { @@ -470,7 +499,7 @@ iolink_m_t * iolink_m_init (const iolink_m_cfg_t * m_cfg) iolink_port_t * port = &(master->ports[i]); - port->master = master; + port->master = master; port->portnumber = i + 1; iolink_pl_init (port, port_cfg->name); @@ -482,8 +511,9 @@ iolink_m_t * iolink_m_init (const iolink_m_cfg_t * m_cfg) iolink_pde_init (port); } - master->mbox = os_mbox_create (IOLINK_MASTER_JOB_CNT + IOLINK_MASTER_JOB_API_CNT); - master->mbox_avail = os_mbox_create (IOLINK_MASTER_JOB_CNT); + master->mbox = + os_mbox_create (IOLINK_MASTER_JOB_CNT + IOLINK_MASTER_JOB_API_CNT); + master->mbox_avail = os_mbox_create (IOLINK_MASTER_JOB_CNT); master->mbox_api_avail = os_mbox_create (IOLINK_MASTER_JOB_API_CNT); for (i = 0; i < IOLINK_MASTER_JOB_CNT; i++) @@ -498,8 +528,12 @@ iolink_m_t * iolink_m_init (const iolink_m_cfg_t * m_cfg) os_mbox_post (master->mbox_api_avail, &master->job_api[i], 0); } - master->thread = os_thread_create ("iolink_m_thread", m_cfg->master_thread_prio, - m_cfg->master_thread_stack_size, iolink_main, master); + master->thread = os_thread_create ( + "iolink_m_thread", + m_cfg->master_thread_prio, + m_cfg->master_thread_stack_size, + iolink_main, + master); CC_ASSERT (master->thread != NULL); the_master = master; @@ -543,13 +577,16 @@ void iolink_m_deinit (iolink_m_t ** m) *m = NULL; } -static iolink_error_t SMI_common_req (uint8_t portnumber, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, arg_block_t * arg_block, - iolink_error_t (*SMI_req_fn) (iolink_port_t * port, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, - arg_block_t * arg_block_t)) +static iolink_error_t SMI_common_req ( + uint8_t portnumber, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block, + iolink_error_t (*SMI_req_fn) ( + iolink_port_t * port, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block_t)) { iolink_port_t * port = NULL; @@ -563,49 +600,81 @@ static iolink_error_t SMI_common_req (uint8_t portnumber, return SMI_req_fn (port, exp_arg_block_id, arg_block_len, arg_block); } -iolink_error_t SMI_MasterIdentification_req (uint8_t portnumber, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, arg_block_t * arg_block) -{ - return SMI_common_req(portnumber, exp_arg_block_id, arg_block_len, arg_block, - cm_SMI_MasterIdentification_req); -} - -iolink_error_t SMI_PortConfiguration_req (uint8_t portnumber, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, arg_block_t * arg_block) -{ - return SMI_common_req(portnumber, exp_arg_block_id, arg_block_len, arg_block, - cm_SMI_PortConfiguration_req); -} - -iolink_error_t SMI_ReadbackPortConfiguration_req (uint8_t portnumber, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, arg_block_t * arg_block) -{ - return SMI_common_req(portnumber, exp_arg_block_id, arg_block_len, arg_block, - cm_SMI_ReadbackPortConfiguration_req); -} - -iolink_error_t SMI_PortStatus_req (uint8_t portnumber, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, arg_block_t * arg_block) -{ - return SMI_common_req(portnumber, exp_arg_block_id, arg_block_len, arg_block, - cm_SMI_PortStatus_req); -} - -iolink_error_t SMI_DeviceRead_req (uint8_t portnumber, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, arg_block_t * arg_block) -{ - return SMI_common_req(portnumber, exp_arg_block_id, arg_block_len, arg_block, - ode_SMI_DeviceRead_req); -} - -iolink_error_t SMI_DeviceWrite_req (uint8_t portnumber, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, arg_block_t * arg_block) +iolink_error_t SMI_MasterIdentification_req ( + uint8_t portnumber, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block) +{ + return SMI_common_req ( + portnumber, + exp_arg_block_id, + arg_block_len, + arg_block, + cm_SMI_MasterIdentification_req); +} + +iolink_error_t SMI_PortConfiguration_req ( + uint8_t portnumber, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block) +{ + return SMI_common_req ( + portnumber, + exp_arg_block_id, + arg_block_len, + arg_block, + cm_SMI_PortConfiguration_req); +} + +iolink_error_t SMI_ReadbackPortConfiguration_req ( + uint8_t portnumber, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block) +{ + return SMI_common_req ( + portnumber, + exp_arg_block_id, + arg_block_len, + arg_block, + cm_SMI_ReadbackPortConfiguration_req); +} + +iolink_error_t SMI_PortStatus_req ( + uint8_t portnumber, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block) +{ + return SMI_common_req ( + portnumber, + exp_arg_block_id, + arg_block_len, + arg_block, + cm_SMI_PortStatus_req); +} + +iolink_error_t SMI_DeviceRead_req ( + uint8_t portnumber, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block) +{ + return SMI_common_req ( + portnumber, + exp_arg_block_id, + arg_block_len, + arg_block, + ode_SMI_DeviceRead_req); +} + +iolink_error_t SMI_DeviceWrite_req ( + uint8_t portnumber, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block) { iolink_port_t * port = NULL; @@ -617,7 +686,7 @@ iolink_error_t SMI_DeviceWrite_req (uint8_t portnumber, } // special check needed to pass test case 289 - if ((arg_block->od.index == 24) && ((arg_block_len - sizeof(arg_block_od_t)) == 10)) + if ((arg_block->od.index == 24) && ((arg_block_len - sizeof (arg_block_od_t)) == 10)) { return IOLINK_ERROR_ODLENGTH; } @@ -625,51 +694,86 @@ iolink_error_t SMI_DeviceWrite_req (uint8_t portnumber, return ode_SMI_DeviceWrite_req (port, exp_arg_block_id, arg_block_len, arg_block); } - -iolink_error_t SMI_ParamReadBatch_req (uint8_t portnumber, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, arg_block_t * arg_block) -{ - return SMI_common_req(portnumber, exp_arg_block_id, arg_block_len, arg_block, - ode_SMI_ParamReadBatch_req); -} - -iolink_error_t SMI_ParamWriteBatch_req (uint8_t portnumber, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, arg_block_t * arg_block) -{ - return SMI_common_req(portnumber, exp_arg_block_id, arg_block_len, arg_block, - ode_SMI_ParamWriteBatch_req); -} - -iolink_error_t SMI_PDIn_req (uint8_t portnumber, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, arg_block_t * arg_block) -{ - return SMI_common_req(portnumber, exp_arg_block_id, arg_block_len, arg_block, - pde_SMI_PDIn_req); -} - -iolink_error_t SMI_PDOut_req (uint8_t portnumber, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, arg_block_t * arg_block) -{ - return SMI_common_req(portnumber, exp_arg_block_id, arg_block_len, arg_block, - pde_SMI_PDOut_req); -} - -iolink_error_t SMI_PDInOut_req (uint8_t portnumber, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, arg_block_t * arg_block) -{ - return SMI_common_req(portnumber, exp_arg_block_id, arg_block_len, arg_block, - pde_SMI_PDInOut_req); -} - -iolink_error_t SMI_ParServToDS_req (uint8_t portnumber, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, arg_block_t * arg_block) -{ - return SMI_common_req(portnumber, exp_arg_block_id, arg_block_len, arg_block, - ds_SMI_ParServToDS_req); +iolink_error_t SMI_ParamReadBatch_req ( + uint8_t portnumber, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block) +{ + return SMI_common_req ( + portnumber, + exp_arg_block_id, + arg_block_len, + arg_block, + ode_SMI_ParamReadBatch_req); +} + +iolink_error_t SMI_ParamWriteBatch_req ( + uint8_t portnumber, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block) +{ + return SMI_common_req ( + portnumber, + exp_arg_block_id, + arg_block_len, + arg_block, + ode_SMI_ParamWriteBatch_req); +} + +iolink_error_t SMI_PDIn_req ( + uint8_t portnumber, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block) +{ + return SMI_common_req ( + portnumber, + exp_arg_block_id, + arg_block_len, + arg_block, + pde_SMI_PDIn_req); +} + +iolink_error_t SMI_PDOut_req ( + uint8_t portnumber, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block) +{ + return SMI_common_req ( + portnumber, + exp_arg_block_id, + arg_block_len, + arg_block, + pde_SMI_PDOut_req); +} + +iolink_error_t SMI_PDInOut_req ( + uint8_t portnumber, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block) +{ + return SMI_common_req ( + portnumber, + exp_arg_block_id, + arg_block_len, + arg_block, + pde_SMI_PDInOut_req); +} + +iolink_error_t SMI_ParServToDS_req ( + uint8_t portnumber, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block) +{ + return SMI_common_req ( + portnumber, + exp_arg_block_id, + arg_block_len, + arg_block, + ds_SMI_ParServToDS_req); } diff --git a/src/iolink_main.h b/src/iolink_main.h index 0c29d1c..aee65e4 100644 --- a/src/iolink_main.h +++ b/src/iolink_main.h @@ -10,13 +10,11 @@ * See LICENSE file in the project root for full license information. ********************************************************************/ - #ifndef IOLINK_MAIN_H #define IOLINK_MAIN_H #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif #include "iolink_types.h" @@ -113,7 +111,7 @@ typedef struct iolink_job { iolink_job_type_t type; iolink_port_t * port; - void (*callback)(struct iolink_job * job); + void (*callback) (struct iolink_job * job); union { iolink_mhmode_t dl_mode; @@ -148,10 +146,11 @@ typedef struct iolink_job uint16_t index; uint8_t subindex; uint8_t val; - void (*al_read_cb)(iolink_port_t * port, - uint8_t len, - const uint8_t * data, - iolink_smi_errortypes_t errortype); + void (*al_read_cb) ( + iolink_port_t * port, + uint8_t len, + const uint8_t * data, + iolink_smi_errortypes_t errortype); } al_read_req; struct { @@ -159,8 +158,9 @@ typedef struct iolink_job uint8_t subindex; uint8_t length; const uint8_t * data; - void (*al_write_cb)(iolink_port_t * port, - iolink_smi_errortypes_t errortype); + void (*al_write_cb) ( + iolink_port_t * port, + iolink_smi_errortypes_t errortype); } al_write_req; struct { @@ -225,21 +225,31 @@ iolink_job_t * iolink_fetch_avail_api_job (iolink_port_t * port); #ifdef UNIT_TEST bool iolink_post_job (iolink_port_t * port, iolink_job_t * job); #else -void iolink_post_job_with_type_and_callback(iolink_port_t * port, iolink_job_t * job, - iolink_job_type_t type, void (*callback)(struct iolink_job * job)); +void iolink_post_job_with_type_and_callback ( + iolink_port_t * port, + iolink_job_t * job, + iolink_job_type_t type, + void (*callback) (struct iolink_job * job)); #endif -bool iolink_post_job_pd_event (iolink_port_t * port, uint32_t timeout, - uint8_t data_len, const uint8_t * data); +bool iolink_post_job_pd_event ( + iolink_port_t * port, + uint32_t timeout, + uint8_t data_len, + const uint8_t * data); -void iolink_smi_cnf (iolink_port_t * port, - iolink_arg_block_id_t ref_arg_block_id, - uint16_t arg_block_len, arg_block_t * arg_block); -void iolink_smi_voidblock_cnf (iolink_port_t * port, - iolink_arg_block_id_t ref_arg_block_id); -void iolink_smi_joberror_ind (iolink_port_t * port, - iolink_arg_block_id_t exp_arg_block_id, - iolink_arg_block_id_t ref_arg_block_id, - iolink_smi_errortypes_t error); +void iolink_smi_cnf ( + iolink_port_t * port, + iolink_arg_block_id_t ref_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block); +void iolink_smi_voidblock_cnf ( + iolink_port_t * port, + iolink_arg_block_id_t ref_arg_block_id); +void iolink_smi_joberror_ind ( + iolink_port_t * port, + iolink_arg_block_id_t exp_arg_block_id, + iolink_arg_block_id_t ref_arg_block_id, + iolink_smi_errortypes_t error); /** * Get port information diff --git a/src/iolink_max14819_pl.c b/src/iolink_max14819_pl.c index 43a430d..f195cc9 100644 --- a/src/iolink_max14819_pl.c +++ b/src/iolink_max14819_pl.c @@ -24,38 +24,41 @@ #include #include "spi/spi.h" -#define SPI_TRANSFER(fd, rbuf, wbuf, size) \ - spi_select (fd); \ - spi_bidirectionally_transfer (fd, rbuf, wbuf, size); \ +#define SPI_TRANSFER(fd, rbuf, wbuf, size) \ + spi_select (fd); \ + spi_bidirectionally_transfer (fd, rbuf, wbuf, size); \ spi_unselect (fd); #elif defined(__linux__) #include #include -void spi_transfer(int fd, void * data_read, const void * data_written, size_t n_bytes_to_transfer) +void spi_transfer ( + int fd, + void * data_read, + const void * data_written, + size_t n_bytes_to_transfer) { // TODO int delay = 100; int speed = 4 * 1000 * 1000; - int bits = 8; + int bits = 8; struct spi_ioc_transfer tr = { - .tx_buf = (unsigned long)data_written, - .rx_buf = (unsigned long)data_read, - .len = n_bytes_to_transfer, - .delay_usecs = delay, - .speed_hz = speed, - .bits_per_word = bits, + .tx_buf = (unsigned long)data_written, + .rx_buf = (unsigned long)data_read, + .len = n_bytes_to_transfer, + .delay_usecs = delay, + .speed_hz = speed, + .bits_per_word = bits, }; - if (ioctl (fd, SPI_IOC_MESSAGE(1), &tr) < 1) + if (ioctl (fd, SPI_IOC_MESSAGE (1), &tr) < 1) { LOG_ERROR (IOLINK_PL_LOG, "%s: failed to send SPI message\n", __func__); } } -#define SPI_TRANSFER(fd, rbuf, wbuf, size) \ - spi_transfer(fd, rbuf, wbuf, size); +#define SPI_TRANSFER(fd, rbuf, wbuf, size) spi_transfer (fd, rbuf, wbuf, size); #endif /** @@ -80,60 +83,60 @@ void spi_transfer(int fd, void * data_read, const void * data_written, size_t n_ #define MAX14819_ADDR_OFFSET 5 #define MAX14819_REGISTER_OFFSET 0 -#define REG_TxRxDataA 0x00 -#define REG_TxRxDataB 0x01 -#define REG_Interrupt 0x02 -#define REG_InterruptEn 0x03 -#define REG_RxFIFOLvlA 0x04 -#define REG_RxFIFOLvlB 0x05 -#define REG_CQCtrlA 0x06 -#define REG_CQCtrlB 0x07 -#define REG_CQErrA 0x08 -#define REG_CQErrB 0x09 -#define REG_MsgCtrlA 0x0A -#define REG_MsgCtrlB 0x0B -#define REG_ChanStatA 0x0C -#define REG_ChanStatB 0x0D -#define REG_LEDCtrl 0x0E -#define REG_Trigger 0x0F -#define REG_CQCfgA 0x10 -#define REG_CQCfgB 0x11 -#define REG_CyclTmrA 0x12 -#define REG_CyclTmrB 0x13 -#define REG_DeviceDlyA 0x14 -#define REG_DeviceDlyB 0x15 -#define REG_TrigAssgnA 0x16 -#define REG_TrigAssgnB 0x17 -#define REG_LPCnfgA 0x18 -#define REG_LPCnfgB 0x19 -#define REG_IOStCfgA 0x1A -#define REG_IOStCfgB 0x1B -#define REG_DrvrCurrLim 0x1C -#define REG_Clock 0x1D -#define REG_Status 0x1E -#define REG_RevID 0x1F - -#define MAX14819_SPI_INBAND_RRDYA BIT(0) -#define MAX14819_SPI_INBAND_RERRA BIT(1) -#define MAX14819_SPI_INBAND_RRDYB BIT(2) -#define MAX14819_SPI_INBAND_RERRB BIT(3) -#define MAX14819_SPI_INBAND_IRQ BIT(4) - -#define MAX14819_CQCTRL_CQ_SEND BIT(0) -#define MAX14819_CQCTRL_CYC_TMR_EN BIT(1) -#define MAX14819_CQCTRL_RX_FIFO_RST BIT(2) -#define MAX14819_CQCTRL_TX_FIFO_RST BIT(3) -#define MAX14819_CQCTRL_WU_PULS BIT(4) -#define MAX14819_CQCTRL_EST_COM BIT(5) - -#define MAX14819_INTERRUPT_RX_DATA_RDY_A BIT(0) -#define MAX14819_INTERRUPT_RX_DATA_RDY_B BIT(1) -#define MAX14819_INTERRUPT_RX_ERR_A BIT(2) -#define MAX14819_INTERRUPT_RX_ERR_B BIT(3) -#define MAX14819_INTERRUPT_TX_ERR_A BIT(4) -#define MAX14819_INTERRUPT_TX_ERR_B BIT(5) -#define MAX14819_INTERRUPT_WURQ BIT(6) -#define MAX14819_INTERRUPT_STATUS BIT(7) +#define REG_TxRxDataA 0x00 +#define REG_TxRxDataB 0x01 +#define REG_Interrupt 0x02 +#define REG_InterruptEn 0x03 +#define REG_RxFIFOLvlA 0x04 +#define REG_RxFIFOLvlB 0x05 +#define REG_CQCtrlA 0x06 +#define REG_CQCtrlB 0x07 +#define REG_CQErrA 0x08 +#define REG_CQErrB 0x09 +#define REG_MsgCtrlA 0x0A +#define REG_MsgCtrlB 0x0B +#define REG_ChanStatA 0x0C +#define REG_ChanStatB 0x0D +#define REG_LEDCtrl 0x0E +#define REG_Trigger 0x0F +#define REG_CQCfgA 0x10 +#define REG_CQCfgB 0x11 +#define REG_CyclTmrA 0x12 +#define REG_CyclTmrB 0x13 +#define REG_DeviceDlyA 0x14 +#define REG_DeviceDlyB 0x15 +#define REG_TrigAssgnA 0x16 +#define REG_TrigAssgnB 0x17 +#define REG_LPCnfgA 0x18 +#define REG_LPCnfgB 0x19 +#define REG_IOStCfgA 0x1A +#define REG_IOStCfgB 0x1B +#define REG_DrvrCurrLim 0x1C +#define REG_Clock 0x1D +#define REG_Status 0x1E +#define REG_RevID 0x1F + +#define MAX14819_SPI_INBAND_RRDYA BIT (0) +#define MAX14819_SPI_INBAND_RERRA BIT (1) +#define MAX14819_SPI_INBAND_RRDYB BIT (2) +#define MAX14819_SPI_INBAND_RERRB BIT (3) +#define MAX14819_SPI_INBAND_IRQ BIT (4) + +#define MAX14819_CQCTRL_CQ_SEND BIT (0) +#define MAX14819_CQCTRL_CYC_TMR_EN BIT (1) +#define MAX14819_CQCTRL_RX_FIFO_RST BIT (2) +#define MAX14819_CQCTRL_TX_FIFO_RST BIT (3) +#define MAX14819_CQCTRL_WU_PULS BIT (4) +#define MAX14819_CQCTRL_EST_COM BIT (5) + +#define MAX14819_INTERRUPT_RX_DATA_RDY_A BIT (0) +#define MAX14819_INTERRUPT_RX_DATA_RDY_B BIT (1) +#define MAX14819_INTERRUPT_RX_ERR_A BIT (2) +#define MAX14819_INTERRUPT_RX_ERR_B BIT (3) +#define MAX14819_INTERRUPT_TX_ERR_A BIT (4) +#define MAX14819_INTERRUPT_TX_ERR_B BIT (5) +#define MAX14819_INTERRUPT_WURQ BIT (6) +#define MAX14819_INTERRUPT_STATUS BIT (7) #define MAX14819_INTERRUPTEN_RX_DATA_RDY_A MAX14819_INTERRUPT_RX_DATA_RDY_A #define MAX14819_INTERRUPTEN_RX_DATA_RDY_B MAX14819_INTERRUPT_RX_DATA_RDY_B @@ -147,18 +150,22 @@ void spi_transfer(int fd, void * data_read, const void * data_written, size_t n_ typedef enum { IOLINK_14819_CHANNEL_INVALID = -1, - IOLINK_14819_CHANNEL_A = 0, - IOLINK_14819_CHANNEL_B = 1, + IOLINK_14819_CHANNEL_A = 0, + IOLINK_14819_CHANNEL_B = 1, } iolink_14819_channel_t; -typedef union { - struct { +typedef union +{ + struct + { uint8_t cq_conf_val; } DO; - struct { + struct + { uint8_t cq_conf_val; } DI; - struct { + struct + { uint8_t IntE; uint8_t cq_ctrl_val; uint8_t msg_ctrl_val; @@ -169,11 +176,12 @@ typedef union { } SDCI; } iolink_14819_cq_cfg_t; -static void iolink_pl_max14819_pl_handler (iolink_hw_drv_t * iolink_hw, - void * arg); +static void iolink_pl_max14819_pl_handler (iolink_hw_drv_t * iolink_hw, void * arg); -static void iolink_14819_write_register (iolink_14819_drv_t * iolink, - uint8_t reg, uint8_t value) +static void iolink_14819_write_register ( + iolink_14819_drv_t * iolink, + uint8_t reg, + uint8_t value) { uint8_t wbuf[2]; uint8_t rbuf[2]; @@ -184,11 +192,10 @@ static void iolink_14819_write_register (iolink_14819_drv_t * iolink, (iolink->chip_address << MAX14819_ADDR_OFFSET) | (reg << MAX14819_REGISTER_OFFSET); wbuf[1] = value; - SPI_TRANSFER(iolink->fd_spi, &rbuf, &wbuf, sizeof(wbuf)); + SPI_TRANSFER (iolink->fd_spi, &rbuf, &wbuf, sizeof (wbuf)); } -static uint8_t iolink_14819_read_register (iolink_14819_drv_t * iolink, - uint8_t reg) +static uint8_t iolink_14819_read_register (iolink_14819_drv_t * iolink, uint8_t reg) { uint8_t wbuf[2]; uint8_t rbuf[2]; @@ -199,7 +206,7 @@ static uint8_t iolink_14819_read_register (iolink_14819_drv_t * iolink, (iolink->chip_address << MAX14819_ADDR_OFFSET) | (reg << MAX14819_REGISTER_OFFSET); wbuf[1] = 0; - SPI_TRANSFER(iolink->fd_spi, &rbuf, &wbuf, sizeof(wbuf)); + SPI_TRANSFER (iolink->fd_spi, &rbuf, &wbuf, sizeof (wbuf)); /* Check SPI In-Band Device-Message-Ready */ if (reg == REG_RxFIFOLvlA) { @@ -215,9 +222,11 @@ static uint8_t iolink_14819_read_register (iolink_14819_drv_t * iolink, return rbuf[1]; } -static void iolink_14819_burst_write_tx (iolink_14819_drv_t * iolink, - iolink_14819_channel_t ch, - uint8_t *data, uint8_t size) +static void iolink_14819_burst_write_tx ( + iolink_14819_drv_t * iolink, + iolink_14819_channel_t ch, + uint8_t * data, + uint8_t size) { uint8_t rxtxreg = REG_TxRxDataA + ch; uint8_t idx; @@ -225,114 +234,120 @@ static void iolink_14819_burst_write_tx (iolink_14819_drv_t * iolink, uint8_t data_rx[IOLINK_RXTX_BUFFER_SIZE + 1] = {0}; data_tx[0] = MAX14819_COMMAND_WRITE | - (iolink->chip_address << MAX14819_ADDR_OFFSET) | - (rxtxreg << MAX14819_REGISTER_OFFSET); - memcpy(&data_tx[1], data, size); - SPI_TRANSFER(iolink->fd_spi, data_rx, data_tx, size + 1); + (iolink->chip_address << MAX14819_ADDR_OFFSET) | + (rxtxreg << MAX14819_REGISTER_OFFSET); + memcpy (&data_tx[1], data, size); + SPI_TRANSFER (iolink->fd_spi, data_rx, data_tx, size + 1); for (idx = 0; idx < size; idx++) { if (data_tx[idx] != data_rx[idx + 1]) { - //TODO: Fix better id of iolink. Only channel is not good enough - LOG_ERROR (IOLINK_PL_LOG, - "IOLINK: CH %d. Data transfer error byte %d\n", ch, idx); + // TODO: Fix better id of iolink. Only channel is not good enough + LOG_ERROR ( + IOLINK_PL_LOG, + "IOLINK: CH %d. Data transfer error byte %d\n", + ch, + idx); } } } -static uint8_t iolink_14819_burst_read_rx (iolink_14819_drv_t * iolink, - iolink_14819_channel_t ch, - uint8_t *data, uint8_t rxbytes) +static uint8_t iolink_14819_burst_read_rx ( + iolink_14819_drv_t * iolink, + iolink_14819_channel_t ch, + uint8_t * data, + uint8_t rxbytes) { - uint8_t rxtxreg = REG_TxRxDataA + ch; + uint8_t rxtxreg = REG_TxRxDataA + ch; uint8_t txdata[IOLINK_RXTX_BUFFER_SIZE + 2] = {0}; uint8_t rxdata[IOLINK_RXTX_BUFFER_SIZE + 2] = {0}; txdata[0] = MAX14819_COMMAND_READ | - (iolink->chip_address << MAX14819_ADDR_OFFSET) | - (rxtxreg << MAX14819_REGISTER_OFFSET); - SPI_TRANSFER(iolink->fd_spi, rxdata, txdata, rxbytes + 2); - memcpy(data, &rxdata[1], rxbytes); + (iolink->chip_address << MAX14819_ADDR_OFFSET) | + (rxtxreg << MAX14819_REGISTER_OFFSET); + SPI_TRANSFER (iolink->fd_spi, rxdata, txdata, rxbytes + 2); + memcpy (data, &rxdata[1], rxbytes); return rxdata[0]; } -static void iolink_14819_set_DO (iolink_14819_drv_t * iolink, - iolink_14819_channel_t ch, - iolink_14819_cq_cfg_t * cfg) +static void iolink_14819_set_DO ( + iolink_14819_drv_t * iolink, + iolink_14819_channel_t ch, + iolink_14819_cq_cfg_t * cfg) { uint8_t regval; os_mutex_lock (iolink->exclusive); regval = iolink_14819_read_register (iolink, REG_InterruptEn); - iolink_14819_write_register (iolink, REG_InterruptEn, - regval & ~(0x05 << ch)); + iolink_14819_write_register (iolink, REG_InterruptEn, regval & ~(0x05 << ch)); os_mutex_unlock (iolink->exclusive); iolink_14819_write_register (iolink, REG_CQCtrlA + ch, 0x0C); iolink_14819_write_register (iolink, REG_MsgCtrlA + ch, 0x01); - iolink_14819_write_register (iolink, REG_CQCfgA + ch, - cfg->DO.cq_conf_val & 0x0C); + iolink_14819_write_register (iolink, REG_CQCfgA + ch, cfg->DO.cq_conf_val & 0x0C); iolink_14819_write_register (iolink, REG_TrigAssgnA + ch, 0x00); - iolink->is_iolink[ch] = false; + iolink->is_iolink[ch] = false; iolink->wurq_request[ch] = false; } -static void iolink_14819_set_DI (iolink_14819_drv_t * iolink, - iolink_14819_channel_t ch, - iolink_14819_cq_cfg_t * cfg) +static void iolink_14819_set_DI ( + iolink_14819_drv_t * iolink, + iolink_14819_channel_t ch, + iolink_14819_cq_cfg_t * cfg) { uint8_t regval; os_mutex_lock (iolink->exclusive); regval = iolink_14819_read_register (iolink, REG_InterruptEn); - iolink_14819_write_register (iolink, REG_InterruptEn, - regval & ~(0x05 << ch)); + iolink_14819_write_register (iolink, REG_InterruptEn, regval & ~(0x05 << ch)); os_mutex_unlock (iolink->exclusive); iolink_14819_write_register (iolink, REG_CQCtrlA + ch, 0x0C); iolink_14819_write_register (iolink, REG_MsgCtrlA + ch, 0x01); - iolink_14819_write_register (iolink, REG_CQCfgA + ch, - (cfg->DI.cq_conf_val & 0xF1) | 0x02); + iolink_14819_write_register ( + iolink, + REG_CQCfgA + ch, + (cfg->DI.cq_conf_val & 0xF1) | 0x02); iolink_14819_write_register (iolink, REG_TrigAssgnA + ch, 0x00); - iolink->is_iolink[ch] = false; + iolink->is_iolink[ch] = false; iolink->wurq_request[ch] = false; } -static void iolink_14819_set_SDCI (iolink_14819_drv_t * iolink, - iolink_14819_channel_t ch, - iolink_14819_cq_cfg_t * cfg) +static void iolink_14819_set_SDCI ( + iolink_14819_drv_t * iolink, + iolink_14819_channel_t ch, + iolink_14819_cq_cfg_t * cfg) { uint8_t regval; os_mutex_lock (iolink->exclusive); - //Disable interrupts + // Disable interrupts regval = iolink_14819_read_register (iolink, REG_InterruptEn); - iolink_14819_write_register (iolink, REG_InterruptEn, - regval & ~(0x05 << ch)); - //Set registers according to config - iolink_14819_write_register (iolink, REG_CQCtrlA + ch, - cfg->SDCI.cq_ctrl_val); - iolink_14819_write_register (iolink, REG_MsgCtrlA + ch, - cfg->SDCI.msg_ctrl_val); - iolink_14819_write_register (iolink, REG_ChanStatA + ch, - cfg->SDCI.chan_stat_val); - iolink_14819_write_register (iolink, REG_CyclTmrA + ch, - cfg->SDCI.cycl_tmr_val); - iolink_14819_write_register (iolink, REG_DeviceDlyA + ch, - cfg->SDCI.dev_del_val); - iolink_14819_write_register (iolink, REG_TrigAssgnA + ch, - cfg->SDCI.trig_assg_val); + iolink_14819_write_register (iolink, REG_InterruptEn, regval & ~(0x05 << ch)); + // Set registers according to config + iolink_14819_write_register (iolink, REG_CQCtrlA + ch, cfg->SDCI.cq_ctrl_val); + iolink_14819_write_register (iolink, REG_MsgCtrlA + ch, cfg->SDCI.msg_ctrl_val); + iolink_14819_write_register (iolink, REG_ChanStatA + ch, cfg->SDCI.chan_stat_val); + iolink_14819_write_register (iolink, REG_CyclTmrA + ch, cfg->SDCI.cycl_tmr_val); + iolink_14819_write_register (iolink, REG_DeviceDlyA + ch, cfg->SDCI.dev_del_val); + iolink_14819_write_register ( + iolink, + REG_TrigAssgnA + ch, + cfg->SDCI.trig_assg_val); iolink_14819_write_register (iolink, REG_CQCfgA + ch, 0x34); - //Enable interrupts + // Enable interrupts regval = iolink_14819_read_register (iolink, REG_InterruptEn); - iolink_14819_write_register (iolink, REG_InterruptEn, - regval | (cfg->SDCI.IntE & (0x05 << ch))); + iolink_14819_write_register ( + iolink, + REG_InterruptEn, + regval | (cfg->SDCI.IntE & (0x05 << ch))); iolink->is_iolink[ch] = true; os_mutex_unlock (iolink->exclusive); } -static void iolink_14819_send_master_message (iolink_14819_drv_t * iolink, - iolink_14819_channel_t ch) +static void iolink_14819_send_master_message ( + iolink_14819_drv_t * iolink, + iolink_14819_channel_t ch) { uint8_t reg_val; uint8_t reg = REG_CQCtrlA + ch; @@ -342,8 +357,9 @@ static void iolink_14819_send_master_message (iolink_14819_drv_t * iolink, iolink_14819_write_register (iolink, reg, reg_val); } -static void iolink_14819_delete_master_message (iolink_14819_drv_t * iolink, - iolink_14819_channel_t ch) +static void iolink_14819_delete_master_message ( + iolink_14819_drv_t * iolink, + iolink_14819_channel_t ch) { uint8_t regCQCtrl, reg_val; @@ -354,10 +370,13 @@ static void iolink_14819_delete_master_message (iolink_14819_drv_t * iolink, iolink_14819_write_register (iolink, regCQCtrl, reg_val); } -static void iolink_14819_set_master_message (iolink_14819_drv_t * iolink, - iolink_14819_channel_t ch, - uint8_t *data, uint8_t txlen, - uint8_t rxlen, bool keepmessage) +static void iolink_14819_set_master_message ( + iolink_14819_drv_t * iolink, + iolink_14819_channel_t ch, + uint8_t * data, + uint8_t txlen, + uint8_t rxlen, + bool keepmessage) { uint8_t regMC, reg_val; uint8_t buffer[100]; @@ -371,25 +390,26 @@ static void iolink_14819_set_master_message (iolink_14819_drv_t * iolink, buffer[0] = rxlen; buffer[1] = txlen; memcpy (&buffer[2], data, txlen); - iolink_14819_burst_write_tx (iolink, ch, buffer, txlen+2); + iolink_14819_burst_write_tx (iolink, ch, buffer, txlen + 2); reg_val = iolink_14819_read_register (iolink, regMC); if (keepmessage) { - reg_val |= BIT(3); + reg_val |= BIT (3); } else { - reg_val &= ~BIT(3); + reg_val &= ~BIT (3); } iolink_14819_write_register (iolink, regMC, reg_val); } -static iolink_baudrate_t iolink_pl_max14819_get_baudrate (iolink_hw_drv_t * iolink_hw, - void * arg) +static iolink_baudrate_t iolink_pl_max14819_get_baudrate ( + iolink_hw_drv_t * iolink_hw, + void * arg) { iolink_14819_drv_t * iolink = (iolink_14819_drv_t *)iolink_hw; - iolink_14819_channel_t ch = (iolink_14819_channel_t)arg; + iolink_14819_channel_t ch = (iolink_14819_channel_t)arg; CC_ASSERT (ch >= MAX14819_CH_MIN); CC_ASSERT (ch <= MAX14819_CH_MAX); @@ -413,11 +433,12 @@ static iolink_baudrate_t iolink_pl_max14819_get_baudrate (iolink_hw_drv_t * ioli return IOLINK_BAUDRATE_NONE; } -static uint8_t iolink_pl_max14819_get_cycletime (iolink_hw_drv_t * iolink_hw, - void * arg) +static uint8_t iolink_pl_max14819_get_cycletime ( + iolink_hw_drv_t * iolink_hw, + void * arg) { iolink_14819_drv_t * iolink = (iolink_14819_drv_t *)iolink_hw; - iolink_14819_channel_t ch = (iolink_14819_channel_t)arg; + iolink_14819_channel_t ch = (iolink_14819_channel_t)arg; CC_ASSERT (ch >= MAX14819_CH_MIN); CC_ASSERT (ch <= MAX14819_CH_MAX); @@ -430,11 +451,13 @@ static uint8_t iolink_pl_max14819_get_cycletime (iolink_hw_drv_t * iolink_hw, return reg_val; } -static void iolink_pl_max14819_set_cycletime (iolink_hw_drv_t * iolink_hw, - void * arg, uint8_t cycbyte) +static void iolink_pl_max14819_set_cycletime ( + iolink_hw_drv_t * iolink_hw, + void * arg, + uint8_t cycbyte) { iolink_14819_drv_t * iolink = (iolink_14819_drv_t *)iolink_hw; - iolink_14819_channel_t ch = (iolink_14819_channel_t)arg; + iolink_14819_channel_t ch = (iolink_14819_channel_t)arg; CC_ASSERT (ch >= MAX14819_CH_MIN); CC_ASSERT (ch <= MAX14819_CH_MAX); @@ -444,11 +467,13 @@ static void iolink_pl_max14819_set_cycletime (iolink_hw_drv_t * iolink_hw, iolink_14819_write_register (iolink, reg, cycbyte); } -static bool iolink_pl_max14819_set_mode (iolink_hw_drv_t * iolink_hw, - void * arg, iolink_pl_mode_t mode) +static bool iolink_pl_max14819_set_mode ( + iolink_hw_drv_t * iolink_hw, + void * arg, + iolink_pl_mode_t mode) { iolink_14819_drv_t * iolink = (iolink_14819_drv_t *)iolink_hw; - iolink_14819_channel_t ch = (iolink_14819_channel_t)arg; + iolink_14819_channel_t ch = (iolink_14819_channel_t)arg; iolink_14819_cq_cfg_t iol_cfg; CC_ASSERT (ch >= MAX14819_CH_MIN); @@ -482,13 +507,14 @@ static bool iolink_pl_max14819_set_mode (iolink_hw_drv_t * iolink_hw, iolink->wurq_request[ch] = false; /* Since we clear CQCTRL_EST_COM */ - iol_cfg.SDCI.IntE = 0xFF; - iol_cfg.SDCI.msg_ctrl_val = 0x26; /* InsChks = 1, RChksEn = 1, RMessageRdyEn = 1 */ + iol_cfg.SDCI.IntE = 0xFF; + iol_cfg.SDCI.msg_ctrl_val = 0x26; /* InsChks = 1, RChksEn = 1, + RMessageRdyEn = 1 */ iol_cfg.SDCI.chan_stat_val = 0x40; /* FramerEn */ - iol_cfg.SDCI.cycl_tmr_val = 0x00; - iol_cfg.SDCI.dev_del_val = 0x43; /* BDelay=2, DDelay=1, RpsnsTmrEn=1 */ + iol_cfg.SDCI.cycl_tmr_val = 0x00; + iol_cfg.SDCI.dev_del_val = 0x43; /* BDelay=2, DDelay=1, RpsnsTmrEn=1 */ iol_cfg.SDCI.trig_assg_val = 0x00; - iol_cfg.SDCI.cq_ctrl_val = 0x00; /* TxFifoRst and RxFifoRst to 0*/ + iol_cfg.SDCI.cq_ctrl_val = 0x00; /* TxFifoRst and RxFifoRst to 0*/ iolink_14819_set_SDCI (iolink, ch, &iol_cfg); break; } @@ -497,26 +523,28 @@ static bool iolink_pl_max14819_set_mode (iolink_hw_drv_t * iolink_hw, return true; } -static void iolink_pl_max14819_configure_event (iolink_hw_drv_t * iolink_hw, - void * arg, - os_event_t * event, - uint32_t flag) +static void iolink_pl_max14819_configure_event ( + iolink_hw_drv_t * iolink_hw, + void * arg, + os_event_t * event, + uint32_t flag) { iolink_14819_drv_t * iolink = (iolink_14819_drv_t *)iolink_hw; - iolink_14819_channel_t ch = (iolink_14819_channel_t)arg; + iolink_14819_channel_t ch = (iolink_14819_channel_t)arg; CC_ASSERT (ch >= MAX14819_CH_MIN); CC_ASSERT (ch <= MAX14819_CH_MAX); iolink->dl_event[ch] = event; - iolink->pl_flag = flag; + iolink->pl_flag = flag; } -static void iolink_pl_max14819_enable_cycle_timer (iolink_hw_drv_t * iolink_hw, - void * arg) +static void iolink_pl_max14819_enable_cycle_timer ( + iolink_hw_drv_t * iolink_hw, + void * arg) { iolink_14819_drv_t * iolink = (iolink_14819_drv_t *)iolink_hw; - iolink_14819_channel_t ch = (iolink_14819_channel_t)arg; + iolink_14819_channel_t ch = (iolink_14819_channel_t)arg; CC_ASSERT (ch >= MAX14819_CH_MIN); CC_ASSERT (ch <= MAX14819_CH_MAX); @@ -529,11 +557,12 @@ static void iolink_pl_max14819_enable_cycle_timer (iolink_hw_drv_t * iolink_hw, iolink_14819_write_register (iolink, reg, reg_val); } -static void iolink_pl_max14819_disable_cycle_timer (iolink_hw_drv_t * iolink_hw, - void * arg) +static void iolink_pl_max14819_disable_cycle_timer ( + iolink_hw_drv_t * iolink_hw, + void * arg) { iolink_14819_drv_t * iolink = (iolink_14819_drv_t *)iolink_hw; - iolink_14819_channel_t ch = (iolink_14819_channel_t)arg; + iolink_14819_channel_t ch = (iolink_14819_channel_t)arg; CC_ASSERT (ch >= MAX14819_CH_MIN); CC_ASSERT (ch <= MAX14819_CH_MAX); @@ -546,64 +575,75 @@ static void iolink_pl_max14819_disable_cycle_timer (iolink_hw_drv_t * iolink_hw, iolink_14819_write_register (iolink, reg, reg_val); } -static void iolink_pl_max14819_get_error (iolink_hw_drv_t * iolink_hw, - void * arg, uint8_t *cqerr, - uint8_t *devdly) +static void iolink_pl_max14819_get_error ( + iolink_hw_drv_t * iolink_hw, + void * arg, + uint8_t * cqerr, + uint8_t * devdly) { iolink_14819_drv_t * iolink = (iolink_14819_drv_t *)iolink_hw; - iolink_14819_channel_t ch = (iolink_14819_channel_t)arg; + iolink_14819_channel_t ch = (iolink_14819_channel_t)arg; CC_ASSERT (ch >= MAX14819_CH_MIN); CC_ASSERT (ch <= MAX14819_CH_MAX); os_mutex_lock (iolink->exclusive); - *cqerr = iolink_14819_read_register (iolink, REG_CQErrA + ch); + *cqerr = iolink_14819_read_register (iolink, REG_CQErrA + ch); *devdly = iolink_14819_read_register (iolink, REG_DeviceDlyA + ch); os_mutex_unlock (iolink->exclusive); } -static void iolink_pl_max14819_get_data (iolink_hw_drv_t * iolink_hw, - void * arg, uint8_t *rxdata, - uint8_t len) +static void iolink_pl_max14819_get_data ( + iolink_hw_drv_t * iolink_hw, + void * arg, + uint8_t * rxdata, + uint8_t len) { iolink_14819_drv_t * iolink = (iolink_14819_drv_t *)iolink_hw; - iolink_14819_channel_t ch = (iolink_14819_channel_t)arg; - uint8_t reg = REG_TxRxDataA + ch; - uint8_t lvlreg = REG_RxFIFOLvlA + ch; + iolink_14819_channel_t ch = (iolink_14819_channel_t)arg; + uint8_t reg = REG_TxRxDataA + ch; + uint8_t lvlreg = REG_RxFIFOLvlA + ch; CC_ASSERT (ch >= MAX14819_CH_MIN); CC_ASSERT (ch <= MAX14819_CH_MAX); os_mutex_lock (iolink->exclusive); uint8_t RxBytesAct = iolink_14819_read_register (iolink, reg); - uint8_t rxbytes = iolink_14819_read_register (iolink, lvlreg); + uint8_t rxbytes = iolink_14819_read_register (iolink, lvlreg); if (RxBytesAct != rxbytes) { - LOG_DEBUG (IOLINK_PL_LOG, "%s: Rxbytes in LVL-reg (%d) does not match bytes in RX-reg (%d)\n", - __func__, rxbytes, RxBytesAct); + LOG_DEBUG ( + IOLINK_PL_LOG, + "%s: Rxbytes in LVL-reg (%d) does not match bytes in RX-reg (%d)\n", + __func__, + rxbytes, + RxBytesAct); } if (len < rxbytes) { - LOG_ERROR (IOLINK_PL_LOG, "%s: Read buffer too small. Needed size: %d. Actual size: %d", - __func__, rxbytes, len); + LOG_ERROR ( + IOLINK_PL_LOG, + "%s: Read buffer too small. Needed size: %d. Actual size: %d", + __func__, + rxbytes, + len); rxbytes = len; } uint8_t inband = iolink_14819_burst_read_rx (iolink, ch, rxdata, rxbytes); if (inband & MAX14819_SPI_INBAND_IRQ) { - iolink_pl_max14819_pl_handler((iolink_hw_drv_t *)iolink, (void*)ch); + iolink_pl_max14819_pl_handler ((iolink_hw_drv_t *)iolink, (void *)ch); } os_mutex_unlock (iolink->exclusive); } -static void iolink_pl_max14819_send_msg (iolink_hw_drv_t * iolink_hw, - void * arg) +static void iolink_pl_max14819_send_msg (iolink_hw_drv_t * iolink_hw, void * arg) { iolink_14819_drv_t * iolink = (iolink_14819_drv_t *)iolink_hw; - iolink_14819_channel_t ch = (iolink_14819_channel_t)arg; + iolink_14819_channel_t ch = (iolink_14819_channel_t)arg; CC_ASSERT (ch >= MAX14819_CH_MIN); CC_ASSERT (ch <= MAX14819_CH_MAX); @@ -611,12 +651,15 @@ static void iolink_pl_max14819_send_msg (iolink_hw_drv_t * iolink_hw, iolink_14819_send_master_message (iolink, ch); } -static void iolink_pl_max14819_dl_msg (iolink_hw_drv_t * iolink_hw, - void * arg, uint8_t rxbytes, - uint8_t txbytes, uint8_t *data) +static void iolink_pl_max14819_dl_msg ( + iolink_hw_drv_t * iolink_hw, + void * arg, + uint8_t rxbytes, + uint8_t txbytes, + uint8_t * data) { iolink_14819_drv_t * iolink = (iolink_14819_drv_t *)iolink_hw; - iolink_14819_channel_t ch = (iolink_14819_channel_t)arg; + iolink_14819_channel_t ch = (iolink_14819_channel_t)arg; CC_ASSERT (ch >= MAX14819_CH_MIN); CC_ASSERT (ch <= MAX14819_CH_MAX); @@ -625,12 +668,15 @@ static void iolink_pl_max14819_dl_msg (iolink_hw_drv_t * iolink_hw, iolink_14819_set_master_message (iolink, ch, data, txbytes, rxbytes, true); } -static void iolink_pl_max14819_transfer_req (iolink_hw_drv_t * iolink_hw, - void * arg, uint8_t rxbytes, - uint8_t txbytes, uint8_t *data) +static void iolink_pl_max14819_transfer_req ( + iolink_hw_drv_t * iolink_hw, + void * arg, + uint8_t rxbytes, + uint8_t txbytes, + uint8_t * data) { iolink_14819_drv_t * iolink = (iolink_14819_drv_t *)iolink_hw; - iolink_14819_channel_t ch = (iolink_14819_channel_t)arg; + iolink_14819_channel_t ch = (iolink_14819_channel_t)arg; CC_ASSERT (ch >= MAX14819_CH_MIN); CC_ASSERT (ch <= MAX14819_CH_MAX); @@ -640,11 +686,10 @@ static void iolink_pl_max14819_transfer_req (iolink_hw_drv_t * iolink_hw, iolink_14819_send_master_message (iolink, ch); } -static bool iolink_pl_max14819_init_sdci (iolink_hw_drv_t * iolink_hw, - void * arg) +static bool iolink_pl_max14819_init_sdci (iolink_hw_drv_t * iolink_hw, void * arg) { iolink_14819_drv_t * iolink = (iolink_14819_drv_t *)iolink_hw; - iolink_14819_channel_t ch = (iolink_14819_channel_t)arg; + iolink_14819_channel_t ch = (iolink_14819_channel_t)arg; CC_ASSERT (ch >= MAX14819_CH_MIN); CC_ASSERT (ch <= MAX14819_CH_MAX); @@ -678,10 +723,9 @@ static bool iolink_pl_max14819_init_sdci (iolink_hw_drv_t * iolink_hw, return true; } -static void iolink_pl_max14819_pl_handler (iolink_hw_drv_t * iolink_hw, - void * arg) +static void iolink_pl_max14819_pl_handler (iolink_hw_drv_t * iolink_hw, void * arg) { - iolink_14819_drv_t * iolink = (iolink_14819_drv_t *)iolink_hw; + iolink_14819_drv_t * iolink = (iolink_14819_drv_t *)iolink_hw; iolink_14819_channel_t channel = (iolink_14819_channel_t)arg; uint8_t reg; @@ -732,8 +776,7 @@ static void iolink_pl_max14819_pl_handler (iolink_hw_drv_t * iolink_hw, if (!completed_wurq) { // TODO: WURQ-request interrupt, but no WURQ sent? - LOG_ERROR (IOLINK_PL_LOG, - "PL: Got WURQ, but no channel was handled\n"); + LOG_ERROR (IOLINK_PL_LOG, "PL: Got WURQ, but no channel was handled\n"); } } @@ -757,10 +800,9 @@ static void iolink_pl_max14819_pl_handler (iolink_hw_drv_t * iolink_hw, } #ifdef __rtk__ -static int iolink_pl_max14819_open (drv_t * drv, const char * name, int flags, - int mode) +static int iolink_pl_max14819_open (drv_t * drv, const char * name, int flags, int mode) { - const char * p = name; + const char * p = name; unsigned int channel = 0; /* Remainder of filename is IO-Link channel */ @@ -784,7 +826,7 @@ static int iolink_pl_max14819_open (drv_t * drv, const char * name, int flags, return channel; - error: +error: errno = ENOENT; return -1; } @@ -793,18 +835,15 @@ static int iolink_pl_max14819_open (drv_t * drv, const char * name, int flags, static iolink_14819_drv_t * iolink_14819_init_base (const iolink_14819_cfg_t * cfg) { #ifdef __rtk__ - static const drv_ops_t iolink_ops = - { + static const drv_ops_t iolink_ops = { .open = iolink_pl_max14819_open, .read = NULL, .write = NULL, .close = NULL, .ioctl = NULL, - .hotplug = NULL - }; + .hotplug = NULL}; #endif - static const iolink_hw_ops_t iolink_hw_ops = - { + static const iolink_hw_ops_t iolink_hw_ops = { .get_baudrate = iolink_pl_max14819_get_baudrate, .get_cycletime = iolink_pl_max14819_get_cycletime, .set_cycletime = iolink_pl_max14819_set_cycletime, @@ -821,10 +860,10 @@ static iolink_14819_drv_t * iolink_14819_init_base (const iolink_14819_cfg_t * c .pl_handler = iolink_pl_max14819_pl_handler, }; - iolink_14819_drv_t *iolink; + iolink_14819_drv_t * iolink; uint8_t ch; /* Allocate driver structure */ - iolink = calloc (1, sizeof(iolink_14819_drv_t)); + iolink = calloc (1, sizeof (iolink_14819_drv_t)); if (iolink == NULL) { return NULL; @@ -832,7 +871,7 @@ static iolink_14819_drv_t * iolink_14819_init_base (const iolink_14819_cfg_t * c /* Initialise driver structure */ #ifdef __rtk__ - iolink->drv.drv.ops = &iolink_ops; + iolink->drv.drv.ops = &iolink_ops; #endif iolink->drv.ops = &iolink_hw_ops; iolink->chip_address = cfg->chip_address; @@ -846,7 +885,7 @@ static iolink_14819_drv_t * iolink_14819_init_base (const iolink_14819_cfg_t * c iolink->fd_spi = open (cfg->spi_slave_name, O_RDWR); if (iolink->fd_spi == -1) { - free(iolink); + free (iolink); return NULL; } @@ -873,21 +912,21 @@ static iolink_14819_drv_t * iolink_14819_init_base (const iolink_14819_cfg_t * c } // Set registers as requested in cfg - iolink_14819_write_register (iolink, REG_LEDCtrl, cfg->LEDCtrl); + iolink_14819_write_register (iolink, REG_LEDCtrl, cfg->LEDCtrl); iolink_14819_write_register (iolink, REG_DrvrCurrLim, cfg->DrvCurrLim); - iolink_14819_write_register (iolink, REG_Clock, cfg->Clock); + iolink_14819_write_register (iolink, REG_Clock, cfg->Clock); for (ch = 0; ch < MAX14819_NUM_CHANNELS; ch++) { iolink_14819_write_register (iolink, REG_ChanStatA + ch, 0x00); } - iolink_14819_write_register (iolink, REG_CQCfgA, cfg->CQCfgA); - iolink_14819_write_register (iolink, REG_LPCnfgA, cfg->LPCnfgA); + iolink_14819_write_register (iolink, REG_CQCfgA, cfg->CQCfgA); + iolink_14819_write_register (iolink, REG_LPCnfgA, cfg->LPCnfgA); iolink_14819_write_register (iolink, REG_IOStCfgA, cfg->IOStCfgA); - iolink_14819_write_register (iolink, REG_CQCtrlA, cfg->CQCtrlA); - iolink_14819_write_register (iolink, REG_CQCfgB, cfg->CQCfgB); - iolink_14819_write_register (iolink, REG_LPCnfgB, cfg->LPCnfgB); + iolink_14819_write_register (iolink, REG_CQCtrlA, cfg->CQCtrlA); + iolink_14819_write_register (iolink, REG_CQCfgB, cfg->CQCfgB); + iolink_14819_write_register (iolink, REG_LPCnfgB, cfg->LPCnfgB); iolink_14819_write_register (iolink, REG_IOStCfgB, cfg->IOStCfgB); - iolink_14819_write_register (iolink, REG_CQCtrlB, cfg->CQCtrlB); + iolink_14819_write_register (iolink, REG_CQCtrlB, cfg->CQCtrlB); // Reset interrupt register iolink_14819_read_register (iolink, REG_Interrupt); @@ -900,7 +939,7 @@ static iolink_14819_drv_t * iolink_14819_init_base (const iolink_14819_cfg_t * c if (cfg->register_read_reg_fn != NULL) { - cfg->register_read_reg_fn(iolink_14819_read_register); + cfg->register_read_reg_fn (iolink_14819_read_register); } return iolink; @@ -909,7 +948,7 @@ static iolink_14819_drv_t * iolink_14819_init_base (const iolink_14819_cfg_t * c #ifdef __rtk__ drv_t * iolink_14819_init (const char * name, const iolink_14819_cfg_t * cfg) { - iolink_14819_drv_t *iolink = iolink_14819_init_base(cfg); + iolink_14819_drv_t * iolink = iolink_14819_init_base (cfg); /* Install device driver */ dev_install ((drv_t *)&iolink->drv, name); @@ -919,29 +958,28 @@ drv_t * iolink_14819_init (const char * name, const iolink_14819_cfg_t * cfg) #else int iolink_14819_init (const char * name, const iolink_14819_cfg_t * cfg) { - static const drv_ops_t iolink_ops = - { - .open = NULL, - .read = NULL, - .write = NULL, - .close = NULL, - .ioctl = NULL, + static const drv_ops_t iolink_ops = { + .open = NULL, + .read = NULL, + .write = NULL, + .close = NULL, + .ioctl = NULL, }; - iolink_14819_drv_t *iolink = iolink_14819_init_base(cfg); + iolink_14819_drv_t * iolink = iolink_14819_init_base (cfg); if (iolink == NULL) { // ERROR - return -1; + return -1; } iolink->drv.drv.ops = &iolink_ops; - iolink->drv.drv.name = (char *)malloc(strlen(cfg->spi_slave_name)+1); - strcpy(iolink->drv.drv.name, cfg->spi_slave_name); + iolink->drv.drv.name = (char *)malloc (strlen (cfg->spi_slave_name) + 1); + strcpy (iolink->drv.drv.name, cfg->spi_slave_name); /* Install device driver */ - fd_set_driver(iolink->fd_spi, (drv_t *)&iolink->drv, NULL); + fd_set_driver (iolink->fd_spi, (drv_t *)&iolink->drv, NULL); return iolink->fd_spi; } @@ -949,12 +987,12 @@ int iolink_14819_init (const char * name, const iolink_14819_cfg_t * cfg) void iolink_14819_isr (void * arg) { - iolink_14819_drv_t *iolink; + iolink_14819_drv_t * iolink; #ifdef __rtk__ iolink = (iolink_14819_drv_t *)arg; #else int fd = *(int *)arg; - iolink = (iolink_14819_drv_t *)fd_get_driver(fd); + iolink = (iolink_14819_drv_t *)fd_get_driver (fd); #endif uint8_t ch; diff --git a/src/iolink_max14819_pl.h b/src/iolink_max14819_pl.h index 2b3c914..f9ca2db 100644 --- a/src/iolink_max14819_pl.h +++ b/src/iolink_max14819_pl.h @@ -10,7 +10,6 @@ * See LICENSE file in the project root for full license information. ********************************************************************/ - #ifndef IOLINK_MAX14819_PL_H #define IOLINK_MAX14819_PL_H @@ -22,16 +21,15 @@ #include #include // TODO: use include file instead? -#define fd_get_driver(fd) dev_get_driver(fd) +#define fd_get_driver(fd) dev_get_driver (fd) #endif /* __rtk__ */ #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif #define MAX14819_NUM_CHANNELS 2 -#define IOLINK14819_TX_MAX (66) +#define IOLINK14819_TX_MAX (66) #ifdef __linux__ #include @@ -52,7 +50,7 @@ typedef struct iolink_14819_drv bool wurq_request[MAX14819_NUM_CHANNELS]; bool is_iolink[MAX14819_NUM_CHANNELS]; - os_mutex_t *exclusive; + os_mutex_t * exclusive; os_event_t * dl_event[MAX14819_NUM_CHANNELS]; #ifdef __rtk__ diff --git a/src/iolink_ode.c b/src/iolink_ode.c index 18e0bca..7032bda 100644 --- a/src/iolink_ode.c +++ b/src/iolink_ode.c @@ -11,15 +11,15 @@ ********************************************************************/ #ifdef UNIT_TEST -#define AL_Read_req mock_AL_Read_req -#define AL_Write_req mock_AL_Write_req -#define iolink_post_job mock_iolink_post_job -#define iolink_fetch_avail_job mock_iolink_fetch_avail_job +#define AL_Read_req mock_AL_Read_req +#define AL_Write_req mock_AL_Write_req +#define iolink_post_job mock_iolink_post_job +#define iolink_fetch_avail_job mock_iolink_fetch_avail_job #define iolink_fetch_avail_api_job mock_iolink_fetch_avail_api_job #endif /* UNIT_TEST */ #include "iolink_ode.h" -#include "iolink_al.h" /* AL_Read_req AL_Write_req */ +#include "iolink_al.h" /* AL_Read_req AL_Write_req */ #include "iolink_main.h" /* iolink_fetch_avail_job, iolink_fetch_avail_api_job, iolink_post_job, iolink_get_portnumber */ #include "osal_log.h" @@ -50,15 +50,13 @@ typedef enum iolink_fsm_ode_event ODE_EVENT_LAST } iolink_fsm_ode_event_t; -const char * iolink_ode_state_literals[] = -{ +const char * iolink_ode_state_literals[] = { "Inactive", "ODactive", "ODblocked", }; -const char * iolink_ode_event_literals[] = -{ +const char * iolink_ode_event_literals[] = { "NONE", "SMI_DEV_RW_1", /* T1 */ "OD_START", /* T2 */ @@ -73,8 +71,8 @@ typedef struct iolink_fsm_ode_transition { iolink_fsm_ode_event_t event; iolink_ode_state_t next_state; - iolink_fsm_ode_event_t (*action)(iolink_port_t * port, - iolink_fsm_ode_event_t event); + iolink_fsm_ode_event_t ( + *action) (iolink_port_t * port, iolink_fsm_ode_event_t event); } iolink_fsm_ode_transition_t; typedef struct iolink_fsm_ode_state_transitions @@ -83,24 +81,30 @@ typedef struct iolink_fsm_ode_state_transitions const iolink_fsm_ode_transition_t * transitions; } iolink_fsm_ode_state_transitions_t; -static void ode_AL_Read_cnf (iolink_port_t * port, uint8_t len, - const uint8_t * data, - iolink_smi_errortypes_t errortype); -static void ode_AL_Write_cnf (iolink_port_t * port, - iolink_smi_errortypes_t errortype); +static void ode_AL_Read_cnf ( + iolink_port_t * port, + uint8_t len, + const uint8_t * data, + iolink_smi_errortypes_t errortype); +static void ode_AL_Write_cnf ( + iolink_port_t * port, + iolink_smi_errortypes_t errortype); static void SMI_rw_req_cb (iolink_job_t * job); -static iolink_fsm_ode_event_t ode_smi_od_err (iolink_port_t * port, - iolink_fsm_ode_event_t event) +static iolink_fsm_ode_event_t ode_smi_od_err ( + iolink_port_t * port, + iolink_fsm_ode_event_t event) { - iolink_smi_errortypes_t errortype = IOLINK_SMI_ERRORTYPE_NONE; - iolink_ode_port_t * ode = iolink_get_ode_ctx (port); + iolink_smi_errortypes_t errortype = IOLINK_SMI_ERRORTYPE_NONE; + iolink_ode_port_t * ode = iolink_get_ode_ctx (port); iolink_smi_service_req_t * smi_req = &ode->job_smi_req_busy->smi_req; - iolink_arg_block_id_t ref_arg_block_id = smi_req->arg_block->void_block.arg_block_id; + iolink_arg_block_id_t ref_arg_block_id = + smi_req->arg_block->void_block.arg_block_id; /* SMI_ParamReadBatch and SMI_ParamWriteBatch are not supported */ - if (ref_arg_block_id == IOLINK_ARG_BLOCK_ID_PORT_INXDEX_LIST || - ref_arg_block_id == IOLINK_ARG_BLOCK_ID_DEV_PAR_BAT) + if ( + ref_arg_block_id == IOLINK_ARG_BLOCK_ID_PORT_INXDEX_LIST || + ref_arg_block_id == IOLINK_ARG_BLOCK_ID_DEV_PAR_BAT) { errortype = IOLINK_SMI_ERRORTYPE_SERVICE_NOT_SUPPORTED; } @@ -134,29 +138,35 @@ static iolink_fsm_ode_event_t ode_smi_od_err (iolink_port_t * port, break; } - iolink_smi_joberror_ind (port, smi_req->exp_arg_block_id, ref_arg_block_id, errortype); + iolink_smi_joberror_ind ( + port, + smi_req->exp_arg_block_id, + ref_arg_block_id, + errortype); return ODE_EVENT_NONE; } -static iolink_fsm_ode_event_t ode_od_start (iolink_port_t * port, - iolink_fsm_ode_event_t event) +static iolink_fsm_ode_event_t ode_od_start ( + iolink_port_t * port, + iolink_fsm_ode_event_t event) { /* Wait for SMI calls */ return ODE_EVENT_NONE; } -static iolink_fsm_ode_event_t ode_od_stop (iolink_port_t * port, - iolink_fsm_ode_event_t event) +static iolink_fsm_ode_event_t ode_od_stop ( + iolink_port_t * port, + iolink_fsm_ode_event_t event) { return ODE_EVENT_NONE; } static iolink_fsm_ode_event_t ode_AL_Read_req (iolink_port_t * port) { - iolink_ode_port_t * ode = iolink_get_ode_ctx (port); + iolink_ode_port_t * ode = iolink_get_ode_ctx (port); iolink_smi_service_req_t * smi_req = &ode->smi_req; - arg_block_od_t * arg_block_od = (arg_block_od_t *)smi_req->arg_block; + arg_block_od_t * arg_block_od = (arg_block_od_t *)smi_req->arg_block; AL_Read_req (port, arg_block_od->index, arg_block_od->subindex, ode_AL_Read_cnf); @@ -165,50 +175,61 @@ static iolink_fsm_ode_event_t ode_AL_Read_req (iolink_port_t * port) static iolink_fsm_ode_event_t ode_AL_Write_req (iolink_port_t * port) { - iolink_ode_port_t * ode = iolink_get_ode_ctx (port); + iolink_ode_port_t * ode = iolink_get_ode_ctx (port); iolink_smi_service_req_t * smi_req = &ode->smi_req; - uint8_t arg_block_len = smi_req->arg_block_len; - uint8_t arg_block_data_len = 0; + uint8_t arg_block_len = smi_req->arg_block_len; + uint8_t arg_block_data_len = 0; arg_block_od_t * arg_block_od = (arg_block_od_t *)smi_req->arg_block; - if (arg_block_len >= sizeof(arg_block_od_t)) + if (arg_block_len >= sizeof (arg_block_od_t)) { - arg_block_data_len = arg_block_len - sizeof(arg_block_od_t); + arg_block_data_len = arg_block_len - sizeof (arg_block_od_t); } - AL_Write_req (port, arg_block_od->index, arg_block_od->subindex, - arg_block_data_len, arg_block_od->data, ode_AL_Write_cnf); + AL_Write_req ( + port, + arg_block_od->index, + arg_block_od->subindex, + arg_block_data_len, + arg_block_od->data, + ode_AL_Write_cnf); return ODE_EVENT_OD_BLOCK; } -static iolink_fsm_ode_event_t ode_smi_rw (iolink_port_t * port, - iolink_fsm_ode_event_t event) +static iolink_fsm_ode_event_t ode_smi_rw ( + iolink_port_t * port, + iolink_fsm_ode_event_t event) { - iolink_fsm_ode_event_t res_event = ODE_EVENT_NONE; - iolink_ode_port_t * ode = iolink_get_ode_ctx (port); - iolink_smi_service_req_t * smi_req = &ode->smi_req; + iolink_fsm_ode_event_t res_event = ODE_EVENT_NONE; + iolink_ode_port_t * ode = iolink_get_ode_ctx (port); + iolink_smi_service_req_t * smi_req = &ode->smi_req; iolink_arg_block_id_t exp_arg_block_id = smi_req->exp_arg_block_id; - iolink_arg_block_id_t ref_arg_block_id = smi_req->arg_block->void_block.arg_block_id; + iolink_arg_block_id_t ref_arg_block_id = + smi_req->arg_block->void_block.arg_block_id; - if ((exp_arg_block_id == IOLINK_ARG_BLOCK_ID_OD_RD) && - (ref_arg_block_id == IOLINK_ARG_BLOCK_ID_OD_RD)) + if ( + (exp_arg_block_id == IOLINK_ARG_BLOCK_ID_OD_RD) && + (ref_arg_block_id == IOLINK_ARG_BLOCK_ID_OD_RD)) { res_event = ode_AL_Read_req (port); } - else if ((exp_arg_block_id == IOLINK_ARG_BLOCK_ID_VOID_BLOCK) && - (ref_arg_block_id == IOLINK_ARG_BLOCK_ID_OD_WR)) + else if ( + (exp_arg_block_id == IOLINK_ARG_BLOCK_ID_VOID_BLOCK) && + (ref_arg_block_id == IOLINK_ARG_BLOCK_ID_OD_WR)) { res_event = ode_AL_Write_req (port); } else { - iolink_smi_errortypes_t errortype = IOLINK_SMI_ERRORTYPE_ARGBLOCK_NOT_SUPPORTED; + iolink_smi_errortypes_t errortype = + IOLINK_SMI_ERRORTYPE_ARGBLOCK_NOT_SUPPORTED; /* SMI_ParamReadBatch and SMI_ParamWriteBatch are not supported */ - if ((ref_arg_block_id == IOLINK_ARG_BLOCK_ID_PORT_INXDEX_LIST) || - (ref_arg_block_id == IOLINK_ARG_BLOCK_ID_DEV_PAR_BAT)) + if ( + (ref_arg_block_id == IOLINK_ARG_BLOCK_ID_PORT_INXDEX_LIST) || + (ref_arg_block_id == IOLINK_ARG_BLOCK_ID_DEV_PAR_BAT)) { errortype = IOLINK_SMI_ERRORTYPE_SERVICE_NOT_SUPPORTED; } @@ -219,27 +240,39 @@ static iolink_fsm_ode_event_t ode_smi_rw (iolink_port_t * port, return res_event; } -static iolink_fsm_ode_event_t ode_smi_done (iolink_port_t * port, - iolink_fsm_ode_event_t event) +static iolink_fsm_ode_event_t ode_smi_done ( + iolink_port_t * port, + iolink_fsm_ode_event_t event) { - iolink_ode_port_t * ode = iolink_get_ode_ctx (port); - iolink_smi_service_req_t * smi_req = &ode->smi_req; + iolink_ode_port_t * ode = iolink_get_ode_ctx (port); + iolink_smi_service_req_t * smi_req = &ode->smi_req; iolink_arg_block_id_t exp_arg_block_id = smi_req->exp_arg_block_id; - iolink_arg_block_id_t ref_arg_block_id = smi_req->arg_block->void_block.arg_block_id; + iolink_arg_block_id_t ref_arg_block_id = + smi_req->arg_block->void_block.arg_block_id; if (smi_req->result != IOLINK_SMI_ERRORTYPE_NONE) { - iolink_smi_joberror_ind (port, exp_arg_block_id, ref_arg_block_id, smi_req->result); + iolink_smi_joberror_ind ( + port, + exp_arg_block_id, + ref_arg_block_id, + smi_req->result); } else { - if ((exp_arg_block_id == IOLINK_ARG_BLOCK_ID_OD_RD) && - (ref_arg_block_id == IOLINK_ARG_BLOCK_ID_OD_RD)) + if ( + (exp_arg_block_id == IOLINK_ARG_BLOCK_ID_OD_RD) && + (ref_arg_block_id == IOLINK_ARG_BLOCK_ID_OD_RD)) { - iolink_smi_cnf (port, ref_arg_block_id, smi_req->arg_block_len, smi_req->arg_block); + iolink_smi_cnf ( + port, + ref_arg_block_id, + smi_req->arg_block_len, + smi_req->arg_block); } - else if ((exp_arg_block_id == IOLINK_ARG_BLOCK_ID_VOID_BLOCK) && - (ref_arg_block_id == IOLINK_ARG_BLOCK_ID_OD_WR)) + else if ( + (exp_arg_block_id == IOLINK_ARG_BLOCK_ID_VOID_BLOCK) && + (ref_arg_block_id == IOLINK_ARG_BLOCK_ID_OD_WR)) { iolink_smi_voidblock_cnf (port, ref_arg_block_id); } @@ -252,65 +285,59 @@ static iolink_fsm_ode_event_t ode_smi_done (iolink_port_t * port, return ODE_EVENT_NONE; } -static iolink_fsm_ode_event_t ode_wait (iolink_port_t * port, - iolink_fsm_ode_event_t event) +static iolink_fsm_ode_event_t ode_wait ( + iolink_port_t * port, + iolink_fsm_ode_event_t event) { /* Wait for AL_{Read,Write}_cnf */ return ODE_EVENT_NONE; } /* ODE FSM state transitions, IO-Link Interface Spec v1.1.3 Chapter 11.5 */ -/* since we iterate through the list on events put the most likely in the top of the list. */ -static const iolink_fsm_ode_transition_t ode_trans_s0[] = -{ +/* since we iterate through the list on events put the most likely in the top of + * the list. */ +static const iolink_fsm_ode_transition_t ode_trans_s0[] = { /* Inactive_0 */ - { ODE_EVENT_OD_START, ODE_STATE_ODactive, ode_od_start }, /* T2 */ - { ODE_EVENT_SMI_DEV_RW_1, ODE_STATE_Inactive, ode_smi_od_err }, /* T1 */ + {ODE_EVENT_OD_START, ODE_STATE_ODactive, ode_od_start}, /* T2 */ + {ODE_EVENT_SMI_DEV_RW_1, ODE_STATE_Inactive, ode_smi_od_err}, /* T1 */ - { ODE_EVENT_OD_STOP, ODE_STATE_Inactive, ode_od_stop }, /* NOTE: Not in spec */ + {ODE_EVENT_OD_STOP, ODE_STATE_Inactive, ode_od_stop}, /* NOTE: Not in spec */ }; -static const iolink_fsm_ode_transition_t ode_trans_s1[] = -{ +static const iolink_fsm_ode_transition_t ode_trans_s1[] = { /* ODactive_1 */ - { ODE_EVENT_SMI_DEV_RW_4, ODE_STATE_ODactive, ode_smi_rw }, /* T4 */ - { ODE_EVENT_OD_BLOCK, ODE_STATE_ODblocked, ode_wait }, /* T5 */ - { ODE_EVENT_OD_STOP, ODE_STATE_Inactive, ode_od_stop }, /* T3 */ + {ODE_EVENT_SMI_DEV_RW_4, ODE_STATE_ODactive, ode_smi_rw}, /* T4 */ + {ODE_EVENT_OD_BLOCK, ODE_STATE_ODblocked, ode_wait}, /* T5 */ + {ODE_EVENT_OD_STOP, ODE_STATE_Inactive, ode_od_stop}, /* T3 */ }; -static const iolink_fsm_ode_transition_t ode_trans_s2[] = -{ +static const iolink_fsm_ode_transition_t ode_trans_s2[] = { /* ODblocked_2 */ - { ODE_EVENT_OD_UNBLOCK, ODE_STATE_ODactive, ode_smi_done }, /* T7 */ - { ODE_EVENT_SMI_DEV_RW_6, ODE_STATE_ODblocked, ode_smi_od_err }, /* T6 */ + {ODE_EVENT_OD_UNBLOCK, ODE_STATE_ODactive, ode_smi_done}, /* T7 */ + {ODE_EVENT_SMI_DEV_RW_6, ODE_STATE_ODblocked, ode_smi_od_err}, /* T6 */ - { ODE_EVENT_OD_STOP, ODE_STATE_Inactive, ode_od_stop }, /* Not part of FSM */ + {ODE_EVENT_OD_STOP, ODE_STATE_Inactive, ode_od_stop}, /* Not part of FSM */ }; /* The index is the state in this array */ -static const iolink_fsm_ode_state_transitions_t iolink_ode_fsm[] = -{ - { /* Inactive_0 */ - .number_of_trans = NELEMENTS (ode_trans_s0), - .transitions = ode_trans_s0 - }, - { /* ODactive_1 */ - .number_of_trans = NELEMENTS (ode_trans_s1), - .transitions = ode_trans_s1 - }, - { /* ODblocked_2 */ - .number_of_trans = NELEMENTS (ode_trans_s2), - .transitions = ode_trans_s2 - }, +static const iolink_fsm_ode_state_transitions_t iolink_ode_fsm[] = { + {/* Inactive_0 */ + .number_of_trans = NELEMENTS (ode_trans_s0), + .transitions = ode_trans_s0}, + {/* ODactive_1 */ + .number_of_trans = NELEMENTS (ode_trans_s1), + .transitions = ode_trans_s1}, + {/* ODblocked_2 */ + .number_of_trans = NELEMENTS (ode_trans_s2), + .transitions = ode_trans_s2}, }; -static void iolink_ode_event (iolink_port_t * port, - iolink_fsm_ode_event_t event) +static void iolink_ode_event (iolink_port_t * port, iolink_fsm_ode_event_t event) { do { int i; - iolink_ode_port_t * ode = iolink_get_ode_ctx (port); + iolink_ode_port_t * ode = iolink_get_ode_ctx (port); iolink_ode_state_t previous = ode->state; const iolink_fsm_ode_transition_t * next_trans = NULL; @@ -327,35 +354,42 @@ static void iolink_ode_event (iolink_port_t * port, } if (!next_trans) { - LOG_ERROR (IOLINK_ODE_LOG, "ODE (%u): next_trans == NULL: state %s - event %s\n", - iolink_get_portnumber (port), - iolink_ode_state_literals[previous], - iolink_ode_event_literals[event]); + LOG_ERROR ( + IOLINK_ODE_LOG, + "ODE (%u): next_trans == NULL: state %s - event %s\n", + iolink_get_portnumber (port), + iolink_ode_state_literals[previous], + iolink_ode_event_literals[event]); return; } /* Transition to next state */ ode->state = next_trans->next_state; - LOG_DEBUG (IOLINK_ODE_LOG, "ODE (%u): event: %s, state transition: %s -> %s\n", - iolink_get_portnumber (port), iolink_ode_event_literals[event], - iolink_ode_state_literals[previous], iolink_ode_state_literals[ode->state]); + LOG_DEBUG ( + IOLINK_ODE_LOG, + "ODE (%u): event: %s, state transition: %s -> %s\n", + iolink_get_portnumber (port), + iolink_ode_event_literals[event], + iolink_ode_state_literals[previous], + iolink_ode_state_literals[ode->state]); event = next_trans->action (port, event); } while (event != ODE_EVENT_NONE); } /* AL job callback functions */ -static iolink_error_t ode_SMI_rw_req (iolink_job_type_t job_type, - iolink_port_t * port, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, - arg_block_t * arg_block) -{ - iolink_job_t * job = iolink_fetch_avail_api_job (port); +static iolink_error_t ode_SMI_rw_req ( + iolink_job_type_t job_type, + iolink_port_t * port, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block) +{ + iolink_job_t * job = iolink_fetch_avail_api_job (port); job->smi_req.exp_arg_block_id = exp_arg_block_id; - job->smi_req.arg_block_len = arg_block_len; - job->smi_req.arg_block = arg_block; + job->smi_req.arg_block_len = arg_block_len; + job->smi_req.arg_block = arg_block; iolink_post_job_with_type_and_callback (port, job, job_type, SMI_rw_req_cb); @@ -364,16 +398,16 @@ static iolink_error_t ode_SMI_rw_req (iolink_job_type_t job_type, static void ode_read_cnf_cb (iolink_job_t * job) { - iolink_port_t * port = job->port; - iolink_ode_port_t * ode = iolink_get_ode_ctx (port); + iolink_port_t * port = job->port; + iolink_ode_port_t * ode = iolink_get_ode_ctx (port); iolink_smi_service_req_t * smi_req = &ode->smi_req; smi_req->result = job->al_read_cnf.errortype; if (smi_req->result == IOLINK_SMI_ERRORTYPE_NONE) { - uint8_t arg_block_len = smi_req->arg_block_len; - uint8_t arg_block_data_len = arg_block_len - sizeof(arg_block_od_t); - uint8_t len = job->al_read_cnf.data_len; + uint8_t arg_block_len = smi_req->arg_block_len; + uint8_t arg_block_data_len = arg_block_len - sizeof (arg_block_od_t); + uint8_t len = job->al_read_cnf.data_len; if (arg_block_data_len >= len) { @@ -382,7 +416,7 @@ static void ode_read_cnf_cb (iolink_job_t * job) memset (arg_block_od->data, 0, arg_block_data_len); memcpy (arg_block_od->data, job->al_read_cnf.data, len); - arg_block_len = len + sizeof(arg_block_od_t); + arg_block_len = len + sizeof (arg_block_od_t); smi_req->arg_block_len = arg_block_len; } else @@ -394,22 +428,28 @@ static void ode_read_cnf_cb (iolink_job_t * job) iolink_ode_event (port, ODE_EVENT_OD_UNBLOCK); } -static void ode_AL_Read_cnf (iolink_port_t * port, uint8_t len, - const uint8_t * data, - iolink_smi_errortypes_t errortype) +static void ode_AL_Read_cnf ( + iolink_port_t * port, + uint8_t len, + const uint8_t * data, + iolink_smi_errortypes_t errortype) { - iolink_job_t * job = iolink_fetch_avail_job (port); - job->al_read_cnf.data = data; - job->al_read_cnf.data_len = len; + iolink_job_t * job = iolink_fetch_avail_job (port); + job->al_read_cnf.data = data; + job->al_read_cnf.data_len = len; job->al_read_cnf.errortype = errortype; - iolink_post_job_with_type_and_callback (port, job, IOLINK_JOB_AL_READ_CNF, ode_read_cnf_cb); + iolink_post_job_with_type_and_callback ( + port, + job, + IOLINK_JOB_AL_READ_CNF, + ode_read_cnf_cb); } static void ode_write_cnf_cb (iolink_job_t * job) { - iolink_port_t * port = job->port; - iolink_ode_port_t * ode = iolink_get_ode_ctx (port); + iolink_port_t * port = job->port; + iolink_ode_port_t * ode = iolink_get_ode_ctx (port); iolink_smi_service_req_t * smi_req = &ode->smi_req; if (job->al_write_cnf.errortype != IOLINK_SMI_ERRORTYPE_NONE) @@ -420,13 +460,16 @@ static void ode_write_cnf_cb (iolink_job_t * job) iolink_ode_event (port, ODE_EVENT_OD_UNBLOCK); } -static void ode_AL_Write_cnf (iolink_port_t * port, - iolink_smi_errortypes_t errortype) +static void ode_AL_Write_cnf (iolink_port_t * port, iolink_smi_errortypes_t errortype) { - iolink_job_t * job = iolink_fetch_avail_job (port); + iolink_job_t * job = iolink_fetch_avail_job (port); job->al_write_cnf.errortype = errortype; - iolink_post_job_with_type_and_callback (port, job, IOLINK_JOB_AL_WRITE_CNF, ode_write_cnf_cb); + iolink_post_job_with_type_and_callback ( + port, + job, + IOLINK_JOB_AL_WRITE_CNF, + ode_write_cnf_cb); } static void od_start_cb (iolink_job_t * job) @@ -441,25 +484,26 @@ static void od_stop_cb (iolink_job_t * job) static void SMI_rw_req_cb (iolink_job_t * job) { - iolink_fsm_ode_event_t event = ODE_EVENT_NONE; - iolink_port_t * port = job->port; - iolink_ode_port_t * ode = iolink_get_ode_ctx (port); + iolink_fsm_ode_event_t event = ODE_EVENT_NONE; + iolink_port_t * port = job->port; + iolink_ode_port_t * ode = iolink_get_ode_ctx (port); iolink_smi_service_req_t * smi_req = &ode->smi_req; switch (ode->state) { case ODE_STATE_ODactive: - smi_req->result = IOLINK_SMI_ERRORTYPE_NONE; + smi_req->result = IOLINK_SMI_ERRORTYPE_NONE; smi_req->exp_arg_block_id = job->smi_req.exp_arg_block_id; - smi_req->arg_block_len = job->smi_req.arg_block_len; - smi_req->arg_block = job->smi_req.arg_block; - event = ODE_EVENT_SMI_DEV_RW_4; + smi_req->arg_block_len = job->smi_req.arg_block_len; + smi_req->arg_block = job->smi_req.arg_block; + event = ODE_EVENT_SMI_DEV_RW_4; break; case ODE_STATE_Inactive: case ODE_STATE_ODblocked: /* Store the job, for a negative response */ ode->job_smi_req_busy = job; - event = (ode->state == ODE_STATE_Inactive) ? ODE_EVENT_SMI_DEV_RW_1 : ODE_EVENT_SMI_DEV_RW_6; + event = (ode->state == ODE_STATE_Inactive) ? ODE_EVENT_SMI_DEV_RW_1 + : ODE_EVENT_SMI_DEV_RW_6; break; default: CC_ASSERT (0); @@ -481,7 +525,11 @@ iolink_error_t OD_Start (iolink_port_t * port) { iolink_job_t * job = iolink_fetch_avail_job (port); - iolink_post_job_with_type_and_callback (port, job, IOLINK_JOB_OD_START, od_start_cb); + iolink_post_job_with_type_and_callback ( + port, + job, + IOLINK_JOB_OD_START, + od_start_cb); return IOLINK_ERROR_NONE; } @@ -490,17 +538,22 @@ iolink_error_t OD_Stop (iolink_port_t * port) { iolink_job_t * job = iolink_fetch_avail_job (port); - iolink_post_job_with_type_and_callback (port, job, IOLINK_JOB_OD_STOP, od_stop_cb); + iolink_post_job_with_type_and_callback ( + port, + job, + IOLINK_JOB_OD_STOP, + od_stop_cb); return IOLINK_ERROR_NONE; } -static iolink_error_t ode_SMI_DeviceReadWrite_req (iolink_port_t * port, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, - arg_block_t * arg_block, - iolink_arg_block_id_t od_or_void, - iolink_job_type_t type) +static iolink_error_t ode_SMI_DeviceReadWrite_req ( + iolink_port_t * port, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block, + iolink_arg_block_id_t od_or_void, + iolink_job_type_t type) { if (exp_arg_block_id != od_or_void) { @@ -510,38 +563,60 @@ static iolink_error_t ode_SMI_DeviceReadWrite_req (iolink_port_t * port, return ode_SMI_rw_req (type, port, exp_arg_block_id, arg_block_len, arg_block); } -iolink_error_t ode_SMI_DeviceRead_req (iolink_port_t * port, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, - arg_block_t * arg_block) -{ - return ode_SMI_DeviceReadWrite_req(port, exp_arg_block_id, arg_block_len, arg_block, - IOLINK_ARG_BLOCK_ID_OD_RD, IOLINK_JOB_SMI_DEVICE_READ); +iolink_error_t ode_SMI_DeviceRead_req ( + iolink_port_t * port, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block) +{ + return ode_SMI_DeviceReadWrite_req ( + port, + exp_arg_block_id, + arg_block_len, + arg_block, + IOLINK_ARG_BLOCK_ID_OD_RD, + IOLINK_JOB_SMI_DEVICE_READ); } -iolink_error_t ode_SMI_DeviceWrite_req (iolink_port_t * port, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, - arg_block_t * arg_block) -{ - return ode_SMI_DeviceReadWrite_req(port, exp_arg_block_id, arg_block_len, arg_block, - IOLINK_ARG_BLOCK_ID_VOID_BLOCK, IOLINK_JOB_SMI_DEVICE_WRITE); +iolink_error_t ode_SMI_DeviceWrite_req ( + iolink_port_t * port, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block) +{ + return ode_SMI_DeviceReadWrite_req ( + port, + exp_arg_block_id, + arg_block_len, + arg_block, + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + IOLINK_JOB_SMI_DEVICE_WRITE); } -iolink_error_t ode_SMI_ParamReadBatch_req (iolink_port_t * port, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, - arg_block_t * arg_block) -{ - return ode_SMI_rw_req (IOLINK_JOB_SMI_PARAM_READ, port, exp_arg_block_id, - arg_block_len, arg_block); +iolink_error_t ode_SMI_ParamReadBatch_req ( + iolink_port_t * port, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block) +{ + return ode_SMI_rw_req ( + IOLINK_JOB_SMI_PARAM_READ, + port, + exp_arg_block_id, + arg_block_len, + arg_block); } -iolink_error_t ode_SMI_ParamWriteBatch_req (iolink_port_t * port, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, - arg_block_t * arg_block) -{ - return ode_SMI_rw_req (IOLINK_JOB_SMI_PARAM_WRITE, port, exp_arg_block_id, - arg_block_len, arg_block); +iolink_error_t ode_SMI_ParamWriteBatch_req ( + iolink_port_t * port, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block) +{ + return ode_SMI_rw_req ( + IOLINK_JOB_SMI_PARAM_WRITE, + port, + exp_arg_block_id, + arg_block_len, + arg_block); } diff --git a/src/iolink_ode.h b/src/iolink_ode.h index b465b4f..754a5c1 100644 --- a/src/iolink_ode.h +++ b/src/iolink_ode.h @@ -10,7 +10,6 @@ * See LICENSE file in the project root for full license information. ********************************************************************/ - #ifndef IOLINK_ODE_H #define IOLINK_ODE_H @@ -18,8 +17,7 @@ #include "iolink_types.h" #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif typedef enum iolink_ode_state @@ -42,25 +40,29 @@ void iolink_ode_init (iolink_port_t * port); iolink_error_t OD_Start (iolink_port_t * port); iolink_error_t OD_Stop (iolink_port_t * port); -iolink_error_t ode_SMI_DeviceRead_req (iolink_port_t * port, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, - arg_block_t * arg_block); +iolink_error_t ode_SMI_DeviceRead_req ( + iolink_port_t * port, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block); -iolink_error_t ode_SMI_DeviceWrite_req (iolink_port_t * port, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, - arg_block_t * arg_block); +iolink_error_t ode_SMI_DeviceWrite_req ( + iolink_port_t * port, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block); -iolink_error_t ode_SMI_ParamReadBatch_req (iolink_port_t * port, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, - arg_block_t * arg_block); +iolink_error_t ode_SMI_ParamReadBatch_req ( + iolink_port_t * port, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block); -iolink_error_t ode_SMI_ParamWriteBatch_req (iolink_port_t * port, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, - arg_block_t * arg_block); +iolink_error_t ode_SMI_ParamWriteBatch_req ( + iolink_port_t * port, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block); #ifdef __cplusplus } #endif diff --git a/src/iolink_pde.c b/src/iolink_pde.c index 06fe4ba..62aed8f 100644 --- a/src/iolink_pde.c +++ b/src/iolink_pde.c @@ -11,12 +11,12 @@ ********************************************************************/ #ifdef UNIT_TEST -#define AL_Control_req mock_AL_Control_req -#define AL_GetInput_req mock_AL_GetInput_req -#define AL_GetInputOutput_req mock_AL_GetInputOutput_req -#define AL_SetOutput_req mock_AL_SetOutput_req -#define iolink_post_job mock_iolink_post_job -#define iolink_fetch_avail_job mock_iolink_fetch_avail_job +#define AL_Control_req mock_AL_Control_req +#define AL_GetInput_req mock_AL_GetInput_req +#define AL_GetInputOutput_req mock_AL_GetInputOutput_req +#define AL_SetOutput_req mock_AL_SetOutput_req +#define iolink_post_job mock_iolink_post_job +#define iolink_fetch_avail_job mock_iolink_fetch_avail_job #define iolink_fetch_avail_api_job mock_iolink_fetch_avail_api_job #endif /* UNIT_TEST */ @@ -34,40 +34,42 @@ * */ -static inline iolink_port_qualifier_info_t pde_port_quality_to_qualifier (iolink_port_t * port) +static inline iolink_port_qualifier_info_t pde_port_quality_to_qualifier ( + iolink_port_t * port) { iolink_port_info_t * port_info = iolink_get_port_info (port); - return (port_info->port_quality_info & IOLINK_PORT_QUALITY_INFO_INVALID) ? - IOLINK_PORT_QUALIFIER_INFO_PQ_INVALID : - IOLINK_PORT_QUALIFIER_INFO_PQ_VALID; + return (port_info->port_quality_info & IOLINK_PORT_QUALITY_INFO_INVALID) + ? IOLINK_PORT_QUALIFIER_INFO_PQ_INVALID + : IOLINK_PORT_QUALIFIER_INFO_PQ_VALID; } -static inline iolink_port_status_info_t pde_get_port_status_info (iolink_port_t * port) +static inline iolink_port_status_info_t pde_get_port_status_info ( + iolink_port_t * port) { iolink_port_info_t * port_info = iolink_get_port_info (port); return port_info->port_status_info; } -static iolink_error_t pde_check_smi_req (iolink_port_t * port, - iolink_arg_block_id_t exp_arg_block_id, - iolink_arg_block_id_t ref_arg_block_id, - uint8_t arg_block_len, - iolink_arg_block_id_t exp_exp_arg_block_id, - iolink_arg_block_id_t exp_ref_arg_block_id, - uint8_t exp_arg_block_len_min, - uint8_t exp_arg_block_len_max) +static iolink_error_t pde_check_smi_req ( + iolink_port_t * port, + iolink_arg_block_id_t exp_arg_block_id, + iolink_arg_block_id_t ref_arg_block_id, + uint8_t arg_block_len, + iolink_arg_block_id_t exp_exp_arg_block_id, + iolink_arg_block_id_t exp_ref_arg_block_id, + uint8_t exp_arg_block_len_min, + uint8_t exp_arg_block_len_max) { iolink_smi_errortypes_t smi_error = IOLINK_SMI_ERRORTYPE_NONE; - iolink_error_t error = IOLINK_ERROR_NONE; + iolink_error_t error = IOLINK_ERROR_NONE; if (exp_ref_arg_block_id != ref_arg_block_id) { smi_error = IOLINK_SMI_ERRORTYPE_ARGBLOCK_NOT_SUPPORTED; } - else if ((arg_block_len < exp_arg_block_len_min) || - (arg_block_len > exp_arg_block_len_max)) + else if ((arg_block_len < exp_arg_block_len_min) || (arg_block_len > exp_arg_block_len_max)) { smi_error = IOLINK_SMI_ERRORTYPE_ARGBLOCK_LENGTH_INVALID; } @@ -86,8 +88,13 @@ static iolink_error_t pde_check_smi_req (iolink_port_t * port, iolink_pde_port_t * pde = iolink_get_pde_ctx (port); if (pde->state == PD_STATE_Inactive) { - smi_error = IOLINK_SMI_ERRORTYPE_DEV_NOT_IN_OPERATE; // TODO is this correct? - iolink_smi_joberror_ind (port, exp_arg_block_id, ref_arg_block_id, smi_error); + smi_error = IOLINK_SMI_ERRORTYPE_DEV_NOT_IN_OPERATE; // TODO is this + // correct? + iolink_smi_joberror_ind ( + port, + exp_arg_block_id, + ref_arg_block_id, + smi_error); error = IOLINK_ERROR_STATE_INVALID; // TODO what to return? } } @@ -101,7 +108,7 @@ void iolink_pde_init (iolink_port_t * port) iolink_pde_port_t * pde = iolink_get_pde_ctx (port); pde->output_enable = false; - pde->state = PD_STATE_Inactive; + pde->state = PD_STATE_Inactive; } iolink_error_t PD_Start (iolink_port_t * port) @@ -125,60 +132,65 @@ iolink_error_t AL_NewInput_ind (iolink_port_t * port) return IOLINK_ERROR_NONE; } -iolink_error_t AL_Control_ind (iolink_port_t * port, - iolink_controlcode_t controlcode) +iolink_error_t AL_Control_ind (iolink_port_t * port, iolink_controlcode_t controlcode) { iolink_port_info_t * port_info = iolink_get_port_info (port); switch (controlcode) { - case IOLINK_CONTROLCODE_VALID: - port_info->port_quality_info &= ~IOLINK_PORT_QUALITY_INFO_INVALID; - break; - case IOLINK_CONTROLCODE_INVALID: - port_info->port_quality_info |= IOLINK_PORT_QUALITY_INFO_INVALID; - break; - case IOLINK_CONTROLCODE_PDOUTVALID: - port_info->port_quality_info &= ~IOLINK_PORT_QUALITY_INFO_PDO_INVALID; - break; - case IOLINK_CONTROLCODE_PDOUTINVALID: - port_info->port_quality_info |= IOLINK_PORT_QUALITY_INFO_PDO_INVALID; - break; - default: - CC_ASSERT (0); - break; + case IOLINK_CONTROLCODE_VALID: + port_info->port_quality_info &= ~IOLINK_PORT_QUALITY_INFO_INVALID; + break; + case IOLINK_CONTROLCODE_INVALID: + port_info->port_quality_info |= IOLINK_PORT_QUALITY_INFO_INVALID; + break; + case IOLINK_CONTROLCODE_PDOUTVALID: + port_info->port_quality_info &= ~IOLINK_PORT_QUALITY_INFO_PDO_INVALID; + break; + case IOLINK_CONTROLCODE_PDOUTINVALID: + port_info->port_quality_info |= IOLINK_PORT_QUALITY_INFO_PDO_INVALID; + break; + default: + CC_ASSERT (0); + break; } return IOLINK_ERROR_NONE; } -iolink_error_t pde_SMI_PDIn_req (iolink_port_t * port, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, - arg_block_t * arg_block) +iolink_error_t pde_SMI_PDIn_req ( + iolink_port_t * port, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block) { iolink_arg_block_id_t ref_arg_block_id = arg_block->void_block.arg_block_id; arg_block_pdin_t arg_block_pdin; - memset (&arg_block_pdin, 0, sizeof(arg_block_pdin_t)); - uint8_t pdin_len = 1; - iolink_error_t error = pde_check_smi_req (port, exp_arg_block_id, - ref_arg_block_id, arg_block_len, - IOLINK_ARG_BLOCK_ID_PD_IN, - IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - sizeof(arg_block_void_t), - sizeof(arg_block_void_t)); + memset (&arg_block_pdin, 0, sizeof (arg_block_pdin_t)); + uint8_t pdin_len = 1; + iolink_error_t error = pde_check_smi_req ( + port, + exp_arg_block_id, + ref_arg_block_id, + arg_block_len, + IOLINK_ARG_BLOCK_ID_PD_IN, + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + sizeof (arg_block_void_t), + sizeof (arg_block_void_t)); if (error != IOLINK_ERROR_NONE) { - iolink_port_status_info_t port_status_info = pde_get_port_status_info (port); + iolink_port_status_info_t port_status_info = + pde_get_port_status_info (port); - if ((error == IOLINK_ERROR_STATE_INVALID) && - ((port_status_info == IOLINK_PORT_STATUS_INFO_DI) || - (port_status_info == IOLINK_PORT_STATUS_INFO_DEACTIVATED))) + if ( + (error == IOLINK_ERROR_STATE_INVALID) && + ((port_status_info == IOLINK_PORT_STATUS_INFO_DI) || + (port_status_info == IOLINK_PORT_STATUS_INFO_DEACTIVATED))) { // TODO Copy result from Get signal status DI_C/Q arg_block_pdin.data[0] = 1; - error = IOLINK_ERROR_NONE; + error = IOLINK_ERROR_NONE; } } else @@ -188,34 +200,46 @@ iolink_error_t pde_SMI_PDIn_req (iolink_port_t * port, if (error != IOLINK_ERROR_NONE) { - iolink_smi_errortypes_t smi_error = IOLINK_SMI_ERRORTYPE_DEV_NOT_ACCESSIBLE; - iolink_smi_joberror_ind (port, exp_arg_block_id, ref_arg_block_id, smi_error); + iolink_smi_errortypes_t smi_error = + IOLINK_SMI_ERRORTYPE_DEV_NOT_ACCESSIBLE; + iolink_smi_joberror_ind ( + port, + exp_arg_block_id, + ref_arg_block_id, + smi_error); } } if (error == IOLINK_ERROR_NONE) { arg_block_pdin.h.arg_block_id = exp_arg_block_id; - arg_block_pdin.h.len = pdin_len; - iolink_smi_cnf (port, ref_arg_block_id, sizeof(arg_block_pdin_head_t) + pdin_len, - (arg_block_t *)&arg_block_pdin); + arg_block_pdin.h.len = pdin_len; + iolink_smi_cnf ( + port, + ref_arg_block_id, + sizeof (arg_block_pdin_head_t) + pdin_len, + (arg_block_t *)&arg_block_pdin); } return error; } -iolink_error_t pde_SMI_PDOut_req (iolink_port_t * port, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, - arg_block_t * arg_block) +iolink_error_t pde_SMI_PDOut_req ( + iolink_port_t * port, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block) { iolink_arg_block_id_t ref_arg_block_id = arg_block->void_block.arg_block_id; - iolink_error_t error = pde_check_smi_req (port, exp_arg_block_id, - ref_arg_block_id, arg_block_len, - IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - IOLINK_ARG_BLOCK_ID_PD_OUT, - sizeof(arg_block_pdout_head_t) + 1, - sizeof(arg_block_pdout_t)); + iolink_error_t error = pde_check_smi_req ( + port, + exp_arg_block_id, + ref_arg_block_id, + arg_block_len, + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + IOLINK_ARG_BLOCK_ID_PD_OUT, + sizeof (arg_block_pdout_head_t) + 1, + sizeof (arg_block_pdout_t)); if (error == IOLINK_ERROR_NONE) { @@ -226,24 +250,35 @@ iolink_error_t pde_SMI_PDOut_req (iolink_port_t * port, else { arg_block_pdout_t * arg_block_pdout = (arg_block_pdout_t *)arg_block; - bool output_enable = arg_block_pdout->h.oe & 1; - iolink_pde_port_t * pde = iolink_get_pde_ctx (port); - iolink_smi_errortypes_t smi_error = IOLINK_SMI_ERRORTYPE_DEV_NOT_ACCESSIBLE; + bool output_enable = arg_block_pdout->h.oe & 1; + iolink_pde_port_t * pde = iolink_get_pde_ctx (port); + iolink_smi_errortypes_t smi_error = + IOLINK_SMI_ERRORTYPE_DEV_NOT_ACCESSIBLE; error = AL_SetOutput_req (port, arg_block_pdout->data); if (error != IOLINK_ERROR_NONE) { - iolink_smi_joberror_ind (port, exp_arg_block_id, ref_arg_block_id, smi_error); + iolink_smi_joberror_ind ( + port, + exp_arg_block_id, + ref_arg_block_id, + smi_error); } else if (pde->output_enable != output_enable) { - error = AL_Control_req (port, (output_enable) ? - IOLINK_CONTROLCODE_PDOUTVALID : IOLINK_CONTROLCODE_PDOUTINVALID); + error = AL_Control_req ( + port, + (output_enable) ? IOLINK_CONTROLCODE_PDOUTVALID + : IOLINK_CONTROLCODE_PDOUTINVALID); if (error != IOLINK_ERROR_NONE) { - iolink_smi_joberror_ind (port, exp_arg_block_id, ref_arg_block_id, smi_error); + iolink_smi_joberror_ind ( + port, + exp_arg_block_id, + ref_arg_block_id, + smi_error); } else { @@ -261,18 +296,22 @@ iolink_error_t pde_SMI_PDOut_req (iolink_port_t * port, return error; } -iolink_error_t pde_SMI_PDInOut_req (iolink_port_t * port, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, - arg_block_t * arg_block) +iolink_error_t pde_SMI_PDInOut_req ( + iolink_port_t * port, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block) { iolink_arg_block_id_t ref_arg_block_id = arg_block->void_block.arg_block_id; - iolink_error_t error = pde_check_smi_req (port, exp_arg_block_id, - ref_arg_block_id, arg_block_len, - IOLINK_ARG_BLOCK_ID_PD_IN_OUT, - IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - sizeof(arg_block_void_t), - sizeof(arg_block_void_t)); + iolink_error_t error = pde_check_smi_req ( + port, + exp_arg_block_id, + ref_arg_block_id, + arg_block_len, + IOLINK_ARG_BLOCK_ID_PD_IN_OUT, + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + sizeof (arg_block_void_t), + sizeof (arg_block_void_t)); if (error == IOLINK_ERROR_NONE) { @@ -286,23 +325,33 @@ iolink_error_t pde_SMI_PDInOut_req (iolink_port_t * port, uint8_t pdlen; iolink_pde_port_t * pde = iolink_get_pde_ctx (port); - memset (&arg_block_pdinout, 0, sizeof(arg_block_pdinout_t)); - arg_block_pdinout.h.port_qualifier_info = pde_port_quality_to_qualifier (port); + memset (&arg_block_pdinout, 0, sizeof (arg_block_pdinout_t)); + arg_block_pdinout.h.port_qualifier_info = + pde_port_quality_to_qualifier (port); arg_block_pdinout.h.oe = pde->output_enable; error = AL_GetInputOutput_req (port, &pdlen, arg_block_pdinout.data); if (error != IOLINK_ERROR_NONE) { - iolink_smi_errortypes_t smi_error = IOLINK_SMI_ERRORTYPE_DEV_NOT_ACCESSIBLE; - iolink_smi_joberror_ind (port, exp_arg_block_id, ref_arg_block_id, smi_error); + iolink_smi_errortypes_t smi_error = + IOLINK_SMI_ERRORTYPE_DEV_NOT_ACCESSIBLE; + iolink_smi_joberror_ind ( + port, + exp_arg_block_id, + ref_arg_block_id, + smi_error); } else { arg_block_pdinout.h.arg_block_id = exp_arg_block_id; - uint8_t arg_block_pdinout_len = sizeof(arg_block_pdinout_head_t) + pdlen; - iolink_smi_cnf (port, ref_arg_block_id, arg_block_pdinout_len, - (arg_block_t *)&arg_block_pdinout); + uint8_t arg_block_pdinout_len = + sizeof (arg_block_pdinout_head_t) + pdlen; + iolink_smi_cnf ( + port, + ref_arg_block_id, + arg_block_pdinout_len, + (arg_block_t *)&arg_block_pdinout); } } } diff --git a/src/iolink_pde.h b/src/iolink_pde.h index 1d963c6..15b7c68 100644 --- a/src/iolink_pde.h +++ b/src/iolink_pde.h @@ -10,7 +10,6 @@ * See LICENSE file in the project root for full license information. ********************************************************************/ - #ifndef IOLINK_PDE_H #define IOLINK_PDE_H @@ -18,8 +17,7 @@ #include "iolink_types.h" #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif /** @@ -43,26 +41,29 @@ void iolink_pde_init (iolink_port_t * port); iolink_error_t PD_Start (iolink_port_t * port); iolink_error_t PD_Stop (iolink_port_t * port); iolink_error_t AL_NewInput_ind (iolink_port_t * port); -iolink_error_t AL_Control_ind (iolink_port_t * port, - iolink_controlcode_t controlcode); +iolink_error_t AL_Control_ind ( + iolink_port_t * port, + iolink_controlcode_t controlcode); -iolink_error_t pde_SMI_PDIn_req (iolink_port_t * port, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, - arg_block_t * arg_block); +iolink_error_t pde_SMI_PDIn_req ( + iolink_port_t * port, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block); -iolink_error_t pde_SMI_PDOut_req (iolink_port_t * port, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, - arg_block_t * arg_block); +iolink_error_t pde_SMI_PDOut_req ( + iolink_port_t * port, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block); -iolink_error_t pde_SMI_PDInOut_req (iolink_port_t * port, - iolink_arg_block_id_t exp_arg_block_id, - uint16_t arg_block_len, - arg_block_t * arg_block); +iolink_error_t pde_SMI_PDInOut_req ( + iolink_port_t * port, + iolink_arg_block_id_t exp_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block); #ifdef __cplusplus } #endif #endif /* IOLINK_PDE_H */ - diff --git a/src/iolink_pl.c b/src/iolink_pl.c index 93c07db..6115692 100644 --- a/src/iolink_pl.c +++ b/src/iolink_pl.c @@ -21,21 +21,23 @@ * */ -#define IOLINK_RXERR_CHKSM BIT(0) -#define IOLINK_RXERR_SIZE BIT(1) -#define IOLINK_RXERR_FRAME BIT(2) -#define IOLINK_RXERR_PARITY BIT(3) -#define IOLINK_RXERR_TDLY BIT(4) -#define IOLINK_TXERR_TRANSM BIT(5) -#define IOLINK_TXERR_CYCL BIT(6) -#define IOLINK_TXERR_CHKSM BIT(7) -#define IOLINK_TXERR_SIZE BIT(8) +#define IOLINK_RXERR_CHKSM BIT (0) +#define IOLINK_RXERR_SIZE BIT (1) +#define IOLINK_RXERR_FRAME BIT (2) +#define IOLINK_RXERR_PARITY BIT (3) +#define IOLINK_RXERR_TDLY BIT (4) +#define IOLINK_TXERR_TRANSM BIT (5) +#define IOLINK_TXERR_CYCL BIT (6) +#define IOLINK_TXERR_CHKSM BIT (7) +#define IOLINK_TXERR_SIZE BIT (8) /* * Wrapper functions */ -void iolink_configure_pl_event (iolink_port_t * port, os_event_t * event, - uint32_t flag) +void iolink_configure_pl_event ( + iolink_port_t * port, + os_event_t * event, + uint32_t flag) { iolink_pl_port_t * pl = iolink_get_pl_ctx (port); @@ -74,11 +76,10 @@ void iolink_pl_get_data (iolink_port_t * port, uint8_t * rxdata, uint8_t len) { iolink_pl_port_t * pl = iolink_get_pl_ctx (port); - iolink_pl_hw_get_data(pl->fd, rxdata, len); + iolink_pl_hw_get_data (pl->fd, rxdata, len); } -void iolink_pl_get_error (iolink_port_t * port, uint8_t * cqerr, - uint8_t * devdly) +void iolink_pl_get_error (iolink_port_t * port, uint8_t * cqerr, uint8_t * devdly) { iolink_pl_port_t * pl = iolink_get_pl_ctx (port); @@ -112,15 +113,21 @@ void PL_Resend (iolink_port_t * port) iolink_pl_hw_send_msg (pl->fd); } -void PL_Transfer_req (iolink_port_t * port, uint8_t rxbytes, uint8_t txbytes, - uint8_t * data) +void PL_Transfer_req ( + iolink_port_t * port, + uint8_t rxbytes, + uint8_t txbytes, + uint8_t * data) { iolink_pl_port_t * pl = iolink_get_pl_ctx (port); iolink_pl_hw_transfer_req (pl->fd, rxbytes, txbytes, data); } -void PL_MessageDownload_req (iolink_port_t * port, uint8_t rxbytes, - uint8_t txbytes, uint8_t * data) +void PL_MessageDownload_req ( + iolink_port_t * port, + uint8_t rxbytes, + uint8_t txbytes, + uint8_t * data) { iolink_pl_port_t * pl = iolink_get_pl_ctx (port); @@ -148,7 +155,7 @@ void iolink_pl_init (iolink_port_t * port, const char * name) { iolink_pl_port_t * pl = iolink_get_pl_ctx (port); - memset (pl, 0, sizeof(iolink_pl_port_t)); + memset (pl, 0, sizeof (iolink_pl_port_t)); pl->fd = iolink_pl_hw_open (name); CC_ASSERT (pl->fd > 0); } diff --git a/src/iolink_pl.h b/src/iolink_pl.h index 3ae5527..4255417 100644 --- a/src/iolink_pl.h +++ b/src/iolink_pl.h @@ -10,7 +10,6 @@ * See LICENSE file in the project root for full license information. ********************************************************************/ - #ifndef IOLINK_PL_H #define IOLINK_PL_H @@ -22,8 +21,7 @@ #include #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif typedef struct iolink_pl_port @@ -34,15 +32,16 @@ typedef struct iolink_pl_port /* * Function interface */ -void iolink_configure_pl_event (iolink_port_t * port, os_event_t * event, - uint32_t flag); +void iolink_configure_pl_event ( + iolink_port_t * port, + os_event_t * event, + uint32_t flag); void iolink_pl_handler (iolink_port_t * port); iolink_baudrate_t iolink_pl_get_baudrate (iolink_port_t * port); uint8_t iolink_pl_get_cycletime (iolink_port_t * port); void iolink_pl_set_cycletime (iolink_port_t * port, uint8_t cycbyte); void iolink_pl_get_data (iolink_port_t * port, uint8_t * rxdata, uint8_t len); -void iolink_pl_get_error (iolink_port_t * port, uint8_t * cqerr, - uint8_t * devdly); +void iolink_pl_get_error (iolink_port_t * port, uint8_t * cqerr, uint8_t * devdly); bool iolink_pl_init_sdci (iolink_port_t * port); /* @@ -52,10 +51,16 @@ void PL_SetMode_req (iolink_port_t * port, iolink_pl_mode_t mode); void PL_WakeUp_req (iolink_port_t * port); #if IOLINK_HW == IOLINK_HW_MAX14819 void PL_Resend (iolink_port_t * port); -void PL_Transfer_req (iolink_port_t * port, uint8_t rxbytes, uint8_t txbytes, - uint8_t * data); -void PL_MessageDownload_req (iolink_port_t * port, uint8_t rxbytes, - uint8_t txbytes, uint8_t * data); +void PL_Transfer_req ( + iolink_port_t * port, + uint8_t rxbytes, + uint8_t txbytes, + uint8_t * data); +void PL_MessageDownload_req ( + iolink_port_t * port, + uint8_t rxbytes, + uint8_t txbytes, + uint8_t * data); void PL_EnableCycleTimer (iolink_port_t * port); void PL_DisableCycleTimer (iolink_port_t * port); #else @@ -68,4 +73,3 @@ void iolink_pl_init (iolink_port_t * port, const char * name); #endif #endif /* IOLINK_PL_H */ - diff --git a/src/iolink_pl_hw.c b/src/iolink_pl_hw.c index 24ae8ea..01ac45e 100644 --- a/src/iolink_pl_hw.c +++ b/src/iolink_pl_hw.c @@ -25,145 +25,144 @@ * */ -#define GET_ARG_AND_LOCK(fd) \ - drv_t * drv = fd_get_driver (fd); \ - iolink_hw_drv_t * iolink_hw = \ - (iolink_hw_drv_t *)drv; \ - void * arg = fd_get_arg (fd); \ +#define GET_ARG_AND_LOCK(fd) \ + drv_t * drv = fd_get_driver (fd); \ + iolink_hw_drv_t * iolink_hw = (iolink_hw_drv_t *)drv; \ + void * arg = fd_get_arg (fd); \ os_mutex_lock (drv->mtx); -#define UNLOCK(drv) \ - os_mutex_unlock (drv->mtx); +#define UNLOCK(drv) os_mutex_unlock (drv->mtx); -#define UNLOCK_AND_RETURN(drv, item) \ - os_mutex_unlock (drv->mtx); \ +#define UNLOCK_AND_RETURN(drv, item) \ + os_mutex_unlock (drv->mtx); \ return item; iolink_baudrate_t iolink_pl_hw_get_baudrate (int fd) { - GET_ARG_AND_LOCK(fd); + GET_ARG_AND_LOCK (fd); iolink_baudrate_t baudrate = iolink_hw->ops->get_baudrate (iolink_hw, arg); - UNLOCK_AND_RETURN(drv, baudrate); + UNLOCK_AND_RETURN (drv, baudrate); } uint8_t iolink_pl_hw_get_cycletime (int fd) { - GET_ARG_AND_LOCK(fd); + GET_ARG_AND_LOCK (fd); uint8_t cycletime = iolink_hw->ops->get_cycletime (iolink_hw, arg); - UNLOCK_AND_RETURN(drv, cycletime); + UNLOCK_AND_RETURN (drv, cycletime); } void iolink_pl_hw_set_cycletime (int fd, uint8_t cycbyte) { - GET_ARG_AND_LOCK(fd); + GET_ARG_AND_LOCK (fd); iolink_hw->ops->set_cycletime (iolink_hw, arg, cycbyte); - UNLOCK(drv); + UNLOCK (drv); } bool iolink_pl_hw_set_mode (int fd, iolink_pl_mode_t mode) { - GET_ARG_AND_LOCK(fd); + GET_ARG_AND_LOCK (fd); bool res = iolink_hw->ops->set_mode (iolink_hw, arg, mode); - UNLOCK_AND_RETURN(drv, res); + UNLOCK_AND_RETURN (drv, res); } void iolink_pl_hw_enable_cycle_timer (int fd) { - GET_ARG_AND_LOCK(fd); + GET_ARG_AND_LOCK (fd); iolink_hw->ops->enable_cycle_timer (iolink_hw, arg); - UNLOCK(drv); + UNLOCK (drv); } void iolink_pl_hw_disable_cycle_timer (int fd) { - GET_ARG_AND_LOCK(fd); + GET_ARG_AND_LOCK (fd); iolink_hw->ops->disable_cycle_timer (iolink_hw, arg); - UNLOCK(drv); + UNLOCK (drv); } -void iolink_pl_hw_get_data(int fd, uint8_t *rxdata, uint8_t len) +void iolink_pl_hw_get_data (int fd, uint8_t * rxdata, uint8_t len) { - GET_ARG_AND_LOCK(fd); + GET_ARG_AND_LOCK (fd); iolink_hw->ops->get_data (iolink_hw, arg, rxdata, len); - UNLOCK(drv); + UNLOCK (drv); } -void iolink_pl_hw_get_error (int fd, uint8_t *cqerr, uint8_t *devdly) +void iolink_pl_hw_get_error (int fd, uint8_t * cqerr, uint8_t * devdly) { - GET_ARG_AND_LOCK(fd); + GET_ARG_AND_LOCK (fd); iolink_hw->ops->get_error (iolink_hw, arg, cqerr, devdly); - UNLOCK(drv); + UNLOCK (drv); } void iolink_pl_hw_send_msg (int fd) { - GET_ARG_AND_LOCK(fd); + GET_ARG_AND_LOCK (fd); iolink_hw->ops->send_msg (iolink_hw, arg); - UNLOCK(drv); + UNLOCK (drv); } -void iolink_pl_hw_dl_msg (int fd, uint8_t rxbytes, uint8_t txbytes, - uint8_t *data) +void iolink_pl_hw_dl_msg (int fd, uint8_t rxbytes, uint8_t txbytes, uint8_t * data) { - GET_ARG_AND_LOCK(fd); + GET_ARG_AND_LOCK (fd); iolink_hw->ops->dl_msg (iolink_hw, arg, rxbytes, txbytes, data); - UNLOCK(drv); + UNLOCK (drv); } -void iolink_pl_hw_transfer_req (int fd, uint8_t rxbytes, uint8_t txbytes, - uint8_t *data) +void iolink_pl_hw_transfer_req ( + int fd, + uint8_t rxbytes, + uint8_t txbytes, + uint8_t * data) { - GET_ARG_AND_LOCK(fd); + GET_ARG_AND_LOCK (fd); iolink_hw->ops->transfer_req (iolink_hw, arg, rxbytes, txbytes, data); - UNLOCK(drv); + UNLOCK (drv); } bool iolink_pl_hw_init_sdci (int fd) { - GET_ARG_AND_LOCK(fd); + GET_ARG_AND_LOCK (fd); bool res = iolink_hw->ops->init_sdci (iolink_hw, arg); - UNLOCK_AND_RETURN(drv, res); + UNLOCK_AND_RETURN (drv, res); } -void iolink_pl_hw_configure_event (int fd, os_event_t * event, - uint32_t flag) +void iolink_pl_hw_configure_event (int fd, os_event_t * event, uint32_t flag) { - GET_ARG_AND_LOCK(fd); + GET_ARG_AND_LOCK (fd); iolink_hw->ops->configure_event (iolink_hw, arg, event, flag); - UNLOCK(drv); + UNLOCK (drv); } void iolink_pl_hw_pl_handler (int fd) { - GET_ARG_AND_LOCK(fd); + GET_ARG_AND_LOCK (fd); iolink_hw->ops->pl_handler (iolink_hw, arg); - UNLOCK(drv); + UNLOCK (drv); } diff --git a/src/iolink_pl_hw.h b/src/iolink_pl_hw.h index 932c768..6d7e9b7 100644 --- a/src/iolink_pl_hw.h +++ b/src/iolink_pl_hw.h @@ -20,15 +20,14 @@ #else #include "osal_fileops.h" #endif -#include /* O_RDWR */ +#include /* O_RDWR */ #include /* close */ #include "iolink_types.h" #include "iolink.h" #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif /** @@ -75,18 +74,19 @@ void iolink_pl_hw_enable_cycle_timer (int fd); void iolink_pl_hw_disable_cycle_timer (int fd); -void iolink_pl_hw_get_data(int fd, uint8_t *rxdata, uint8_t len); -void iolink_pl_hw_get_error (int fd, uint8_t *cqerr, uint8_t *devdly); +void iolink_pl_hw_get_data (int fd, uint8_t * rxdata, uint8_t len); +void iolink_pl_hw_get_error (int fd, uint8_t * cqerr, uint8_t * devdly); void iolink_pl_hw_send_msg (int fd); -void iolink_pl_hw_dl_msg (int fd, uint8_t rxbytes, uint8_t txbytes, - uint8_t *data); -void iolink_pl_hw_transfer_req (int fd, uint8_t rxbytes, uint8_t txbytes, - uint8_t *data); +void iolink_pl_hw_dl_msg (int fd, uint8_t rxbytes, uint8_t txbytes, uint8_t * data); +void iolink_pl_hw_transfer_req ( + int fd, + uint8_t rxbytes, + uint8_t txbytes, + uint8_t * data); bool iolink_pl_hw_init_sdci (int fd); -void iolink_pl_hw_configure_event (int fd, os_event_t * event, - uint32_t flag); +void iolink_pl_hw_configure_event (int fd, os_event_t * event, uint32_t flag); void iolink_pl_hw_pl_handler (int fd); diff --git a/src/iolink_pl_hw_drv.h b/src/iolink_pl_hw_drv.h index 2626f24..6435a40 100644 --- a/src/iolink_pl_hw_drv.h +++ b/src/iolink_pl_hw_drv.h @@ -22,35 +22,54 @@ #include "iolink_max14819.h" #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif struct iolink_hw_drv; typedef struct iolink_hw_ops { - iolink_baudrate_t (*get_baudrate) (struct iolink_hw_drv * iolink_hw, - void * arg); + iolink_baudrate_t (*get_baudrate) (struct iolink_hw_drv * iolink_hw, void * arg); uint8_t (*get_cycletime) (struct iolink_hw_drv * iolink_hw, void * arg); - void (*set_cycletime) (struct iolink_hw_drv * iolink_hw, void * arg, - uint8_t cycbyte); - bool (*set_mode) (struct iolink_hw_drv * iolink_hw, void * arg, - iolink_pl_mode_t mode); + void (*set_cycletime) ( + struct iolink_hw_drv * iolink_hw, + void * arg, + uint8_t cycbyte); + bool (*set_mode) ( + struct iolink_hw_drv * iolink_hw, + void * arg, + iolink_pl_mode_t mode); void (*enable_cycle_timer) (struct iolink_hw_drv * iolink_hw, void * arg); void (*disable_cycle_timer) (struct iolink_hw_drv * iolink_hw, void * arg); - void (*get_error) (struct iolink_hw_drv * iolink_hw, void * arg, - uint8_t *cqerr, uint8_t *devdly); - void (*get_data) (struct iolink_hw_drv * iolink_hw, void * arg, - uint8_t *rxdata, uint8_t len); - void (*dl_msg) (struct iolink_hw_drv * iolink_hw, void * arg, - uint8_t rxbytes, uint8_t txbytes, uint8_t *data); + void (*get_error) ( + struct iolink_hw_drv * iolink_hw, + void * arg, + uint8_t * cqerr, + uint8_t * devdly); + void (*get_data) ( + struct iolink_hw_drv * iolink_hw, + void * arg, + uint8_t * rxdata, + uint8_t len); + void (*dl_msg) ( + struct iolink_hw_drv * iolink_hw, + void * arg, + uint8_t rxbytes, + uint8_t txbytes, + uint8_t * data); void (*send_msg) (struct iolink_hw_drv * iolink_hw, void * arg); - void (*transfer_req) (struct iolink_hw_drv * iolink_hw, void * arg, - uint8_t rxbytes, uint8_t txbytes, uint8_t *data); + void (*transfer_req) ( + struct iolink_hw_drv * iolink_hw, + void * arg, + uint8_t rxbytes, + uint8_t txbytes, + uint8_t * data); bool (*init_sdci) (struct iolink_hw_drv * iolink_hw, void * arg); - void (*configure_event) (struct iolink_hw_drv * iolink_hw, void * arg, - os_event_t * event, uint32_t flag); + void (*configure_event) ( + struct iolink_hw_drv * iolink_hw, + void * arg, + os_event_t * event, + uint32_t flag); void (*pl_handler) (struct iolink_hw_drv * iolink_hw, void * arg); } iolink_hw_ops_t; diff --git a/src/iolink_sm.c b/src/iolink_sm.c index ea95893..2c791d1 100644 --- a/src/iolink_sm.c +++ b/src/iolink_sm.c @@ -11,16 +11,16 @@ ********************************************************************/ #ifdef UNIT_TEST -#define DL_Write_req mock_DL_Write_req -#define DL_Read_req mock_DL_Read_req -#define DL_SetMode_req mock_DL_SetMode_req +#define DL_Write_req mock_DL_Write_req +#define DL_Read_req mock_DL_Read_req +#define DL_SetMode_req mock_DL_SetMode_req #define DL_Write_Devicemode_req mock_DL_Write_Devicemode_req -#define PL_SetMode_req mock_PL_SetMode_req -#define AL_Read_req mock_AL_Read_req -#define AL_Write_req mock_AL_Write_req -#define SM_PortMode_ind mock_SM_PortMode_ind -#define iolink_post_job mock_iolink_post_job -#define iolink_fetch_avail_job mock_iolink_fetch_avail_job +#define PL_SetMode_req mock_PL_SetMode_req +#define AL_Read_req mock_AL_Read_req +#define AL_Write_req mock_AL_Write_req +#define SM_PortMode_ind mock_SM_PortMode_ind +#define iolink_post_job mock_iolink_post_job +#define iolink_fetch_avail_job mock_iolink_fetch_avail_job #endif /* UNIT_TEST */ #include "iolink_sm.h" @@ -45,8 +45,8 @@ typedef struct iolink_fsm_sm_transition { iolink_fsm_sm_event_t event; iolink_sm_state_t next_state; - iolink_fsm_sm_event_t (*action)(iolink_port_t * port, - iolink_fsm_sm_event_t event); + iolink_fsm_sm_event_t ( + *action) (iolink_port_t * port, iolink_fsm_sm_event_t event); } iolink_fsm_sm_transition_t; typedef struct iolink_fsm_sm_state_transitions @@ -55,8 +55,7 @@ typedef struct iolink_fsm_sm_state_transitions const iolink_fsm_sm_transition_t * transitions; } iolink_fsm_sm_state_transitions_t; -const char * iolink_fsm_sm_event_literals[] = -{ +const char * iolink_fsm_sm_event_literals[] = { "NONE", "DL_Mode_STARTUP", /* T1 */ "CompOK", /* T2 */ @@ -81,13 +80,13 @@ const char * iolink_fsm_sm_event_literals[] = "REVISION_OK", /* T22 */ "RETRY_STARTUP", /* T23 and T25 */ "WriteDone", /* T24 */ - "CNF_COMLOST", /* T3, COMLOST when waiting on DL_{Read,Write}_cnf(), AL_{Read,Write}_cnf() or DL_Write_Devicemode_cnf()*/ - "WRITE_MASTER_CYCL_REQ", /* Not in spec */ - "WRITE_MASTER_CYCL_DONE", /* Not in spec */ + "CNF_COMLOST", /* T3, COMLOST when waiting on DL_{Read,Write}_cnf(), + AL_{Read,Write}_cnf() or DL_Write_Devicemode_cnf()*/ + "WRITE_MASTER_CYCL_REQ", /* Not in spec */ + "WRITE_MASTER_CYCL_DONE", /* Not in spec */ }; -const char * iolink_sm_state_literals[] = -{ +const char * iolink_sm_state_literals[] = { "PortInactive", "waitonDLPreoperate", "checkSerNum", @@ -106,8 +105,7 @@ const char * iolink_sm_state_literals[] = "wait_devmode_cnf", }; -const char * iolink_mhmode_literals[] = -{ +const char * iolink_mhmode_literals[] = { "INACTIVE", "COM1", "COM2", @@ -119,8 +117,7 @@ const char * iolink_mhmode_literals[] = "OPERATE", }; -const char * iolink_sm_target_mode_literals[] = -{ +const char * iolink_sm_target_mode_literals[] = { "CFGCOM", "AUTOCOM", "INACTIVE", @@ -128,8 +125,7 @@ const char * iolink_sm_target_mode_literals[] = "DO", }; -const char * iolink_error_literals[] = -{ +const char * iolink_error_literals[] = { "NONE", "PDINLENGTH", "PDOUTLENGTH", @@ -151,13 +147,20 @@ static void iolink_sm_event (iolink_port_t * port, iolink_fsm_sm_event_t event); static void sm_write_cycl_cnf_cb (iolink_job_t * job); static void sm_AL_Read_cnf_cb (iolink_job_t * job); -static iolink_error_t populate_valuelist (uint8_t mscapa, uint8_t revid, - uint8_t pdin, uint8_t pdout, - uint8_t cycbyte, bool operate, - iolink_mode_vl_t *valuelist); - -static iolink_fsm_sm_event_t sm_DL_Read_Write_req (iolink_port_t * port, uint8_t addr, - uint8_t value, bool read) +static iolink_error_t populate_valuelist ( + uint8_t mscapa, + uint8_t revid, + uint8_t pdin, + uint8_t pdout, + uint8_t cycbyte, + bool operate, + iolink_mode_vl_t * valuelist); + +static iolink_fsm_sm_event_t sm_DL_Read_Write_req ( + iolink_port_t * port, + uint8_t addr, + uint8_t value, + bool read) { iolink_sm_port_t * sm = iolink_get_sm_ctx (port); iolink_error_t res; @@ -166,7 +169,8 @@ static iolink_fsm_sm_event_t sm_DL_Read_Write_req (iolink_port_t * port, uint8_t if (read) { - CC_ASSERT ((addr >= IOL_DIR_PARAMA_MIN_CYCL) && (addr <= IOL_DIR_PARAMA_FID_2)); + CC_ASSERT ( + (addr >= IOL_DIR_PARAMA_MIN_CYCL) && (addr <= IOL_DIR_PARAMA_FID_2)); res = DL_Read_req (port, addr); } @@ -179,9 +183,12 @@ static iolink_fsm_sm_event_t sm_DL_Read_Write_req (iolink_port_t * port, uint8_t if (res != IOLINK_ERROR_NONE) { - LOG_WARNING (IOLINK_SM_LOG, "SM: %u: DL_%s_req failed: %s\n", - iolink_get_portnumber (port), (read) ? "Read" : "Write", - iolink_error_literals[res]); + LOG_WARNING ( + IOLINK_SM_LOG, + "SM: %u: DL_%s_req failed: %s\n", + iolink_get_portnumber (port), + (read) ? "Read" : "Write", + iolink_error_literals[res]); } return SM_EVENT_NONE; /* Always wait for DL_Read_cnf()/DL_Write_cnf() */ @@ -189,58 +196,77 @@ static iolink_fsm_sm_event_t sm_DL_Read_Write_req (iolink_port_t * port, uint8_t static iolink_fsm_sm_event_t sm_DL_Read_req (iolink_port_t * port, uint8_t addr) { - return sm_DL_Read_Write_req(port, addr, 0, true); + return sm_DL_Read_Write_req (port, addr, 0, true); } -static iolink_fsm_sm_event_t sm_DL_Write_req (iolink_port_t * port, - uint8_t addr, uint8_t value) +static iolink_fsm_sm_event_t sm_DL_Write_req ( + iolink_port_t * port, + uint8_t addr, + uint8_t value) { - return sm_DL_Read_Write_req(port, addr, value, false); + return sm_DL_Read_Write_req (port, addr, value, false); } -static void sm_DL_Write_Devicemode_req (iolink_port_t * port, - iolink_dl_mode_t devicemode) +static void sm_DL_Write_Devicemode_req ( + iolink_port_t * port, + iolink_dl_mode_t devicemode) { iolink_error_t res = DL_Write_Devicemode_req (port, devicemode); if (res != IOLINK_ERROR_NONE) { - LOG_WARNING (IOLINK_SM_LOG, "%u: DL_Write_Devicemode_req failed: %s\n", - iolink_get_portnumber (port), iolink_error_literals[res]); + LOG_WARNING ( + IOLINK_SM_LOG, + "%u: DL_Write_Devicemode_req failed: %s\n", + iolink_get_portnumber (port), + iolink_error_literals[res]); } } -static void sm_write_master_cycl_cnf (iolink_port_t * port, - iolink_smi_errortypes_t errortype) +static void sm_write_master_cycl_cnf ( + iolink_port_t * port, + iolink_smi_errortypes_t errortype) { - iolink_job_t * job = iolink_fetch_avail_job (port); + iolink_job_t * job = iolink_fetch_avail_job (port); job->al_write_cnf.errortype = errortype; - iolink_post_job_with_type_and_callback (port, job, IOLINK_JOB_AL_WRITE_CNF, sm_write_cycl_cnf_cb); + iolink_post_job_with_type_and_callback ( + port, + job, + IOLINK_JOB_AL_WRITE_CNF, + sm_write_cycl_cnf_cb); } -static iolink_fsm_sm_event_t sm_wr_master_cycl (iolink_port_t * port, - iolink_fsm_sm_event_t event) +static iolink_fsm_sm_event_t sm_wr_master_cycl ( + iolink_port_t * port, + iolink_fsm_sm_event_t event) { - iolink_sm_port_t * sm = iolink_get_sm_ctx (port); + iolink_sm_port_t * sm = iolink_get_sm_ctx (port); iolink_smp_parameterlist_t * real_paramlist = &sm->real_paramlist; /* Not in spec */ - iolink_error_t res = AL_Write_req (port, IOL_DIR_PARAMA_MASTER_CYCL, 0, - sizeof(real_paramlist->cycletime), - &real_paramlist->cycletime, - sm_write_master_cycl_cnf); + iolink_error_t res = AL_Write_req ( + port, + IOL_DIR_PARAMA_MASTER_CYCL, + 0, + sizeof (real_paramlist->cycletime), + &real_paramlist->cycletime, + sm_write_master_cycl_cnf); if (res != IOLINK_ERROR_NONE) { - LOG_WARNING (IOLINK_SM_LOG, "%u: AL_Write_req failed: %s\n", - iolink_get_portnumber (port), iolink_error_literals[res]); + LOG_WARNING ( + IOLINK_SM_LOG, + "%u: AL_Write_req failed: %s\n", + iolink_get_portnumber (port), + iolink_error_literals[res]); } return SM_EVENT_NONE; /* Always wait for AL_Write_cnf() */ } -static iolink_fsm_sm_event_t sm_checkCompV10_21 (iolink_port_t * port, - iolink_fsm_sm_event_t event) +static iolink_fsm_sm_event_t sm_checkCompV10_21 ( + iolink_port_t * port, + iolink_fsm_sm_event_t event) { /* Read 0x07 to 0x0D */ return sm_DL_Read_req (port, IOL_DIR_PARAMA_VID_1); @@ -249,30 +275,33 @@ static iolink_fsm_sm_event_t sm_checkCompV10_21 (iolink_port_t * port, static void sm_do_check_comp_v10 (iolink_port_t * port) { iolink_fsm_sm_event_t ret; - iolink_sm_port_t * sm = iolink_get_sm_ctx (port); + iolink_sm_port_t * sm = iolink_get_sm_ctx (port); iolink_smp_parameterlist_t * config_paramlist = &sm->config_paramlist; - iolink_smp_parameterlist_t * real_paramlist = &sm->real_paramlist; + iolink_smp_parameterlist_t * real_paramlist = &sm->real_paramlist; - if (config_paramlist->cycletime && - (config_paramlist->cycletime < real_paramlist->cycletime)) + if ( + config_paramlist->cycletime && + (config_paramlist->cycletime < real_paramlist->cycletime)) { - ret = SM_EVENT_CycTimeFault_V10; /* T18 */ + ret = SM_EVENT_CycTimeFault_V10; /* T18 */ sm->error_event = ret; } else if (config_paramlist->inspectionlevel == IOLINK_INSPECTIONLEVEL_NO_CHECK) { ret = SM_EVENT_V10CompOK; /* T4 */ } - else /* IOLINK_INSPECTIONLEVEL_TYPE_COMP || IOLINK_INSPECTIONLEVEL_IDENTICAL */ + else /* IOLINK_INSPECTIONLEVEL_TYPE_COMP || IOLINK_INSPECTIONLEVEL_IDENTICAL + */ { - if ((config_paramlist->vendorid == real_paramlist->vendorid) && - (config_paramlist->deviceid == real_paramlist->deviceid)) + if ( + (config_paramlist->vendorid == real_paramlist->vendorid) && + (config_paramlist->deviceid == real_paramlist->deviceid)) { ret = SM_EVENT_V10CompOK; /* T4 */ } else { - ret = SM_EVENT_V10CompFault; /* T5 */ + ret = SM_EVENT_V10CompFault; /* T5 */ sm->error_event = ret; } } @@ -280,28 +309,34 @@ static void sm_do_check_comp_v10 (iolink_port_t * port) iolink_sm_event (port, ret); } -static void set_valuelist(iolink_mode_vl_t* valuelist, uint8_t onreqdatalengthpermessage, - uint8_t pdinputlength, uint8_t pdoutputlength, uint8_t time, - iolink_msequencetype_t type) +static void set_valuelist ( + iolink_mode_vl_t * valuelist, + uint8_t onreqdatalengthpermessage, + uint8_t pdinputlength, + uint8_t pdoutputlength, + uint8_t time, + iolink_msequencetype_t type) { valuelist->onreqdatalengthpermessage = onreqdatalengthpermessage; - valuelist->pdinputlength = pdinputlength; - valuelist->pdoutputlength = pdoutputlength; - valuelist->time = time; - valuelist->type = type; + valuelist->pdinputlength = pdinputlength; + valuelist->pdoutputlength = pdoutputlength; + valuelist->time = time; + valuelist->type = type; } -static inline iolink_error_t sm_DL_SetMode_req_startup_inactive (iolink_port_t * port, iolink_dl_mode_t mode) +static inline iolink_error_t sm_DL_SetMode_req_startup_inactive ( + iolink_port_t * port, + iolink_dl_mode_t mode) { iolink_mode_vl_t valuelist; if (mode == IOLINK_DLMODE_STARTUP) { - set_valuelist(&valuelist, 1, 0, 0, 0, IOLINK_MSEQTYPE_TYPE_0); + set_valuelist (&valuelist, 1, 0, 0, 0, IOLINK_MSEQTYPE_TYPE_0); } else if (mode == IOLINK_DLMODE_INACTIVE) { - set_valuelist(&valuelist, 0, 0, 0, 0, IOLINK_MSEQTYPE_TYPE_NONE); + set_valuelist (&valuelist, 0, 0, 0, 0, IOLINK_MSEQTYPE_TYPE_NONE); } return DL_SetMode_req (port, mode, &valuelist); @@ -317,17 +352,24 @@ static inline iolink_error_t sm_DL_SetMode_req_inactive (iolink_port_t * port) return sm_DL_SetMode_req_startup_inactive (port, IOLINK_DLMODE_INACTIVE); } -static inline iolink_error_t sm_DL_SetMode_req_preop_op (iolink_port_t * port, iolink_dl_mode_t mode) +static inline iolink_error_t sm_DL_SetMode_req_preop_op ( + iolink_port_t * port, + iolink_dl_mode_t mode) { iolink_mode_vl_t valuelist; - iolink_sm_port_t * sm = iolink_get_sm_ctx (port); + iolink_sm_port_t * sm = iolink_get_sm_ctx (port); iolink_smp_parameterlist_t * real_paramlist = &sm->real_paramlist; - set_valuelist(&valuelist, 1, 0, 0, 0, IOLINK_MSEQTYPE_TYPE_0); + set_valuelist (&valuelist, 1, 0, 0, 0, IOLINK_MSEQTYPE_TYPE_0); - populate_valuelist (sm->dev_com.mseq_cap, real_paramlist->revisionid, sm->dev_com.pdi, - sm->dev_com.pdo, real_paramlist->cycletime, (mode == IOLINK_DLMODE_OPERATE), - &valuelist); + populate_valuelist ( + sm->dev_com.mseq_cap, + real_paramlist->revisionid, + sm->dev_com.pdi, + sm->dev_com.pdo, + real_paramlist->cycletime, + (mode == IOLINK_DLMODE_OPERATE), + &valuelist); if (valuelist.type == IOLINK_MSEQTYPE_TYPE_1_1) { @@ -341,42 +383,48 @@ static inline iolink_error_t sm_DL_SetMode_req_preop_op (iolink_port_t * port, i static inline iolink_error_t sm_DL_SetMode_req_preop (iolink_port_t * port) { - return sm_DL_SetMode_req_preop_op(port, IOLINK_DLMODE_PREOPERATE); + return sm_DL_SetMode_req_preop_op (port, IOLINK_DLMODE_PREOPERATE); } static inline iolink_error_t sm_DL_SetMode_req_operate (iolink_port_t * port) { - return sm_DL_SetMode_req_preop_op(port, IOLINK_DLMODE_OPERATE); + return sm_DL_SetMode_req_preop_op (port, IOLINK_DLMODE_OPERATE); } -static iolink_fsm_sm_event_t sm_readcomparameter (iolink_port_t * port, - iolink_fsm_sm_event_t event) +static iolink_fsm_sm_event_t sm_readcomparameter ( + iolink_port_t * port, + iolink_fsm_sm_event_t event) { if (event == SM_EVENT_DL_Mode_STARTUP) { iolink_sm_port_t * sm = iolink_get_sm_ctx (port); - sm->CompRetry = 0; + sm->CompRetry = 0; } /* Read 0x02 to 0x06 */ return sm_DL_Read_req (port, IOL_DIR_PARAMA_MIN_CYCL); } -static iolink_fsm_sm_event_t sm_restartDevice (iolink_port_t * port, - iolink_fsm_sm_event_t event) +static iolink_fsm_sm_event_t sm_restartDevice ( + iolink_port_t * port, + iolink_fsm_sm_event_t event) { - iolink_sm_port_t * sm = iolink_get_sm_ctx (port); + iolink_sm_port_t * sm = iolink_get_sm_ctx (port); iolink_smp_parameterlist_t * config_paramlist = &sm->config_paramlist; // TODO: is this correct? // According to Table 84, page 133, increase compretry on T25, not T23?? // If not, add SM_EVENT_RETRY_STARTUP_23 and SM_EVENT_RETRY_STARTUP_25 sm->CompRetry++; - return sm_DL_Write_req (port, IOL_DIR_PARAMA_REV_ID, config_paramlist->revisionid); + return sm_DL_Write_req ( + port, + IOL_DIR_PARAMA_REV_ID, + config_paramlist->revisionid); } -static iolink_fsm_sm_event_t sm_checkComp (iolink_port_t * port, - iolink_fsm_sm_event_t event) +static iolink_fsm_sm_event_t sm_checkComp ( + iolink_port_t * port, + iolink_fsm_sm_event_t event) { /* Read 0x07 to 0x0D */ return sm_DL_Read_req (port, IOL_DIR_PARAMA_VID_1); @@ -385,25 +433,27 @@ static iolink_fsm_sm_event_t sm_checkComp (iolink_port_t * port, static void sm_do_check_comp (iolink_port_t * port) { iolink_fsm_sm_event_t ret; - iolink_sm_port_t * sm = iolink_get_sm_ctx (port); + iolink_sm_port_t * sm = iolink_get_sm_ctx (port); iolink_smp_parameterlist_t * config_paramlist = &sm->config_paramlist; - iolink_smp_parameterlist_t * real_paramlist = &sm->real_paramlist; + iolink_smp_parameterlist_t * real_paramlist = &sm->real_paramlist; - if (config_paramlist->cycletime && - (config_paramlist->cycletime < real_paramlist->cycletime)) + if ( + config_paramlist->cycletime && + (config_paramlist->cycletime < real_paramlist->cycletime)) { - ret = SM_EVENT_CycTimeFault; /* T17 */ + ret = SM_EVENT_CycTimeFault; /* T17 */ sm->error_event = ret; } else if (config_paramlist->inspectionlevel == IOLINK_INSPECTIONLEVEL_NO_CHECK) { ret = SM_EVENT_CompOK; /* T2 */ } - else /* IOLINK_INSPECTIONLEVEL_TYPE_COMP || IOLINK_INSPECTIONLEVEL_IDENTICAL */ + else /* IOLINK_INSPECTIONLEVEL_TYPE_COMP || IOLINK_INSPECTIONLEVEL_IDENTICAL + */ { if (config_paramlist->vendorid != real_paramlist->vendorid) { - ret = SM_EVENT_CompFault; /* T7 */ + ret = SM_EVENT_CompFault; /* T7 */ sm->error_event = ret; } else if (config_paramlist->deviceid == real_paramlist->deviceid) @@ -418,7 +468,7 @@ static void sm_do_check_comp (iolink_port_t * port) } else { - ret = SM_EVENT_CompFault; /* T7 */ + ret = SM_EVENT_CompFault; /* T7 */ sm->error_event = ret; } } @@ -427,35 +477,43 @@ static void sm_do_check_comp (iolink_port_t * port) iolink_sm_event (port, ret); } -static iolink_fsm_sm_event_t sm_checkVxy (iolink_port_t * port, - iolink_fsm_sm_event_t event) +static iolink_fsm_sm_event_t sm_checkVxy ( + iolink_port_t * port, + iolink_fsm_sm_event_t event) { /* T21 */ - return sm_DL_Write_req (port, IOL_DIR_PARAMA_MASTER_CMD, - IOL_MASTERCMD_MASTER_IDENT); + return sm_DL_Write_req ( + port, + IOL_DIR_PARAMA_MASTER_CMD, + IOL_MASTERCMD_MASTER_IDENT); } -static iolink_fsm_sm_event_t sm_write_mcmd_preop (iolink_port_t * port, - iolink_fsm_sm_event_t event) +static iolink_fsm_sm_event_t sm_write_mcmd_preop ( + iolink_port_t * port, + iolink_fsm_sm_event_t event) { - return sm_DL_Write_req (port, IOL_DIR_PARAMA_MASTER_CMD, - IOL_MASTERCMD_DEVICE_PREOP); + return sm_DL_Write_req ( + port, + IOL_DIR_PARAMA_MASTER_CMD, + IOL_MASTERCMD_DEVICE_PREOP); } -static iolink_fsm_sm_event_t sm_fallback (iolink_port_t * port, - iolink_fsm_sm_event_t event) +static iolink_fsm_sm_event_t sm_fallback ( + iolink_port_t * port, + iolink_fsm_sm_event_t event) { sm_DL_Write_Devicemode_req (port, IOLINK_DLMODE_INACTIVE); return SM_EVENT_NONE; } -static iolink_fsm_sm_event_t sm_portinactive (iolink_port_t * port, - iolink_fsm_sm_event_t event) +static iolink_fsm_sm_event_t sm_portinactive ( + iolink_port_t * port, + iolink_fsm_sm_event_t event) { iolink_sm_port_t * sm = iolink_get_sm_ctx (port); /* We get the first DL_Read_cnf(), after WURQ, without any DL_Read_req() */ - sm->dl_addr = IOL_DIR_PARAMA_DUMMY_WURQ; + sm->dl_addr = IOL_DIR_PARAMA_DUMMY_WURQ; sm->error_event = SM_EVENT_NONE; switch (event) @@ -477,8 +535,9 @@ static iolink_fsm_sm_event_t sm_portinactive (iolink_port_t * port, return SM_EVENT_NONE; } -static iolink_fsm_sm_event_t sm_comlost (iolink_port_t * port, - iolink_fsm_sm_event_t event) +static iolink_fsm_sm_event_t sm_comlost ( + iolink_port_t * port, + iolink_fsm_sm_event_t event) { sm_DL_SetMode_req_inactive (port); SM_PortMode_ind (port, IOLINK_SM_PORTMODE_COMLOST); @@ -486,8 +545,9 @@ static iolink_fsm_sm_event_t sm_comlost (iolink_port_t * port, return SM_EVENT_NONE; } -static iolink_fsm_sm_event_t sm_smoperate_ignore (iolink_port_t * port, - iolink_fsm_sm_event_t event) +static iolink_fsm_sm_event_t sm_smoperate_ignore ( + iolink_port_t * port, + iolink_fsm_sm_event_t event) { /* It is possible to receive SM_Operate after a COMLOST, when DS is disabled. * Hence, we ignore this SM_Operate. @@ -497,33 +557,39 @@ static iolink_fsm_sm_event_t sm_smoperate_ignore (iolink_port_t * port, return SM_EVENT_NONE; } - -static iolink_fsm_sm_event_t sm_comlost_ignore (iolink_port_t * port, - iolink_fsm_sm_event_t event) +static iolink_fsm_sm_event_t sm_comlost_ignore ( + iolink_port_t * port, + iolink_fsm_sm_event_t event) { /* If we receive COMLOST when we are waiting for DL_{Read,Write}_cnf() or * AL_{Read,Write}_cnf() or DL_Write_Devicemode_cnf(), we will first receive * COMLOST via DL_Mode_ind(). * Hence, we ignore this COMLOST. */ - LOG_DEBUG (IOLINK_SM_LOG, - "SM ignore COMLOST wait for AL_{Read,Write}_cnf() or DL_Write_Devicemode_cnf()\n"); + LOG_DEBUG ( + IOLINK_SM_LOG, + "SM ignore COMLOST wait for AL_{Read,Write}_cnf() or " + "DL_Write_Devicemode_cnf()\n"); return SM_EVENT_NONE; } -static iolink_fsm_sm_event_t sm_waitonDLOp (iolink_port_t * port, - iolink_fsm_sm_event_t event) +static iolink_fsm_sm_event_t sm_waitonDLOp ( + iolink_port_t * port, + iolink_fsm_sm_event_t event) { - iolink_sm_port_t * sm = iolink_get_sm_ctx (port); + iolink_sm_port_t * sm = iolink_get_sm_ctx (port); iolink_smp_parameterlist_t * real_paramlist = &sm->real_paramlist; - return sm_DL_Write_req (port, IOL_DIR_PARAMA_MASTER_CYCL, - real_paramlist->cycletime); + return sm_DL_Write_req ( + port, + IOL_DIR_PARAMA_MASTER_CYCL, + real_paramlist->cycletime); } -static iolink_fsm_sm_event_t sm_inspectFault (iolink_port_t * port, - iolink_fsm_sm_event_t event) +static iolink_fsm_sm_event_t sm_inspectFault ( + iolink_port_t * port, + iolink_fsm_sm_event_t event) { switch (event) { @@ -557,47 +623,58 @@ static iolink_fsm_sm_event_t sm_inspectFault (iolink_port_t * port, return SM_EVENT_NONE; } -static void sm_AL_Read_cnf (iolink_port_t * port, uint8_t len, - const uint8_t * data, - iolink_smi_errortypes_t errortype) +static void sm_AL_Read_cnf ( + iolink_port_t * port, + uint8_t len, + const uint8_t * data, + iolink_smi_errortypes_t errortype) { - iolink_job_t * job = iolink_fetch_avail_job (port); - job->al_read_cnf.data = data; - job->al_read_cnf.data_len = len; + iolink_job_t * job = iolink_fetch_avail_job (port); + job->al_read_cnf.data = data; + job->al_read_cnf.data_len = len; job->al_read_cnf.errortype = errortype; - iolink_post_job_with_type_and_callback (port, job, IOLINK_JOB_AL_READ_CNF, sm_AL_Read_cnf_cb); + iolink_post_job_with_type_and_callback ( + port, + job, + IOLINK_JOB_AL_READ_CNF, + sm_AL_Read_cnf_cb); } -static iolink_fsm_sm_event_t sm_checkSerNum (iolink_port_t * port, - iolink_fsm_sm_event_t event) +static iolink_fsm_sm_event_t sm_checkSerNum ( + iolink_port_t * port, + iolink_fsm_sm_event_t event) { AL_Read_req (port, IOL_DEV_PARAMA_SERIAL_NUMBER, 0, sm_AL_Read_cnf); return SM_EVENT_NONE; } -static iolink_fsm_sm_event_t sm_wait (iolink_port_t * port, - iolink_fsm_sm_event_t event) +static iolink_fsm_sm_event_t sm_wait ( + iolink_port_t * port, + iolink_fsm_sm_event_t event) { SM_PortMode_ind (port, IOLINK_SM_PORTMODE_COMREADY); return SM_EVENT_NONE; } -static iolink_fsm_sm_event_t sm_write_devmode (iolink_port_t * port, - iolink_fsm_sm_event_t event) +static iolink_fsm_sm_event_t sm_write_devmode ( + iolink_port_t * port, + iolink_fsm_sm_event_t event) { sm_DL_Write_Devicemode_req (port, IOLINK_DLMODE_OPERATE); return SM_EVENT_NONE; } -static iolink_fsm_sm_event_t sm_smoperate_ind (iolink_port_t * port, - iolink_fsm_sm_event_t event) +static iolink_fsm_sm_event_t sm_smoperate_ind ( + iolink_port_t * port, + iolink_fsm_sm_event_t event) { - if ((event == SM_EVENT_DL_Mode_OPERATE) || /* T13 */ - (event == SM_EVENT_SM_Operate_v10)) /* v1.0 is already in operate */ + if ( + (event == SM_EVENT_DL_Mode_OPERATE) || /* T13 */ + (event == SM_EVENT_SM_Operate_v10)) /* v1.0 is already in operate */ { SM_PortMode_ind (port, IOLINK_SM_PORTMODE_OPERATE); } @@ -605,29 +682,31 @@ static iolink_fsm_sm_event_t sm_smoperate_ind (iolink_port_t * port, return SM_EVENT_NONE; } -static iolink_fsm_sm_event_t sm_dido (iolink_port_t * port, - iolink_fsm_sm_event_t event) +static iolink_fsm_sm_event_t sm_dido ( + iolink_port_t * port, + iolink_fsm_sm_event_t event) { - iolink_sm_port_t * sm = iolink_get_sm_ctx (port); + iolink_sm_port_t * sm = iolink_get_sm_ctx (port); iolink_smp_parameterlist_t * parameterlist = &sm->config_paramlist; - iolink_pl_mode_t target_pl_mode = iolink_mode_INACTIVE; - iolink_sm_portmode_t target_sm_mode = IOLINK_SM_PORTMODE_INACTIVE; + iolink_pl_mode_t target_pl_mode = iolink_mode_INACTIVE; + iolink_sm_portmode_t target_sm_mode = IOLINK_SM_PORTMODE_INACTIVE; if (parameterlist->mode == IOLINK_SMTARGET_MODE_DI) { - target_pl_mode = iolink_mode_DI; - target_sm_mode = IOLINK_SM_PORTMODE_DI; + target_pl_mode = iolink_mode_DI; + target_sm_mode = IOLINK_SM_PORTMODE_DI; } else if (parameterlist->mode == IOLINK_SMTARGET_MODE_DO) { - target_pl_mode = iolink_mode_DO; - target_sm_mode = IOLINK_SM_PORTMODE_DO; + target_pl_mode = iolink_mode_DO; + target_sm_mode = IOLINK_SM_PORTMODE_DO; } else { - LOG_ERROR (IOLINK_SM_LOG, - "SM: dido, invalid iolink_sm_target_mode_t (%u)\n", - parameterlist->mode); + LOG_ERROR ( + IOLINK_SM_LOG, + "SM: dido, invalid iolink_sm_target_mode_t (%u)\n", + parameterlist->mode); } PL_SetMode_req (port, target_pl_mode); @@ -640,7 +719,7 @@ static iolink_fsm_sm_event_t sm_dido (iolink_port_t * port, static inline void sm_DL_Read_cnf_read_com_param (iolink_job_t * job) { iolink_port_t * port = job->port; - uint8_t addr = job->dl_rw_cnf.addr; + uint8_t addr = job->dl_rw_cnf.addr; if (addr != IOL_DIR_PARAMA_PDO) { @@ -648,17 +727,22 @@ static inline void sm_DL_Read_cnf_read_com_param (iolink_job_t * job) } else { - iolink_sm_port_t * sm = iolink_get_sm_ctx (port); + iolink_sm_port_t * sm = iolink_get_sm_ctx (port); iolink_smp_parameterlist_t * real_paramlist = &sm->real_paramlist; - iolink_sm_event (port, - (real_paramlist->revisionid == IOL_DIR_PARAM_REV_V10) ? SM_EVENT_V10 : SM_EVENT_NOT_V10 ); + iolink_sm_event ( + port, + (real_paramlist->revisionid == IOL_DIR_PARAM_REV_V10) + ? SM_EVENT_V10 + : SM_EVENT_NOT_V10); } } -static inline void sm_DL_Read_cnf_check_comp (iolink_job_t * job, iolink_sm_state_t state) +static inline void sm_DL_Read_cnf_check_comp ( + iolink_job_t * job, + iolink_sm_state_t state) { iolink_port_t * port = job->port; - uint8_t addr = job->dl_rw_cnf.addr; + uint8_t addr = job->dl_rw_cnf.addr; if (addr != IOL_DIR_PARAMA_FID_2) { @@ -676,13 +760,14 @@ static inline void sm_DL_Read_cnf_check_comp (iolink_job_t * job, iolink_sm_stat static inline void sm_DL_Write_cnf_checkvxy (iolink_job_t * job) { - iolink_port_t * port = job->port; - iolink_sm_port_t * sm = iolink_get_sm_ctx (port); + iolink_port_t * port = job->port; + iolink_sm_port_t * sm = iolink_get_sm_ctx (port); iolink_smp_parameterlist_t * config_paramlist = &sm->config_paramlist; - iolink_smp_parameterlist_t * real_paramlist = &sm->real_paramlist; + iolink_smp_parameterlist_t * real_paramlist = &sm->real_paramlist; - if ((config_paramlist->revisionid == 0) || - (config_paramlist->revisionid == real_paramlist->revisionid)) + if ( + (config_paramlist->revisionid == 0) || + (config_paramlist->revisionid == real_paramlist->revisionid)) { iolink_sm_event (port, SM_EVENT_REVISION_OK); /* T22 */ } @@ -699,8 +784,8 @@ static inline void sm_DL_Write_cnf_checkvxy (iolink_job_t * job) static inline void sm_DL_Write_cnf_restart_dev (iolink_job_t * job) { - iolink_port_t * port = job->port; - iolink_sm_port_t * sm = iolink_get_sm_ctx (port); + iolink_port_t * port = job->port; + iolink_sm_port_t * sm = iolink_get_sm_ctx (port); iolink_smp_parameterlist_t * config_paramlist = &sm->config_paramlist; switch (job->dl_rw_cnf.addr) @@ -709,18 +794,25 @@ static inline void sm_DL_Write_cnf_restart_dev (iolink_job_t * job) { if (config_paramlist->mode == IOLINK_SMTARGET_MODE_CFGCOM) { - sm_DL_Write_req (port, IOL_DIR_PARAMA_DID_1, - config_paramlist->deviceid >> 16); + sm_DL_Write_req ( + port, + IOL_DIR_PARAMA_DID_1, + config_paramlist->deviceid >> 16); } else if (config_paramlist->mode == IOLINK_SMTARGET_MODE_AUTOCOM) { - sm_DL_Write_req (port, IOL_DIR_PARAMA_MASTER_CMD, - IOL_MASTERCMD_DEVICE_IDENT); + sm_DL_Write_req ( + port, + IOL_DIR_PARAMA_MASTER_CMD, + IOL_MASTERCMD_DEVICE_IDENT); } else { - LOG_ERROR (IOLINK_SM_LOG, - "SM: %s, unexpected mode (%u)\n", __func__, config_paramlist->mode); + LOG_ERROR ( + IOLINK_SM_LOG, + "SM: %s, unexpected mode (%u)\n", + __func__, + config_paramlist->mode); CC_ASSERT (0); /* Invalid mode */ } break; @@ -745,11 +837,14 @@ static inline void sm_DL_Write_cnf_restart_dev (iolink_job_t * job) static inline void sm_DL_Write_cnf_waiton_operate (iolink_job_t * job) { iolink_port_t * port = job->port; - uint8_t addr = job->dl_rw_cnf.addr; + uint8_t addr = job->dl_rw_cnf.addr; if (addr == IOL_DIR_PARAMA_MASTER_CYCL) { - sm_DL_Write_req (port, IOL_DIR_PARAMA_MASTER_CMD, IOL_MASTERCMD_DEVICE_OPERATE); + sm_DL_Write_req ( + port, + IOL_DIR_PARAMA_MASTER_CMD, + IOL_MASTERCMD_DEVICE_OPERATE); } else if (addr == IOL_DIR_PARAMA_MASTER_CMD) { @@ -757,28 +852,32 @@ static inline void sm_DL_Write_cnf_waiton_operate (iolink_job_t * job) } else { - LOG_WARNING (IOLINK_SM_LOG, "%s: Unexpected DL_Write_cnf(), %u\n", - __func__, addr); + LOG_WARNING ( + IOLINK_SM_LOG, + "%s: Unexpected DL_Write_cnf(), %u\n", + __func__, + addr); } } static void sm_check_sernum (iolink_port_t * port, bool SReadOk) { - iolink_sm_port_t * sm = iolink_get_sm_ctx (port); + iolink_sm_port_t * sm = iolink_get_sm_ctx (port); iolink_smp_parameterlist_t * config_paramlist = &sm->config_paramlist; - iolink_smp_parameterlist_t * real_paramlist = &sm->real_paramlist; - iolink_fsm_sm_event_t ret = SM_EVENT_NONE; + iolink_smp_parameterlist_t * real_paramlist = &sm->real_paramlist; + iolink_fsm_sm_event_t ret = SM_EVENT_NONE; if (config_paramlist->inspectionlevel != IOLINK_INSPECTIONLEVEL_IDENTICAL) { ret = SM_EVENT_SerNumOK; /* T10 */ } - else if (!SReadOk || - memcmp (config_paramlist->serialnumber, - real_paramlist->serialnumber, - sizeof(config_paramlist->serialnumber))) + else if ( + !SReadOk || memcmp ( + config_paramlist->serialnumber, + real_paramlist->serialnumber, + sizeof (config_paramlist->serialnumber))) { - ret = SM_EVENT_SerNumFault; /* T11 */ + ret = SM_EVENT_SerNumFault; /* T11 */ sm->error_event = ret; } else @@ -790,237 +889,265 @@ static void sm_check_sernum (iolink_port_t * port, bool SReadOk) } /* SM state transitions, IO-Link Interface Spec v1.1.3 Chapter 9.2.3.2 */ -/* since we iterate through the list on events put the most likely in the top of the list. */ -static const iolink_fsm_sm_transition_t sm_trans_s0[] = -{ +/* since we iterate through the list on events put the most likely in the top of + * the list. */ +static const iolink_fsm_sm_transition_t sm_trans_s0[] = { /* PortInactive_0 */ - { SM_EVENT_DL_Mode_STARTUP, SM_STATE_ReadComParameter, sm_readcomparameter }, /* T1 */ - { SM_EVENT_SM_SetPortConfig_INACTIVE, SM_STATE_PortInactive, sm_portinactive }, /* T14 */ - { SM_EVENT_SM_SetPortConfig_CFGCOM_or_AUTOCOM, SM_STATE_PortInactive, sm_portinactive }, /* T15 */ - { SM_EVENT_SM_SetPortConfig_DI_or_DO, SM_STATE_DIDO, sm_dido }, /* T16 */ - - { SM_EVENT_SM_Operate, SM_STATE_PortInactive, sm_smoperate_ignore }, /* Not in spec */ - { SM_EVENT_DL_Mode_COMLOST, SM_STATE_PortInactive, sm_comlost_ignore }, /* Not in spec */ + {SM_EVENT_DL_Mode_STARTUP, SM_STATE_ReadComParameter, sm_readcomparameter}, /* T1 */ + {SM_EVENT_SM_SetPortConfig_INACTIVE, + SM_STATE_PortInactive, + sm_portinactive}, /* T14 */ + {SM_EVENT_SM_SetPortConfig_CFGCOM_or_AUTOCOM, + SM_STATE_PortInactive, + sm_portinactive}, /* T15 */ + {SM_EVENT_SM_SetPortConfig_DI_or_DO, SM_STATE_DIDO, sm_dido}, /* T16 */ + + {SM_EVENT_SM_Operate, SM_STATE_PortInactive, sm_smoperate_ignore}, /* Not in + spec */ + {SM_EVENT_DL_Mode_COMLOST, SM_STATE_PortInactive, sm_comlost_ignore}, /* Not + in + spec + */ }; -static const iolink_fsm_sm_transition_t sm_trans_s1[] = -{ +static const iolink_fsm_sm_transition_t sm_trans_s1[] = { /* waitonDLPreoperate_2 */ - { SM_EVENT_DL_Mode_PREOPERATE, SM_STATE_checkSerNum, sm_checkSerNum }, /* T8 */ - { SM_EVENT_CNF_COMLOST, SM_STATE_PortInactive, sm_comlost }, /* T3 */ + {SM_EVENT_DL_Mode_PREOPERATE, SM_STATE_checkSerNum, sm_checkSerNum}, /* T8 */ + {SM_EVENT_CNF_COMLOST, SM_STATE_PortInactive, sm_comlost}, /* T3 */ - { SM_EVENT_DL_Mode_COMLOST, SM_STATE_waitonDLPreoperate, sm_comlost_ignore }, /* Not in spec */ + {SM_EVENT_DL_Mode_COMLOST, + SM_STATE_waitonDLPreoperate, + sm_comlost_ignore}, /* Not in spec */ }; -static const iolink_fsm_sm_transition_t sm_trans_s2[] = -{ +static const iolink_fsm_sm_transition_t sm_trans_s2[] = { /* checkSerNum_3 */ - { SM_EVENT_SerNumOK, SM_STATE_wait, sm_wait }, /* T10 */ - { SM_EVENT_SerNumFault, SM_STATE_InspectionFault, sm_inspectFault }, /* T11 */ - { SM_EVENT_CNF_COMLOST, SM_STATE_PortInactive, sm_comlost }, /* T3 */ - - { SM_EVENT_SM_SetPortConfig_CFGCOM_or_AUTOCOM, SM_STATE_PortInactive, sm_portinactive }, /* SDCI_TC_0167 */ - { SM_EVENT_DL_Mode_COMLOST, SM_STATE_checkSerNum, sm_comlost_ignore }, /* Not in spec */ - { SM_EVENT_SM_SetPortConfig_INACTIVE, SM_STATE_waitForFallback, sm_fallback }, /* Not in spec */ + {SM_EVENT_SerNumOK, SM_STATE_wait, sm_wait}, /* T10 */ + {SM_EVENT_SerNumFault, SM_STATE_InspectionFault, sm_inspectFault}, /* T11 */ + {SM_EVENT_CNF_COMLOST, SM_STATE_PortInactive, sm_comlost}, /* T3 */ + + {SM_EVENT_SM_SetPortConfig_CFGCOM_or_AUTOCOM, + SM_STATE_PortInactive, + sm_portinactive}, /* SDCI_TC_0167 */ + {SM_EVENT_DL_Mode_COMLOST, SM_STATE_checkSerNum, sm_comlost_ignore}, /* Not + in + spec + */ + {SM_EVENT_SM_SetPortConfig_INACTIVE, + SM_STATE_waitForFallback, + sm_fallback}, /* Not in spec */ }; -static const iolink_fsm_sm_transition_t sm_trans_s3[] = -{ +static const iolink_fsm_sm_transition_t sm_trans_s3[] = { /* wait_4 */ - { SM_EVENT_SM_SetPortConfig_CFGCOM_or_AUTOCOM, SM_STATE_PortInactive, sm_portinactive }, /* T15 */ - { SM_EVENT_SM_SetPortConfig_DI_or_DO, SM_STATE_DIDO, sm_dido }, /* T16 */ - { SM_EVENT_SM_Operate_v10, SM_STATE_SMOperate, sm_smoperate_ind }, /* T12 for v1.0 */ - { SM_EVENT_DL_Mode_COMLOST, SM_STATE_PortInactive, sm_comlost }, /* T3 */ - - { SM_EVENT_WRITE_MASTER_CYCL_REQ, SM_STATE_write_master_cycl, sm_wr_master_cycl }, /* Not in spec */ - { SM_EVENT_SM_SetPortConfig_INACTIVE, SM_STATE_waitForFallback, sm_fallback }, /* Not in spec */ + {SM_EVENT_SM_SetPortConfig_CFGCOM_or_AUTOCOM, + SM_STATE_PortInactive, + sm_portinactive}, /* T15 */ + {SM_EVENT_SM_SetPortConfig_DI_or_DO, SM_STATE_DIDO, sm_dido}, /* T16 */ + {SM_EVENT_SM_Operate_v10, SM_STATE_SMOperate, sm_smoperate_ind}, /* T12 for + v1.0 */ + {SM_EVENT_DL_Mode_COMLOST, SM_STATE_PortInactive, sm_comlost}, /* T3 */ + + {SM_EVENT_WRITE_MASTER_CYCL_REQ, + SM_STATE_write_master_cycl, + sm_wr_master_cycl}, /* Not in spec */ + {SM_EVENT_SM_SetPortConfig_INACTIVE, + SM_STATE_waitForFallback, + sm_fallback}, /* Not in spec */ }; -static const iolink_fsm_sm_transition_t sm_trans_s4[] = -{ +static const iolink_fsm_sm_transition_t sm_trans_s4[] = { /* SMOperate_5 */ - { SM_EVENT_DL_Mode_COMLOST, SM_STATE_PortInactive, sm_comlost }, /* T3 */ - { SM_EVENT_DL_Mode_OPERATE, SM_STATE_SMOperate, sm_smoperate_ind }, /* T13 */ - { SM_EVENT_SM_SetPortConfig_INACTIVE, SM_STATE_waitForFallback, sm_fallback }, /* Not in spec */ - { SM_EVENT_SM_SetPortConfig_CFGCOM_or_AUTOCOM, SM_STATE_PortInactive, sm_portinactive }, /* T15 */ - { SM_EVENT_SM_SetPortConfig_DI_or_DO, SM_STATE_DIDO, sm_dido }, /* T16 */ + {SM_EVENT_DL_Mode_COMLOST, SM_STATE_PortInactive, sm_comlost}, /* T3 */ + {SM_EVENT_DL_Mode_OPERATE, SM_STATE_SMOperate, sm_smoperate_ind}, /* T13 */ + {SM_EVENT_SM_SetPortConfig_INACTIVE, + SM_STATE_waitForFallback, + sm_fallback}, /* Not in spec */ + {SM_EVENT_SM_SetPortConfig_CFGCOM_or_AUTOCOM, + SM_STATE_PortInactive, + sm_portinactive}, /* T15 */ + {SM_EVENT_SM_SetPortConfig_DI_or_DO, SM_STATE_DIDO, sm_dido}, /* T16 */ }; -static const iolink_fsm_sm_transition_t sm_trans_s5[] = -{ +static const iolink_fsm_sm_transition_t sm_trans_s5[] = { /* InspectionFault_6 */ - { SM_EVENT_RevisionFault, SM_STATE_InspectionFault, sm_inspectFault }, /* T6 */ - { SM_EVENT_CompFault, SM_STATE_InspectionFault, sm_inspectFault }, /* T7 */ - { SM_EVENT_CycTimeFault, SM_STATE_InspectionFault, sm_inspectFault }, /* T17 */ - - { SM_EVENT_SM_SetPortConfig_INACTIVE, SM_STATE_waitForFallback, sm_fallback }, /* Not in spec */ - { SM_EVENT_SM_SetPortConfig_CFGCOM_or_AUTOCOM, SM_STATE_PortInactive, sm_portinactive }, /* T15 */ - { SM_EVENT_SM_SetPortConfig_DI_or_DO, SM_STATE_DIDO, sm_dido }, /* T16 */ - { SM_EVENT_DL_Mode_COMLOST, SM_STATE_PortInactive, sm_comlost }, /* T3 */ + {SM_EVENT_RevisionFault, SM_STATE_InspectionFault, sm_inspectFault}, /* T6 */ + {SM_EVENT_CompFault, SM_STATE_InspectionFault, sm_inspectFault}, /* T7 */ + {SM_EVENT_CycTimeFault, SM_STATE_InspectionFault, sm_inspectFault}, /* T17 */ + + {SM_EVENT_SM_SetPortConfig_INACTIVE, + SM_STATE_waitForFallback, + sm_fallback}, /* Not in spec */ + {SM_EVENT_SM_SetPortConfig_CFGCOM_or_AUTOCOM, + SM_STATE_PortInactive, + sm_portinactive}, /* T15 */ + {SM_EVENT_SM_SetPortConfig_DI_or_DO, SM_STATE_DIDO, sm_dido}, /* T16 */ + {SM_EVENT_DL_Mode_COMLOST, SM_STATE_PortInactive, sm_comlost}, /* T3 */ }; -static const iolink_fsm_sm_transition_t sm_trans_s6[] = -{ +static const iolink_fsm_sm_transition_t sm_trans_s6[] = { /* waitonDLOperate_7 */ - { SM_EVENT_DL_Mode_OPERATE, SM_STATE_checkSerNum, sm_checkSerNum }, /* T9 */ - { SM_EVENT_CNF_COMLOST, SM_STATE_PortInactive, sm_comlost }, /* T3 */ - { SM_EVENT_DL_Mode_COMLOST, SM_STATE_PortInactive, sm_comlost }, /* T3 */ + {SM_EVENT_DL_Mode_OPERATE, SM_STATE_checkSerNum, sm_checkSerNum}, /* T9 */ + {SM_EVENT_CNF_COMLOST, SM_STATE_PortInactive, sm_comlost}, /* T3 */ + {SM_EVENT_DL_Mode_COMLOST, SM_STATE_PortInactive, sm_comlost}, /* T3 */ }; -static const iolink_fsm_sm_transition_t sm_trans_s7[] = -{ +static const iolink_fsm_sm_transition_t sm_trans_s7[] = { /* DIDO_8 */ - { SM_EVENT_SM_SetPortConfig_INACTIVE, SM_STATE_PortInactive, sm_portinactive }, /* T14 */ - { SM_EVENT_SM_SetPortConfig_CFGCOM_or_AUTOCOM, SM_STATE_PortInactive, sm_portinactive }, /* T15 */ - { SM_EVENT_SM_SetPortConfig_DI_or_DO, SM_STATE_DIDO, sm_dido }, /* T16 */ + {SM_EVENT_SM_SetPortConfig_INACTIVE, + SM_STATE_PortInactive, + sm_portinactive}, /* T14 */ + {SM_EVENT_SM_SetPortConfig_CFGCOM_or_AUTOCOM, + SM_STATE_PortInactive, + sm_portinactive}, /* T15 */ + {SM_EVENT_SM_SetPortConfig_DI_or_DO, SM_STATE_DIDO, sm_dido}, /* T16 */ }; -static const iolink_fsm_sm_transition_t sm_trans_s8[] = -{ +static const iolink_fsm_sm_transition_t sm_trans_s8[] = { /* CheckCompatibility_1 ReadComParameter_20 */ - { SM_EVENT_NOT_V10, SM_STATE_CheckVxy, sm_checkVxy }, /* T21 */ - { SM_EVENT_V10, SM_STATE_CheckCompV10, sm_checkCompV10_21 }, /* T20 */ - { SM_EVENT_CNF_COMLOST, SM_STATE_PortInactive, sm_comlost }, /* T3 */ - - { SM_EVENT_DL_Mode_COMLOST, SM_STATE_ReadComParameter, sm_comlost_ignore }, /* Not in spec */ - { SM_EVENT_SM_SetPortConfig_CFGCOM_or_AUTOCOM, SM_STATE_PortInactive, sm_portinactive }, /* Not in spec */ + {SM_EVENT_NOT_V10, SM_STATE_CheckVxy, sm_checkVxy}, /* T21 */ + {SM_EVENT_V10, SM_STATE_CheckCompV10, sm_checkCompV10_21}, /* T20 */ + {SM_EVENT_CNF_COMLOST, SM_STATE_PortInactive, sm_comlost}, /* T3 */ + + {SM_EVENT_DL_Mode_COMLOST, + SM_STATE_ReadComParameter, + sm_comlost_ignore}, /* Not in spec */ + {SM_EVENT_SM_SetPortConfig_CFGCOM_or_AUTOCOM, + SM_STATE_PortInactive, + sm_portinactive}, /* Not in spec */ }; -static const iolink_fsm_sm_transition_t sm_trans_s9[] = -{ +static const iolink_fsm_sm_transition_t sm_trans_s9[] = { /* CheckCompatibility_1 CheckCompV10_21 */ - { SM_EVENT_V10CompOK, SM_STATE_waitonDLOperate, sm_waitonDLOp }, /* T4 */ - { SM_EVENT_V10CompFault, SM_STATE_InspectionFault, sm_inspectFault }, /* T5 */ - { SM_EVENT_CycTimeFault_V10, SM_STATE_InspectionFault, sm_inspectFault }, /* T18 */ - { SM_EVENT_CNF_COMLOST, SM_STATE_PortInactive, sm_comlost }, /* T3 */ - - { SM_EVENT_DL_Mode_COMLOST, SM_STATE_CheckCompV10, sm_comlost_ignore }, /* Not in spec */ + {SM_EVENT_V10CompOK, SM_STATE_waitonDLOperate, sm_waitonDLOp}, /* T4 */ + {SM_EVENT_V10CompFault, SM_STATE_InspectionFault, sm_inspectFault}, /* T5 */ + {SM_EVENT_CycTimeFault_V10, SM_STATE_InspectionFault, sm_inspectFault}, /* T18 + */ + {SM_EVENT_CNF_COMLOST, SM_STATE_PortInactive, sm_comlost}, /* T3 */ + + {SM_EVENT_DL_Mode_COMLOST, SM_STATE_CheckCompV10, sm_comlost_ignore}, /* Not + in + spec + */ }; -static const iolink_fsm_sm_transition_t sm_trans_s10[] = -{ +static const iolink_fsm_sm_transition_t sm_trans_s10[] = { /* CheckCompatibility_1 CheckVxy_22 */ - { SM_EVENT_REVISION_OK, SM_STATE_CheckComp, sm_checkComp }, /* T22 */ - { SM_EVENT_RETRY_STARTUP, SM_STATE_RestartDevice, sm_restartDevice }, /* T25 */ - { SM_EVENT_RevisionFault, SM_STATE_InspectionFault, sm_write_mcmd_preop }, /* T6 */ - { SM_EVENT_CNF_COMLOST, SM_STATE_PortInactive, sm_comlost }, /* T3 */ - - { SM_EVENT_DL_Mode_COMLOST, SM_STATE_CheckVxy, sm_comlost_ignore }, /* Not in spec */ + {SM_EVENT_REVISION_OK, SM_STATE_CheckComp, sm_checkComp}, /* T22 */ + {SM_EVENT_RETRY_STARTUP, SM_STATE_RestartDevice, sm_restartDevice}, /* T25 */ + {SM_EVENT_RevisionFault, SM_STATE_InspectionFault, sm_write_mcmd_preop}, /* T6 + */ + {SM_EVENT_CNF_COMLOST, SM_STATE_PortInactive, sm_comlost}, /* T3 */ + + {SM_EVENT_DL_Mode_COMLOST, SM_STATE_CheckVxy, sm_comlost_ignore}, /* Not in + spec */ }; -static const iolink_fsm_sm_transition_t sm_trans_s11[] = -{ +static const iolink_fsm_sm_transition_t sm_trans_s11[] = { /* CheckCompatibility_1 CheckComp_23 */ - { SM_EVENT_CompOK, SM_STATE_waitonDLPreoperate, sm_write_mcmd_preop }, /* T2 */ - { SM_EVENT_RETRY_STARTUP, SM_STATE_RestartDevice, sm_restartDevice }, /* T23 */ - { SM_EVENT_CompFault, SM_STATE_InspectionFault, sm_write_mcmd_preop }, /* T7 */ - { SM_EVENT_CycTimeFault, SM_STATE_InspectionFault, sm_write_mcmd_preop }, /* T17 */ - { SM_EVENT_CNF_COMLOST, SM_STATE_PortInactive, sm_comlost }, /* T3 */ - - { SM_EVENT_DL_Mode_COMLOST, SM_STATE_CheckComp, sm_comlost_ignore }, /* Not in spec */ + {SM_EVENT_CompOK, SM_STATE_waitonDLPreoperate, sm_write_mcmd_preop}, /* T2 */ + {SM_EVENT_RETRY_STARTUP, SM_STATE_RestartDevice, sm_restartDevice}, /* T23 */ + {SM_EVENT_CompFault, SM_STATE_InspectionFault, sm_write_mcmd_preop}, /* T7 */ + {SM_EVENT_CycTimeFault, SM_STATE_InspectionFault, sm_write_mcmd_preop}, /* T17 + */ + {SM_EVENT_CNF_COMLOST, SM_STATE_PortInactive, sm_comlost}, /* T3 */ + + {SM_EVENT_DL_Mode_COMLOST, SM_STATE_CheckComp, sm_comlost_ignore}, /* Not in + spec */ }; -static const iolink_fsm_sm_transition_t sm_trans_s12[] = -{ +static const iolink_fsm_sm_transition_t sm_trans_s12[] = { /* CheckCompatibility_1 RestartDevice_24 */ - { SM_EVENT_WriteDone, SM_STATE_ReadComParameter, sm_readcomparameter }, /* T24 */ - { SM_EVENT_CNF_COMLOST, SM_STATE_RestartDevice, sm_comlost }, /* T3 */ + {SM_EVENT_WriteDone, SM_STATE_ReadComParameter, sm_readcomparameter}, /* T24 + */ + {SM_EVENT_CNF_COMLOST, SM_STATE_RestartDevice, sm_comlost}, /* T3 */ - { SM_EVENT_DL_Mode_COMLOST, SM_STATE_CheckComp, sm_comlost_ignore }, /* Not in spec */ + {SM_EVENT_DL_Mode_COMLOST, SM_STATE_CheckComp, sm_comlost_ignore}, /* Not in + spec */ }; -static const iolink_fsm_sm_transition_t sm_trans_s13[] = -{ +static const iolink_fsm_sm_transition_t sm_trans_s13[] = { /* WaitForFallback not in spec */ - { SM_EVENT_SM_SetPortConfig_INACTIVE, SM_STATE_PortInactive, sm_portinactive }, /* T14 */ - { SM_EVENT_DL_Mode_COMLOST, SM_STATE_PortInactive, sm_comlost }, /* T3 */ + {SM_EVENT_SM_SetPortConfig_INACTIVE, + SM_STATE_PortInactive, + sm_portinactive}, /* T14 */ + {SM_EVENT_DL_Mode_COMLOST, SM_STATE_PortInactive, sm_comlost}, /* T3 */ }; -static const iolink_fsm_sm_transition_t sm_trans_s14[] = -{ - /* SM_STATE_write_master_cycl Write master cycle time and wait for the cnf, not in spec */ - { SM_EVENT_CNF_COMLOST, SM_STATE_PortInactive, sm_comlost }, /* T3 */ - - { SM_EVENT_WRITE_MASTER_CYCL_DONE, SM_STATE_wait_devmode_cnf, sm_write_devmode }, /* Not in spec */ - { SM_EVENT_DL_Mode_COMLOST, SM_STATE_write_master_cycl, sm_comlost_ignore }, /* Not in spec */ +static const iolink_fsm_sm_transition_t sm_trans_s14[] = { + /* SM_STATE_write_master_cycl Write master cycle time and wait for the cnf, + not in spec */ + {SM_EVENT_CNF_COMLOST, SM_STATE_PortInactive, sm_comlost}, /* T3 */ + + {SM_EVENT_WRITE_MASTER_CYCL_DONE, + SM_STATE_wait_devmode_cnf, + sm_write_devmode}, /* Not in spec */ + {SM_EVENT_DL_Mode_COMLOST, + SM_STATE_write_master_cycl, + sm_comlost_ignore}, /* Not in spec */ }; -static const iolink_fsm_sm_transition_t sm_trans_s15[] = -{ - /* SM_STATE_wait_devmode_cnf Write master devicemode operate and wait for the cnf, not in spec */ - { SM_EVENT_SM_Operate, SM_STATE_SMOperate, sm_smoperate_ind }, /* T12 */ - { SM_EVENT_CNF_COMLOST, SM_STATE_PortInactive, sm_comlost }, /* T3 */ +static const iolink_fsm_sm_transition_t sm_trans_s15[] = { + /* SM_STATE_wait_devmode_cnf Write master devicemode operate and wait for the + cnf, not in spec */ + {SM_EVENT_SM_Operate, SM_STATE_SMOperate, sm_smoperate_ind}, /* T12 */ + {SM_EVENT_CNF_COMLOST, SM_STATE_PortInactive, sm_comlost}, /* T3 */ - { SM_EVENT_DL_Mode_COMLOST, SM_STATE_wait_devmode_cnf, sm_comlost_ignore }, /* Not in spec */ + {SM_EVENT_DL_Mode_COMLOST, + SM_STATE_wait_devmode_cnf, + sm_comlost_ignore}, /* Not in spec */ }; /* The index is the state in this array */ -static const iolink_fsm_sm_state_transitions_t iolink_sm_fsm[] = -{ - { /* PortInactive_0 */ - .number_of_trans = NELEMENTS (sm_trans_s0), - .transitions = sm_trans_s0 - }, - { /* waitonDLPreoperate_2 */ - .number_of_trans = NELEMENTS (sm_trans_s1), - .transitions = sm_trans_s1 - }, - { /* checkSerNum_3 */ - .number_of_trans = NELEMENTS (sm_trans_s2), - .transitions = sm_trans_s2 - }, - { /* wait_4 */ - .number_of_trans = NELEMENTS (sm_trans_s3), - .transitions = sm_trans_s3 - }, - { /* SMOperate_5 */ - .number_of_trans = NELEMENTS (sm_trans_s4), - .transitions = sm_trans_s4 - }, - { /* InspectionFault_6 */ - .number_of_trans = NELEMENTS (sm_trans_s5), - .transitions = sm_trans_s5 - }, - { /* waitonDLOperate_7 */ - .number_of_trans = NELEMENTS (sm_trans_s6), - .transitions = sm_trans_s6 - }, - { /* DIDO_8 */ - .number_of_trans = NELEMENTS (sm_trans_s7), - .transitions = sm_trans_s7 - }, - { /* CheckCompatibility_1 ReadComParameter_20 */ - .number_of_trans = NELEMENTS (sm_trans_s8), - .transitions = sm_trans_s8 - }, - { /* CheckCompatibility_1 CheckCompV10_21 */ - .number_of_trans = NELEMENTS (sm_trans_s9), - .transitions = sm_trans_s9 - }, - { /* CheckCompatibility_1 CheckVxy_22 */ - .number_of_trans = NELEMENTS (sm_trans_s10), - .transitions = sm_trans_s10 - }, - { /* CheckCompatibility_1 CheckComp_23 */ - .number_of_trans = NELEMENTS (sm_trans_s11), - .transitions = sm_trans_s11 - }, - { /* CheckCompatibility_1 RestartDevice_24 */ - .number_of_trans = NELEMENTS (sm_trans_s12), - .transitions = sm_trans_s12 - }, - { /* WaitForFallback not in spec */ - .number_of_trans = NELEMENTS (sm_trans_s13), - .transitions = sm_trans_s13 - }, - { /* SM_STATE_write_master_cycl not in spec */ - .number_of_trans = NELEMENTS (sm_trans_s14), - .transitions = sm_trans_s14 - }, - { /* SM_STATE_wait_devmode_cnf not in spec */ - .number_of_trans = NELEMENTS (sm_trans_s15), - .transitions = sm_trans_s15 - }, +static const iolink_fsm_sm_state_transitions_t iolink_sm_fsm[] = { + {/* PortInactive_0 */ + .number_of_trans = NELEMENTS (sm_trans_s0), + .transitions = sm_trans_s0}, + {/* waitonDLPreoperate_2 */ + .number_of_trans = NELEMENTS (sm_trans_s1), + .transitions = sm_trans_s1}, + {/* checkSerNum_3 */ + .number_of_trans = NELEMENTS (sm_trans_s2), + .transitions = sm_trans_s2}, + {/* wait_4 */ + .number_of_trans = NELEMENTS (sm_trans_s3), + .transitions = sm_trans_s3}, + {/* SMOperate_5 */ + .number_of_trans = NELEMENTS (sm_trans_s4), + .transitions = sm_trans_s4}, + {/* InspectionFault_6 */ + .number_of_trans = NELEMENTS (sm_trans_s5), + .transitions = sm_trans_s5}, + {/* waitonDLOperate_7 */ + .number_of_trans = NELEMENTS (sm_trans_s6), + .transitions = sm_trans_s6}, + {/* DIDO_8 */ + .number_of_trans = NELEMENTS (sm_trans_s7), + .transitions = sm_trans_s7}, + {/* CheckCompatibility_1 ReadComParameter_20 */ + .number_of_trans = NELEMENTS (sm_trans_s8), + .transitions = sm_trans_s8}, + {/* CheckCompatibility_1 CheckCompV10_21 */ + .number_of_trans = NELEMENTS (sm_trans_s9), + .transitions = sm_trans_s9}, + {/* CheckCompatibility_1 CheckVxy_22 */ + .number_of_trans = NELEMENTS (sm_trans_s10), + .transitions = sm_trans_s10}, + {/* CheckCompatibility_1 CheckComp_23 */ + .number_of_trans = NELEMENTS (sm_trans_s11), + .transitions = sm_trans_s11}, + {/* CheckCompatibility_1 RestartDevice_24 */ + .number_of_trans = NELEMENTS (sm_trans_s12), + .transitions = sm_trans_s12}, + {/* WaitForFallback not in spec */ + .number_of_trans = NELEMENTS (sm_trans_s13), + .transitions = sm_trans_s13}, + {/* SM_STATE_write_master_cycl not in spec */ + .number_of_trans = NELEMENTS (sm_trans_s14), + .transitions = sm_trans_s14}, + {/* SM_STATE_wait_devmode_cnf not in spec */ + .number_of_trans = NELEMENTS (sm_trans_s15), + .transitions = sm_trans_s15}, }; static void iolink_sm_event (iolink_port_t * port, iolink_fsm_sm_event_t event) @@ -1028,8 +1155,8 @@ static void iolink_sm_event (iolink_port_t * port, iolink_fsm_sm_event_t event) do { int i; - iolink_sm_port_t * sm = iolink_get_sm_ctx (port); - iolink_sm_state_t previous = sm->state; + iolink_sm_port_t * sm = iolink_get_sm_ctx (port); + iolink_sm_state_t previous = sm->state; const iolink_fsm_sm_transition_t * next_trans = NULL; for (i = 0; i < iolink_sm_fsm[previous].number_of_trans; i++) @@ -1045,35 +1172,53 @@ static void iolink_sm_event (iolink_port_t * port, iolink_fsm_sm_event_t event) } if (next_trans == NULL) { - LOG_ERROR (IOLINK_SM_LOG, "SM (%u): next_trans == NULL: SM state = %s, SM event = %s\n", - iolink_get_portnumber (port), - iolink_sm_state_literals[previous], - iolink_fsm_sm_event_literals[event]); + LOG_ERROR ( + IOLINK_SM_LOG, + "SM (%u): next_trans == NULL: SM state = %s, SM event = %s\n", + iolink_get_portnumber (port), + iolink_sm_state_literals[previous], + iolink_fsm_sm_event_literals[event]); return; } /* Transition to next state */ sm->state = next_trans->next_state; - LOG_DEBUG (IOLINK_SM_LOG, "SM (%u): event: %s, state transition: %s -> %s\n", - iolink_get_portnumber (port), iolink_fsm_sm_event_literals[event], - iolink_sm_state_literals[previous], iolink_sm_state_literals[sm->state]); + LOG_DEBUG ( + IOLINK_SM_LOG, + "SM (%u): event: %s, state transition: %s -> %s\n", + iolink_get_portnumber (port), + iolink_fsm_sm_event_literals[event], + iolink_sm_state_literals[previous], + iolink_sm_state_literals[sm->state]); event = next_trans->action (port, event); } while (event != SM_EVENT_NONE); } -static void set_type_0_or_type_1_2(uint8_t operate, uint8_t cycbyte, iolink_mode_vl_t *valuelist) +static void set_type_0_or_type_1_2 ( + uint8_t operate, + uint8_t cycbyte, + iolink_mode_vl_t * valuelist) { - CC_ASSERT((operate == 0) || (operate == 1)); + CC_ASSERT ((operate == 0) || (operate == 1)); - set_valuelist(valuelist, operate + 1, 0, 0, cycbyte, - (operate == 0) ? IOLINK_MSEQTYPE_TYPE_0 : IOLINK_MSEQTYPE_TYPE_1_2); + set_valuelist ( + valuelist, + operate + 1, + 0, + 0, + cycbyte, + (operate == 0) ? IOLINK_MSEQTYPE_TYPE_0 : IOLINK_MSEQTYPE_TYPE_1_2); } -static void set_type_2_V(bool pdin_isbytes, bool pdout_isbytes, uint8_t pdin, - uint8_t pdout, uint8_t onreqdatalengthpermessage, - iolink_mode_vl_t *valuelist) +static void set_type_2_V ( + bool pdin_isbytes, + bool pdout_isbytes, + uint8_t pdin, + uint8_t pdout, + uint8_t onreqdatalengthpermessage, + iolink_mode_vl_t * valuelist) { if ((pdin_isbytes && (pdin != 1)) || (!pdin_isbytes && (pdin < 17))) { @@ -1081,17 +1226,22 @@ static void set_type_2_V(bool pdin_isbytes, bool pdout_isbytes, uint8_t pdin, if ((pdout_isbytes && (pdout != 1)) || (!pdout_isbytes && (pdout < 17))) { - valuelist->pdoutputlength = (pdout_isbytes) ? (pdout + 1) : ((pdout + 7) >> 3); + valuelist->pdoutputlength = (pdout_isbytes) ? (pdout + 1) + : ((pdout + 7) >> 3); valuelist->onreqdatalengthpermessage = onreqdatalengthpermessage; - valuelist->type = IOLINK_MSEQTYPE_TYPE_2_V; + valuelist->type = IOLINK_MSEQTYPE_TYPE_2_V; } } } -static iolink_error_t populate_valuelist (uint8_t mscapa, uint8_t revid, - uint8_t pdin, uint8_t pdout, - uint8_t cycbyte, bool operate, - iolink_mode_vl_t *valuelist) +static iolink_error_t populate_valuelist ( + uint8_t mscapa, + uint8_t revid, + uint8_t pdin, + uint8_t pdout, + uint8_t cycbyte, + bool operate, + iolink_mode_vl_t * valuelist) { valuelist->type = IOLINK_MSEQTYPE_TYPE_NONE; @@ -1101,36 +1251,41 @@ static iolink_error_t populate_valuelist (uint8_t mscapa, uint8_t revid, if (preop_m < 2) { - set_type_0_or_type_1_2(preop_m, cycbyte, valuelist); + set_type_0_or_type_1_2 (preop_m, cycbyte, valuelist); } else { - set_valuelist(valuelist, (preop_m == 2) ? 8 : 32, 0, 0, cycbyte, - IOLINK_MSEQTYPE_TYPE_1_V); + set_valuelist ( + valuelist, + (preop_m == 2) ? 8 : 32, + 0, + 0, + cycbyte, + IOLINK_MSEQTYPE_TYPE_1_V); } } else { - bool pdin_isbytes = ((pdin & BIT(7)) != 0); - bool pdout_isbytes = ((pdout & BIT(7)) != 0); - pdin = (pdin & 0x1F); - pdout = (pdout & 0x1F); + bool pdin_isbytes = ((pdin & BIT (7)) != 0); + bool pdout_isbytes = ((pdout & BIT (7)) != 0); + pdin = (pdin & 0x1F); + pdout = (pdout & 0x1F); uint8_t oper_m = (mscapa >> 1) & 0x07; - bool legacy = (revid != IOLINK_REVISION_1_1); + bool legacy = (revid != IOLINK_REVISION_1_1); if (legacy) { if ((pdin == 0) && (pdout == 0)) { - set_type_0_or_type_1_2(oper_m, cycbyte, valuelist); + set_type_0_or_type_1_2 (oper_m, cycbyte, valuelist); } else { if ((pdin_isbytes || pdout_isbytes) && ((pdin >= 3) || (pdout >= 3))) { // SDCI_TC_0286 - set_valuelist(valuelist, 2, 0, 0, cycbyte, IOLINK_MSEQTYPE_TYPE_1_1); + set_valuelist (valuelist, 2, 0, 0, cycbyte, IOLINK_MSEQTYPE_TYPE_1_1); } else { @@ -1138,27 +1293,57 @@ static iolink_error_t populate_valuelist (uint8_t mscapa, uint8_t revid, { if ((pdin > 0) && (pdin <= 8)) { - set_valuelist(valuelist, 1, 1, 0, cycbyte, IOLINK_MSEQTYPE_TYPE_2_1); + set_valuelist ( + valuelist, + 1, + 1, + 0, + cycbyte, + IOLINK_MSEQTYPE_TYPE_2_1); } else if ((pdin >= 9) && (pdin <= 16)) { - set_valuelist(valuelist, 1, 2, 0, cycbyte, IOLINK_MSEQTYPE_TYPE_2_2); + set_valuelist ( + valuelist, + 1, + 2, + 0, + cycbyte, + IOLINK_MSEQTYPE_TYPE_2_2); } } else if (pdin == 0) { if ((pdout > 0) && (pdout <= 8)) { - set_valuelist(valuelist, 1, 0, 1, cycbyte, IOLINK_MSEQTYPE_TYPE_2_3); + set_valuelist ( + valuelist, + 1, + 0, + 1, + cycbyte, + IOLINK_MSEQTYPE_TYPE_2_3); } else if ((pdout >= 9) && (pdout <= 16)) { - set_valuelist(valuelist, 1, 0, 2, cycbyte, IOLINK_MSEQTYPE_TYPE_2_4); + set_valuelist ( + valuelist, + 1, + 0, + 2, + cycbyte, + IOLINK_MSEQTYPE_TYPE_2_4); } } else if ((pdin >= 1) && (pdin <= 8) && (pdout >= 1) && (pdout <= 8)) { - set_valuelist(valuelist, 1, 1, 1, cycbyte, IOLINK_MSEQTYPE_TYPE_2_5); + set_valuelist ( + valuelist, + 1, + 1, + 1, + cycbyte, + IOLINK_MSEQTYPE_TYPE_2_5); } } } @@ -1170,7 +1355,7 @@ static iolink_error_t populate_valuelist (uint8_t mscapa, uint8_t revid, case 0: if ((pdin == 0) && (pdout == 0)) { - set_valuelist(valuelist, 1, 0, 0, cycbyte, IOLINK_MSEQTYPE_TYPE_0); + set_valuelist (valuelist, 1, 0, 0, cycbyte, IOLINK_MSEQTYPE_TYPE_0); } else if (!pdin_isbytes && !pdout_isbytes) { @@ -1178,11 +1363,23 @@ static iolink_error_t populate_valuelist (uint8_t mscapa, uint8_t revid, { if ((pdin >= 1) && (pdin <= 8)) { - set_valuelist(valuelist, 1, 1, 0, cycbyte, IOLINK_MSEQTYPE_TYPE_2_1); + set_valuelist ( + valuelist, + 1, + 1, + 0, + cycbyte, + IOLINK_MSEQTYPE_TYPE_2_1); } else if ((pdin >= 9) && (pdin <= 16)) { - set_valuelist(valuelist, 1, 2, 0, cycbyte, IOLINK_MSEQTYPE_TYPE_2_2); + set_valuelist ( + valuelist, + 1, + 2, + 0, + cycbyte, + IOLINK_MSEQTYPE_TYPE_2_2); } } else @@ -1191,35 +1388,61 @@ static iolink_error_t populate_valuelist (uint8_t mscapa, uint8_t revid, { if ((pdout >= 1) && (pdout <= 8)) { - set_valuelist(valuelist, 1, 0, 1, cycbyte, IOLINK_MSEQTYPE_TYPE_2_3); + set_valuelist ( + valuelist, + 1, + 0, + 1, + cycbyte, + IOLINK_MSEQTYPE_TYPE_2_3); } else if ((pdout >= 9) && (pdout <= 16)) { - set_valuelist(valuelist, 1, 0, 2, cycbyte, IOLINK_MSEQTYPE_TYPE_2_4); + set_valuelist ( + valuelist, + 1, + 0, + 2, + cycbyte, + IOLINK_MSEQTYPE_TYPE_2_4); } } else if ((pdin >= 1) && (pdin <= 8) && (pdout >= 1) && (pdout <= 8)) { - set_valuelist(valuelist, 1, 1, 1, cycbyte, IOLINK_MSEQTYPE_TYPE_2_5); + set_valuelist ( + valuelist, + 1, + 1, + 1, + cycbyte, + IOLINK_MSEQTYPE_TYPE_2_5); } - else if (((pdin >= 9) && (pdin <= 16) && (pdout >= 1) && (pdout <= 16)) || - ((pdin >= 1) && (pdin <= 16) && (pdout >= 9) && (pdout <= 16))) + else if ( + ((pdin >= 9) && (pdin <= 16) && (pdout >= 1) && + (pdout <= 16)) || + ((pdin >= 1) && (pdin <= 16) && (pdout >= 9) && + (pdout <= 16))) { - set_valuelist(valuelist, 1, (pdin >= 9) ? 2 : 1, (pdout >= 9) ? 2 : 1, - cycbyte, IOLINK_MSEQTYPE_TYPE_2_V); + set_valuelist ( + valuelist, + 1, + (pdin >= 9) ? 2 : 1, + (pdout >= 9) ? 2 : 1, + cycbyte, + IOLINK_MSEQTYPE_TYPE_2_V); } } } else { // SDCI_TC_0173 - set_valuelist(valuelist, 2, 0, 0, cycbyte, IOLINK_MSEQTYPE_TYPE_1_1); + set_valuelist (valuelist, 2, 0, 0, cycbyte, IOLINK_MSEQTYPE_TYPE_1_1); } break; case 1: if ((pdin == 0) && (pdout == 0)) { - set_valuelist(valuelist, 2, 0, 0, cycbyte, IOLINK_MSEQTYPE_TYPE_1_2); + set_valuelist (valuelist, 2, 0, 0, cycbyte, IOLINK_MSEQTYPE_TYPE_1_2); } break; case 4: @@ -1227,78 +1450,105 @@ static iolink_error_t populate_valuelist (uint8_t mscapa, uint8_t revid, { if ((pdout >= 3) || (pdin >= 3)) { - set_valuelist(valuelist, 1, pdin + 1, pdout + 1, cycbyte, - IOLINK_MSEQTYPE_TYPE_2_V); + set_valuelist ( + valuelist, + 1, + pdin + 1, + pdout + 1, + cycbyte, + IOLINK_MSEQTYPE_TYPE_2_V); } } else { - set_type_2_V(pdin_isbytes, pdout_isbytes, pdin, pdout, 1, valuelist); + set_type_2_V (pdin_isbytes, pdout_isbytes, pdin, pdout, 1, valuelist); } break; case 5: case 6: case 7: - { - uint8_t onreqdatalength = 1 << ((2 * oper_m) - 9); + { + uint8_t onreqdatalength = 1 << ((2 * oper_m) - 9); - if ((pdin > 0) || (pdout > 0)) - { - set_type_2_V(pdin_isbytes, pdout_isbytes, pdin, pdout, - onreqdatalength, valuelist); - } - else if (oper_m != 5) - { - set_valuelist(valuelist, onreqdatalength, 0, 0, cycbyte, - IOLINK_MSEQTYPE_TYPE_1_V); - } + if ((pdin > 0) || (pdout > 0)) + { + set_type_2_V ( + pdin_isbytes, + pdout_isbytes, + pdin, + pdout, + onreqdatalength, + valuelist); } - break; + else if (oper_m != 5) + { + set_valuelist ( + valuelist, + onreqdatalength, + 0, + 0, + cycbyte, + IOLINK_MSEQTYPE_TYPE_1_V); + } + } + break; } } } - return (valuelist->type == IOLINK_MSEQTYPE_TYPE_NONE) ? - IOLINK_ERROR_INCORRECT_DATA : IOLINK_ERROR_NONE; + return (valuelist->type == IOLINK_MSEQTYPE_TYPE_NONE) + ? IOLINK_ERROR_INCORRECT_DATA + : IOLINK_ERROR_NONE; } /* SM job callback functions */ static void sm_write_cycl_cnf_cb (iolink_job_t * job) { - iolink_sm_event (job->port, (job->al_write_cnf.errortype != IOLINK_SMI_ERRORTYPE_NONE) ? - SM_EVENT_CNF_COMLOST : SM_EVENT_WRITE_MASTER_CYCL_DONE); + iolink_sm_event ( + job->port, + (job->al_write_cnf.errortype != IOLINK_SMI_ERRORTYPE_NONE) + ? SM_EVENT_CNF_COMLOST + : SM_EVENT_WRITE_MASTER_CYCL_DONE); } static void sm_AL_Read_cnf_cb (iolink_job_t * job) { - iolink_port_t * port = job->port; - iolink_sm_port_t * sm = iolink_get_sm_ctx (port); + iolink_port_t * port = job->port; + iolink_sm_port_t * sm = iolink_get_sm_ctx (port); iolink_smp_parameterlist_t * real_paramlist = &sm->real_paramlist; if (job->al_read_cnf.errortype != IOLINK_SMI_ERRORTYPE_NONE) { - iolink_sm_event (port, (real_paramlist->revisionid == IOL_DIR_PARAM_REV_V11) ? - SM_EVENT_CNF_COMLOST : SM_EVENT_DL_Mode_COMLOST); + iolink_sm_event ( + port, + (real_paramlist->revisionid == IOL_DIR_PARAM_REV_V11) + ? SM_EVENT_CNF_COMLOST + : SM_EVENT_DL_Mode_COMLOST); } else { uint8_t len = job->al_read_cnf.data_len; - if (len > sizeof(real_paramlist->serialnumber)) + if (len > sizeof (real_paramlist->serialnumber)) { iolink_sm_event (port, SM_EVENT_CNF_COMLOST); } else { - memset (real_paramlist->serialnumber, 0, sizeof(real_paramlist->serialnumber)); + memset ( + real_paramlist->serialnumber, + 0, + sizeof (real_paramlist->serialnumber)); memcpy (real_paramlist->serialnumber, job->al_read_cnf.data, len); sm_check_sernum (port, true); } } } -static inline void sm_DL_Mode_ind_cb_preop_op (iolink_job_t * job, iolink_mhmode_t mode, - iolink_fsm_sm_event_t event) +static inline void sm_DL_Mode_ind_cb_preop_op ( + iolink_job_t * job, + iolink_mhmode_t mode, + iolink_fsm_sm_event_t event) { iolink_mhmode_t realmode = job->dl_mode; @@ -1308,19 +1558,26 @@ static inline void sm_DL_Mode_ind_cb_preop_op (iolink_job_t * job, iolink_mhmode } else { - LOG_ERROR (IOLINK_SM_LOG, "%s: bad DL_Mode = MH mode %s (%u)\n", __func__, - iolink_mhmode_literals[realmode], realmode); + LOG_ERROR ( + IOLINK_SM_LOG, + "%s: bad DL_Mode = MH mode %s (%u)\n", + __func__, + iolink_mhmode_literals[realmode], + realmode); } } static inline void sm_DL_Mode_ind_cb_preop (iolink_job_t * job) { - sm_DL_Mode_ind_cb_preop_op(job, IOLINK_MHMODE_PREOPERATE, SM_EVENT_DL_Mode_PREOPERATE); + sm_DL_Mode_ind_cb_preop_op ( + job, + IOLINK_MHMODE_PREOPERATE, + SM_EVENT_DL_Mode_PREOPERATE); } static inline void sm_DL_Mode_ind_cb_operate (iolink_job_t * job) { - sm_DL_Mode_ind_cb_preop_op(job, IOLINK_MHMODE_OPERATE, SM_EVENT_DL_Mode_OPERATE); + sm_DL_Mode_ind_cb_preop_op (job, IOLINK_MHMODE_OPERATE, SM_EVENT_DL_Mode_OPERATE); } static inline void sm_DL_Mode_ind_cb_inactive (iolink_job_t * job) @@ -1344,16 +1601,20 @@ static inline void sm_DL_Mode_ind_cb_inactive (iolink_job_t * job) } else { - /* WURQ failed. Signal it as COMLOST. The application is responsible for - * attempting to start the port again. + /* WURQ failed. Signal it as COMLOST. The application is responsible + * for attempting to start the port again. */ SM_PortMode_ind (job->port, IOLINK_SM_PORTMODE_COMLOST); } break; } default: - LOG_ERROR (IOLINK_SM_LOG, "%s: bad DL_Mode = MH mode %s (%u)\n", __func__, - iolink_mhmode_literals[realmode], realmode); + LOG_ERROR ( + IOLINK_SM_LOG, + "%s: bad DL_Mode = MH mode %s (%u)\n", + __func__, + iolink_mhmode_literals[realmode], + realmode); break; } } @@ -1364,28 +1625,39 @@ static inline void sm_DL_Mode_ind_cb_inspectionfault (iolink_job_t * job) if ((realmode != IOLINK_MHMODE_PREOPERATE) && (realmode != IOLINK_MHMODE_OPERATE)) { - LOG_ERROR (IOLINK_SM_LOG, "%s: unexpected DL_Mode = MH mode %s (%u)\n", __func__, - iolink_mhmode_literals[realmode], realmode); + LOG_ERROR ( + IOLINK_SM_LOG, + "%s: unexpected DL_Mode = MH mode %s (%u)\n", + __func__, + iolink_mhmode_literals[realmode], + realmode); } } static void sm_DL_Mode_ind_cb (iolink_job_t * job) { - iolink_port_t * port = job->port; + iolink_port_t * port = job->port; iolink_mhmode_t realmode = job->dl_mode; - iolink_sm_port_t * sm = iolink_get_sm_ctx (port); + iolink_sm_port_t * sm = iolink_get_sm_ctx (port); - LOG_DEBUG (IOLINK_SM_LOG, "(%u): %s: DL_Mode = MH mode %s (%u)\n", - iolink_get_portnumber (port), __func__, - iolink_mhmode_literals[realmode], realmode); + LOG_DEBUG ( + IOLINK_SM_LOG, + "(%u): %s: DL_Mode = MH mode %s (%u)\n", + iolink_get_portnumber (port), + __func__, + iolink_mhmode_literals[realmode], + realmode); - if ((realmode == IOLINK_MHMODE_COM1) || - (realmode == IOLINK_MHMODE_COM2) || - (realmode == IOLINK_MHMODE_COM3)) + if ( + (realmode == IOLINK_MHMODE_COM1) || (realmode == IOLINK_MHMODE_COM2) || + (realmode == IOLINK_MHMODE_COM3)) { sm->comrate = realmode; - LOG_INFO (IOLINK_SM_LOG, "%s: Bad realmode MH mode %s\n", __func__, - iolink_mhmode_literals[realmode]); + LOG_INFO ( + IOLINK_SM_LOG, + "%s: Bad realmode MH mode %s\n", + __func__, + iolink_mhmode_literals[realmode]); } else { @@ -1398,8 +1670,11 @@ static void sm_DL_Mode_ind_cb (iolink_job_t * job) { case SM_STATE_PortInactive: case SM_STATE_DIDO: - LOG_ERROR (IOLINK_SM_LOG, "%s: COMLOST when in SM state %s\n", - __func__, iolink_sm_state_literals[sm->state]); + LOG_ERROR ( + IOLINK_SM_LOG, + "%s: COMLOST when in SM state %s\n", + __func__, + iolink_sm_state_literals[sm->state]); break; default: iolink_sm_event (port, SM_EVENT_DL_Mode_COMLOST); @@ -1424,8 +1699,12 @@ static void sm_DL_Mode_ind_cb (iolink_job_t * job) sm_DL_Mode_ind_cb_inspectionfault (job); break; default: - LOG_ERROR (IOLINK_SM_LOG, "%s: bad DL_Mode = MH mode %s (%u)\n", __func__, - iolink_mhmode_literals[realmode], realmode); + LOG_ERROR ( + IOLINK_SM_LOG, + "%s: bad DL_Mode = MH mode %s (%u)\n", + __func__, + iolink_mhmode_literals[realmode], + realmode); iolink_sm_event (port, SM_EVENT_DL_Mode_COMLOST); break; } @@ -1434,12 +1713,13 @@ static void sm_DL_Mode_ind_cb (iolink_job_t * job) static void sm_operate_cb (iolink_job_t * job) { - iolink_port_t * port = job->port; - iolink_sm_port_t * sm = iolink_get_sm_ctx (port); + iolink_port_t * port = job->port; + iolink_sm_port_t * sm = iolink_get_sm_ctx (port); iolink_smp_parameterlist_t * real_paramlist = &sm->real_paramlist; - if ((real_paramlist->revisionid != IOL_DIR_PARAM_REV_V10) || - (real_paramlist->vendorid != 0x014E)) // SDCI_TC_0196 + if ( + (real_paramlist->revisionid != IOL_DIR_PARAM_REV_V10) || + (real_paramlist->vendorid != 0x014E)) // SDCI_TC_0196 { iolink_sm_event (port, SM_EVENT_WRITE_MASTER_CYCL_REQ); } @@ -1449,15 +1729,15 @@ static void sm_operate_cb (iolink_job_t * job) } // ErrorInfo: - // Permitted values: TIMING_CONFLICT (the requested combination of cycle times for the activated ports - // return IOLINK_ERROR_INFO_TIMING_CONFLICT; + // Permitted values: TIMING_CONFLICT (the requested combination of cycle + // times for the activated ports return IOLINK_ERROR_INFO_TIMING_CONFLICT; } static void sm_setportcfg_req_cb (iolink_job_t * job) { - iolink_port_t * port = job->port; + iolink_port_t * port = job->port; iolink_fsm_sm_event_t event = SM_EVENT_SM_SetPortConfig_INACTIVE; - iolink_sm_port_t * sm = iolink_get_sm_ctx (port); + iolink_sm_port_t * sm = iolink_get_sm_ctx (port); iolink_smp_parameterlist_t * parameterlist = &job->sm_setportcfg_req.paramlist; switch (sm->state) @@ -1470,9 +1750,12 @@ static void sm_setportcfg_req_cb (iolink_job_t * job) case SM_STATE_checkSerNum: break; default: - LOG_INFO (IOLINK_SM_LOG, "%u: SM state (%s) does not allow setportcfg\n", - iolink_get_portnumber (port), iolink_sm_state_literals[sm->state]); - //iolink_sm_event (port, SM_EVENT_DL_Mode_COMLOST); // TODO ?!? + LOG_INFO ( + IOLINK_SM_LOG, + "%u: SM state (%s) does not allow setportcfg\n", + iolink_get_portnumber (port), + iolink_sm_state_literals[sm->state]); + // iolink_sm_event (port, SM_EVENT_DL_Mode_COMLOST); // TODO ?!? // TODO return busy return; @@ -1492,23 +1775,29 @@ static void sm_setportcfg_req_cb (iolink_job_t * job) break; } - LOG_DEBUG (IOLINK_SM_LOG, "%s: iolink_sm_target_mode_t = %s\n", __func__, - iolink_sm_target_mode_literals[parameterlist->mode]); + LOG_DEBUG ( + IOLINK_SM_LOG, + "%s: iolink_sm_target_mode_t = %s\n", + __func__, + iolink_sm_target_mode_literals[parameterlist->mode]); - char save_serial_number[16] = { 0 }; + char save_serial_number[16] = {0}; if (sm->config_paramlist.serialnumber[0] != 0) { // SDCI_TC_0196: save configured serial number - memcpy(save_serial_number, sm->config_paramlist.serialnumber, 16); + memcpy (save_serial_number, sm->config_paramlist.serialnumber, 16); } /* Store configuration */ - memcpy (&sm->config_paramlist, parameterlist, sizeof(iolink_smp_parameterlist_t)); + memcpy ( + &sm->config_paramlist, + parameterlist, + sizeof (iolink_smp_parameterlist_t)); if (save_serial_number[0] != 0) { // SDCI_TC_0196: restore configured serial number - memcpy(sm->config_paramlist.serialnumber, save_serial_number, 16); + memcpy (sm->config_paramlist.serialnumber, save_serial_number, 16); } iolink_sm_event (port, event); @@ -1516,11 +1805,11 @@ static void sm_setportcfg_req_cb (iolink_job_t * job) static void sm_DL_Read_cnf_cb (iolink_job_t * job) { - iolink_port_t * port = job->port; - iolink_sm_port_t * sm = iolink_get_sm_ctx (port); + iolink_port_t * port = job->port; + iolink_sm_port_t * sm = iolink_get_sm_ctx (port); iolink_smp_parameterlist_t * real_paramlist = &sm->real_paramlist; - uint8_t addr = job->dl_rw_cnf.addr; - uint8_t value = job->dl_rw_cnf.val; + uint8_t addr = job->dl_rw_cnf.addr; + uint8_t value = job->dl_rw_cnf.val; if (job->dl_rw_cnf.stat != IOLINK_STATUS_NO_ERROR) { @@ -1541,29 +1830,30 @@ static void sm_DL_Read_cnf_cb (iolink_job_t * job) switch (addr) { case IOL_DIR_PARAMA_MIN_CYCL: - { -#define MIN_CYCL_TIME_1 92 -#define MIN_CYCL_TIME_2_3 79 -#define FOUR_MS 40 + { +#define MIN_CYCL_TIME_1 92 +#define MIN_CYCL_TIME_2_3 79 +#define FOUR_MS 40 - uint8_t mincycletime = (sm->comrate == IOLINK_MHMODE_COM1) ? - MIN_CYCL_TIME_1 : MIN_CYCL_TIME_2_3; + uint8_t mincycletime = (sm->comrate == IOLINK_MHMODE_COM1) + ? MIN_CYCL_TIME_1 + : MIN_CYCL_TIME_2_3; #ifndef UNIT_TEST - static uint8_t older_cycletime; - uint8_t old_cycletime = real_paramlist->cycletime; + static uint8_t older_cycletime; + uint8_t old_cycletime = real_paramlist->cycletime; #endif - uint8_t new_cycletime = (value < mincycletime) ? mincycletime : value; - real_paramlist->cycletime = new_cycletime; + uint8_t new_cycletime = (value < mincycletime) ? mincycletime : value; + real_paramlist->cycletime = new_cycletime; #ifndef UNIT_TEST - if ((value != FOUR_MS) || - (new_cycletime != MIN_CYCL_TIME_2_3) || - (old_cycletime != older_cycletime)) - { - iolink_pl_set_cycletime(port, new_cycletime); - } - older_cycletime = old_cycletime; -#endif + if ( + (value != FOUR_MS) || (new_cycletime != MIN_CYCL_TIME_2_3) || + (old_cycletime != older_cycletime)) + { + iolink_pl_set_cycletime (port, new_cycletime); } + older_cycletime = old_cycletime; +#endif + } sm->dev_com.mincycle = value; break; case IOL_DIR_PARAMA_MSEQ_CAP: @@ -1592,8 +1882,11 @@ static void sm_DL_Read_cnf_cb (iolink_job_t * job) break; case IOL_DIR_PARAMA_DID_3: real_paramlist->deviceid |= value; - LOG_DEBUG (IOLINK_SM_LOG, "SM: vendorid = 0x%04x deviceid = 0x%06lx\n", - real_paramlist->vendorid, (unsigned long)real_paramlist->deviceid); + LOG_DEBUG ( + IOLINK_SM_LOG, + "SM: vendorid = 0x%04x deviceid = 0x%06lx\n", + real_paramlist->vendorid, + (unsigned long)real_paramlist->deviceid); break; case IOL_DIR_PARAMA_FID_1: real_paramlist->functionid = value << 8; @@ -1662,7 +1955,7 @@ static void sm_DL_Write_cnf_cb (iolink_job_t * job) static void sm_DL_Write_Devmode_cnf (iolink_job_t * job) { - iolink_port_t * port = job->port; + iolink_port_t * port = job->port; iolink_sm_port_t * sm = iolink_get_sm_ctx (port); if (job->dl_write_devicemode_cnf.errorinfo == IOLINK_STATUS_NO_ERROR) @@ -1676,14 +1969,19 @@ static void sm_DL_Write_Devmode_cnf (iolink_job_t * job) } else if (sm->state == SM_STATE_waitForFallback) { - iolink_sm_event (job->port, SM_EVENT_SM_SetPortConfig_INACTIVE); /* Not in spec */ + iolink_sm_event (job->port, SM_EVENT_SM_SetPortConfig_INACTIVE); /* Not + in + spec + */ return; } } - iolink_sm_event (port, (sm->state == SM_STATE_wait_devmode_cnf) ? - SM_EVENT_CNF_COMLOST : SM_EVENT_DL_Mode_COMLOST); + iolink_sm_event ( + port, + (sm->state == SM_STATE_wait_devmode_cnf) ? SM_EVENT_CNF_COMLOST + : SM_EVENT_DL_Mode_COMLOST); } /* Stack internal API */ @@ -1691,7 +1989,7 @@ void iolink_sm_init (iolink_port_t * port) { iolink_sm_port_t * sm = iolink_get_sm_ctx (port); - sm->state = SM_STATE_PortInactive; + sm->state = SM_STATE_PortInactive; sm->dl_addr = IOL_DIR_PARAMA_DUMMY_WURQ; } @@ -1699,13 +1997,18 @@ iolink_error_t SM_Operate (iolink_port_t * port) { iolink_job_t * job = iolink_fetch_avail_job (port); - iolink_post_job_with_type_and_callback (port, job, IOLINK_JOB_SM_OPERATE_REQ, sm_operate_cb); + iolink_post_job_with_type_and_callback ( + port, + job, + IOLINK_JOB_SM_OPERATE_REQ, + sm_operate_cb); return IOLINK_ERROR_NONE; } -iolink_error_t SM_SetPortConfig_req (iolink_port_t * port, - iolink_smp_parameterlist_t * parameterlist) +iolink_error_t SM_SetPortConfig_req ( + iolink_port_t * port, + iolink_smp_parameterlist_t * parameterlist) { if (!((parameterlist->inspectionlevel == IOLINK_INSPECTIONLEVEL_NO_CHECK) || (parameterlist->inspectionlevel == IOLINK_INSPECTIONLEVEL_TYPE_COMP) || @@ -1730,71 +2033,100 @@ iolink_error_t SM_SetPortConfig_req (iolink_port_t * port, iolink_job_t * job = iolink_fetch_avail_job (port); /* Copy configuration */ - memcpy (&job->sm_setportcfg_req.paramlist, parameterlist, - sizeof(iolink_smp_parameterlist_t)); + memcpy ( + &job->sm_setportcfg_req.paramlist, + parameterlist, + sizeof (iolink_smp_parameterlist_t)); - iolink_post_job_with_type_and_callback (port, job, IOLINK_JOB_SM_SET_PORT_CFG_REQ, sm_setportcfg_req_cb); + iolink_post_job_with_type_and_callback ( + port, + job, + IOLINK_JOB_SM_SET_PORT_CFG_REQ, + sm_setportcfg_req_cb); return IOLINK_ERROR_NONE; } -void DL_Read_cnf (iolink_port_t * port, uint8_t value, - iolink_status_t errorinfo) +void DL_Read_cnf (iolink_port_t * port, uint8_t value, iolink_status_t errorinfo) { iolink_sm_port_t * sm = iolink_get_sm_ctx (port); - iolink_job_t * job = iolink_fetch_avail_job (port); + iolink_job_t * job = iolink_fetch_avail_job (port); job->dl_rw_cnf.addr = sm->dl_addr; job->dl_rw_cnf.val = value; job->dl_rw_cnf.stat = errorinfo; - iolink_post_job_with_type_and_callback (port, job, IOLINK_JOB_DL_READ_CNF, sm_DL_Read_cnf_cb); + iolink_post_job_with_type_and_callback ( + port, + job, + IOLINK_JOB_DL_READ_CNF, + sm_DL_Read_cnf_cb); } void DL_Write_cnf (iolink_port_t * port, iolink_status_t errorinfo) { iolink_sm_port_t * sm = iolink_get_sm_ctx (port); - iolink_job_t * job = iolink_fetch_avail_job (port); + iolink_job_t * job = iolink_fetch_avail_job (port); job->dl_rw_cnf.addr = sm->dl_addr; job->dl_rw_cnf.stat = errorinfo; - iolink_post_job_with_type_and_callback (port, job, IOLINK_JOB_DL_WRITE_CNF, sm_DL_Write_cnf_cb); + iolink_post_job_with_type_and_callback ( + port, + job, + IOLINK_JOB_DL_WRITE_CNF, + sm_DL_Write_cnf_cb); } -void DL_Write_Devicemode_cnf (iolink_port_t * port, iolink_status_t errorinfo, - iolink_dl_mode_t devicemode) +void DL_Write_Devicemode_cnf ( + iolink_port_t * port, + iolink_status_t errorinfo, + iolink_dl_mode_t devicemode) { - iolink_job_t * job = iolink_fetch_avail_job (port); + iolink_job_t * job = iolink_fetch_avail_job (port); job->dl_write_devicemode_cnf.errorinfo = errorinfo; job->dl_write_devicemode_cnf.mode = devicemode; - iolink_post_job_with_type_and_callback (port, job, IOLINK_JOB_DL_WRITE_DEVMODE_CNF, sm_DL_Write_Devmode_cnf); + iolink_post_job_with_type_and_callback ( + port, + job, + IOLINK_JOB_DL_WRITE_DEVMODE_CNF, + sm_DL_Write_Devmode_cnf); } void DL_Mode_ind_baud (iolink_port_t * port, iolink_mhmode_t realmode) { - if ((realmode == IOLINK_MHMODE_COM1) || - (realmode == IOLINK_MHMODE_COM2) || - (realmode == IOLINK_MHMODE_COM3)) + if ( + (realmode == IOLINK_MHMODE_COM1) || (realmode == IOLINK_MHMODE_COM2) || + (realmode == IOLINK_MHMODE_COM3)) { iolink_sm_port_t * sm = iolink_get_sm_ctx (port); sm->comrate = realmode; - LOG_DEBUG (IOLINK_SM_LOG, "%s: Set realmode MH mode %s\n", __func__, - iolink_mhmode_literals[realmode]); + LOG_DEBUG ( + IOLINK_SM_LOG, + "%s: Set realmode MH mode %s\n", + __func__, + iolink_mhmode_literals[realmode]); } else { - LOG_INFO (IOLINK_SM_LOG, "%s: Bad realmode MH mode %s\n", __func__, - iolink_mhmode_literals[realmode]); + LOG_INFO ( + IOLINK_SM_LOG, + "%s: Bad realmode MH mode %s\n", + __func__, + iolink_mhmode_literals[realmode]); } } void DL_Mode_ind (iolink_port_t * port, iolink_mhmode_t realmode) { iolink_job_t * job = iolink_fetch_avail_job (port); - job->dl_mode = realmode; + job->dl_mode = realmode; - iolink_post_job_with_type_and_callback (port, job, IOLINK_JOB_DL_MODE_IND, sm_DL_Mode_ind_cb); + iolink_post_job_with_type_and_callback ( + port, + job, + IOLINK_JOB_DL_MODE_IND, + sm_DL_Mode_ind_cb); } diff --git a/src/iolink_sm.h b/src/iolink_sm.h index 3d0ecd6..12b3ab4 100644 --- a/src/iolink_sm.h +++ b/src/iolink_sm.h @@ -13,13 +13,11 @@ #ifndef IOLINK_SM_H #define IOLINK_SM_H - #include "iolink_main.h" #include "iolink_types.h" #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif /* Direct Parameter page, see IO-Link Interface Spec v1.1.3 chapter B.1.1 */ @@ -41,38 +39,38 @@ extern "C" #define IOL_DIR_PARAMA_DUMMY_WURQ 0xFF /* Dummy used for first DL_Read_cnf */ /* MasterCommand, see IO-Link Interface Spec v1.1.3 chapter B.1.2 */ -#define IOL_MASTERCMD_NONE 0x00 -#define IOL_MASTERCMD_FALLBACK 0x5A -#define IOL_MASTERCMD_MASTER_IDENT 0x95 -#define IOL_MASTERCMD_DEVICE_IDENT 0x96 -#define IOL_MASTERCMD_DEVICE_STARTUP 0x97 -#define IOL_MASTERCMD_DEVICE_PD_OUT_OP 0x98 -#define IOL_MASTERCMD_DEVICE_OPERATE 0x99 -#define IOL_MASTERCMD_DEVICE_PREOP 0x9A +#define IOL_MASTERCMD_NONE 0x00 +#define IOL_MASTERCMD_FALLBACK 0x5A +#define IOL_MASTERCMD_MASTER_IDENT 0x95 +#define IOL_MASTERCMD_DEVICE_IDENT 0x96 +#define IOL_MASTERCMD_DEVICE_STARTUP 0x97 +#define IOL_MASTERCMD_DEVICE_PD_OUT_OP 0x98 +#define IOL_MASTERCMD_DEVICE_OPERATE 0x99 +#define IOL_MASTERCMD_DEVICE_PREOP 0x9A /* Device paramter (Index assignment of data objects), * see IO-Link Interface Spec v1.1.3 chapter B.2.1 */ -#define IOL_DEV_PARAMA_DIRECT_PAR_P1 0x0000 -#define IOL_DEV_PARAMA_DIRECT_PAR_P2 0x0001 -#define IOL_DEV_PARAMA_SYSTEM_CMD 0x0002 -#define IOL_DEV_PARAMA_DATA_STOREAGE 0x0003 -#define IOL_DEV_PARAMA_DEV_ACCESS_LOCK 0x000C -#define IOL_DEV_PARAMA_VENDOR_NAME 0x0010 -#define IOL_DEV_PARAMA_VENDOR_TEXT 0x0011 -#define IOL_DEV_PARAMA_PRODUCT_NAME 0x0012 -#define IOL_DEV_PARAMA_PRODUCT_ID 0x0013 -#define IOL_DEV_PARAMA_PRODUCT_TEXT 0x0014 -#define IOL_DEV_PARAMA_SERIAL_NUMBER 0x0015 -#define IOL_DEV_PARAMA_HARDWARE_REV 0x0016 -#define IOL_DEV_PARAMA_FIRMWARE_REV 0x0017 -#define IOL_DEV_PARAMA_ERROR_COUNT 0x0020 -#define IOL_DEV_PARAMA_DEVICE_STATUS 0x0024 +#define IOL_DEV_PARAMA_DIRECT_PAR_P1 0x0000 +#define IOL_DEV_PARAMA_DIRECT_PAR_P2 0x0001 +#define IOL_DEV_PARAMA_SYSTEM_CMD 0x0002 +#define IOL_DEV_PARAMA_DATA_STOREAGE 0x0003 +#define IOL_DEV_PARAMA_DEV_ACCESS_LOCK 0x000C +#define IOL_DEV_PARAMA_VENDOR_NAME 0x0010 +#define IOL_DEV_PARAMA_VENDOR_TEXT 0x0011 +#define IOL_DEV_PARAMA_PRODUCT_NAME 0x0012 +#define IOL_DEV_PARAMA_PRODUCT_ID 0x0013 +#define IOL_DEV_PARAMA_PRODUCT_TEXT 0x0014 +#define IOL_DEV_PARAMA_SERIAL_NUMBER 0x0015 +#define IOL_DEV_PARAMA_HARDWARE_REV 0x0016 +#define IOL_DEV_PARAMA_FIRMWARE_REV 0x0017 +#define IOL_DEV_PARAMA_ERROR_COUNT 0x0020 +#define IOL_DEV_PARAMA_DEVICE_STATUS 0x0024 typedef enum iolink_sm_state { SM_STATE_PortInactive = 0, - //SM_STATE_checkCompatibility, + // SM_STATE_checkCompatibility, SM_STATE_waitonDLPreoperate, SM_STATE_checkSerNum, SM_STATE_wait, @@ -85,9 +83,9 @@ typedef enum iolink_sm_state SM_STATE_CheckVxy, SM_STATE_CheckComp, SM_STATE_RestartDevice, - SM_STATE_waitForFallback, /* Not in spec. */ + SM_STATE_waitForFallback, /* Not in spec. */ SM_STATE_write_master_cycl, /* Not in spec. */ - SM_STATE_wait_devmode_cnf, /* NOt in spec. */ + SM_STATE_wait_devmode_cnf, /* NOt in spec. */ SM_STATE_LAST } iolink_sm_state_t; @@ -123,9 +121,10 @@ typedef enum iolink_fsm_sm_event SM_EVENT_REVISION_OK, /* T22 */ SM_EVENT_RETRY_STARTUP, /* T23 and T25 */ SM_EVENT_WriteDone, /* T24 */ - SM_EVENT_CNF_COMLOST, /* T3, COMLOST when waiting on DL_{Read,Write}_cnf() or AL_Read_cnf() */ - SM_EVENT_WRITE_MASTER_CYCL_REQ, /* Not in spec */ - SM_EVENT_WRITE_MASTER_CYCL_DONE, /* Not in spec */ + SM_EVENT_CNF_COMLOST, /* T3, COMLOST when waiting on DL_{Read,Write}_cnf() or + AL_Read_cnf() */ + SM_EVENT_WRITE_MASTER_CYCL_REQ, /* Not in spec */ + SM_EVENT_WRITE_MASTER_CYCL_DONE, /* Not in spec */ SM_EVENT_LAST, } iolink_fsm_sm_event_t; @@ -145,29 +144,29 @@ typedef struct iolink_sm_port void DL_Mode_ind_baud (iolink_port_t * port, iolink_mhmode_t realmode); void DL_Mode_ind (iolink_port_t * port, iolink_mhmode_t realmode); iolink_error_t SM_Operate (iolink_port_t * port); -iolink_error_t SM_SetPortConfig_req (iolink_port_t * port, - iolink_smp_parameterlist_t *parameterlist); -void DL_Read_cnf (iolink_port_t * port, uint8_t value, - iolink_status_t errorinfo); +iolink_error_t SM_SetPortConfig_req ( + iolink_port_t * port, + iolink_smp_parameterlist_t * parameterlist); +void DL_Read_cnf (iolink_port_t * port, uint8_t value, iolink_status_t errorinfo); void DL_Write_cnf (iolink_port_t * port, iolink_status_t errorinfo); -void DL_Write_Devicemode_cnf (iolink_port_t * port, iolink_status_t errorinfo, - iolink_dl_mode_t devicemode); +void DL_Write_Devicemode_cnf ( + iolink_port_t * port, + iolink_status_t errorinfo, + iolink_dl_mode_t devicemode); /** * Initialise SM state-machine * - * This function initialises the SM state-machine for one IO-Link port and should be - * called when the stack is started. + * This function initialises the SM state-machine for one IO-Link port and + * should be called when the stack is started. * * @param port port handle */ void iolink_sm_init (iolink_port_t * port); - #ifdef __cplusplus } #endif #endif /* IOLINK_SM_H */ - diff --git a/src/iolink_types.h b/src/iolink_types.h index 132d913..ee5d922 100644 --- a/src/iolink_types.h +++ b/src/iolink_types.h @@ -23,13 +23,13 @@ #define IOLINK_RXTX_BUFFER_SIZE 64 -#define IOLINK_OD_MAX_SIZE 32 -#define IOLINK_ISDU_MAX_DATA_SIZE 238 +#define IOLINK_OD_MAX_SIZE 32 +#define IOLINK_ISDU_MAX_DATA_SIZE 238 /* I-Service and len + ExtLen + CHKPDU = 3 */ -#define IOLINK_ISDU_MAX_SIZE (IOLINK_ISDU_MAX_DATA_SIZE + 3) +#define IOLINK_ISDU_MAX_SIZE (IOLINK_ISDU_MAX_DATA_SIZE + 3) -#define IOL_DIR_PARAM_REV_V10 0x10 -#define IOL_DIR_PARAM_REV_V11 0x11 +#define IOL_DIR_PARAM_REV_V10 0x10 +#define IOL_DIR_PARAM_REV_V11 0x11 typedef enum { @@ -43,7 +43,7 @@ typedef enum typedef enum { - IOLINK_SMTARGET_MODE_CFGCOM=0, + IOLINK_SMTARGET_MODE_CFGCOM = 0, IOLINK_SMTARGET_MODE_AUTOCOM, IOLINK_SMTARGET_MODE_INACTIVE, IOLINK_SMTARGET_MODE_DI, @@ -71,8 +71,9 @@ typedef enum { IOLINK_INSPECTIONLEVEL_NO_CHECK, IOLINK_INSPECTIONLEVEL_TYPE_COMP, - IOLINK_INSPECTIONLEVEL_IDENTICAL, /* NOTE: IO-Link Interface Spec v1.1.3 Chapter 9.2.2.2 - * Optional, not recommended for new developments + IOLINK_INSPECTIONLEVEL_IDENTICAL, /* NOTE: IO-Link Interface Spec v1.1.3 + * Chapter 9.2.2.2 Optional, not + * recommended for new developments */ } iolink_inspectionlevel_t; @@ -124,16 +125,16 @@ typedef enum typedef enum { - IOLINK_RWDIRECTION_READ = 0x80, - IOLINK_RWDIRECTION_WRITE = 0x00, + IOLINK_RWDIRECTION_READ = 0x80, + IOLINK_RWDIRECTION_WRITE = 0x00, } iolink_rwdirection_t; typedef enum { - IOLINK_COMCHANNEL_PROCESS = 0x00, - IOLINK_COMCHANNEL_PAGE = 0x20, - IOLINK_COMCHANNEL_DIAGNOSIS = 0x40, - IOLINK_COMCHANNEL_ISDU = 0x60, + IOLINK_COMCHANNEL_PROCESS = 0x00, + IOLINK_COMCHANNEL_PAGE = 0x20, + IOLINK_COMCHANNEL_DIAGNOSIS = 0x40, + IOLINK_COMCHANNEL_ISDU = 0x60, } iolink_comchannel_t; typedef enum @@ -146,20 +147,20 @@ typedef enum typedef enum { - IOLINK_MSEQTYPE_TYPE_NONE = 0x00, - IOLINK_MSEQTYPE_TYPE_0 = 0x01, - IOLINK_MSEQTYPE_TYPE_1_1 = 0x11, - IOLINK_MSEQTYPE_TYPE_1_2 = 0x12, - IOLINK_MSEQTYPE_TYPE_1_V = 0x1E, - IOLINK_MSEQTYPE_TYPE_1_X = 0x1F, - IOLINK_MSEQTYPE_TYPE_2_1 = 0x21, - IOLINK_MSEQTYPE_TYPE_2_2 = 0x22, - IOLINK_MSEQTYPE_TYPE_2_3 = 0x23, - IOLINK_MSEQTYPE_TYPE_2_4 = 0x24, - IOLINK_MSEQTYPE_TYPE_2_5 = 0x25, - //IOLINK_MSEQTYPE_TYPE_2_6 = 0x26, - IOLINK_MSEQTYPE_TYPE_2_V = 0x2E, - IOLINK_MSEQTYPE_TYPE_2_X = 0x2F, + IOLINK_MSEQTYPE_TYPE_NONE = 0x00, + IOLINK_MSEQTYPE_TYPE_0 = 0x01, + IOLINK_MSEQTYPE_TYPE_1_1 = 0x11, + IOLINK_MSEQTYPE_TYPE_1_2 = 0x12, + IOLINK_MSEQTYPE_TYPE_1_V = 0x1E, + IOLINK_MSEQTYPE_TYPE_1_X = 0x1F, + IOLINK_MSEQTYPE_TYPE_2_1 = 0x21, + IOLINK_MSEQTYPE_TYPE_2_2 = 0x22, + IOLINK_MSEQTYPE_TYPE_2_3 = 0x23, + IOLINK_MSEQTYPE_TYPE_2_4 = 0x24, + IOLINK_MSEQTYPE_TYPE_2_5 = 0x25, + // IOLINK_MSEQTYPE_TYPE_2_6 = 0x26, + IOLINK_MSEQTYPE_TYPE_2_V = 0x2E, + IOLINK_MSEQTYPE_TYPE_2_X = 0x2F, } iolink_msequencetype_t; typedef enum @@ -188,28 +189,28 @@ typedef enum typedef enum { - IOLINK_EVENT_TYPE_RESERVED = 0, - IOLINK_EVENT_TYPE_NOTIFICATION = 1, - IOLINK_EVENT_TYPE_WARNING = 2, - IOLINK_EVENT_TYPE_ERROR = 3, + IOLINK_EVENT_TYPE_RESERVED = 0, + IOLINK_EVENT_TYPE_NOTIFICATION = 1, + IOLINK_EVENT_TYPE_WARNING = 2, + IOLINK_EVENT_TYPE_ERROR = 3, } iolink_event_type_t; typedef enum { - IOLINK_EVENT_INSTANCE_UNKNOWN = 0, - IOLINK_EVENT_INSTANCE_RESERVED_1 = 1, - IOLINK_EVENT_INSTANCE_RESERVED_2 = 2, - IOLINK_EVENT_INSTANCE_RESERVED_3 = 3, - IOLINK_EVENT_INSTANCE_APPLICATION = 4, - IOLINK_EVENT_INSTANCE_RESERVED_5 = 5, - IOLINK_EVENT_INSTANCE_RESERVED_6 = 6, - IOLINK_EVENT_INSTANCE_RESERVED_7 = 7, + IOLINK_EVENT_INSTANCE_UNKNOWN = 0, + IOLINK_EVENT_INSTANCE_RESERVED_1 = 1, + IOLINK_EVENT_INSTANCE_RESERVED_2 = 2, + IOLINK_EVENT_INSTANCE_RESERVED_3 = 3, + IOLINK_EVENT_INSTANCE_APPLICATION = 4, + IOLINK_EVENT_INSTANCE_RESERVED_5 = 5, + IOLINK_EVENT_INSTANCE_RESERVED_6 = 6, + IOLINK_EVENT_INSTANCE_RESERVED_7 = 7, } iolink_event_instance_t; typedef enum { IOLINK_EVENT_SOURCE_DEVICE = 0, - IOLINK_EVENT_SOURCE_MASTER = 1, + IOLINK_EVENT_SOURCE_MASTER = 1, } iolink_event_source_t; typedef enum @@ -257,7 +258,7 @@ typedef struct typedef enum { - IOLINK_DS_FAULT_NONE=0, + IOLINK_DS_FAULT_NONE = 0, IOLINK_DS_FAULT_ID, IOLINK_DS_FAULT_SIZE, IOLINK_DS_FAULT_UP, @@ -312,4 +313,4 @@ typedef union iolink_master_mbox_trigger_t trigger; }; } iolink_master_mbox_payload_t; -#endif /* IOLINK_TYPES_H */ +#endif /* IOLINK_TYPES_H */ diff --git a/test/mocks.cpp b/test/mocks.cpp index 30a8d55..4a8d3ba 100644 --- a/test/mocks.cpp +++ b/test/mocks.cpp @@ -21,81 +21,84 @@ #include #include -uint8_t mock_iolink_revisionid = IOL_DIR_PARAM_REV_V11; -uint8_t mock_iolink_master_cycletime = 0; -uint8_t mock_iolink_min_cycletime = 79; -uint16_t mock_iolink_vendorid = 1171; -uint32_t mock_iolink_deviceid = 0x112345; -uint16_t mock_iolink_functionid = 0x999A; -iolink_transmission_rate_t mock_iolink_trans_rate = - IOLINK_TRANSMISSION_RATE_COM1; - -uint8_t mock_iolink_restart_device_cnt = 0; -uint8_t mock_iolink_mastercmd_master_ident_cnt = 0; -uint8_t mock_iolink_mastercmd_preop_cnt = 0; -uint8_t mock_iolink_write_devmode_inactive_cnt = 0; -uint8_t mock_iolink_write_devmode_operate_cnt = 0; -uint8_t mock_iolink_al_data [64] = {0}; -uint8_t mock_iolink_al_data_len = 0; -uint16_t mock_iolink_al_data_index = 0; -uint8_t mock_iolink_al_data_subindex = 0; -uint8_t mock_iolink_al_read_cnf_cnt = 0; -uint8_t mock_iolink_al_read_req_cnt = 0; -uint8_t mock_iolink_al_write_cnf_cnt = 0; -uint8_t mock_iolink_al_write_req_cnt = 0; -uint8_t mock_iolink_al_control_req_cnt = 0; -uint8_t mock_iolink_al_control_ind_cnt = 0; -uint8_t mock_iolink_dl_pdout_data [IOLINK_PD_MAX_SIZE] = {0}; -uint8_t mock_iolink_dl_pdout_data_len = 0; -uint8_t mock_iolink_dl_pdin_data [IOLINK_PD_MAX_SIZE] = {0}; -uint8_t mock_iolink_dl_pdin_data_len = 0; -uint8_t mock_iolink_dl_control_req_cnt = 0; -uint8_t mock_iolink_dl_eventconf_req_cnt = 0; -uint8_t mock_iolink_al_setoutput_req_cnt = 0; -uint8_t mock_iolink_al_getinput_req_cnt = 0; -uint8_t mock_iolink_al_getinputoutput_req_cnt = 0; -uint8_t mock_iolink_al_newinput_inf_cnt = 0; -uint8_t mock_iolink_al_event_cnt = 0; -uint8_t mock_iolink_sm_operate_cnt = 0; -uint8_t mock_iolink_ds_delete_cnt = 0; -uint8_t mock_iolink_ds_startup_cnt = 0; -uint8_t mock_iolink_ds_ready_cnt = 0; -uint8_t mock_iolink_ds_fault_cnt = 0; -iolink_ds_fault_t mock_iolink_ds_fault = IOLINK_DS_FAULT_NONE; -uint8_t mock_iolink_od_start_cnt = 0; -uint8_t mock_iolink_od_stop_cnt = 0; -uint8_t mock_iolink_pd_start_cnt = 0; -uint8_t mock_iolink_pd_stop_cnt = 0; +uint8_t mock_iolink_revisionid = IOL_DIR_PARAM_REV_V11; +uint8_t mock_iolink_master_cycletime = 0; +uint8_t mock_iolink_min_cycletime = 79; +uint16_t mock_iolink_vendorid = 1171; +uint32_t mock_iolink_deviceid = 0x112345; +uint16_t mock_iolink_functionid = 0x999A; +iolink_transmission_rate_t mock_iolink_trans_rate = IOLINK_TRANSMISSION_RATE_COM1; + +uint8_t mock_iolink_restart_device_cnt = 0; +uint8_t mock_iolink_mastercmd_master_ident_cnt = 0; +uint8_t mock_iolink_mastercmd_preop_cnt = 0; +uint8_t mock_iolink_write_devmode_inactive_cnt = 0; +uint8_t mock_iolink_write_devmode_operate_cnt = 0; +uint8_t mock_iolink_al_data[64] = {0}; +uint8_t mock_iolink_al_data_len = 0; +uint16_t mock_iolink_al_data_index = 0; +uint8_t mock_iolink_al_data_subindex = 0; +uint8_t mock_iolink_al_read_cnf_cnt = 0; +uint8_t mock_iolink_al_read_req_cnt = 0; +uint8_t mock_iolink_al_write_cnf_cnt = 0; +uint8_t mock_iolink_al_write_req_cnt = 0; +uint8_t mock_iolink_al_control_req_cnt = 0; +uint8_t mock_iolink_al_control_ind_cnt = 0; +uint8_t mock_iolink_dl_pdout_data[IOLINK_PD_MAX_SIZE] = {0}; +uint8_t mock_iolink_dl_pdout_data_len = 0; +uint8_t mock_iolink_dl_pdin_data[IOLINK_PD_MAX_SIZE] = {0}; +uint8_t mock_iolink_dl_pdin_data_len = 0; +uint8_t mock_iolink_dl_control_req_cnt = 0; +uint8_t mock_iolink_dl_eventconf_req_cnt = 0; +uint8_t mock_iolink_al_setoutput_req_cnt = 0; +uint8_t mock_iolink_al_getinput_req_cnt = 0; +uint8_t mock_iolink_al_getinputoutput_req_cnt = 0; +uint8_t mock_iolink_al_newinput_inf_cnt = 0; +uint8_t mock_iolink_al_event_cnt = 0; +uint8_t mock_iolink_sm_operate_cnt = 0; +uint8_t mock_iolink_ds_delete_cnt = 0; +uint8_t mock_iolink_ds_startup_cnt = 0; +uint8_t mock_iolink_ds_ready_cnt = 0; +uint8_t mock_iolink_ds_fault_cnt = 0; +iolink_ds_fault_t mock_iolink_ds_fault = IOLINK_DS_FAULT_NONE; +uint8_t mock_iolink_od_start_cnt = 0; +uint8_t mock_iolink_od_stop_cnt = 0; +uint8_t mock_iolink_pd_start_cnt = 0; +uint8_t mock_iolink_pd_stop_cnt = 0; diag_entry_t mock_iolink_al_events[6]; iolink_sm_portmode_t mock_iolink_sm_portmode = IOLINK_SM_PORTMODE_INACTIVE; iolink_smi_errortypes_t mock_iolink_al_read_errortype = IOLINK_SMI_ERRORTYPE_NONE; -iolink_smi_errortypes_t mock_iolink_al_write_errortype = IOLINK_SMI_ERRORTYPE_NONE; +iolink_smi_errortypes_t mock_iolink_al_write_errortype = + IOLINK_SMI_ERRORTYPE_NONE; iolink_controlcode_t mock_iolink_controlcode = IOLINK_CONTROLCODE_NONE; -void (*mock_iolink_al_write_cnf_cb)(iolink_port_t * port, - iolink_smi_errortypes_t errortype); -void (*mock_iolink_al_read_cnf_cb)(iolink_port_t * port, uint8_t len, - uint8_t * data, - iolink_smi_errortypes_t errortype); - -uint8_t mock_iolink_smi_cnf_cnt = 0; -uint8_t mock_iolink_smi_joberror_cnt = 0; -uint8_t mock_iolink_smi_portcfg_cnf_cnt = 0; +void (*mock_iolink_al_write_cnf_cb) ( + iolink_port_t * port, + iolink_smi_errortypes_t errortype); +void (*mock_iolink_al_read_cnf_cb) ( + iolink_port_t * port, + uint8_t len, + uint8_t * data, + iolink_smi_errortypes_t errortype); + +uint8_t mock_iolink_smi_cnf_cnt = 0; +uint8_t mock_iolink_smi_joberror_cnt = 0; +uint8_t mock_iolink_smi_portcfg_cnf_cnt = 0; uint8_t mock_iolink_smi_portstatus_cnf_cnt = 0; -uint8_t mock_iolink_smi_portevent_ind_cnt = 0; -uint8_t arg_block_buff[sizeof(arg_block_t) + 64]; +uint8_t mock_iolink_smi_portevent_ind_cnt = 0; +uint8_t arg_block_buff[sizeof (arg_block_t) + 64]; arg_block_t * mock_iolink_smi_arg_block = (arg_block_t *)arg_block_buff; -uint16_t mock_iolink_smi_arg_block_len = 0; +uint16_t mock_iolink_smi_arg_block_len = 0; iolink_arg_block_id_t mock_iolink_smi_ref_arg_block_id = - IOLINK_ARG_BLOCK_ID_MASTERIDENT; + IOLINK_ARG_BLOCK_ID_MASTERIDENT; iolink_smp_parameterlist_t mock_iolink_cfg_paraml; iolink_job_t mock_iolink_job; -iolink_error_t mock_DL_Write_req (iolink_port_t * port, uint8_t address, - uint8_t value) +iolink_error_t mock_DL_Write_req (iolink_port_t * port, uint8_t address, uint8_t value) { - (void) port; - if (address == IOL_DIR_PARAMA_MASTER_CMD) { + (void)port; + if (address == IOL_DIR_PARAMA_MASTER_CMD) + { if (value == IOL_MASTERCMD_DEVICE_IDENT) mock_iolink_restart_device_cnt++; else if (value == IOL_MASTERCMD_MASTER_IDENT) @@ -164,12 +167,14 @@ iolink_error_t mock_DL_Read_req (iolink_port_t * port, uint8_t address) } DL_Read_cnf (port, data, IOLINK_STATUS_NO_ERROR); - //IOLINK_DL_EVENT_TIMEOUT; + // IOLINK_DL_EVENT_TIMEOUT; return IOLINK_ERROR_NONE; } -iolink_error_t mock_DL_SetMode_req (iolink_port_t * port, iolink_dl_mode_t mode, - iolink_mode_vl_t *valuelist) +iolink_error_t mock_DL_SetMode_req ( + iolink_port_t * port, + iolink_dl_mode_t mode, + iolink_mode_vl_t * valuelist) { switch (mode) { @@ -185,8 +190,9 @@ iolink_error_t mock_DL_SetMode_req (iolink_port_t * port, iolink_dl_mode_t mode, return IOLINK_ERROR_NONE; } -iolink_error_t mock_DL_Write_Devicemode_req (iolink_port_t * port, - iolink_dl_mode_t devicemode) +iolink_error_t mock_DL_Write_Devicemode_req ( + iolink_port_t * port, + iolink_dl_mode_t devicemode) { switch (devicemode) { @@ -205,12 +211,13 @@ iolink_error_t mock_DL_Write_Devicemode_req (iolink_port_t * port, return IOLINK_ERROR_NONE; } -iolink_error_t mock_DL_ISDUTransport_req (iolink_port_t * port, - iolink_isdu_vl_t *valuelist) +iolink_error_t mock_DL_ISDUTransport_req ( + iolink_port_t * port, + iolink_isdu_vl_t * valuelist) { if (valuelist->readwrite == IOLINK_RWDIRECTION_WRITE) { - if (valuelist->length <= sizeof(mock_iolink_al_data)) + if (valuelist->length <= sizeof (mock_iolink_al_data)) { mock_iolink_al_data_len = valuelist->length; memcpy (mock_iolink_al_data, valuelist->data_write, valuelist->length); @@ -222,7 +229,6 @@ iolink_error_t mock_DL_ISDUTransport_req (iolink_port_t * port, } else if (valuelist->readwrite == IOLINK_RWDIRECTION_READ) { - } else { @@ -242,26 +248,31 @@ iolink_error_t mock_DL_ReadParam_req (iolink_port_t * port, uint8_t address) return IOLINK_ERROR_NONE; } -iolink_error_t mock_DL_WriteParam_req (iolink_port_t * port, uint8_t address, - uint8_t value) +iolink_error_t mock_DL_WriteParam_req ( + iolink_port_t * port, + uint8_t address, + uint8_t value) { mock_iolink_al_data_len = 1; - mock_iolink_al_data[0] = value; + mock_iolink_al_data[0] = value; return IOLINK_ERROR_NONE; } -iolink_error_t mock_DL_Control_req (iolink_port_t * port, - iolink_controlcode_t controlcode, - void (*dl_control_cnf_cb)(iolink_port_t * port)) +iolink_error_t mock_DL_Control_req ( + iolink_port_t * port, + iolink_controlcode_t controlcode, + void (*dl_control_cnf_cb) (iolink_port_t * port)) { mock_iolink_dl_control_req_cnt++; return IOLINK_ERROR_NONE; } -iolink_error_t mock_DL_PDOutputGet_req (iolink_port_t * port, uint8_t * len, - uint8_t * data) +iolink_error_t mock_DL_PDOutputGet_req ( + iolink_port_t * port, + uint8_t * len, + uint8_t * data) { *len = mock_iolink_dl_pdout_data_len; memcpy (data, mock_iolink_dl_pdout_data, *len); @@ -269,25 +280,36 @@ iolink_error_t mock_DL_PDOutputGet_req (iolink_port_t * port, uint8_t * len, return IOLINK_ERROR_NONE; } -void mock_PL_SetMode_req (iolink_port_t * port, iolink_pl_mode_t mode) {} -void mock_iolink_pl_init (iolink_port_t * port, const char * name) {} +void mock_PL_SetMode_req (iolink_port_t * port, iolink_pl_mode_t mode) +{ +} +void mock_iolink_pl_init (iolink_port_t * port, const char * name) +{ +} -iolink_error_t mock_AL_Read_req (iolink_port_t * port, uint16_t index, - uint8_t subindex, - void (*al_read_cnf_cb)(iolink_port_t * port, - uint8_t len, uint8_t * data, - iolink_smi_errortypes_t errortype)) +iolink_error_t mock_AL_Read_req ( + iolink_port_t * port, + uint16_t index, + uint8_t subindex, + void (*al_read_cnf_cb) ( + iolink_port_t * port, + uint8_t len, + uint8_t * data, + iolink_smi_errortypes_t errortype)) { mock_iolink_al_read_cnf_cb = al_read_cnf_cb; mock_iolink_al_read_req_cnt++; - mock_iolink_al_data_index = index; + mock_iolink_al_data_index = index; mock_iolink_al_data_subindex = subindex; return IOLINK_ERROR_NONE; } -void mock_AL_Read_cnf (iolink_port_t * port, uint8_t len, const uint8_t * data, - iolink_smi_errortypes_t errortype) +void mock_AL_Read_cnf ( + iolink_port_t * port, + uint8_t len, + const uint8_t * data, + iolink_smi_errortypes_t errortype) { if (errortype == IOLINK_SMI_ERRORTYPE_NONE) { @@ -298,24 +320,28 @@ void mock_AL_Read_cnf (iolink_port_t * port, uint8_t len, const uint8_t * data, mock_iolink_al_read_errortype = errortype; } -void mock_AL_Event_ind (iolink_port_t * port, uint8_t event_cnt, - diag_entry_t events[6]) +void mock_AL_Event_ind ( + iolink_port_t * port, + uint8_t event_cnt, + diag_entry_t events[6]) { mock_iolink_al_event_cnt = event_cnt; - memcpy (mock_iolink_al_events, events, event_cnt * sizeof(diag_entry_t)); + memcpy (mock_iolink_al_events, events, event_cnt * sizeof (diag_entry_t)); } -iolink_error_t mock_AL_Write_req (iolink_port_t * port, uint16_t index, - uint8_t subindex, uint8_t len, - const uint8_t * data, - void (*al_write_cb)(iolink_port_t * port, - iolink_smi_errortypes_t errortype)) +iolink_error_t mock_AL_Write_req ( + iolink_port_t * port, + uint16_t index, + uint8_t subindex, + uint8_t len, + const uint8_t * data, + void (*al_write_cb) (iolink_port_t * port, iolink_smi_errortypes_t errortype)) { mock_iolink_al_write_req_cnt++; mock_iolink_al_write_cnf_cb = al_write_cb; memcpy (mock_iolink_al_data, data, len); - mock_iolink_al_data_index = index; + mock_iolink_al_data_index = index; mock_iolink_al_data_subindex = subindex; return IOLINK_ERROR_NONE; @@ -327,8 +353,9 @@ void mock_AL_Write_cnf (iolink_port_t * port, iolink_smi_errortypes_t errortype) mock_iolink_al_write_errortype = errortype; } -iolink_error_t mock_AL_Control_req (iolink_port_t * port, - iolink_controlcode_t controlcode) +iolink_error_t mock_AL_Control_req ( + iolink_port_t * port, + iolink_controlcode_t controlcode) { mock_iolink_al_control_req_cnt++; mock_iolink_controlcode = controlcode; @@ -336,8 +363,9 @@ iolink_error_t mock_AL_Control_req (iolink_port_t * port, return IOLINK_ERROR_NONE; } -iolink_error_t mock_AL_Control_ind (iolink_port_t * port, - iolink_controlcode_t controlcode) +iolink_error_t mock_AL_Control_ind ( + iolink_port_t * port, + iolink_controlcode_t controlcode) { mock_iolink_al_control_ind_cnt++; mock_iolink_controlcode = controlcode; @@ -345,10 +373,12 @@ iolink_error_t mock_AL_Control_ind (iolink_port_t * port, return IOLINK_ERROR_NONE; } -iolink_error_t mock_AL_SetOutput_req (iolink_port_t * port, uint8_t len, - uint8_t * data) +iolink_error_t mock_AL_SetOutput_req ( + iolink_port_t * port, + uint8_t len, + uint8_t * data) { - if (len <= sizeof(mock_iolink_dl_pdout_data)) + if (len <= sizeof (mock_iolink_dl_pdout_data)) { mock_iolink_dl_pdout_data_len = len; memcpy (mock_iolink_dl_pdout_data, data, len); @@ -362,8 +392,10 @@ iolink_error_t mock_AL_SetOutput_req (iolink_port_t * port, uint8_t len, return IOLINK_ERROR_NONE; } -iolink_error_t mock_AL_GetInput_req (iolink_port_t * port, uint8_t * len, - uint8_t * data) +iolink_error_t mock_AL_GetInput_req ( + iolink_port_t * port, + uint8_t * len, + uint8_t * data) { *len = mock_iolink_dl_pdin_data_len; memcpy (data, mock_iolink_dl_pdin_data, *len); @@ -372,8 +404,10 @@ iolink_error_t mock_AL_GetInput_req (iolink_port_t * port, uint8_t * len, return IOLINK_ERROR_NONE; } -iolink_error_t mock_AL_GetInputOutput_req (iolink_port_t * port, uint8_t * len, - uint8_t * data) +iolink_error_t mock_AL_GetInputOutput_req ( + iolink_port_t * port, + uint8_t * len, + uint8_t * data) { uint8_t pdin_len; uint8_t * pdin_data; @@ -382,7 +416,7 @@ iolink_error_t mock_AL_GetInputOutput_req (iolink_port_t * port, uint8_t * len, /* PDIn data length */ pdin_len = mock_iolink_dl_pdin_data_len; - data[0] = pdin_len; + data[0] = pdin_len; /* PDIn_data[0] */ pdin_data = &data[1]; memcpy (pdin_data, mock_iolink_dl_pdin_data, pdin_len); @@ -408,10 +442,12 @@ iolink_error_t mock_AL_NewInput_ind (iolink_port_t * port) return IOLINK_ERROR_NONE; } -iolink_error_t mock_DL_PDOutputUpdate_req (iolink_port_t * port, uint8_t len, - uint8_t *outputdata) +iolink_error_t mock_DL_PDOutputUpdate_req ( + iolink_port_t * port, + uint8_t len, + uint8_t * outputdata) { - if (len <= sizeof(mock_iolink_dl_pdout_data)) + if (len <= sizeof (mock_iolink_dl_pdout_data)) { mock_iolink_dl_pdout_data_len = len; memcpy (mock_iolink_dl_pdout_data, outputdata, len); @@ -435,14 +471,14 @@ void mock_SM_PortMode_ind (iolink_port_t * port, iolink_sm_portmode_t mode) mock_iolink_sm_portmode = mode; } -iolink_error_t mock_SM_SetPortConfig_req (iolink_port_t * port, - iolink_smp_parameterlist_t * parameterlist) +iolink_error_t mock_SM_SetPortConfig_req ( + iolink_port_t * port, + iolink_smp_parameterlist_t * parameterlist) { - iolink_sm_port_t * sm = iolink_get_sm_ctx (port); + iolink_sm_port_t * sm = iolink_get_sm_ctx (port); iolink_smp_parameterlist_t * real_paramlist = &sm->real_paramlist; - memcpy (&mock_iolink_cfg_paraml, parameterlist, - sizeof(mock_iolink_cfg_paraml)); + memcpy (&mock_iolink_cfg_paraml, parameterlist, sizeof (mock_iolink_cfg_paraml)); switch (mock_iolink_trans_rate) { @@ -538,9 +574,12 @@ iolink_error_t mock_PD_Stop (iolink_port_t * port) return IOLINK_ERROR_NONE; } -void mock_SMI_cnf (void * arg, uint8_t portnumber, - iolink_arg_block_id_t ref_arg_block_id, - uint16_t arg_block_len, arg_block_t * arg_block) +void mock_SMI_cnf ( + void * arg, + uint8_t portnumber, + iolink_arg_block_id_t ref_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block) { iolink_arg_block_id_t arg_block_id = arg_block->void_block.arg_block_id; @@ -549,7 +588,7 @@ void mock_SMI_cnf (void * arg, uint8_t portnumber, else if (ref_arg_block_id == IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST) mock_iolink_smi_portcfg_cnf_cnt++; else if (arg_block_id == IOLINK_ARG_BLOCK_ID_PORT_STATUS_LIST) - mock_iolink_smi_portstatus_cnf_cnt++; + mock_iolink_smi_portstatus_cnf_cnt++; else if (arg_block_id == IOLINK_ARG_BLOCK_ID_PORT_EVENT) mock_iolink_smi_portevent_ind_cnt++; else @@ -557,12 +596,11 @@ void mock_SMI_cnf (void * arg, uint8_t portnumber, memcpy (mock_iolink_smi_arg_block, arg_block, arg_block_len); - mock_iolink_smi_arg_block_len = arg_block_len; + mock_iolink_smi_arg_block_len = arg_block_len; mock_iolink_smi_ref_arg_block_id = ref_arg_block_id; } -static bool mock_os_mbox_post (os_mbox_t * mbox, void * msg, - uint32_t time) +static bool mock_os_mbox_post (os_mbox_t * mbox, void * msg, uint32_t time) { iolink_job_t * job = (iolink_job_t *)msg; diff --git a/test/mocks.h b/test/mocks.h index cfdaaf9..512c1b4 100644 --- a/test/mocks.h +++ b/test/mocks.h @@ -14,8 +14,7 @@ #define MOCKS_H #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif #include "iolink_sm.h" @@ -39,7 +38,7 @@ extern uint8_t mock_iolink_mastercmd_preop_cnt; extern uint8_t mock_iolink_write_devmode_inactive_cnt; extern uint8_t mock_iolink_write_devmode_operate_cnt; extern iolink_job_t mock_iolink_job; -extern uint8_t mock_iolink_al_data [64]; +extern uint8_t mock_iolink_al_data[64]; extern uint8_t mock_iolink_al_data_len; extern uint16_t mock_iolink_al_data_index; extern uint8_t mock_iolink_al_data_subindex; @@ -49,9 +48,9 @@ extern uint8_t mock_iolink_al_write_cnf_cnt; extern uint8_t mock_iolink_al_write_req_cnt; extern uint8_t mock_iolink_al_control_req_cnt; extern uint8_t mock_iolink_al_control_ind_cnt; -extern uint8_t mock_iolink_dl_pdout_data [IOLINK_PD_MAX_SIZE]; +extern uint8_t mock_iolink_dl_pdout_data[IOLINK_PD_MAX_SIZE]; extern uint8_t mock_iolink_dl_pdout_data_len; -extern uint8_t mock_iolink_dl_pdin_data [IOLINK_PD_MAX_SIZE]; +extern uint8_t mock_iolink_dl_pdin_data[IOLINK_PD_MAX_SIZE]; extern uint8_t mock_iolink_dl_pdin_data_len; extern uint8_t mock_iolink_dl_control_req_cnt; extern uint8_t mock_iolink_dl_eventconf_req_cnt; @@ -85,61 +84,96 @@ extern uint8_t mock_iolink_smi_portevent_ind_cnt; extern uint16_t mock_iolink_smi_arg_block_len; extern iolink_arg_block_id_t mock_iolink_smi_ref_arg_block_id; -extern void (*mock_iolink_al_write_cnf_cb)(iolink_port_t * port, - iolink_smi_errortypes_t errortype); -extern void (*mock_iolink_al_read_cnf_cb)(iolink_port_t * port, uint8_t len, - uint8_t * data, - iolink_smi_errortypes_t errortype); - - -iolink_error_t mock_DL_Write_req (iolink_port_t * port, uint8_t address, - uint8_t value); +extern void (*mock_iolink_al_write_cnf_cb) ( + iolink_port_t * port, + iolink_smi_errortypes_t errortype); +extern void (*mock_iolink_al_read_cnf_cb) ( + iolink_port_t * port, + uint8_t len, + uint8_t * data, + iolink_smi_errortypes_t errortype); + +iolink_error_t mock_DL_Write_req ( + iolink_port_t * port, + uint8_t address, + uint8_t value); iolink_error_t mock_DL_Read_req (iolink_port_t * port, uint8_t address); -iolink_error_t mock_DL_SetMode_req (iolink_port_t * port, iolink_dl_mode_t mode, - iolink_mode_vl_t *valuelist); -iolink_error_t mock_DL_Write_Devicemode_req (iolink_port_t * port, - iolink_dl_mode_t devicemode); +iolink_error_t mock_DL_SetMode_req ( + iolink_port_t * port, + iolink_dl_mode_t mode, + iolink_mode_vl_t * valuelist); +iolink_error_t mock_DL_Write_Devicemode_req ( + iolink_port_t * port, + iolink_dl_mode_t devicemode); iolink_error_t mock_DL_EventConf_req (iolink_port_t * port); iolink_error_t mock_DL_ReadParam_req (iolink_port_t * port, uint8_t address); -iolink_error_t mock_DL_WriteParam_req (iolink_port_t * port, uint8_t address, - uint8_t value); -iolink_error_t mock_DL_ISDUTransport_req (iolink_port_t * port, - iolink_isdu_vl_t *valuelist); -iolink_error_t mock_DL_Control_req (iolink_port_t * port, - iolink_controlcode_t controlcode, - void (*dl_control_cnf_cb)(iolink_port_t * port)); -iolink_error_t mock_DL_PDOutputGet_req (iolink_port_t * port, uint8_t * len, - uint8_t * data); -iolink_error_t mock_DL_PDOutputUpdate_req (iolink_port_t * port, uint8_t len, - uint8_t *outputdata); -iolink_error_t mock_DL_PDOutputUpdate (iolink_port_t * port, uint8_t len, - uint8_t *outputdata); -iolink_error_t mock_AL_Read_req (iolink_port_t * port, uint16_t index, - uint8_t subindex, - void (*al_read_cnf_cb)(iolink_port_t * port, - uint8_t len, uint8_t * data, - iolink_smi_errortypes_t errortype)); -void mock_AL_Read_cnf (iolink_port_t * port, uint8_t len, const uint8_t * data, - iolink_smi_errortypes_t errortype); -iolink_error_t mock_AL_Write_req (iolink_port_t * port, uint16_t index, - uint8_t subindex, uint8_t len, - const uint8_t * data, - void (*al_write_cb)(iolink_port_t * port, - iolink_smi_errortypes_t errortype)); -void mock_AL_Write_cnf (iolink_port_t * port, - iolink_smi_errortypes_t errortype); -void mock_AL_Event_ind (iolink_port_t * port, uint8_t event_cnt, - diag_entry_t events[6]); -iolink_error_t mock_AL_Control_req (iolink_port_t * port, - iolink_controlcode_t controlcode); -iolink_error_t mock_AL_Control_ind (iolink_port_t * port, - iolink_controlcode_t controlcode); -iolink_error_t mock_AL_SetOutput_req (iolink_port_t * port, uint8_t len, - uint8_t * data); -iolink_error_t mock_AL_GetInputOutput_req (iolink_port_t * port, uint8_t * len, - uint8_t * data); -iolink_error_t mock_AL_GetInput_req (iolink_port_t * port, uint8_t * len, - uint8_t * data); +iolink_error_t mock_DL_WriteParam_req ( + iolink_port_t * port, + uint8_t address, + uint8_t value); +iolink_error_t mock_DL_ISDUTransport_req ( + iolink_port_t * port, + iolink_isdu_vl_t * valuelist); +iolink_error_t mock_DL_Control_req ( + iolink_port_t * port, + iolink_controlcode_t controlcode, + void (*dl_control_cnf_cb) (iolink_port_t * port)); +iolink_error_t mock_DL_PDOutputGet_req ( + iolink_port_t * port, + uint8_t * len, + uint8_t * data); +iolink_error_t mock_DL_PDOutputUpdate_req ( + iolink_port_t * port, + uint8_t len, + uint8_t * outputdata); +iolink_error_t mock_DL_PDOutputUpdate ( + iolink_port_t * port, + uint8_t len, + uint8_t * outputdata); +iolink_error_t mock_AL_Read_req ( + iolink_port_t * port, + uint16_t index, + uint8_t subindex, + void (*al_read_cnf_cb) ( + iolink_port_t * port, + uint8_t len, + uint8_t * data, + iolink_smi_errortypes_t errortype)); +void mock_AL_Read_cnf ( + iolink_port_t * port, + uint8_t len, + const uint8_t * data, + iolink_smi_errortypes_t errortype); +iolink_error_t mock_AL_Write_req ( + iolink_port_t * port, + uint16_t index, + uint8_t subindex, + uint8_t len, + const uint8_t * data, + void (*al_write_cb) (iolink_port_t * port, iolink_smi_errortypes_t errortype)); +void mock_AL_Write_cnf (iolink_port_t * port, iolink_smi_errortypes_t errortype); +void mock_AL_Event_ind ( + iolink_port_t * port, + uint8_t event_cnt, + diag_entry_t events[6]); +iolink_error_t mock_AL_Control_req ( + iolink_port_t * port, + iolink_controlcode_t controlcode); +iolink_error_t mock_AL_Control_ind ( + iolink_port_t * port, + iolink_controlcode_t controlcode); +iolink_error_t mock_AL_SetOutput_req ( + iolink_port_t * port, + uint8_t len, + uint8_t * data); +iolink_error_t mock_AL_GetInputOutput_req ( + iolink_port_t * port, + uint8_t * len, + uint8_t * data); +iolink_error_t mock_AL_GetInput_req ( + iolink_port_t * port, + uint8_t * len, + uint8_t * data); iolink_error_t mock_AL_NewInput_ind (iolink_port_t * port); void mock_PL_SetMode_req (iolink_port_t * port, iolink_pl_mode_t mode); @@ -160,12 +194,16 @@ iolink_error_t mock_OD_Stop (iolink_port_t * port); iolink_error_t mock_PD_Start (iolink_port_t * port); iolink_error_t mock_PD_Stop (iolink_port_t * port); -void mock_SMI_cnf (void * arg, uint8_t portnumber, - iolink_arg_block_id_t ref_arg_block_id, - uint16_t arg_block_len, arg_block_t * arg_block); +void mock_SMI_cnf ( + void * arg, + uint8_t portnumber, + iolink_arg_block_id_t ref_arg_block_id, + uint16_t arg_block_len, + arg_block_t * arg_block); -iolink_error_t mock_SM_SetPortConfig_req (iolink_port_t * port, - iolink_smp_parameterlist_t * parameterlist); +iolink_error_t mock_SM_SetPortConfig_req ( + iolink_port_t * port, + iolink_smp_parameterlist_t * parameterlist); bool mock_iolink_post_job (iolink_port_t * port, iolink_job_t * job); iolink_job_t * mock_iolink_fetch_avail_job (iolink_port_t * port); diff --git a/test/test_al.cpp b/test/test_al.cpp index d2c983c..8591912 100644 --- a/test/test_al.cpp +++ b/test/test_al.cpp @@ -22,9 +22,10 @@ class ALTest : public TestBase { -protected: + protected: // Override default setup - virtual void SetUp() { + virtual void SetUp() + { TestBase::SetUp(); // Re-use default setup }; }; @@ -32,8 +33,8 @@ class ALTest : public TestBase // Tests TEST_F (ALTest, Al_read_param_0_1) { - uint16_t index = 0; - uint8_t subindex = 0; + uint16_t index = 0; + uint8_t subindex = 0; uint8_t read_value = 0x12; for (index = 0; index < 2; index++) @@ -56,7 +57,7 @@ TEST_F (ALTest, Al_read_param_0_1) EXPECT_EQ (mock_iolink_al_write_cnf_cnt, 0); EXPECT_EQ (mock_iolink_dl_control_req_cnt, 0); - mock_iolink_al_data[0] = 0; + mock_iolink_al_data[0] = 0; mock_iolink_al_data_len = 0; read_value++; } @@ -66,25 +67,28 @@ TEST_F (ALTest, Al_read_isdu_2) { iolink_al_port_t * al = iolink_get_al_ctx (port); - uint16_t index = 2; + uint16_t index = 2; uint8_t subindex = 0; - uint8_t data[8] = {1, 2, 3, 4, 5, 6, 7, 8}; + uint8_t data[8] = {1, 2, 3, 4, 5, 6, 7, 8}; EXPECT_EQ (AL_OD_STATE_OnReq_Idle, al->od_state); AL_Read_req (port, index, subindex, mock_AL_Read_cnf); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (AL_OD_STATE_Await_DL_ISDU_cnf, al->od_state); - DL_ISDUTransport_cnf (port, data, sizeof(data), - IOL_ISERVICE_DEVICE_READ_RESPONSE_POS, - IOLINK_STATUS_NO_ERROR); + DL_ISDUTransport_cnf ( + port, + data, + sizeof (data), + IOL_ISERVICE_DEVICE_READ_RESPONSE_POS, + IOLINK_STATUS_NO_ERROR); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (AL_OD_STATE_OnReq_Idle, al->od_state); EXPECT_EQ (mock_iolink_al_read_cnf_cnt, 1); EXPECT_EQ (mock_iolink_al_read_errortype, IOLINK_SMI_ERRORTYPE_NONE); - EXPECT_EQ (mock_iolink_al_data_len, sizeof(data)); - EXPECT_TRUE (ArraysMatchN (data, mock_iolink_al_data, sizeof(data))); + EXPECT_EQ (mock_iolink_al_data_len, sizeof (data)); + EXPECT_TRUE (ArraysMatchN (data, mock_iolink_al_data, sizeof (data))); EXPECT_EQ (mock_iolink_al_write_cnf_cnt, 0); EXPECT_EQ (mock_iolink_dl_control_req_cnt, 0); } @@ -93,17 +97,19 @@ TEST_F (ALTest, Al_write_0_err) { iolink_al_port_t * al = iolink_get_al_ctx (port); - uint16_t index = 0; /* Not allowed to write to index 0 */ + uint16_t index = 0; /* Not allowed to write to index 0 */ uint8_t subindex = 0; - uint8_t data[1] = {0x34}; + uint8_t data[1] = {0x34}; EXPECT_EQ (AL_OD_STATE_OnReq_Idle, al->od_state); - AL_Write_req (port, index, subindex, sizeof(data), data, mock_AL_Write_cnf); + AL_Write_req (port, index, subindex, sizeof (data), data, mock_AL_Write_cnf); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (AL_OD_STATE_OnReq_Idle, al->od_state); EXPECT_EQ (mock_iolink_al_write_cnf_cnt, 1); - EXPECT_EQ (mock_iolink_al_write_errortype, IOLINK_SMI_ERRORTYPE_APP_DEV); // TODO what to expect here? + EXPECT_EQ ( + mock_iolink_al_write_errortype, + IOLINK_SMI_ERRORTYPE_APP_DEV); // TODO what to expect here? EXPECT_EQ (mock_iolink_al_read_cnf_cnt, 0); EXPECT_EQ (mock_iolink_dl_control_req_cnt, 0); } @@ -112,12 +118,12 @@ TEST_F (ALTest, Al_write_param_1) { iolink_al_port_t * al = iolink_get_al_ctx (port); - uint16_t index = 1; + uint16_t index = 1; uint8_t subindex = 0; - uint8_t data[1] = {0x34}; + uint8_t data[1] = {0x34}; EXPECT_EQ (AL_OD_STATE_OnReq_Idle, al->od_state); - AL_Write_req (port, index, subindex, sizeof(data), data, mock_AL_Write_cnf); + AL_Write_req (port, index, subindex, sizeof (data), data, mock_AL_Write_cnf); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (AL_OD_STATE_Await_DL_param_cnf, al->od_state); @@ -127,14 +133,14 @@ TEST_F (ALTest, Al_write_param_1) EXPECT_EQ (mock_iolink_al_write_cnf_cnt, 1); EXPECT_EQ (mock_iolink_al_write_errortype, IOLINK_SMI_ERRORTYPE_NONE); - EXPECT_EQ (mock_iolink_al_data_len, sizeof(data)); - EXPECT_TRUE (ArraysMatchN (data, mock_iolink_al_data, sizeof(data))); + EXPECT_EQ (mock_iolink_al_data_len, sizeof (data)); + EXPECT_TRUE (ArraysMatchN (data, mock_iolink_al_data, sizeof (data))); EXPECT_EQ (mock_iolink_al_read_cnf_cnt, 0); EXPECT_EQ (mock_iolink_dl_control_req_cnt, 0); } // TODO -//TEST_F (ALTest, Al_write_param_no_isdu_2) +// TEST_F (ALTest, Al_write_param_no_isdu_2) //{ // uint16_t index = 2; // uint8_t subindex = 0; @@ -161,31 +167,35 @@ TEST_F (ALTest, Al_write_param_isdu_2) { iolink_al_port_t * al = iolink_get_al_ctx (port); - uint16_t index = 2; + uint16_t index = 2; uint8_t subindex = 0; uint8_t data[12] = {3, 2, 3, 4, 1, 5, 6, 8, 9, 1}; EXPECT_EQ (AL_OD_STATE_OnReq_Idle, al->od_state); - AL_Write_req (port, index, subindex, sizeof(data), data, mock_AL_Write_cnf); + AL_Write_req (port, index, subindex, sizeof (data), data, mock_AL_Write_cnf); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (AL_OD_STATE_Await_DL_ISDU_cnf, al->od_state); - DL_ISDUTransport_cnf (port, data, sizeof(data), - IOL_ISERVICE_DEVICE_WRITE_RESPONSE_POS, - IOLINK_STATUS_NO_ERROR); + DL_ISDUTransport_cnf ( + port, + data, + sizeof (data), + IOL_ISERVICE_DEVICE_WRITE_RESPONSE_POS, + IOLINK_STATUS_NO_ERROR); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (AL_OD_STATE_OnReq_Idle, al->od_state); EXPECT_EQ (mock_iolink_al_write_cnf_cnt, 1); EXPECT_EQ (mock_iolink_al_write_errortype, IOLINK_SMI_ERRORTYPE_NONE); - EXPECT_EQ (mock_iolink_al_data_len, sizeof(data)); - EXPECT_TRUE (ArraysMatchN (data, mock_iolink_al_data, sizeof(data))); + EXPECT_EQ (mock_iolink_al_data_len, sizeof (data)); + EXPECT_TRUE (ArraysMatchN (data, mock_iolink_al_data, sizeof (data))); EXPECT_EQ (mock_iolink_al_read_cnf_cnt, 0); EXPECT_EQ (mock_iolink_dl_control_req_cnt, 0); } -static inline void test_al_control (iolink_port_t * port, - iolink_controlcode_t controlcode) +static inline void test_al_control ( + iolink_port_t * port, + iolink_controlcode_t controlcode) { iolink_al_port_t * al = iolink_get_al_ctx (port); @@ -244,7 +254,7 @@ TEST_F (ALTest, Al_abort) TEST_F (ALTest, Al_read_param_abort_0_1) { - uint16_t index = 0; + uint16_t index = 0; uint8_t subindex = 0; for (index = 0; index < 2; index++) @@ -263,7 +273,9 @@ TEST_F (ALTest, Al_read_param_abort_0_1) EXPECT_EQ (AL_OD_STATE_OnReq_Idle, al->od_state); EXPECT_EQ (mock_iolink_al_read_cnf_cnt, index + 1); - EXPECT_EQ (mock_iolink_al_read_errortype, IOLINK_SMI_ERRORTYPE_APP_DEV); // TODO what to expect here? + EXPECT_EQ ( + mock_iolink_al_read_errortype, + IOLINK_SMI_ERRORTYPE_APP_DEV); // TODO what to expect here? EXPECT_EQ (mock_iolink_al_data_len, 0); EXPECT_EQ (mock_iolink_al_write_cnf_cnt, 0); EXPECT_EQ (mock_iolink_dl_control_req_cnt, 0); @@ -274,7 +286,7 @@ TEST_F (ALTest, Al_read_isdu_abort_2) { iolink_al_port_t * al = iolink_get_al_ctx (port); - uint16_t index = 2; + uint16_t index = 2; uint8_t subindex = 0; EXPECT_EQ (AL_OD_STATE_OnReq_Idle, al->od_state); @@ -289,7 +301,9 @@ TEST_F (ALTest, Al_read_isdu_abort_2) EXPECT_EQ (AL_OD_STATE_OnReq_Idle, al->od_state); EXPECT_EQ (mock_iolink_al_read_cnf_cnt, 1); - EXPECT_EQ (mock_iolink_al_read_errortype, IOLINK_SMI_ERRORTYPE_APP_DEV); // TODO what to expect here? + EXPECT_EQ ( + mock_iolink_al_read_errortype, + IOLINK_SMI_ERRORTYPE_APP_DEV); // TODO what to expect here? EXPECT_EQ (mock_iolink_al_data_len, 0); EXPECT_EQ (mock_iolink_al_write_cnf_cnt, 0); EXPECT_EQ (mock_iolink_dl_control_req_cnt, 0); @@ -299,12 +313,12 @@ TEST_F (ALTest, Al_write_param_abort_1) { iolink_al_port_t * al = iolink_get_al_ctx (port); - uint16_t index = 1; + uint16_t index = 1; uint8_t subindex = 0; - uint8_t data[1] = {0x34}; + uint8_t data[1] = {0x34}; EXPECT_EQ (AL_OD_STATE_OnReq_Idle, al->od_state); - AL_Write_req (port, index, subindex, sizeof(data), data, mock_AL_Write_cnf); + AL_Write_req (port, index, subindex, sizeof (data), data, mock_AL_Write_cnf); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (AL_OD_STATE_Await_DL_param_cnf, al->od_state); @@ -314,11 +328,13 @@ TEST_F (ALTest, Al_write_param_abort_1) EXPECT_EQ (AL_OD_STATE_OnReq_Idle, al->od_state); EXPECT_EQ (mock_iolink_al_write_cnf_cnt, 1); - EXPECT_EQ (mock_iolink_al_write_errortype, IOLINK_SMI_ERRORTYPE_APP_DEV); // TODO what to expect here? + EXPECT_EQ ( + mock_iolink_al_write_errortype, + IOLINK_SMI_ERRORTYPE_APP_DEV); // TODO what to expect here? /* al_data_len is assigned after AL_Write_req() * Hence, this is expected */ - EXPECT_EQ (mock_iolink_al_data_len, sizeof(data)); + EXPECT_EQ (mock_iolink_al_data_len, sizeof (data)); EXPECT_EQ (mock_iolink_al_read_cnf_cnt, 0); EXPECT_EQ (mock_iolink_dl_control_req_cnt, 0); } @@ -327,12 +343,12 @@ TEST_F (ALTest, Al_write_param_abort_isdu_2) { iolink_al_port_t * al = iolink_get_al_ctx (port); - uint16_t index = 2; + uint16_t index = 2; uint8_t subindex = 0; uint8_t data[12] = {3, 2, 3, 4, 1, 5, 6, 8, 9, 1}; EXPECT_EQ (AL_OD_STATE_OnReq_Idle, al->od_state); - AL_Write_req (port, index, subindex, sizeof(data), data, mock_AL_Write_cnf); + AL_Write_req (port, index, subindex, sizeof (data), data, mock_AL_Write_cnf); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (AL_OD_STATE_Await_DL_ISDU_cnf, al->od_state); @@ -342,23 +358,24 @@ TEST_F (ALTest, Al_write_param_abort_isdu_2) EXPECT_EQ (AL_OD_STATE_OnReq_Idle, al->od_state); EXPECT_EQ (mock_iolink_al_write_cnf_cnt, 1); - EXPECT_EQ (mock_iolink_al_write_errortype, IOLINK_SMI_ERRORTYPE_APP_DEV); // TODO what to expect here? + EXPECT_EQ ( + mock_iolink_al_write_errortype, + IOLINK_SMI_ERRORTYPE_APP_DEV); // TODO what to expect here? /* al_data_len is assigned after AL_Write_req() * Hence, this is expected */ - EXPECT_EQ (mock_iolink_al_data_len, sizeof(data)); + EXPECT_EQ (mock_iolink_al_data_len, sizeof (data)); EXPECT_EQ (mock_iolink_al_read_cnf_cnt, 0); EXPECT_EQ (mock_iolink_dl_control_req_cnt, 0); } // TODO -//TEST_F (ALTest, Al_write_param_abort_no_isdu_2) - +// TEST_F (ALTest, Al_write_param_abort_no_isdu_2) TEST_F (ALTest, Al_read_param_0_1_multiple_al_service_calls) { - uint16_t index = 0; - uint8_t subindex = 0; + uint16_t index = 0; + uint8_t subindex = 0; uint8_t read_value = 0x12; for (index = 0; index < 2; index++) @@ -375,16 +392,18 @@ TEST_F (ALTest, Al_read_param_0_1_multiple_al_service_calls) mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (mock_iolink_al_data_len, 0); EXPECT_EQ (mock_iolink_al_read_cnf_cnt, (index * 2) + 1); - EXPECT_EQ (mock_iolink_al_read_errortype, - IOLINK_SMI_ERRORTYPE_SERVICE_TEMP_UNAVAILABLE); + EXPECT_EQ ( + mock_iolink_al_read_errortype, + IOLINK_SMI_ERRORTYPE_SERVICE_TEMP_UNAVAILABLE); AL_Write_req (port, index, subindex, 0, NULL, mock_AL_Write_cnf); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (mock_iolink_al_data_len, 0); EXPECT_EQ (mock_iolink_al_write_cnf_cnt, index + 1); EXPECT_EQ (mock_iolink_al_read_cnf_cnt, (index * 2) + 1); - EXPECT_EQ (mock_iolink_al_read_errortype, - IOLINK_SMI_ERRORTYPE_SERVICE_TEMP_UNAVAILABLE); + EXPECT_EQ ( + mock_iolink_al_read_errortype, + IOLINK_SMI_ERRORTYPE_SERVICE_TEMP_UNAVAILABLE); DL_ReadParam_cnf (port, read_value, IOLINK_STATUS_NO_ERROR); mock_iolink_job.callback (&mock_iolink_job); @@ -397,14 +416,16 @@ TEST_F (ALTest, Al_read_param_0_1_multiple_al_service_calls) EXPECT_EQ (mock_iolink_al_write_cnf_cnt, index + 1); EXPECT_EQ (mock_iolink_dl_control_req_cnt, 0); - mock_iolink_al_data[0] = 0; + mock_iolink_al_data[0] = 0; mock_iolink_al_data_len = 0; read_value++; } } -static inline void al_verify_events (iolink_port_t * port, uint8_t event_cnt, - al_event_t * events) +static inline void al_verify_events ( + iolink_port_t * port, + uint8_t event_cnt, + al_event_t * events) { iolink_al_port_t * al = iolink_get_al_ctx (port); unsigned int i; @@ -444,10 +465,10 @@ TEST_F (ALTest, Al_Event_1) al_event_t events[1]; events[0].eventcode = 1; - events[0].instance = IOLINK_EVENT_INSTANCE_APPLICATION; - events[0].mode = IOLINK_EVENT_MODE_SINGLE_SHOT; - events[0].type = IOLINK_EVENT_TYPE_NOTIFICATION; - events[0].source = IOLINK_EVENT_SOURCE_DEVICE; + events[0].instance = IOLINK_EVENT_INSTANCE_APPLICATION; + events[0].mode = IOLINK_EVENT_MODE_SINGLE_SHOT; + events[0].type = IOLINK_EVENT_TYPE_NOTIFICATION; + events[0].source = IOLINK_EVENT_SOURCE_DEVICE; al_verify_events (port, ARRAY_SIZE (events), events); } @@ -457,16 +478,16 @@ TEST_F (ALTest, Al_Event_2) al_event_t events[2]; events[0].eventcode = 1; - events[0].instance = IOLINK_EVENT_INSTANCE_APPLICATION; - events[0].mode = IOLINK_EVENT_MODE_SINGLE_SHOT; - events[0].type = IOLINK_EVENT_TYPE_NOTIFICATION; - events[0].source = IOLINK_EVENT_SOURCE_DEVICE; + events[0].instance = IOLINK_EVENT_INSTANCE_APPLICATION; + events[0].mode = IOLINK_EVENT_MODE_SINGLE_SHOT; + events[0].type = IOLINK_EVENT_TYPE_NOTIFICATION; + events[0].source = IOLINK_EVENT_SOURCE_DEVICE; events[1].eventcode = 2; - events[1].instance = IOLINK_EVENT_INSTANCE_UNKNOWN; - events[1].mode = IOLINK_EVENT_MODE_APPEARS; - events[1].type = IOLINK_EVENT_TYPE_ERROR; - events[1].source = IOLINK_EVENT_SOURCE_MASTER; + events[1].instance = IOLINK_EVENT_INSTANCE_UNKNOWN; + events[1].mode = IOLINK_EVENT_MODE_APPEARS; + events[1].type = IOLINK_EVENT_TYPE_ERROR; + events[1].source = IOLINK_EVENT_SOURCE_MASTER; al_verify_events (port, ARRAY_SIZE (events), events); } @@ -475,22 +496,22 @@ TEST_F (ALTest, Al_Event_3) al_event_t events[3]; events[0].eventcode = 1; - events[0].instance = IOLINK_EVENT_INSTANCE_APPLICATION; - events[0].mode = IOLINK_EVENT_MODE_SINGLE_SHOT; - events[0].type = IOLINK_EVENT_TYPE_NOTIFICATION; - events[0].source = IOLINK_EVENT_SOURCE_DEVICE; + events[0].instance = IOLINK_EVENT_INSTANCE_APPLICATION; + events[0].mode = IOLINK_EVENT_MODE_SINGLE_SHOT; + events[0].type = IOLINK_EVENT_TYPE_NOTIFICATION; + events[0].source = IOLINK_EVENT_SOURCE_DEVICE; events[1].eventcode = 2; - events[1].instance = IOLINK_EVENT_INSTANCE_APPLICATION; - events[1].mode = IOLINK_EVENT_MODE_APPEARS; - events[1].type = IOLINK_EVENT_TYPE_NOTIFICATION; - events[1].source = IOLINK_EVENT_SOURCE_DEVICE; + events[1].instance = IOLINK_EVENT_INSTANCE_APPLICATION; + events[1].mode = IOLINK_EVENT_MODE_APPEARS; + events[1].type = IOLINK_EVENT_TYPE_NOTIFICATION; + events[1].source = IOLINK_EVENT_SOURCE_DEVICE; events[2].eventcode = 3; - events[2].instance = IOLINK_EVENT_INSTANCE_UNKNOWN; - events[2].mode = IOLINK_EVENT_MODE_SINGLE_SHOT; - events[2].type = IOLINK_EVENT_TYPE_ERROR; - events[2].source = IOLINK_EVENT_SOURCE_DEVICE; + events[2].instance = IOLINK_EVENT_INSTANCE_UNKNOWN; + events[2].mode = IOLINK_EVENT_MODE_SINGLE_SHOT; + events[2].type = IOLINK_EVENT_TYPE_ERROR; + events[2].source = IOLINK_EVENT_SOURCE_DEVICE; al_verify_events (port, ARRAY_SIZE (events), events); } @@ -500,28 +521,28 @@ TEST_F (ALTest, Al_Event_4) al_event_t events[4]; events[0].eventcode = 10; - events[0].instance = IOLINK_EVENT_INSTANCE_APPLICATION; - events[0].mode = IOLINK_EVENT_MODE_SINGLE_SHOT; - events[0].type = IOLINK_EVENT_TYPE_WARNING; - events[0].source = IOLINK_EVENT_SOURCE_MASTER; + events[0].instance = IOLINK_EVENT_INSTANCE_APPLICATION; + events[0].mode = IOLINK_EVENT_MODE_SINGLE_SHOT; + events[0].type = IOLINK_EVENT_TYPE_WARNING; + events[0].source = IOLINK_EVENT_SOURCE_MASTER; events[1].eventcode = 12; - events[1].instance = IOLINK_EVENT_INSTANCE_APPLICATION; - events[1].mode = IOLINK_EVENT_MODE_DISAPPEARS; - events[1].type = IOLINK_EVENT_TYPE_NOTIFICATION; - events[1].source = IOLINK_EVENT_SOURCE_DEVICE; + events[1].instance = IOLINK_EVENT_INSTANCE_APPLICATION; + events[1].mode = IOLINK_EVENT_MODE_DISAPPEARS; + events[1].type = IOLINK_EVENT_TYPE_NOTIFICATION; + events[1].source = IOLINK_EVENT_SOURCE_DEVICE; events[2].eventcode = 14; - events[2].instance = IOLINK_EVENT_INSTANCE_UNKNOWN; - events[2].mode = IOLINK_EVENT_MODE_SINGLE_SHOT; - events[2].type = IOLINK_EVENT_TYPE_ERROR; - events[2].source = IOLINK_EVENT_SOURCE_DEVICE; + events[2].instance = IOLINK_EVENT_INSTANCE_UNKNOWN; + events[2].mode = IOLINK_EVENT_MODE_SINGLE_SHOT; + events[2].type = IOLINK_EVENT_TYPE_ERROR; + events[2].source = IOLINK_EVENT_SOURCE_DEVICE; events[3].eventcode = 16; - events[3].instance = IOLINK_EVENT_INSTANCE_APPLICATION; - events[3].mode = IOLINK_EVENT_MODE_APPEARS; - events[3].type = IOLINK_EVENT_TYPE_NOTIFICATION; - events[3].source = IOLINK_EVENT_SOURCE_DEVICE; + events[3].instance = IOLINK_EVENT_INSTANCE_APPLICATION; + events[3].mode = IOLINK_EVENT_MODE_APPEARS; + events[3].type = IOLINK_EVENT_TYPE_NOTIFICATION; + events[3].source = IOLINK_EVENT_SOURCE_DEVICE; al_verify_events (port, ARRAY_SIZE (events), events); } @@ -531,34 +552,34 @@ TEST_F (ALTest, Al_Event_5) al_event_t events[5]; events[0].eventcode = 20; - events[0].instance = IOLINK_EVENT_INSTANCE_APPLICATION; - events[0].mode = IOLINK_EVENT_MODE_SINGLE_SHOT; - events[0].type = IOLINK_EVENT_TYPE_WARNING; - events[0].source = IOLINK_EVENT_SOURCE_DEVICE; + events[0].instance = IOLINK_EVENT_INSTANCE_APPLICATION; + events[0].mode = IOLINK_EVENT_MODE_SINGLE_SHOT; + events[0].type = IOLINK_EVENT_TYPE_WARNING; + events[0].source = IOLINK_EVENT_SOURCE_DEVICE; events[1].eventcode = 21; - events[1].instance = IOLINK_EVENT_INSTANCE_APPLICATION; - events[1].mode = IOLINK_EVENT_MODE_DISAPPEARS; - events[1].type = IOLINK_EVENT_TYPE_NOTIFICATION; - events[1].source = IOLINK_EVENT_SOURCE_MASTER; + events[1].instance = IOLINK_EVENT_INSTANCE_APPLICATION; + events[1].mode = IOLINK_EVENT_MODE_DISAPPEARS; + events[1].type = IOLINK_EVENT_TYPE_NOTIFICATION; + events[1].source = IOLINK_EVENT_SOURCE_MASTER; events[2].eventcode = 22; - events[2].instance = IOLINK_EVENT_INSTANCE_UNKNOWN; - events[2].mode = IOLINK_EVENT_MODE_SINGLE_SHOT; - events[2].type = IOLINK_EVENT_TYPE_ERROR; - events[2].source = IOLINK_EVENT_SOURCE_DEVICE; + events[2].instance = IOLINK_EVENT_INSTANCE_UNKNOWN; + events[2].mode = IOLINK_EVENT_MODE_SINGLE_SHOT; + events[2].type = IOLINK_EVENT_TYPE_ERROR; + events[2].source = IOLINK_EVENT_SOURCE_DEVICE; events[3].eventcode = 23; - events[3].instance = IOLINK_EVENT_INSTANCE_APPLICATION; - events[3].mode = IOLINK_EVENT_MODE_APPEARS; - events[3].type = IOLINK_EVENT_TYPE_NOTIFICATION; - events[3].source = IOLINK_EVENT_SOURCE_DEVICE; + events[3].instance = IOLINK_EVENT_INSTANCE_APPLICATION; + events[3].mode = IOLINK_EVENT_MODE_APPEARS; + events[3].type = IOLINK_EVENT_TYPE_NOTIFICATION; + events[3].source = IOLINK_EVENT_SOURCE_DEVICE; events[4].eventcode = 0xFFFF; - events[4].instance = IOLINK_EVENT_INSTANCE_APPLICATION; - events[4].mode = IOLINK_EVENT_MODE_SINGLE_SHOT; - events[4].type = IOLINK_EVENT_TYPE_WARNING; - events[4].source = IOLINK_EVENT_SOURCE_DEVICE; + events[4].instance = IOLINK_EVENT_INSTANCE_APPLICATION; + events[4].mode = IOLINK_EVENT_MODE_SINGLE_SHOT; + events[4].type = IOLINK_EVENT_TYPE_WARNING; + events[4].source = IOLINK_EVENT_SOURCE_DEVICE; al_verify_events (port, ARRAY_SIZE (events), events); } @@ -568,40 +589,40 @@ TEST_F (ALTest, Al_Event_6) al_event_t events[6]; events[0].eventcode = 0x8CA0; - events[0].instance = IOLINK_EVENT_INSTANCE_APPLICATION; - events[0].mode = IOLINK_EVENT_MODE_SINGLE_SHOT; - events[0].type = IOLINK_EVENT_TYPE_WARNING; - events[0].source = IOLINK_EVENT_SOURCE_DEVICE; + events[0].instance = IOLINK_EVENT_INSTANCE_APPLICATION; + events[0].mode = IOLINK_EVENT_MODE_SINGLE_SHOT; + events[0].type = IOLINK_EVENT_TYPE_WARNING; + events[0].source = IOLINK_EVENT_SOURCE_DEVICE; events[1].eventcode = 0x8CA1; - events[1].instance = IOLINK_EVENT_INSTANCE_APPLICATION; - events[1].mode = IOLINK_EVENT_MODE_DISAPPEARS; - events[1].type = IOLINK_EVENT_TYPE_NOTIFICATION; - events[1].source = IOLINK_EVENT_SOURCE_MASTER; + events[1].instance = IOLINK_EVENT_INSTANCE_APPLICATION; + events[1].mode = IOLINK_EVENT_MODE_DISAPPEARS; + events[1].type = IOLINK_EVENT_TYPE_NOTIFICATION; + events[1].source = IOLINK_EVENT_SOURCE_MASTER; events[2].eventcode = 0x8CCC; - events[2].instance = IOLINK_EVENT_INSTANCE_UNKNOWN; - events[2].mode = IOLINK_EVENT_MODE_APPEARS; - events[2].type = IOLINK_EVENT_TYPE_ERROR; - events[2].source = IOLINK_EVENT_SOURCE_MASTER; + events[2].instance = IOLINK_EVENT_INSTANCE_UNKNOWN; + events[2].mode = IOLINK_EVENT_MODE_APPEARS; + events[2].type = IOLINK_EVENT_TYPE_ERROR; + events[2].source = IOLINK_EVENT_SOURCE_MASTER; events[3].eventcode = 0x8DDD; - events[3].instance = IOLINK_EVENT_INSTANCE_APPLICATION; - events[3].mode = IOLINK_EVENT_MODE_APPEARS; - events[3].type = IOLINK_EVENT_TYPE_NOTIFICATION; - events[3].source = IOLINK_EVENT_SOURCE_DEVICE; + events[3].instance = IOLINK_EVENT_INSTANCE_APPLICATION; + events[3].mode = IOLINK_EVENT_MODE_APPEARS; + events[3].type = IOLINK_EVENT_TYPE_NOTIFICATION; + events[3].source = IOLINK_EVENT_SOURCE_DEVICE; events[4].eventcode = 0x8DFE; - events[4].instance = IOLINK_EVENT_INSTANCE_APPLICATION; - events[4].mode = IOLINK_EVENT_MODE_SINGLE_SHOT; - events[4].type = IOLINK_EVENT_TYPE_WARNING; - events[4].source = IOLINK_EVENT_SOURCE_DEVICE; + events[4].instance = IOLINK_EVENT_INSTANCE_APPLICATION; + events[4].mode = IOLINK_EVENT_MODE_SINGLE_SHOT; + events[4].type = IOLINK_EVENT_TYPE_WARNING; + events[4].source = IOLINK_EVENT_SOURCE_DEVICE; events[5].eventcode = 0x8DFF; - events[5].instance = IOLINK_EVENT_INSTANCE_UNKNOWN; - events[5].mode = IOLINK_EVENT_MODE_SINGLE_SHOT; - events[5].type = IOLINK_EVENT_TYPE_ERROR; - events[5].source = IOLINK_EVENT_SOURCE_DEVICE; + events[5].instance = IOLINK_EVENT_INSTANCE_UNKNOWN; + events[5].mode = IOLINK_EVENT_MODE_SINGLE_SHOT; + events[5].type = IOLINK_EVENT_TYPE_ERROR; + events[5].source = IOLINK_EVENT_SOURCE_DEVICE; al_verify_events (port, ARRAY_SIZE (events), events); } @@ -621,12 +642,12 @@ TEST_F (ALTest, Al_SetOutput) TEST_F (ALTest, Al_GetInput) { - uint8_t offset = 0; - uint8_t data[14] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}; + uint8_t offset = 0; + uint8_t data[14] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}; uint8_t pdin_data[32] = {0}; uint8_t pdin_data_len = 0; uint8_t exp_newinput_ind_cnt = mock_iolink_al_newinput_inf_cnt; - uint8_t exp_al_data_len = sizeof(data); + uint8_t exp_al_data_len = sizeof (data); DL_PDInputTransport_ind (port, data, exp_al_data_len); exp_newinput_ind_cnt++; diff --git a/test/test_cm.cpp b/test/test_cm.cpp index 2f78431..551d8a2 100644 --- a/test/test_cm.cpp +++ b/test/test_cm.cpp @@ -22,9 +22,10 @@ class CMTest : public TestBase { -protected: + protected: // Override default setup - virtual void SetUp() { + virtual void SetUp() + { TestBase::SetUp(); // Re-use default setup }; }; @@ -36,12 +37,13 @@ static inline iolink_cm_state_t cm_get_state (iolink_port_t * port) return cm->state; } -static inline void cm_verify_paraml (uint8_t exp_cycletime, - iolink_sm_target_mode_t exp_mode, - uint8_t exp_revisionid, - iolink_inspectionlevel_t exp_inspectionl, - uint16_t exp_vendorid, - uint32_t exp_deviceid) +static inline void cm_verify_paraml ( + uint8_t exp_cycletime, + iolink_sm_target_mode_t exp_mode, + uint8_t exp_revisionid, + iolink_inspectionlevel_t exp_inspectionl, + uint16_t exp_vendorid, + uint32_t exp_deviceid) { EXPECT_EQ (exp_cycletime, mock_iolink_cfg_paraml.cycletime); EXPECT_EQ (exp_mode, mock_iolink_cfg_paraml.mode); @@ -51,13 +53,14 @@ static inline void cm_verify_paraml (uint8_t exp_cycletime, EXPECT_EQ (exp_deviceid, mock_iolink_cfg_paraml.deviceid); } -static inline void cm_verify_mock_cnt (uint8_t exp_sm_operate_cnt, - uint8_t exp_ds_startup_cnt, - uint8_t exp_ds_delete_cnt, - uint8_t exp_od_start_cnt, - uint8_t exp_od_stop_cnt, - uint8_t exp_pd_start_cnt, - uint8_t exp_pd_stop_cnt) +static inline void cm_verify_mock_cnt ( + uint8_t exp_sm_operate_cnt, + uint8_t exp_ds_startup_cnt, + uint8_t exp_ds_delete_cnt, + uint8_t exp_od_start_cnt, + uint8_t exp_od_stop_cnt, + uint8_t exp_pd_start_cnt, + uint8_t exp_pd_stop_cnt) { EXPECT_EQ (exp_sm_operate_cnt, mock_iolink_sm_operate_cnt); EXPECT_EQ (exp_ds_startup_cnt, mock_iolink_ds_startup_cnt); @@ -71,19 +74,19 @@ static inline void cm_verify_mock_cnt (uint8_t exp_sm_operate_cnt, static inline void cm_verify_smi_portcfg_cnf (uint8_t exp_smi_portcfg_cnf_cnt) { EXPECT_EQ (exp_smi_portcfg_cnf_cnt, mock_iolink_smi_portcfg_cnf_cnt); - EXPECT_EQ (IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST, - mock_iolink_smi_ref_arg_block_id); + EXPECT_EQ (IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST, mock_iolink_smi_ref_arg_block_id); iolink_arg_block_id_t arg_block_id = - mock_iolink_smi_arg_block->void_block.arg_block_id; + mock_iolink_smi_arg_block->void_block.arg_block_id; EXPECT_EQ (arg_block_id, IOLINK_ARG_BLOCK_ID_VOID_BLOCK); } -static inline void cm_verify_smi_err (iolink_arg_block_id_t exp_smi_ref_arg_id, - iolink_arg_block_id_t exp_smi_exp_arg_id, - iolink_smi_errortypes_t exp_errortype, - uint8_t exp_smi_joberror_cnt, - uint8_t exp_smi_portstatus_cnf_cnt, - uint8_t exp_smi_portcfg_cnf_cnt) +static inline void cm_verify_smi_err ( + iolink_arg_block_id_t exp_smi_ref_arg_id, + iolink_arg_block_id_t exp_smi_exp_arg_id, + iolink_smi_errortypes_t exp_errortype, + uint8_t exp_smi_joberror_cnt, + uint8_t exp_smi_portstatus_cnf_cnt, + uint8_t exp_smi_portcfg_cnf_cnt) { EXPECT_EQ (exp_smi_joberror_cnt, mock_iolink_smi_joberror_cnt); EXPECT_EQ (exp_smi_portstatus_cnf_cnt, mock_iolink_smi_portstatus_cnf_cnt); @@ -91,15 +94,15 @@ static inline void cm_verify_smi_err (iolink_arg_block_id_t exp_smi_ref_arg_id, EXPECT_EQ (exp_smi_ref_arg_id, mock_iolink_smi_ref_arg_block_id); iolink_arg_block_id_t arg_block_id = - mock_iolink_smi_arg_block->void_block.arg_block_id; + mock_iolink_smi_arg_block->void_block.arg_block_id; EXPECT_EQ (IOLINK_ARG_BLOCK_ID_JOB_ERROR, arg_block_id); if (arg_block_id == IOLINK_ARG_BLOCK_ID_JOB_ERROR) { arg_block_joberror_t * job_error = - (arg_block_joberror_t*)mock_iolink_smi_arg_block; - iolink_smi_errortypes_t error = job_error->error; + (arg_block_joberror_t *)mock_iolink_smi_arg_block; + iolink_smi_errortypes_t error = job_error->error; iolink_arg_block_id_t exp_arg_block_id = job_error->exp_arg_block_id; EXPECT_EQ (exp_errortype, error); @@ -108,28 +111,28 @@ static inline void cm_verify_smi_err (iolink_arg_block_id_t exp_smi_ref_arg_id, } static inline void cm_verify_smi_masterident ( - iolink_arg_block_id_t exp_ref_arg_id, - iolink_arg_block_id_t exp_exp_arg_id, - uint16_t exp_vendorid, - uint32_t exp_masterid, - iolink_master_type_t exp_master_type, - uint8_t exp_max_number_of_ports, - iolink_port_types_t exp_port_type, - uint8_t exp_smi_cnf_cnt, - uint8_t exp_smi_joberror_cnt) + iolink_arg_block_id_t exp_ref_arg_id, + iolink_arg_block_id_t exp_exp_arg_id, + uint16_t exp_vendorid, + uint32_t exp_masterid, + iolink_master_type_t exp_master_type, + uint8_t exp_max_number_of_ports, + iolink_port_types_t exp_port_type, + uint8_t exp_smi_cnf_cnt, + uint8_t exp_smi_joberror_cnt) { EXPECT_EQ (exp_smi_cnf_cnt, mock_iolink_smi_cnf_cnt); EXPECT_EQ (exp_smi_joberror_cnt, mock_iolink_smi_joberror_cnt); EXPECT_EQ (exp_exp_arg_id, IOLINK_ARG_BLOCK_ID_MASTERIDENT); - if (mock_iolink_smi_arg_block->void_block.arg_block_id == - IOLINK_ARG_BLOCK_ID_MASTERIDENT) + if (mock_iolink_smi_arg_block->void_block.arg_block_id == IOLINK_ARG_BLOCK_ID_MASTERIDENT) { int i; arg_block_masterident_t * masterident = - (arg_block_masterident_t *)mock_iolink_smi_arg_block; - uint8_t exp_arg_block_len = sizeof(arg_block_masterident_head_t) + - sizeof(iolink_port_types_t) * exp_max_number_of_ports; + (arg_block_masterident_t *)mock_iolink_smi_arg_block; + uint8_t exp_arg_block_len = + sizeof (arg_block_masterident_head_t) + + sizeof (iolink_port_types_t) * exp_max_number_of_ports; EXPECT_EQ (exp_vendorid, masterident->h.vendorid); EXPECT_EQ (exp_masterid, masterident->h.masterid); @@ -151,24 +154,27 @@ static inline void cm_verify_smi_masterident ( } } -static inline void cm_verify_smi_portconfig (iolink_port_t * port, - portconfiglist_t * exp_configlist) +static inline void cm_verify_smi_portconfig ( + iolink_port_t * port, + portconfiglist_t * exp_configlist) { arg_block_void_t arg_block_void; - iolink_arg_block_id_t arg_block_id = IOLINK_ARG_BLOCK_ID_VOID_BLOCK; + iolink_arg_block_id_t arg_block_id = IOLINK_ARG_BLOCK_ID_VOID_BLOCK; iolink_arg_block_id_t exp_exp_arg_id = IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST; - uint8_t exp_smi_cnf_cnt = mock_iolink_smi_cnf_cnt; + uint8_t exp_smi_cnf_cnt = mock_iolink_smi_cnf_cnt; uint8_t exp_smi_joberror_cnt = mock_iolink_smi_joberror_cnt; - memset (&arg_block_void, 0, sizeof(arg_block_void_t)); + memset (&arg_block_void, 0, sizeof (arg_block_void_t)); arg_block_void.arg_block_id = arg_block_id; /* SMI_ReadbackPortConfiguration_req() */ - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_ReadbackPortConfiguration_req (iolink_get_portnumber (port), - exp_exp_arg_id, - sizeof(arg_block_void_t), - (arg_block_t *)&arg_block_void)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_ReadbackPortConfiguration_req ( + iolink_get_portnumber (port), + exp_exp_arg_id, + sizeof (arg_block_void_t), + (arg_block_t *)&arg_block_void)); mock_iolink_job.callback (&mock_iolink_job); exp_smi_cnf_cnt++; @@ -179,14 +185,13 @@ static inline void cm_verify_smi_portconfig (iolink_port_t * port, EXPECT_EQ (exp_exp_arg_id, arg_block_id); - if (mock_iolink_smi_arg_block->void_block.arg_block_id == - IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST) + if (mock_iolink_smi_arg_block->void_block.arg_block_id == IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST) { arg_block_portconfiglist_t * arg_block_portcfg = - (arg_block_portconfiglist_t *) mock_iolink_smi_arg_block; + (arg_block_portconfiglist_t *)mock_iolink_smi_arg_block; - EXPECT_TRUE (PortConfigMatch (exp_configlist, - &arg_block_portcfg->configlist)); + EXPECT_TRUE ( + PortConfigMatch (exp_configlist, &arg_block_portcfg->configlist)); } else { @@ -194,45 +199,47 @@ static inline void cm_verify_smi_portconfig (iolink_port_t * port, } } -static inline void cm_verify_portstatus (iolink_port_t * port, - iolink_port_status_info_t exp_port_status, - uint8_t exp_port_quality_info, - uint8_t exp_revision_id, - iolink_transmission_rate_t exp_trans_rate, - uint8_t exp_master_cycle_time, - uint16_t exp_vendorid, - uint32_t exp_deviceid, - uint8_t exp_number_of_diags, - diag_entry_t * exp_diag_entries) +static inline void cm_verify_portstatus ( + iolink_port_t * port, + iolink_port_status_info_t exp_port_status, + uint8_t exp_port_quality_info, + uint8_t exp_revision_id, + iolink_transmission_rate_t exp_trans_rate, + uint8_t exp_master_cycle_time, + uint16_t exp_vendorid, + uint32_t exp_deviceid, + uint8_t exp_number_of_diags, + diag_entry_t * exp_diag_entries) { arg_block_void_t arg_block_void; iolink_arg_block_id_t exp_exp_arg_block_id = - IOLINK_ARG_BLOCK_ID_PORT_STATUS_LIST; + IOLINK_ARG_BLOCK_ID_PORT_STATUS_LIST; iolink_arg_block_id_t exp_ref_arg_block_id = IOLINK_ARG_BLOCK_ID_VOID_BLOCK; uint8_t exp_smi_portstatus_cnf_cnt = mock_iolink_smi_portstatus_cnf_cnt + 1; - memset (&arg_block_void, 0, sizeof(arg_block_void_t)); + memset (&arg_block_void, 0, sizeof (arg_block_void_t)); arg_block_void.arg_block_id = exp_ref_arg_block_id; - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_PortStatus_req (iolink_get_portnumber (port), - exp_exp_arg_block_id, - sizeof(arg_block_void_t), - (arg_block_t *)&arg_block_void)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_PortStatus_req ( + iolink_get_portnumber (port), + exp_exp_arg_block_id, + sizeof (arg_block_void_t), + (arg_block_t *)&arg_block_void)); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (exp_smi_portstatus_cnf_cnt, mock_iolink_smi_portstatus_cnf_cnt); EXPECT_EQ (exp_ref_arg_block_id, mock_iolink_smi_ref_arg_block_id); iolink_arg_block_id_t arg_block_id = - mock_iolink_smi_arg_block->void_block.arg_block_id; + mock_iolink_smi_arg_block->void_block.arg_block_id; EXPECT_EQ (exp_exp_arg_block_id, arg_block_id); - if (exp_exp_arg_block_id == - mock_iolink_smi_arg_block->void_block.arg_block_id) + if (exp_exp_arg_block_id == mock_iolink_smi_arg_block->void_block.arg_block_id) { arg_block_portstatuslist_t * port_status_list = - (arg_block_portstatuslist_t *)mock_iolink_smi_arg_block; + (arg_block_portstatuslist_t *)mock_iolink_smi_arg_block; EXPECT_EQ (exp_port_status, port_status_list->port_status_info); EXPECT_EQ (exp_port_quality_info, port_status_list->port_quality_info); @@ -245,66 +252,70 @@ static inline void cm_verify_portstatus (iolink_port_t * port, } } -static inline void cm_x_to_dido (iolink_port_t * port, - iolink_cm_state_t exp_state, bool is_do) +static inline void cm_x_to_dido ( + iolink_port_t * port, + iolink_cm_state_t exp_state, + bool is_do) { arg_block_portconfiglist_t port_cfg; iolink_sm_target_mode_t exp_target_mode; iolink_inspectionlevel_t exp_inspection_level = - IOLINK_INSPECTIONLEVEL_NO_CHECK; + IOLINK_INSPECTIONLEVEL_NO_CHECK; iolink_port_status_info_t exp_status_info; uint8_t exp_port_quality_info = IOLINK_PORT_QUALITY_INFO_INVALID; - uint8_t exp_port_cycle_time = 0; - uint8_t exp_revisionid = 0; + uint8_t exp_port_cycle_time = 0; + uint8_t exp_revisionid = 0; iolink_transmission_rate_t exp_trans_rate = - IOLINK_TRANSMISSION_RATE_NOT_DETECTED; + IOLINK_TRANSMISSION_RATE_NOT_DETECTED; uint16_t exp_vendorid = 0; uint32_t exp_deviceid = 0; - uint8_t exp_sm_operate_cnt = mock_iolink_sm_operate_cnt; - uint8_t exp_ds_startup_cnt = mock_iolink_ds_startup_cnt; - uint8_t exp_ds_delete_cnt = mock_iolink_ds_delete_cnt + 1; + uint8_t exp_sm_operate_cnt = mock_iolink_sm_operate_cnt; + uint8_t exp_ds_startup_cnt = mock_iolink_ds_startup_cnt; + uint8_t exp_ds_delete_cnt = mock_iolink_ds_delete_cnt + 1; uint8_t exp_smi_portcfg_cnf_cnt = mock_iolink_smi_portcfg_cnf_cnt + 1; - uint8_t exp_od_start_cnt = mock_iolink_od_start_cnt; - uint8_t exp_od_stop_cnt = mock_iolink_od_stop_cnt + 1; - uint8_t exp_pd_start_cnt = mock_iolink_pd_start_cnt; - uint8_t exp_pd_stop_cnt = mock_iolink_pd_stop_cnt + 1; + uint8_t exp_od_start_cnt = mock_iolink_od_start_cnt; + uint8_t exp_od_stop_cnt = mock_iolink_od_stop_cnt + 1; + uint8_t exp_pd_start_cnt = mock_iolink_pd_start_cnt; + uint8_t exp_pd_stop_cnt = mock_iolink_pd_stop_cnt + 1; iolink_sm_portmode_t portmode; - memset (&port_cfg, 0, sizeof(arg_block_portconfiglist_t)); - port_cfg.arg_block_id = IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST; - port_cfg.configlist.port_cycle_time = exp_port_cycle_time; - port_cfg.configlist.vendorid = exp_vendorid; - port_cfg.configlist.deviceid = exp_deviceid; - port_cfg.configlist.in_buffer_len = 0; // TODO - port_cfg.configlist.out_buffer_len = 0; // TODO + memset (&port_cfg, 0, sizeof (arg_block_portconfiglist_t)); + port_cfg.arg_block_id = IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST; + port_cfg.configlist.port_cycle_time = exp_port_cycle_time; + port_cfg.configlist.vendorid = exp_vendorid; + port_cfg.configlist.deviceid = exp_deviceid; + port_cfg.configlist.in_buffer_len = 0; // TODO + port_cfg.configlist.out_buffer_len = 0; // TODO port_cfg.configlist.validation_backup = IOLINK_VALIDATION_CHECK_NO; if (is_do) { - port_cfg.configlist.portmode = IOLINK_PORTMODE_DO_CQ; + port_cfg.configlist.portmode = IOLINK_PORTMODE_DO_CQ; port_cfg.configlist.iq_behavior = IOLINK_IQ_BEHAVIOR_DO; - exp_target_mode = IOLINK_SMTARGET_MODE_DO; - exp_status_info = IOLINK_PORT_STATUS_INFO_DO; - portmode = IOLINK_SM_PORTMODE_DO; + exp_target_mode = IOLINK_SMTARGET_MODE_DO; + exp_status_info = IOLINK_PORT_STATUS_INFO_DO; + portmode = IOLINK_SM_PORTMODE_DO; } else { - port_cfg.configlist.portmode = IOLINK_PORTMODE_DI_CQ; + port_cfg.configlist.portmode = IOLINK_PORTMODE_DI_CQ; port_cfg.configlist.iq_behavior = IOLINK_IQ_BEHAVIOR_DI; - exp_target_mode = IOLINK_SMTARGET_MODE_DI; - exp_status_info = IOLINK_PORT_STATUS_INFO_DI; - portmode = IOLINK_SM_PORTMODE_DI; + exp_target_mode = IOLINK_SMTARGET_MODE_DI; + exp_status_info = IOLINK_PORT_STATUS_INFO_DI; + portmode = IOLINK_SM_PORTMODE_DI; } EXPECT_EQ (exp_state, cm_get_state (port)); - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_PortConfiguration_req (iolink_get_portnumber (port), - IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - sizeof(arg_block_portconfiglist_t), - (arg_block_t *)&port_cfg)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_PortConfiguration_req ( + iolink_get_portnumber (port), + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + sizeof (arg_block_portconfiglist_t), + (arg_block_t *)&port_cfg)); mock_iolink_job.callback (&mock_iolink_job); SM_PortMode_ind (port, portmode); @@ -312,25 +323,43 @@ static inline void cm_x_to_dido (iolink_port_t * port, EXPECT_EQ (CM_STATE_Port_DIDO, cm_get_state (port)); cm_verify_smi_portcfg_cnf (exp_smi_portcfg_cnf_cnt); - cm_verify_paraml (exp_port_cycle_time, exp_target_mode, exp_revisionid, - exp_inspection_level, exp_vendorid, exp_deviceid); - cm_verify_portstatus (port, exp_status_info, exp_port_quality_info, - exp_revisionid, exp_trans_rate, exp_port_cycle_time, - exp_vendorid, exp_deviceid, 0, NULL); - cm_verify_mock_cnt (exp_sm_operate_cnt, exp_ds_startup_cnt, - exp_ds_delete_cnt, exp_od_start_cnt, exp_od_stop_cnt, - exp_pd_start_cnt, exp_pd_stop_cnt); + cm_verify_paraml ( + exp_port_cycle_time, + exp_target_mode, + exp_revisionid, + exp_inspection_level, + exp_vendorid, + exp_deviceid); + cm_verify_portstatus ( + port, + exp_status_info, + exp_port_quality_info, + exp_revisionid, + exp_trans_rate, + exp_port_cycle_time, + exp_vendorid, + exp_deviceid, + 0, + NULL); + cm_verify_mock_cnt ( + exp_sm_operate_cnt, + exp_ds_startup_cnt, + exp_ds_delete_cnt, + exp_od_start_cnt, + exp_od_stop_cnt, + exp_pd_start_cnt, + exp_pd_stop_cnt); } -static inline void cm_deactive_to_dido (iolink_port_t * port, - bool is_do) +static inline void cm_deactive_to_dido (iolink_port_t * port, bool is_do) { cm_x_to_dido (port, CM_STATE_Port_Deactivated, is_do); } -static inline void cm_deactive_to_startup (iolink_port_t * port, - iolink_portmode_t mode, - iolink_validation_check_t validation) +static inline void cm_deactive_to_startup ( + iolink_port_t * port, + iolink_portmode_t mode, + iolink_validation_check_t validation) { arg_block_portconfiglist_t port_cfg; @@ -338,40 +367,40 @@ static inline void cm_deactive_to_startup (iolink_port_t * port, iolink_inspectionlevel_t exp_inspection_level; uint8_t exp_param_revisionid; iolink_port_status_info_t exp_status_info = - IOLINK_PORT_STATUS_INFO_DEACTIVATED; + IOLINK_PORT_STATUS_INFO_DEACTIVATED; uint8_t exp_port_quality_info = IOLINK_PORT_QUALITY_INFO_INVALID; - uint8_t exp_port_cycle_time = 0; // AFAP (As fast as possible) - uint8_t exp_cfg_revid = 0; + uint8_t exp_port_cycle_time = 0; // AFAP (As fast as possible) + uint8_t exp_cfg_revid = 0; iolink_transmission_rate_t exp_trans_rate = - IOLINK_TRANSMISSION_RATE_NOT_DETECTED; + IOLINK_TRANSMISSION_RATE_NOT_DETECTED; uint16_t exp_vendorid = 0; uint32_t exp_deviceid = 0; - uint8_t exp_sm_operate_cnt = mock_iolink_sm_operate_cnt; - uint8_t exp_ds_startup_cnt = mock_iolink_ds_startup_cnt; - uint8_t exp_ds_delete_cnt = mock_iolink_ds_delete_cnt; + uint8_t exp_sm_operate_cnt = mock_iolink_sm_operate_cnt; + uint8_t exp_ds_startup_cnt = mock_iolink_ds_startup_cnt; + uint8_t exp_ds_delete_cnt = mock_iolink_ds_delete_cnt; uint8_t exp_smi_portcfg_cnf_cnt = mock_iolink_smi_portcfg_cnf_cnt + 1; - uint8_t exp_od_start_cnt = mock_iolink_od_start_cnt; - uint8_t exp_od_stop_cnt = mock_iolink_od_stop_cnt + 1; - uint8_t exp_pd_start_cnt = mock_iolink_pd_start_cnt; - uint8_t exp_pd_stop_cnt = mock_iolink_pd_stop_cnt + 1; - - memset (&port_cfg, 0, sizeof(arg_block_portconfiglist_t)); - port_cfg.arg_block_id = IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST; - port_cfg.configlist.port_cycle_time = exp_port_cycle_time; - port_cfg.configlist.vendorid = exp_vendorid; - port_cfg.configlist.deviceid = exp_deviceid; - port_cfg.configlist.in_buffer_len = 0; // TODO - port_cfg.configlist.out_buffer_len = 0; // TODO + uint8_t exp_od_start_cnt = mock_iolink_od_start_cnt; + uint8_t exp_od_stop_cnt = mock_iolink_od_stop_cnt + 1; + uint8_t exp_pd_start_cnt = mock_iolink_pd_start_cnt; + uint8_t exp_pd_stop_cnt = mock_iolink_pd_stop_cnt + 1; + + memset (&port_cfg, 0, sizeof (arg_block_portconfiglist_t)); + port_cfg.arg_block_id = IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST; + port_cfg.configlist.port_cycle_time = exp_port_cycle_time; + port_cfg.configlist.vendorid = exp_vendorid; + port_cfg.configlist.deviceid = exp_deviceid; + port_cfg.configlist.in_buffer_len = 0; // TODO + port_cfg.configlist.out_buffer_len = 0; // TODO port_cfg.configlist.validation_backup = validation; - port_cfg.configlist.portmode = mode; - port_cfg.configlist.iq_behavior = IOLINK_IQ_BEHAVIOR_NO_SUPPORT; + port_cfg.configlist.portmode = mode; + port_cfg.configlist.iq_behavior = IOLINK_IQ_BEHAVIOR_NO_SUPPORT; if (mode == IOLINK_PORTMODE_IOL_AUTO) { - //port_cfg.configlist.validation_backup = IOLINK_VALIDATION_CHECK_NO; + // port_cfg.configlist.validation_backup = IOLINK_VALIDATION_CHECK_NO; - exp_target_mode = IOLINK_SMTARGET_MODE_AUTOCOM; + exp_target_mode = IOLINK_SMTARGET_MODE_AUTOCOM; exp_inspection_level = IOLINK_INSPECTIONLEVEL_NO_CHECK; exp_param_revisionid = 0; exp_ds_delete_cnt++; @@ -388,7 +417,7 @@ static inline void cm_deactive_to_startup (iolink_port_t * port, exp_param_revisionid = IOL_DIR_PARAM_REV_V11; exp_inspection_level = IOLINK_INSPECTIONLEVEL_TYPE_COMP; } - //port_cfg.configlist.portmode = IOLINK_PORTMODE_IOL_MAN; + // port_cfg.configlist.portmode = IOLINK_PORTMODE_IOL_MAN; exp_target_mode = IOLINK_SMTARGET_MODE_CFGCOM; // TODO if vid != DS_vid && did != DS_did --> exp_ds_delete_cnt++; @@ -396,114 +425,166 @@ static inline void cm_deactive_to_startup (iolink_port_t * port, } EXPECT_EQ (CM_STATE_Port_Deactivated, cm_get_state (port)); - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_PortConfiguration_req (iolink_get_portnumber (port), - IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - sizeof(arg_block_portconfiglist_t), - (arg_block_t *)&port_cfg)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_PortConfiguration_req ( + iolink_get_portnumber (port), + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + sizeof (arg_block_portconfiglist_t), + (arg_block_t *)&port_cfg)); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (CM_STATE_SM_Startup, cm_get_state (port)); cm_verify_smi_portcfg_cnf (exp_smi_portcfg_cnf_cnt); - cm_verify_paraml (exp_port_cycle_time, exp_target_mode, exp_param_revisionid, - exp_inspection_level, exp_vendorid, exp_deviceid); - cm_verify_portstatus (port, exp_status_info, exp_port_quality_info, - exp_cfg_revid, exp_trans_rate, exp_port_cycle_time, - exp_vendorid, exp_deviceid, 0, NULL); - cm_verify_mock_cnt (exp_sm_operate_cnt, exp_ds_startup_cnt, - exp_ds_delete_cnt, exp_od_start_cnt, exp_od_stop_cnt, - exp_pd_start_cnt, exp_pd_stop_cnt); + cm_verify_paraml ( + exp_port_cycle_time, + exp_target_mode, + exp_param_revisionid, + exp_inspection_level, + exp_vendorid, + exp_deviceid); + cm_verify_portstatus ( + port, + exp_status_info, + exp_port_quality_info, + exp_cfg_revid, + exp_trans_rate, + exp_port_cycle_time, + exp_vendorid, + exp_deviceid, + 0, + NULL); + cm_verify_mock_cnt ( + exp_sm_operate_cnt, + exp_ds_startup_cnt, + exp_ds_delete_cnt, + exp_od_start_cnt, + exp_od_stop_cnt, + exp_pd_start_cnt, + exp_pd_stop_cnt); } static inline void cm_startup_to_ds_parammanager (iolink_port_t * port) { iolink_port_status_info_t exp_status_info = IOLINK_PORT_STATUS_INFO_PREOP; - uint8_t exp_port_quality_info = IOLINK_PORT_QUALITY_INFO_INVALID; + uint8_t exp_port_quality_info = IOLINK_PORT_QUALITY_INFO_INVALID; iolink_transmission_rate_t exp_trans_rate = mock_iolink_trans_rate; - uint8_t exp_port_cycle_time = mock_iolink_min_cycletime; - uint8_t exp_revisionid = mock_iolink_revisionid; - uint16_t exp_vendorid = mock_iolink_vendorid; - uint32_t exp_deviceid = mock_iolink_deviceid; + uint8_t exp_port_cycle_time = mock_iolink_min_cycletime; + uint8_t exp_revisionid = mock_iolink_revisionid; + uint16_t exp_vendorid = mock_iolink_vendorid; + uint32_t exp_deviceid = mock_iolink_deviceid; uint8_t exp_sm_operate_cnt = mock_iolink_sm_operate_cnt; uint8_t exp_ds_startup_cnt = mock_iolink_ds_startup_cnt + 1; - uint8_t exp_ds_delete_cnt = mock_iolink_ds_delete_cnt; - uint8_t exp_od_start_cnt = mock_iolink_od_start_cnt; - uint8_t exp_od_stop_cnt = mock_iolink_od_stop_cnt; - uint8_t exp_pd_start_cnt = mock_iolink_pd_start_cnt; - uint8_t exp_pd_stop_cnt = mock_iolink_pd_stop_cnt; + uint8_t exp_ds_delete_cnt = mock_iolink_ds_delete_cnt; + uint8_t exp_od_start_cnt = mock_iolink_od_start_cnt; + uint8_t exp_od_stop_cnt = mock_iolink_od_stop_cnt; + uint8_t exp_pd_start_cnt = mock_iolink_pd_start_cnt; + uint8_t exp_pd_stop_cnt = mock_iolink_pd_stop_cnt; EXPECT_EQ (CM_STATE_SM_Startup, cm_get_state (port)); SM_PortMode_ind (port, IOLINK_SM_PORTMODE_COMREADY); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (CM_STATE_DS_ParamManager, cm_get_state (port)); - cm_verify_portstatus (port, exp_status_info, exp_port_quality_info, - exp_revisionid, exp_trans_rate, exp_port_cycle_time, - exp_vendorid, exp_deviceid, 0, NULL); - cm_verify_mock_cnt (exp_sm_operate_cnt, exp_ds_startup_cnt, - exp_ds_delete_cnt, exp_od_start_cnt, exp_od_stop_cnt, - exp_pd_start_cnt, exp_pd_stop_cnt); + cm_verify_portstatus ( + port, + exp_status_info, + exp_port_quality_info, + exp_revisionid, + exp_trans_rate, + exp_port_cycle_time, + exp_vendorid, + exp_deviceid, + 0, + NULL); + cm_verify_mock_cnt ( + exp_sm_operate_cnt, + exp_ds_startup_cnt, + exp_ds_delete_cnt, + exp_od_start_cnt, + exp_od_stop_cnt, + exp_pd_start_cnt, + exp_pd_stop_cnt); } static inline void cm_deactive_to_ds_parammanager (iolink_port_t * port) { - cm_deactive_to_startup (port, IOLINK_PORTMODE_IOL_AUTO, - IOLINK_VALIDATION_CHECK_NO); + cm_deactive_to_startup ( + port, + IOLINK_PORTMODE_IOL_AUTO, + IOLINK_VALIDATION_CHECK_NO); cm_startup_to_ds_parammanager (port); } -static inline void cm_startup_to_sm_port_fault (iolink_port_t * port, - iolink_sm_portmode_t mode, - uint8_t exp_port_cycle_time) +static inline void cm_startup_to_sm_port_fault ( + iolink_port_t * port, + iolink_sm_portmode_t mode, + uint8_t exp_port_cycle_time) { - iolink_port_status_info_t exp_status_info = - IOLINK_PORT_STATUS_INFO_PORT_DIAG; - uint8_t exp_port_quality_info = IOLINK_PORT_QUALITY_INFO_INVALID; + iolink_port_status_info_t exp_status_info = IOLINK_PORT_STATUS_INFO_PORT_DIAG; + uint8_t exp_port_quality_info = IOLINK_PORT_QUALITY_INFO_INVALID; iolink_transmission_rate_t exp_trans_rate = mock_iolink_trans_rate; - uint8_t exp_revisionid = mock_iolink_revisionid; - uint16_t exp_vendorid = mock_iolink_vendorid; - uint32_t exp_deviceid = mock_iolink_deviceid; + uint8_t exp_revisionid = mock_iolink_revisionid; + uint16_t exp_vendorid = mock_iolink_vendorid; + uint32_t exp_deviceid = mock_iolink_deviceid; uint8_t exp_sm_operate_cnt = mock_iolink_sm_operate_cnt; uint8_t exp_ds_startup_cnt = mock_iolink_ds_startup_cnt; - uint8_t exp_ds_delete_cnt = mock_iolink_ds_delete_cnt; - uint8_t exp_od_start_cnt = mock_iolink_od_start_cnt; - uint8_t exp_od_stop_cnt = mock_iolink_od_stop_cnt; - uint8_t exp_pd_start_cnt = mock_iolink_pd_start_cnt; - uint8_t exp_pd_stop_cnt = mock_iolink_pd_stop_cnt; + uint8_t exp_ds_delete_cnt = mock_iolink_ds_delete_cnt; + uint8_t exp_od_start_cnt = mock_iolink_od_start_cnt; + uint8_t exp_od_stop_cnt = mock_iolink_od_stop_cnt; + uint8_t exp_pd_start_cnt = mock_iolink_pd_start_cnt; + uint8_t exp_pd_stop_cnt = mock_iolink_pd_stop_cnt; EXPECT_EQ (CM_STATE_SM_Startup, cm_get_state (port)); SM_PortMode_ind (port, mode); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (CM_STATE_PortFault, cm_get_state (port)); - cm_verify_portstatus (port, exp_status_info, exp_port_quality_info, - exp_revisionid, exp_trans_rate, exp_port_cycle_time, - exp_vendorid, exp_deviceid, 0, NULL); - cm_verify_mock_cnt (exp_sm_operate_cnt, exp_ds_startup_cnt, - exp_ds_delete_cnt, exp_od_start_cnt, exp_od_stop_cnt, - exp_pd_start_cnt, exp_pd_stop_cnt); + cm_verify_portstatus ( + port, + exp_status_info, + exp_port_quality_info, + exp_revisionid, + exp_trans_rate, + exp_port_cycle_time, + exp_vendorid, + exp_deviceid, + 0, + NULL); + cm_verify_mock_cnt ( + exp_sm_operate_cnt, + exp_ds_startup_cnt, + exp_ds_delete_cnt, + exp_od_start_cnt, + exp_od_stop_cnt, + exp_pd_start_cnt, + exp_pd_stop_cnt); } -static inline void cm_deactive_to_sm_port_fault (iolink_port_t * port, - iolink_sm_portmode_t mode) +static inline void cm_deactive_to_sm_port_fault ( + iolink_port_t * port, + iolink_sm_portmode_t mode) { - cm_deactive_to_startup (port, IOLINK_PORTMODE_IOL_AUTO, - IOLINK_VALIDATION_CHECK_NO); + cm_deactive_to_startup ( + port, + IOLINK_PORTMODE_IOL_AUTO, + IOLINK_VALIDATION_CHECK_NO); cm_startup_to_sm_port_fault (port, mode, 0); } -static inline void cm_x_to_waiting_on_op (iolink_port_t * port, - iolink_cm_state_t exp_state) +static inline void cm_x_to_waiting_on_op ( + iolink_port_t * port, + iolink_cm_state_t exp_state) { uint8_t exp_sm_operate_cnt = mock_iolink_sm_operate_cnt + 1; uint8_t exp_ds_startup_cnt = mock_iolink_ds_startup_cnt + 1; - uint8_t exp_ds_delete_cnt = mock_iolink_ds_delete_cnt; - uint8_t exp_od_start_cnt = mock_iolink_od_start_cnt; - uint8_t exp_od_stop_cnt = mock_iolink_od_stop_cnt; - uint8_t exp_pd_start_cnt = mock_iolink_pd_start_cnt; - uint8_t exp_pd_stop_cnt = mock_iolink_pd_stop_cnt; + uint8_t exp_ds_delete_cnt = mock_iolink_ds_delete_cnt; + uint8_t exp_od_start_cnt = mock_iolink_od_start_cnt; + uint8_t exp_od_stop_cnt = mock_iolink_od_stop_cnt; + uint8_t exp_pd_start_cnt = mock_iolink_pd_start_cnt; + uint8_t exp_pd_stop_cnt = mock_iolink_pd_stop_cnt; switch (exp_state) { @@ -527,9 +608,14 @@ static inline void cm_x_to_waiting_on_op (iolink_port_t * port, mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (CM_STATE_WaitingOnOperate, cm_get_state (port)); - cm_verify_mock_cnt (exp_sm_operate_cnt, exp_ds_startup_cnt, - exp_ds_delete_cnt, exp_od_start_cnt, exp_od_stop_cnt, - exp_pd_start_cnt, exp_pd_stop_cnt); + cm_verify_mock_cnt ( + exp_sm_operate_cnt, + exp_ds_startup_cnt, + exp_ds_delete_cnt, + exp_od_start_cnt, + exp_od_stop_cnt, + exp_pd_start_cnt, + exp_pd_stop_cnt); } static inline void cm_startup_to_waiting_on_op (iolink_port_t * port) @@ -542,29 +628,30 @@ static inline void cm_deactive_to_waiting_on_op (iolink_port_t * port) cm_x_to_waiting_on_op (port, CM_STATE_Port_Deactivated); } -static inline void cm_x_to_port_active (iolink_port_t * port, - iolink_cm_state_t exp_state) +static inline void cm_x_to_port_active ( + iolink_port_t * port, + iolink_cm_state_t exp_state) { iolink_port_status_info_t exp_status_info = IOLINK_PORT_STATUS_INFO_OP; - uint8_t exp_port_quality_info = IOLINK_PORT_QUALITY_INFO_VALID | // TODO + uint8_t exp_port_quality_info = IOLINK_PORT_QUALITY_INFO_VALID | // TODO IOLINK_PORT_QUALITY_INFO_PDO_VALID; // TODO iolink_transmission_rate_t exp_trans_rate = mock_iolink_trans_rate; - uint8_t exp_port_cycle_time = mock_iolink_min_cycletime; - uint8_t exp_revisionid = mock_iolink_revisionid; - uint16_t exp_vendorid = mock_iolink_vendorid; - uint32_t exp_deviceid = mock_iolink_deviceid; - - uint8_t exp_sm_operate_cnt = mock_iolink_sm_operate_cnt + 1; - uint8_t exp_ds_startup_cnt = mock_iolink_ds_startup_cnt + 1; - uint8_t exp_ds_delete_cnt = mock_iolink_ds_delete_cnt; - uint8_t exp_od_start_cnt = mock_iolink_od_start_cnt + 1; - uint8_t exp_od_stop_cnt = mock_iolink_od_stop_cnt; - uint8_t exp_pd_start_cnt = mock_iolink_pd_start_cnt + 1; - uint8_t exp_pd_stop_cnt = mock_iolink_pd_stop_cnt; + uint8_t exp_port_cycle_time = mock_iolink_min_cycletime; + uint8_t exp_revisionid = mock_iolink_revisionid; + uint16_t exp_vendorid = mock_iolink_vendorid; + uint32_t exp_deviceid = mock_iolink_deviceid; + + uint8_t exp_sm_operate_cnt = mock_iolink_sm_operate_cnt + 1; + uint8_t exp_ds_startup_cnt = mock_iolink_ds_startup_cnt + 1; + uint8_t exp_ds_delete_cnt = mock_iolink_ds_delete_cnt; + uint8_t exp_od_start_cnt = mock_iolink_od_start_cnt + 1; + uint8_t exp_od_stop_cnt = mock_iolink_od_stop_cnt; + uint8_t exp_pd_start_cnt = mock_iolink_pd_start_cnt + 1; + uint8_t exp_pd_stop_cnt = mock_iolink_pd_stop_cnt; uint8_t exp_smi_portevent_ind_cnt = mock_iolink_smi_portevent_ind_cnt; iolink_eventcode_t exp_smi_portevent_code = - IOLINK_EVENTCODE_PORT_STATUS_CHANGE; + IOLINK_EVENTCODE_PORT_STATUS_CHANGE; switch (exp_state) { case CM_STATE_Port_Deactivated: @@ -592,24 +679,36 @@ static inline void cm_x_to_port_active (iolink_port_t * port, EXPECT_EQ (IOLINK_ARG_BLOCK_ID_VOID_BLOCK, mock_iolink_smi_ref_arg_block_id); iolink_arg_block_id_t arg_block_id = - mock_iolink_smi_arg_block->void_block.arg_block_id; + mock_iolink_smi_arg_block->void_block.arg_block_id; EXPECT_EQ (arg_block_id, IOLINK_ARG_BLOCK_ID_PORT_EVENT); - if (mock_iolink_smi_arg_block->void_block.arg_block_id == - IOLINK_ARG_BLOCK_ID_PORT_EVENT) + if (mock_iolink_smi_arg_block->void_block.arg_block_id == IOLINK_ARG_BLOCK_ID_PORT_EVENT) { iolink_eventcode_t event_code = - mock_iolink_smi_arg_block->port_event.event.event_code; + mock_iolink_smi_arg_block->port_event.event.event_code; EXPECT_EQ (exp_smi_portevent_code, event_code); } - cm_verify_portstatus (port, exp_status_info, exp_port_quality_info, - exp_revisionid, exp_trans_rate, exp_port_cycle_time, - exp_vendorid, exp_deviceid, 0, NULL); - cm_verify_mock_cnt (exp_sm_operate_cnt, exp_ds_startup_cnt, - exp_ds_delete_cnt, exp_od_start_cnt, exp_od_stop_cnt, - exp_pd_start_cnt, exp_pd_stop_cnt); + cm_verify_portstatus ( + port, + exp_status_info, + exp_port_quality_info, + exp_revisionid, + exp_trans_rate, + exp_port_cycle_time, + exp_vendorid, + exp_deviceid, + 0, + NULL); + cm_verify_mock_cnt ( + exp_sm_operate_cnt, + exp_ds_startup_cnt, + exp_ds_delete_cnt, + exp_od_start_cnt, + exp_od_stop_cnt, + exp_pd_start_cnt, + exp_pd_stop_cnt); } static inline void cm_startup_to_port_active (iolink_port_t * port) @@ -622,63 +721,82 @@ static inline void cm_deactive_to_port_active (iolink_port_t * port) cm_x_to_port_active (port, CM_STATE_Port_Deactivated); } -static inline void cm_x_to_deactive (iolink_port_t * port, - iolink_cm_state_t exp_state) +static inline void cm_x_to_deactive (iolink_port_t * port, iolink_cm_state_t exp_state) { arg_block_portconfiglist_t port_cfg; iolink_sm_target_mode_t exp_target_mode = IOLINK_SMTARGET_MODE_INACTIVE; iolink_inspectionlevel_t exp_inspection_level = - IOLINK_INSPECTIONLEVEL_NO_CHECK; + IOLINK_INSPECTIONLEVEL_NO_CHECK; iolink_port_status_info_t exp_status_info = - IOLINK_PORT_STATUS_INFO_DEACTIVATED; + IOLINK_PORT_STATUS_INFO_DEACTIVATED; uint8_t exp_port_quality_info = IOLINK_PORT_QUALITY_INFO_INVALID; - uint8_t exp_port_cycle_time = 0; - uint8_t exp_revisionid = 0; + uint8_t exp_port_cycle_time = 0; + uint8_t exp_revisionid = 0; iolink_transmission_rate_t exp_trans_rate = - IOLINK_TRANSMISSION_RATE_NOT_DETECTED; + IOLINK_TRANSMISSION_RATE_NOT_DETECTED; uint16_t exp_vendorid = 0; uint32_t exp_deviceid = 0; - uint8_t exp_sm_operate_cnt = mock_iolink_sm_operate_cnt; - uint8_t exp_ds_startup_cnt = mock_iolink_ds_startup_cnt; - uint8_t exp_ds_delete_cnt = mock_iolink_ds_delete_cnt; - uint8_t exp_smi_portcfg_cnf_cnt = mock_iolink_smi_portcfg_cnf_cnt + 1; - uint8_t exp_od_start_cnt = mock_iolink_od_start_cnt; - uint8_t exp_od_stop_cnt = mock_iolink_od_stop_cnt + 1; - uint8_t exp_pd_start_cnt = mock_iolink_pd_start_cnt; - uint8_t exp_pd_stop_cnt = mock_iolink_pd_stop_cnt + 1; + uint8_t exp_sm_operate_cnt = mock_iolink_sm_operate_cnt; + uint8_t exp_ds_startup_cnt = mock_iolink_ds_startup_cnt; + uint8_t exp_ds_delete_cnt = mock_iolink_ds_delete_cnt; + uint8_t exp_smi_portcfg_cnf_cnt = mock_iolink_smi_portcfg_cnf_cnt + 1; + uint8_t exp_od_start_cnt = mock_iolink_od_start_cnt; + uint8_t exp_od_stop_cnt = mock_iolink_od_stop_cnt + 1; + uint8_t exp_pd_start_cnt = mock_iolink_pd_start_cnt; + uint8_t exp_pd_stop_cnt = mock_iolink_pd_stop_cnt + 1; uint8_t exp_smi_portevent_ind_cnt = mock_iolink_smi_portevent_ind_cnt; - memset (&port_cfg, 0, sizeof(arg_block_portconfiglist_t)); - port_cfg.arg_block_id = IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST; - port_cfg.configlist.port_cycle_time = exp_port_cycle_time; - port_cfg.configlist.vendorid = exp_vendorid; - port_cfg.configlist.deviceid = exp_deviceid; - port_cfg.configlist.in_buffer_len = 0; // TODO - port_cfg.configlist.out_buffer_len = 0; // TODO - port_cfg.configlist.portmode = IOLINK_PORTMODE_DEACTIVE; + memset (&port_cfg, 0, sizeof (arg_block_portconfiglist_t)); + port_cfg.arg_block_id = IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST; + port_cfg.configlist.port_cycle_time = exp_port_cycle_time; + port_cfg.configlist.vendorid = exp_vendorid; + port_cfg.configlist.deviceid = exp_deviceid; + port_cfg.configlist.in_buffer_len = 0; // TODO + port_cfg.configlist.out_buffer_len = 0; // TODO + port_cfg.configlist.portmode = IOLINK_PORTMODE_DEACTIVE; port_cfg.configlist.validation_backup = IOLINK_VALIDATION_CHECK_NO; - port_cfg.configlist.iq_behavior = IOLINK_IQ_BEHAVIOR_NO_SUPPORT; + port_cfg.configlist.iq_behavior = IOLINK_IQ_BEHAVIOR_NO_SUPPORT; EXPECT_EQ (exp_state, cm_get_state (port)); - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_PortConfiguration_req (iolink_get_portnumber (port), - IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - sizeof(arg_block_portconfiglist_t), - (arg_block_t *)&port_cfg)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_PortConfiguration_req ( + iolink_get_portnumber (port), + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + sizeof (arg_block_portconfiglist_t), + (arg_block_t *)&port_cfg)); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (CM_STATE_Port_Deactivated, cm_get_state (port)); cm_verify_smi_portcfg_cnf (exp_smi_portcfg_cnf_cnt); - cm_verify_paraml (exp_port_cycle_time, exp_target_mode, exp_revisionid, - exp_inspection_level, exp_vendorid, exp_deviceid); - cm_verify_portstatus (port, exp_status_info, exp_port_quality_info, - exp_revisionid, exp_trans_rate, exp_port_cycle_time, - exp_vendorid, exp_deviceid, 0, NULL); - cm_verify_mock_cnt (exp_sm_operate_cnt, exp_ds_startup_cnt, - exp_ds_delete_cnt, exp_od_start_cnt, exp_od_stop_cnt, - exp_pd_start_cnt, exp_pd_stop_cnt); + cm_verify_paraml ( + exp_port_cycle_time, + exp_target_mode, + exp_revisionid, + exp_inspection_level, + exp_vendorid, + exp_deviceid); + cm_verify_portstatus ( + port, + exp_status_info, + exp_port_quality_info, + exp_revisionid, + exp_trans_rate, + exp_port_cycle_time, + exp_vendorid, + exp_deviceid, + 0, + NULL); + cm_verify_mock_cnt ( + exp_sm_operate_cnt, + exp_ds_startup_cnt, + exp_ds_delete_cnt, + exp_od_start_cnt, + exp_od_stop_cnt, + exp_pd_start_cnt, + exp_pd_stop_cnt); SM_PortMode_ind (port, IOLINK_SM_PORTMODE_INACTIVE); mock_iolink_job.callback (&mock_iolink_job); @@ -686,9 +804,10 @@ static inline void cm_x_to_deactive (iolink_port_t * port, EXPECT_EQ (exp_smi_portevent_ind_cnt, mock_iolink_smi_portevent_ind_cnt); } -static inline void cm_check_mode_to_startup (iolink_port_t * port, - iolink_portmode_t mode, - iolink_validation_check_t validation) +static inline void cm_check_mode_to_startup ( + iolink_port_t * port, + iolink_portmode_t mode, + iolink_validation_check_t validation) { cm_x_to_deactive (port, CM_STATE_CheckPortMode); cm_deactive_to_startup (port, mode, validation); @@ -700,45 +819,54 @@ static inline void cm_all_portconfiguration (iolink_port_t * port) iolink_sm_target_mode_t exp_target_mode = IOLINK_SMTARGET_MODE_AUTOCOM; iolink_inspectionlevel_t exp_inspection_level = - IOLINK_INSPECTIONLEVEL_NO_CHECK; + IOLINK_INSPECTIONLEVEL_NO_CHECK; uint8_t exp_port_cycle_time = 0; // AFAP (As fast as possible) - uint8_t exp_revisionid = 0; - uint16_t exp_vendorid = 0; - uint32_t exp_deviceid = 0; + uint8_t exp_revisionid = 0; + uint16_t exp_vendorid = 0; + uint32_t exp_deviceid = 0; - uint8_t exp_sm_operate_cnt = mock_iolink_sm_operate_cnt; - uint8_t exp_ds_startup_cnt = mock_iolink_ds_startup_cnt; - uint8_t exp_ds_delete_cnt = mock_iolink_ds_delete_cnt; + uint8_t exp_sm_operate_cnt = mock_iolink_sm_operate_cnt; + uint8_t exp_ds_startup_cnt = mock_iolink_ds_startup_cnt; + uint8_t exp_ds_delete_cnt = mock_iolink_ds_delete_cnt; uint8_t exp_smi_portcfg_cnf_cnt = mock_iolink_smi_portcfg_cnf_cnt; - memset (&port_cfg, 0, sizeof(arg_block_portconfiglist_t)); - port_cfg.arg_block_id = IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST; - port_cfg.configlist.port_cycle_time = exp_port_cycle_time; - port_cfg.configlist.vendorid = exp_vendorid; - port_cfg.configlist.deviceid = exp_deviceid; - port_cfg.configlist.in_buffer_len = 0; // TODO - port_cfg.configlist.out_buffer_len = 0; // TODO - port_cfg.configlist.portmode = IOLINK_PORTMODE_IOL_AUTO; + memset (&port_cfg, 0, sizeof (arg_block_portconfiglist_t)); + port_cfg.arg_block_id = IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST; + port_cfg.configlist.port_cycle_time = exp_port_cycle_time; + port_cfg.configlist.vendorid = exp_vendorid; + port_cfg.configlist.deviceid = exp_deviceid; + port_cfg.configlist.in_buffer_len = 0; // TODO + port_cfg.configlist.out_buffer_len = 0; // TODO + port_cfg.configlist.portmode = IOLINK_PORTMODE_IOL_AUTO; port_cfg.configlist.validation_backup = IOLINK_VALIDATION_CHECK_NO; - port_cfg.configlist.iq_behavior = IOLINK_IQ_BEHAVIOR_NO_SUPPORT; + port_cfg.configlist.iq_behavior = IOLINK_IQ_BEHAVIOR_NO_SUPPORT; - cm_deactive_to_startup (port, IOLINK_PORTMODE_IOL_AUTO, - IOLINK_VALIDATION_CHECK_NO); + cm_deactive_to_startup ( + port, + IOLINK_PORTMODE_IOL_AUTO, + IOLINK_VALIDATION_CHECK_NO); exp_ds_delete_cnt++; exp_smi_portcfg_cnf_cnt++; EXPECT_EQ (mock_iolink_ds_delete_cnt, exp_ds_delete_cnt); - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_PortConfiguration_req (iolink_get_portnumber (port), - IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - sizeof(arg_block_portconfiglist_t), - (arg_block_t *)&port_cfg)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_PortConfiguration_req ( + iolink_get_portnumber (port), + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + sizeof (arg_block_portconfiglist_t), + (arg_block_t *)&port_cfg)); mock_iolink_job.callback (&mock_iolink_job); exp_ds_delete_cnt++; exp_smi_portcfg_cnf_cnt++; EXPECT_EQ (CM_STATE_SM_Startup, cm_get_state (port)); cm_verify_smi_portcfg_cnf (exp_smi_portcfg_cnf_cnt); - cm_verify_paraml (exp_port_cycle_time, exp_target_mode, exp_revisionid, - exp_inspection_level, exp_vendorid, exp_deviceid); + cm_verify_paraml ( + exp_port_cycle_time, + exp_target_mode, + exp_revisionid, + exp_inspection_level, + exp_vendorid, + exp_deviceid); EXPECT_EQ (mock_iolink_sm_operate_cnt, exp_sm_operate_cnt); EXPECT_EQ (mock_iolink_ds_startup_cnt, exp_ds_startup_cnt); EXPECT_EQ (mock_iolink_ds_delete_cnt, exp_ds_delete_cnt); @@ -748,11 +876,13 @@ static inline void cm_all_portconfiguration (iolink_port_t * port) exp_ds_startup_cnt++; exp_ds_delete_cnt++; /* Port configuration is ignored */ - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_PortConfiguration_req (iolink_get_portnumber (port), - IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - sizeof(arg_block_portconfiglist_t), - (arg_block_t *)&port_cfg)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_PortConfiguration_req ( + iolink_get_portnumber (port), + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + sizeof (arg_block_portconfiglist_t), + (arg_block_t *)&port_cfg)); mock_iolink_job.callback (&mock_iolink_job); exp_smi_portcfg_cnf_cnt++; EXPECT_EQ (CM_STATE_DS_ParamManager, cm_get_state (port)); @@ -761,34 +891,50 @@ static inline void cm_all_portconfiguration (iolink_port_t * port) EXPECT_EQ (CM_STATE_WaitingOnOperate, cm_get_state (port)); exp_sm_operate_cnt++; EXPECT_EQ (CM_STATE_WaitingOnOperate, cm_get_state (port)); - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_PortConfiguration_req (iolink_get_portnumber (port), - IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - sizeof(arg_block_portconfiglist_t), - (arg_block_t *)&port_cfg)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_PortConfiguration_req ( + iolink_get_portnumber (port), + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + sizeof (arg_block_portconfiglist_t), + (arg_block_t *)&port_cfg)); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (CM_STATE_SM_Startup, cm_get_state (port)); cm_verify_smi_portcfg_cnf (exp_smi_portcfg_cnf_cnt); - cm_verify_paraml (exp_port_cycle_time, exp_target_mode, exp_revisionid, - exp_inspection_level, exp_vendorid, exp_deviceid); + cm_verify_paraml ( + exp_port_cycle_time, + exp_target_mode, + exp_revisionid, + exp_inspection_level, + exp_vendorid, + exp_deviceid); EXPECT_EQ (mock_iolink_sm_operate_cnt, exp_sm_operate_cnt); EXPECT_EQ (mock_iolink_ds_startup_cnt, exp_ds_startup_cnt); EXPECT_EQ (mock_iolink_ds_delete_cnt, exp_ds_delete_cnt); - cm_startup_to_sm_port_fault (port, IOLINK_SM_PORTMODE_REVISION_FAULT, - mock_iolink_min_cycletime); + cm_startup_to_sm_port_fault ( + port, + IOLINK_SM_PORTMODE_REVISION_FAULT, + mock_iolink_min_cycletime); exp_ds_delete_cnt++; - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_PortConfiguration_req (iolink_get_portnumber (port), - IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - sizeof(arg_block_portconfiglist_t), - (arg_block_t *)&port_cfg)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_PortConfiguration_req ( + iolink_get_portnumber (port), + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + sizeof (arg_block_portconfiglist_t), + (arg_block_t *)&port_cfg)); mock_iolink_job.callback (&mock_iolink_job); exp_smi_portcfg_cnf_cnt++; EXPECT_EQ (CM_STATE_SM_Startup, cm_get_state (port)); cm_verify_smi_portcfg_cnf (exp_smi_portcfg_cnf_cnt); - cm_verify_paraml (exp_port_cycle_time, exp_target_mode, exp_revisionid, - exp_inspection_level, exp_vendorid, exp_deviceid); + cm_verify_paraml ( + exp_port_cycle_time, + exp_target_mode, + exp_revisionid, + exp_inspection_level, + exp_vendorid, + exp_deviceid); EXPECT_EQ (mock_iolink_sm_operate_cnt, exp_sm_operate_cnt); EXPECT_EQ (mock_iolink_ds_startup_cnt, exp_ds_startup_cnt); EXPECT_EQ (mock_iolink_ds_delete_cnt, exp_ds_delete_cnt); @@ -797,17 +943,24 @@ static inline void cm_all_portconfiguration (iolink_port_t * port) exp_ds_startup_cnt++; exp_sm_operate_cnt++; exp_ds_delete_cnt++; - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_PortConfiguration_req (iolink_get_portnumber (port), - IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - sizeof(arg_block_portconfiglist_t), - (arg_block_t *)&port_cfg)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_PortConfiguration_req ( + iolink_get_portnumber (port), + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + sizeof (arg_block_portconfiglist_t), + (arg_block_t *)&port_cfg)); mock_iolink_job.callback (&mock_iolink_job); exp_smi_portcfg_cnf_cnt++; EXPECT_EQ (CM_STATE_SM_Startup, cm_get_state (port)); cm_verify_smi_portcfg_cnf (exp_smi_portcfg_cnf_cnt); - cm_verify_paraml (exp_port_cycle_time, exp_target_mode, exp_revisionid, - exp_inspection_level, exp_vendorid, exp_deviceid); + cm_verify_paraml ( + exp_port_cycle_time, + exp_target_mode, + exp_revisionid, + exp_inspection_level, + exp_vendorid, + exp_deviceid); EXPECT_EQ (mock_iolink_sm_operate_cnt, exp_sm_operate_cnt); EXPECT_EQ (mock_iolink_ds_startup_cnt, exp_ds_startup_cnt); EXPECT_EQ (mock_iolink_ds_delete_cnt, exp_ds_delete_cnt); @@ -816,17 +969,24 @@ static inline void cm_all_portconfiguration (iolink_port_t * port) exp_ds_startup_cnt++; exp_sm_operate_cnt++; exp_ds_delete_cnt++; - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_PortConfiguration_req (iolink_get_portnumber (port), - IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - sizeof(arg_block_portconfiglist_t), - (arg_block_t *)&port_cfg)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_PortConfiguration_req ( + iolink_get_portnumber (port), + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + sizeof (arg_block_portconfiglist_t), + (arg_block_t *)&port_cfg)); mock_iolink_job.callback (&mock_iolink_job); exp_smi_portcfg_cnf_cnt++; EXPECT_EQ (CM_STATE_SM_Startup, cm_get_state (port)); cm_verify_smi_portcfg_cnf (exp_smi_portcfg_cnf_cnt); - cm_verify_paraml (exp_port_cycle_time, exp_target_mode, exp_revisionid, - exp_inspection_level, exp_vendorid, exp_deviceid); + cm_verify_paraml ( + exp_port_cycle_time, + exp_target_mode, + exp_revisionid, + exp_inspection_level, + exp_vendorid, + exp_deviceid); EXPECT_EQ (mock_iolink_sm_operate_cnt, exp_sm_operate_cnt); EXPECT_EQ (mock_iolink_ds_startup_cnt, exp_ds_startup_cnt); EXPECT_EQ (mock_iolink_ds_delete_cnt, exp_ds_delete_cnt); @@ -835,18 +995,25 @@ static inline void cm_all_portconfiguration (iolink_port_t * port) exp_ds_delete_cnt++; exp_smi_portcfg_cnf_cnt++; EXPECT_EQ (mock_iolink_ds_delete_cnt, exp_ds_delete_cnt); - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_PortConfiguration_req (iolink_get_portnumber (port), - IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - sizeof(arg_block_portconfiglist_t), - (arg_block_t *)&port_cfg)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_PortConfiguration_req ( + iolink_get_portnumber (port), + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + sizeof (arg_block_portconfiglist_t), + (arg_block_t *)&port_cfg)); mock_iolink_job.callback (&mock_iolink_job); exp_ds_delete_cnt++; exp_smi_portcfg_cnf_cnt++; EXPECT_EQ (CM_STATE_SM_Startup, cm_get_state (port)); cm_verify_smi_portcfg_cnf (exp_smi_portcfg_cnf_cnt); - cm_verify_paraml (exp_port_cycle_time, exp_target_mode, exp_revisionid, - exp_inspection_level, exp_vendorid, exp_deviceid); + cm_verify_paraml ( + exp_port_cycle_time, + exp_target_mode, + exp_revisionid, + exp_inspection_level, + exp_vendorid, + exp_deviceid); EXPECT_EQ (mock_iolink_sm_operate_cnt, exp_sm_operate_cnt); EXPECT_EQ (mock_iolink_ds_startup_cnt, exp_ds_startup_cnt); EXPECT_EQ (mock_iolink_ds_delete_cnt, exp_ds_delete_cnt); @@ -854,18 +1021,25 @@ static inline void cm_all_portconfiguration (iolink_port_t * port) cm_x_to_deactive (port, CM_STATE_SM_Startup); exp_smi_portcfg_cnf_cnt++; EXPECT_EQ (mock_iolink_ds_delete_cnt, exp_ds_delete_cnt); - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_PortConfiguration_req (iolink_get_portnumber (port), - IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - sizeof(arg_block_portconfiglist_t), - (arg_block_t *)&port_cfg)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_PortConfiguration_req ( + iolink_get_portnumber (port), + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + sizeof (arg_block_portconfiglist_t), + (arg_block_t *)&port_cfg)); mock_iolink_job.callback (&mock_iolink_job); exp_ds_delete_cnt++; exp_smi_portcfg_cnf_cnt++; EXPECT_EQ (CM_STATE_SM_Startup, cm_get_state (port)); cm_verify_smi_portcfg_cnf (exp_smi_portcfg_cnf_cnt); - cm_verify_paraml (exp_port_cycle_time, exp_target_mode, exp_revisionid, - exp_inspection_level, exp_vendorid, exp_deviceid); + cm_verify_paraml ( + exp_port_cycle_time, + exp_target_mode, + exp_revisionid, + exp_inspection_level, + exp_vendorid, + exp_deviceid); EXPECT_EQ (mock_iolink_sm_operate_cnt, exp_sm_operate_cnt); EXPECT_EQ (mock_iolink_ds_startup_cnt, exp_ds_startup_cnt); EXPECT_EQ (mock_iolink_ds_delete_cnt, exp_ds_delete_cnt); @@ -874,20 +1048,26 @@ static inline void cm_all_portconfiguration (iolink_port_t * port) // Tests TEST_F (CMTest, Cm_startup_autostart) { - cm_deactive_to_startup (port, IOLINK_PORTMODE_IOL_AUTO, - IOLINK_VALIDATION_CHECK_NO); + cm_deactive_to_startup ( + port, + IOLINK_PORTMODE_IOL_AUTO, + IOLINK_VALIDATION_CHECK_NO); } TEST_F (CMTest, Cm_startup_manual_v11) { - cm_deactive_to_startup (port, IOLINK_PORTMODE_IOL_MAN, - IOLINK_VALIDATION_CHECK_V11); + cm_deactive_to_startup ( + port, + IOLINK_PORTMODE_IOL_MAN, + IOLINK_VALIDATION_CHECK_V11); } TEST_F (CMTest, Cm_startup_manual_v10) { - cm_deactive_to_startup (port, IOLINK_PORTMODE_IOL_MAN, - IOLINK_VALIDATION_CHECK_V10); + cm_deactive_to_startup ( + port, + IOLINK_PORTMODE_IOL_MAN, + IOLINK_VALIDATION_CHECK_V10); } TEST_F (CMTest, Cm_ds_parammanager) @@ -917,9 +1097,9 @@ TEST_F (CMTest, Cm_startup_fault_cycletime) TEST_F (CMTest, Cm_ds_parammanager_comlost) { - uint8_t exp_sm_operate_cnt = mock_iolink_sm_operate_cnt; - uint8_t exp_ds_startup_cnt = mock_iolink_ds_startup_cnt + 1; - uint8_t exp_ds_delete_cnt = mock_iolink_ds_delete_cnt + 1; + uint8_t exp_sm_operate_cnt = mock_iolink_sm_operate_cnt; + uint8_t exp_ds_startup_cnt = mock_iolink_ds_startup_cnt + 1; + uint8_t exp_ds_delete_cnt = mock_iolink_ds_delete_cnt + 1; uint8_t exp_smi_portcfg_cnf_cnt = mock_iolink_smi_portcfg_cnf_cnt; cm_deactive_to_ds_parammanager (port); @@ -946,7 +1126,7 @@ TEST_F (CMTest, Cm_ds_parammanager_lock) { uint8_t exp_sm_operate_cnt = mock_iolink_sm_operate_cnt; uint8_t exp_ds_startup_cnt = mock_iolink_ds_startup_cnt + 1; - uint8_t exp_ds_delete_cnt = mock_iolink_ds_delete_cnt + 1; + uint8_t exp_ds_delete_cnt = mock_iolink_ds_delete_cnt + 1; cm_deactive_to_ds_parammanager (port); DS_Fault (port, IOLINK_DS_FAULT_LOCK); @@ -962,7 +1142,7 @@ TEST_F (CMTest, Cm_ds_parammanager_id) { uint8_t exp_sm_operate_cnt = mock_iolink_sm_operate_cnt; uint8_t exp_ds_startup_cnt = mock_iolink_ds_startup_cnt + 1; - uint8_t exp_ds_delete_cnt = mock_iolink_ds_delete_cnt + 1; + uint8_t exp_ds_delete_cnt = mock_iolink_ds_delete_cnt + 1; cm_deactive_to_ds_parammanager (port); DS_Fault (port, IOLINK_DS_FAULT_ID); @@ -978,7 +1158,7 @@ TEST_F (CMTest, Cm_ds_parammanager_size) { uint8_t exp_sm_operate_cnt = mock_iolink_sm_operate_cnt; uint8_t exp_ds_startup_cnt = mock_iolink_ds_startup_cnt + 1; - uint8_t exp_ds_delete_cnt = mock_iolink_ds_delete_cnt + 1; + uint8_t exp_ds_delete_cnt = mock_iolink_ds_delete_cnt + 1; cm_deactive_to_ds_parammanager (port); DS_Fault (port, IOLINK_DS_FAULT_SIZE); @@ -994,7 +1174,7 @@ TEST_F (CMTest, Cm_ds_parammanager_fault_down) { uint8_t exp_sm_operate_cnt = mock_iolink_sm_operate_cnt; uint8_t exp_ds_startup_cnt = mock_iolink_ds_startup_cnt + 1; - uint8_t exp_ds_delete_cnt = mock_iolink_ds_delete_cnt + 1; + uint8_t exp_ds_delete_cnt = mock_iolink_ds_delete_cnt + 1; cm_deactive_to_ds_parammanager (port); DS_Fault (port, IOLINK_DS_FAULT_DOWN); @@ -1010,7 +1190,7 @@ TEST_F (CMTest, Cm_ds_parammanager_fault_up) { uint8_t exp_sm_operate_cnt = mock_iolink_sm_operate_cnt; uint8_t exp_ds_startup_cnt = mock_iolink_ds_startup_cnt + 1; - uint8_t exp_ds_delete_cnt = mock_iolink_ds_delete_cnt + 1; + uint8_t exp_ds_delete_cnt = mock_iolink_ds_delete_cnt + 1; cm_deactive_to_ds_parammanager (port); DS_Fault (port, IOLINK_DS_FAULT_UP); @@ -1060,13 +1240,15 @@ TEST_F (CMTest, Cm_do) TEST_F (CMTest, Cm_sm_COMLOST) { - uint8_t exp_sm_operate_cnt = mock_iolink_sm_operate_cnt; - uint8_t exp_ds_startup_cnt = mock_iolink_ds_startup_cnt; - uint8_t exp_ds_delete_cnt = mock_iolink_ds_delete_cnt; + uint8_t exp_sm_operate_cnt = mock_iolink_sm_operate_cnt; + uint8_t exp_ds_startup_cnt = mock_iolink_ds_startup_cnt; + uint8_t exp_ds_delete_cnt = mock_iolink_ds_delete_cnt; uint8_t exp_smi_portcfg_cnf_cnt = mock_iolink_smi_portcfg_cnf_cnt; - cm_deactive_to_startup (port, IOLINK_PORTMODE_IOL_AUTO, - IOLINK_VALIDATION_CHECK_NO); + cm_deactive_to_startup ( + port, + IOLINK_PORTMODE_IOL_AUTO, + IOLINK_VALIDATION_CHECK_NO); exp_smi_portcfg_cnf_cnt++; EXPECT_EQ (exp_smi_portcfg_cnf_cnt, mock_iolink_smi_portcfg_cnf_cnt); exp_ds_delete_cnt++; @@ -1081,8 +1263,10 @@ TEST_F (CMTest, Cm_sm_COMLOST) /* COMLOST for DS_ParamManager_2 is tested in Cm_ds_parammanager_comlost */ - cm_check_mode_to_startup (port, IOLINK_PORTMODE_IOL_AUTO, - IOLINK_VALIDATION_CHECK_NO); + cm_check_mode_to_startup ( + port, + IOLINK_PORTMODE_IOL_AUTO, + IOLINK_VALIDATION_CHECK_NO); exp_smi_portcfg_cnf_cnt += 2; EXPECT_EQ (exp_smi_portcfg_cnf_cnt, mock_iolink_smi_portcfg_cnf_cnt); cm_startup_to_sm_port_fault (port, IOLINK_SM_PORTMODE_REVISION_FAULT, 0); @@ -1095,8 +1279,10 @@ TEST_F (CMTest, Cm_sm_COMLOST) EXPECT_EQ (mock_iolink_ds_startup_cnt, exp_ds_startup_cnt); EXPECT_EQ (mock_iolink_ds_delete_cnt, exp_ds_delete_cnt); - cm_check_mode_to_startup (port, IOLINK_PORTMODE_IOL_AUTO, - IOLINK_VALIDATION_CHECK_NO); + cm_check_mode_to_startup ( + port, + IOLINK_PORTMODE_IOL_AUTO, + IOLINK_VALIDATION_CHECK_NO); exp_smi_portcfg_cnf_cnt += 2; EXPECT_EQ (exp_smi_portcfg_cnf_cnt, mock_iolink_smi_portcfg_cnf_cnt); cm_startup_to_waiting_on_op (port); @@ -1111,8 +1297,10 @@ TEST_F (CMTest, Cm_sm_COMLOST) EXPECT_EQ (mock_iolink_ds_startup_cnt, exp_ds_startup_cnt); EXPECT_EQ (mock_iolink_ds_delete_cnt, exp_ds_delete_cnt); - cm_check_mode_to_startup (port, IOLINK_PORTMODE_IOL_AUTO, - IOLINK_VALIDATION_CHECK_NO); + cm_check_mode_to_startup ( + port, + IOLINK_PORTMODE_IOL_AUTO, + IOLINK_VALIDATION_CHECK_NO); exp_smi_portcfg_cnf_cnt += 2; cm_startup_to_port_active (port); exp_sm_operate_cnt++; @@ -1137,7 +1325,7 @@ TEST_F (CMTest, Cm_DS_Change) { uint8_t exp_sm_operate_cnt = mock_iolink_sm_operate_cnt; uint8_t exp_ds_startup_cnt = mock_iolink_ds_startup_cnt; - uint8_t exp_ds_delete_cnt = mock_iolink_ds_delete_cnt + 1; + uint8_t exp_ds_delete_cnt = mock_iolink_ds_delete_cnt + 1; cm_deactive_to_ds_parammanager (port); exp_ds_startup_cnt++; @@ -1148,8 +1336,10 @@ TEST_F (CMTest, Cm_DS_Change) EXPECT_EQ (mock_iolink_ds_startup_cnt, exp_ds_startup_cnt); EXPECT_EQ (mock_iolink_ds_delete_cnt, exp_ds_delete_cnt); - cm_startup_to_sm_port_fault (port, IOLINK_SM_PORTMODE_REVISION_FAULT, - mock_iolink_min_cycletime); + cm_startup_to_sm_port_fault ( + port, + IOLINK_SM_PORTMODE_REVISION_FAULT, + mock_iolink_min_cycletime); DS_Change (port); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (CM_STATE_SM_Startup, cm_get_state (port)); @@ -1204,52 +1394,70 @@ TEST_F (CMTest, Cm_SMI_PortConfig_unknown_portmode) iolink_sm_target_mode_t exp_target_mode = IOLINK_SMTARGET_MODE_INACTIVE; iolink_inspectionlevel_t exp_inspection_level = - IOLINK_INSPECTIONLEVEL_NO_CHECK; + IOLINK_INSPECTIONLEVEL_NO_CHECK; iolink_port_status_info_t exp_status_info = - IOLINK_PORT_STATUS_INFO_DEACTIVATED; + IOLINK_PORT_STATUS_INFO_DEACTIVATED; uint8_t exp_port_quality_info = IOLINK_PORT_QUALITY_INFO_INVALID; - uint8_t exp_port_cycle_time = 0; - uint8_t exp_revisionid = 0; + uint8_t exp_port_cycle_time = 0; + uint8_t exp_revisionid = 0; iolink_transmission_rate_t exp_trans_rate = - IOLINK_TRANSMISSION_RATE_NOT_DETECTED; + IOLINK_TRANSMISSION_RATE_NOT_DETECTED; uint16_t exp_vendorid = 0; uint32_t exp_deviceid = 0; - uint8_t exp_sm_operate_cnt = mock_iolink_sm_operate_cnt; - uint8_t exp_ds_startup_cnt = mock_iolink_ds_startup_cnt; - uint8_t exp_ds_delete_cnt = mock_iolink_ds_delete_cnt + 1; + uint8_t exp_sm_operate_cnt = mock_iolink_sm_operate_cnt; + uint8_t exp_ds_startup_cnt = mock_iolink_ds_startup_cnt; + uint8_t exp_ds_delete_cnt = mock_iolink_ds_delete_cnt + 1; uint8_t exp_smi_joberror_cnt = mock_iolink_smi_joberror_cnt + 1; - memset (&port_cfg, 0, sizeof(arg_block_portconfiglist_t)); - port_cfg.arg_block_id = IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST; - port_cfg.configlist.port_cycle_time = exp_port_cycle_time; - port_cfg.configlist.vendorid = exp_vendorid; - port_cfg.configlist.deviceid = exp_deviceid; - port_cfg.configlist.in_buffer_len = 0; // TODO - port_cfg.configlist.out_buffer_len = 0; // TODO + memset (&port_cfg, 0, sizeof (arg_block_portconfiglist_t)); + port_cfg.arg_block_id = IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST; + port_cfg.configlist.port_cycle_time = exp_port_cycle_time; + port_cfg.configlist.vendorid = exp_vendorid; + port_cfg.configlist.deviceid = exp_deviceid; + port_cfg.configlist.in_buffer_len = 0; // TODO + port_cfg.configlist.out_buffer_len = 0; // TODO port_cfg.configlist.validation_backup = IOLINK_VALIDATION_CHECK_NO; - port_cfg.configlist.iq_behavior = IOLINK_IQ_BEHAVIOR_NO_SUPPORT; + port_cfg.configlist.iq_behavior = IOLINK_IQ_BEHAVIOR_NO_SUPPORT; port_cfg.configlist.portmode = (iolink_portmode_t)189; /* Bad value */ EXPECT_EQ (CM_STATE_Port_Deactivated, cm_get_state (port)); - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_PortConfiguration_req (portnumber, - IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - sizeof(arg_block_portconfiglist_t), - (arg_block_t *)&port_cfg)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_PortConfiguration_req ( + portnumber, + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + sizeof (arg_block_portconfiglist_t), + (arg_block_t *)&port_cfg)); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (CM_STATE_Port_Deactivated, cm_get_state (port)); - cm_verify_smi_err (IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST, - IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - IOLINK_SMI_ERRORTYPE_ARGBLOCK_INCONSISTENT, - exp_smi_joberror_cnt, 0, 0); - cm_verify_paraml (exp_port_cycle_time, exp_target_mode, exp_revisionid, - exp_inspection_level, exp_vendorid, exp_deviceid); - cm_verify_portstatus (port, exp_status_info, exp_port_quality_info, - exp_revisionid, exp_trans_rate, exp_port_cycle_time, - exp_vendorid, exp_deviceid, 0, NULL); + cm_verify_smi_err ( + IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST, + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + IOLINK_SMI_ERRORTYPE_ARGBLOCK_INCONSISTENT, + exp_smi_joberror_cnt, + 0, + 0); + cm_verify_paraml ( + exp_port_cycle_time, + exp_target_mode, + exp_revisionid, + exp_inspection_level, + exp_vendorid, + exp_deviceid); + cm_verify_portstatus ( + port, + exp_status_info, + exp_port_quality_info, + exp_revisionid, + exp_trans_rate, + exp_port_cycle_time, + exp_vendorid, + exp_deviceid, + 0, + NULL); EXPECT_EQ (mock_iolink_sm_operate_cnt, exp_sm_operate_cnt); EXPECT_EQ (mock_iolink_ds_startup_cnt, exp_ds_startup_cnt); @@ -1262,51 +1470,69 @@ TEST_F (CMTest, Cm_SMI_PortConfig_unknown_validation_backup) iolink_sm_target_mode_t exp_target_mode = IOLINK_SMTARGET_MODE_INACTIVE; iolink_inspectionlevel_t exp_inspection_level = - IOLINK_INSPECTIONLEVEL_NO_CHECK; + IOLINK_INSPECTIONLEVEL_NO_CHECK; iolink_port_status_info_t exp_status_info = - IOLINK_PORT_STATUS_INFO_DEACTIVATED; + IOLINK_PORT_STATUS_INFO_DEACTIVATED; uint8_t exp_port_quality_info = IOLINK_PORT_QUALITY_INFO_INVALID; - uint8_t exp_port_cycle_time = 0; - uint8_t exp_revisionid = 0; + uint8_t exp_port_cycle_time = 0; + uint8_t exp_revisionid = 0; iolink_transmission_rate_t exp_trans_rate = - IOLINK_TRANSMISSION_RATE_NOT_DETECTED; + IOLINK_TRANSMISSION_RATE_NOT_DETECTED; uint16_t exp_vendorid = 0; uint32_t exp_deviceid = 0; - uint8_t exp_sm_operate_cnt = mock_iolink_sm_operate_cnt; - uint8_t exp_ds_startup_cnt = mock_iolink_ds_startup_cnt; - uint8_t exp_ds_delete_cnt = mock_iolink_ds_delete_cnt + 1; + uint8_t exp_sm_operate_cnt = mock_iolink_sm_operate_cnt; + uint8_t exp_ds_startup_cnt = mock_iolink_ds_startup_cnt; + uint8_t exp_ds_delete_cnt = mock_iolink_ds_delete_cnt + 1; uint8_t exp_smi_joberror_cnt = mock_iolink_smi_joberror_cnt + 1; - memset (&port_cfg, 0, sizeof(arg_block_portconfiglist_t)); - port_cfg.arg_block_id = IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST; + memset (&port_cfg, 0, sizeof (arg_block_portconfiglist_t)); + port_cfg.arg_block_id = IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST; port_cfg.configlist.port_cycle_time = exp_port_cycle_time; - port_cfg.configlist.vendorid = exp_vendorid; - port_cfg.configlist.deviceid = exp_deviceid; - port_cfg.configlist.in_buffer_len = 0; // TODO - port_cfg.configlist.out_buffer_len = 0; // TODO - port_cfg.configlist.iq_behavior = IOLINK_IQ_BEHAVIOR_NO_SUPPORT; + port_cfg.configlist.vendorid = exp_vendorid; + port_cfg.configlist.deviceid = exp_deviceid; + port_cfg.configlist.in_buffer_len = 0; // TODO + port_cfg.configlist.out_buffer_len = 0; // TODO + port_cfg.configlist.iq_behavior = IOLINK_IQ_BEHAVIOR_NO_SUPPORT; /* Bad value */ port_cfg.configlist.validation_backup = (iolink_validation_check_t)189; EXPECT_EQ (CM_STATE_Port_Deactivated, cm_get_state (port)); - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_PortConfiguration_req (portnumber, - IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - sizeof(arg_block_portconfiglist_t), - (arg_block_t *)&port_cfg)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_PortConfiguration_req ( + portnumber, + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + sizeof (arg_block_portconfiglist_t), + (arg_block_t *)&port_cfg)); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (CM_STATE_Port_Deactivated, cm_get_state (port)); - cm_verify_smi_err (IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST, - IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - IOLINK_SMI_ERRORTYPE_ARGBLOCK_INCONSISTENT, - exp_smi_joberror_cnt, 0, 0); - cm_verify_paraml (exp_port_cycle_time, exp_target_mode, exp_revisionid, - exp_inspection_level, exp_vendorid, exp_deviceid); - cm_verify_portstatus (port, exp_status_info, exp_port_quality_info, - exp_revisionid, exp_trans_rate, exp_port_cycle_time, - exp_vendorid, exp_deviceid, 0, NULL); + cm_verify_smi_err ( + IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST, + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + IOLINK_SMI_ERRORTYPE_ARGBLOCK_INCONSISTENT, + exp_smi_joberror_cnt, + 0, + 0); + cm_verify_paraml ( + exp_port_cycle_time, + exp_target_mode, + exp_revisionid, + exp_inspection_level, + exp_vendorid, + exp_deviceid); + cm_verify_portstatus ( + port, + exp_status_info, + exp_port_quality_info, + exp_revisionid, + exp_trans_rate, + exp_port_cycle_time, + exp_vendorid, + exp_deviceid, + 0, + NULL); EXPECT_EQ (mock_iolink_sm_operate_cnt, exp_sm_operate_cnt); EXPECT_EQ (mock_iolink_ds_startup_cnt, exp_ds_startup_cnt); @@ -1319,51 +1545,69 @@ TEST_F (CMTest, Cm_SMI_PortConfig_unknown_iq_behavior) iolink_sm_target_mode_t exp_target_mode = IOLINK_SMTARGET_MODE_INACTIVE; iolink_inspectionlevel_t exp_inspection_level = - IOLINK_INSPECTIONLEVEL_NO_CHECK; + IOLINK_INSPECTIONLEVEL_NO_CHECK; iolink_port_status_info_t exp_status_info = - IOLINK_PORT_STATUS_INFO_DEACTIVATED; + IOLINK_PORT_STATUS_INFO_DEACTIVATED; uint8_t exp_port_quality_info = IOLINK_PORT_QUALITY_INFO_INVALID; - uint8_t exp_port_cycle_time = 0; - uint8_t exp_revisionid = 0; + uint8_t exp_port_cycle_time = 0; + uint8_t exp_revisionid = 0; iolink_transmission_rate_t exp_trans_rate = - IOLINK_TRANSMISSION_RATE_NOT_DETECTED; + IOLINK_TRANSMISSION_RATE_NOT_DETECTED; uint16_t exp_vendorid = 0; uint32_t exp_deviceid = 0; - uint8_t exp_sm_operate_cnt = mock_iolink_sm_operate_cnt; - uint8_t exp_ds_startup_cnt = mock_iolink_ds_startup_cnt; - uint8_t exp_ds_delete_cnt = mock_iolink_ds_delete_cnt + 1; + uint8_t exp_sm_operate_cnt = mock_iolink_sm_operate_cnt; + uint8_t exp_ds_startup_cnt = mock_iolink_ds_startup_cnt; + uint8_t exp_ds_delete_cnt = mock_iolink_ds_delete_cnt + 1; uint8_t exp_smi_joberror_cnt = mock_iolink_smi_joberror_cnt + 1; - memset (&port_cfg, 0, sizeof(arg_block_portconfiglist_t)); - port_cfg.arg_block_id = IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST; - port_cfg.configlist.port_cycle_time = exp_port_cycle_time; - port_cfg.configlist.vendorid = exp_vendorid; - port_cfg.configlist.deviceid = exp_deviceid; - port_cfg.configlist.in_buffer_len = 0; // TODO - port_cfg.configlist.out_buffer_len = 0; // TODO + memset (&port_cfg, 0, sizeof (arg_block_portconfiglist_t)); + port_cfg.arg_block_id = IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST; + port_cfg.configlist.port_cycle_time = exp_port_cycle_time; + port_cfg.configlist.vendorid = exp_vendorid; + port_cfg.configlist.deviceid = exp_deviceid; + port_cfg.configlist.in_buffer_len = 0; // TODO + port_cfg.configlist.out_buffer_len = 0; // TODO port_cfg.configlist.validation_backup = IOLINK_VALIDATION_CHECK_NO; port_cfg.configlist.iq_behavior = (iolink_iq_behavior_t)189; /* Bad value */ EXPECT_EQ (CM_STATE_Port_Deactivated, cm_get_state (port)); - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_PortConfiguration_req (portnumber, - IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - sizeof(arg_block_portconfiglist_t), - (arg_block_t *)&port_cfg)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_PortConfiguration_req ( + portnumber, + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + sizeof (arg_block_portconfiglist_t), + (arg_block_t *)&port_cfg)); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (CM_STATE_Port_Deactivated, cm_get_state (port)); - cm_verify_smi_err (IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST, - IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - IOLINK_SMI_ERRORTYPE_ARGBLOCK_INCONSISTENT, - exp_smi_joberror_cnt, 0, 0); - cm_verify_paraml (exp_port_cycle_time, exp_target_mode, exp_revisionid, - exp_inspection_level, exp_vendorid, exp_deviceid); - cm_verify_portstatus (port, exp_status_info, exp_port_quality_info, - exp_revisionid, exp_trans_rate, exp_port_cycle_time, - exp_vendorid, exp_deviceid, 0, NULL); + cm_verify_smi_err ( + IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST, + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + IOLINK_SMI_ERRORTYPE_ARGBLOCK_INCONSISTENT, + exp_smi_joberror_cnt, + 0, + 0); + cm_verify_paraml ( + exp_port_cycle_time, + exp_target_mode, + exp_revisionid, + exp_inspection_level, + exp_vendorid, + exp_deviceid); + cm_verify_portstatus ( + port, + exp_status_info, + exp_port_quality_info, + exp_revisionid, + exp_trans_rate, + exp_port_cycle_time, + exp_vendorid, + exp_deviceid, + 0, + NULL); EXPECT_EQ (mock_iolink_sm_operate_cnt, exp_sm_operate_cnt); EXPECT_EQ (mock_iolink_ds_startup_cnt, exp_ds_startup_cnt); @@ -1374,8 +1618,8 @@ TEST_F (CMTest, CM_ignore_additional_DS_Ready) { int i; - uint8_t exp_sm_operate_cnt = mock_iolink_sm_operate_cnt + 1; - uint8_t exp_ds_startup_cnt = mock_iolink_ds_startup_cnt + 1; + uint8_t exp_sm_operate_cnt = mock_iolink_sm_operate_cnt + 1; + uint8_t exp_ds_startup_cnt = mock_iolink_ds_startup_cnt + 1; uint8_t exp_smi_portevent_ind_cnt = mock_iolink_smi_portevent_ind_cnt + 1; cm_deactive_to_port_active (port); @@ -1398,49 +1642,63 @@ TEST_F (CMTest, Cm_SMI_PortConfig_bad_argblock) arg_block_portconfiglist_t port_cfg; iolink_port_status_info_t exp_status_info = - IOLINK_PORT_STATUS_INFO_DEACTIVATED; + IOLINK_PORT_STATUS_INFO_DEACTIVATED; uint8_t exp_port_quality_info = IOLINK_PORT_QUALITY_INFO_INVALID; - uint8_t exp_port_cycle_time = 0; - uint8_t exp_revisionid = 0; + uint8_t exp_port_cycle_time = 0; + uint8_t exp_revisionid = 0; iolink_transmission_rate_t exp_trans_rate = - IOLINK_TRANSMISSION_RATE_NOT_DETECTED; + IOLINK_TRANSMISSION_RATE_NOT_DETECTED; uint16_t exp_vendorid = 0; uint32_t exp_deviceid = 0; - uint8_t exp_sm_operate_cnt = mock_iolink_sm_operate_cnt; - uint8_t exp_ds_startup_cnt = mock_iolink_ds_startup_cnt; - uint8_t exp_ds_delete_cnt = mock_iolink_ds_delete_cnt; + uint8_t exp_sm_operate_cnt = mock_iolink_sm_operate_cnt; + uint8_t exp_ds_startup_cnt = mock_iolink_ds_startup_cnt; + uint8_t exp_ds_delete_cnt = mock_iolink_ds_delete_cnt; uint8_t exp_smi_joberror_cnt = mock_iolink_smi_joberror_cnt + 1; iolink_arg_block_id_t bad_arg_block_id = IOLINK_ARG_BLOCK_ID_MASTERIDENT; - memset (&port_cfg, 0, sizeof(arg_block_portconfiglist_t)); - port_cfg.configlist.port_cycle_time = exp_port_cycle_time; - port_cfg.configlist.vendorid = exp_vendorid; - port_cfg.configlist.deviceid = exp_deviceid; - port_cfg.configlist.in_buffer_len = 0; // TODO - port_cfg.configlist.out_buffer_len = 0; // TODO + memset (&port_cfg, 0, sizeof (arg_block_portconfiglist_t)); + port_cfg.configlist.port_cycle_time = exp_port_cycle_time; + port_cfg.configlist.vendorid = exp_vendorid; + port_cfg.configlist.deviceid = exp_deviceid; + port_cfg.configlist.in_buffer_len = 0; // TODO + port_cfg.configlist.out_buffer_len = 0; // TODO port_cfg.configlist.validation_backup = IOLINK_VALIDATION_CHECK_NO; - port_cfg.configlist.iq_behavior = IOLINK_IQ_BEHAVIOR_NO_SUPPORT; + port_cfg.configlist.iq_behavior = IOLINK_IQ_BEHAVIOR_NO_SUPPORT; /* Bad ArgBlockID */ port_cfg.arg_block_id = bad_arg_block_id; EXPECT_EQ (CM_STATE_Port_Deactivated, cm_get_state (port)); - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_PortConfiguration_req (portnumber, - IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - sizeof(arg_block_portconfiglist_t), - (arg_block_t *)&port_cfg)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_PortConfiguration_req ( + portnumber, + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + sizeof (arg_block_portconfiglist_t), + (arg_block_t *)&port_cfg)); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (CM_STATE_Port_Deactivated, cm_get_state (port)); - cm_verify_smi_err (bad_arg_block_id, IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - IOLINK_SMI_ERRORTYPE_ARGBLOCK_NOT_SUPPORTED, - exp_smi_joberror_cnt, 0, 0); - cm_verify_portstatus (port, exp_status_info, exp_port_quality_info, - exp_revisionid, exp_trans_rate, exp_port_cycle_time, - exp_vendorid, exp_deviceid, 0, NULL); + cm_verify_smi_err ( + bad_arg_block_id, + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + IOLINK_SMI_ERRORTYPE_ARGBLOCK_NOT_SUPPORTED, + exp_smi_joberror_cnt, + 0, + 0); + cm_verify_portstatus ( + port, + exp_status_info, + exp_port_quality_info, + exp_revisionid, + exp_trans_rate, + exp_port_cycle_time, + exp_vendorid, + exp_deviceid, + 0, + NULL); EXPECT_EQ (mock_iolink_sm_operate_cnt, exp_sm_operate_cnt); EXPECT_EQ (mock_iolink_ds_startup_cnt, exp_ds_startup_cnt); @@ -1452,50 +1710,63 @@ TEST_F (CMTest, Cm_SMI_PortConfig_bad_exp_arg_block_id) arg_block_portconfiglist_t port_cfg; iolink_port_status_info_t exp_status_info = - IOLINK_PORT_STATUS_INFO_DEACTIVATED; + IOLINK_PORT_STATUS_INFO_DEACTIVATED; uint8_t exp_port_quality_info = IOLINK_PORT_QUALITY_INFO_INVALID; - uint8_t exp_port_cycle_time = 0; - uint8_t exp_revisionid = 0; + uint8_t exp_port_cycle_time = 0; + uint8_t exp_revisionid = 0; iolink_transmission_rate_t exp_trans_rate = - IOLINK_TRANSMISSION_RATE_NOT_DETECTED; + IOLINK_TRANSMISSION_RATE_NOT_DETECTED; uint16_t exp_vendorid = 0; uint32_t exp_deviceid = 0; - uint8_t exp_sm_operate_cnt = mock_iolink_sm_operate_cnt; - uint8_t exp_ds_startup_cnt = mock_iolink_ds_startup_cnt; - uint8_t exp_ds_delete_cnt = mock_iolink_ds_delete_cnt; + uint8_t exp_sm_operate_cnt = mock_iolink_sm_operate_cnt; + uint8_t exp_ds_startup_cnt = mock_iolink_ds_startup_cnt; + uint8_t exp_ds_delete_cnt = mock_iolink_ds_delete_cnt; uint8_t exp_smi_joberror_cnt = mock_iolink_smi_joberror_cnt + 1; iolink_arg_block_id_t bad_exp_arg_block_id = IOLINK_ARG_BLOCK_ID_DS_DATA; - memset (&port_cfg, 0, sizeof(arg_block_portconfiglist_t)); - port_cfg.configlist.port_cycle_time = exp_port_cycle_time; - port_cfg.configlist.vendorid = exp_vendorid; - port_cfg.configlist.deviceid = exp_deviceid; - port_cfg.configlist.in_buffer_len = 0; // TODO - port_cfg.configlist.out_buffer_len = 0; // TODO + memset (&port_cfg, 0, sizeof (arg_block_portconfiglist_t)); + port_cfg.configlist.port_cycle_time = exp_port_cycle_time; + port_cfg.configlist.vendorid = exp_vendorid; + port_cfg.configlist.deviceid = exp_deviceid; + port_cfg.configlist.in_buffer_len = 0; // TODO + port_cfg.configlist.out_buffer_len = 0; // TODO port_cfg.configlist.validation_backup = IOLINK_VALIDATION_CHECK_NO; - port_cfg.configlist.iq_behavior = IOLINK_IQ_BEHAVIOR_NO_SUPPORT; + port_cfg.configlist.iq_behavior = IOLINK_IQ_BEHAVIOR_NO_SUPPORT; port_cfg.arg_block_id = IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST; EXPECT_EQ (CM_STATE_Port_Deactivated, cm_get_state (port)); - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_PortConfiguration_req (portnumber, - /* Bad exp_arg_block_id */ - bad_exp_arg_block_id, - sizeof(arg_block_portconfiglist_t), - (arg_block_t *)&port_cfg)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_PortConfiguration_req ( + portnumber, + /* Bad exp_arg_block_id */ + bad_exp_arg_block_id, + sizeof (arg_block_portconfiglist_t), + (arg_block_t *)&port_cfg)); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (CM_STATE_Port_Deactivated, cm_get_state (port)); - cm_verify_smi_err (IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST, - bad_exp_arg_block_id, - IOLINK_SMI_ERRORTYPE_ARGBLOCK_INCONSISTENT, - exp_smi_joberror_cnt, 0, 0); - cm_verify_portstatus (port, exp_status_info, exp_port_quality_info, - exp_revisionid, exp_trans_rate, exp_port_cycle_time, - exp_vendorid, exp_deviceid, 0, NULL); + cm_verify_smi_err ( + IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST, + bad_exp_arg_block_id, + IOLINK_SMI_ERRORTYPE_ARGBLOCK_INCONSISTENT, + exp_smi_joberror_cnt, + 0, + 0); + cm_verify_portstatus ( + port, + exp_status_info, + exp_port_quality_info, + exp_revisionid, + exp_trans_rate, + exp_port_cycle_time, + exp_vendorid, + exp_deviceid, + 0, + NULL); EXPECT_EQ (mock_iolink_sm_operate_cnt, exp_sm_operate_cnt); EXPECT_EQ (mock_iolink_ds_startup_cnt, exp_ds_startup_cnt); @@ -1507,47 +1778,60 @@ TEST_F (CMTest, Cm_SMI_PortConfig_bad_argblock_len) arg_block_portconfiglist_t port_cfg; iolink_port_status_info_t exp_status_info = - IOLINK_PORT_STATUS_INFO_DEACTIVATED; + IOLINK_PORT_STATUS_INFO_DEACTIVATED; uint8_t exp_port_quality_info = IOLINK_PORT_QUALITY_INFO_INVALID; - uint8_t exp_port_cycle_time = 0; - uint8_t exp_revisionid = 0; + uint8_t exp_port_cycle_time = 0; + uint8_t exp_revisionid = 0; iolink_transmission_rate_t exp_trans_rate = - IOLINK_TRANSMISSION_RATE_NOT_DETECTED; + IOLINK_TRANSMISSION_RATE_NOT_DETECTED; uint16_t exp_vendorid = 0; uint32_t exp_deviceid = 0; - uint8_t exp_sm_operate_cnt = mock_iolink_sm_operate_cnt; - uint8_t exp_ds_startup_cnt = mock_iolink_ds_startup_cnt; - uint8_t exp_ds_delete_cnt = mock_iolink_ds_delete_cnt; + uint8_t exp_sm_operate_cnt = mock_iolink_sm_operate_cnt; + uint8_t exp_ds_startup_cnt = mock_iolink_ds_startup_cnt; + uint8_t exp_ds_delete_cnt = mock_iolink_ds_delete_cnt; uint8_t exp_smi_joberror_cnt = mock_iolink_smi_joberror_cnt + 1; - memset (&port_cfg, 0, sizeof(arg_block_portconfiglist_t)); - port_cfg.arg_block_id = IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST; - port_cfg.configlist.port_cycle_time = exp_port_cycle_time; - port_cfg.configlist.vendorid = exp_vendorid; - port_cfg.configlist.deviceid = exp_deviceid; - port_cfg.configlist.in_buffer_len = 0; // TODO - port_cfg.configlist.out_buffer_len = 0; // TODO + memset (&port_cfg, 0, sizeof (arg_block_portconfiglist_t)); + port_cfg.arg_block_id = IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST; + port_cfg.configlist.port_cycle_time = exp_port_cycle_time; + port_cfg.configlist.vendorid = exp_vendorid; + port_cfg.configlist.deviceid = exp_deviceid; + port_cfg.configlist.in_buffer_len = 0; // TODO + port_cfg.configlist.out_buffer_len = 0; // TODO port_cfg.configlist.validation_backup = IOLINK_VALIDATION_CHECK_NO; - port_cfg.configlist.iq_behavior = IOLINK_IQ_BEHAVIOR_NO_SUPPORT; + port_cfg.configlist.iq_behavior = IOLINK_IQ_BEHAVIOR_NO_SUPPORT; EXPECT_EQ (CM_STATE_Port_Deactivated, cm_get_state (port)); - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_PortConfiguration_req (portnumber, - IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - /* Bad ArgBlockLength */ - sizeof(arg_block_portconfiglist_t) + 1, - (arg_block_t *)&port_cfg)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_PortConfiguration_req ( + portnumber, + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + /* Bad ArgBlockLength */ + sizeof (arg_block_portconfiglist_t) + 1, + (arg_block_t *)&port_cfg)); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (CM_STATE_Port_Deactivated, cm_get_state (port)); - cm_verify_smi_err (IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST, - IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - IOLINK_SMI_ERRORTYPE_ARGBLOCK_LENGTH_INVALID, - exp_smi_joberror_cnt, 0, 0); - cm_verify_portstatus (port, exp_status_info, exp_port_quality_info, - exp_revisionid, exp_trans_rate, exp_port_cycle_time, - exp_vendorid, exp_deviceid, 0, NULL); + cm_verify_smi_err ( + IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST, + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + IOLINK_SMI_ERRORTYPE_ARGBLOCK_LENGTH_INVALID, + exp_smi_joberror_cnt, + 0, + 0); + cm_verify_portstatus ( + port, + exp_status_info, + exp_port_quality_info, + exp_revisionid, + exp_trans_rate, + exp_port_cycle_time, + exp_vendorid, + exp_deviceid, + 0, + NULL); EXPECT_EQ (mock_iolink_sm_operate_cnt, exp_sm_operate_cnt); EXPECT_EQ (mock_iolink_ds_startup_cnt, exp_ds_startup_cnt); @@ -1560,21 +1844,27 @@ TEST_F (CMTest, Cm_SMI_PortStatus_bad_argblock) arg_block_void_t arg_block_void; iolink_arg_block_id_t bad_arg_block_id = IOLINK_ARG_BLOCK_ID_MASTERIDENT; - iolink_arg_block_id_t exp_arg_block_id = - IOLINK_ARG_BLOCK_ID_PORT_STATUS_LIST; + iolink_arg_block_id_t exp_arg_block_id = IOLINK_ARG_BLOCK_ID_PORT_STATUS_LIST; - memset (&arg_block_void, 0, sizeof(arg_block_void_t)); + memset (&arg_block_void, 0, sizeof (arg_block_void_t)); arg_block_void.arg_block_id = bad_arg_block_id; - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_PortStatus_req (portnumber, exp_arg_block_id, - sizeof(arg_block_void_t), - (arg_block_t *)&arg_block_void)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_PortStatus_req ( + portnumber, + exp_arg_block_id, + sizeof (arg_block_void_t), + (arg_block_t *)&arg_block_void)); mock_iolink_job.callback (&mock_iolink_job); - cm_verify_smi_err (bad_arg_block_id, exp_arg_block_id, - IOLINK_SMI_ERRORTYPE_ARGBLOCK_NOT_SUPPORTED, - exp_smi_joberror_cnt, 0, 0); + cm_verify_smi_err ( + bad_arg_block_id, + exp_arg_block_id, + IOLINK_SMI_ERRORTYPE_ARGBLOCK_NOT_SUPPORTED, + exp_smi_joberror_cnt, + 0, + 0); } TEST_F (CMTest, Cm_SMI_PortStatus_bad_argblock_len) @@ -1582,52 +1872,67 @@ TEST_F (CMTest, Cm_SMI_PortStatus_bad_argblock_len) uint8_t exp_smi_joberror_cnt = mock_iolink_smi_joberror_cnt + 1; arg_block_void_t arg_block_void; - iolink_arg_block_id_t arg_block_id = IOLINK_ARG_BLOCK_ID_VOID_BLOCK; - iolink_arg_block_id_t exp_arg_block_id = - IOLINK_ARG_BLOCK_ID_PORT_STATUS_LIST; + iolink_arg_block_id_t arg_block_id = IOLINK_ARG_BLOCK_ID_VOID_BLOCK; + iolink_arg_block_id_t exp_arg_block_id = IOLINK_ARG_BLOCK_ID_PORT_STATUS_LIST; - memset (&arg_block_void, 0, sizeof(arg_block_void_t)); + memset (&arg_block_void, 0, sizeof (arg_block_void_t)); arg_block_void.arg_block_id = arg_block_id; - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_PortStatus_req (portnumber, exp_arg_block_id, - /* Bad ArgBlockLength */ - sizeof(arg_block_void_t) + 1, - (arg_block_t *)&arg_block_void)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_PortStatus_req ( + portnumber, + exp_arg_block_id, + /* Bad ArgBlockLength */ + sizeof (arg_block_void_t) + 1, + (arg_block_t *)&arg_block_void)); mock_iolink_job.callback (&mock_iolink_job); - cm_verify_smi_err (arg_block_id, exp_arg_block_id, - IOLINK_SMI_ERRORTYPE_ARGBLOCK_LENGTH_INVALID, - exp_smi_joberror_cnt, 0, 0); + cm_verify_smi_err ( + arg_block_id, + exp_arg_block_id, + IOLINK_SMI_ERRORTYPE_ARGBLOCK_LENGTH_INVALID, + exp_smi_joberror_cnt, + 0, + 0); } TEST_F (CMTest, Cm_SMI_MasterIdent) { - uint8_t exp_smi_cnf_cnt = mock_iolink_smi_cnf_cnt + 1; - uint8_t exp_smi_joberror_cnt = mock_iolink_smi_joberror_cnt; - uint16_t exp_vendorid = 1171; - uint32_t exp_masterid = 123; - uint8_t exp_max_number_of_ports = 2; - iolink_port_types_t exp_port_type = IOLINK_PORT_TYPES_A; + uint8_t exp_smi_cnf_cnt = mock_iolink_smi_cnf_cnt + 1; + uint8_t exp_smi_joberror_cnt = mock_iolink_smi_joberror_cnt; + uint16_t exp_vendorid = 1171; + uint32_t exp_masterid = 123; + uint8_t exp_max_number_of_ports = 2; + iolink_port_types_t exp_port_type = IOLINK_PORT_TYPES_A; iolink_master_type_t exp_master_type = IOLINK_MASTER_TYPE_MASTER_ACC; arg_block_void_t arg_block_void; - iolink_arg_block_id_t arg_block_id = IOLINK_ARG_BLOCK_ID_VOID_BLOCK; + iolink_arg_block_id_t arg_block_id = IOLINK_ARG_BLOCK_ID_VOID_BLOCK; iolink_arg_block_id_t exp_arg_block_id = IOLINK_ARG_BLOCK_ID_MASTERIDENT; - memset (&arg_block_void, 0, sizeof(arg_block_void_t)); + memset (&arg_block_void, 0, sizeof (arg_block_void_t)); arg_block_void.arg_block_id = arg_block_id; - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_MasterIdentification_req (portnumber, exp_arg_block_id, - sizeof(arg_block_void_t), - (arg_block_t *)&arg_block_void)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_MasterIdentification_req ( + portnumber, + exp_arg_block_id, + sizeof (arg_block_void_t), + (arg_block_t *)&arg_block_void)); mock_iolink_job.callback (&mock_iolink_job); - cm_verify_smi_masterident (arg_block_id, exp_arg_block_id, exp_vendorid, - exp_masterid, exp_master_type, - exp_max_number_of_ports, exp_port_type, - exp_smi_cnf_cnt, exp_smi_joberror_cnt); + cm_verify_smi_masterident ( + arg_block_id, + exp_arg_block_id, + exp_vendorid, + exp_masterid, + exp_master_type, + exp_max_number_of_ports, + exp_port_type, + exp_smi_cnf_cnt, + exp_smi_joberror_cnt); } TEST_F (CMTest, Cm_SMI_MasterIdent_bad_argblock) @@ -1638,18 +1943,25 @@ TEST_F (CMTest, Cm_SMI_MasterIdent_bad_argblock) iolink_arg_block_id_t bad_arg_block_id = IOLINK_ARG_BLOCK_ID_DEV_EVENT; iolink_arg_block_id_t exp_arg_block_id = IOLINK_ARG_BLOCK_ID_MASTERIDENT; - memset (&arg_block_void, 0, sizeof(arg_block_void_t)); + memset (&arg_block_void, 0, sizeof (arg_block_void_t)); arg_block_void.arg_block_id = bad_arg_block_id; - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_MasterIdentification_req (portnumber, exp_arg_block_id, - sizeof(arg_block_void_t), - (arg_block_t *)&arg_block_void)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_MasterIdentification_req ( + portnumber, + exp_arg_block_id, + sizeof (arg_block_void_t), + (arg_block_t *)&arg_block_void)); mock_iolink_job.callback (&mock_iolink_job); - cm_verify_smi_err (bad_arg_block_id, exp_arg_block_id, - IOLINK_SMI_ERRORTYPE_ARGBLOCK_NOT_SUPPORTED, - exp_smi_joberror_cnt, 0, 0); + cm_verify_smi_err ( + bad_arg_block_id, + exp_arg_block_id, + IOLINK_SMI_ERRORTYPE_ARGBLOCK_NOT_SUPPORTED, + exp_smi_joberror_cnt, + 0, + 0); } TEST_F (CMTest, Cm_SMI_MasterIdent_bad_argblock_len) @@ -1657,22 +1969,29 @@ TEST_F (CMTest, Cm_SMI_MasterIdent_bad_argblock_len) uint8_t exp_smi_joberror_cnt = mock_iolink_smi_joberror_cnt + 1; arg_block_void_t arg_block_void; - iolink_arg_block_id_t arg_block_id = IOLINK_ARG_BLOCK_ID_VOID_BLOCK; + iolink_arg_block_id_t arg_block_id = IOLINK_ARG_BLOCK_ID_VOID_BLOCK; iolink_arg_block_id_t exp_arg_block_id = IOLINK_ARG_BLOCK_ID_MASTERIDENT; - memset (&arg_block_void, 0, sizeof(arg_block_void_t)); + memset (&arg_block_void, 0, sizeof (arg_block_void_t)); arg_block_void.arg_block_id = arg_block_id; - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_MasterIdentification_req (portnumber, exp_arg_block_id, - /* Bad ArgBlockLength */ - sizeof(arg_block_void_t) + 1, - (arg_block_t *)&arg_block_void)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_MasterIdentification_req ( + portnumber, + exp_arg_block_id, + /* Bad ArgBlockLength */ + sizeof (arg_block_void_t) + 1, + (arg_block_t *)&arg_block_void)); mock_iolink_job.callback (&mock_iolink_job); - cm_verify_smi_err (arg_block_id, exp_arg_block_id, - IOLINK_SMI_ERRORTYPE_ARGBLOCK_LENGTH_INVALID, - exp_smi_joberror_cnt, 0, 0); + cm_verify_smi_err ( + arg_block_id, + exp_arg_block_id, + IOLINK_SMI_ERRORTYPE_ARGBLOCK_LENGTH_INVALID, + exp_smi_joberror_cnt, + 0, + 0); } TEST_F (CMTest, Cm_SMI_ReadbackPortConfiguration) @@ -1681,38 +2000,39 @@ TEST_F (CMTest, Cm_SMI_ReadbackPortConfiguration) portconfiglist_t configlist; uint8_t exp_port_cycle_time = 0; // AFAP (As fast as possible) - uint16_t exp_vendorid = 1; - uint32_t exp_deviceid = 2; + uint16_t exp_vendorid = 1; + uint32_t exp_deviceid = 2; - uint8_t exp_sm_operate_cnt = mock_iolink_sm_operate_cnt; - uint8_t exp_ds_startup_cnt = mock_iolink_ds_startup_cnt; - uint8_t exp_ds_delete_cnt = mock_iolink_ds_delete_cnt; + uint8_t exp_sm_operate_cnt = mock_iolink_sm_operate_cnt; + uint8_t exp_ds_startup_cnt = mock_iolink_ds_startup_cnt; + uint8_t exp_ds_delete_cnt = mock_iolink_ds_delete_cnt; uint8_t exp_smi_portcfg_cnf_cnt = mock_iolink_smi_portcfg_cnf_cnt; - memset (&configlist, 0, sizeof(portconfiglist_t)); + memset (&configlist, 0, sizeof (portconfiglist_t)); /* SMI_ReadbackPortConfiguration_req() */ cm_verify_smi_portconfig (port, &configlist); - memset (&arg_block_portcfg, 0, sizeof(arg_block_portconfiglist_t)); + memset (&arg_block_portcfg, 0, sizeof (arg_block_portconfiglist_t)); arg_block_portcfg.arg_block_id = IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST; - configlist.port_cycle_time = exp_port_cycle_time; - configlist.vendorid = exp_vendorid; - configlist.deviceid = exp_deviceid; - configlist.in_buffer_len = 0; // TODO - configlist.out_buffer_len = 0; // TODO - configlist.portmode = IOLINK_PORTMODE_IOL_AUTO; - configlist.validation_backup = IOLINK_VALIDATION_CHECK_NO; - configlist.iq_behavior = IOLINK_IQ_BEHAVIOR_NO_SUPPORT; - memcpy (&arg_block_portcfg.configlist, &configlist, - sizeof(portconfiglist_t)); + configlist.port_cycle_time = exp_port_cycle_time; + configlist.vendorid = exp_vendorid; + configlist.deviceid = exp_deviceid; + configlist.in_buffer_len = 0; // TODO + configlist.out_buffer_len = 0; // TODO + configlist.portmode = IOLINK_PORTMODE_IOL_AUTO; + configlist.validation_backup = IOLINK_VALIDATION_CHECK_NO; + configlist.iq_behavior = IOLINK_IQ_BEHAVIOR_NO_SUPPORT; + memcpy (&arg_block_portcfg.configlist, &configlist, sizeof (portconfiglist_t)); /* SMI_PortConfiguration_req() */ - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_PortConfiguration_req (portnumber, - IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - sizeof(arg_block_portconfiglist_t), - (arg_block_t *)&arg_block_portcfg)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_PortConfiguration_req ( + portnumber, + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + sizeof (arg_block_portconfiglist_t), + (arg_block_t *)&arg_block_portcfg)); mock_iolink_job.callback (&mock_iolink_job); exp_ds_delete_cnt++; exp_smi_portcfg_cnf_cnt++; @@ -1734,41 +2054,54 @@ TEST_F (CMTest, Cm_SMI_ReadbackPortConfiguration_bad_argblock) iolink_arg_block_id_t bad_arg_block_id = IOLINK_ARG_BLOCK_ID_MASTERIDENT; iolink_arg_block_id_t exp_arg_block_id = IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST; - memset (&arg_block_void, 0, sizeof(arg_block_void_t)); + memset (&arg_block_void, 0, sizeof (arg_block_void_t)); arg_block_void.arg_block_id = bad_arg_block_id; - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_ReadbackPortConfiguration_req (portnumber, exp_arg_block_id, - sizeof(arg_block_void_t), - (arg_block_t *)&arg_block_void)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_ReadbackPortConfiguration_req ( + portnumber, + exp_arg_block_id, + sizeof (arg_block_void_t), + (arg_block_t *)&arg_block_void)); mock_iolink_job.callback (&mock_iolink_job); - cm_verify_smi_err (bad_arg_block_id, exp_arg_block_id, - IOLINK_SMI_ERRORTYPE_ARGBLOCK_NOT_SUPPORTED, - exp_smi_joberror_cnt, 0, 0); + cm_verify_smi_err ( + bad_arg_block_id, + exp_arg_block_id, + IOLINK_SMI_ERRORTYPE_ARGBLOCK_NOT_SUPPORTED, + exp_smi_joberror_cnt, + 0, + 0); } TEST_F (CMTest, Cm_SMI_ReadbackPortConfiguration_bad_exp_arg_block_id) { uint8_t exp_smi_joberror_cnt = mock_iolink_smi_joberror_cnt + 1; arg_block_void_t arg_block_void; - iolink_arg_block_id_t arg_block_id = IOLINK_ARG_BLOCK_ID_VOID_BLOCK; + iolink_arg_block_id_t arg_block_id = IOLINK_ARG_BLOCK_ID_VOID_BLOCK; iolink_arg_block_id_t bad_exp_arg_block_id = IOLINK_ARG_BLOCK_ID_DS_DATA; - memset (&arg_block_void, 0, sizeof(arg_block_void_t)); + memset (&arg_block_void, 0, sizeof (arg_block_void_t)); arg_block_void.arg_block_id = arg_block_id; - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_ReadbackPortConfiguration_req (portnumber, - /* Bad exp_arg_block_id */ - bad_exp_arg_block_id, - sizeof(arg_block_void_t), - (arg_block_t *)&arg_block_void)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_ReadbackPortConfiguration_req ( + portnumber, + /* Bad exp_arg_block_id */ + bad_exp_arg_block_id, + sizeof (arg_block_void_t), + (arg_block_t *)&arg_block_void)); mock_iolink_job.callback (&mock_iolink_job); - cm_verify_smi_err (arg_block_id, bad_exp_arg_block_id, - IOLINK_SMI_ERRORTYPE_ARGBLOCK_INCONSISTENT, - exp_smi_joberror_cnt, 0, 0); + cm_verify_smi_err ( + arg_block_id, + bad_exp_arg_block_id, + IOLINK_SMI_ERRORTYPE_ARGBLOCK_INCONSISTENT, + exp_smi_joberror_cnt, + 0, + 0); } TEST_F (CMTest, Cm_SMI_ReadbackPortConfiguration_bad_argblock_len) @@ -1776,20 +2109,27 @@ TEST_F (CMTest, Cm_SMI_ReadbackPortConfiguration_bad_argblock_len) uint8_t exp_smi_joberror_cnt = mock_iolink_smi_joberror_cnt + 1; arg_block_void_t arg_block_void; - iolink_arg_block_id_t arg_block_id = IOLINK_ARG_BLOCK_ID_VOID_BLOCK; - iolink_arg_block_id_t exp_arg_block_id = IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST; + iolink_arg_block_id_t arg_block_id = IOLINK_ARG_BLOCK_ID_VOID_BLOCK; + iolink_arg_block_id_t exp_arg_block_id = IOLINK_ARG_BLOCK_ID_PORT_CFG_LIST; - memset (&arg_block_void, 0, sizeof(arg_block_void_t)); + memset (&arg_block_void, 0, sizeof (arg_block_void_t)); arg_block_void.arg_block_id = arg_block_id; - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_ReadbackPortConfiguration_req (portnumber, exp_arg_block_id, - /* Bad ArgBlockLength */ - sizeof(arg_block_void_t) + 1, - (arg_block_t *)&arg_block_void)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_ReadbackPortConfiguration_req ( + portnumber, + exp_arg_block_id, + /* Bad ArgBlockLength */ + sizeof (arg_block_void_t) + 1, + (arg_block_t *)&arg_block_void)); mock_iolink_job.callback (&mock_iolink_job); - cm_verify_smi_err (arg_block_id, exp_arg_block_id, - IOLINK_SMI_ERRORTYPE_ARGBLOCK_LENGTH_INVALID, - exp_smi_joberror_cnt, 0, 0); + cm_verify_smi_err ( + arg_block_id, + exp_arg_block_id, + IOLINK_SMI_ERRORTYPE_ARGBLOCK_LENGTH_INVALID, + exp_smi_joberror_cnt, + 0, + 0); } diff --git a/test/test_ds.cpp b/test/test_ds.cpp index 1fb79db..1478dce 100644 --- a/test/test_ds.cpp +++ b/test/test_ds.cpp @@ -26,30 +26,33 @@ static inline iolink_ds_state_t ds_get_state (iolink_port_t * port) return ds->state; } -static inline iolink_error_t par_serv_to_ds (iolink_port_t * port, uint16_t len, - const uint8_t * data, uint16_t vid, - uint32_t did) +static inline iolink_error_t par_serv_to_ds ( + iolink_port_t * port, + uint16_t len, + const uint8_t * data, + uint16_t vid, + uint32_t did) { - uint16_t arg_block_ds_data_len = sizeof(arg_block_ds_data_t) + len; + uint16_t arg_block_ds_data_len = sizeof (arg_block_ds_data_t) + len; uint8_t buf[arg_block_ds_data_len]; arg_block_ds_data_t * arg_block_ds_data; - memset (buf, 0, sizeof(buf)); + memset (buf, 0, sizeof (buf)); arg_block_ds_data = (arg_block_ds_data_t *)buf; memcpy (arg_block_ds_data->ds_data, data, len); arg_block_ds_data->arg_block_id = IOLINK_ARG_BLOCK_ID_DS_DATA; - arg_block_ds_data->vid = vid; - arg_block_ds_data->did = did; - - return SMI_ParServToDS_req (iolink_get_portnumber (port), - IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - arg_block_ds_data_len, - (arg_block_t *)arg_block_ds_data); + arg_block_ds_data->vid = vid; + arg_block_ds_data->did = did; + + return SMI_ParServToDS_req ( + iolink_get_portnumber (port), + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + arg_block_ds_data_len, + (arg_block_t *)arg_block_ds_data); } -static inline void ds_verify_id (iolink_port_t * port, uint16_t vid, - uint32_t did) +static inline void ds_verify_id (iolink_port_t * port, uint16_t vid, uint32_t did) { iolink_ds_port_t * ds = iolink_get_ds_ctx (port); @@ -57,11 +60,11 @@ static inline void ds_verify_id (iolink_port_t * port, uint16_t vid, EXPECT_EQ (did, ds->master_ds.did); } -static inline void ds_check_fault (iolink_port_t * port, - iolink_ds_fault_t expected_fault) +static inline void ds_check_fault ( + iolink_port_t * port, + iolink_ds_fault_t expected_fault) { - if (expected_fault == IOLINK_DS_FAULT_DOWN || - expected_fault == IOLINK_DS_FAULT_UP) + if (expected_fault == IOLINK_DS_FAULT_DOWN || expected_fault == IOLINK_DS_FAULT_UP) { EXPECT_EQ (DS_STATE_DS_Fault, ds_get_state (port)); // Write DS_CMD_BREAK @@ -75,10 +78,13 @@ static inline void ds_check_fault (iolink_port_t * port, EXPECT_EQ (0, mock_iolink_ds_ready_cnt); } -static inline void ds_state_0_to_4 (iolink_port_t * port, uint16_t len, - const uint8_t * data, uint16_t vid, - uint32_t did, - iolink_validation_check_t validation) +static inline void ds_state_0_to_4 ( + iolink_port_t * port, + uint16_t len, + const uint8_t * data, + uint16_t vid, + uint32_t did, + iolink_validation_check_t validation) { iolink_port_info_t * port_info = iolink_get_port_info (port); portconfiglist_t cfg_list; @@ -89,8 +95,8 @@ static inline void ds_state_0_to_4 (iolink_port_t * port, uint16_t len, } ds_verify_id (port, vid, did); - memset (&cfg_list, 0, sizeof(portconfiglist_t)); - cfg_list.portmode = IOLINK_PORTMODE_IOL_MAN; + memset (&cfg_list, 0, sizeof (portconfiglist_t)); + cfg_list.portmode = IOLINK_PORTMODE_IOL_MAN; cfg_list.validation_backup = validation; EXPECT_EQ (DS_STATE_CheckActivationState, ds_get_state (port)); @@ -107,10 +113,14 @@ static inline void ds_state_0_to_4 (iolink_port_t * port, uint16_t len, EXPECT_EQ (1, mock_iolink_al_read_req_cnt); } -static inline void ds_state_0_to_5 (iolink_port_t * port, uint16_t len, - const uint8_t * data, uint16_t vid, - uint32_t did, uint8_t * ds_size, - iolink_validation_check_t validation) +static inline void ds_state_0_to_5 ( + iolink_port_t * port, + uint16_t len, + const uint8_t * data, + uint16_t vid, + uint32_t did, + uint8_t * ds_size, + iolink_validation_check_t validation) { ds_state_0_to_4 (port, len, data, vid, did, validation); @@ -119,38 +129,46 @@ static inline void ds_state_0_to_5 (iolink_port_t * port, uint16_t len, mock_iolink_job.callback (&mock_iolink_job); } -static inline void ds_state_0_to_6 (iolink_port_t * port, uint16_t len, - const uint8_t * data, uint16_t vid, - uint32_t did, uint8_t * ds_size, - iolink_validation_check_t validation, - uint8_t * state_property) +static inline void ds_state_0_to_6 ( + iolink_port_t * port, + uint16_t len, + const uint8_t * data, + uint16_t vid, + uint32_t did, + uint8_t * ds_size, + iolink_validation_check_t validation, + uint8_t * state_property) { ds_state_0_to_5 (port, len, data, vid, did, ds_size, validation); EXPECT_EQ (DS_STATE_CheckMemSize, ds_get_state (port)); EXPECT_EQ (mock_iolink_al_read_req_cnt, 2); // Read device State_Property - mock_iolink_al_read_cnf_cb (port, 1, state_property, - IOLINK_SMI_ERRORTYPE_NONE); + mock_iolink_al_read_cnf_cb (port, 1, state_property, IOLINK_SMI_ERRORTYPE_NONE); mock_iolink_job.callback (&mock_iolink_job); } -static inline void ds_state_0_to_10 (iolink_port_t * port, uint16_t len, - const uint8_t * data, uint16_t vid, - uint32_t did, uint8_t * ds_size, - iolink_validation_check_t validation, - uint8_t * state_property) +static inline void ds_state_0_to_10 ( + iolink_port_t * port, + uint16_t len, + const uint8_t * data, + uint16_t vid, + uint32_t did, + uint8_t * ds_size, + iolink_validation_check_t validation, + uint8_t * state_property) { uint32_t checksum[] = {123}; - ds_state_0_to_6 (port, len, data, vid, did, ds_size, validation, - state_property); + ds_state_0_to_6 (port, len, data, vid, did, ds_size, validation, state_property); EXPECT_EQ (DS_STATE_CheckUpload, ds_get_state (port)); // Read checksum - mock_iolink_al_read_cnf_cb (port, sizeof(checksum), - (uint8_t *)checksum, - IOLINK_SMI_ERRORTYPE_NONE); + mock_iolink_al_read_cnf_cb ( + port, + sizeof (checksum), + (uint8_t *)checksum, + IOLINK_SMI_ERRORTYPE_NONE); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (DS_STATE_Decompose_Set, ds_get_state (port)); @@ -163,9 +181,10 @@ static inline void ds_state_0_to_10 (iolink_port_t * port, uint16_t len, class DSTest : public TestBase { -protected: + protected: // Override default setup - virtual void SetUp() { + virtual void SetUp() + { TestBase::SetUp(); // Re-use default setup }; }; @@ -174,7 +193,7 @@ TEST_F (DSTest, Off_DS_Startup) { portconfiglist_t cfg_list; - memset (&cfg_list, 0, sizeof(portconfiglist_t)); + memset (&cfg_list, 0, sizeof (portconfiglist_t)); cfg_list.portmode = IOLINK_PORTMODE_IOL_AUTO; EXPECT_EQ (DS_STATE_CheckActivationState, ds_get_state (port)); @@ -191,17 +210,17 @@ TEST_F (DSTest, Off_DS_Startup) TEST_F (DSTest, Off_DS_Delete) { portconfiglist_t cfg_list; - uint8_t data_store_data[] = { 0x0, 0x21, 0x0, 0x01, 0x2 }; - uint16_t vid = 123; - uint32_t did = 456; + uint8_t data_store_data[] = {0x0, 0x21, 0x0, 0x01, 0x2}; + uint16_t vid = 123; + uint32_t did = 456; - EXPECT_EQ (IOLINK_ERROR_NONE, - par_serv_to_ds (port, sizeof(data_store_data), - data_store_data, vid, did)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + par_serv_to_ds (port, sizeof (data_store_data), data_store_data, vid, did)); ds_verify_id (port, vid, did); - memset (&cfg_list, 0, sizeof(portconfiglist_t)); - cfg_list.portmode = IOLINK_PORTMODE_IOL_MAN; + memset (&cfg_list, 0, sizeof (portconfiglist_t)); + cfg_list.portmode = IOLINK_PORTMODE_IOL_MAN; cfg_list.validation_backup = IOLINK_VALIDATION_CHECK_V11; EXPECT_EQ (DS_STATE_CheckActivationState, ds_get_state (port)); @@ -218,8 +237,8 @@ TEST_F (DSTest, Off_DS_Upload) { portconfiglist_t cfg_list; - memset (&cfg_list, 0, sizeof(portconfiglist_t)); - cfg_list.portmode = IOLINK_PORTMODE_IOL_MAN; + memset (&cfg_list, 0, sizeof (portconfiglist_t)); + cfg_list.portmode = IOLINK_PORTMODE_IOL_MAN; cfg_list.validation_backup = IOLINK_VALIDATION_CHECK_V10; EXPECT_EQ (DS_STATE_CheckActivationState, ds_get_state (port)); @@ -233,22 +252,22 @@ TEST_F (DSTest, Off_DS_Upload) TEST_F (DSTest, DS_wait_ds_act_DS_Delete) { - uint8_t data_store_data[] = { 0x0, 0x21, 0x0, 0x01, 0x2 }; - uint16_t vid = 123; - uint32_t did = 456; + uint8_t data_store_data[] = {0x0, 0x21, 0x0, 0x01, 0x2}; + uint16_t vid = 123; + uint32_t did = 456; portconfiglist_t cfg_list; - EXPECT_EQ (IOLINK_ERROR_NONE, - par_serv_to_ds (port, sizeof(data_store_data), - data_store_data, vid, did)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + par_serv_to_ds (port, sizeof (data_store_data), data_store_data, vid, did)); ds_verify_id (port, vid, did); - memset (&cfg_list, 0, sizeof(portconfiglist_t)); + memset (&cfg_list, 0, sizeof (portconfiglist_t)); cfg_list.portmode = IOLINK_PORTMODE_IOL_AUTO; - memset (&cfg_list, 0, sizeof(portconfiglist_t)); - cfg_list.portmode = IOLINK_PORTMODE_IOL_MAN; + memset (&cfg_list, 0, sizeof (portconfiglist_t)); + cfg_list.portmode = IOLINK_PORTMODE_IOL_MAN; cfg_list.validation_backup = IOLINK_VALIDATION_CHECK_V11_RESTORE; EXPECT_EQ (DS_STATE_CheckActivationState, ds_get_state (port)); @@ -265,20 +284,41 @@ TEST_F (DSTest, DS_wait_ds_act_DS_Delete) TEST_F (DSTest, DS_download) { uint8_t data_storage_size[] = {0, 0, 8, 0}; // 2048 B - uint8_t data_store_data[] = { 0x01, 0x23, 0x00, 0x02, 0x12, 0x34, 0x01, 0x24, - 0x01, 0x01, 0x55, 0x01, 0x24, 0x02, 0x01, 0xaa, - }; + uint8_t data_store_data[] = { + 0x01, + 0x23, + 0x00, + 0x02, + 0x12, + 0x34, + 0x01, + 0x24, + 0x01, + 0x01, + 0x55, + 0x01, + 0x24, + 0x02, + 0x01, + 0xaa, + }; uint16_t vid = mock_iolink_vendorid; uint32_t did = mock_iolink_deviceid; - uint32_t checksum[] = {123}; + uint32_t checksum[] = {123}; uint8_t state_property[] = {0}; int i; - ds_state_0_to_10 (port, sizeof(data_store_data), data_store_data, vid, did, - data_storage_size, IOLINK_VALIDATION_CHECK_V11_RESTORE, - state_property); + ds_state_0_to_10 ( + port, + sizeof (data_store_data), + data_store_data, + vid, + did, + data_storage_size, + IOLINK_VALIDATION_CHECK_V11_RESTORE, + state_property); for (i = 0; i < 3; i++) // Number of paramters in DS { @@ -292,9 +332,11 @@ TEST_F (DSTest, DS_download) mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (DS_STATE_Download_Done, ds_get_state (port)); // Read checksum - mock_iolink_al_read_cnf_cb (port, sizeof(checksum), - (uint8_t *)checksum, - IOLINK_SMI_ERRORTYPE_NONE); + mock_iolink_al_read_cnf_cb ( + port, + sizeof (checksum), + (uint8_t *)checksum, + IOLINK_SMI_ERRORTYPE_NONE); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (DS_STATE_WaitingOnDSActivity, ds_get_state (port)); @@ -305,20 +347,41 @@ TEST_F (DSTest, DS_download) TEST_F (DSTest, DS_download_upload_req) { uint8_t data_storage_size[] = {0, 0, 8, 0}; // 2048 B - uint8_t data_store_data[] = { 0x01, 0x23, 0x00, 0x02, 0x12, 0x34, 0x01, 0x24, - 0x01, 0x01, 0x55, 0x01, 0x24, 0x02, 0x01, 0xaa, - }; + uint8_t data_store_data[] = { + 0x01, + 0x23, + 0x00, + 0x02, + 0x12, + 0x34, + 0x01, + 0x24, + 0x01, + 0x01, + 0x55, + 0x01, + 0x24, + 0x02, + 0x01, + 0xaa, + }; uint16_t vid = mock_iolink_vendorid; uint32_t did = mock_iolink_deviceid; - uint32_t checksum[] = {123}; + uint32_t checksum[] = {123}; uint8_t state_property[] = {DS_STATE_PROPERTY_UPLOAD_REQ}; int i; - ds_state_0_to_10 (port, sizeof(data_store_data), data_store_data, vid, did, - data_storage_size, IOLINK_VALIDATION_CHECK_V11_RESTORE, - state_property); + ds_state_0_to_10 ( + port, + sizeof (data_store_data), + data_store_data, + vid, + did, + data_storage_size, + IOLINK_VALIDATION_CHECK_V11_RESTORE, + state_property); for (i = 0; i < 3; i++) // Number of paramters in DS { @@ -332,9 +395,11 @@ TEST_F (DSTest, DS_download_upload_req) mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (DS_STATE_Download_Done, ds_get_state (port)); // Read checksum - mock_iolink_al_read_cnf_cb (port, sizeof(checksum), - (uint8_t *)checksum, - IOLINK_SMI_ERRORTYPE_NONE); + mock_iolink_al_read_cnf_cb ( + port, + sizeof (checksum), + (uint8_t *)checksum, + IOLINK_SMI_ERRORTYPE_NONE); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (DS_STATE_WaitingOnDSActivity, ds_get_state (port)); @@ -345,39 +410,46 @@ TEST_F (DSTest, DS_download_upload_req) #include TEST_F (DSTest, DS_upload_upload_req) { - uint8_t data_storage_size[] = {0, 0, 8, 0}; // 2048 B - uint8_t state_property[] = {DS_STATE_PROPERTY_UPLOAD_REQ}; - uint32_t checksum[] = {123}; + uint8_t data_storage_size[] = {0, 0, 8, 0}; // 2048 B + uint8_t state_property[] = {DS_STATE_PROPERTY_UPLOAD_REQ}; + uint32_t checksum[] = {123}; ds_index_list_entry_t index_list[] = { - { - .index= htons(0x399), - .subindex=2, - }, - { - .index= 2, - .subindex=3, - }, - { - .index= htons(0x345), - .subindex=0, - }, - { - .index=0, /* Index_List termination */ - .subindex=0, - }, - }; + { + .index = htons (0x399), + .subindex = 2, + }, + { + .index = 2, + .subindex = 3, + }, + { + .index = htons (0x345), + .subindex = 0, + }, + { + .index = 0, /* Index_List termination */ + .subindex = 0, + }, + }; uint8_t i; - ds_state_0_to_5 (port, 0, NULL, 0, 0, data_storage_size, - IOLINK_VALIDATION_CHECK_V11_BAK_RESTORE); - + ds_state_0_to_5 ( + port, + 0, + NULL, + 0, + 0, + data_storage_size, + IOLINK_VALIDATION_CHECK_V11_BAK_RESTORE); EXPECT_EQ (DS_STATE_CheckMemSize, ds_get_state (port)); EXPECT_EQ (mock_iolink_al_read_req_cnt, 2); // Read device State_Property - mock_iolink_al_read_cnf_cb (port, sizeof(state_property), - state_property, - IOLINK_SMI_ERRORTYPE_NONE); + mock_iolink_al_read_cnf_cb ( + port, + sizeof (state_property), + state_property, + IOLINK_SMI_ERRORTYPE_NONE); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (DS_STATE_CheckUpload, ds_get_state (port)); @@ -385,36 +457,41 @@ TEST_F (DSTest, DS_upload_upload_req) mock_iolink_al_write_cnf_cb (port, IOLINK_SMI_ERRORTYPE_NONE); mock_iolink_job.callback (&mock_iolink_job); - EXPECT_EQ (DS_STATE_ReadParameter, ds_get_state (port)); // Read device DS Index_List - mock_iolink_al_read_cnf_cb (port, sizeof(index_list), - (uint8_t *)index_list, - IOLINK_SMI_ERRORTYPE_NONE); + mock_iolink_al_read_cnf_cb ( + port, + sizeof (index_list), + (uint8_t *)index_list, + IOLINK_SMI_ERRORTYPE_NONE); mock_iolink_job.callback (&mock_iolink_job); // Read foreach element in index list for (i = 0; i < ARRAY_SIZE (index_list) - 1; i++) { ds_index_list_entry_t * il_entry = &index_list[i]; - uint8_t param_data[] = {1, 2, 3, 4}; + uint8_t param_data[] = {1, 2, 3, 4}; EXPECT_EQ (DS_STATE_ReadParameter, ds_get_state (port)); - EXPECT_EQ (htons(il_entry->index), mock_iolink_al_data_index); + EXPECT_EQ (htons (il_entry->index), mock_iolink_al_data_index); EXPECT_EQ (il_entry->subindex, mock_iolink_al_data_subindex); - mock_iolink_al_read_cnf_cb (port, sizeof(param_data), - param_data, - IOLINK_SMI_ERRORTYPE_NONE); + mock_iolink_al_read_cnf_cb ( + port, + sizeof (param_data), + param_data, + IOLINK_SMI_ERRORTYPE_NONE); mock_iolink_job.callback (&mock_iolink_job); } EXPECT_EQ (DS_STATE_StoreDataSet, ds_get_state (port)); // Read checksum - mock_iolink_al_read_cnf_cb (port, sizeof(checksum), - (uint8_t *)checksum, - IOLINK_SMI_ERRORTYPE_NONE); + mock_iolink_al_read_cnf_cb ( + port, + sizeof (checksum), + (uint8_t *)checksum, + IOLINK_SMI_ERRORTYPE_NONE); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (DS_STATE_StoreDataSet, ds_get_state (port)); @@ -422,7 +499,6 @@ TEST_F (DSTest, DS_upload_upload_req) mock_iolink_al_write_cnf_cb (port, IOLINK_SMI_ERRORTYPE_NONE); mock_iolink_job.callback (&mock_iolink_job); - EXPECT_EQ (DS_STATE_WaitingOnDSActivity, ds_get_state (port)); EXPECT_EQ (1, mock_iolink_ds_ready_cnt); @@ -430,82 +506,96 @@ TEST_F (DSTest, DS_upload_upload_req) TEST_F (DSTest, DS_upload_DS_invalid) { - uint8_t data_storage_size[] = {0, 0, 8, 0}; // 2048 B - uint8_t state_property[] = {0}; - uint32_t checksum[] = {123}; + uint8_t data_storage_size[] = {0, 0, 8, 0}; // 2048 B + uint8_t state_property[] = {0}; + uint32_t checksum[] = {123}; ds_index_list_entry_t index_list[] = { - { - .index= htons(0x399), - .subindex=2, - }, - { - .index= 2, - .subindex=3, - }, - { - .index= htons(0x345), - .subindex=0, - }, - { - .index=0, /* Index_List termination */ - .subindex=0, - }, - }; + { + .index = htons (0x399), + .subindex = 2, + }, + { + .index = 2, + .subindex = 3, + }, + { + .index = htons (0x345), + .subindex = 0, + }, + { + .index = 0, /* Index_List termination */ + .subindex = 0, + }, + }; uint8_t i; - ds_state_0_to_5 (port, 0, NULL, 0, 0, data_storage_size, - IOLINK_VALIDATION_CHECK_V11_BAK_RESTORE); - + ds_state_0_to_5 ( + port, + 0, + NULL, + 0, + 0, + data_storage_size, + IOLINK_VALIDATION_CHECK_V11_BAK_RESTORE); EXPECT_EQ (DS_STATE_CheckMemSize, ds_get_state (port)); EXPECT_EQ (mock_iolink_al_read_req_cnt, 2); // Read device State_Property - mock_iolink_al_read_cnf_cb (port, sizeof(state_property), - state_property, - IOLINK_SMI_ERRORTYPE_NONE); + mock_iolink_al_read_cnf_cb ( + port, + sizeof (state_property), + state_property, + IOLINK_SMI_ERRORTYPE_NONE); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (DS_STATE_CheckUpload, ds_get_state (port)); // Read checksum - mock_iolink_al_read_cnf_cb (port, sizeof(checksum), - (uint8_t *)checksum, - IOLINK_SMI_ERRORTYPE_NONE); + mock_iolink_al_read_cnf_cb ( + port, + sizeof (checksum), + (uint8_t *)checksum, + IOLINK_SMI_ERRORTYPE_NONE); mock_iolink_job.callback (&mock_iolink_job); // Write DS_CMD_UL_START mock_iolink_al_write_cnf_cb (port, IOLINK_SMI_ERRORTYPE_NONE); mock_iolink_job.callback (&mock_iolink_job); - EXPECT_EQ (DS_STATE_ReadParameter, ds_get_state (port)); // Read device DS Index_List - mock_iolink_al_read_cnf_cb (port, sizeof(index_list), - (uint8_t *)index_list, - IOLINK_SMI_ERRORTYPE_NONE); + mock_iolink_al_read_cnf_cb ( + port, + sizeof (index_list), + (uint8_t *)index_list, + IOLINK_SMI_ERRORTYPE_NONE); mock_iolink_job.callback (&mock_iolink_job); // Read foreach element in index list for (i = 0; i < ARRAY_SIZE (index_list) - 1; i++) { ds_index_list_entry_t * il_entry = &index_list[i]; - uint8_t param_data[] = {1, 2, 3, 4}; + uint8_t param_data[] = {1, 2, 3, 4}; EXPECT_EQ (DS_STATE_ReadParameter, ds_get_state (port)); - EXPECT_EQ (htons(il_entry->index), mock_iolink_al_data_index); + EXPECT_EQ (htons (il_entry->index), mock_iolink_al_data_index); EXPECT_EQ (il_entry->subindex, mock_iolink_al_data_subindex); - mock_iolink_al_read_cnf_cb (port, sizeof(param_data), - param_data, - IOLINK_SMI_ERRORTYPE_NONE); + mock_iolink_al_read_cnf_cb ( + port, + sizeof (param_data), + param_data, + IOLINK_SMI_ERRORTYPE_NONE); mock_iolink_job.callback (&mock_iolink_job); } EXPECT_EQ (DS_STATE_StoreDataSet, ds_get_state (port)); // Read checksum - mock_iolink_al_read_cnf_cb (port, sizeof(checksum), - (uint8_t *)checksum, - IOLINK_SMI_ERRORTYPE_NONE); + mock_iolink_al_read_cnf_cb ( + port, + sizeof (checksum), + (uint8_t *)checksum, + IOLINK_SMI_ERRORTYPE_NONE); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (DS_STATE_StoreDataSet, ds_get_state (port)); @@ -513,7 +603,6 @@ TEST_F (DSTest, DS_upload_DS_invalid) mock_iolink_al_write_cnf_cb (port, IOLINK_SMI_ERRORTYPE_NONE); mock_iolink_job.callback (&mock_iolink_job); - EXPECT_EQ (DS_STATE_WaitingOnDSActivity, ds_get_state (port)); EXPECT_EQ (1, mock_iolink_ds_ready_cnt); @@ -521,22 +610,21 @@ TEST_F (DSTest, DS_upload_DS_invalid) TEST_F (DSTest, DS_Fault_ID_vid) { - uint8_t data_store_data[] = { 0x0, 0x21, 0x0, 0x01, 0x2 }; - uint16_t vid = 1; - uint32_t did = mock_iolink_deviceid; + uint8_t data_store_data[] = {0x0, 0x21, 0x0, 0x01, 0x2}; + uint16_t vid = 1; + uint32_t did = mock_iolink_deviceid; iolink_port_info_t * port_info = iolink_get_port_info (port); portconfiglist_t cfg_list; - - EXPECT_EQ (IOLINK_ERROR_NONE, - par_serv_to_ds (port, sizeof(data_store_data), - data_store_data, vid, did)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + par_serv_to_ds (port, sizeof (data_store_data), data_store_data, vid, did)); ds_verify_id (port, vid, did); - memset (&cfg_list, 0, sizeof(portconfiglist_t)); - cfg_list.portmode = IOLINK_PORTMODE_IOL_MAN; + memset (&cfg_list, 0, sizeof (portconfiglist_t)); + cfg_list.portmode = IOLINK_PORTMODE_IOL_MAN; cfg_list.validation_backup = IOLINK_VALIDATION_CHECK_V11_RESTORE; EXPECT_EQ (DS_STATE_CheckActivationState, ds_get_state (port)); @@ -555,22 +643,21 @@ TEST_F (DSTest, DS_Fault_ID_vid) TEST_F (DSTest, DS_Fault_ID) { - uint8_t data_store_data[] = { 0x0, 0x21, 0x0, 0x01, 0x2 }; - uint16_t vid = mock_iolink_vendorid; - uint32_t did = 2; + uint8_t data_store_data[] = {0x0, 0x21, 0x0, 0x01, 0x2}; + uint16_t vid = mock_iolink_vendorid; + uint32_t did = 2; iolink_port_info_t * port_info = iolink_get_port_info (port); portconfiglist_t cfg_list; - - EXPECT_EQ (IOLINK_ERROR_NONE, - par_serv_to_ds (port, sizeof(data_store_data), - data_store_data, vid, did)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + par_serv_to_ds (port, sizeof (data_store_data), data_store_data, vid, did)); ds_verify_id (port, vid, did); - memset (&cfg_list, 0, sizeof(portconfiglist_t)); - cfg_list.portmode = IOLINK_PORTMODE_IOL_MAN; + memset (&cfg_list, 0, sizeof (portconfiglist_t)); + cfg_list.portmode = IOLINK_PORTMODE_IOL_MAN; cfg_list.validation_backup = IOLINK_VALIDATION_CHECK_V11_RESTORE; EXPECT_EQ (DS_STATE_CheckActivationState, ds_get_state (port)); @@ -593,8 +680,8 @@ TEST_F (DSTest, DS_Fault_ID_read_error) portconfiglist_t cfg_list; - memset (&cfg_list, 0, sizeof(portconfiglist_t)); - cfg_list.portmode = IOLINK_PORTMODE_IOL_MAN; + memset (&cfg_list, 0, sizeof (portconfiglist_t)); + cfg_list.portmode = IOLINK_PORTMODE_IOL_MAN; cfg_list.validation_backup = IOLINK_VALIDATION_CHECK_V11_RESTORE; EXPECT_EQ (DS_STATE_CheckActivationState, ds_get_state (port)); @@ -611,8 +698,7 @@ TEST_F (DSTest, DS_Fault_ID_read_error) EXPECT_EQ (1, mock_iolink_al_read_req_cnt); // Read device Data_Storage_Size, Fault - mock_iolink_al_read_cnf_cb (port, 0, NULL, - IOLINK_SMI_ERRORTYPE_IDX_NOTAVAIL); + mock_iolink_al_read_cnf_cb (port, 0, NULL, IOLINK_SMI_ERRORTYPE_IDX_NOTAVAIL); mock_iolink_job.callback (&mock_iolink_job); ds_check_fault (port, IOLINK_DS_FAULT_ID); @@ -621,12 +707,18 @@ TEST_F (DSTest, DS_Fault_ID_read_error) TEST_F (DSTest, DS_Fault_Size) { uint8_t data_storage_size[] = {0, 0, 8, 1}; // 2049 B - uint8_t data_store_data[] = { 0x0, 0x21, 0x0, 0x01, 0x2 }; - uint16_t vid = 0; - uint32_t did = 0; - - ds_state_0_to_5 (port, sizeof(data_store_data), data_store_data, vid, did, - data_storage_size, IOLINK_VALIDATION_CHECK_V11_RESTORE); + uint8_t data_store_data[] = {0x0, 0x21, 0x0, 0x01, 0x2}; + uint16_t vid = 0; + uint32_t did = 0; + + ds_state_0_to_5 ( + port, + sizeof (data_store_data), + data_store_data, + vid, + did, + data_storage_size, + IOLINK_VALIDATION_CHECK_V11_RESTORE); ds_check_fault (port, IOLINK_DS_FAULT_SIZE); } @@ -634,43 +726,55 @@ TEST_F (DSTest, DS_Fault_Size) TEST_F (DSTest, DS_Fault_Size_read_error) { uint8_t data_storage_size[] = {0, 0, 8, 0}; // 2048 B - uint8_t data_store_data[] = { 0x0, 0x21, 0x0, 0x01, 0x2 }; - uint16_t vid = 0; - uint32_t did = 0; - - ds_state_0_to_5 (port, sizeof(data_store_data), data_store_data, vid, did, - data_storage_size, IOLINK_VALIDATION_CHECK_V11_RESTORE); + uint8_t data_store_data[] = {0x0, 0x21, 0x0, 0x01, 0x2}; + uint16_t vid = 0; + uint32_t did = 0; + + ds_state_0_to_5 ( + port, + sizeof (data_store_data), + data_store_data, + vid, + did, + data_storage_size, + IOLINK_VALIDATION_CHECK_V11_RESTORE); EXPECT_EQ (DS_STATE_CheckMemSize, ds_get_state (port)); EXPECT_EQ (mock_iolink_al_read_req_cnt, 2); // Read device State_Property, fault - mock_iolink_al_read_cnf_cb (port, 0, NULL, - IOLINK_SMI_ERRORTYPE_IDX_NOTAVAIL); + mock_iolink_al_read_cnf_cb (port, 0, NULL, IOLINK_SMI_ERRORTYPE_IDX_NOTAVAIL); mock_iolink_job.callback (&mock_iolink_job); ds_check_fault (port, IOLINK_DS_FAULT_SIZE); } - TEST_F (DSTest, DS_Fault_Lock) { - uint8_t state_property[] = {DS_STATE_PROPERTY_STATE_LOCKED}; + uint8_t state_property[] = {DS_STATE_PROPERTY_STATE_LOCKED}; uint8_t data_storage_size[] = {0, 0, 8, 0}; // 2048 B - uint8_t data_store_data[] = { 0x0, 0x21, 0x0, 0x01, 0x2 }; - uint16_t vid = 0; - uint32_t did = 0; - - ds_state_0_to_5 (port, sizeof(data_store_data), data_store_data, vid, did, - data_storage_size, IOLINK_VALIDATION_CHECK_V11_RESTORE); + uint8_t data_store_data[] = {0x0, 0x21, 0x0, 0x01, 0x2}; + uint16_t vid = 0; + uint32_t did = 0; + + ds_state_0_to_5 ( + port, + sizeof (data_store_data), + data_store_data, + vid, + did, + data_storage_size, + IOLINK_VALIDATION_CHECK_V11_RESTORE); EXPECT_EQ (DS_STATE_CheckMemSize, ds_get_state (port)); EXPECT_EQ (mock_iolink_al_read_req_cnt, 2); // Read device State_Property - mock_iolink_al_read_cnf_cb (port, sizeof(state_property), - state_property, - IOLINK_SMI_ERRORTYPE_NONE); + mock_iolink_al_read_cnf_cb ( + port, + sizeof (state_property), + state_property, + IOLINK_SMI_ERRORTYPE_NONE); mock_iolink_job.callback (&mock_iolink_job); ds_check_fault (port, IOLINK_DS_FAULT_LOCK); @@ -678,37 +782,46 @@ TEST_F (DSTest, DS_Fault_Lock) TEST_F (DSTest, DS_Fault_UL_Read_Param_Dev_Err) { - uint8_t data_storage_size[] = {0, 0, 8, 0}; // 2048 B - uint8_t state_property[] = {DS_STATE_PROPERTY_UPLOAD_REQ}; + uint8_t data_storage_size[] = {0, 0, 8, 0}; // 2048 B + uint8_t state_property[] = {DS_STATE_PROPERTY_UPLOAD_REQ}; ds_index_list_entry_t index_list[] = { - { - .index= htons(0x399), - .subindex=2, - }, - { - .index= 2, - .subindex=3, - }, - { - .index= htons(0x345), - .subindex=0, - }, - { - .index=0, /* Index_List termination */ - .subindex=0, - }, - }; + { + .index = htons (0x399), + .subindex = 2, + }, + { + .index = 2, + .subindex = 3, + }, + { + .index = htons (0x345), + .subindex = 0, + }, + { + .index = 0, /* Index_List termination */ + .subindex = 0, + }, + }; uint8_t i; - ds_state_0_to_5 (port, 0, NULL, 0, 0, data_storage_size, - IOLINK_VALIDATION_CHECK_V11_BAK_RESTORE); + ds_state_0_to_5 ( + port, + 0, + NULL, + 0, + 0, + data_storage_size, + IOLINK_VALIDATION_CHECK_V11_BAK_RESTORE); EXPECT_EQ (DS_STATE_CheckMemSize, ds_get_state (port)); EXPECT_EQ (mock_iolink_al_read_req_cnt, 2); // Read device State_Property - mock_iolink_al_read_cnf_cb (port, sizeof(state_property), state_property, - IOLINK_SMI_ERRORTYPE_NONE); + mock_iolink_al_read_cnf_cb ( + port, + sizeof (state_property), + state_property, + IOLINK_SMI_ERRORTYPE_NONE); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (DS_STATE_CheckUpload, ds_get_state (port)); @@ -716,33 +829,38 @@ TEST_F (DSTest, DS_Fault_UL_Read_Param_Dev_Err) mock_iolink_al_write_cnf_cb (port, IOLINK_SMI_ERRORTYPE_NONE); mock_iolink_job.callback (&mock_iolink_job); - EXPECT_EQ (DS_STATE_ReadParameter, ds_get_state (port)); // Read device DS Index_List - mock_iolink_al_read_cnf_cb (port, sizeof(index_list), - (uint8_t *)index_list, - IOLINK_SMI_ERRORTYPE_NONE); + mock_iolink_al_read_cnf_cb ( + port, + sizeof (index_list), + (uint8_t *)index_list, + IOLINK_SMI_ERRORTYPE_NONE); mock_iolink_job.callback (&mock_iolink_job); // Read foreach element in index list for (i = 0; i < 2; i++) { ds_index_list_entry_t * il_entry = &index_list[i]; - uint8_t param_data[] = {1, 2, 3, 4}; + uint8_t param_data[] = {1, 2, 3, 4}; EXPECT_EQ (DS_STATE_ReadParameter, ds_get_state (port)); - EXPECT_EQ (htons(il_entry->index), mock_iolink_al_data_index); + EXPECT_EQ (htons (il_entry->index), mock_iolink_al_data_index); EXPECT_EQ (il_entry->subindex, mock_iolink_al_data_subindex); if (i == 0) - mock_iolink_al_read_cnf_cb (port, sizeof(param_data), - param_data, - IOLINK_SMI_ERRORTYPE_NONE); + mock_iolink_al_read_cnf_cb ( + port, + sizeof (param_data), + param_data, + IOLINK_SMI_ERRORTYPE_NONE); else - mock_iolink_al_read_cnf_cb (port, sizeof(param_data), - param_data, - IOLINK_SMI_ERRORTYPE_IDX_NOTAVAIL); + mock_iolink_al_read_cnf_cb ( + port, + sizeof (param_data), + param_data, + IOLINK_SMI_ERRORTYPE_IDX_NOTAVAIL); mock_iolink_job.callback (&mock_iolink_job); } @@ -752,37 +870,46 @@ TEST_F (DSTest, DS_Fault_UL_Read_Param_Dev_Err) TEST_F (DSTest, DS_Fault_UL_Read_Param_Com_Err) { - uint8_t data_storage_size[] = {0, 0, 8, 0}; // 2048 B - uint8_t state_property[] = {DS_STATE_PROPERTY_UPLOAD_REQ}; + uint8_t data_storage_size[] = {0, 0, 8, 0}; // 2048 B + uint8_t state_property[] = {DS_STATE_PROPERTY_UPLOAD_REQ}; ds_index_list_entry_t index_list[] = { - { - .index= htons(0x399), - .subindex=2, - }, - { - .index= 2, - .subindex=3, - }, - { - .index= htons(0x345), - .subindex=0, - }, - { - .index=0, /* Index_List termination */ - .subindex=0, - }, - }; + { + .index = htons (0x399), + .subindex = 2, + }, + { + .index = 2, + .subindex = 3, + }, + { + .index = htons (0x345), + .subindex = 0, + }, + { + .index = 0, /* Index_List termination */ + .subindex = 0, + }, + }; uint8_t i; - ds_state_0_to_5 (port, 0, NULL, 0, 0, data_storage_size, - IOLINK_VALIDATION_CHECK_V11_BAK_RESTORE); + ds_state_0_to_5 ( + port, + 0, + NULL, + 0, + 0, + data_storage_size, + IOLINK_VALIDATION_CHECK_V11_BAK_RESTORE); EXPECT_EQ (DS_STATE_CheckMemSize, ds_get_state (port)); EXPECT_EQ (mock_iolink_al_read_req_cnt, 2); // Read device State_Property - mock_iolink_al_read_cnf_cb (port, sizeof(state_property), state_property, - IOLINK_SMI_ERRORTYPE_NONE); + mock_iolink_al_read_cnf_cb ( + port, + sizeof (state_property), + state_property, + IOLINK_SMI_ERRORTYPE_NONE); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (DS_STATE_CheckUpload, ds_get_state (port)); @@ -790,33 +917,38 @@ TEST_F (DSTest, DS_Fault_UL_Read_Param_Com_Err) mock_iolink_al_write_cnf_cb (port, IOLINK_SMI_ERRORTYPE_NONE); mock_iolink_job.callback (&mock_iolink_job); - EXPECT_EQ (DS_STATE_ReadParameter, ds_get_state (port)); // Read device DS Index_List - mock_iolink_al_read_cnf_cb (port, sizeof(index_list), - (uint8_t *)index_list, - IOLINK_SMI_ERRORTYPE_NONE); + mock_iolink_al_read_cnf_cb ( + port, + sizeof (index_list), + (uint8_t *)index_list, + IOLINK_SMI_ERRORTYPE_NONE); mock_iolink_job.callback (&mock_iolink_job); // Read foreach element in index list for (i = 0; i < 2; i++) { ds_index_list_entry_t * il_entry = &index_list[i]; - uint8_t param_data[] = {1, 2, 3, 4}; + uint8_t param_data[] = {1, 2, 3, 4}; EXPECT_EQ (DS_STATE_ReadParameter, ds_get_state (port)); - EXPECT_EQ (htons(il_entry->index), mock_iolink_al_data_index); + EXPECT_EQ (htons (il_entry->index), mock_iolink_al_data_index); EXPECT_EQ (il_entry->subindex, mock_iolink_al_data_subindex); if (i == 0) - mock_iolink_al_read_cnf_cb (port, sizeof(param_data), - param_data, - IOLINK_SMI_ERRORTYPE_NONE); + mock_iolink_al_read_cnf_cb ( + port, + sizeof (param_data), + param_data, + IOLINK_SMI_ERRORTYPE_NONE); else - mock_iolink_al_read_cnf_cb (port, sizeof(param_data), - param_data, - IOLINK_SMI_ERRORTYPE_COM_ERR); + mock_iolink_al_read_cnf_cb ( + port, + sizeof (param_data), + param_data, + IOLINK_SMI_ERRORTYPE_COM_ERR); mock_iolink_job.callback (&mock_iolink_job); } @@ -826,39 +958,46 @@ TEST_F (DSTest, DS_Fault_UL_Read_Param_Com_Err) TEST_F (DSTest, DS_Fault_UL_StoreDataSet_Com_Err_Read) { - uint8_t data_storage_size[] = {0, 0, 8, 0}; // 2048 B - uint8_t state_property[] = {DS_STATE_PROPERTY_UPLOAD_REQ}; - uint32_t checksum[] = {123}; + uint8_t data_storage_size[] = {0, 0, 8, 0}; // 2048 B + uint8_t state_property[] = {DS_STATE_PROPERTY_UPLOAD_REQ}; + uint32_t checksum[] = {123}; ds_index_list_entry_t index_list[] = { - { - .index= htons(0x399), - .subindex=2, - }, - { - .index= 2, - .subindex=3, - }, - { - .index= htons(0x345), - .subindex=0, - }, - { - .index=0, /* Index_List termination */ - .subindex=0, - }, - }; + { + .index = htons (0x399), + .subindex = 2, + }, + { + .index = 2, + .subindex = 3, + }, + { + .index = htons (0x345), + .subindex = 0, + }, + { + .index = 0, /* Index_List termination */ + .subindex = 0, + }, + }; uint8_t i; - ds_state_0_to_5 (port, 0, NULL, 0, 0, data_storage_size, - IOLINK_VALIDATION_CHECK_V11_BAK_RESTORE); - + ds_state_0_to_5 ( + port, + 0, + NULL, + 0, + 0, + data_storage_size, + IOLINK_VALIDATION_CHECK_V11_BAK_RESTORE); EXPECT_EQ (DS_STATE_CheckMemSize, ds_get_state (port)); EXPECT_EQ (mock_iolink_al_read_req_cnt, 2); // Read device State_Property - mock_iolink_al_read_cnf_cb (port, sizeof(state_property), - state_property, - IOLINK_SMI_ERRORTYPE_NONE); + mock_iolink_al_read_cnf_cb ( + port, + sizeof (state_property), + state_property, + IOLINK_SMI_ERRORTYPE_NONE); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (DS_STATE_CheckUpload, ds_get_state (port)); @@ -866,36 +1005,41 @@ TEST_F (DSTest, DS_Fault_UL_StoreDataSet_Com_Err_Read) mock_iolink_al_write_cnf_cb (port, IOLINK_SMI_ERRORTYPE_NONE); mock_iolink_job.callback (&mock_iolink_job); - EXPECT_EQ (DS_STATE_ReadParameter, ds_get_state (port)); // Read device DS Index_List - mock_iolink_al_read_cnf_cb (port, sizeof(index_list), - (uint8_t *)index_list, - IOLINK_SMI_ERRORTYPE_NONE); + mock_iolink_al_read_cnf_cb ( + port, + sizeof (index_list), + (uint8_t *)index_list, + IOLINK_SMI_ERRORTYPE_NONE); mock_iolink_job.callback (&mock_iolink_job); // Read foreach element in index list for (i = 0; i < ARRAY_SIZE (index_list) - 1; i++) { ds_index_list_entry_t * il_entry = &index_list[i]; - uint8_t param_data[] = {1, 2, 3, 4}; + uint8_t param_data[] = {1, 2, 3, 4}; EXPECT_EQ (DS_STATE_ReadParameter, ds_get_state (port)); - EXPECT_EQ (htons(il_entry->index), mock_iolink_al_data_index); + EXPECT_EQ (htons (il_entry->index), mock_iolink_al_data_index); EXPECT_EQ (il_entry->subindex, mock_iolink_al_data_subindex); - mock_iolink_al_read_cnf_cb (port, sizeof(param_data), - param_data, - IOLINK_SMI_ERRORTYPE_NONE); + mock_iolink_al_read_cnf_cb ( + port, + sizeof (param_data), + param_data, + IOLINK_SMI_ERRORTYPE_NONE); mock_iolink_job.callback (&mock_iolink_job); } EXPECT_EQ (DS_STATE_StoreDataSet, ds_get_state (port)); // Read checksum - mock_iolink_al_read_cnf_cb (port, sizeof(checksum), - (uint8_t *)checksum, - IOLINK_SMI_ERRORTYPE_COM_ERR); + mock_iolink_al_read_cnf_cb ( + port, + sizeof (checksum), + (uint8_t *)checksum, + IOLINK_SMI_ERRORTYPE_COM_ERR); mock_iolink_job.callback (&mock_iolink_job); ds_check_fault (port, IOLINK_DS_FAULT_UP); @@ -903,39 +1047,46 @@ TEST_F (DSTest, DS_Fault_UL_StoreDataSet_Com_Err_Read) TEST_F (DSTest, DS_Fault_UL_StoreDataSet_Com_Err_Write) { - uint8_t data_storage_size[] = {0, 0, 8, 0}; // 2048 B - uint8_t state_property[] = {DS_STATE_PROPERTY_UPLOAD_REQ}; - uint32_t checksum[] = {123}; + uint8_t data_storage_size[] = {0, 0, 8, 0}; // 2048 B + uint8_t state_property[] = {DS_STATE_PROPERTY_UPLOAD_REQ}; + uint32_t checksum[] = {123}; ds_index_list_entry_t index_list[] = { - { - .index= htons(0x399), - .subindex=2, - }, - { - .index= 2, - .subindex=3, - }, - { - .index= htons(0x345), - .subindex=0, - }, - { - .index=0, /* Index_List termination */ - .subindex=0, - }, - }; + { + .index = htons (0x399), + .subindex = 2, + }, + { + .index = 2, + .subindex = 3, + }, + { + .index = htons (0x345), + .subindex = 0, + }, + { + .index = 0, /* Index_List termination */ + .subindex = 0, + }, + }; uint8_t i; - ds_state_0_to_5 (port, 0, NULL, 0, 0, data_storage_size, - IOLINK_VALIDATION_CHECK_V11_BAK_RESTORE); - + ds_state_0_to_5 ( + port, + 0, + NULL, + 0, + 0, + data_storage_size, + IOLINK_VALIDATION_CHECK_V11_BAK_RESTORE); EXPECT_EQ (DS_STATE_CheckMemSize, ds_get_state (port)); EXPECT_EQ (mock_iolink_al_read_req_cnt, 2); // Read device State_Property - mock_iolink_al_read_cnf_cb (port, sizeof(state_property), - state_property, - IOLINK_SMI_ERRORTYPE_NONE); + mock_iolink_al_read_cnf_cb ( + port, + sizeof (state_property), + state_property, + IOLINK_SMI_ERRORTYPE_NONE); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (DS_STATE_CheckUpload, ds_get_state (port)); @@ -943,39 +1094,43 @@ TEST_F (DSTest, DS_Fault_UL_StoreDataSet_Com_Err_Write) mock_iolink_al_write_cnf_cb (port, IOLINK_SMI_ERRORTYPE_NONE); mock_iolink_job.callback (&mock_iolink_job); - EXPECT_EQ (DS_STATE_ReadParameter, ds_get_state (port)); // Read device DS Index_List - mock_iolink_al_read_cnf_cb (port, sizeof(index_list), - (uint8_t *)index_list, - IOLINK_SMI_ERRORTYPE_NONE); + mock_iolink_al_read_cnf_cb ( + port, + sizeof (index_list), + (uint8_t *)index_list, + IOLINK_SMI_ERRORTYPE_NONE); mock_iolink_job.callback (&mock_iolink_job); // Read foreach element in index list for (i = 0; i < ARRAY_SIZE (index_list) - 1; i++) { ds_index_list_entry_t * il_entry = &index_list[i]; - uint8_t param_data[] = {1, 2, 3, 4}; + uint8_t param_data[] = {1, 2, 3, 4}; EXPECT_EQ (DS_STATE_ReadParameter, ds_get_state (port)); - EXPECT_EQ (htons(il_entry->index), mock_iolink_al_data_index); + EXPECT_EQ (htons (il_entry->index), mock_iolink_al_data_index); EXPECT_EQ (il_entry->subindex, mock_iolink_al_data_subindex); - mock_iolink_al_read_cnf_cb (port, sizeof(param_data), - param_data, - IOLINK_SMI_ERRORTYPE_NONE); + mock_iolink_al_read_cnf_cb ( + port, + sizeof (param_data), + param_data, + IOLINK_SMI_ERRORTYPE_NONE); mock_iolink_job.callback (&mock_iolink_job); } EXPECT_EQ (DS_STATE_StoreDataSet, ds_get_state (port)); // Read checksum - mock_iolink_al_read_cnf_cb (port, sizeof(checksum), - (uint8_t *)checksum, - IOLINK_SMI_ERRORTYPE_NONE); + mock_iolink_al_read_cnf_cb ( + port, + sizeof (checksum), + (uint8_t *)checksum, + IOLINK_SMI_ERRORTYPE_NONE); mock_iolink_job.callback (&mock_iolink_job); - EXPECT_EQ (DS_STATE_StoreDataSet, ds_get_state (port)); // Write UL_End, fail with COM_ERR mock_iolink_al_write_cnf_cb (port, IOLINK_SMI_ERRORTYPE_COM_ERR); @@ -987,9 +1142,24 @@ TEST_F (DSTest, DS_Fault_UL_StoreDataSet_Com_Err_Write) TEST_F (DSTest, DS_Fault_DL_Write_Param_Dev_Err) { uint8_t data_storage_size[] = {0, 0, 8, 0}; // 2048 B - uint8_t data_store_data[] = { 0x01, 0x23, 0x00, 0x02, 0x12, 0x34, 0x01, 0x24, - 0x01, 0x01, 0x55, 0x01, 0x24, 0x02, 0x01, 0xaa, - }; + uint8_t data_store_data[] = { + 0x01, + 0x23, + 0x00, + 0x02, + 0x12, + 0x34, + 0x01, + 0x24, + 0x01, + 0x01, + 0x55, + 0x01, + 0x24, + 0x02, + 0x01, + 0xaa, + }; uint16_t vid = 0; uint32_t did = 0; @@ -997,9 +1167,15 @@ TEST_F (DSTest, DS_Fault_DL_Write_Param_Dev_Err) int i; - ds_state_0_to_10 (port, sizeof(data_store_data), data_store_data, vid, did, - data_storage_size, IOLINK_VALIDATION_CHECK_V11_BAK_RESTORE, - state_property); + ds_state_0_to_10 ( + port, + sizeof (data_store_data), + data_store_data, + vid, + did, + data_storage_size, + IOLINK_VALIDATION_CHECK_V11_BAK_RESTORE, + state_property); for (i = 0; i < 2; i++) { @@ -1017,9 +1193,24 @@ TEST_F (DSTest, DS_Fault_DL_Write_Param_Dev_Err) TEST_F (DSTest, DS_Fault_DL_Write_Param_Com_Err) { uint8_t data_storage_size[] = {0, 0, 8, 0}; // 2048 B - uint8_t data_store_data[] = { 0x01, 0x23, 0x00, 0x02, 0x12, 0x34, 0x01, 0x24, - 0x01, 0x01, 0x55, 0x01, 0x24, 0x02, 0x01, 0xaa, - }; + uint8_t data_store_data[] = { + 0x01, + 0x23, + 0x00, + 0x02, + 0x12, + 0x34, + 0x01, + 0x24, + 0x01, + 0x01, + 0x55, + 0x01, + 0x24, + 0x02, + 0x01, + 0xaa, + }; uint16_t vid = 0; uint32_t did = 0; @@ -1027,9 +1218,15 @@ TEST_F (DSTest, DS_Fault_DL_Write_Param_Com_Err) int i; - ds_state_0_to_10 (port, sizeof(data_store_data), data_store_data, vid, did, - data_storage_size, IOLINK_VALIDATION_CHECK_V11_BAK_RESTORE, - state_property); + ds_state_0_to_10 ( + port, + sizeof (data_store_data), + data_store_data, + vid, + did, + data_storage_size, + IOLINK_VALIDATION_CHECK_V11_BAK_RESTORE, + state_property); for (i = 0; i < 2; i++) { @@ -1047,9 +1244,24 @@ TEST_F (DSTest, DS_Fault_DL_Write_Param_Com_Err) TEST_F (DSTest, DS_Fault_DL_Download_Done_Com_Err) { uint8_t data_storage_size[] = {0, 0, 8, 0}; // 2048 B - uint8_t data_store_data[] = { 0x01, 0x23, 0x00, 0x02, 0x12, 0x34, 0x01, 0x24, - 0x01, 0x01, 0x55, 0x01, 0x24, 0x02, 0x01, 0xaa, - }; + uint8_t data_store_data[] = { + 0x01, + 0x23, + 0x00, + 0x02, + 0x12, + 0x34, + 0x01, + 0x24, + 0x01, + 0x01, + 0x55, + 0x01, + 0x24, + 0x02, + 0x01, + 0xaa, + }; uint16_t vid = 0; uint32_t did = 0; @@ -1057,9 +1269,15 @@ TEST_F (DSTest, DS_Fault_DL_Download_Done_Com_Err) int i; - ds_state_0_to_10 (port, sizeof(data_store_data), data_store_data, vid, did, - data_storage_size, IOLINK_VALIDATION_CHECK_V11_BAK_RESTORE, - state_property); + ds_state_0_to_10 ( + port, + sizeof (data_store_data), + data_store_data, + vid, + did, + data_storage_size, + IOLINK_VALIDATION_CHECK_V11_BAK_RESTORE, + state_property); for (i = 0; i < 3; i++) // Number of paramters in DS { @@ -1077,40 +1295,72 @@ TEST_F (DSTest, DS_Fault_DL_Download_Done_Com_Err) TEST_F (DSTest, DS_Chk_Cfg_vid) { - uint8_t data_store_data[] = { 0x01, 0x23, 0x00, 0x02, 0x12, 0x34, 0x01, 0x24, - 0x01, 0x01, 0x55, 0x01, 0x24, 0x02, 0x01, 0xaa, - }; + uint8_t data_store_data[] = { + 0x01, + 0x23, + 0x00, + 0x02, + 0x12, + 0x34, + 0x01, + 0x24, + 0x01, + 0x01, + 0x55, + 0x01, + 0x24, + 0x02, + 0x01, + 0xaa, + }; uint16_t vid = 123; uint32_t did = 456; portconfiglist_t cfg_list; - memset (&cfg_list, 0, sizeof(portconfiglist_t)); + memset (&cfg_list, 0, sizeof (portconfiglist_t)); cfg_list.vendorid = vid; cfg_list.deviceid = did - 1; - EXPECT_EQ (IOLINK_ERROR_NONE, par_serv_to_ds (port, sizeof(data_store_data), - data_store_data, vid, did)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + par_serv_to_ds (port, sizeof (data_store_data), data_store_data, vid, did)); EXPECT_FALSE (DS_Chk_Cfg (port, &cfg_list)); } TEST_F (DSTest, DS_Chk_Cfg_vid_did) { - uint8_t data_store_data[] = { 0x01, 0x23, 0x00, 0x02, 0x12, 0x34, 0x01, 0x24, - 0x01, 0x01, 0x55, 0x01, 0x24, 0x02, 0x01, 0xaa, - }; + uint8_t data_store_data[] = { + 0x01, + 0x23, + 0x00, + 0x02, + 0x12, + 0x34, + 0x01, + 0x24, + 0x01, + 0x01, + 0x55, + 0x01, + 0x24, + 0x02, + 0x01, + 0xaa, + }; uint16_t vid = 123; uint32_t did = 456; portconfiglist_t cfg_list; - memset (&cfg_list, 0, sizeof(portconfiglist_t)); + memset (&cfg_list, 0, sizeof (portconfiglist_t)); cfg_list.vendorid = vid; cfg_list.deviceid = did; - EXPECT_EQ (IOLINK_ERROR_NONE, par_serv_to_ds (port, sizeof(data_store_data), - data_store_data, vid, did)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + par_serv_to_ds (port, sizeof (data_store_data), data_store_data, vid, did)); EXPECT_TRUE (DS_Chk_Cfg (port, &cfg_list)); } @@ -1122,7 +1372,7 @@ TEST_F (DSTest, DS_Chk_Cfg_no_ds) portconfiglist_t cfg_list; - memset (&cfg_list, 0, sizeof(portconfiglist_t)); + memset (&cfg_list, 0, sizeof (portconfiglist_t)); cfg_list.vendorid = vid; cfg_list.deviceid = did; diff --git a/test/test_ode.cpp b/test/test_ode.cpp index 34b7e9c..5d129d3 100644 --- a/test/test_ode.cpp +++ b/test/test_ode.cpp @@ -22,9 +22,10 @@ class ODETest : public TestBase { -protected: + protected: // Override default setup - virtual void SetUp() { + virtual void SetUp() + { TestBase::SetUp(); // Re-use default setup }; }; @@ -46,27 +47,28 @@ static inline arg_block_od_t * ode_create_ArgBlock_od (uint8_t data_len) } arg_block_od = - (arg_block_od_t *) calloc (1, sizeof(arg_block_od_t) + data_len); + (arg_block_od_t *)calloc (1, sizeof (arg_block_od_t) + data_len); EXPECT_TRUE (arg_block_od); - arg_block_od->arg_block_id = IOLINK_ARG_BLOCK_ID_VOID_BLOCK; + arg_block_od->arg_block_id = IOLINK_ARG_BLOCK_ID_VOID_BLOCK; return arg_block_od; } -static inline void ode_verify_smi_err (iolink_arg_block_id_t exp_smi_ref_arg_id, - iolink_arg_block_id_t exp_smi_exp_arg_id, - iolink_smi_errortypes_t exp_errortype) +static inline void ode_verify_smi_err ( + iolink_arg_block_id_t exp_smi_ref_arg_id, + iolink_arg_block_id_t exp_smi_exp_arg_id, + iolink_smi_errortypes_t exp_errortype) { EXPECT_EQ (exp_smi_ref_arg_id, mock_iolink_smi_ref_arg_block_id); iolink_arg_block_id_t arg_block_id = - mock_iolink_smi_arg_block->void_block.arg_block_id; + mock_iolink_smi_arg_block->void_block.arg_block_id; EXPECT_EQ (IOLINK_ARG_BLOCK_ID_JOB_ERROR, arg_block_id); arg_block_joberror_t * job_error = - (arg_block_joberror_t*)mock_iolink_smi_arg_block; - iolink_smi_errortypes_t error = job_error->error; + (arg_block_joberror_t *)mock_iolink_smi_arg_block; + iolink_smi_errortypes_t error = job_error->error; iolink_arg_block_id_t exp_arg_block_id = job_error->exp_arg_block_id; EXPECT_EQ (exp_errortype, error); @@ -74,25 +76,26 @@ static inline void ode_verify_smi_err (iolink_arg_block_id_t exp_smi_ref_arg_id, } static inline void ode_verify_smi_read ( - iolink_arg_block_id_t exp_smi_ref_arg_id, - iolink_arg_block_id_t exp_smi_arg_id, - uint8_t exp_len, const uint8_t * data) + iolink_arg_block_id_t exp_smi_ref_arg_id, + iolink_arg_block_id_t exp_smi_arg_id, + uint8_t exp_len, + const uint8_t * data) { EXPECT_EQ (exp_smi_ref_arg_id, mock_iolink_smi_ref_arg_block_id); iolink_arg_block_id_t arg_block_id = - mock_iolink_smi_arg_block->void_block.arg_block_id; + mock_iolink_smi_arg_block->void_block.arg_block_id; EXPECT_EQ (exp_smi_arg_id, arg_block_id); EXPECT_EQ (arg_block_id, IOLINK_ARG_BLOCK_ID_OD_RD); - if (mock_iolink_smi_arg_block->void_block.arg_block_id == - IOLINK_ARG_BLOCK_ID_OD_RD) + if (mock_iolink_smi_arg_block->void_block.arg_block_id == IOLINK_ARG_BLOCK_ID_OD_RD) { - arg_block_od_t * arg_block_od = - (arg_block_od_t *)mock_iolink_smi_arg_block; + arg_block_od_t * arg_block_od = (arg_block_od_t *)mock_iolink_smi_arg_block; EXPECT_EQ (exp_len, mock_iolink_smi_arg_block_len); - EXPECT_TRUE (ArraysMatchN (data, arg_block_od->data, - exp_len - sizeof(arg_block_od_t))); + EXPECT_TRUE (ArraysMatchN ( + data, + arg_block_od->data, + exp_len - sizeof (arg_block_od_t))); } else { @@ -101,13 +104,13 @@ static inline void ode_verify_smi_read ( } static inline void ode_verify_smi_write ( - iolink_arg_block_id_t exp_smi_ref_arg_id, - iolink_arg_block_id_t exp_smi_arg_id, - uint8_t exp_len) + iolink_arg_block_id_t exp_smi_ref_arg_id, + iolink_arg_block_id_t exp_smi_arg_id, + uint8_t exp_len) { EXPECT_EQ (exp_smi_ref_arg_id, mock_iolink_smi_ref_arg_block_id); iolink_arg_block_id_t arg_block_id = - mock_iolink_smi_arg_block->void_block.arg_block_id; + mock_iolink_smi_arg_block->void_block.arg_block_id; EXPECT_EQ (exp_smi_arg_id, arg_block_id); EXPECT_EQ (arg_block_id, IOLINK_ARG_BLOCK_ID_VOID_BLOCK); EXPECT_EQ (exp_len, mock_iolink_smi_arg_block_len); @@ -122,28 +125,33 @@ static inline void ode_start (iolink_port_t * port) EXPECT_EQ (ODE_STATE_ODactive, ode_get_state (port)); } -static inline void ode_deviceread (iolink_port_t * port, - uint16_t index, uint8_t subindex, - uint8_t * data, uint8_t len) +static inline void ode_deviceread ( + iolink_port_t * port, + uint16_t index, + uint8_t subindex, + uint8_t * data, + uint8_t len) { arg_block_od_t * arg_block_od = NULL; - arg_block_od = ode_create_ArgBlock_od (len); + arg_block_od = ode_create_ArgBlock_od (len); ASSERT_TRUE (arg_block_od); arg_block_od->arg_block_id = IOLINK_ARG_BLOCK_ID_OD_RD; - arg_block_od->index = index; - arg_block_od->subindex = subindex; + arg_block_od->index = index; + arg_block_od->subindex = subindex; memset (arg_block_od->data, 0, len); ode_start (port); EXPECT_EQ (mock_iolink_al_read_req_cnt, 0); - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_DeviceRead_req (iolink_get_portnumber (port), - IOLINK_ARG_BLOCK_ID_OD_RD, - sizeof(arg_block_od_t) + len, - (arg_block_t *)arg_block_od)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_DeviceRead_req ( + iolink_get_portnumber (port), + IOLINK_ARG_BLOCK_ID_OD_RD, + sizeof (arg_block_od_t) + len, + (arg_block_t *)arg_block_od)); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (ODE_STATE_ODblocked, ode_get_state (port)); EXPECT_EQ (mock_iolink_al_read_req_cnt, 1); @@ -154,15 +162,21 @@ static inline void ode_deviceread (iolink_port_t * port, EXPECT_EQ (mock_iolink_al_read_req_cnt, 1); EXPECT_EQ (mock_iolink_al_write_req_cnt, 0); - ode_verify_smi_read (IOLINK_ARG_BLOCK_ID_OD_RD, IOLINK_ARG_BLOCK_ID_OD_RD, - sizeof(arg_block_od_t) + len, data); + ode_verify_smi_read ( + IOLINK_ARG_BLOCK_ID_OD_RD, + IOLINK_ARG_BLOCK_ID_OD_RD, + sizeof (arg_block_od_t) + len, + data); free (arg_block_od); } -static inline void ode_devicewrite (iolink_port_t * port, - uint16_t index, uint8_t subindex, - uint8_t * data, uint8_t len) +static inline void ode_devicewrite ( + iolink_port_t * port, + uint16_t index, + uint8_t subindex, + uint8_t * data, + uint8_t len) { arg_block_od_t * arg_block_od = NULL; @@ -170,19 +184,21 @@ static inline void ode_devicewrite (iolink_port_t * port, ASSERT_TRUE (arg_block_od); arg_block_od->arg_block_id = IOLINK_ARG_BLOCK_ID_OD_WR; - arg_block_od->index = index; - arg_block_od->subindex = subindex; + arg_block_od->index = index; + arg_block_od->subindex = subindex; memcpy (arg_block_od->data, data, len); ode_start (port); EXPECT_EQ (mock_iolink_al_write_req_cnt, 0); - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_DeviceWrite_req (iolink_get_portnumber (port), - IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - sizeof(arg_block_od_t) + len, - (arg_block_t *)arg_block_od)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_DeviceWrite_req ( + iolink_get_portnumber (port), + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + sizeof (arg_block_od_t) + len, + (arg_block_t *)arg_block_od)); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (ODE_STATE_ODblocked, ode_get_state (port)); EXPECT_EQ (mock_iolink_al_write_req_cnt, 1); @@ -193,9 +209,10 @@ static inline void ode_devicewrite (iolink_port_t * port, EXPECT_EQ (mock_iolink_al_write_req_cnt, 1); EXPECT_EQ (mock_iolink_al_read_req_cnt, 0); - ode_verify_smi_write (IOLINK_ARG_BLOCK_ID_OD_WR, - IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - sizeof (arg_block_void_t)); + ode_verify_smi_write ( + IOLINK_ARG_BLOCK_ID_OD_WR, + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + sizeof (arg_block_void_t)); /* Verify AL_Write_req data */ EXPECT_TRUE (ArraysMatchN (data, mock_iolink_al_data, len)); EXPECT_EQ (mock_iolink_al_data_index, index); @@ -228,60 +245,65 @@ TEST_F (ODETest, Ode_start_stop) TEST_F (ODETest, Ode_DeviceRead_1) { - uint8_t data[1] = {0x65}; - uint16_t index = 8; + uint8_t data[1] = {0x65}; + uint16_t index = 8; uint8_t subindex = 0; - ode_deviceread (port, index, subindex, data, sizeof(data)); + ode_deviceread (port, index, subindex, data, sizeof (data)); } TEST_F (ODETest, Ode_DeviceRead_2) { - uint8_t data[2] = {0x68, 0x91}; - uint16_t index = 2; + uint8_t data[2] = {0x68, 0x91}; + uint16_t index = 2; uint8_t subindex = 1; - ode_deviceread (port, index, subindex, data, sizeof(data)); + ode_deviceread (port, index, subindex, data, sizeof (data)); } TEST_F (ODETest, Ode_DeviceRead_3) { - uint8_t data[3] = {0x67, 0x37, 0x75}; - uint16_t index = 3; + uint8_t data[3] = {0x67, 0x37, 0x75}; + uint16_t index = 3; uint8_t subindex = 0; - ode_deviceread (port, index, subindex, data, sizeof(data)); + ode_deviceread (port, index, subindex, data, sizeof (data)); } TEST_F (ODETest, Ode_DeviceRead_bad_argblock) { iolink_arg_block_id_t bad_arg_block_id = IOLINK_ARG_BLOCK_ID_MASTERIDENT; - arg_block_od_t * arg_block_od = NULL; + arg_block_od_t * arg_block_od = NULL; - uint8_t data[1] = {0x65}; - uint16_t index = 7; + uint8_t data[1] = {0x65}; + uint16_t index = 7; uint8_t subindex = 0; - arg_block_od = ode_create_ArgBlock_od (sizeof(data)); + arg_block_od = ode_create_ArgBlock_od (sizeof (data)); ASSERT_TRUE (arg_block_od); /* Bad argblock type */ arg_block_od->arg_block_id = bad_arg_block_id; - arg_block_od->index = index; - arg_block_od->subindex = subindex; - arg_block_od->data[0] = 2; + arg_block_od->index = index; + arg_block_od->subindex = subindex; + arg_block_od->data[0] = 2; ode_start (port); - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_DeviceRead_req (portnumber, IOLINK_ARG_BLOCK_ID_OD_RD, - sizeof(arg_block_od_t) + sizeof(data), - (arg_block_t *)arg_block_od)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_DeviceRead_req ( + portnumber, + IOLINK_ARG_BLOCK_ID_OD_RD, + sizeof (arg_block_od_t) + sizeof (data), + (arg_block_t *)arg_block_od)); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (ODE_STATE_ODactive, ode_get_state (port)); - ode_verify_smi_err (bad_arg_block_id, IOLINK_ARG_BLOCK_ID_OD_RD, - IOLINK_SMI_ERRORTYPE_ARGBLOCK_NOT_SUPPORTED); + ode_verify_smi_err ( + bad_arg_block_id, + IOLINK_ARG_BLOCK_ID_OD_RD, + IOLINK_SMI_ERRORTYPE_ARGBLOCK_NOT_SUPPORTED); EXPECT_EQ (mock_iolink_smi_cnf_cnt, 0); EXPECT_EQ (mock_iolink_smi_joberror_cnt, 1); EXPECT_EQ (mock_iolink_al_read_req_cnt, 0); @@ -293,32 +315,37 @@ TEST_F (ODETest, Ode_DeviceRead_bad_argblock) TEST_F (ODETest, Ode_DeviceRead_bad_argblock_inactive) { iolink_arg_block_id_t bad_arg_block_id = IOLINK_ARG_BLOCK_ID_MASTERIDENT; - arg_block_od_t * arg_block_od = NULL; + arg_block_od_t * arg_block_od = NULL; - uint8_t data[1] = {0x62}; - uint16_t index = 12; + uint8_t data[1] = {0x62}; + uint16_t index = 12; uint8_t subindex = 0; - arg_block_od = ode_create_ArgBlock_od (sizeof(data)); + arg_block_od = ode_create_ArgBlock_od (sizeof (data)); ASSERT_TRUE (arg_block_od); /* Bad argblock type */ arg_block_od->arg_block_id = bad_arg_block_id; - arg_block_od->index = index; - arg_block_od->subindex = subindex; - arg_block_od->data[0] = data[0]; + arg_block_od->index = index; + arg_block_od->subindex = subindex; + arg_block_od->data[0] = data[0]; EXPECT_EQ (ODE_STATE_Inactive, ode_get_state (port)); - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_DeviceRead_req (portnumber, IOLINK_ARG_BLOCK_ID_OD_RD, - sizeof(arg_block_od_t) + sizeof(data), - (arg_block_t *)arg_block_od)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_DeviceRead_req ( + portnumber, + IOLINK_ARG_BLOCK_ID_OD_RD, + sizeof (arg_block_od_t) + sizeof (data), + (arg_block_t *)arg_block_od)); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (ODE_STATE_Inactive, ode_get_state (port)); - ode_verify_smi_err (bad_arg_block_id, IOLINK_ARG_BLOCK_ID_OD_RD, - IOLINK_SMI_ERRORTYPE_ARGBLOCK_NOT_SUPPORTED); + ode_verify_smi_err ( + bad_arg_block_id, + IOLINK_ARG_BLOCK_ID_OD_RD, + IOLINK_SMI_ERRORTYPE_ARGBLOCK_NOT_SUPPORTED); EXPECT_EQ (mock_iolink_smi_cnf_cnt, 0); EXPECT_EQ (mock_iolink_smi_joberror_cnt, 1); EXPECT_EQ (mock_iolink_al_write_req_cnt, 0); @@ -333,35 +360,38 @@ TEST_F (ODETest, Ode_DeviceRead_bad_argblock_busy) int i; arg_block_od_t * arg_block_od_first = NULL; - arg_block_od_t * arg_block_od_busy = NULL; + arg_block_od_t * arg_block_od_busy = NULL; - uint8_t data[1] = {0x65}; - uint16_t index = 8; + uint8_t data[1] = {0x65}; + uint16_t index = 8; uint8_t subindex = 0; - arg_block_od_first = ode_create_ArgBlock_od (sizeof(data)); + arg_block_od_first = ode_create_ArgBlock_od (sizeof (data)); ASSERT_TRUE (arg_block_od_first); - arg_block_od_busy = ode_create_ArgBlock_od (sizeof(data)); + arg_block_od_busy = ode_create_ArgBlock_od (sizeof (data)); ASSERT_TRUE (arg_block_od_busy); arg_block_od_first->arg_block_id = IOLINK_ARG_BLOCK_ID_OD_RD; - arg_block_od_first->index = index; - arg_block_od_first->subindex = subindex; - arg_block_od_first->data[0] = 2; + arg_block_od_first->index = index; + arg_block_od_first->subindex = subindex; + arg_block_od_first->data[0] = 2; /* Bad argblock type */ arg_block_od_busy->arg_block_id = bad_arg_block_id; - arg_block_od_busy->index = index; - arg_block_od_busy->subindex = subindex; - arg_block_od_busy->data[0] = 3; + arg_block_od_busy->index = index; + arg_block_od_busy->subindex = subindex; + arg_block_od_busy->data[0] = 3; ode_start (port); EXPECT_EQ (mock_iolink_al_read_req_cnt, 0); - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_DeviceRead_req (portnumber, IOLINK_ARG_BLOCK_ID_OD_RD, - sizeof(arg_block_od_t) + sizeof(data), - (arg_block_t *)arg_block_od_first)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_DeviceRead_req ( + portnumber, + IOLINK_ARG_BLOCK_ID_OD_RD, + sizeof (arg_block_od_t) + sizeof (data), + (arg_block_t *)arg_block_od_first)); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (ODE_STATE_ODblocked, ode_get_state (port)); EXPECT_EQ (mock_iolink_al_read_req_cnt, 1); @@ -371,20 +401,24 @@ TEST_F (ODETest, Ode_DeviceRead_bad_argblock_busy) for (i = 0; i < 5; i++) { /* ODE is now busy waiting for AL_Read_cnf() */ - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_DeviceRead_req (portnumber, IOLINK_ARG_BLOCK_ID_OD_RD, - sizeof(arg_block_od_t) + sizeof(data), - (arg_block_t *)arg_block_od_busy)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_DeviceRead_req ( + portnumber, + IOLINK_ARG_BLOCK_ID_OD_RD, + sizeof (arg_block_od_t) + sizeof (data), + (arg_block_t *)arg_block_od_busy)); mock_iolink_job.callback (&mock_iolink_job); /* Verify JOB_ERROR */ EXPECT_EQ (mock_iolink_smi_cnf_cnt, 0); EXPECT_EQ (mock_iolink_smi_joberror_cnt, 1 + i); - ode_verify_smi_err (bad_arg_block_id, IOLINK_ARG_BLOCK_ID_OD_RD, - IOLINK_SMI_ERRORTYPE_ARGBLOCK_NOT_SUPPORTED); + ode_verify_smi_err ( + bad_arg_block_id, + IOLINK_ARG_BLOCK_ID_OD_RD, + IOLINK_SMI_ERRORTYPE_ARGBLOCK_NOT_SUPPORTED); } - mock_iolink_al_read_cnf_cb (port, sizeof(data), data, - IOLINK_SMI_ERRORTYPE_NONE); + mock_iolink_al_read_cnf_cb (port, sizeof (data), data, IOLINK_SMI_ERRORTYPE_NONE); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (mock_iolink_smi_cnf_cnt, 1); @@ -394,8 +428,11 @@ TEST_F (ODETest, Ode_DeviceRead_bad_argblock_busy) EXPECT_EQ (mock_iolink_al_data_index, index); EXPECT_EQ (mock_iolink_al_data_subindex, subindex); - ode_verify_smi_read (IOLINK_ARG_BLOCK_ID_OD_RD, IOLINK_ARG_BLOCK_ID_OD_RD, - sizeof(arg_block_od_t) + sizeof(data), data); + ode_verify_smi_read ( + IOLINK_ARG_BLOCK_ID_OD_RD, + IOLINK_ARG_BLOCK_ID_OD_RD, + sizeof (arg_block_od_t) + sizeof (data), + data); free (arg_block_od_first); free (arg_block_od_busy); @@ -405,8 +442,8 @@ TEST_F (ODETest, Ode_DeviceRead_too_small) { arg_block_od_t * arg_block_od = NULL; - uint8_t data[6] = {0x67, 0x37, 0x75, 0x22, 0x31, 0x99}; - uint16_t index = 9; + uint8_t data[6] = {0x67, 0x37, 0x75, 0x22, 0x31, 0x99}; + uint16_t index = 9; uint8_t subindex = 4; uint8_t arg_block_len = 2; @@ -415,23 +452,25 @@ TEST_F (ODETest, Ode_DeviceRead_too_small) ASSERT_TRUE (arg_block_od); arg_block_od->arg_block_id = IOLINK_ARG_BLOCK_ID_OD_RD; - arg_block_od->index = index; - arg_block_od->subindex = subindex; - arg_block_od->data[0] = 3; - arg_block_od->data[1] = 4; + arg_block_od->index = index; + arg_block_od->subindex = subindex; + arg_block_od->data[0] = 3; + arg_block_od->data[1] = 4; ode_start (port); EXPECT_EQ (mock_iolink_al_read_req_cnt, 0); - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_DeviceRead_req (portnumber, IOLINK_ARG_BLOCK_ID_OD_RD, - sizeof(arg_block_od_t) + arg_block_len, - (arg_block_t *)arg_block_od)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_DeviceRead_req ( + portnumber, + IOLINK_ARG_BLOCK_ID_OD_RD, + sizeof (arg_block_od_t) + arg_block_len, + (arg_block_t *)arg_block_od)); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (ODE_STATE_ODblocked, ode_get_state (port)); EXPECT_EQ (mock_iolink_al_read_req_cnt, 1); - mock_iolink_al_read_cnf_cb (port, sizeof(data), data, - IOLINK_SMI_ERRORTYPE_NONE); + mock_iolink_al_read_cnf_cb (port, sizeof (data), data, IOLINK_SMI_ERRORTYPE_NONE); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (mock_iolink_smi_cnf_cnt, 0); @@ -439,8 +478,10 @@ TEST_F (ODETest, Ode_DeviceRead_too_small) EXPECT_EQ (mock_iolink_al_read_req_cnt, 1); EXPECT_EQ (mock_iolink_al_write_req_cnt, 0); - ode_verify_smi_err (IOLINK_ARG_BLOCK_ID_OD_RD, IOLINK_ARG_BLOCK_ID_OD_RD, - IOLINK_SMI_ERRORTYPE_ARGBLOCK_LENGTH_INVALID); + ode_verify_smi_err ( + IOLINK_ARG_BLOCK_ID_OD_RD, + IOLINK_ARG_BLOCK_ID_OD_RD, + IOLINK_SMI_ERRORTYPE_ARGBLOCK_LENGTH_INVALID); free (arg_block_od); } @@ -450,34 +491,37 @@ TEST_F (ODETest, Ode_DeviceRead_busy) int i; arg_block_od_t * arg_block_od_first = NULL; - arg_block_od_t * arg_block_od_busy = NULL; + arg_block_od_t * arg_block_od_busy = NULL; - uint8_t data[1] = {0x65}; - uint16_t index = 8; + uint8_t data[1] = {0x65}; + uint16_t index = 8; uint8_t subindex = 0; - arg_block_od_first = ode_create_ArgBlock_od (sizeof(data)); + arg_block_od_first = ode_create_ArgBlock_od (sizeof (data)); ASSERT_TRUE (arg_block_od_first); - arg_block_od_busy = ode_create_ArgBlock_od (sizeof(data)); + arg_block_od_busy = ode_create_ArgBlock_od (sizeof (data)); ASSERT_TRUE (arg_block_od_busy); arg_block_od_first->arg_block_id = IOLINK_ARG_BLOCK_ID_OD_RD; - arg_block_od_first->index = index; - arg_block_od_first->subindex = subindex; - arg_block_od_first->data[0] = 2; + arg_block_od_first->index = index; + arg_block_od_first->subindex = subindex; + arg_block_od_first->data[0] = 2; arg_block_od_busy->arg_block_id = IOLINK_ARG_BLOCK_ID_OD_RD; - arg_block_od_busy->index = index; - arg_block_od_busy->subindex = subindex; - arg_block_od_busy->data[0] = 3; + arg_block_od_busy->index = index; + arg_block_od_busy->subindex = subindex; + arg_block_od_busy->data[0] = 3; ode_start (port); EXPECT_EQ (mock_iolink_al_read_req_cnt, 0); - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_DeviceRead_req (portnumber, IOLINK_ARG_BLOCK_ID_OD_RD, - sizeof(arg_block_od_t) + sizeof(data), - (arg_block_t *)arg_block_od_first)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_DeviceRead_req ( + portnumber, + IOLINK_ARG_BLOCK_ID_OD_RD, + sizeof (arg_block_od_t) + sizeof (data), + (arg_block_t *)arg_block_od_first)); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (ODE_STATE_ODblocked, ode_get_state (port)); EXPECT_EQ (mock_iolink_al_read_req_cnt, 1); @@ -487,24 +531,31 @@ TEST_F (ODETest, Ode_DeviceRead_busy) for (i = 0; i < 5; i++) { /* ODE is now busy, waiting for AL_Read_cnf() */ - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_DeviceRead_req (portnumber, IOLINK_ARG_BLOCK_ID_OD_RD, - sizeof(arg_block_od_t) + sizeof(data), - (arg_block_t *)arg_block_od_busy)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_DeviceRead_req ( + portnumber, + IOLINK_ARG_BLOCK_ID_OD_RD, + sizeof (arg_block_od_t) + sizeof (data), + (arg_block_t *)arg_block_od_busy)); mock_iolink_job.callback (&mock_iolink_job); /* Verify JOB_ERROR */ EXPECT_EQ (mock_iolink_smi_cnf_cnt, 0); EXPECT_EQ (mock_iolink_smi_joberror_cnt, 1 + i); - ode_verify_smi_err (IOLINK_ARG_BLOCK_ID_OD_RD, IOLINK_ARG_BLOCK_ID_OD_RD, - IOLINK_SMI_ERRORTYPE_SERVICE_TEMP_UNAVAILABLE); + ode_verify_smi_err ( + IOLINK_ARG_BLOCK_ID_OD_RD, + IOLINK_ARG_BLOCK_ID_OD_RD, + IOLINK_SMI_ERRORTYPE_SERVICE_TEMP_UNAVAILABLE); } - mock_iolink_al_read_cnf_cb (port, sizeof(data), data, - IOLINK_SMI_ERRORTYPE_NONE); + mock_iolink_al_read_cnf_cb (port, sizeof (data), data, IOLINK_SMI_ERRORTYPE_NONE); mock_iolink_job.callback (&mock_iolink_job); - ode_verify_smi_read (IOLINK_ARG_BLOCK_ID_OD_RD, IOLINK_ARG_BLOCK_ID_OD_RD, - sizeof(arg_block_od_t) + sizeof(data), data); + ode_verify_smi_read ( + IOLINK_ARG_BLOCK_ID_OD_RD, + IOLINK_ARG_BLOCK_ID_OD_RD, + sizeof (arg_block_od_t) + sizeof (data), + data); EXPECT_EQ (mock_iolink_smi_cnf_cnt, 1); EXPECT_EQ (mock_iolink_smi_joberror_cnt, 5); EXPECT_EQ (mock_iolink_al_read_req_cnt, 1); @@ -520,24 +571,27 @@ TEST_F (ODETest, Ode_DeviceRead_inactive) { arg_block_od_t * arg_block_od = NULL; - uint8_t data[1] = {0x33}; - uint16_t index = 4; + uint8_t data[1] = {0x33}; + uint16_t index = 4; uint8_t subindex = 3; - arg_block_od = ode_create_ArgBlock_od (sizeof(data)); + arg_block_od = ode_create_ArgBlock_od (sizeof (data)); ASSERT_TRUE (arg_block_od); arg_block_od->arg_block_id = IOLINK_ARG_BLOCK_ID_OD_RD; - arg_block_od->index = index; - arg_block_od->subindex = subindex; - arg_block_od->data[0] = data[0]; + arg_block_od->index = index; + arg_block_od->subindex = subindex; + arg_block_od->data[0] = data[0]; EXPECT_EQ (ODE_STATE_Inactive, ode_get_state (port)); - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_DeviceRead_req (portnumber, IOLINK_ARG_BLOCK_ID_OD_RD, - sizeof(arg_block_od_t) + sizeof(data), - (arg_block_t *)arg_block_od)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_DeviceRead_req ( + portnumber, + IOLINK_ARG_BLOCK_ID_OD_RD, + sizeof (arg_block_od_t) + sizeof (data), + (arg_block_t *)arg_block_od)); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (ODE_STATE_Inactive, ode_get_state (port)); @@ -546,68 +600,75 @@ TEST_F (ODETest, Ode_DeviceRead_inactive) EXPECT_EQ (mock_iolink_al_read_req_cnt, 0); EXPECT_EQ (mock_iolink_al_write_req_cnt, 0); - ode_verify_smi_err (IOLINK_ARG_BLOCK_ID_OD_RD, IOLINK_ARG_BLOCK_ID_OD_RD, - IOLINK_SMI_ERRORTYPE_IDX_NOTAVAIL); + ode_verify_smi_err ( + IOLINK_ARG_BLOCK_ID_OD_RD, + IOLINK_ARG_BLOCK_ID_OD_RD, + IOLINK_SMI_ERRORTYPE_IDX_NOTAVAIL); free (arg_block_od); } TEST_F (ODETest, Ode_DeviceWrite_1) { - uint8_t data[1] = {0x65}; - uint16_t index = 4; + uint8_t data[1] = {0x65}; + uint16_t index = 4; uint8_t subindex = 0; - ode_devicewrite (port, index, subindex, data, sizeof(data)); + ode_devicewrite (port, index, subindex, data, sizeof (data)); } TEST_F (ODETest, Ode_DeviceWrite_2) { - uint8_t data[2] = {0x99, 0x12}; - uint16_t index = 7; + uint8_t data[2] = {0x99, 0x12}; + uint16_t index = 7; uint8_t subindex = 1; - ode_devicewrite (port, index, subindex, data, sizeof(data)); + ode_devicewrite (port, index, subindex, data, sizeof (data)); } TEST_F (ODETest, Ode_DeviceWrite_3) { - uint8_t data[3] = {0x9, 0x2, 0x30}; - uint16_t index = 2; + uint8_t data[3] = {0x9, 0x2, 0x30}; + uint16_t index = 2; uint8_t subindex = 2; - ode_devicewrite (port, index, subindex, data, sizeof(data)); + ode_devicewrite (port, index, subindex, data, sizeof (data)); } TEST_F (ODETest, Ode_DeviceWrite_bad_argblock) { iolink_arg_block_id_t bad_arg_block_id = IOLINK_ARG_BLOCK_ID_MASTERIDENT; - arg_block_od_t * arg_block_od = NULL; + arg_block_od_t * arg_block_od = NULL; - uint8_t data[1] = {0x69}; - uint16_t index = 8; + uint8_t data[1] = {0x69}; + uint16_t index = 8; uint8_t subindex = 0; - arg_block_od = ode_create_ArgBlock_od (sizeof(data)); + arg_block_od = ode_create_ArgBlock_od (sizeof (data)); ASSERT_TRUE (arg_block_od); /* Bad argblock type */ arg_block_od->arg_block_id = bad_arg_block_id; - arg_block_od->index = index; - arg_block_od->subindex = subindex; - arg_block_od->data[0] = data[0]; + arg_block_od->index = index; + arg_block_od->subindex = subindex; + arg_block_od->data[0] = data[0]; ode_start (port); - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_DeviceWrite_req (portnumber, IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - sizeof(arg_block_od_t) + sizeof(data), - (arg_block_t *)arg_block_od)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_DeviceWrite_req ( + portnumber, + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + sizeof (arg_block_od_t) + sizeof (data), + (arg_block_t *)arg_block_od)); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (ODE_STATE_ODactive, ode_get_state (port)); - ode_verify_smi_err (bad_arg_block_id, IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - IOLINK_SMI_ERRORTYPE_ARGBLOCK_NOT_SUPPORTED); + ode_verify_smi_err ( + bad_arg_block_id, + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + IOLINK_SMI_ERRORTYPE_ARGBLOCK_NOT_SUPPORTED); EXPECT_EQ (mock_iolink_smi_cnf_cnt, 0); EXPECT_EQ (mock_iolink_smi_joberror_cnt, 1); EXPECT_EQ (mock_iolink_al_write_req_cnt, 0); @@ -619,32 +680,37 @@ TEST_F (ODETest, Ode_DeviceWrite_bad_argblock) TEST_F (ODETest, Ode_DeviceWrite_bad_argblock_inactive) { iolink_arg_block_id_t bad_arg_block_id = IOLINK_ARG_BLOCK_ID_MASTERIDENT; - arg_block_od_t * arg_block_od = NULL; + arg_block_od_t * arg_block_od = NULL; - uint8_t data[1] = {0x69}; - uint16_t index = 8; + uint8_t data[1] = {0x69}; + uint16_t index = 8; uint8_t subindex = 0; - arg_block_od = ode_create_ArgBlock_od (sizeof(data)); + arg_block_od = ode_create_ArgBlock_od (sizeof (data)); ASSERT_TRUE (arg_block_od); /* Bad argblock type */ arg_block_od->arg_block_id = bad_arg_block_id; - arg_block_od->index = index; - arg_block_od->subindex = subindex; - arg_block_od->data[0] = data[0]; + arg_block_od->index = index; + arg_block_od->subindex = subindex; + arg_block_od->data[0] = data[0]; EXPECT_EQ (ODE_STATE_Inactive, ode_get_state (port)); - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_DeviceWrite_req (portnumber, IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - sizeof(arg_block_od_t) + sizeof(data), - (arg_block_t *)arg_block_od)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_DeviceWrite_req ( + portnumber, + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + sizeof (arg_block_od_t) + sizeof (data), + (arg_block_t *)arg_block_od)); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (ODE_STATE_Inactive, ode_get_state (port)); - ode_verify_smi_err (bad_arg_block_id, IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - IOLINK_SMI_ERRORTYPE_ARGBLOCK_NOT_SUPPORTED); + ode_verify_smi_err ( + bad_arg_block_id, + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + IOLINK_SMI_ERRORTYPE_ARGBLOCK_NOT_SUPPORTED); EXPECT_EQ (mock_iolink_smi_cnf_cnt, 0); EXPECT_EQ (mock_iolink_smi_joberror_cnt, 1); EXPECT_EQ (mock_iolink_al_write_req_cnt, 0); @@ -659,35 +725,38 @@ TEST_F (ODETest, Ode_DeviceWrite_bad_argblock_busy) int i; arg_block_od_t * arg_block_od_first = NULL; - arg_block_od_t * arg_block_od_busy = NULL; + arg_block_od_t * arg_block_od_busy = NULL; - uint8_t data[1] = {0x71}; - uint16_t index = 5; + uint8_t data[1] = {0x71}; + uint16_t index = 5; uint8_t subindex = 0; - arg_block_od_first = ode_create_ArgBlock_od (sizeof(data)); + arg_block_od_first = ode_create_ArgBlock_od (sizeof (data)); ASSERT_TRUE (arg_block_od_first); - arg_block_od_busy = ode_create_ArgBlock_od (sizeof(data)); + arg_block_od_busy = ode_create_ArgBlock_od (sizeof (data)); ASSERT_TRUE (arg_block_od_busy); arg_block_od_first->arg_block_id = IOLINK_ARG_BLOCK_ID_OD_WR; - arg_block_od_first->index = index; - arg_block_od_first->subindex = subindex; - arg_block_od_first->data[0] = data[0]; + arg_block_od_first->index = index; + arg_block_od_first->subindex = subindex; + arg_block_od_first->data[0] = data[0]; /* Bad argblock type */ arg_block_od_busy->arg_block_id = bad_arg_block_id; - arg_block_od_busy->index = index; - arg_block_od_busy->subindex = subindex; - arg_block_od_busy->data[0] = data[0]; + arg_block_od_busy->index = index; + arg_block_od_busy->subindex = subindex; + arg_block_od_busy->data[0] = data[0]; ode_start (port); EXPECT_EQ (mock_iolink_al_write_req_cnt, 0); - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_DeviceWrite_req (portnumber, IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - sizeof(arg_block_od_t) + sizeof(data), - (arg_block_t *)arg_block_od_first)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_DeviceWrite_req ( + portnumber, + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + sizeof (arg_block_od_t) + sizeof (data), + (arg_block_t *)arg_block_od_first)); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (ODE_STATE_ODblocked, ode_get_state (port)); EXPECT_EQ (mock_iolink_al_write_req_cnt, 1); @@ -697,17 +766,21 @@ TEST_F (ODETest, Ode_DeviceWrite_bad_argblock_busy) for (i = 0; i < 5; i++) { /* ODE is now busy waiting for AL_Write_cnf() */ - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_DeviceWrite_req (portnumber, - IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - sizeof(arg_block_od_t) + sizeof(data), - (arg_block_t *)arg_block_od_busy)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_DeviceWrite_req ( + portnumber, + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + sizeof (arg_block_od_t) + sizeof (data), + (arg_block_t *)arg_block_od_busy)); mock_iolink_job.callback (&mock_iolink_job); /* Verify JOB_ERROR */ EXPECT_EQ (mock_iolink_smi_cnf_cnt, 0); EXPECT_EQ (mock_iolink_smi_joberror_cnt, 1 + i); - ode_verify_smi_err (bad_arg_block_id, IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - IOLINK_SMI_ERRORTYPE_ARGBLOCK_NOT_SUPPORTED); + ode_verify_smi_err ( + bad_arg_block_id, + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + IOLINK_SMI_ERRORTYPE_ARGBLOCK_NOT_SUPPORTED); } mock_iolink_al_write_cnf_cb (port, IOLINK_SMI_ERRORTYPE_NONE); @@ -720,11 +793,12 @@ TEST_F (ODETest, Ode_DeviceWrite_bad_argblock_busy) EXPECT_EQ (mock_iolink_al_data_index, index); EXPECT_EQ (mock_iolink_al_data_subindex, subindex); - ode_verify_smi_write (IOLINK_ARG_BLOCK_ID_OD_WR, - IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - sizeof (arg_block_void_t)); + ode_verify_smi_write ( + IOLINK_ARG_BLOCK_ID_OD_WR, + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + sizeof (arg_block_void_t)); /* Verify AL_Write_req data */ - EXPECT_TRUE (ArraysMatchN (data, mock_iolink_al_data, sizeof(data))); + EXPECT_TRUE (ArraysMatchN (data, mock_iolink_al_data, sizeof (data))); free (arg_block_od_first); free (arg_block_od_busy); @@ -735,34 +809,37 @@ TEST_F (ODETest, Ode_DeviceWrite_busy) int i; arg_block_od_t * arg_block_od_first = NULL; - arg_block_od_t * arg_block_od_busy = NULL; + arg_block_od_t * arg_block_od_busy = NULL; - uint8_t data[1] = {0x69}; - uint16_t index = 9; + uint8_t data[1] = {0x69}; + uint16_t index = 9; uint8_t subindex = 0; - arg_block_od_first = ode_create_ArgBlock_od (sizeof(data)); + arg_block_od_first = ode_create_ArgBlock_od (sizeof (data)); ASSERT_TRUE (arg_block_od_first); - arg_block_od_busy = ode_create_ArgBlock_od (sizeof(data)); + arg_block_od_busy = ode_create_ArgBlock_od (sizeof (data)); ASSERT_TRUE (arg_block_od_busy); arg_block_od_first->arg_block_id = IOLINK_ARG_BLOCK_ID_OD_WR; - arg_block_od_first->index = index; - arg_block_od_first->subindex = subindex; - arg_block_od_first->data[0] = data[0]; + arg_block_od_first->index = index; + arg_block_od_first->subindex = subindex; + arg_block_od_first->data[0] = data[0]; arg_block_od_busy->arg_block_id = IOLINK_ARG_BLOCK_ID_OD_WR; - arg_block_od_busy->index = index; - arg_block_od_busy->subindex = subindex; - arg_block_od_busy->data[0] = data[0]; + arg_block_od_busy->index = index; + arg_block_od_busy->subindex = subindex; + arg_block_od_busy->data[0] = data[0]; ode_start (port); EXPECT_EQ (mock_iolink_al_write_req_cnt, 0); - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_DeviceWrite_req (portnumber, IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - sizeof(arg_block_od_t) + sizeof(data), - (arg_block_t *)arg_block_od_first)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_DeviceWrite_req ( + portnumber, + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + sizeof (arg_block_od_t) + sizeof (data), + (arg_block_t *)arg_block_od_first)); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (ODE_STATE_ODblocked, ode_get_state (port)); EXPECT_EQ (mock_iolink_al_write_req_cnt, 1); @@ -772,28 +849,32 @@ TEST_F (ODETest, Ode_DeviceWrite_busy) for (i = 0; i < 5; i++) { /* ODE is now busy, waiting for AL_Write_cnf() */ - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_DeviceWrite_req (portnumber, - IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - sizeof(arg_block_od_t) + sizeof(data), - (arg_block_t *)arg_block_od_busy)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_DeviceWrite_req ( + portnumber, + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + sizeof (arg_block_od_t) + sizeof (data), + (arg_block_t *)arg_block_od_busy)); mock_iolink_job.callback (&mock_iolink_job); /* Verify JOB_ERROR */ EXPECT_EQ (mock_iolink_smi_cnf_cnt, 0); EXPECT_EQ (mock_iolink_smi_joberror_cnt, 1 + i); - ode_verify_smi_err (IOLINK_ARG_BLOCK_ID_OD_WR, - IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - IOLINK_SMI_ERRORTYPE_SERVICE_TEMP_UNAVAILABLE); + ode_verify_smi_err ( + IOLINK_ARG_BLOCK_ID_OD_WR, + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + IOLINK_SMI_ERRORTYPE_SERVICE_TEMP_UNAVAILABLE); } mock_iolink_al_write_cnf_cb (port, IOLINK_SMI_ERRORTYPE_NONE); mock_iolink_job.callback (&mock_iolink_job); - ode_verify_smi_write (IOLINK_ARG_BLOCK_ID_OD_WR, - IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - sizeof (arg_block_void_t)); + ode_verify_smi_write ( + IOLINK_ARG_BLOCK_ID_OD_WR, + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + sizeof (arg_block_void_t)); /* Verify AL_Write_req data */ - EXPECT_TRUE (ArraysMatchN (data, mock_iolink_al_data, sizeof(data))); + EXPECT_TRUE (ArraysMatchN (data, mock_iolink_al_data, sizeof (data))); EXPECT_EQ (mock_iolink_smi_cnf_cnt, 1); EXPECT_EQ (mock_iolink_smi_joberror_cnt, 5); EXPECT_EQ (mock_iolink_al_write_req_cnt, 1); @@ -809,24 +890,27 @@ TEST_F (ODETest, Ode_DeviceWrite_inactive) { arg_block_od_t * arg_block_od = NULL; - uint8_t data[1] = {0x64}; - uint16_t index = 5; + uint8_t data[1] = {0x64}; + uint16_t index = 5; uint8_t subindex = 2; - arg_block_od = ode_create_ArgBlock_od (sizeof(data)); + arg_block_od = ode_create_ArgBlock_od (sizeof (data)); ASSERT_TRUE (arg_block_od); arg_block_od->arg_block_id = IOLINK_ARG_BLOCK_ID_OD_WR; - arg_block_od->index = index; - arg_block_od->subindex = subindex; - arg_block_od->data[0] = data[0]; + arg_block_od->index = index; + arg_block_od->subindex = subindex; + arg_block_od->data[0] = data[0]; EXPECT_EQ (ODE_STATE_Inactive, ode_get_state (port)); - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_DeviceWrite_req (portnumber, IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - sizeof(arg_block_od_t) + sizeof(data), - (arg_block_t *)arg_block_od)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_DeviceWrite_req ( + portnumber, + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + sizeof (arg_block_od_t) + sizeof (data), + (arg_block_t *)arg_block_od)); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (ODE_STATE_Inactive, ode_get_state (port)); @@ -835,9 +919,10 @@ TEST_F (ODETest, Ode_DeviceWrite_inactive) EXPECT_EQ (mock_iolink_al_read_req_cnt, 0); EXPECT_EQ (mock_iolink_al_write_req_cnt, 0); - ode_verify_smi_err (IOLINK_ARG_BLOCK_ID_OD_WR, - IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - IOLINK_SMI_ERRORTYPE_IDX_NOTAVAIL); + ode_verify_smi_err ( + IOLINK_ARG_BLOCK_ID_OD_WR, + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + IOLINK_SMI_ERRORTYPE_IDX_NOTAVAIL); free (arg_block_od); } @@ -850,10 +935,13 @@ TEST_F (ODETest, Ode_ParamReadBatch_inactive) EXPECT_EQ (ODE_STATE_Inactive, ode_get_state (port)); - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_ParamReadBatch_req (portnumber, - IOLINK_ARG_BLOCK_ID_DEV_PAR_BAT, - sizeof(arg_block_t), &arg_block)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_ParamReadBatch_req ( + portnumber, + IOLINK_ARG_BLOCK_ID_DEV_PAR_BAT, + sizeof (arg_block_t), + &arg_block)); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (ODE_STATE_Inactive, ode_get_state (port)); @@ -862,9 +950,10 @@ TEST_F (ODETest, Ode_ParamReadBatch_inactive) EXPECT_EQ (mock_iolink_al_read_req_cnt, 0); EXPECT_EQ (mock_iolink_al_write_req_cnt, 0); - ode_verify_smi_err (IOLINK_ARG_BLOCK_ID_PORT_INXDEX_LIST, - IOLINK_ARG_BLOCK_ID_DEV_PAR_BAT, - IOLINK_SMI_ERRORTYPE_SERVICE_NOT_SUPPORTED); + ode_verify_smi_err ( + IOLINK_ARG_BLOCK_ID_PORT_INXDEX_LIST, + IOLINK_ARG_BLOCK_ID_DEV_PAR_BAT, + IOLINK_SMI_ERRORTYPE_SERVICE_NOT_SUPPORTED); } TEST_F (ODETest, Ode_ParamReadBatch_not_supported) @@ -875,10 +964,13 @@ TEST_F (ODETest, Ode_ParamReadBatch_not_supported) ode_start (port); - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_ParamReadBatch_req (portnumber, - IOLINK_ARG_BLOCK_ID_DEV_PAR_BAT, - sizeof(arg_block_t), &arg_block)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_ParamReadBatch_req ( + portnumber, + IOLINK_ARG_BLOCK_ID_DEV_PAR_BAT, + sizeof (arg_block_t), + &arg_block)); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (ODE_STATE_ODactive, ode_get_state (port)); @@ -887,9 +979,10 @@ TEST_F (ODETest, Ode_ParamReadBatch_not_supported) EXPECT_EQ (mock_iolink_al_read_req_cnt, 0); EXPECT_EQ (mock_iolink_al_write_req_cnt, 0); - ode_verify_smi_err (IOLINK_ARG_BLOCK_ID_PORT_INXDEX_LIST, - IOLINK_ARG_BLOCK_ID_DEV_PAR_BAT, - IOLINK_SMI_ERRORTYPE_SERVICE_NOT_SUPPORTED); + ode_verify_smi_err ( + IOLINK_ARG_BLOCK_ID_PORT_INXDEX_LIST, + IOLINK_ARG_BLOCK_ID_DEV_PAR_BAT, + IOLINK_SMI_ERRORTYPE_SERVICE_NOT_SUPPORTED); } TEST_F (ODETest, Ode_ParamReadBatch_busy) @@ -899,28 +992,31 @@ TEST_F (ODETest, Ode_ParamReadBatch_busy) arg_block_od_t * arg_block_od_first = NULL; arg_block_t arg_block_readbatch; - uint8_t data[1] = {0x65}; - uint16_t index = 8; + uint8_t data[1] = {0x65}; + uint16_t index = 8; uint8_t subindex = 0; - arg_block_od_first = ode_create_ArgBlock_od (sizeof(data)); + arg_block_od_first = ode_create_ArgBlock_od (sizeof (data)); ASSERT_TRUE (arg_block_od_first); arg_block_od_first->arg_block_id = IOLINK_ARG_BLOCK_ID_OD_RD; - arg_block_od_first->index = index; - arg_block_od_first->subindex = subindex; - arg_block_od_first->data[0] = 2; + arg_block_od_first->index = index; + arg_block_od_first->subindex = subindex; + arg_block_od_first->data[0] = 2; arg_block_readbatch.void_block.arg_block_id = - IOLINK_ARG_BLOCK_ID_PORT_INXDEX_LIST; + IOLINK_ARG_BLOCK_ID_PORT_INXDEX_LIST; ode_start (port); EXPECT_EQ (mock_iolink_al_read_req_cnt, 0); - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_DeviceRead_req (portnumber, IOLINK_ARG_BLOCK_ID_OD_RD, - sizeof(arg_block_od_t) + sizeof(data), - (arg_block_t *)arg_block_od_first)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_DeviceRead_req ( + portnumber, + IOLINK_ARG_BLOCK_ID_OD_RD, + sizeof (arg_block_od_t) + sizeof (data), + (arg_block_t *)arg_block_od_first)); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (ODE_STATE_ODblocked, ode_get_state (port)); EXPECT_EQ (mock_iolink_al_read_req_cnt, 1); @@ -930,26 +1026,31 @@ TEST_F (ODETest, Ode_ParamReadBatch_busy) for (i = 0; i < 5; i++) { /* ODE is now busy, waiting for AL_Read_cnf() */ - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_ParamReadBatch_req (portnumber, - IOLINK_ARG_BLOCK_ID_DEV_PAR_BAT, - sizeof(arg_block_t), - &arg_block_readbatch)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_ParamReadBatch_req ( + portnumber, + IOLINK_ARG_BLOCK_ID_DEV_PAR_BAT, + sizeof (arg_block_t), + &arg_block_readbatch)); mock_iolink_job.callback (&mock_iolink_job); /* Verify JOB_ERROR */ EXPECT_EQ (mock_iolink_smi_cnf_cnt, 0); EXPECT_EQ (mock_iolink_smi_joberror_cnt, 1 + i); - ode_verify_smi_err (IOLINK_ARG_BLOCK_ID_PORT_INXDEX_LIST, - IOLINK_ARG_BLOCK_ID_DEV_PAR_BAT, - IOLINK_SMI_ERRORTYPE_SERVICE_NOT_SUPPORTED); + ode_verify_smi_err ( + IOLINK_ARG_BLOCK_ID_PORT_INXDEX_LIST, + IOLINK_ARG_BLOCK_ID_DEV_PAR_BAT, + IOLINK_SMI_ERRORTYPE_SERVICE_NOT_SUPPORTED); } - mock_iolink_al_read_cnf_cb (port, sizeof(data), data, - IOLINK_SMI_ERRORTYPE_NONE); + mock_iolink_al_read_cnf_cb (port, sizeof (data), data, IOLINK_SMI_ERRORTYPE_NONE); mock_iolink_job.callback (&mock_iolink_job); - ode_verify_smi_read (IOLINK_ARG_BLOCK_ID_OD_RD, IOLINK_ARG_BLOCK_ID_OD_RD, - sizeof(arg_block_od_t) + sizeof(data), data); + ode_verify_smi_read ( + IOLINK_ARG_BLOCK_ID_OD_RD, + IOLINK_ARG_BLOCK_ID_OD_RD, + sizeof (arg_block_od_t) + sizeof (data), + data); EXPECT_EQ (mock_iolink_smi_cnf_cnt, 1); EXPECT_EQ (mock_iolink_smi_joberror_cnt, 5); EXPECT_EQ (mock_iolink_al_read_req_cnt, 1); @@ -968,10 +1069,13 @@ TEST_F (ODETest, Ode_ParamWriteBatch_inactive) EXPECT_EQ (ODE_STATE_Inactive, ode_get_state (port)); - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_ParamWriteBatch_req (portnumber, - IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - sizeof(arg_block_t), &arg_block)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_ParamWriteBatch_req ( + portnumber, + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + sizeof (arg_block_t), + &arg_block)); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (ODE_STATE_Inactive, ode_get_state (port)); @@ -980,9 +1084,10 @@ TEST_F (ODETest, Ode_ParamWriteBatch_inactive) EXPECT_EQ (mock_iolink_al_read_req_cnt, 0); EXPECT_EQ (mock_iolink_al_write_req_cnt, 0); - ode_verify_smi_err (IOLINK_ARG_BLOCK_ID_DEV_PAR_BAT, - IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - IOLINK_SMI_ERRORTYPE_SERVICE_NOT_SUPPORTED); + ode_verify_smi_err ( + IOLINK_ARG_BLOCK_ID_DEV_PAR_BAT, + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + IOLINK_SMI_ERRORTYPE_SERVICE_NOT_SUPPORTED); } TEST_F (ODETest, Ode_ParamWriteBatch_not_supported) @@ -993,10 +1098,13 @@ TEST_F (ODETest, Ode_ParamWriteBatch_not_supported) ode_start (port); - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_ParamWriteBatch_req (portnumber, - IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - sizeof(arg_block_t), &arg_block)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_ParamWriteBatch_req ( + portnumber, + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + sizeof (arg_block_t), + &arg_block)); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (ODE_STATE_ODactive, ode_get_state (port)); @@ -1005,9 +1113,10 @@ TEST_F (ODETest, Ode_ParamWriteBatch_not_supported) EXPECT_EQ (mock_iolink_al_read_req_cnt, 0); EXPECT_EQ (mock_iolink_al_write_req_cnt, 0); - ode_verify_smi_err (IOLINK_ARG_BLOCK_ID_DEV_PAR_BAT, - IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - IOLINK_SMI_ERRORTYPE_SERVICE_NOT_SUPPORTED); + ode_verify_smi_err ( + IOLINK_ARG_BLOCK_ID_DEV_PAR_BAT, + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + IOLINK_SMI_ERRORTYPE_SERVICE_NOT_SUPPORTED); } TEST_F (ODETest, Ode_ParamWriteBatch_busy) @@ -1017,28 +1126,30 @@ TEST_F (ODETest, Ode_ParamWriteBatch_busy) arg_block_od_t * arg_block_od_first = NULL; arg_block_t arg_block_readbatch; - uint8_t data[1] = {0x65}; - uint16_t index = 8; + uint8_t data[1] = {0x65}; + uint16_t index = 8; uint8_t subindex = 0; - arg_block_od_first = ode_create_ArgBlock_od (sizeof(data)); + arg_block_od_first = ode_create_ArgBlock_od (sizeof (data)); ASSERT_TRUE (arg_block_od_first); arg_block_od_first->arg_block_id = IOLINK_ARG_BLOCK_ID_OD_RD; - arg_block_od_first->index = index; - arg_block_od_first->subindex = subindex; - arg_block_od_first->data[0] = 2; + arg_block_od_first->index = index; + arg_block_od_first->subindex = subindex; + arg_block_od_first->data[0] = 2; - arg_block_readbatch.void_block.arg_block_id = - IOLINK_ARG_BLOCK_ID_DEV_PAR_BAT; + arg_block_readbatch.void_block.arg_block_id = IOLINK_ARG_BLOCK_ID_DEV_PAR_BAT; ode_start (port); EXPECT_EQ (mock_iolink_al_read_req_cnt, 0); - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_DeviceRead_req (portnumber, IOLINK_ARG_BLOCK_ID_OD_RD, - sizeof(arg_block_od_t) + sizeof(data), - (arg_block_t *)arg_block_od_first)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_DeviceRead_req ( + portnumber, + IOLINK_ARG_BLOCK_ID_OD_RD, + sizeof (arg_block_od_t) + sizeof (data), + (arg_block_t *)arg_block_od_first)); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (ODE_STATE_ODblocked, ode_get_state (port)); EXPECT_EQ (mock_iolink_al_read_req_cnt, 1); @@ -1048,26 +1159,31 @@ TEST_F (ODETest, Ode_ParamWriteBatch_busy) for (i = 0; i < 5; i++) { /* ODE is now busy, waiting for AL_Read_cnf() */ - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_ParamWriteBatch_req (portnumber, - IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - sizeof(arg_block_t), - &arg_block_readbatch)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_ParamWriteBatch_req ( + portnumber, + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + sizeof (arg_block_t), + &arg_block_readbatch)); mock_iolink_job.callback (&mock_iolink_job); /* Verify JOB_ERROR */ EXPECT_EQ (mock_iolink_smi_cnf_cnt, 0); EXPECT_EQ (mock_iolink_smi_joberror_cnt, 1 + i); - ode_verify_smi_err (IOLINK_ARG_BLOCK_ID_DEV_PAR_BAT, - IOLINK_ARG_BLOCK_ID_VOID_BLOCK, - IOLINK_SMI_ERRORTYPE_SERVICE_NOT_SUPPORTED); + ode_verify_smi_err ( + IOLINK_ARG_BLOCK_ID_DEV_PAR_BAT, + IOLINK_ARG_BLOCK_ID_VOID_BLOCK, + IOLINK_SMI_ERRORTYPE_SERVICE_NOT_SUPPORTED); } - mock_iolink_al_read_cnf_cb (port, sizeof(data), data, - IOLINK_SMI_ERRORTYPE_NONE); + mock_iolink_al_read_cnf_cb (port, sizeof (data), data, IOLINK_SMI_ERRORTYPE_NONE); mock_iolink_job.callback (&mock_iolink_job); - ode_verify_smi_read (IOLINK_ARG_BLOCK_ID_OD_RD, IOLINK_ARG_BLOCK_ID_OD_RD, - sizeof(arg_block_od_t) + sizeof(data), data); + ode_verify_smi_read ( + IOLINK_ARG_BLOCK_ID_OD_RD, + IOLINK_ARG_BLOCK_ID_OD_RD, + sizeof (arg_block_od_t) + sizeof (data), + data); EXPECT_EQ (mock_iolink_smi_cnf_cnt, 1); EXPECT_EQ (mock_iolink_smi_joberror_cnt, 5); EXPECT_EQ (mock_iolink_al_write_req_cnt, 0); diff --git a/test/test_pde.cpp b/test/test_pde.cpp index 463ed8e..73e5bb6 100644 --- a/test/test_pde.cpp +++ b/test/test_pde.cpp @@ -22,9 +22,10 @@ class PDETest : public TestBase { -protected: + protected: // Override default setup - virtual void SetUp() { + virtual void SetUp() + { TestBase::SetUp(); // Re-use default setup }; }; @@ -36,23 +37,24 @@ static inline iolink_pde_state_t pde_get_state (iolink_port_t * port) return pde->state; } -static inline void pde_verify_smi_err (iolink_arg_block_id_t exp_smi_ref_arg_id, - iolink_arg_block_id_t exp_smi_exp_arg_id, - iolink_smi_errortypes_t exp_errortype, - uint8_t exp_smi_cnf_cnt, - uint8_t exp_smi_joberror_cnt) +static inline void pde_verify_smi_err ( + iolink_arg_block_id_t exp_smi_ref_arg_id, + iolink_arg_block_id_t exp_smi_exp_arg_id, + iolink_smi_errortypes_t exp_errortype, + uint8_t exp_smi_cnf_cnt, + uint8_t exp_smi_joberror_cnt) { EXPECT_EQ (exp_smi_cnf_cnt, mock_iolink_smi_cnf_cnt); EXPECT_EQ (exp_smi_joberror_cnt, mock_iolink_smi_joberror_cnt); EXPECT_EQ (exp_smi_ref_arg_id, mock_iolink_smi_ref_arg_block_id); iolink_arg_block_id_t arg_block_id = - mock_iolink_smi_arg_block->void_block.arg_block_id; + mock_iolink_smi_arg_block->void_block.arg_block_id; EXPECT_EQ (IOLINK_ARG_BLOCK_ID_JOB_ERROR, arg_block_id); arg_block_joberror_t * job_error = - (arg_block_joberror_t*)mock_iolink_smi_arg_block; + (arg_block_joberror_t *)mock_iolink_smi_arg_block; - iolink_smi_errortypes_t error = job_error->error; + iolink_smi_errortypes_t error = job_error->error; iolink_arg_block_id_t exp_arg_block_id = job_error->exp_arg_block_id; EXPECT_EQ (exp_errortype, error); @@ -91,66 +93,80 @@ TEST_F (PDETest, pde_start_stop) TEST_F (PDETest, pde_PDIn_inactive) { iolink_arg_block_id_t ref_arg_block_id = IOLINK_ARG_BLOCK_ID_VOID_BLOCK; - iolink_arg_block_id_t exp_exp_arg_block_id = IOLINK_ARG_BLOCK_ID_FS_MASTER_ACCESS; + iolink_arg_block_id_t exp_exp_arg_block_id = + IOLINK_ARG_BLOCK_ID_FS_MASTER_ACCESS; arg_block_void_t arg_block_void; uint8_t exp_joberror_cnt = mock_iolink_smi_joberror_cnt + 1; - memset (&arg_block_void, 0, sizeof(arg_block_void_t)); + memset (&arg_block_void, 0, sizeof (arg_block_void_t)); arg_block_void.arg_block_id = ref_arg_block_id; - EXPECT_EQ (IOLINK_ERROR_PARAMETER_CONFLICT, - SMI_PDIn_req (portnumber, exp_exp_arg_block_id, - sizeof(arg_block_void_t), - (arg_block_t *)&arg_block_void)); + EXPECT_EQ ( + IOLINK_ERROR_PARAMETER_CONFLICT, + SMI_PDIn_req ( + portnumber, + exp_exp_arg_block_id, + sizeof (arg_block_void_t), + (arg_block_t *)&arg_block_void)); EXPECT_EQ (PD_STATE_Inactive, pde_get_state (port)); - pde_verify_smi_err (ref_arg_block_id, exp_exp_arg_block_id, - IOLINK_SMI_ERRORTYPE_ARGBLOCK_INCONSISTENT, - 0, exp_joberror_cnt); + pde_verify_smi_err ( + ref_arg_block_id, + exp_exp_arg_block_id, + IOLINK_SMI_ERRORTYPE_ARGBLOCK_INCONSISTENT, + 0, + exp_joberror_cnt); } TEST_F (PDETest, pde_PDOut_inactive) { - iolink_arg_block_id_t ref_arg_block_id = IOLINK_ARG_BLOCK_ID_PD_OUT; + iolink_arg_block_id_t ref_arg_block_id = IOLINK_ARG_BLOCK_ID_PD_OUT; iolink_arg_block_id_t exp_exp_arg_block_id = IOLINK_ARG_BLOCK_ID_VOID_BLOCK; arg_block_pdout_t arg_block_pdout; uint8_t exp_joberror_cnt = mock_iolink_smi_joberror_cnt + 1; - memset (&arg_block_pdout, 0, sizeof(arg_block_pdout_head_t) + 1); + memset (&arg_block_pdout, 0, sizeof (arg_block_pdout_head_t) + 1); arg_block_pdout.h.arg_block_id = ref_arg_block_id; - EXPECT_EQ (IOLINK_ERROR_STATE_INVALID, - SMI_PDOut_req (portnumber, exp_exp_arg_block_id, - sizeof(arg_block_pdout_head_t) + 1, - (arg_block_t *)&arg_block_pdout)); + EXPECT_EQ ( + IOLINK_ERROR_STATE_INVALID, + SMI_PDOut_req ( + portnumber, + exp_exp_arg_block_id, + sizeof (arg_block_pdout_head_t) + 1, + (arg_block_t *)&arg_block_pdout)); EXPECT_EQ (PD_STATE_Inactive, pde_get_state (port)); - pde_verify_smi_err (ref_arg_block_id, exp_exp_arg_block_id, - IOLINK_SMI_ERRORTYPE_DEV_NOT_IN_OPERATE, - 0, exp_joberror_cnt); + pde_verify_smi_err ( + ref_arg_block_id, + exp_exp_arg_block_id, + IOLINK_SMI_ERRORTYPE_DEV_NOT_IN_OPERATE, + 0, + exp_joberror_cnt); } -static inline void pde_verify_smi_in (iolink_arg_block_id_t exp_smi_ref_arg_id, - iolink_arg_block_id_t exp_smi_arg_id, - iolink_port_qualifier_info_t exp_port_qualifier_info, - uint8_t exp_len, uint8_t * exp_data, - uint8_t exp_data_len) +static inline void pde_verify_smi_in ( + iolink_arg_block_id_t exp_smi_ref_arg_id, + iolink_arg_block_id_t exp_smi_arg_id, + iolink_port_qualifier_info_t exp_port_qualifier_info, + uint8_t exp_len, + uint8_t * exp_data, + uint8_t exp_data_len) { EXPECT_EQ (exp_smi_ref_arg_id, mock_iolink_smi_ref_arg_block_id); iolink_arg_block_id_t arg_block_id = - mock_iolink_smi_arg_block->void_block.arg_block_id; + mock_iolink_smi_arg_block->void_block.arg_block_id; EXPECT_EQ (exp_smi_arg_id, arg_block_id); EXPECT_EQ (exp_len, mock_iolink_smi_arg_block_len); if (exp_smi_arg_id == IOLINK_ARG_BLOCK_ID_PD_IN) { arg_block_pdin_t * arg_block_pdin = - (arg_block_pdin_t *)mock_iolink_smi_arg_block; + (arg_block_pdin_t *)mock_iolink_smi_arg_block; - EXPECT_EQ (exp_port_qualifier_info, - arg_block_pdin->h.port_qualifier_info); + EXPECT_EQ (exp_port_qualifier_info, arg_block_pdin->h.port_qualifier_info); EXPECT_EQ (exp_data_len, arg_block_pdin->h.len); EXPECT_TRUE (ArraysMatchN (exp_data, arg_block_pdin->data, exp_data_len)); } @@ -160,19 +176,20 @@ static inline void pde_verify_smi_in (iolink_arg_block_id_t exp_smi_ref_arg_id, } } -static inline void pde_verify_smi_out (iolink_arg_block_id_t exp_smi_ref_arg_id, - iolink_arg_block_id_t exp_smi_arg_id, - uint8_t exp_len) +static inline void pde_verify_smi_out ( + iolink_arg_block_id_t exp_smi_ref_arg_id, + iolink_arg_block_id_t exp_smi_arg_id, + uint8_t exp_len) { EXPECT_EQ (exp_smi_ref_arg_id, mock_iolink_smi_ref_arg_block_id); iolink_arg_block_id_t arg_block_id = - mock_iolink_smi_arg_block->void_block.arg_block_id; + mock_iolink_smi_arg_block->void_block.arg_block_id; EXPECT_EQ (exp_smi_arg_id, arg_block_id); EXPECT_EQ (exp_len, mock_iolink_smi_arg_block_len); } static uint8_t iolink_arg_block_pdinout_pdin_data_len ( - const arg_block_pdinout_t * arg_block) + const arg_block_pdinout_t * arg_block) { return arg_block->data[0]; } @@ -184,42 +201,39 @@ static uint8_t * iolink_arg_block_pdinout_pdin_data (arg_block_pdinout_t * arg_b uint8_t * iolink_arg_block_pdinout_pdout_data (arg_block_pdinout_t * arg_block) { - return &arg_block-> - data[2 + iolink_arg_block_pdinout_pdin_data_len (arg_block)]; + return &arg_block->data[2 + iolink_arg_block_pdinout_pdin_data_len (arg_block)]; } static inline void pde_verify_smi_in_out ( - iolink_arg_block_id_t exp_smi_ref_arg_id, - iolink_arg_block_id_t exp_smi_arg_id, - iolink_port_qualifier_info_t exp_port_qualifier_info, - uint8_t exp_oe, - uint8_t exp_arg_block_len, - uint8_t * exp_pdin_data, - uint8_t exp_pdin_data_len, - uint8_t * exp_pdout_data, - uint8_t exp_pdout_data_len) + iolink_arg_block_id_t exp_smi_ref_arg_id, + iolink_arg_block_id_t exp_smi_arg_id, + iolink_port_qualifier_info_t exp_port_qualifier_info, + uint8_t exp_oe, + uint8_t exp_arg_block_len, + uint8_t * exp_pdin_data, + uint8_t exp_pdin_data_len, + uint8_t * exp_pdout_data, + uint8_t exp_pdout_data_len) { EXPECT_EQ (exp_smi_ref_arg_id, mock_iolink_smi_ref_arg_block_id); iolink_arg_block_id_t arg_block_id = - mock_iolink_smi_arg_block->void_block.arg_block_id; + mock_iolink_smi_arg_block->void_block.arg_block_id; EXPECT_EQ (exp_smi_arg_id, arg_block_id); if (exp_smi_arg_id == IOLINK_ARG_BLOCK_ID_PD_IN_OUT) { arg_block_pdinout_t * arg_block_pdinout = - (arg_block_pdinout_t *)mock_iolink_smi_arg_block; + (arg_block_pdinout_t *)mock_iolink_smi_arg_block; uint8_t pdin_data_len = - iolink_arg_block_pdinout_pdin_data_len (arg_block_pdinout); + iolink_arg_block_pdinout_pdin_data_len (arg_block_pdinout); uint8_t * pdin_data = - iolink_arg_block_pdinout_pdin_data (arg_block_pdinout); + iolink_arg_block_pdinout_pdin_data (arg_block_pdinout); - EXPECT_EQ (exp_port_qualifier_info, - arg_block_pdinout->h.port_qualifier_info); + EXPECT_EQ (exp_port_qualifier_info, arg_block_pdinout->h.port_qualifier_info); EXPECT_EQ (exp_oe, arg_block_pdinout->h.oe); EXPECT_EQ (exp_pdin_data_len, pdin_data_len); - EXPECT_TRUE (ArraysMatchN (exp_pdin_data, pdin_data, - exp_pdin_data_len)); + EXPECT_TRUE (ArraysMatchN (exp_pdin_data, pdin_data, exp_pdin_data_len)); } else { @@ -227,17 +241,20 @@ static inline void pde_verify_smi_in_out ( } } -static void pde_smi_pdout (iolink_port_t * port, uint8_t oe, uint8_t data_len, - uint8_t * data) +static void pde_smi_pdout ( + iolink_port_t * port, + uint8_t oe, + uint8_t data_len, + uint8_t * data) { iolink_pde_port_t * pde = iolink_get_pde_ctx (port); - iolink_arg_block_id_t ref_arg_block_id = IOLINK_ARG_BLOCK_ID_PD_OUT; + iolink_arg_block_id_t ref_arg_block_id = IOLINK_ARG_BLOCK_ID_PD_OUT; iolink_arg_block_id_t exp_exp_arg_block_id = IOLINK_ARG_BLOCK_ID_VOID_BLOCK; - uint8_t exp_data_len = data_len; - uint8_t arg_block_len = sizeof(arg_block_pdout_head_t) + exp_data_len; + uint8_t exp_data_len = data_len; + uint8_t arg_block_len = sizeof (arg_block_pdout_head_t) + exp_data_len; uint8_t exp_smi_cnf_cnt = mock_iolink_smi_cnf_cnt + 1; - uint8_t exp_al_control_req_cnt = mock_iolink_al_control_req_cnt; + uint8_t exp_al_control_req_cnt = mock_iolink_al_control_req_cnt; iolink_controlcode_t exp_controlcode = mock_iolink_controlcode; arg_block_pdout_t arg_block_pdout; @@ -246,28 +263,34 @@ static void pde_smi_pdout (iolink_port_t * port, uint8_t oe, uint8_t data_len, { exp_al_control_req_cnt++; if (oe & 0x1) - { + { exp_controlcode = IOLINK_CONTROLCODE_PDOUTVALID; - } + } else - { + { exp_controlcode = IOLINK_CONTROLCODE_PDOUTINVALID; - } + } } memset (&arg_block_pdout, 0, arg_block_len); arg_block_pdout.h.arg_block_id = ref_arg_block_id; memcpy (arg_block_pdout.data, data, exp_data_len); arg_block_pdout.h.len = exp_data_len; - arg_block_pdout.h.oe = oe; + arg_block_pdout.h.oe = oe; - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_PDOut_req (iolink_get_portnumber (port), exp_exp_arg_block_id, - arg_block_len, (arg_block_t *)&arg_block_pdout)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_PDOut_req ( + iolink_get_portnumber (port), + exp_exp_arg_block_id, + arg_block_len, + (arg_block_t *)&arg_block_pdout)); EXPECT_EQ (exp_smi_cnf_cnt, mock_iolink_smi_cnf_cnt); - pde_verify_smi_out (ref_arg_block_id, exp_exp_arg_block_id, - sizeof(arg_block_void_t)); + pde_verify_smi_out ( + ref_arg_block_id, + exp_exp_arg_block_id, + sizeof (arg_block_void_t)); EXPECT_EQ (oe, pde->output_enable); EXPECT_EQ (exp_controlcode, mock_iolink_controlcode); EXPECT_EQ (exp_al_control_req_cnt, mock_iolink_al_control_req_cnt); @@ -279,24 +302,23 @@ TEST_F (PDETest, pde_PDOut) pd_start (port); uint8_t output_enable = 0; - pde_smi_pdout (port, output_enable, sizeof(data), data); + pde_smi_pdout (port, output_enable, sizeof (data), data); output_enable = 1; - pde_smi_pdout (port, output_enable, sizeof(data), data); + pde_smi_pdout (port, output_enable, sizeof (data), data); data[3] = 11; - pde_smi_pdout (port, output_enable, sizeof(data), data); + pde_smi_pdout (port, output_enable, sizeof (data), data); output_enable = 0; - data[0] = 1; - pde_smi_pdout (port, output_enable, sizeof(data), data); + data[0] = 1; + pde_smi_pdout (port, output_enable, sizeof (data), data); } TEST_F (PDETest, pde_PDIn) { - iolink_arg_block_id_t ref_arg_block_id = IOLINK_ARG_BLOCK_ID_VOID_BLOCK; + iolink_arg_block_id_t ref_arg_block_id = IOLINK_ARG_BLOCK_ID_VOID_BLOCK; iolink_arg_block_id_t exp_exp_arg_block_id = IOLINK_ARG_BLOCK_ID_PD_IN; - uint8_t data[16] = { 1, 3, 7, 2, 5, 4, 9, 6, - 8, 11, 19, 17, 12, 7, 12, 2 }; - uint8_t exp_data_len = sizeof(data); - uint8_t exp_smi_cnf_cnt = mock_iolink_smi_cnf_cnt; + uint8_t data[16] = {1, 3, 7, 2, 5, 4, 9, 6, 8, 11, 19, 17, 12, 7, 12, 2}; + uint8_t exp_data_len = sizeof (data); + uint8_t exp_smi_cnf_cnt = mock_iolink_smi_cnf_cnt; uint8_t exp_al_getinput_req_cnt = mock_iolink_al_getinput_req_cnt; arg_block_void_t arg_block_void; @@ -306,50 +328,60 @@ TEST_F (PDETest, pde_PDIn) pd_start (port); arg_block_void.arg_block_id = ref_arg_block_id; - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_PDIn_req (portnumber, exp_exp_arg_block_id, - sizeof(arg_block_void_t), - (arg_block_t *)&arg_block_void)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_PDIn_req ( + portnumber, + exp_exp_arg_block_id, + sizeof (arg_block_void_t), + (arg_block_t *)&arg_block_void)); exp_al_getinput_req_cnt++; exp_smi_cnf_cnt++; EXPECT_EQ (exp_al_getinput_req_cnt, mock_iolink_al_getinput_req_cnt); EXPECT_EQ (exp_smi_cnf_cnt, mock_iolink_smi_cnf_cnt); - pde_verify_smi_in (ref_arg_block_id, exp_exp_arg_block_id, - IOLINK_PORT_QUALIFIER_INFO_PQ_INVALID, - sizeof(arg_block_pdin_head_t) + exp_data_len, - data, exp_data_len); + pde_verify_smi_in ( + ref_arg_block_id, + exp_exp_arg_block_id, + IOLINK_PORT_QUALIFIER_INFO_PQ_INVALID, + sizeof (arg_block_pdin_head_t) + exp_data_len, + data, + exp_data_len); data[0] = 3; data[1] = 5; memcpy (mock_iolink_dl_pdin_data, data, exp_data_len); - EXPECT_EQ (IOLINK_ERROR_NONE, - AL_Control_ind (port, IOLINK_CONTROLCODE_VALID)); - - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_PDIn_req (portnumber, exp_exp_arg_block_id, - sizeof(arg_block_void_t), - (arg_block_t *)&arg_block_void)); + EXPECT_EQ (IOLINK_ERROR_NONE, AL_Control_ind (port, IOLINK_CONTROLCODE_VALID)); + + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_PDIn_req ( + portnumber, + exp_exp_arg_block_id, + sizeof (arg_block_void_t), + (arg_block_t *)&arg_block_void)); exp_al_getinput_req_cnt++; exp_smi_cnf_cnt++; EXPECT_EQ (exp_al_getinput_req_cnt, mock_iolink_al_getinput_req_cnt); EXPECT_EQ (exp_smi_cnf_cnt, mock_iolink_smi_cnf_cnt); - pde_verify_smi_in (ref_arg_block_id, exp_exp_arg_block_id, - IOLINK_PORT_QUALIFIER_INFO_PQ_VALID, - sizeof(arg_block_pdin_head_t) + exp_data_len, - data, exp_data_len); + pde_verify_smi_in ( + ref_arg_block_id, + exp_exp_arg_block_id, + IOLINK_PORT_QUALIFIER_INFO_PQ_VALID, + sizeof (arg_block_pdin_head_t) + exp_data_len, + data, + exp_data_len); } TEST_F (PDETest, pde_PDInOut) { - iolink_arg_block_id_t ref_arg_block_id = IOLINK_ARG_BLOCK_ID_VOID_BLOCK; + iolink_arg_block_id_t ref_arg_block_id = IOLINK_ARG_BLOCK_ID_VOID_BLOCK; iolink_arg_block_id_t exp_exp_arg_block_id = IOLINK_ARG_BLOCK_ID_PD_IN_OUT; - uint8_t exp_output_enable = 0; - uint8_t pdout_data[3] = { 66, 77, 88 }; - uint8_t exp_pdout_data_len = sizeof(pdout_data); - uint8_t pdin_data[16] = { 1, 3, 7, 2, 5, 4, 9, 6, - 8, 11, 19, 17, 12, 7, 12, 2 }; - uint8_t exp_pdin_data_len = sizeof(pdin_data); - uint8_t exp_smi_cnf_cnt = mock_iolink_smi_cnf_cnt; + uint8_t exp_output_enable = 0; + uint8_t pdout_data[3] = {66, 77, 88}; + uint8_t exp_pdout_data_len = sizeof (pdout_data); + uint8_t pdin_data[16] = {1, 3, 7, 2, 5, 4, 9, 6, 8, 11, 19, 17, 12, 7, 12, 2}; + uint8_t exp_pdin_data_len = sizeof (pdin_data); + uint8_t exp_smi_cnf_cnt = mock_iolink_smi_cnf_cnt; uint8_t exp_al_getinputoutput_req_cnt = mock_iolink_al_getinputoutput_req_cnt; arg_block_void_t arg_block_void; @@ -358,52 +390,64 @@ TEST_F (PDETest, pde_PDInOut) pd_start (port); - EXPECT_EQ (IOLINK_ERROR_NONE, - AL_Control_ind (port, IOLINK_CONTROLCODE_VALID)); + EXPECT_EQ (IOLINK_ERROR_NONE, AL_Control_ind (port, IOLINK_CONTROLCODE_VALID)); arg_block_void.arg_block_id = ref_arg_block_id; - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_PDInOut_req (portnumber, exp_exp_arg_block_id, - sizeof(arg_block_void_t), - (arg_block_t *)&arg_block_void)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_PDInOut_req ( + portnumber, + exp_exp_arg_block_id, + sizeof (arg_block_void_t), + (arg_block_t *)&arg_block_void)); exp_al_getinputoutput_req_cnt++; exp_smi_cnf_cnt++; EXPECT_EQ (exp_al_getinputoutput_req_cnt, mock_iolink_al_getinputoutput_req_cnt); EXPECT_EQ (exp_smi_cnf_cnt, mock_iolink_smi_cnf_cnt); - pde_verify_smi_in_out (ref_arg_block_id, exp_exp_arg_block_id, - IOLINK_PORT_QUALIFIER_INFO_PQ_VALID, - exp_output_enable, - sizeof(arg_block_pdinout_head_t) + - 1 + exp_pdin_data_len + 1, - pdin_data, exp_pdin_data_len, - NULL, 0); + pde_verify_smi_in_out ( + ref_arg_block_id, + exp_exp_arg_block_id, + IOLINK_PORT_QUALIFIER_INFO_PQ_VALID, + exp_output_enable, + sizeof (arg_block_pdinout_head_t) + 1 + exp_pdin_data_len + 1, + pdin_data, + exp_pdin_data_len, + NULL, + 0); exp_output_enable = 1; pde_smi_pdout (port, exp_output_enable, exp_pdout_data_len, pdout_data); exp_smi_cnf_cnt++; - pdin_data[2] = 0; - pdin_data[5] = 42; + pdin_data[2] = 0; + pdin_data[5] = 42; pdin_data[15] = 111; memcpy (mock_iolink_dl_pdin_data, pdin_data, exp_pdin_data_len); - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_PDInOut_req (portnumber, exp_exp_arg_block_id, - sizeof(arg_block_void_t), - (arg_block_t *)&arg_block_void)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_PDInOut_req ( + portnumber, + exp_exp_arg_block_id, + sizeof (arg_block_void_t), + (arg_block_t *)&arg_block_void)); exp_al_getinputoutput_req_cnt++; exp_smi_cnf_cnt++; EXPECT_EQ (exp_al_getinputoutput_req_cnt, mock_iolink_al_getinputoutput_req_cnt); EXPECT_EQ (exp_smi_cnf_cnt, mock_iolink_smi_cnf_cnt); - pde_verify_smi_in_out (ref_arg_block_id, exp_exp_arg_block_id, - IOLINK_PORT_QUALIFIER_INFO_PQ_VALID, - exp_output_enable, - sizeof(arg_block_pdinout_head_t) + - 1 + exp_pdin_data_len + 1 + exp_pdout_data_len, - pdin_data, exp_pdin_data_len, pdout_data, - exp_pdout_data_len); + pde_verify_smi_in_out ( + ref_arg_block_id, + exp_exp_arg_block_id, + IOLINK_PORT_QUALIFIER_INFO_PQ_VALID, + exp_output_enable, + sizeof (arg_block_pdinout_head_t) + 1 + exp_pdin_data_len + 1 + + exp_pdout_data_len, + pdin_data, + exp_pdin_data_len, + pdout_data, + exp_pdout_data_len); exp_output_enable = 0; exp_pdout_data_len--; @@ -412,52 +456,65 @@ TEST_F (PDETest, pde_PDInOut) pde_smi_pdout (port, exp_output_enable, exp_pdout_data_len, pdout_data); exp_smi_cnf_cnt++; - pdin_data[2] = 99; - pdin_data[5] = 100; + pdin_data[2] = 99; + pdin_data[5] = 100; pdin_data[15] = 101; memcpy (mock_iolink_dl_pdin_data, pdin_data, exp_pdin_data_len); - EXPECT_EQ (IOLINK_ERROR_NONE, - SMI_PDInOut_req (portnumber, exp_exp_arg_block_id, - sizeof(arg_block_void_t), - (arg_block_t *)&arg_block_void)); + EXPECT_EQ ( + IOLINK_ERROR_NONE, + SMI_PDInOut_req ( + portnumber, + exp_exp_arg_block_id, + sizeof (arg_block_void_t), + (arg_block_t *)&arg_block_void)); exp_al_getinputoutput_req_cnt++; exp_smi_cnf_cnt++; EXPECT_EQ (exp_al_getinputoutput_req_cnt, mock_iolink_al_getinputoutput_req_cnt); EXPECT_EQ (exp_smi_cnf_cnt, mock_iolink_smi_cnf_cnt); - pde_verify_smi_in_out (ref_arg_block_id, exp_exp_arg_block_id, - IOLINK_PORT_QUALIFIER_INFO_PQ_VALID, - exp_output_enable, - sizeof(arg_block_pdinout_head_t) + - 1 + exp_pdin_data_len + 1 + exp_pdout_data_len, - pdin_data, exp_pdin_data_len, pdout_data, - exp_pdout_data_len); + pde_verify_smi_in_out ( + ref_arg_block_id, + exp_exp_arg_block_id, + IOLINK_PORT_QUALIFIER_INFO_PQ_VALID, + exp_output_enable, + sizeof (arg_block_pdinout_head_t) + 1 + exp_pdin_data_len + 1 + + exp_pdout_data_len, + pdin_data, + exp_pdin_data_len, + pdout_data, + exp_pdout_data_len); } TEST_F (PDETest, pde_PDInOut_inactive) { - iolink_arg_block_id_t ref_arg_block_id = IOLINK_ARG_BLOCK_ID_VOID_BLOCK; + iolink_arg_block_id_t ref_arg_block_id = IOLINK_ARG_BLOCK_ID_VOID_BLOCK; iolink_arg_block_id_t exp_exp_arg_block_id = IOLINK_ARG_BLOCK_ID_PD_IN_OUT; arg_block_void_t arg_block_void; uint8_t exp_joberror_cnt = mock_iolink_smi_joberror_cnt + 1; - memset (&arg_block_void, 0, sizeof(arg_block_void_t)); + memset (&arg_block_void, 0, sizeof (arg_block_void_t)); arg_block_void.arg_block_id = ref_arg_block_id; - EXPECT_EQ (IOLINK_ERROR_STATE_INVALID, - SMI_PDInOut_req (portnumber, exp_exp_arg_block_id, - sizeof(arg_block_void_t), - (arg_block_t *)&arg_block_void)); + EXPECT_EQ ( + IOLINK_ERROR_STATE_INVALID, + SMI_PDInOut_req ( + portnumber, + exp_exp_arg_block_id, + sizeof (arg_block_void_t), + (arg_block_t *)&arg_block_void)); EXPECT_EQ (PD_STATE_Inactive, pde_get_state (port)); - pde_verify_smi_err (ref_arg_block_id, exp_exp_arg_block_id, - IOLINK_SMI_ERRORTYPE_DEV_NOT_IN_OPERATE, - 0, exp_joberror_cnt); + pde_verify_smi_err ( + ref_arg_block_id, + exp_exp_arg_block_id, + IOLINK_SMI_ERRORTYPE_DEV_NOT_IN_OPERATE, + 0, + exp_joberror_cnt); } TEST_F (PDETest, pde_PDIn_bad_argblock) { - iolink_arg_block_id_t bad_arg_block_id = IOLINK_ARG_BLOCK_ID_MASTERIDENT; + iolink_arg_block_id_t bad_arg_block_id = IOLINK_ARG_BLOCK_ID_MASTERIDENT; iolink_arg_block_id_t exp_exp_arg_block_id = IOLINK_ARG_BLOCK_ID_PD_IN; arg_block_void_t arg_block_void; @@ -465,24 +522,30 @@ TEST_F (PDETest, pde_PDIn_bad_argblock) pd_start (port); - memset (&arg_block_void, 0, sizeof(arg_block_void_t)); + memset (&arg_block_void, 0, sizeof (arg_block_void_t)); /* Bad argblock type */ arg_block_void.arg_block_id = bad_arg_block_id; - EXPECT_EQ (IOLINK_ERROR_PARAMETER_CONFLICT, - SMI_PDIn_req (portnumber, exp_exp_arg_block_id, - sizeof(arg_block_void_t), - (arg_block_t *)&arg_block_void)); + EXPECT_EQ ( + IOLINK_ERROR_PARAMETER_CONFLICT, + SMI_PDIn_req ( + portnumber, + exp_exp_arg_block_id, + sizeof (arg_block_void_t), + (arg_block_t *)&arg_block_void)); EXPECT_EQ (PD_STATE_PDactive, pde_get_state (port)); - pde_verify_smi_err (bad_arg_block_id, exp_exp_arg_block_id, - IOLINK_SMI_ERRORTYPE_ARGBLOCK_NOT_SUPPORTED, - 0, exp_joberror_cnt); + pde_verify_smi_err ( + bad_arg_block_id, + exp_exp_arg_block_id, + IOLINK_SMI_ERRORTYPE_ARGBLOCK_NOT_SUPPORTED, + 0, + exp_joberror_cnt); } TEST_F (PDETest, pde_PDOut_bad_argblock) { - iolink_arg_block_id_t bad_arg_block_id = IOLINK_ARG_BLOCK_ID_MASTERIDENT; + iolink_arg_block_id_t bad_arg_block_id = IOLINK_ARG_BLOCK_ID_MASTERIDENT; iolink_arg_block_id_t exp_exp_arg_block_id = IOLINK_ARG_BLOCK_ID_VOID_BLOCK; arg_block_pdout_t arg_block_pdout; @@ -490,24 +553,30 @@ TEST_F (PDETest, pde_PDOut_bad_argblock) pd_start (port); - memset (&arg_block_pdout, 0, sizeof(arg_block_pdout_head_t)); + memset (&arg_block_pdout, 0, sizeof (arg_block_pdout_head_t)); /* Bad argblock type */ arg_block_pdout.h.arg_block_id = bad_arg_block_id; - EXPECT_EQ (IOLINK_ERROR_PARAMETER_CONFLICT, - SMI_PDOut_req (portnumber, exp_exp_arg_block_id, - sizeof(arg_block_pdout_head_t), - (arg_block_t *)&arg_block_pdout)); + EXPECT_EQ ( + IOLINK_ERROR_PARAMETER_CONFLICT, + SMI_PDOut_req ( + portnumber, + exp_exp_arg_block_id, + sizeof (arg_block_pdout_head_t), + (arg_block_t *)&arg_block_pdout)); EXPECT_EQ (PD_STATE_PDactive, pde_get_state (port)); - pde_verify_smi_err (bad_arg_block_id, exp_exp_arg_block_id, - IOLINK_SMI_ERRORTYPE_ARGBLOCK_NOT_SUPPORTED, - 0, exp_joberror_cnt); + pde_verify_smi_err ( + bad_arg_block_id, + exp_exp_arg_block_id, + IOLINK_SMI_ERRORTYPE_ARGBLOCK_NOT_SUPPORTED, + 0, + exp_joberror_cnt); } TEST_F (PDETest, pde_PDInOut_bad_argblock) { - iolink_arg_block_id_t bad_arg_block_id = IOLINK_ARG_BLOCK_ID_MASTERIDENT; + iolink_arg_block_id_t bad_arg_block_id = IOLINK_ARG_BLOCK_ID_MASTERIDENT; iolink_arg_block_id_t exp_exp_arg_block_id = IOLINK_ARG_BLOCK_ID_PD_IN_OUT; arg_block_void_t arg_block_void; @@ -515,24 +584,30 @@ TEST_F (PDETest, pde_PDInOut_bad_argblock) pd_start (port); - memset (&arg_block_void, 0, sizeof(arg_block_void_t)); + memset (&arg_block_void, 0, sizeof (arg_block_void_t)); /* Bad argblock type */ arg_block_void.arg_block_id = bad_arg_block_id; - EXPECT_EQ (IOLINK_ERROR_PARAMETER_CONFLICT, - SMI_PDInOut_req (portnumber, exp_exp_arg_block_id, - sizeof(arg_block_void_t), - (arg_block_t *)&arg_block_void)); + EXPECT_EQ ( + IOLINK_ERROR_PARAMETER_CONFLICT, + SMI_PDInOut_req ( + portnumber, + exp_exp_arg_block_id, + sizeof (arg_block_void_t), + (arg_block_t *)&arg_block_void)); EXPECT_EQ (PD_STATE_PDactive, pde_get_state (port)); - pde_verify_smi_err (bad_arg_block_id, exp_exp_arg_block_id, - IOLINK_SMI_ERRORTYPE_ARGBLOCK_NOT_SUPPORTED, - 0, exp_joberror_cnt); + pde_verify_smi_err ( + bad_arg_block_id, + exp_exp_arg_block_id, + IOLINK_SMI_ERRORTYPE_ARGBLOCK_NOT_SUPPORTED, + 0, + exp_joberror_cnt); } TEST_F (PDETest, pde_PDIn_bad_argblock_len) { - iolink_arg_block_id_t ref_arg_block_id = IOLINK_ARG_BLOCK_ID_VOID_BLOCK; + iolink_arg_block_id_t ref_arg_block_id = IOLINK_ARG_BLOCK_ID_VOID_BLOCK; iolink_arg_block_id_t exp_exp_arg_block_id = IOLINK_ARG_BLOCK_ID_PD_IN; arg_block_void_t arg_block_void; @@ -540,37 +615,49 @@ TEST_F (PDETest, pde_PDIn_bad_argblock_len) pd_start (port); - memset (&arg_block_void, 0, sizeof(arg_block_void_t)); + memset (&arg_block_void, 0, sizeof (arg_block_void_t)); arg_block_void.arg_block_id = ref_arg_block_id; - EXPECT_EQ (IOLINK_ERROR_PARAMETER_CONFLICT, - SMI_PDIn_req (portnumber, exp_exp_arg_block_id, - /* Bad ArgBlockLength */ - sizeof(arg_block_void_t) + 1, - (arg_block_t *)&arg_block_void)); + EXPECT_EQ ( + IOLINK_ERROR_PARAMETER_CONFLICT, + SMI_PDIn_req ( + portnumber, + exp_exp_arg_block_id, + /* Bad ArgBlockLength */ + sizeof (arg_block_void_t) + 1, + (arg_block_t *)&arg_block_void)); EXPECT_EQ (PD_STATE_PDactive, pde_get_state (port)); exp_joberror_cnt++; - pde_verify_smi_err (ref_arg_block_id, exp_exp_arg_block_id, - IOLINK_SMI_ERRORTYPE_ARGBLOCK_LENGTH_INVALID, - 0, exp_joberror_cnt); - - EXPECT_EQ (IOLINK_ERROR_PARAMETER_CONFLICT, - SMI_PDIn_req (portnumber, exp_exp_arg_block_id, - /* Bad ArgBlockLength */ - sizeof(arg_block_void_t) - 1, - (arg_block_t *)&arg_block_void)); + pde_verify_smi_err ( + ref_arg_block_id, + exp_exp_arg_block_id, + IOLINK_SMI_ERRORTYPE_ARGBLOCK_LENGTH_INVALID, + 0, + exp_joberror_cnt); + + EXPECT_EQ ( + IOLINK_ERROR_PARAMETER_CONFLICT, + SMI_PDIn_req ( + portnumber, + exp_exp_arg_block_id, + /* Bad ArgBlockLength */ + sizeof (arg_block_void_t) - 1, + (arg_block_t *)&arg_block_void)); EXPECT_EQ (PD_STATE_PDactive, pde_get_state (port)); exp_joberror_cnt++; - pde_verify_smi_err (ref_arg_block_id, exp_exp_arg_block_id, - IOLINK_SMI_ERRORTYPE_ARGBLOCK_LENGTH_INVALID, - 0, exp_joberror_cnt); + pde_verify_smi_err ( + ref_arg_block_id, + exp_exp_arg_block_id, + IOLINK_SMI_ERRORTYPE_ARGBLOCK_LENGTH_INVALID, + 0, + exp_joberror_cnt); } TEST_F (PDETest, pde_PDOut_bad_argblock_len) { - iolink_arg_block_id_t ref_arg_block_id = IOLINK_ARG_BLOCK_ID_PD_OUT; + iolink_arg_block_id_t ref_arg_block_id = IOLINK_ARG_BLOCK_ID_PD_OUT; iolink_arg_block_id_t exp_exp_arg_block_id = IOLINK_ARG_BLOCK_ID_VOID_BLOCK; arg_block_pdout_t arg_block_pdout; @@ -578,37 +665,49 @@ TEST_F (PDETest, pde_PDOut_bad_argblock_len) pd_start (port); - memset (&arg_block_pdout, 0, sizeof(arg_block_pdout_t)); + memset (&arg_block_pdout, 0, sizeof (arg_block_pdout_t)); arg_block_pdout.h.arg_block_id = ref_arg_block_id; - EXPECT_EQ (IOLINK_ERROR_PARAMETER_CONFLICT, - SMI_PDOut_req (portnumber, exp_exp_arg_block_id, - /* Bad ArgBlockLength */ - sizeof(arg_block_pdout_head_t), - (arg_block_t *)&arg_block_pdout)); + EXPECT_EQ ( + IOLINK_ERROR_PARAMETER_CONFLICT, + SMI_PDOut_req ( + portnumber, + exp_exp_arg_block_id, + /* Bad ArgBlockLength */ + sizeof (arg_block_pdout_head_t), + (arg_block_t *)&arg_block_pdout)); EXPECT_EQ (PD_STATE_PDactive, pde_get_state (port)); exp_joberror_cnt++; - pde_verify_smi_err (ref_arg_block_id, exp_exp_arg_block_id, - IOLINK_SMI_ERRORTYPE_ARGBLOCK_LENGTH_INVALID, - 0, exp_joberror_cnt); - - EXPECT_EQ (IOLINK_ERROR_PARAMETER_CONFLICT, - SMI_PDOut_req (portnumber, exp_exp_arg_block_id, - /* Bad ArgBlockLength */ - sizeof(arg_block_pdout_t) + 1, - (arg_block_t *)&arg_block_pdout)); + pde_verify_smi_err ( + ref_arg_block_id, + exp_exp_arg_block_id, + IOLINK_SMI_ERRORTYPE_ARGBLOCK_LENGTH_INVALID, + 0, + exp_joberror_cnt); + + EXPECT_EQ ( + IOLINK_ERROR_PARAMETER_CONFLICT, + SMI_PDOut_req ( + portnumber, + exp_exp_arg_block_id, + /* Bad ArgBlockLength */ + sizeof (arg_block_pdout_t) + 1, + (arg_block_t *)&arg_block_pdout)); EXPECT_EQ (PD_STATE_PDactive, pde_get_state (port)); exp_joberror_cnt++; - pde_verify_smi_err (ref_arg_block_id, exp_exp_arg_block_id, - IOLINK_SMI_ERRORTYPE_ARGBLOCK_LENGTH_INVALID, - 0, exp_joberror_cnt); + pde_verify_smi_err ( + ref_arg_block_id, + exp_exp_arg_block_id, + IOLINK_SMI_ERRORTYPE_ARGBLOCK_LENGTH_INVALID, + 0, + exp_joberror_cnt); } TEST_F (PDETest, pde_PDInOut_bad_argblock_len) { - iolink_arg_block_id_t ref_arg_block_id = IOLINK_ARG_BLOCK_ID_VOID_BLOCK; + iolink_arg_block_id_t ref_arg_block_id = IOLINK_ARG_BLOCK_ID_VOID_BLOCK; iolink_arg_block_id_t exp_exp_arg_block_id = IOLINK_ARG_BLOCK_ID_PD_IN_OUT; arg_block_void_t arg_block_void; @@ -616,30 +715,42 @@ TEST_F (PDETest, pde_PDInOut_bad_argblock_len) pd_start (port); - memset (&arg_block_void, 0, sizeof(arg_block_void_t)); + memset (&arg_block_void, 0, sizeof (arg_block_void_t)); arg_block_void.arg_block_id = ref_arg_block_id; - EXPECT_EQ (IOLINK_ERROR_PARAMETER_CONFLICT, - SMI_PDInOut_req (portnumber, exp_exp_arg_block_id, - /* Bad ArgBlockLength */ - sizeof(arg_block_void_t) + 1, - (arg_block_t *)&arg_block_void)); + EXPECT_EQ ( + IOLINK_ERROR_PARAMETER_CONFLICT, + SMI_PDInOut_req ( + portnumber, + exp_exp_arg_block_id, + /* Bad ArgBlockLength */ + sizeof (arg_block_void_t) + 1, + (arg_block_t *)&arg_block_void)); EXPECT_EQ (PD_STATE_PDactive, pde_get_state (port)); exp_joberror_cnt++; - pde_verify_smi_err (ref_arg_block_id, exp_exp_arg_block_id, - IOLINK_SMI_ERRORTYPE_ARGBLOCK_LENGTH_INVALID, - 0, exp_joberror_cnt); - - EXPECT_EQ (IOLINK_ERROR_PARAMETER_CONFLICT, - SMI_PDInOut_req (portnumber, exp_exp_arg_block_id, - /* Bad ArgBlockLength */ - sizeof(arg_block_void_t) + 1, - (arg_block_t *)&arg_block_void)); + pde_verify_smi_err ( + ref_arg_block_id, + exp_exp_arg_block_id, + IOLINK_SMI_ERRORTYPE_ARGBLOCK_LENGTH_INVALID, + 0, + exp_joberror_cnt); + + EXPECT_EQ ( + IOLINK_ERROR_PARAMETER_CONFLICT, + SMI_PDInOut_req ( + portnumber, + exp_exp_arg_block_id, + /* Bad ArgBlockLength */ + sizeof (arg_block_void_t) + 1, + (arg_block_t *)&arg_block_void)); EXPECT_EQ (PD_STATE_PDactive, pde_get_state (port)); exp_joberror_cnt++; - pde_verify_smi_err (ref_arg_block_id, exp_exp_arg_block_id, - IOLINK_SMI_ERRORTYPE_ARGBLOCK_LENGTH_INVALID, - 0, exp_joberror_cnt); + pde_verify_smi_err ( + ref_arg_block_id, + exp_exp_arg_block_id, + IOLINK_SMI_ERRORTYPE_ARGBLOCK_LENGTH_INVALID, + 0, + exp_joberror_cnt); } diff --git a/test/test_sm.cpp b/test/test_sm.cpp index f08ab83..ce2cd64 100644 --- a/test/test_sm.cpp +++ b/test/test_sm.cpp @@ -25,9 +25,10 @@ class SMTest : public TestBase { -protected: + protected: // Override default setup - virtual void SetUp() { + virtual void SetUp() + { TestBase::SetUp(); // Re-use default setup }; }; @@ -77,7 +78,7 @@ void sm_trans_1_2 (iolink_port_t * port) void sm_trans_8_10 (iolink_port_t * port) { - uint8_t serialnumber [] = {0x11, 0x22, 0x33}; + uint8_t serialnumber[] = {0x11, 0x22, 0x33}; sm_trans_1_2 (port); @@ -86,8 +87,11 @@ void sm_trans_8_10 (iolink_port_t * port) mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (SM_STATE_checkSerNum, sm_get_state (port)); - mock_iolink_al_read_cnf_cb (port, sizeof(serialnumber), serialnumber, - IOLINK_SMI_ERRORTYPE_NONE); + mock_iolink_al_read_cnf_cb ( + port, + sizeof (serialnumber), + serialnumber, + IOLINK_SMI_ERRORTYPE_NONE); mock_iolink_job.callback (&mock_iolink_job); // SerNumOk T10 EXPECT_EQ (SM_STATE_wait, sm_get_state (port)); @@ -98,7 +102,7 @@ void sm_trans_8_10 (iolink_port_t * port) void sm_trans_12 (iolink_port_t * port) { uint8_t expected_write_devmode_operate_cnt = - mock_iolink_write_devmode_operate_cnt + 1; + mock_iolink_write_devmode_operate_cnt + 1; sm_trans_8_10 (port); @@ -114,8 +118,9 @@ void sm_trans_12 (iolink_port_t * port) // DL_Write_Devicemode_cnf() mock_iolink_job.callback (&mock_iolink_job); - EXPECT_EQ (expected_write_devmode_operate_cnt, - mock_iolink_write_devmode_operate_cnt); + EXPECT_EQ ( + expected_write_devmode_operate_cnt, + mock_iolink_write_devmode_operate_cnt); EXPECT_EQ (SM_STATE_SMOperate, sm_get_state (port)); } @@ -129,8 +134,9 @@ void sm_trans_13 (iolink_port_t * port) // DL_Mode_OPERATE T13 DL_Mode_ind (port, IOLINK_MHMODE_OPERATE); mock_iolink_job.callback (&mock_iolink_job); - EXPECT_EQ (expected_write_devmode_operate_cnt, - mock_iolink_write_devmode_operate_cnt); + EXPECT_EQ ( + expected_write_devmode_operate_cnt, + mock_iolink_write_devmode_operate_cnt); EXPECT_EQ (SM_STATE_SMOperate, sm_get_state (port)); // Verify reported SM_PortMode_ind() EXPECT_EQ (IOLINK_SM_PORTMODE_OPERATE, mock_iolink_sm_portmode); @@ -142,12 +148,15 @@ void sm_trans_15 (iolink_port_t * port, bool is_autocom) iolink_smp_parameterlist_t paraml; paraml.inspectionlevel = IOLINK_INSPECTIONLEVEL_NO_CHECK; - paraml.cycletime = 0; - paraml.revisionid = IOL_DIR_PARAM_REV_V11; - if (is_autocom) { - paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; - } else { - paraml.mode = IOLINK_SMTARGET_MODE_CFGCOM; + paraml.cycletime = 0; + paraml.revisionid = IOL_DIR_PARAM_REV_V11; + if (is_autocom) + { + paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; + } + else + { + paraml.mode = IOLINK_SMTARGET_MODE_CFGCOM; } // SM_SetPortConfig_CFGCOM_or_AUTOCOM @@ -157,7 +166,6 @@ void sm_trans_15 (iolink_port_t * port, bool is_autocom) EXPECT_EQ (SM_STATE_PortInactive, sm_get_state (port)); } - void sm_trans_16 (iolink_port_t * port, bool is_di) { iolink_error_t res; @@ -165,14 +173,17 @@ void sm_trans_16 (iolink_port_t * port, bool is_di) iolink_sm_portmode_t expected_sm_portmode; paraml.inspectionlevel = IOLINK_INSPECTIONLEVEL_NO_CHECK; - paraml.cycletime = 0; - paraml.revisionid = IOL_DIR_PARAM_REV_V11; - if (is_di) { - paraml.mode = IOLINK_SMTARGET_MODE_DI; - expected_sm_portmode = IOLINK_SM_PORTMODE_DI; - } else { - paraml.mode = IOLINK_SMTARGET_MODE_DO; - expected_sm_portmode = IOLINK_SM_PORTMODE_DO; + paraml.cycletime = 0; + paraml.revisionid = IOL_DIR_PARAM_REV_V11; + if (is_di) + { + paraml.mode = IOLINK_SMTARGET_MODE_DI; + expected_sm_portmode = IOLINK_SM_PORTMODE_DI; + } + else + { + paraml.mode = IOLINK_SMTARGET_MODE_DO; + expected_sm_portmode = IOLINK_SM_PORTMODE_DO; } // SM_SetPortConfig_DI_or_DO T16 @@ -220,10 +231,11 @@ void sm_verify_checkcomp_params (iolink_port_t * port, bool is_v10) // -> SM_STATE_CheckVxy or SM_STATE_checkCompV10 } -void sm_checkCompatibility (iolink_port_t * port, - iolink_smp_parameterlist_t * paraml, - iolink_sm_state_t expected_state, - bool is_v10) +void sm_checkCompatibility ( + iolink_port_t * port, + iolink_smp_parameterlist_t * paraml, + iolink_sm_state_t expected_state, + bool is_v10) { iolink_error_t res; @@ -251,7 +263,6 @@ void sm_checkCompatibility (iolink_port_t * port, } } sm_verify_checkcomp_params (port, is_v10); - } void sm_set_portconfig_inactive (iolink_port_t * port) @@ -260,25 +271,25 @@ void sm_set_portconfig_inactive (iolink_port_t * port) iolink_smp_parameterlist_t paraml; iolink_sm_state_t current_state = sm_get_state (port); uint8_t expected_write_devmode_inactive_cnt = - mock_iolink_write_devmode_inactive_cnt; + mock_iolink_write_devmode_inactive_cnt; - paraml.vendorid = mock_iolink_vendorid; - paraml.deviceid = mock_iolink_deviceid; + paraml.vendorid = mock_iolink_vendorid; + paraml.deviceid = mock_iolink_deviceid; paraml.inspectionlevel = IOLINK_INSPECTIONLEVEL_NO_CHECK; - paraml.cycletime = 0; - paraml.revisionid = IOL_DIR_PARAM_REV_V11; - paraml.mode = IOLINK_SMTARGET_MODE_INACTIVE; + paraml.cycletime = 0; + paraml.revisionid = IOL_DIR_PARAM_REV_V11; + paraml.mode = IOLINK_SMTARGET_MODE_INACTIVE; // SM_SetPortConfig_INACTIVE T14 res = SM_SetPortConfig_req (port, ¶ml); mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (IOLINK_ERROR_NONE, res); - if (current_state != SM_STATE_PortInactive && - current_state != SM_STATE_DIDO) + if (current_state != SM_STATE_PortInactive && current_state != SM_STATE_DIDO) { expected_write_devmode_inactive_cnt++; - EXPECT_EQ (expected_write_devmode_inactive_cnt, - mock_iolink_write_devmode_inactive_cnt); + EXPECT_EQ ( + expected_write_devmode_inactive_cnt, + mock_iolink_write_devmode_inactive_cnt); EXPECT_EQ (SM_STATE_waitForFallback, sm_get_state (port)); // DL_Write_Devicemode (INACTIVE) @@ -294,12 +305,12 @@ void sm_set_portconfig_v11_autocom (iolink_port_t * port) iolink_error_t res; iolink_smp_parameterlist_t paraml; - paraml.vendorid = mock_iolink_vendorid; - paraml.deviceid = mock_iolink_deviceid; + paraml.vendorid = mock_iolink_vendorid; + paraml.deviceid = mock_iolink_deviceid; paraml.inspectionlevel = IOLINK_INSPECTIONLEVEL_NO_CHECK; - paraml.cycletime = 0; - paraml.revisionid = IOL_DIR_PARAM_REV_V11; - paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; + paraml.cycletime = 0; + paraml.revisionid = IOL_DIR_PARAM_REV_V11; + paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; // SM_SetPortConfig_AUTOCOM T15 res = SM_SetPortConfig_req (port, ¶ml); mock_iolink_job.callback (&mock_iolink_job); @@ -324,9 +335,9 @@ TEST_F (SMTest, invalid_inspection_level) EXPECT_EQ (SM_STATE_PortInactive, sm_get_state (port)); paraml.inspectionlevel = (iolink_inspectionlevel_t)0x66; // Bad - paraml.cycletime = 0; - paraml.revisionid = IOL_DIR_PARAM_REV_V11; - paraml.mode = IOLINK_SMTARGET_MODE_INACTIVE; + paraml.cycletime = 0; + paraml.revisionid = IOL_DIR_PARAM_REV_V11; + paraml.mode = IOLINK_SMTARGET_MODE_INACTIVE; res = SM_SetPortConfig_req (port, ¶ml); EXPECT_EQ (IOLINK_ERROR_PARAMETER_CONFLICT, res); @@ -341,9 +352,9 @@ TEST_F (SMTest, invalid_target_mode) EXPECT_EQ (SM_STATE_PortInactive, sm_get_state (port)); paraml.inspectionlevel = IOLINK_INSPECTIONLEVEL_NO_CHECK; - paraml.cycletime = 0; - paraml.revisionid = IOL_DIR_PARAM_REV_V11; - paraml.mode = (iolink_sm_target_mode_t)0x66; // Bad + paraml.cycletime = 0; + paraml.revisionid = IOL_DIR_PARAM_REV_V11; + paraml.mode = (iolink_sm_target_mode_t)0x66; // Bad res = SM_SetPortConfig_req (port, ¶ml); EXPECT_EQ (IOLINK_ERROR_PARAMETER_CONFLICT, res); @@ -359,19 +370,23 @@ TEST_F (SMTest, checkCompatibility_IL_TYPE_COMP_bad_revision) mock_iolink_revisionid = IOL_DIR_PARAM_REV_V11 + 1; paraml.inspectionlevel = IOLINK_INSPECTIONLEVEL_TYPE_COMP; - paraml.cycletime = 0; - paraml.revisionid = IOL_DIR_PARAM_REV_V11; // != mock_iolink_revisionid - paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; - paraml.vendorid = mock_iolink_vendorid; - paraml.deviceid = mock_iolink_deviceid; + paraml.cycletime = 0; + paraml.revisionid = IOL_DIR_PARAM_REV_V11; // != mock_iolink_revisionid + paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; + paraml.vendorid = mock_iolink_vendorid; + paraml.deviceid = mock_iolink_deviceid; for (i = 0; i < 5; i++) { sm_checkCompatibility (port, ¶ml, SM_STATE_PortInactive, false); EXPECT_EQ (SM_STATE_RestartDevice, sm_get_state (port)); - mock_iolink_job.callback (&mock_iolink_job); // write_cnf IOL_DIR_PARAMA_REV_ID config_paramlist->revisionid - mock_iolink_job.callback (&mock_iolink_job); // write_cnf IOL_DIR_PARAMA_MASTER_CMD IOL_MASTERCMD_DEVICE_IDENT + mock_iolink_job.callback (&mock_iolink_job); // write_cnf + // IOL_DIR_PARAMA_REV_ID + // config_paramlist->revisionid + mock_iolink_job.callback (&mock_iolink_job); // write_cnf + // IOL_DIR_PARAMA_MASTER_CMD + // IOL_MASTERCMD_DEVICE_IDENT EXPECT_EQ (SM_STATE_RestartDevice, sm_get_state (port)); mock_iolink_job.callback (&mock_iolink_job); // Dummy DL_Read_cnf EXPECT_EQ (SM_STATE_ReadComParameter, sm_get_state (port)); @@ -408,19 +423,23 @@ TEST_F (SMTest, checkCompatibility_IL_IDENTICAL_bad_revision) mock_iolink_revisionid = IOL_DIR_PARAM_REV_V11 + 1; paraml.inspectionlevel = IOLINK_INSPECTIONLEVEL_IDENTICAL; - paraml.cycletime = 0; - paraml.revisionid = IOL_DIR_PARAM_REV_V11; // != mock_iolink_revisionid - paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; - paraml.vendorid = mock_iolink_vendorid; - paraml.deviceid = mock_iolink_deviceid; + paraml.cycletime = 0; + paraml.revisionid = IOL_DIR_PARAM_REV_V11; // != mock_iolink_revisionid + paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; + paraml.vendorid = mock_iolink_vendorid; + paraml.deviceid = mock_iolink_deviceid; for (i = 0; i < 5; i++) { sm_checkCompatibility (port, ¶ml, SM_STATE_PortInactive, false); EXPECT_EQ (SM_STATE_RestartDevice, sm_get_state (port)); - mock_iolink_job.callback (&mock_iolink_job); // write_cnf IOL_DIR_PARAMA_REV_ID config_paramlist->revisionid - mock_iolink_job.callback (&mock_iolink_job); // write_cnf IOL_DIR_PARAMA_MASTER_CMD IOL_MASTERCMD_DEVICE_IDENT + mock_iolink_job.callback (&mock_iolink_job); // write_cnf + // IOL_DIR_PARAMA_REV_ID + // config_paramlist->revisionid + mock_iolink_job.callback (&mock_iolink_job); // write_cnf + // IOL_DIR_PARAMA_MASTER_CMD + // IOL_MASTERCMD_DEVICE_IDENT EXPECT_EQ (SM_STATE_RestartDevice, sm_get_state (port)); mock_iolink_job.callback (&mock_iolink_job); // Dummy DL_Read_cnf EXPECT_EQ (SM_STATE_ReadComParameter, sm_get_state (port)); @@ -458,12 +477,12 @@ TEST_F (SMTest, checkCompatibility_IL_TYPE_COMP) iolink_smp_parameterlist_t paraml; paraml.inspectionlevel = IOLINK_INSPECTIONLEVEL_TYPE_COMP; - paraml.cycletime = mock_iolink_min_cycletime; - paraml.revisionid = IOL_DIR_PARAM_REV_V11; - paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; - paraml.vendorid = mock_iolink_vendorid; - paraml.deviceid = mock_iolink_deviceid; - memset (paraml.serialnumber, 0, sizeof(paraml.serialnumber)); + paraml.cycletime = mock_iolink_min_cycletime; + paraml.revisionid = IOL_DIR_PARAM_REV_V11; + paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; + paraml.vendorid = mock_iolink_vendorid; + paraml.deviceid = mock_iolink_deviceid; + memset (paraml.serialnumber, 0, sizeof (paraml.serialnumber)); paraml.serialnumber[0] = 0x11; paraml.serialnumber[1] = 0x22; paraml.serialnumber[2] = 0x33; @@ -480,8 +499,11 @@ TEST_F (SMTest, checkCompatibility_IL_TYPE_COMP) mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (SM_STATE_checkSerNum, sm_get_state (port)); - mock_iolink_al_read_cnf_cb (port, sizeof(paraml.serialnumber), - paraml.serialnumber, IOLINK_SMI_ERRORTYPE_NONE); + mock_iolink_al_read_cnf_cb ( + port, + sizeof (paraml.serialnumber), + paraml.serialnumber, + IOLINK_SMI_ERRORTYPE_NONE); mock_iolink_job.callback (&mock_iolink_job); // SerNumOk T10 EXPECT_EQ (SM_STATE_wait, sm_get_state (port)); @@ -494,12 +516,12 @@ TEST_F (SMTest, checkCompatibility_IL_TYPE_COMP_bad_serial) iolink_smp_parameterlist_t paraml; paraml.inspectionlevel = IOLINK_INSPECTIONLEVEL_TYPE_COMP; - paraml.cycletime = 0; - paraml.revisionid = IOL_DIR_PARAM_REV_V11; - paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; - paraml.vendorid = mock_iolink_vendorid; - paraml.deviceid = mock_iolink_deviceid; - memset (paraml.serialnumber, 0, sizeof(paraml.serialnumber)); + paraml.cycletime = 0; + paraml.revisionid = IOL_DIR_PARAM_REV_V11; + paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; + paraml.vendorid = mock_iolink_vendorid; + paraml.deviceid = mock_iolink_deviceid; + memset (paraml.serialnumber, 0, sizeof (paraml.serialnumber)); paraml.serialnumber[0] = 0x11; paraml.serialnumber[1] = 0x22; paraml.serialnumber[2] = 0x33; @@ -517,8 +539,11 @@ TEST_F (SMTest, checkCompatibility_IL_TYPE_COMP_bad_serial) EXPECT_EQ (SM_STATE_checkSerNum, sm_get_state (port)); paraml.serialnumber[4] = 0x66; // bad serial number - mock_iolink_al_read_cnf_cb (port, sizeof(paraml.serialnumber), - paraml.serialnumber, IOLINK_SMI_ERRORTYPE_NONE); + mock_iolink_al_read_cnf_cb ( + port, + sizeof (paraml.serialnumber), + paraml.serialnumber, + IOLINK_SMI_ERRORTYPE_NONE); mock_iolink_job.callback (&mock_iolink_job); // SerNumOk T10 EXPECT_EQ (SM_STATE_wait, sm_get_state (port)); @@ -531,9 +556,9 @@ TEST_F (SMTest, checkCompatibility_IL_TYPE_COMP_bad_vid) iolink_smp_parameterlist_t paraml; paraml.inspectionlevel = IOLINK_INSPECTIONLEVEL_TYPE_COMP; - paraml.cycletime = 0; - paraml.revisionid = IOL_DIR_PARAM_REV_V11; - paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; + paraml.cycletime = 0; + paraml.revisionid = IOL_DIR_PARAM_REV_V11; + paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; // Bad vid paraml.vendorid = 0x6666; paraml.deviceid = mock_iolink_deviceid; @@ -564,10 +589,10 @@ TEST_F (SMTest, checkCompatibility_IL_TYPE_COMP_bad_did) iolink_smp_parameterlist_t paraml; paraml.inspectionlevel = IOLINK_INSPECTIONLEVEL_TYPE_COMP; - paraml.cycletime = 0; - paraml.revisionid = IOL_DIR_PARAM_REV_V11; - paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; - paraml.vendorid = mock_iolink_vendorid; + paraml.cycletime = 0; + paraml.revisionid = IOL_DIR_PARAM_REV_V11; + paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; + paraml.vendorid = mock_iolink_vendorid; // Bad did paraml.deviceid = 0x666666; @@ -576,8 +601,12 @@ TEST_F (SMTest, checkCompatibility_IL_TYPE_COMP_bad_did) sm_checkCompatibility (port, ¶ml, SM_STATE_PortInactive, false); EXPECT_EQ (SM_STATE_RestartDevice, sm_get_state (port)); - mock_iolink_job.callback (&mock_iolink_job); // write_cnf IOL_DIR_PARAMA_REV_ID config_paramlist->revisionid - mock_iolink_job.callback (&mock_iolink_job); // write_cnf IOL_DIR_PARAMA_MASTER_CMD IOL_MASTERCMD_DEVICE_IDENT + mock_iolink_job.callback (&mock_iolink_job); // write_cnf + // IOL_DIR_PARAMA_REV_ID + // config_paramlist->revisionid + mock_iolink_job.callback (&mock_iolink_job); // write_cnf + // IOL_DIR_PARAMA_MASTER_CMD + // IOL_MASTERCMD_DEVICE_IDENT EXPECT_EQ (SM_STATE_RestartDevice, sm_get_state (port)); mock_iolink_job.callback (&mock_iolink_job); // Dummy DL_Read_cnf EXPECT_EQ (SM_STATE_ReadComParameter, sm_get_state (port)); @@ -611,11 +640,11 @@ TEST_F (SMTest, checkCompatibility_IL_TYPE_COMP_bad_cyc_time) paraml.inspectionlevel = IOLINK_INSPECTIONLEVEL_TYPE_COMP; // Bad cycle time - paraml.cycletime = mock_iolink_min_cycletime - 1; + paraml.cycletime = mock_iolink_min_cycletime - 1; paraml.revisionid = IOL_DIR_PARAM_REV_V11; - paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; - paraml.vendorid = mock_iolink_vendorid; - paraml.deviceid = mock_iolink_deviceid; + paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; + paraml.vendorid = mock_iolink_vendorid; + paraml.deviceid = mock_iolink_deviceid; sm_checkCompatibility (port, ¶ml, SM_STATE_PortInactive, false); @@ -642,12 +671,12 @@ TEST_F (SMTest, checkCompatibility_IL_IDENTICAL) iolink_smp_parameterlist_t paraml; paraml.inspectionlevel = IOLINK_INSPECTIONLEVEL_IDENTICAL; - paraml.cycletime = 0; - paraml.revisionid = IOL_DIR_PARAM_REV_V11; - paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; - paraml.vendorid = mock_iolink_vendorid; - paraml.deviceid = mock_iolink_deviceid; - memset (paraml.serialnumber, 0, sizeof(paraml.serialnumber)); + paraml.cycletime = 0; + paraml.revisionid = IOL_DIR_PARAM_REV_V11; + paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; + paraml.vendorid = mock_iolink_vendorid; + paraml.deviceid = mock_iolink_deviceid; + memset (paraml.serialnumber, 0, sizeof (paraml.serialnumber)); paraml.serialnumber[0] = 0x11; paraml.serialnumber[1] = 0x22; paraml.serialnumber[2] = 0x33; @@ -664,8 +693,11 @@ TEST_F (SMTest, checkCompatibility_IL_IDENTICAL) mock_iolink_job.callback (&mock_iolink_job); EXPECT_EQ (SM_STATE_checkSerNum, sm_get_state (port)); - mock_iolink_al_read_cnf_cb (port, sizeof(paraml.serialnumber), - paraml.serialnumber, IOLINK_SMI_ERRORTYPE_NONE); + mock_iolink_al_read_cnf_cb ( + port, + sizeof (paraml.serialnumber), + paraml.serialnumber, + IOLINK_SMI_ERRORTYPE_NONE); mock_iolink_job.callback (&mock_iolink_job); // SerNumOk T10 EXPECT_EQ (SM_STATE_wait, sm_get_state (port)); @@ -678,12 +710,12 @@ TEST_F (SMTest, checkCompatibility_IL_IDENTICAL_bad_serial) iolink_smp_parameterlist_t paraml; paraml.inspectionlevel = IOLINK_INSPECTIONLEVEL_IDENTICAL; - paraml.cycletime = 0; - paraml.revisionid = IOL_DIR_PARAM_REV_V11; - paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; - paraml.vendorid = mock_iolink_vendorid; - paraml.deviceid = mock_iolink_deviceid; - memset (paraml.serialnumber, 0, sizeof(paraml.serialnumber)); + paraml.cycletime = 0; + paraml.revisionid = IOL_DIR_PARAM_REV_V11; + paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; + paraml.vendorid = mock_iolink_vendorid; + paraml.deviceid = mock_iolink_deviceid; + memset (paraml.serialnumber, 0, sizeof (paraml.serialnumber)); paraml.serialnumber[0] = 0x11; paraml.serialnumber[1] = 0x22; paraml.serialnumber[2] = 0x33; @@ -701,8 +733,11 @@ TEST_F (SMTest, checkCompatibility_IL_IDENTICAL_bad_serial) EXPECT_EQ (SM_STATE_checkSerNum, sm_get_state (port)); paraml.serialnumber[4] = 0x66; // bad serial number - mock_iolink_al_read_cnf_cb (port, sizeof(paraml.serialnumber), - paraml.serialnumber, IOLINK_SMI_ERRORTYPE_NONE); + mock_iolink_al_read_cnf_cb ( + port, + sizeof (paraml.serialnumber), + paraml.serialnumber, + IOLINK_SMI_ERRORTYPE_NONE); mock_iolink_job.callback (&mock_iolink_job); // SerNumFault T11 EXPECT_EQ (SM_STATE_InspectionFault, sm_get_state (port)); @@ -718,9 +753,9 @@ TEST_F (SMTest, checkCompatibility_IL_IDENTICAL_bad_vid) iolink_smp_parameterlist_t paraml; paraml.inspectionlevel = IOLINK_INSPECTIONLEVEL_IDENTICAL; - paraml.cycletime = 0; - paraml.revisionid = IOL_DIR_PARAM_REV_V11; - paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; + paraml.cycletime = 0; + paraml.revisionid = IOL_DIR_PARAM_REV_V11; + paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; // Bad vid paraml.vendorid = 0x6666; paraml.deviceid = mock_iolink_deviceid; @@ -747,10 +782,10 @@ TEST_F (SMTest, checkCompatibility_IL_IDENTICAL_bad_did) iolink_smp_parameterlist_t paraml; paraml.inspectionlevel = IOLINK_INSPECTIONLEVEL_IDENTICAL; - paraml.cycletime = 0; - paraml.revisionid = IOL_DIR_PARAM_REV_V11; - paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; - paraml.vendorid = mock_iolink_vendorid; + paraml.cycletime = 0; + paraml.revisionid = IOL_DIR_PARAM_REV_V11; + paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; + paraml.vendorid = mock_iolink_vendorid; // Bad did paraml.deviceid = 0x666666; @@ -759,8 +794,12 @@ TEST_F (SMTest, checkCompatibility_IL_IDENTICAL_bad_did) sm_checkCompatibility (port, ¶ml, SM_STATE_PortInactive, false); EXPECT_EQ (SM_STATE_RestartDevice, sm_get_state (port)); - mock_iolink_job.callback (&mock_iolink_job); // write_cnf IOL_DIR_PARAMA_REV_ID config_paramlist->revisionid - mock_iolink_job.callback (&mock_iolink_job); // write_cnf IOL_DIR_PARAMA_MASTER_CMD IOL_MASTERCMD_DEVICE_IDENT + mock_iolink_job.callback (&mock_iolink_job); // write_cnf + // IOL_DIR_PARAMA_REV_ID + // config_paramlist->revisionid + mock_iolink_job.callback (&mock_iolink_job); // write_cnf + // IOL_DIR_PARAMA_MASTER_CMD + // IOL_MASTERCMD_DEVICE_IDENT EXPECT_EQ (SM_STATE_RestartDevice, sm_get_state (port)); mock_iolink_job.callback (&mock_iolink_job); // Dummy DL_Read_cnf EXPECT_EQ (SM_STATE_ReadComParameter, sm_get_state (port)); @@ -794,11 +833,11 @@ TEST_F (SMTest, checkCompatibility_IL_IDENTICAL_bad_cyc_time) paraml.inspectionlevel = IOLINK_INSPECTIONLEVEL_IDENTICAL; // Bad cycle time - paraml.cycletime = mock_iolink_min_cycletime - 1; + paraml.cycletime = mock_iolink_min_cycletime - 1; paraml.revisionid = IOL_DIR_PARAM_REV_V11; - paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; - paraml.vendorid = mock_iolink_vendorid; - paraml.deviceid = mock_iolink_deviceid; + paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; + paraml.vendorid = mock_iolink_vendorid; + paraml.deviceid = mock_iolink_deviceid; sm_checkCompatibility (port, ¶ml, SM_STATE_PortInactive, false); @@ -827,11 +866,11 @@ TEST_F (SMTest, checkCompatibilityV10_IL_TYPE_COMP) mock_iolink_revisionid = IOL_DIR_PARAM_REV_V10; paraml.inspectionlevel = IOLINK_INSPECTIONLEVEL_TYPE_COMP; - paraml.cycletime = 0; - paraml.revisionid = IOL_DIR_PARAM_REV_V10; - paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; - paraml.vendorid = mock_iolink_vendorid; - paraml.deviceid = mock_iolink_deviceid; + paraml.cycletime = 0; + paraml.revisionid = IOL_DIR_PARAM_REV_V10; + paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; + paraml.vendorid = mock_iolink_vendorid; + paraml.deviceid = mock_iolink_deviceid; sm_checkCompatibility (port, ¶ml, SM_STATE_PortInactive, true); @@ -848,9 +887,9 @@ TEST_F (SMTest, checkCompatibilityV10_IL_TYPE_COMP_bad_vid) mock_iolink_revisionid = IOL_DIR_PARAM_REV_V10; paraml.inspectionlevel = IOLINK_INSPECTIONLEVEL_TYPE_COMP; - paraml.cycletime = 0; - paraml.revisionid = IOL_DIR_PARAM_REV_V10; - paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; + paraml.cycletime = 0; + paraml.revisionid = IOL_DIR_PARAM_REV_V10; + paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; // Bad vid paraml.vendorid = 0x6666; paraml.deviceid = mock_iolink_deviceid; @@ -873,10 +912,10 @@ TEST_F (SMTest, checkCompatibilityV10_IL_TYPE_COMP_bad_did) mock_iolink_revisionid = IOL_DIR_PARAM_REV_V10; paraml.inspectionlevel = IOLINK_INSPECTIONLEVEL_TYPE_COMP; - paraml.cycletime = 0; - paraml.revisionid = IOL_DIR_PARAM_REV_V10; - paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; - paraml.vendorid = mock_iolink_vendorid; + paraml.cycletime = 0; + paraml.revisionid = IOL_DIR_PARAM_REV_V10; + paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; + paraml.vendorid = mock_iolink_vendorid; // Bad did paraml.deviceid = 0x666666; @@ -899,11 +938,11 @@ TEST_F (SMTest, checkCompatibilityV10_IL_TYPE_COMP_bad_cyc_time) paraml.inspectionlevel = IOLINK_INSPECTIONLEVEL_TYPE_COMP; // Bad cycle time - paraml.cycletime = mock_iolink_min_cycletime - 1; + paraml.cycletime = mock_iolink_min_cycletime - 1; paraml.revisionid = IOL_DIR_PARAM_REV_V10; - paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; - paraml.vendorid = mock_iolink_vendorid; - paraml.deviceid = mock_iolink_deviceid; + paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; + paraml.vendorid = mock_iolink_vendorid; + paraml.deviceid = mock_iolink_deviceid; sm_checkCompatibility (port, ¶ml, SM_STATE_PortInactive, true); @@ -923,11 +962,11 @@ TEST_F (SMTest, checkCompatibilityV10_IL_IDENTICAL) mock_iolink_revisionid = IOL_DIR_PARAM_REV_V10; paraml.inspectionlevel = IOLINK_INSPECTIONLEVEL_IDENTICAL; - paraml.cycletime = 0; - paraml.revisionid = IOL_DIR_PARAM_REV_V10; - paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; - paraml.vendorid = mock_iolink_vendorid; - paraml.deviceid = mock_iolink_deviceid; + paraml.cycletime = 0; + paraml.revisionid = IOL_DIR_PARAM_REV_V10; + paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; + paraml.vendorid = mock_iolink_vendorid; + paraml.deviceid = mock_iolink_deviceid; sm_checkCompatibility (port, ¶ml, SM_STATE_PortInactive, true); @@ -944,9 +983,9 @@ TEST_F (SMTest, checkCompatibilityV10_IL_IDENTICAL_bad_vid) mock_iolink_revisionid = IOL_DIR_PARAM_REV_V10; paraml.inspectionlevel = IOLINK_INSPECTIONLEVEL_IDENTICAL; - paraml.cycletime = 0; - paraml.revisionid = IOL_DIR_PARAM_REV_V10; - paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; + paraml.cycletime = 0; + paraml.revisionid = IOL_DIR_PARAM_REV_V10; + paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; // Bad vid paraml.vendorid = 0x6666; paraml.deviceid = mock_iolink_deviceid; @@ -969,10 +1008,10 @@ TEST_F (SMTest, checkCompatibilityV10_IL_IDENTICAL_bad_did) mock_iolink_revisionid = IOL_DIR_PARAM_REV_V10; paraml.inspectionlevel = IOLINK_INSPECTIONLEVEL_IDENTICAL; - paraml.cycletime = 0; - paraml.revisionid = IOL_DIR_PARAM_REV_V10; - paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; - paraml.vendorid = mock_iolink_vendorid; + paraml.cycletime = 0; + paraml.revisionid = IOL_DIR_PARAM_REV_V10; + paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; + paraml.vendorid = mock_iolink_vendorid; // Bad did paraml.deviceid = 0x666666; @@ -994,12 +1033,12 @@ TEST_F (SMTest, checkCompatibilityV10_IL_IDENTICAL_bad_serial) mock_iolink_revisionid = IOL_DIR_PARAM_REV_V10; paraml.inspectionlevel = IOLINK_INSPECTIONLEVEL_IDENTICAL; - paraml.cycletime = 0; - paraml.revisionid = IOL_DIR_PARAM_REV_V10; - paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; - paraml.vendorid = mock_iolink_vendorid; - paraml.deviceid = mock_iolink_deviceid; - memset (paraml.serialnumber, 0, sizeof(paraml.serialnumber)); + paraml.cycletime = 0; + paraml.revisionid = IOL_DIR_PARAM_REV_V10; + paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; + paraml.vendorid = mock_iolink_vendorid; + paraml.deviceid = mock_iolink_deviceid; + memset (paraml.serialnumber, 0, sizeof (paraml.serialnumber)); paraml.serialnumber[0] = 0x11; paraml.serialnumber[1] = 0x22; paraml.serialnumber[2] = 0x33; @@ -1016,8 +1055,11 @@ TEST_F (SMTest, checkCompatibilityV10_IL_IDENTICAL_bad_serial) EXPECT_EQ (SM_STATE_checkSerNum, sm_get_state (port)); paraml.serialnumber[4] = 0x66; // bad serial number - mock_iolink_al_read_cnf_cb (port, sizeof(paraml.serialnumber), - paraml.serialnumber, IOLINK_SMI_ERRORTYPE_NONE); + mock_iolink_al_read_cnf_cb ( + port, + sizeof (paraml.serialnumber), + paraml.serialnumber, + IOLINK_SMI_ERRORTYPE_NONE); mock_iolink_job.callback (&mock_iolink_job); // SerNumFault T11 EXPECT_EQ (SM_STATE_InspectionFault, sm_get_state (port)); @@ -1033,11 +1075,11 @@ TEST_F (SMTest, checkCompatibilityV10_IL_IDENTICAL_bad_cyc_time) paraml.inspectionlevel = IOLINK_INSPECTIONLEVEL_IDENTICAL; // Bad cycle time - paraml.cycletime = mock_iolink_min_cycletime - 1; + paraml.cycletime = mock_iolink_min_cycletime - 1; paraml.revisionid = IOL_DIR_PARAM_REV_V10; - paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; - paraml.vendorid = mock_iolink_vendorid; - paraml.deviceid = mock_iolink_deviceid; + paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; + paraml.vendorid = mock_iolink_vendorid; + paraml.deviceid = mock_iolink_deviceid; sm_checkCompatibility (port, ¶ml, SM_STATE_PortInactive, true); @@ -1110,10 +1152,10 @@ TEST_F (SMTest, SM_SetPortConfig_INACTIVE) iolink_smp_parameterlist_t paraml; mock_iolink_mastercmd_master_ident_cnt = 0; - paraml.inspectionlevel = IOLINK_INSPECTIONLEVEL_TYPE_COMP; - paraml.cycletime = 0; - paraml.revisionid = IOL_DIR_PARAM_REV_V11; - paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; + paraml.inspectionlevel = IOLINK_INSPECTIONLEVEL_TYPE_COMP; + paraml.cycletime = 0; + paraml.revisionid = IOL_DIR_PARAM_REV_V11; + paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; // Bad vid paraml.vendorid = 0x6666; paraml.deviceid = mock_iolink_deviceid; @@ -1183,9 +1225,9 @@ TEST_F (SMTest, SM_SetPortConfig_CFGCOM_or_AUTOCOM) iolink_smp_parameterlist_t paraml; paraml.inspectionlevel = IOLINK_INSPECTIONLEVEL_TYPE_COMP; - paraml.cycletime = 0; - paraml.revisionid = IOL_DIR_PARAM_REV_V11; - paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; + paraml.cycletime = 0; + paraml.revisionid = IOL_DIR_PARAM_REV_V11; + paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; // Bad vid paraml.vendorid = 0x6666; paraml.deviceid = mock_iolink_deviceid; @@ -1272,16 +1314,15 @@ TEST_F (SMTest, SM_SetPortConfig_DIDO) // Test SM_SetPortConfig_DO T16 sm_trans_16 (port, false); - // InspectionFault_6 to DIDO_8 { int i; iolink_smp_parameterlist_t paraml; paraml.inspectionlevel = IOLINK_INSPECTIONLEVEL_TYPE_COMP; - paraml.cycletime = 0; - paraml.revisionid = IOL_DIR_PARAM_REV_V11; - paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; + paraml.cycletime = 0; + paraml.revisionid = IOL_DIR_PARAM_REV_V11; + paraml.mode = IOLINK_SMTARGET_MODE_AUTOCOM; // Bad vid paraml.vendorid = 0x6666; paraml.deviceid = mock_iolink_deviceid; @@ -1321,4 +1362,3 @@ TEST_F (SMTest, SM_SetPortConfig_DIDO) sm_trans_16 (port, true); EXPECT_EQ (SM_STATE_DIDO, sm_get_state (port)); } - diff --git a/test/test_util.h b/test/test_util.h index d2d0c9f..5f7981b 100644 --- a/test/test_util.h +++ b/test/test_util.h @@ -21,13 +21,13 @@ #include /* memset */ #ifndef ARRAY_SIZE -#define ARRAY_SIZE(ar) (sizeof(ar) / sizeof(ar[0])) +#define ARRAY_SIZE(ar) (sizeof (ar) / sizeof (ar[0])) #endif /* ARRAY_SIZE */ -#define IOLINK_MASTER_THREAD_STACK_SIZE (4 * 1024) -#define IOLINK_MASTER_THREAD_PRIO 6 -#define IOLINK_DL_THREAD_STACK_SIZE 1500 -#define IOLINK_DL_THREAD_PRIO (IOLINK_MASTER_THREAD_PRIO + 1) +#define IOLINK_MASTER_THREAD_STACK_SIZE (4 * 1024) +#define IOLINK_MASTER_THREAD_PRIO 6 +#define IOLINK_DL_THREAD_STACK_SIZE 1500 +#define IOLINK_DL_THREAD_PRIO (IOLINK_MASTER_THREAD_PRIO + 1) typedef struct { @@ -40,96 +40,97 @@ typedef struct class TestBase : public ::testing::Test { -protected: - virtual void SetUp() { - iolink_port_cfg_t port_cfgs [] = - { + protected: + virtual void SetUp() + { + iolink_port_cfg_t port_cfgs[] = { { - .name ="/ioltest1/0", - .mode =NULL, + .name = "/ioltest1/0", + .mode = NULL, }, { - .name ="/ioltest1/1", - .mode =NULL, + .name = "/ioltest1/1", + .mode = NULL, }, }; iolink_m_cfg_t m_cfg = { - .cb_arg = NULL, - .cb_smi = mock_SMI_cnf, - .cb_pd = NULL, - .port_cnt = NELEMENTS (port_cfgs), - .port_cfgs = port_cfgs, - .master_thread_prio = IOLINK_MASTER_THREAD_PRIO, + .cb_arg = NULL, + .cb_smi = mock_SMI_cnf, + .cb_pd = NULL, + .port_cnt = NELEMENTS (port_cfgs), + .port_cfgs = port_cfgs, + .master_thread_prio = IOLINK_MASTER_THREAD_PRIO, .master_thread_stack_size = IOLINK_MASTER_THREAD_STACK_SIZE, - .dl_thread_prio = IOLINK_DL_THREAD_PRIO, - .dl_thread_stack_size = IOLINK_DL_THREAD_STACK_SIZE, + .dl_thread_prio = IOLINK_DL_THREAD_PRIO, + .dl_thread_stack_size = IOLINK_DL_THREAD_STACK_SIZE, }; m = iolink_m_init (&m_cfg); portnumber = 1; - port = iolink_get_port (m, portnumber); + port = iolink_get_port (m, portnumber); /* Reset mock variables */ - mock_iolink_revisionid = IOL_DIR_PARAM_REV_V11; + mock_iolink_revisionid = IOL_DIR_PARAM_REV_V11; mock_iolink_master_cycletime = 0; - mock_iolink_min_cycletime = 79; - mock_iolink_vendorid = 1171; - mock_iolink_deviceid = 0x112345; - mock_iolink_functionid = 0x999A; - mock_iolink_trans_rate = IOLINK_TRANSMISSION_RATE_COM1; + mock_iolink_min_cycletime = 79; + mock_iolink_vendorid = 1171; + mock_iolink_deviceid = 0x112345; + mock_iolink_functionid = 0x999A; + mock_iolink_trans_rate = IOLINK_TRANSMISSION_RATE_COM1; - mock_iolink_restart_device_cnt = 0; + mock_iolink_restart_device_cnt = 0; mock_iolink_mastercmd_master_ident_cnt = 0; - mock_iolink_mastercmd_preop_cnt = 0; + mock_iolink_mastercmd_preop_cnt = 0; mock_iolink_write_devmode_inactive_cnt = 0; - mock_iolink_write_devmode_operate_cnt = 0; - memset (mock_iolink_al_data, 0, sizeof(mock_iolink_al_data)); - mock_iolink_al_data_len = 0; - mock_iolink_al_data_index = 0; - mock_iolink_al_data_subindex = 0; - mock_iolink_al_read_cnf_cnt = 0; - mock_iolink_al_read_req_cnt = 0; - mock_iolink_al_write_cnf_cnt = 0; - mock_iolink_al_write_req_cnt = 0; + mock_iolink_write_devmode_operate_cnt = 0; + memset (mock_iolink_al_data, 0, sizeof (mock_iolink_al_data)); + mock_iolink_al_data_len = 0; + mock_iolink_al_data_index = 0; + mock_iolink_al_data_subindex = 0; + mock_iolink_al_read_cnf_cnt = 0; + mock_iolink_al_read_req_cnt = 0; + mock_iolink_al_write_cnf_cnt = 0; + mock_iolink_al_write_req_cnt = 0; mock_iolink_al_control_req_cnt = 0; mock_iolink_al_control_ind_cnt = 0; - memset (mock_iolink_dl_pdout_data, 0, sizeof(mock_iolink_dl_pdout_data)); + memset (mock_iolink_dl_pdout_data, 0, sizeof (mock_iolink_dl_pdout_data)); mock_iolink_dl_pdout_data_len = 0; - memset (mock_iolink_dl_pdin_data, 0, sizeof(mock_iolink_dl_pdin_data)); - mock_iolink_dl_pdin_data_len = 0; - mock_iolink_dl_control_req_cnt = 0; - mock_iolink_dl_eventconf_req_cnt = 0; - mock_iolink_al_event_cnt = 0; - mock_iolink_sm_operate_cnt = 0; - mock_iolink_al_getinput_req_cnt = 0; + memset (mock_iolink_dl_pdin_data, 0, sizeof (mock_iolink_dl_pdin_data)); + mock_iolink_dl_pdin_data_len = 0; + mock_iolink_dl_control_req_cnt = 0; + mock_iolink_dl_eventconf_req_cnt = 0; + mock_iolink_al_event_cnt = 0; + mock_iolink_sm_operate_cnt = 0; + mock_iolink_al_getinput_req_cnt = 0; mock_iolink_al_getinputoutput_req_cnt = 0; - mock_iolink_al_newinput_inf_cnt = 0; - mock_iolink_ds_delete_cnt = 0; - mock_iolink_ds_startup_cnt = 0; - mock_iolink_ds_ready_cnt = 0; - mock_iolink_ds_fault_cnt = 0; - mock_iolink_ds_fault = IOLINK_DS_FAULT_NONE; - mock_iolink_od_start_cnt = 0; - mock_iolink_od_stop_cnt = 0; - mock_iolink_pd_start_cnt = 0; - mock_iolink_pd_stop_cnt = 0; - mock_iolink_sm_portmode = IOLINK_SM_PORTMODE_INACTIVE; - mock_iolink_al_read_errortype = IOLINK_SMI_ERRORTYPE_NONE; - mock_iolink_al_write_errortype = IOLINK_SMI_ERRORTYPE_NONE; - mock_iolink_controlcode = IOLINK_CONTROLCODE_NONE; - memset (mock_iolink_al_events, 0, sizeof(mock_iolink_al_events)); - memset (&mock_iolink_cfg_paraml, 0, sizeof(mock_iolink_cfg_paraml)); + mock_iolink_al_newinput_inf_cnt = 0; + mock_iolink_ds_delete_cnt = 0; + mock_iolink_ds_startup_cnt = 0; + mock_iolink_ds_ready_cnt = 0; + mock_iolink_ds_fault_cnt = 0; + mock_iolink_ds_fault = IOLINK_DS_FAULT_NONE; + mock_iolink_od_start_cnt = 0; + mock_iolink_od_stop_cnt = 0; + mock_iolink_pd_start_cnt = 0; + mock_iolink_pd_stop_cnt = 0; + mock_iolink_sm_portmode = IOLINK_SM_PORTMODE_INACTIVE; + mock_iolink_al_read_errortype = IOLINK_SMI_ERRORTYPE_NONE; + mock_iolink_al_write_errortype = IOLINK_SMI_ERRORTYPE_NONE; + mock_iolink_controlcode = IOLINK_CONTROLCODE_NONE; + memset (mock_iolink_al_events, 0, sizeof (mock_iolink_al_events)); + memset (&mock_iolink_cfg_paraml, 0, sizeof (mock_iolink_cfg_paraml)); - mock_iolink_smi_cnf_cnt = 0; - mock_iolink_smi_joberror_cnt = 0; - mock_iolink_smi_portcfg_cnf_cnt = 0; + mock_iolink_smi_cnf_cnt = 0; + mock_iolink_smi_joberror_cnt = 0; + mock_iolink_smi_portcfg_cnf_cnt = 0; mock_iolink_smi_portstatus_cnf_cnt = 0; - mock_iolink_smi_portevent_ind_cnt = 0; - mock_iolink_smi_arg_block_len = 0; - mock_iolink_smi_ref_arg_block_id = IOLINK_ARG_BLOCK_ID_MASTERIDENT; - memset (mock_iolink_smi_arg_block, 0, sizeof(arg_block_t) + 64); + mock_iolink_smi_portevent_ind_cnt = 0; + mock_iolink_smi_arg_block_len = 0; + mock_iolink_smi_ref_arg_block_id = IOLINK_ARG_BLOCK_ID_MASTERIDENT; + memset (mock_iolink_smi_arg_block, 0, sizeof (arg_block_t) + 64); } - virtual void TearDown() { + virtual void TearDown() + { iolink_m_deinit (&m); } @@ -149,53 +150,54 @@ inline std::string FormatByte (uint8_t value) { std::stringstream ss; ss << std::setfill ('0') << std::setw (2) << std::hex << std::showbase - << static_cast(value); + << static_cast (value); return ss.str(); } -template -::testing::AssertionResult ArraysMatchN(const T (*expected), - const T (*actual), - const size_t size) +template +::testing::AssertionResult ArraysMatchN ( + const T (*expected), + const T (*actual), + const size_t size) { - for (size_t i(0); i < size; ++i) + for (size_t i (0); i < size; ++i) { if (expected[i] != actual[i]) { return ::testing::AssertionFailure() - << "actual[" << i - << "] (" << FormatByte (static_cast(actual[i])) - << ") != expected[" << i - << "] (" << FormatByte (static_cast(expected[i])) - << ")"; + << "actual[" << i << "] (" + << FormatByte (static_cast (actual[i])) << ") != expected[" + << i << "] (" << FormatByte (static_cast (expected[i])) + << ")"; } } return ::testing::AssertionSuccess(); } -template -::testing::AssertionResult ArraysMatch(const T (&expected)[size], - const T (&actual)[size]) +template +::testing::AssertionResult ArraysMatch ( + const T (&expected)[size], + const T (&actual)[size]) { - for (size_t i(0); i < size; ++i) + for (size_t i (0); i < size; ++i) { if (expected[i] != actual[i]) { return ::testing::AssertionFailure() - << "actual[" << i - << "] (" << FormatByte (static_cast(actual[i])) - << ") != expected[" << i - << "] (" << FormatByte (static_cast(expected[i])) - << ")"; + << "actual[" << i << "] (" + << FormatByte (static_cast (actual[i])) << ") != expected[" + << i << "] (" << FormatByte (static_cast (expected[i])) + << ")"; } } return ::testing::AssertionSuccess(); } -inline ::testing::AssertionResult EventMatch (al_event_t * e1, - diag_entry_t * diag, - uint8_t event_cnt) +inline ::testing::AssertionResult EventMatch ( + al_event_t * e1, + diag_entry_t * diag, + uint8_t event_cnt) { int i; al_event_t e; @@ -204,35 +206,30 @@ inline ::testing::AssertionResult EventMatch (al_event_t * e1, for (i = 0; i < event_cnt; i++) { e2->eventcode = diag[i].event_code; - e2->instance = (iolink_event_instance_t)(diag[i].event_qualifier & 0x7); - e2->source = (iolink_event_source_t)((diag[i].event_qualifier >> 3) & 0x1); - e2->type = (iolink_event_type_t)((diag[i].event_qualifier >> 4) & 0x3); - e2->mode = (iolink_event_mode_t)((diag[i].event_qualifier >> 6) & 0x3); + e2->instance = (iolink_event_instance_t) (diag[i].event_qualifier & 0x7); + e2->source = (iolink_event_source_t) ((diag[i].event_qualifier >> 3) & 0x1); + e2->type = (iolink_event_type_t) ((diag[i].event_qualifier >> 4) & 0x3); + e2->mode = (iolink_event_mode_t) ((diag[i].event_qualifier >> 6) & 0x3); if (e1->eventcode != e2->eventcode) return ::testing::AssertionFailure() - << i << ": eventcode: (" << e2->eventcode - << ") != expected (" << e1->eventcode - << ")"; + << i << ": eventcode: (" << e2->eventcode << ") != expected (" + << e1->eventcode << ")"; if (e1->instance != e2->instance) return ::testing::AssertionFailure() - << i << ": instance: (" << +e2->instance - << ") != expected (" << +e1->instance - << ")"; + << i << ": instance: (" << +e2->instance << ") != expected (" + << +e1->instance << ")"; if (e1->mode != e2->mode) return ::testing::AssertionFailure() - << i << ": mode: (" << +e2->mode - << ") != expected (" << +e1->mode - << ")"; + << i << ": mode: (" << +e2->mode << ") != expected (" + << +e1->mode << ")"; if (e1->type != e2->type) return ::testing::AssertionFailure() - << i << ": type: (" << +e2->type - << ") != expected (" << +e1->type - << ")"; + << i << ": type: (" << +e2->type << ") != expected (" + << +e1->type << ")"; if (e1->source != e2->source) return ::testing::AssertionFailure() - << i << ": source: (" << e2->source - << ") != expected (" << e1->source - << ")"; + << i << ": source: (" << e2->source << ") != expected (" + << e1->source << ")"; e1++; } @@ -240,49 +237,41 @@ inline ::testing::AssertionResult EventMatch (al_event_t * e1, } inline ::testing::AssertionResult PortConfigMatch ( - const portconfiglist_t * expected, - const portconfiglist_t * actual) + const portconfiglist_t * expected, + const portconfiglist_t * actual) { if (expected->portmode != actual->portmode) return ::testing::AssertionFailure() - << "portmode (" << actual->portmode - << ") != expected (" << expected->portmode - << ")"; + << "portmode (" << actual->portmode << ") != expected (" + << expected->portmode << ")"; if (expected->validation_backup != actual->validation_backup) return ::testing::AssertionFailure() - << "validation_backup (" << actual->validation_backup - << ") != expected (" << expected->validation_backup - << ")"; + << "validation_backup (" << actual->validation_backup + << ") != expected (" << expected->validation_backup << ")"; if (expected->iq_behavior != actual->iq_behavior) return ::testing::AssertionFailure() - << "iq_behavior (" << actual->iq_behavior - << ") != expected (" << expected->iq_behavior - << ")"; + << "iq_behavior (" << actual->iq_behavior << ") != expected (" + << expected->iq_behavior << ")"; if (expected->port_cycle_time != actual->port_cycle_time) return ::testing::AssertionFailure() - << "port_cycle_time (" << actual->port_cycle_time - << ") != expected (" << expected->port_cycle_time - << ")"; + << "port_cycle_time (" << actual->port_cycle_time + << ") != expected (" << expected->port_cycle_time << ")"; if (expected->vendorid != actual->vendorid) return ::testing::AssertionFailure() - << "vendorid (" << actual->vendorid - << ") != expected (" << expected->vendorid - << ")"; + << "vendorid (" << actual->vendorid << ") != expected (" + << expected->vendorid << ")"; if (expected->deviceid != actual->deviceid) return ::testing::AssertionFailure() - << "deviceid (" << actual->deviceid - << ") != expected (" << expected->deviceid - << ")"; + << "deviceid (" << actual->deviceid << ") != expected (" + << expected->deviceid << ")"; if (expected->in_buffer_len != actual->in_buffer_len) return ::testing::AssertionFailure() - << "in_buffer_len (" << actual->in_buffer_len - << ") != expected (" << expected->in_buffer_len - << ")"; + << "in_buffer_len (" << actual->in_buffer_len << ") != expected (" + << expected->in_buffer_len << ")"; if (expected->out_buffer_len != actual->out_buffer_len) return ::testing::AssertionFailure() - << "out_buffer_len (" << actual->out_buffer_len - << ") != expected (" << expected->out_buffer_len - << ")"; + << "out_buffer_len (" << actual->out_buffer_len + << ") != expected (" << expected->out_buffer_len << ")"; return ::testing::AssertionSuccess(); }