MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / timer_get_time_ns

Function timer_get_time_ns

bsp/loongson/ls1cdev/libraries/ls1c_timer.c:164–185  ·  view source on GitHub ↗

* ��ȡ��ʱ���ӳ�ʼ�������ڵ�ʱ��(ʵ�ּ�ʱ����)����λns * @timer_info Ӳ����ʱ�� * @ret ʱ�䣬��λns */

Source from the content-addressed store, hash-verified

162 * @ret ʱ�䣬��λns
163 */
164unsigned long timer_get_time_ns(timer_info_t *timer_info)
165{
166 unsigned int timer_reg_base = 0;
167 unsigned int cntr = 0; // �Ĵ���CNTR��ֵ
168 unsigned long time_ns = 0; // ʱ�䣬��λns
169 unsigned long timer_clk = 0; // ��ʱ��ʱ��
170
171 // ��ȡ�Ĵ���CNTR��ֵ
172 timer_reg_base = timer_get_reg_base(timer_info->timer);
173 cntr = reg_read_32((volatile unsigned int *)(timer_reg_base + LS1C_PWM_CNTR));
174
175 /*
176 * ��CNTRֵ����Ϊʱ�䣬��λus
177 * ʱ�� = (������ֵCNTR * 1000000000) / ��ʱ��ʱ��Ƶ��
178 * Ϊ�������������ֶ��Ż���ʽΪ ʱ�� = (������ֵCNTR * 1000) / (��ʱ��ʱ��Ƶ�� / 1000000)
179 */
180 timer_clk = clk_get_apb_rate();
181 time_ns = (cntr * 1000 ) / (timer_clk /1000000);
182// printf("[%s] time_us=%lu, cntr=%d, timer_clk=%d\n", __FUNCTION__, time_ns, cntr, timer_clk);
183
184 return time_ns;
185}
186
187/*
188 * ��ӡtimer��ؼĴ�����ֵ

Callers

nothing calls this directly

Calls 3

timer_get_reg_baseFunction · 0.85
reg_read_32Function · 0.70
clk_get_apb_rateFunction · 0.70

Tested by

no test coverage detected