Skip to content

Commit c2e15e0

Browse files
committed
add function rt_hw_1ms_tick_get()
1 parent 3bca2cf commit c2e15e0

File tree

6 files changed

+29
-4
lines changed

6 files changed

+29
-4
lines changed

bsp/stm32/libraries/HAL_Drivers/drv_common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void SysTick_Handler(void)
5858

5959
uint32_t HAL_GetTick(void)
6060
{
61-
return rt_tick_get() * 1000 / RT_TICK_PER_SECOND;
61+
return rt_hw_1ms_tick_get();
6262
}
6363

6464
void HAL_SuspendTick(void)

components/net/lwip-1.4.1/src/arch/sys_arch.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
*/
3333

3434
#include <rtthread.h>
35+
#include <rthw.h>
3536

3637
#include "lwip/sys.h"
3738
#include "lwip/opt.h"
@@ -617,7 +618,7 @@ u32_t sys_jiffies(void)
617618

618619
u32_t sys_now(void)
619620
{
620-
return rt_tick_get() * (1000 / RT_TICK_PER_SECOND);
621+
return rt_hw_1ms_tick_get();
621622
}
622623

623624
#ifdef RT_LWIP_PPP

components/net/lwip-2.0.2/src/arch/sys_arch.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
*/
3333

3434
#include <rtthread.h>
35+
#include <rthw.h>
3536

3637
#include "lwip/sys.h"
3738
#include "lwip/opt.h"
@@ -627,7 +628,7 @@ u32_t sys_jiffies(void)
627628

628629
u32_t sys_now(void)
629630
{
630-
return rt_tick_get() * (1000 / RT_TICK_PER_SECOND);
631+
return rt_hw_1ms_tick_get();
631632
}
632633

633634

components/net/lwip-2.1.2/src/arch/sys_arch.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
*/
3434

3535
#include <rtthread.h>
36+
#include <rthw.h>
3637

3738
#include "lwip/sys.h"
3839
#include "lwip/opt.h"
@@ -641,7 +642,7 @@ u32_t sys_jiffies(void)
641642

642643
u32_t sys_now(void)
643644
{
644-
return rt_tick_get() * (1000 / RT_TICK_PER_SECOND);
645+
return rt_hw_1ms_tick_get();
645646
}
646647

647648
#if MEM_OVERFLOW_CHECK || MEMP_OVERFLOW_CHECK

include/rthw.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ void rt_hw_exception_install(rt_err_t (*exception_handle)(void *context));
134134
*/
135135
void rt_hw_us_delay(rt_uint32_t us);
136136

137+
/*
138+
* provides a tick value ALWAYS in millisecond
139+
*/
140+
rt_tick_t rt_hw_1ms_tick_get(void);
141+
137142
#ifdef RT_USING_SMP
138143
typedef union {
139144
unsigned long slock;

src/clock.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* 2010-07-13 Bernard fix rt_tick_from_millisecond issue found by kuronca
1414
* 2011-06-26 Bernard add rt_tick_set function.
1515
* 2018-11-22 Jesven add per cpu tick
16+
* 2020-12-29 Meco Man add function rt_hw_1ms_tick_get()
1617
*/
1718

1819
#include <rthw.h>
@@ -116,5 +117,21 @@ rt_tick_t rt_tick_from_millisecond(rt_int32_t ms)
116117
}
117118
RTM_EXPORT(rt_tick_from_millisecond);
118119

120+
/**
121+
* This function provides a tick value ALWAYS in millisecond
122+
*
123+
* @return 1ms-based tick
124+
*/
125+
RT_WEAK rt_tick_t rt_hw_1ms_tick_get(void)
126+
{
127+
#if 1000 % RT_TICK_PER_SECOND == 0
128+
return rt_tick_get() * (1000U / RT_TICK_PER_SECOND);
129+
#else
130+
#warning "rt-thread cannot provide a correct 1ms-based tick any longer,\
131+
please redefine this function in another file by using a high-precision hard-timer."
132+
return 0;
133+
#endif
134+
}
135+
119136
/**@}*/
120137

0 commit comments

Comments
 (0)