* ��ȡ��ʱ���ӳ�ʼ�������ڵ�ʱ��(ʵ�ּ�ʱ����)����λns * @timer_info Ӳ����ʱ�� * @ret ʱ�䣬��λns */
| 162 | * @ret ʱ�䣬��λns |
| 163 | */ |
| 164 | unsigned 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��ؼĴ�����ֵ |
nothing calls this directly
no test coverage detected