/************************************************************************************************** * @fn macMcuPrecisionCount * * @brief This function is used by higher layer to read a free running counter driven by * MAC timer. * * @param none * * @return overflowCount ************************************************************************************************** */ uint32 macMcuPrecisionCount(void) { uint32 overflowCount = 0; halIntState_t s; HAL_ENTER_CRITICAL_SECTION(s); /* This T2 access macro allows accessing both T2MOVFx and T2Mx */ MAC_MCU_T2_ACCESS_OVF_COUNT_VALUE(); /* Latch the entire T2MOVFx first by reading T2M0. * T2M0 is discarded. */ T2M0; ((uint8 *)&overflowCount)[UINT32_NDX0] = T2MOVF0; ((uint8 *)&overflowCount)[UINT32_NDX1] = T2MOVF1; ((uint8 *)&overflowCount)[UINT32_NDX2] = T2MOVF2; /* the overflowCount needs to account for the accumulated overflow count in Beacon mode. */ overflowCount += accumulatedOverflowCount; HAL_EXIT_CRITICAL_SECTION(s); return(overflowCount); }
/************************************************************************************************** * @fn macMcuPrecisionCount * * @brief This function is used by higher layer to read a free running counter driven by * MAC timer. * * @param none * * @return overflowCount ************************************************************************************************** */ uint32 macMcuPrecisionCount(void) { uint32 overflowCount = 0; halIntState_t s; HAL_ENTER_CRITICAL_SECTION(s); /* This T2 access macro allows accessing both T2MOVFx and T2Mx */ MAC_MCU_T2_ACCESS_OVF_COUNT_VALUE(); /* Latch the entire T2MOVFx first by reading T2M0. * T2M0 is discarded. */ T2M0; ((uint8 *)&overflowCount)[UINT32_NDX0] = (uint8)T2MOVF0; ((uint8 *)&overflowCount)[UINT32_NDX1] = (uint8)T2MOVF1; ((uint8 *)&overflowCount)[UINT32_NDX2] = (uint8)T2MOVF2; ((uint8 *)&overflowCount)[UINT32_NDX3] = 0; /* the overflowCount needs to account for the accumulated overflow count in Beacon mode */ overflowCount += accumulatedOverflowCount; /* * Workaround to take care of the case where a rollover just occured and the call to * macBackoffTimerPeriodIsr() hasn't yet occured or if one rollover occured during * sleep then update the accumulatedoverflowCount with the rollover */ if((prevoverflowCount > overflowCount) && (prevAccumulatedOverflowCount == accumulatedOverflowCount)) { accumulatedOverflowCount += macGetBackOffTimerRollover(); overflowCount += macGetBackOffTimerRollover(); /*don't update the rollover since it has been updated already */ updateRolloverflag = TRUE; } /* store the current value of overflowcount and accumulatedOverflowCount */ prevoverflowCount = overflowCount; prevAccumulatedOverflowCount = accumulatedOverflowCount; HAL_EXIT_CRITICAL_SECTION(s); return(overflowCount); }
/************************************************************************************************** * @fn macMcuOverflowSetCount * * @brief Sets the value of the hardware overflow counter. * * @param count - new overflow count value * * @return none ************************************************************************************************** */ MAC_INTERNAL_API void macMcuOverflowSetCount(uint32 count) { halIntState_t s; MAC_ASSERT(! (count >> 24) ); /* illegal count value */ /* save the current overflow count */ accumulatedOverflowCount += macMcuOverflowCount(); /* deduct the initial count */ accumulatedOverflowCount -= count; HAL_ENTER_CRITICAL_SECTION(s); MAC_MCU_T2_ACCESS_OVF_COUNT_VALUE(); /* for efficiency, the 32-bit value is decoded using endian abstracted indexing */ /* T2OF2 must be written last */ T2MOVF0 = (uint32)((uint8 *)&count)[UINT32_NDX0]; T2MOVF1 = (uint32)((uint8 *)&count)[UINT32_NDX1]; T2MOVF2 = (uint32)((uint8 *)&count)[UINT32_NDX2]; HAL_EXIT_CRITICAL_SECTION(s); }
/************************************************************************************************** * @fn macMcuOverflowCount * * @brief Returns the value of the overflow counter which is a special hardware feature. * The overflow count actually is 24 bits of information. * * @param none * * @return value of overflow counter ************************************************************************************************** */ MAC_INTERNAL_API uint32 macMcuOverflowCount(void) { uint32 overflowCount; halIntState_t s; /* for efficiency, the 32-bit value is encoded using endian abstracted indexing */ HAL_ENTER_CRITICAL_SECTION(s); /* This T2 access macro allows accessing both T2MOVFx and T2Mx */ MAC_MCU_T2_ACCESS_OVF_COUNT_VALUE(); /* Latch the entire T2MOVFx first by reading T2M0. */ T2M0; ((uint8 *)&overflowCount)[UINT32_NDX0] = T2MOVF0; ((uint8 *)&overflowCount)[UINT32_NDX1] = T2MOVF1; ((uint8 *)&overflowCount)[UINT32_NDX2] = T2MOVF2; ((uint8 *)&overflowCount)[UINT32_NDX3] = 0; HAL_EXIT_CRITICAL_SECTION(s); return (overflowCount); }