| 166 | } |
| 167 | |
| 168 | static CO_ReturnError_t |
| 169 | CO_HBconsumer_initEntry(CO_HBconsumer_t* HBcons, uint8_t idx, uint8_t nodeId, uint16_t consumerTime_ms) { |
| 170 | CO_ReturnError_t ret = CO_ERROR_NO; |
| 171 | |
| 172 | /* verify arguments */ |
| 173 | if ((HBcons == NULL) || (idx >= HBcons->numberOfMonitoredNodes)) { |
| 174 | return CO_ERROR_ILLEGAL_ARGUMENT; |
| 175 | } |
| 176 | |
| 177 | /* verify for duplicate entries */ |
| 178 | if ((consumerTime_ms != 0U) && (nodeId != 0U)) { |
| 179 | for (uint8_t i = 0; i < HBcons->numberOfMonitoredNodes; i++) { |
| 180 | CO_HBconsNode_t node = HBcons->monitoredNodes[i]; |
| 181 | if ((idx != i) && (node.time_us != 0U) && (node.nodeId == nodeId)) { |
| 182 | ret = CO_ERROR_OD_PARAMETERS; |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | /* Configure one monitored node */ |
| 188 | if (ret == CO_ERROR_NO) { |
| 189 | uint16_t COB_ID; |
| 190 | |
| 191 | CO_HBconsNode_t* monitoredNode = &HBcons->monitoredNodes[idx]; |
| 192 | monitoredNode->nodeId = nodeId; |
| 193 | monitoredNode->time_us = (uint32_t)consumerTime_ms * 1000U; |
| 194 | monitoredNode->NMTstate = CO_NMT_UNKNOWN; |
| 195 | #if (((CO_CONFIG_HB_CONS)&CO_CONFIG_HB_CONS_CALLBACK_CHANGE) != 0) \ |
| 196 | || (((CO_CONFIG_HB_CONS)&CO_CONFIG_HB_CONS_CALLBACK_MULTI) != 0) |
| 197 | monitoredNode->NMTstatePrev = CO_NMT_UNKNOWN; |
| 198 | #endif |
| 199 | CO_FLAG_CLEAR(monitoredNode->CANrxNew); |
| 200 | |
| 201 | /* is channel used */ |
| 202 | if ((monitoredNode->nodeId != 0U) && (monitoredNode->time_us != 0U)) { |
| 203 | COB_ID = monitoredNode->nodeId + (uint16_t)CO_CAN_ID_HEARTBEAT; |
| 204 | monitoredNode->HBstate = CO_HBconsumer_UNKNOWN; |
| 205 | } else { |
| 206 | COB_ID = 0; |
| 207 | monitoredNode->time_us = 0; |
| 208 | monitoredNode->HBstate = CO_HBconsumer_UNCONFIGURED; |
| 209 | } |
| 210 | |
| 211 | /* configure Heartbeat consumer (or disable) CAN reception */ |
| 212 | ret = CO_CANrxBufferInit(HBcons->CANdevRx, HBcons->CANdevRxIdxStart + idx, COB_ID, 0x7FF, false, |
| 213 | (void*)&HBcons->monitoredNodes[idx], CO_HBcons_receive); |
| 214 | } |
| 215 | return ret; |
| 216 | } |
| 217 | |
| 218 | #if ((CO_CONFIG_HB_CONS)&CO_CONFIG_FLAG_CALLBACK_PRE) != 0 |
| 219 | void |
no test coverage detected