ソースを参照

Improve comments and documentation for code clarity

Co-authored-by: BernardXiong <1241087+BernardXiong@users.noreply.github.com>
copilot-swe-agent[bot] 2 ヶ月 前
コミット
9a3daf23ac

+ 12 - 2
components/drivers/clock_time/src/hrtimer.c

@@ -82,7 +82,11 @@ static unsigned long _cnt_convert(unsigned long cnt)
     unsigned long rtn   = 0;
     unsigned long current_cnt = rt_clock_cputimer_getcnt();
     
-    /* Check for overflow/underflow - if cnt is in the past or wrapped around */
+    /* 
+     * Check if target count is in the past.
+     * For unsigned counters, if cnt <= current_cnt, it means the target
+     * has already passed (or is exactly now).
+     */
     if (cnt <= current_cnt)
     {
         return 0;
@@ -90,7 +94,13 @@ static unsigned long _cnt_convert(unsigned long cnt)
     
     unsigned long count = cnt - current_cnt;
     
-    /* Sanity check: if count is too large, it might be a wrap-around */
+    /* 
+     * Sanity check for wrap-around detection.
+     * If the difference exceeds half the maximum counter value, it's likely
+     * a wrap-around or invalid value. This handles both:
+     * - Forward overflow: count is unreasonably large
+     * - Backward wrap: cnt was in the past but appeared larger due to overflow
+     */
     if (count > (_HRTIMER_MAX_CNT / 2))
         return 0;
 

+ 1 - 2
components/drivers/include/drivers/hwtimer_compat.h

@@ -98,8 +98,7 @@ extern void (*rt_device_hwtimer_us_delay)(rt_uint32_t us);
 
 #else /* !RT_USING_CLOCK_TIME */
 
-#warning "RT_USING_HWTIMER is deprecated. Please migrate to RT_USING_CLOCK_TIME."
-#warning "Include <drivers/clock_time.h> instead and use rt_clock_time_* APIs."
+#warning "RT_USING_HWTIMER is deprecated. Please migrate to RT_USING_CLOCK_TIME. Include <drivers/clock_time.h> instead and use rt_clock_time_* APIs."
 
 /* If clock_time is not enabled, this means the old hwtimer module should still exist */
 /* The build system should handle this by including the old hwtimer directory */