| 959 | #endif /* (CO_CONFIG_LSS) & CO_CONFIG_LSS_SLAVE */ |
| 960 | |
| 961 | CO_ReturnError_t |
| 962 | CO_CANopenInit(CO_t* co, CO_NMT_t* NMT, CO_EM_t* em, OD_t* od, OD_entry_t* OD_statusBits, uint16_t NMTcontrol, |
| 963 | uint16_t firstHBTime_ms, uint16_t SDOserverTimeoutTime_ms, uint16_t SDOclientTimeoutTime_ms, |
| 964 | bool_t SDOclientBlockTransfer, uint8_t nodeId, uint32_t* errInfo) { |
| 965 | (void)SDOclientTimeoutTime_ms; |
| 966 | (void)SDOclientBlockTransfer; |
| 967 | CO_ReturnError_t err; |
| 968 | |
| 969 | #if ((CO_CONFIG_EM)&CO_CONFIG_EM_STATUS_BITS) == 0 |
| 970 | (void)OD_statusBits; /* may be unused */ |
| 971 | #endif |
| 972 | |
| 973 | if ((co == NULL) || ((CO_GET_CNT(NMT) == 0U) && (NMT == NULL)) || ((CO_GET_CNT(EM) == 0U) && (em == NULL))) { |
| 974 | return CO_ERROR_ILLEGAL_ARGUMENT; |
| 975 | } |
| 976 | |
| 977 | /* alternatives */ |
| 978 | if (CO_GET_CNT(NMT) == 0U) { |
| 979 | co->NMT = NMT; |
| 980 | } |
| 981 | if (em == NULL) { |
| 982 | em = co->em; |
| 983 | } |
| 984 | |
| 985 | /* Verify CANopen Node-ID */ |
| 986 | co->nodeIdUnconfigured = false; |
| 987 | #if ((CO_CONFIG_LSS)&CO_CONFIG_LSS_SLAVE) != 0 |
| 988 | if ((CO_GET_CNT(LSS_SLV) == 1U) && (nodeId == CO_LSS_NODE_ID_ASSIGNMENT)) { |
| 989 | co->nodeIdUnconfigured = true; |
| 990 | } else |
| 991 | #endif |
| 992 | if ((nodeId < 1U) || (nodeId > 127U)) { |
| 993 | return CO_ERROR_ILLEGAL_ARGUMENT; |
| 994 | } else { /* MISRA C 2004 14.10 */ |
| 995 | } |
| 996 | |
| 997 | #if ((CO_CONFIG_LEDS)&CO_CONFIG_LEDS_ENABLE) != 0 |
| 998 | if (CO_GET_CNT(LEDS) == 1U) { |
| 999 | err = CO_LEDs_init(co->LEDs); |
| 1000 | if (err != CO_ERROR_NO) { |
| 1001 | return err; |
| 1002 | } |
| 1003 | } |
| 1004 | #endif |
| 1005 | |
| 1006 | /* CANopen Node ID is unconfigured, stop initialization here */ |
| 1007 | if (co->nodeIdUnconfigured) { |
| 1008 | return CO_ERROR_NODE_ID_UNCONFIGURED_LSS; |
| 1009 | } |
| 1010 | |
| 1011 | /* Emergency */ |
| 1012 | if (CO_GET_CNT(EM) == 1U) { |
| 1013 | err = CO_EM_init(co->em, co->CANmodule, OD_GET(H1001, OD_H1001_ERR_REG), |
| 1014 | #if ((CO_CONFIG_EM) & (CO_CONFIG_EM_PRODUCER | CO_CONFIG_EM_HISTORY)) != 0 |
| 1015 | co->em_fifo, (CO_GET_CNT(ARR_1003) + 1U), |
| 1016 | #endif |
| 1017 | #if ((CO_CONFIG_EM)&CO_CONFIG_EM_PRODUCER) != 0 |
| 1018 | OD_GET(H1014, OD_H1014_COBID_EMERGENCY), CO_GET_CO(TX_IDX_EM_PROD), |
no test coverage detected