| 152 | #endif |
| 153 | |
| 154 | bool_t |
| 155 | CO_TIME_process(CO_TIME_t* TIME, bool_t NMTisPreOrOperational, uint32_t timeDifference_us) { |
| 156 | bool_t timestampReceived = false; |
| 157 | |
| 158 | /* Was TIME stamp message just received */ |
| 159 | if (NMTisPreOrOperational && TIME->isConsumer) { |
| 160 | if (CO_FLAG_READ(TIME->CANrxNew)) { |
| 161 | uint32_t ms_swapped = CO_getUint32(&TIME->timeStamp[0]); |
| 162 | uint16_t days_swapped = CO_getUint16(&TIME->timeStamp[4]); |
| 163 | TIME->ms = CO_SWAP_32(ms_swapped) & 0x0FFFFFFFU; |
| 164 | TIME->days = CO_SWAP_16(days_swapped); |
| 165 | TIME->residual_us = 0; |
| 166 | timestampReceived = true; |
| 167 | |
| 168 | CO_FLAG_CLEAR(TIME->CANrxNew); |
| 169 | } |
| 170 | } else { |
| 171 | CO_FLAG_CLEAR(TIME->CANrxNew); |
| 172 | } |
| 173 | |
| 174 | /* Update time */ |
| 175 | uint32_t ms = 0; |
| 176 | if (!timestampReceived && (timeDifference_us > 0U)) { |
| 177 | uint32_t us = timeDifference_us + TIME->residual_us; |
| 178 | ms = us / 1000U; |
| 179 | TIME->residual_us = (uint16_t)(us % 1000U); |
| 180 | TIME->ms += ms; |
| 181 | if (TIME->ms >= ((uint32_t)1000U * 60U * 60U * 24U)) { |
| 182 | TIME->ms -= ((uint32_t)1000U * 60U * 60U * 24U); |
| 183 | TIME->days += 1U; |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | #if ((CO_CONFIG_TIME)&CO_CONFIG_TIME_PRODUCER) != 0 |
| 188 | if (NMTisPreOrOperational && TIME->isProducer && TIME->producerInterval_ms > 0) { |
| 189 | if (TIME->producerTimer_ms >= TIME->producerInterval_ms) { |
| 190 | TIME->producerTimer_ms -= TIME->producerInterval_ms; |
| 191 | |
| 192 | uint32_t ms_swapped = CO_SWAP_32(TIME->ms); |
| 193 | uint16_t days_swapped = CO_SWAP_16(TIME->days); |
| 194 | (void)CO_setUint32(&TIME->CANtxBuff->data[0], ms_swapped); |
| 195 | (void)CO_setUint16(&TIME->CANtxBuff->data[4], days_swapped); |
| 196 | (void)CO_CANsend(TIME->CANdevTx, TIME->CANtxBuff); |
| 197 | } else { |
| 198 | TIME->producerTimer_ms += ms; |
| 199 | } |
| 200 | } else { |
| 201 | TIME->producerTimer_ms = TIME->producerInterval_ms; |
| 202 | } |
| 203 | #endif |
| 204 | |
| 205 | return timestampReceived; |
| 206 | } |
| 207 | |
| 208 | #endif /* (CO_CONFIG_TIME) & CO_CONFIG_TIME_ENABLE */ |
no test coverage detected