MCPcopy Create free account
hub / github.com/CANopenNode/CANopenNode / CO_HBconsumer_init

Function CO_HBconsumer_init

301/CO_HBconsumer.c:104–166  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

102#endif
103
104CO_ReturnError_t
105CO_HBconsumer_init(CO_HBconsumer_t* HBcons, CO_EM_t* em, CO_HBconsNode_t* monitoredNodes, uint8_t monitoredNodesCount,
106 OD_entry_t* OD_1016_HBcons, CO_CANmodule_t* CANdevRx, uint16_t CANdevRxIdxStart, uint32_t* errInfo) {
107 ODR_t odRet;
108
109 /* verify arguments */
110 if ((HBcons == NULL) || (em == NULL) || (monitoredNodes == NULL) || (OD_1016_HBcons == NULL)
111 || (CANdevRx == NULL)) {
112 return CO_ERROR_ILLEGAL_ARGUMENT;
113 }
114
115 /* Configure object variables */
116 (void)memset(HBcons, 0, sizeof(CO_HBconsumer_t));
117 HBcons->em = em;
118 HBcons->monitoredNodes = monitoredNodes;
119 HBcons->CANdevRx = CANdevRx;
120 HBcons->CANdevRxIdxStart = CANdevRxIdxStart;
121
122 /* get actual number of monitored nodes */
123 HBcons->numberOfMonitoredNodes = ((OD_1016_HBcons->subEntriesCount - 1U) < monitoredNodesCount)
124 ? (OD_1016_HBcons->subEntriesCount - 1U)
125 : monitoredNodesCount;
126
127 for (uint8_t i = 0; i < HBcons->numberOfMonitoredNodes; i++) {
128 uint32_t val;
129 odRet = OD_get_u32(OD_1016_HBcons, i + 1U, &val, true);
130 if (odRet != ODR_OK) {
131 if (errInfo != NULL) {
132 *errInfo = OD_getIndex(OD_1016_HBcons);
133 }
134 return CO_ERROR_OD_PARAMETERS;
135 }
136
137 uint8_t nodeId = (uint8_t)((val >> 16) & 0xFFU);
138 uint16_t consumer_time = (uint16_t)(val & 0xFFFFU);
139 CO_ReturnError_t ret = CO_HBconsumer_initEntry(HBcons, i, nodeId, consumer_time);
140 if (ret != CO_ERROR_NO) {
141 if (errInfo != NULL) {
142 *errInfo = OD_getIndex(OD_1016_HBcons);
143 }
144 /* don't break a program, if only value of a parameter is wrong */
145 if (ret != CO_ERROR_OD_PARAMETERS) {
146 return ret;
147 }
148 }
149 }
150
151 /* configure extension for OD */
152#if ((CO_CONFIG_HB_CONS)&CO_CONFIG_FLAG_OD_DYNAMIC) != 0
153 HBcons->OD_1016_extension.object = HBcons;
154 HBcons->OD_1016_extension.read = OD_readOriginal;
155 HBcons->OD_1016_extension.write = OD_write_1016;
156 odRet = OD_extension_init(OD_1016_HBcons, &HBcons->OD_1016_extension);
157 if (odRet != ODR_OK) {
158 if (errInfo != NULL) {
159 *errInfo = OD_getIndex(OD_1016_HBcons);
160 }
161 return CO_ERROR_OD_PARAMETERS;

Callers 1

CO_CANopenInitFunction · 0.85

Calls 4

OD_get_u32Function · 0.85
OD_getIndexFunction · 0.85
CO_HBconsumer_initEntryFunction · 0.85
OD_extension_initFunction · 0.85

Tested by

no test coverage detected