| 731 | } |
| 732 | |
| 733 | CO_SRDO_state_t |
| 734 | CO_SRDO_process(CO_SRDO_t* SRDO, uint32_t timeDifference_us, uint32_t* timerNext_us, bool_t NMTisOperational) { |
| 735 | (void)timerNext_us; /* may be unused */ |
| 736 | |
| 737 | if (NMTisOperational && (SRDO->informationDirection != CO_SRDO_INVALID) && SRDO->SRDOGuard->configurationValid |
| 738 | && (SRDO->internalState >= CO_SRDO_state_unknown)) { |
| 739 | SRDO->cycleTimer = (SRDO->cycleTimer > timeDifference_us) ? (SRDO->cycleTimer - timeDifference_us) : 0U; |
| 740 | SRDO->invertedDelay = (SRDO->invertedDelay > timeDifference_us) ? (SRDO->invertedDelay - timeDifference_us) |
| 741 | : 0U; |
| 742 | SRDO->validationTimer = (SRDO->validationTimer > timeDifference_us) |
| 743 | ? (SRDO->validationTimer - timeDifference_us) |
| 744 | : 0U; |
| 745 | |
| 746 | /* Detect transition to NMT operational */ |
| 747 | if (!SRDO->NMTisOperationalPrevious) { |
| 748 | SRDO->cycleTimer = (SRDO->informationDirection == CO_SRDO_TX) |
| 749 | ? ((uint32_t)SRDO->nodeId * 500U) /* 0.5ms * node-ID delay */ |
| 750 | : SRDO->cycleTime_us; |
| 751 | SRDO->validationTimer = SRDO->cycleTime_us; |
| 752 | SRDO->internalState = CO_SRDO_state_initializing; |
| 753 | SRDO->nextIsNormal = true; |
| 754 | } |
| 755 | |
| 756 | if (SRDO->internalState <= CO_SRDO_state_unknown) { |
| 757 | SRDO->internalState = CO_SRDO_state_error_internal; /* should not happen */ |
| 758 | } else if (SRDO->informationDirection == CO_SRDO_TX) { |
| 759 | if (SRDO->nextIsNormal) { |
| 760 | if (SRDO->cycleTimer == 0U) { |
| 761 | uint8_t* dataSRDO[2] = {&SRDO->CANtxBuff[0]->data[0], &SRDO->CANtxBuff[1]->data[0]}; |
| 762 | size_t verifyLength[2] = {0, 0}; |
| 763 | |
| 764 | /* copy mapped data from Object Dictionary into CAN buffers */ |
| 765 | for (uint8_t i = 0; i < SRDO->mappedObjectsCount; i++) { |
| 766 | uint8_t plain_inverted = i % 2U; |
| 767 | OD_IO_t* OD_IO = &SRDO->OD_IO[i]; |
| 768 | OD_stream_t* stream = &OD_IO->stream; |
| 769 | |
| 770 | /* get mappedLength from temporary storage */ |
| 771 | uint8_t mappedLength = (uint8_t)stream->dataOffset; |
| 772 | |
| 773 | /* additional safety check */ |
| 774 | verifyLength[plain_inverted] += mappedLength; |
| 775 | if (verifyLength[plain_inverted] > CO_SRDO_MAX_SIZE) { |
| 776 | break; |
| 777 | } |
| 778 | |
| 779 | /* length of OD variable may be larger than mappedLength */ |
| 780 | OD_size_t ODdataLength = stream->dataLength; |
| 781 | if (ODdataLength > CO_SRDO_MAX_SIZE) { |
| 782 | ODdataLength = CO_SRDO_MAX_SIZE; |
| 783 | } |
| 784 | /* If mappedLength is smaller than ODdataLength, use auxiliary buffer */ |
| 785 | uint8_t buf[CO_SRDO_MAX_SIZE]; |
| 786 | uint8_t* dataSRDOCopy; |
| 787 | if (ODdataLength > mappedLength) { |
| 788 | (void)memset(buf, 0, sizeof(buf)); |
| 789 | dataSRDOCopy = buf; |
| 790 | } else { |
no test coverage detected