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

Function OD_read_1003

301/CO_Emergency.c:158–192  ·  view source on GitHub ↗

* Custom functions for read/write OD object _OD_statusBits_, optional * * For more information see file CO_ODinterface.h, OD_IO_t. */

Source from the content-addressed store, hash-verified

156 * For more information see file CO_ODinterface.h, OD_IO_t.
157 */
158static ODR_t
159OD_read_1003(OD_stream_t* stream, void* buf, OD_size_t count, OD_size_t* countRead) {
160 if ((stream == NULL) || (buf == NULL) || (countRead == NULL) || ((count < 4U) && (stream->subIndex > 0U))
161 || (count < 1U)) {
162 return ODR_DEV_INCOMPAT;
163 }
164
165 CO_EM_t* em = (CO_EM_t*)stream->object;
166
167 if (em->fifoSize < 2U) {
168 return ODR_DEV_INCOMPAT;
169 }
170 if (stream->subIndex == 0U) {
171 (void)CO_setUint8(buf, em->fifoCount);
172
173 *countRead = sizeof(uint8_t);
174 return ODR_OK;
175 } else if (stream->subIndex <= em->fifoCount) {
176 /* newest error is reported on subIndex 1 and is stored just behind
177 * fifoWrPtr. Get correct index in FIFO buffer. */
178 int16_t index = (int16_t)em->fifoWrPtr - (int16_t)stream->subIndex;
179 if (index < 0) {
180 index += (int16_t)em->fifoSize;
181 } else if (index >= (int16_t)(em->fifoSize)) {
182 return ODR_DEV_INCOMPAT;
183 } else { /* MISRA C 2004 14.10 */
184 }
185 (void)CO_setUint32(buf, em->fifo[index].msg);
186
187 *countRead = sizeof(uint32_t);
188 return ODR_OK;
189 } else {
190 return ODR_NO_DATA;
191 }
192}
193
194static ODR_t
195OD_write_1003(OD_stream_t* stream, const void* buf, OD_size_t count, OD_size_t* countWritten) {

Callers

nothing calls this directly

Calls 2

CO_setUint8Function · 0.85
CO_setUint32Function · 0.85

Tested by

no test coverage detected