From 029e161f594ec46eb96ed878ea31f17037740848 Mon Sep 17 00:00:00 2001 From: sundm75 Date: Mon, 24 Dec 2018 18:49:00 +0800 Subject: [BSP][all ls1c]change license to Apache-2.0 [BSP][ls1c] add rtc library [BSP][ls1c] add pwm ,touch , rtc driver --- bsp/ls1cdev/libraries/ls1c_timer.c | 115 ++++++++++++++++++++++++++++++++++--- 1 file changed, 108 insertions(+), 7 deletions(-) (limited to 'bsp/ls1cdev/libraries/ls1c_timer.c') diff --git a/bsp/ls1cdev/libraries/ls1c_timer.c b/bsp/ls1cdev/libraries/ls1c_timer.c index 0075e6e3f6..11cadf18aa 100644 --- a/bsp/ls1cdev/libraries/ls1c_timer.c +++ b/bsp/ls1cdev/libraries/ls1c_timer.c @@ -1,6 +1,15 @@ + /* + * Copyright (c) 2006-2018, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * first version + */ // 硬件定时器源码 - +#include #include "ls1c_public.h" #include "ls1c_pin.h" #include "ls1c_clock.h" @@ -147,8 +156,6 @@ void timer_stop(timer_info_t *timer_info) return ; } - - /* * 获取定时器从初始化到现在的时间(实现计时功能),单位ns * @timer_info 硬件定时器 @@ -172,13 +179,11 @@ unsigned long timer_get_time_ns(timer_info_t *timer_info) */ timer_clk = clk_get_apb_rate(); time_ns = (cntr * 1000 ) / (timer_clk /1000000); -// rt_kprintf("[%s] time_us=%lu, cntr=%d, timer_clk=%d\n", __FUNCTION__, time_ns, cntr, timer_clk); +// printf("[%s] time_us=%lu, cntr=%d, timer_clk=%d\n", __FUNCTION__, time_ns, cntr, timer_clk); return time_ns; } - - /* * 打印timer相关寄存器的值 * @timer_info 硬件定时器 @@ -188,7 +193,7 @@ void timer_print_regs(timer_info_t *timer_info) unsigned int timer_reg_base = 0; timer_reg_base = timer_get_reg_base(timer_info->timer); - rt_kprintf("CNTR=0x%x, HRC=0x%x, LRC=0x%x, CTRL=0x%x\n", + printf("CNTR=0x%x, HRC=0x%x, LRC=0x%x, CTRL=0x%x\n", reg_read_32((volatile unsigned int *)(timer_reg_base + LS1C_PWM_CNTR)), reg_read_32((volatile unsigned int *)(timer_reg_base + LS1C_PWM_HRC)), reg_read_32((volatile unsigned int *)(timer_reg_base + LS1C_PWM_LRC)), @@ -197,4 +202,100 @@ void timer_print_regs(timer_info_t *timer_info) return ; } +/* + * 定时器中断清 + * @timer_info 定时器信息 + */ +void timer_int_clr(timer_info_t *timer_info) +{ + unsigned int timer_reg_base = 0; // 寄存器基地址 + unsigned int ctrl ; + + // 判断入参 + if (NULL == timer_info) + { + return ; + } + timer_reg_base = timer_get_reg_base(timer_info->timer); // 获取寄存器基地址 + ctrl = reg_read_32((volatile unsigned int *)(timer_reg_base + LS1C_PWM_CTRL)); + ctrl = ctrl | (1<timer); // 获取寄存器基地址 + ctrl = reg_read_32((volatile unsigned int *)(timer_reg_base + LS1C_PWM_CTRL)); + ctrl = ctrl | (1<time_ns / 1000); // 将1000000000拆分为1000000和1000 + l_value = MIN(l_value, TIMER_COUNTER_MAX); + h_value = (timer_clk / 1000000) * (timer_info->time_h_ns / 1000); // 将1000000000拆分为1000000和1000 + h_value = MIN(h_value, l_value); + + // 控制寄存器信息 + ctrl = (lrc << LS1C_PWM_INT_LRC_EN) + | (hrc << LS1C_PWM_INT_HRC_EN) + | (0 << LS1C_PWM_CNTR_RST) + | (0 << LS1C_PWM_INT_SR) + | (1 << LS1C_PWM_INTEN) + | (1 << LS1C_PWM_SINGLE) + | (1 << LS1C_PWM_OE) + | (1 << LS1C_PWM_CNT_EN); + + // 设置各个寄存器 + timer_reg_base = timer_get_reg_base(timer_info->timer); // 获取寄存器基地址 + reg_write_32(0, (volatile unsigned int *)(timer_reg_base + LS1C_PWM_HRC)); + reg_write_32(l_value--, (volatile unsigned int *)(timer_reg_base + LS1C_PWM_LRC)); + reg_write_32(h_value--, (volatile unsigned int *)(timer_reg_base + LS1C_PWM_HRC)); + reg_write_32(0, (volatile unsigned int *)(timer_reg_base + LS1C_PWM_CNTR)); + reg_write_32(ctrl, (volatile unsigned int *)(timer_reg_base + LS1C_PWM_CTRL)); + + return ; +} -- cgit v1.3.1