summaryrefslogtreecommitdiff
path: root/bsp/ls1cdev/libraries
diff options
context:
space:
mode:
authorxph <[email protected]>2020-04-09 16:35:28 +0800
committerGitHub <[email protected]>2020-04-09 16:35:28 +0800
commitca7f01d79b3e0a997c771cec298e4ebd65b75809 (patch)
tree3d2c48aae7203b14038ba7b98b500b5343ed7f2a /bsp/ls1cdev/libraries
parentf763f8e7284b0492c5a65ad0abf94ee1963d7dcc (diff)
parentbaa3145bfe61b3330b6a160523cc5470fa5db3a7 (diff)
Merge pull request #1 from RT-Thread/master
sync rtt
Diffstat (limited to 'bsp/ls1cdev/libraries')
-rw-r--r--bsp/ls1cdev/libraries/ls1c_can.c25
-rw-r--r--bsp/ls1cdev/libraries/ls1c_can.h21
-rw-r--r--bsp/ls1cdev/libraries/ls1c_clock.c46
-rw-r--r--bsp/ls1cdev/libraries/ls1c_clock.h10
-rw-r--r--bsp/ls1cdev/libraries/ls1c_delay.c25
-rw-r--r--bsp/ls1cdev/libraries/ls1c_delay.h11
-rw-r--r--bsp/ls1cdev/libraries/ls1c_gpio.c88
-rw-r--r--bsp/ls1cdev/libraries/ls1c_gpio.h9
-rw-r--r--bsp/ls1cdev/libraries/ls1c_i2c.c18
-rw-r--r--bsp/ls1cdev/libraries/ls1c_i2c.h18
-rw-r--r--bsp/ls1cdev/libraries/ls1c_pin.c10
-rw-r--r--bsp/ls1cdev/libraries/ls1c_pin.h10
-rw-r--r--bsp/ls1cdev/libraries/ls1c_public.c10
-rw-r--r--bsp/ls1cdev/libraries/ls1c_public.h58
-rw-r--r--bsp/ls1cdev/libraries/ls1c_pwm.c16
-rw-r--r--bsp/ls1cdev/libraries/ls1c_pwm.h9
-rw-r--r--bsp/ls1cdev/libraries/ls1c_regs.h12
-rw-r--r--bsp/ls1cdev/libraries/ls1c_rtc.c102
-rw-r--r--bsp/ls1cdev/libraries/ls1c_rtc.h41
-rw-r--r--bsp/ls1cdev/libraries/ls1c_spi.c31
-rw-r--r--bsp/ls1cdev/libraries/ls1c_spi.h102
-rw-r--r--bsp/ls1cdev/libraries/ls1c_timer.c115
-rw-r--r--bsp/ls1cdev/libraries/ls1c_timer.h36
-rw-r--r--bsp/ls1cdev/libraries/ls1c_uart.c9
-rw-r--r--bsp/ls1cdev/libraries/ls1c_uart.h9
-rw-r--r--bsp/ls1cdev/libraries/ls1c_wdog.c91
-rw-r--r--bsp/ls1cdev/libraries/ls1c_wdog.h32
27 files changed, 695 insertions, 269 deletions
diff --git a/bsp/ls1cdev/libraries/ls1c_can.c b/bsp/ls1cdev/libraries/ls1c_can.c
index f113e60990..437ef3ba84 100644
--- a/bsp/ls1cdev/libraries/ls1c_can.c
+++ b/bsp/ls1cdev/libraries/ls1c_can.c
@@ -1,21 +1,7 @@
/*
- * File : ls1c_can.c
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team
+ * Copyright (c) 2006-2018, RT-Thread Development Team
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
@@ -25,6 +11,7 @@
#include "ls1c.h"
#include "ls1c_public.h"
#include "ls1c_can.h"
+#include "ls1c_delay.h"
unsigned char set_reset_mode(CAN_TypeDef* CANx)
{
@@ -51,7 +38,7 @@ unsigned char set_reset_mode(CAN_TypeDef* CANx)
/*检查复位标志*/
status = CANx->MOD;
}
- rt_kprintf("\r\nSetting SJA1000 into reset mode failed!\r\n");
+ printf("\r\nSetting SJA1000 into reset mode failed!\r\n");
return 0;
}
@@ -77,7 +64,7 @@ static unsigned char set_normal_mode(CAN_TypeDef* CANx)
delay_us(10);
status = CANx->MOD;
}
- rt_kprintf("\r\nSetting SJA1000 into normal mode failed!\r\n");
+ printf("\r\nSetting SJA1000 into normal mode failed!\r\n");
return 0;
}
@@ -102,7 +89,7 @@ unsigned char CAN_Init(CAN_TypeDef* CANx, CAN_InitTypeDef* CAN_InitStruct)
status = CANx->MOD;
if( status == 0xFF)
{
- rt_kprintf("\n Probe can0 failed \r\n");
+ printf("\n Probe can0 failed \r\n");
return CAN_InitStatus_Failed;
}
diff --git a/bsp/ls1cdev/libraries/ls1c_can.h b/bsp/ls1cdev/libraries/ls1c_can.h
index 4e27a4b075..b2b0f8efa8 100644
--- a/bsp/ls1cdev/libraries/ls1c_can.h
+++ b/bsp/ls1cdev/libraries/ls1c_can.h
@@ -1,22 +1,7 @@
-
/*
- * File : ls1c_can.h
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * Copyright (c) 2006-2018, RT-Thread Development Team
*
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: Apache-2.0
*
* Change Logs: (Pelican Mode)
* Date Author Notes
@@ -221,7 +206,7 @@ unsigned char CAN_Transmit(CAN_TypeDef* CANx, CanTxMsg* TxMessage);
void CAN_Receive(CAN_TypeDef* CANx, CanRxMsg* RxMessage);
unsigned char set_reset_mode(CAN_TypeDef* CANx);
-unsigned char set_start(CAN_TypeDef* CANx);
+unsigned char set_start(CAN_TypeDef* CANx);
#endif
diff --git a/bsp/ls1cdev/libraries/ls1c_clock.c b/bsp/ls1cdev/libraries/ls1c_clock.c
index c038651e8d..1ae621cbbb 100644
--- a/bsp/ls1cdev/libraries/ls1c_clock.c
+++ b/bsp/ls1cdev/libraries/ls1c_clock.c
@@ -1,28 +1,32 @@
-/*************************************************************************
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
*
- * ʱ����غ���
+ * SPDX-License-Identifier: Apache-2.0
*
- *************************************************************************/
+ * Change Logs:
+ * Date Author Notes
+ * 2017-09-06 勤为本 first version
+ */
#include "ls1c_regs.h"
#include "ls1c_public.h"
-// �����Ƶ��
+// 晶振的频率
#define AHB_CLK (24000000)
#define APB_CLK (AHB_CLK)
-// START_FREQ�Ĵ���bits
+// START_FREQ寄存器bits
#define M_PLL_SHIFT (8)
-#define M_PLL (0xff << M_PLL_SHIFT) // PLL��Ƶϵ������������
+#define M_PLL (0xff << M_PLL_SHIFT) // PLL倍频系数的整数部分
#define FRAC_N_SHIFT (16)
-#define FRAC_N (0xff << FRAC_N_SHIFT) // PLL��Ƶϵ����С������
+#define FRAC_N (0xff << FRAC_N_SHIFT) // PLL倍频系数的小数部分
#define DIV_SDRAM_SHIFT (0)
#define DIV_SDRAM (0x3 << DIV_SDRAM_SHIFT)
-// CLK_DIV_PARAM�Ĵ���bits
+// CLK_DIV_PARAM寄存器bits
#define DIV_PIX_EN (0x1 << 31)
#define DIV_PIX (0x7f << 24)
#define DIV_CAM_EN (0x1 << 23)
@@ -42,8 +46,8 @@
/*
- * ��ȡPLLƵ��
- * @ret PLLƵ��
+ * 获取PLL频率
+ * @ret PLL频率
*/
unsigned long clk_get_pll_rate(void)
{
@@ -58,8 +62,8 @@ unsigned long clk_get_pll_rate(void)
/*
- * ��ȡCPUƵ��
- * @ret CPUƵ��
+ * 获取CPU频率
+ * @ret CPU频率
*/
unsigned long clk_get_cpu_rate(void)
{
@@ -69,8 +73,8 @@ unsigned long clk_get_cpu_rate(void)
pll_rate = clk_get_pll_rate();
ctrl = reg_read_32((volatile unsigned int *)LS1C_CLK_DIV_PARAM);
- // ѡ��ʱ����Դ
- if (DIV_CPU_SEL & ctrl) // pll��Ƶ��Ϊʱ���ź�
+ // 选择时钟来源
+ if (DIV_CPU_SEL & ctrl) // pll分频作为时钟信号
{
if (DIV_CPU_EN & ctrl)
{
@@ -81,7 +85,7 @@ unsigned long clk_get_cpu_rate(void)
cpu_rate = pll_rate / 2;
}
}
- else // bypassģʽ��������Ϊʱ������
+ else // bypass模式,晶振作为时钟输入
{
cpu_rate = APB_CLK;
}
@@ -91,8 +95,8 @@ unsigned long clk_get_cpu_rate(void)
/*
- * ��ȡDDRƵ��
- * @ret DDRƵ��
+ * 获取DDR频率
+ * @ret DDR频率
*/
unsigned long clk_get_ddr_rate(void)
{
@@ -125,8 +129,8 @@ unsigned long clk_get_ddr_rate(void)
/*
- * ��ȡAPBƵ��
- * @ret APBƵ��
+ * 获取APB频率
+ * @ret APB频率
*/
unsigned long clk_get_apb_rate(void)
{
@@ -135,8 +139,8 @@ unsigned long clk_get_apb_rate(void)
/*
- * ��ȡDCƵ��
- * @ret DCƵ��
+ * 获取DC频率
+ * @ret DC频率
*/
unsigned long clk_get_dc_rate(void)
{
diff --git a/bsp/ls1cdev/libraries/ls1c_clock.h b/bsp/ls1cdev/libraries/ls1c_clock.h
index 8222350022..3cacb7454a 100644
--- a/bsp/ls1cdev/libraries/ls1c_clock.h
+++ b/bsp/ls1cdev/libraries/ls1c_clock.h
@@ -1,8 +1,12 @@
-/*************************************************************************
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
*
- * ʱ�����ͷ�ļ�
+ * SPDX-License-Identifier: Apache-2.0
*
- *************************************************************************/
+ * Change Logs:
+ * Date Author Notes
+ * 2017-09-06 ���� first version
+ */
#ifndef __OPENLOONGSON_CLOCK_H
diff --git a/bsp/ls1cdev/libraries/ls1c_delay.c b/bsp/ls1cdev/libraries/ls1c_delay.c
index 214926e58e..418a310bf8 100644
--- a/bsp/ls1cdev/libraries/ls1c_delay.c
+++ b/bsp/ls1cdev/libraries/ls1c_delay.c
@@ -1,4 +1,12 @@
-// ������ʱԴ�ļ�
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2017-09-06 ���� first version
+ */
#include "ls1c_clock.h"
@@ -12,7 +20,7 @@
*/
void delay_ms(int j)
{
- int k_max = clk_get_cpu_rate()/1000/3; // ����1000��ʾms������3Ϊ�������õľ���(��������Ϊ���ڲ�ѭ��ִ��һ����Ҫ��ʱ�Ӹ���)
+ int k_max = clk_get_cpu_rate()/1000/92; // ����1000��ʾms������һ������Ϊʵ���õľ���ֵ
int k = k_max;
for ( ; j > 0; j--)
@@ -33,24 +41,25 @@ void delay_ms(int j)
*/
void delay_us(int n)
{
- int count_1us = clk_get_cpu_rate() / 1000000 / 3; // ��ʱ1us��ѭ������
+ int count_1us = 252000000 / 1000000 / 84; // ��ʱ1us��ѭ������
+ // 252000000ΪcpuƵ�ʣ�����1000000��ʾ��ʱ��λΪus��92Ϊʵ���õľ���ֵ
int count_max; // ��ʱn΢���ѭ������
int tmp;
- // ������ʱ����΢��(ע�⣬�������ֶ��Ż��ģ�cpuƵ�ʸı��˿�����Ҫ�����Ż�����ʱcpuƵ��Ϊ252Mhz)
+ // ΢��
+ count_max = n * count_1us;
if (10 >= n) // <=10us
{
- count_1us -= 35;
+ count_max = count_max / 3;
}
else if (100 >= n) // <= 100us
{
- count_1us -= 6;
+ count_max = count_max - count_max / 5;
}
else // > 100us
{
- count_1us -= 1;
+ count_max = count_max - count_max / 10;
}
- count_max = n * count_1us;
// ��ʱ
for (tmp = count_max; tmp > 0; tmp--)
diff --git a/bsp/ls1cdev/libraries/ls1c_delay.h b/bsp/ls1cdev/libraries/ls1c_delay.h
index d6f366de33..15cc1d43b1 100644
--- a/bsp/ls1cdev/libraries/ls1c_delay.h
+++ b/bsp/ls1cdev/libraries/ls1c_delay.h
@@ -1,5 +1,12 @@
-// ������ʱͷ�ļ�
-
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2017-09-06 ���� first version
+ */
#ifndef __OPENLOONGSON_DELAY_H
diff --git a/bsp/ls1cdev/libraries/ls1c_gpio.c b/bsp/ls1cdev/libraries/ls1c_gpio.c
index ee073b7c4b..4bf6b7a20b 100644
--- a/bsp/ls1cdev/libraries/ls1c_gpio.c
+++ b/bsp/ls1cdev/libraries/ls1c_gpio.c
@@ -1,4 +1,12 @@
-// ��װgpio�ӿ�
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2017-09-06 勤为本 first version
+ */
#include "ls1c_public.h"
@@ -8,13 +16,13 @@
/*
- * ��ȡָ��gpio��CFG�Ĵ���
- * @gpio gpio���
- * @ret CFG�Ĵ���
+ * 获取指定gpio的CFG寄存器
+ * @gpio gpio编号
+ * @ret CFG寄存器
*/
volatile unsigned int *gpio_get_cfg_reg(unsigned int gpio)
{
- volatile unsigned int *gpio_cfgx = NULL; // GPIO_CFGx�Ĵ���
+ volatile unsigned int *gpio_cfgx = NULL; // GPIO_CFGx寄存器
unsigned int port = GPIO_GET_PORT(gpio);
switch (port)
@@ -45,13 +53,13 @@ volatile unsigned int *gpio_get_cfg_reg(unsigned int gpio)
/*
- * ��ȡָ��gpio��EN�Ĵ���
- * @gpio gpio���
- * @ret EN�Ĵ���
+ * 获取指定gpio的EN寄存器
+ * @gpio gpio编号
+ * @ret EN寄存器
*/
volatile unsigned int *gpio_get_en_reg(unsigned int gpio)
{
- volatile unsigned int *gpio_enx = NULL; // GPIO_ENx�Ĵ���
+ volatile unsigned int *gpio_enx = NULL; // GPIO_ENx寄存器
unsigned int port = GPIO_GET_PORT(gpio);
switch (port)
@@ -81,28 +89,28 @@ volatile unsigned int *gpio_get_en_reg(unsigned int gpio)
}
/*
- * gpio��ʼ��
- * @gpio gpio���ţ�ȡֵ��Χ[0, 127]
- * @mode gpio�Ĺ���ģʽ(���롢���)
+ * gpio初始化
+ * @gpio gpio引脚,取值范围[0, 127]
+ * @mode gpio的工作模式(输入、输出)
*
- * ��: ��gpio50��ʼ��Ϊ���
+ * 例: 将gpio50初始化为输出
* gpio_init(50, gpio_mode_output);
*/
void gpio_init(unsigned int gpio, gpio_mode_t mode)
{
- volatile unsigned int *gpio_enx = NULL; // GPIO_ENx�Ĵ���
+ volatile unsigned int *gpio_enx = NULL; // GPIO_ENx寄存器
unsigned int pin = GPIO_GET_PIN(gpio);
- // ��pin��Ϊ��ͨGPIO
+ // 将pin设为普通GPIO
pin_set_purpose(gpio, PIN_PURPOSE_GPIO);
- // ����gpio����ģʽ(���롢���)
+ // 设置gpio工作模式(输入、输出)
gpio_enx = gpio_get_en_reg(gpio);
- if (gpio_mode_output == mode) // ���
+ if (gpio_mode_output == mode) // 输出
{
reg_clr_one_bit(gpio_enx, pin);
}
- else // ����
+ else // 输入
{
reg_set_one_bit(gpio_enx, pin);
}
@@ -112,20 +120,20 @@ void gpio_init(unsigned int gpio, gpio_mode_t mode)
/*
- * ��ָ��gpio����ߵ�ƽ��͵�ƽ
- * @gpio gpio���ţ�ȡֵ��Χ[0, 127]
- * @level ��ƽֵ
+ * 在指定gpio输出高电平或低电平
+ * @gpio gpio引脚,取值范围[0, 127]
+ * @level 电平值
*
- * ��: ��gpio50������͵�ƽ
+ * 例: 在gpio50上输出低电平
* gpio_set(50, gpio_level_low);
*/
void gpio_set(unsigned int gpio, gpio_level_t level)
{
- volatile unsigned int *gpio_outx = NULL; // GPIO_OUTx�Ĵ���
+ volatile unsigned int *gpio_outx = NULL; // GPIO_OUTx寄存器
unsigned int port = GPIO_GET_PORT(gpio);
unsigned int pin = GPIO_GET_PIN(gpio);
- // ��ȡ�Ĵ�����ַ
+ // 获取寄存器地址
switch (port)
{
case 0:
@@ -144,11 +152,11 @@ void gpio_set(unsigned int gpio, gpio_level_t level)
gpio_outx = (volatile unsigned int *)LS1C_GPIO_OUT3;
break;
- default: // ��ȷ�ij���Ӧ���ߵ����ֱ�ӷ���
+ default: // 正确的程序不应该走到这里,直接返回
return ;
}
- // ���
+ // 输出
if (gpio_level_low == level)
{
reg_clr_one_bit(gpio_outx, pin);
@@ -163,20 +171,20 @@ void gpio_set(unsigned int gpio, gpio_level_t level)
/*
- * ��ȡָ��gpio���ŵ�ֵ
- * @gpio gpio���ţ�ȡֵ��Χ[0,127]
+ * 读取指定gpio引脚的值
+ * @gpio gpio引脚,取值范围[0,127]
*
- * ��: ��ȡgpio50�����ϵ�ֵ
+ * 例: 读取gpio50引脚上的值
* gpio_level_t level;
* level = gpio_get(50);
*/
unsigned int gpio_get(unsigned int gpio)
{
- volatile unsigned int *gpio_inx = NULL; // GPIO_INx�Ĵ���
+ volatile unsigned int *gpio_inx = NULL; // GPIO_INx寄存器
unsigned int port = GPIO_GET_PORT(gpio);
unsigned int pin = GPIO_GET_PIN(gpio);
- // ��ȡ�Ĵ�����ַ
+ // 获取寄存器地址
switch (port)
{
case 0:
@@ -195,28 +203,28 @@ unsigned int gpio_get(unsigned int gpio)
gpio_inx = (volatile unsigned int *)LS1C_GPIO_IN3;
break;
- default: // ���������̲�Ӧ���ߵ����ֱ�ӷ���
+ default: // 正常的流程不应该走到这里,直接返回
return 0;
}
- // ��ȡ
+ // 读取
return reg_get_bit(gpio_inx, pin);
}
/**
- * ���������
- * @gpio gpio����
- * @type �����жϵ��������ߵ�ƽ�������͵�ƽ�����������ش��� or �½��ش���
+ * 设置中断类型
+ * @gpio gpio引脚
+ * @type 触发中断的条件。高电平触发、低电平触发、上升沿触发 or 下降沿触发
*/
void gpio_set_irq_type(unsigned int gpio, gpio_irq_type_t type)
{
- volatile unsigned int *int_pol = NULL; // �жϼ���ѡ��Ĵ���
- volatile unsigned int *int_edge = NULL; // �жϱ���ѡ��Ĵ���
+ volatile unsigned int *int_pol = NULL; // 中断极性选择寄存器
+ volatile unsigned int *int_edge = NULL; // 中断边沿选择寄存器
unsigned int port = GPIO_GET_PORT(gpio);
unsigned int pin = GPIO_GET_PIN(gpio);
- // ��ȡ�Ĵ�����ַ
+ // 获取寄存器地址
switch (port)
{
case 0: // GPIO[31:0]
@@ -235,7 +243,7 @@ void gpio_set_irq_type(unsigned int gpio, gpio_irq_type_t type)
break;
}
- // ���������
+ // 设置中断类型
switch (type)
{
case IRQ_TYPE_EDGE_RISING:
diff --git a/bsp/ls1cdev/libraries/ls1c_gpio.h b/bsp/ls1cdev/libraries/ls1c_gpio.h
index 1609684bd3..c5c9b12312 100644
--- a/bsp/ls1cdev/libraries/ls1c_gpio.h
+++ b/bsp/ls1cdev/libraries/ls1c_gpio.h
@@ -1,3 +1,12 @@
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2017-09-06 ���� first version
+ */
#ifndef __OPENLOONGSON_GPIO_H
diff --git a/bsp/ls1cdev/libraries/ls1c_i2c.c b/bsp/ls1cdev/libraries/ls1c_i2c.c
index 6a1622471c..11475cf149 100644
--- a/bsp/ls1cdev/libraries/ls1c_i2c.c
+++ b/bsp/ls1cdev/libraries/ls1c_i2c.c
@@ -1,21 +1,7 @@
/*
- * File : ls1c_i2c.c
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
+ * Copyright (c) 2006-2018, RT-Thread Development Team
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
diff --git a/bsp/ls1cdev/libraries/ls1c_i2c.h b/bsp/ls1cdev/libraries/ls1c_i2c.h
index ada22242fb..1fb1ef6941 100644
--- a/bsp/ls1cdev/libraries/ls1c_i2c.h
+++ b/bsp/ls1cdev/libraries/ls1c_i2c.h
@@ -1,21 +1,7 @@
/*
- * File : ls1c_i2c.h
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
+ * Copyright (c) 2006-2018, RT-Thread Development Team
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
diff --git a/bsp/ls1cdev/libraries/ls1c_pin.c b/bsp/ls1cdev/libraries/ls1c_pin.c
index 81f56c0b0c..0a817abe07 100644
--- a/bsp/ls1cdev/libraries/ls1c_pin.c
+++ b/bsp/ls1cdev/libraries/ls1c_pin.c
@@ -1,3 +1,13 @@
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2017-09-06 勤为本 first version
+ */
+
// 引脚功能(普通gpio,pwm,复用等)相关接口
diff --git a/bsp/ls1cdev/libraries/ls1c_pin.h b/bsp/ls1cdev/libraries/ls1c_pin.h
index c483f5659a..26cc4cac92 100644
--- a/bsp/ls1cdev/libraries/ls1c_pin.h
+++ b/bsp/ls1cdev/libraries/ls1c_pin.h
@@ -1,3 +1,13 @@
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2017-09-06 ���� first version
+ */
+
// ���Ź���(��ͨgpio��pwm�����õ�)��ؽӿ�
#ifndef __OPENLOONGSON_PIN_H
diff --git a/bsp/ls1cdev/libraries/ls1c_public.c b/bsp/ls1cdev/libraries/ls1c_public.c
index 3e57e9a50a..3523ced419 100644
--- a/bsp/ls1cdev/libraries/ls1c_public.c
+++ b/bsp/ls1cdev/libraries/ls1c_public.c
@@ -1,3 +1,13 @@
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2017-09-06 ���� first version
+ */
+
// һЩ���õġ����õĽӿ�
/*
diff --git a/bsp/ls1cdev/libraries/ls1c_public.h b/bsp/ls1cdev/libraries/ls1c_public.h
index c06aa4dd8a..5d2390acec 100644
--- a/bsp/ls1cdev/libraries/ls1c_public.h
+++ b/bsp/ls1cdev/libraries/ls1c_public.h
@@ -1,4 +1,14 @@
-// һЩ���õġ����õĽӿ�
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2017-09-06 勤为本 first version
+ */
+
+// 一些常用的、共用的接口
#ifndef __OPENLOONGSON_PUBLIC_H
#define __OPENLOONGSON_PUBLIC_H
@@ -7,7 +17,7 @@
#include <stdio.h>
-// pmon�ṩ�Ĵ�ӡ��������main()����
+// pmon提供的打印函数,见main()函数
struct callvectors {
int (*open) (char *, int, int);
int (*close) (int);
@@ -35,58 +45,58 @@ typedef enum
}BOOL;
/*
- * ��ָ���Ĵ�����ָ��λ��1
- * @reg �Ĵ�����ַ
- * @bit ��Ҫ��1����һbit
+ * 将指定寄存器的指定位置1
+ * @reg 寄存器地址
+ * @bit 需要置1的那一bit
*/
void reg_set_one_bit(volatile unsigned int *reg, unsigned int bit);
/*
- * ��ָ���Ĵ�����ָ��λ����
- * @reg �Ĵ�����ַ
- * @bit ��Ҫ�������һbit
+ * 将指定寄存器的指定位清零
+ * @reg 寄存器地址
+ * @bit 需要清零的那一bit
*/
void reg_clr_one_bit(volatile unsigned int *reg, unsigned int bit);
/*
- * ��ȡָ���Ĵ�����ָ��λ��ֵ
- * @reg �Ĵ�����ַ
- * @bit ��Ҫ��ȡֵ����һbit
- * @ret ָ��λ��ֵ
+ * 获取指定寄存器的指定位的值
+ * @reg 寄存器地址
+ * @bit 需要读取值的那一bit
+ * @ret 指定位的值
*/
unsigned int reg_get_bit(volatile unsigned int *reg, unsigned int bit);
/*
- * ��Ĵ�����д��8bit(һ���ֽ�)����
- * @data ��������
- * @addr �Ĵ�����ַ
+ * 向寄存器中写入8bit(一个字节)数据
+ * @data 待写入的数据
+ * @addr 寄存器地址
*/
void reg_write_8(unsigned char data, volatile unsigned char *addr);
/*
- * �ӼĴ�������8bit(һ���ֽ�)����
- * @addr �Ĵ�����ַ
- * @ret ����������
+ * 从寄存器读出8bit(一个字节)数据
+ * @addr 寄存器地址
+ * @ret 读出的数据
*/
unsigned char reg_read_8(volatile unsigned char *addr);
/*
- * ��Ĵ�����дһ��32bit������
- * @data ��������
- * @addr �Ĵ�����ַ
+ * 向寄存器中写一个32bit的数据
+ * @data 待写入的数据
+ * @addr 寄存器地址
*/
void reg_write_32(unsigned int data, volatile unsigned int *addr);
/*
- * �ӼĴ�������һ��32bit����
- * @addr �Ĵ�����ַ
- * @ret ����������
+ * 从寄存器读出一个32bit数据
+ * @addr 寄存器地址
+ * @ret 读出的数据
*/
unsigned int reg_read_32(volatile unsigned int *addr);
diff --git a/bsp/ls1cdev/libraries/ls1c_pwm.c b/bsp/ls1cdev/libraries/ls1c_pwm.c
index 01ffc6f3a9..b91f81c43b 100644
--- a/bsp/ls1cdev/libraries/ls1c_pwm.c
+++ b/bsp/ls1cdev/libraries/ls1c_pwm.c
@@ -1,3 +1,13 @@
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2017-09-06 ���� first version
+ */
+
// ��װӲ��pwm�ӿ�
#include "ls1c_public.h"
@@ -6,13 +16,9 @@
#include "ls1c_clock.h"
#include "ls1c_regs.h"
-
-
// pwm���������
#define PWM_MAX_PERIOD (0xFFFFFF) // ��������ֵ
-
-
/*
* ����gpio��ȡ��Ӧpwm�Ļ���ַ
* @gpio pwm����
@@ -193,5 +199,3 @@ void pwm_init(pwm_info_t *pwm_info)
return ;
}
-
-
diff --git a/bsp/ls1cdev/libraries/ls1c_pwm.h b/bsp/ls1cdev/libraries/ls1c_pwm.h
index aa9daeeb0c..865a2ddf1d 100644
--- a/bsp/ls1cdev/libraries/ls1c_pwm.h
+++ b/bsp/ls1cdev/libraries/ls1c_pwm.h
@@ -1,3 +1,12 @@
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2017-09-06 ���� first version
+ */
#ifndef __OPENLOONGSON_PWM_H
diff --git a/bsp/ls1cdev/libraries/ls1c_regs.h b/bsp/ls1cdev/libraries/ls1c_regs.h
index 1f8b60ed17..7947c2bfe0 100644
--- a/bsp/ls1cdev/libraries/ls1c_regs.h
+++ b/bsp/ls1cdev/libraries/ls1c_regs.h
@@ -1,3 +1,13 @@
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2017-09-06 勤为本 first version
+ */
+
// 龙芯1c外设寄存器
@@ -139,6 +149,8 @@
#define LS1C_UART10_BASE (0xbfe4ca00)
#define LS1C_UART11_BASE (0xbfe4cb00)
+//RTC寄存器
+#define LS1C_RTC_BASE (0xbfe64024)
#endif
diff --git a/bsp/ls1cdev/libraries/ls1c_rtc.c b/bsp/ls1cdev/libraries/ls1c_rtc.c
new file mode 100644
index 0000000000..838f6a85c1
--- /dev/null
+++ b/bsp/ls1cdev/libraries/ls1c_rtc.c
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2018-05-06 sundm75 first version
+ */
+#include "ls1c.h"
+#include "ls1c_public.h"
+#include "ls1c_rtc.h"
+
+#define LS1C_SEC_OFFSET (4)
+#define LS1C_MIN_OFFSET (10)
+#define LS1C_HOUR_OFFSET (16)
+#define LS1C_DAY_OFFSET (21)
+#define LS1C_MONTH_OFFSET (26)
+
+#define LS1C_SEC_MASK (0x3f)
+#define LS1C_MIN_MASK (0x3f)
+#define LS1C_HOUR_MASK (0x1f)
+#define LS1C_DAY_MASK (0x1f)
+#define LS1C_MONTH_MASK (0x3f)
+#define LS1C_YEAR_MASK (0xff)
+
+#define ls1c_get_sec(t) (((t) >> LS1C_SEC_OFFSET) & LS1C_SEC_MASK)
+#define ls1c_get_min(t) (((t) >> LS1C_MIN_OFFSET) & LS1C_MIN_MASK)
+#define ls1c_get_hour(t) (((t) >> LS1C_HOUR_OFFSET) & LS1C_HOUR_MASK)
+#define ls1c_get_day(t) (((t) >> LS1C_DAY_OFFSET) & LS1C_DAY_MASK)
+#define ls1c_get_month(t) (((t) >> LS1C_MONTH_OFFSET) & LS1C_MONTH_MASK)
+
+int RTC_SetTime(RTC_TypeDef *hrtc, RTC_TimeTypeDef *sTime)
+{
+
+ hrtc->SYS_TOYWRITE0
+ = (sTime->Month << LS1C_MONTH_OFFSET)
+ | (sTime->Date << LS1C_DAY_OFFSET)
+ | (sTime->Hours << LS1C_HOUR_OFFSET)
+ | (sTime->Minutes << LS1C_MIN_OFFSET)
+ | (sTime->Seconds << LS1C_SEC_OFFSET);
+ hrtc->SYS_TOYWRITE1 = sTime->Year % 100;
+ printf("\r\ntoy_read0 = 0x%x, toy_read1 = 0x%x.\r\n", hrtc->SYS_TOYREAD0, hrtc->SYS_TOYREAD1);
+
+ return 0;
+}
+
+int RTC_GetTime(RTC_TypeDef *hrtc, RTC_TimeTypeDef *sTime)
+{
+ unsigned long toy_read0, toy_read1;
+ toy_read0 = hrtc->SYS_TOYREAD0;
+ toy_read1 = hrtc->SYS_TOYREAD1;
+ sTime->Seconds = ls1c_get_sec(toy_read0);
+ sTime->Minutes = ls1c_get_min(toy_read0);
+ sTime->Hours = ls1c_get_hour(toy_read0);
+ sTime->Date = ls1c_get_day(toy_read0);
+ sTime->Month = ls1c_get_month(toy_read0);
+ sTime->Year = toy_read1 & LS1C_YEAR_MASK;
+ return 0 ;
+}
+
+unsigned char RTC_IsLeapYear(unsigned int nYear)
+{
+ if((nYear % 4U) != 0U)
+ {
+ return 0U;
+ }
+
+ if((nYear % 100U) != 0U)
+ {
+ return 1U;
+ }
+
+ if((nYear % 400U) == 0U)
+ {
+ return 1U;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+unsigned char RTC_WeekDayNum(unsigned long nYear, unsigned char nMonth, unsigned char nDay)
+{
+ unsigned long year = 0U, weekday = 0U;
+
+ year = 2000U + nYear;
+
+ if(nMonth < 3U)
+ {
+ /*D = { [(23 x month)/9] + day + 4 + year + [(year-1)/4] - [(year-1)/100] + [(year-1)/400] } mod 7*/
+ weekday = (((23U * nMonth)/9U) + nDay + 4U + year + ((year-1U)/4U) - ((year-1U)/100U) + ((year-1U)/400U)) % 7U;
+ }
+ else
+ {
+ /*D = { [(23 x month)/9] + day + 4 + year + [year/4] - [year/100] + [year/400] - 2 } mod 7*/
+ weekday = (((23U * nMonth)/9U) + nDay + 4U + year + (year/4U) - (year/100U) + (year/400U) - 2U ) % 7U;
+ }
+
+ return (unsigned char)weekday;
+}
diff --git a/bsp/ls1cdev/libraries/ls1c_rtc.h b/bsp/ls1cdev/libraries/ls1c_rtc.h
new file mode 100644
index 0000000000..dee8000d6b
--- /dev/null
+++ b/bsp/ls1cdev/libraries/ls1c_rtc.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2018-05-06 sundm75 first version
+ */
+
+ #ifndef __OPENLOONGSON_RTC_H
+#define __OPENLOONGSON_RTC_H
+
+
+#define RTC ( (RTC_TypeDef* )LS1C_RTC_BASE)
+
+typedef struct
+{
+ unsigned char Year; /*0 ~ 99 */
+ unsigned char Month; /*1 ~ 12 */
+ unsigned char Date; /*1 ~ 31 */
+ unsigned char Hours; /*0 ~ 23 */
+ unsigned char Minutes; /*0 ~ 59 */
+ unsigned char Seconds; /*0 ~ 59 */
+}RTC_TimeTypeDef;
+
+typedef struct
+{
+ unsigned long SYS_TOYWRITE0;
+ unsigned long SYS_TOYWRITE1;
+ unsigned long SYS_TOYREAD0;
+ unsigned long SYS_TOYREAD1;
+} RTC_TypeDef;
+
+int RTC_SetTime(RTC_TypeDef *hrtc, RTC_TimeTypeDef *sTime);
+int RTC_GetTime(RTC_TypeDef *hrtc, RTC_TimeTypeDef *sTime);
+
+unsigned char RTC_IsLeapYear(unsigned int nYear);
+unsigned char RTC_WeekDayNum(unsigned long nYear, unsigned char nMonth, unsigned char nDay);
+
+#endif
diff --git a/bsp/ls1cdev/libraries/ls1c_spi.c b/bsp/ls1cdev/libraries/ls1c_spi.c
index eff1deb74f..6ad39d964c 100644
--- a/bsp/ls1cdev/libraries/ls1c_spi.c
+++ b/bsp/ls1cdev/libraries/ls1c_spi.c
@@ -1,21 +1,7 @@
/*
- * File : ls1c_spi.c
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
+ * Copyright (c) 2006-2018, RT-Thread Development Team
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
@@ -24,7 +10,6 @@
// 硬件spi接口源文件
-
#include <string.h>
#include "ls1c_public.h"
#include "ls1c_regs.h"
@@ -38,7 +23,7 @@
* 获取指定SPI模块的基地址
* @SPIx SPI模块的编号
*/
-inline void *ls1c_spi_get_base(unsigned char SPIx)
+void *ls1c_spi_get_base(unsigned char SPIx)
{
void *base = NULL;
@@ -67,7 +52,7 @@ inline void *ls1c_spi_get_base(unsigned char SPIx)
*/
void ls1c_spi_print_all_regs_info(void *spi_base)
{
- rt_kprintf("[%s] SPCR=0x%x, SPSR=0x%x, SPER=0x%x, SFC_PARAM=0x%x, SFC_SOFTCS=0x%x, SFC_TIMING=0x%x\r\n",
+ printf("[%s] SPCR=0x%x, SPSR=0x%x, SPER=0x%x, SFC_PARAM=0x%x, SFC_SOFTCS=0x%x, SFC_TIMING=0x%x\r\n",
__FUNCTION__,
reg_read_8(spi_base + LS1C_SPI_SPCR_OFFSET),
reg_read_8(spi_base + LS1C_SPI_SPSR_OFFSET),
@@ -137,7 +122,7 @@ unsigned int ls1c_spi_get_div(unsigned int max_speed_hz)
break;
}
/*
- rt_kprintf("[%s] clk=%ld, max_speed_hz=%d, div_tmp=%d, bit=%d\r\n",
+ printf("[%s] clk=%ld, max_speed_hz=%d, div_tmp=%d, bit=%d\r\n",
__FUNCTION__, clk, max_speed_hz, div_tmp, bit);
*/
return div_tmp;
@@ -229,7 +214,7 @@ void ls1c_spi_set_cs(void *spi_base, unsigned char cs, int new_status)
* 等待收发完成
* @spi_base 基地址
*/
-inline void ls1c_spi_wait_txrx_done(void *spi_base)
+void ls1c_spi_wait_txrx_done(void *spi_base)
{
int timeout = LS1C_SPI_TX_TIMEOUT;
@@ -247,7 +232,7 @@ inline void ls1c_spi_wait_txrx_done(void *spi_base)
* 清中断和标志位
* @spi_base 基地址
*/
-inline void ls1c_spi_clear(void *spi_base)
+void ls1c_spi_clear(void *spi_base)
{
unsigned char val = 0;
@@ -260,7 +245,7 @@ inline void ls1c_spi_clear(void *spi_base)
val = reg_read_8(spi_base + LS1C_SPI_SPSR_OFFSET);
if (LS1C_SPI_SPSR_WCOL_MASK & val)
{
- rt_kprintf("[%s] clear register SPSR's wcol!\r\n",__FUNCTION__); // 手册和linux源码中不一样,加个打印看看
+ printf("[%s] clear register SPSR's wcol!\r\n"); // 手册和linux源码中不一样,加个打印看看
reg_write_8(val & ~LS1C_SPI_SPSR_WCOL_MASK, spi_base + LS1C_SPI_SPSR_OFFSET); // 写0,linux源码中是写0
// reg_write_8(val | LS1C_SPI_SPSR_WCOL_MASK, spi_base + LS1C_SPI_SPSR_OFFSET); // 写1,按照1c手册,应该写1
}
diff --git a/bsp/ls1cdev/libraries/ls1c_spi.h b/bsp/ls1cdev/libraries/ls1c_spi.h
index 8046127de7..bd02dd8d17 100644
--- a/bsp/ls1cdev/libraries/ls1c_spi.h
+++ b/bsp/ls1cdev/libraries/ls1c_spi.h
@@ -1,61 +1,47 @@
/*
- * File : ls1c_spi.h
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
+ * Copyright (c) 2006-2018, RT-Thread Development Team
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
- * 2017-10-23 ���� first version
+ * 2017-10-23 勤为本 first version
*/
-// Ӳ��spi�ӿڵ�ͷ�ļ�
+// 硬件spi接口的头文件
#ifndef __OPENLOONGSON_SPI_H
#define __OPENLOONGSON_SPI_H
-// SPI���
+// SPI模块编号
#define LS1C_SPI_0 (0)
#define LS1C_SPI_1 (1)
-// Ƭѡ
+// 片选
#define LS1C_SPI_CS_0 (0)
#define LS1C_SPI_CS_1 (1)
#define LS1C_SPI_CS_2 (2)
#define LS1C_SPI_CS_3 (3)
-// ʱ�Ӽ��Ժ���λ
+// 时钟极性和相位
#define SPI_CPOL_1 (1)
#define SPI_CPOL_0 (0)
#define SPI_CPHA_1 (1)
#define SPI_CPHA_0 (0)
-// �Ĵ���ƫ��
-#define LS1C_SPI_SPCR_OFFSET (0) // ���ƼĴ���
-#define LS1C_SPI_SPSR_OFFSET (1) // ״̬�Ĵ���
-#define LS1C_SPI_TxFIFO_OFFSET (2) // ���͵����ݼĴ�������������ݼĴ�����ƫ����ͬ
-#define LS1C_SPI_RxFIFO_OFFSET (2) // ���յ����ݼĴ������뷢�����ݼĴ�����ƫ����ͬ
-#define LS1C_SPI_SPER_OFFSET (3) // �ⲿ�Ĵ���
-#define LS1C_SPI_SFC_PARAM_OFFSET (4) // �������ƼĴ���
-#define LS1C_SPI_SFC_SOFTCS_OFFSET (5) // Ƭѡ���ƼĴ���
-#define LS1C_SPI_SFC_TIMING_OFFSET (6) // ʱ����ƼĴ���
+// 寄存器偏移
+#define LS1C_SPI_SPCR_OFFSET (0) // 控制寄存器
+#define LS1C_SPI_SPSR_OFFSET (1) // 状态寄存器
+#define LS1C_SPI_TxFIFO_OFFSET (2) // 发送的数据寄存器,与接收数据寄存器的偏移相同
+#define LS1C_SPI_RxFIFO_OFFSET (2) // 接收的数据寄存器,与发送数据寄存器的偏移相同
+#define LS1C_SPI_SPER_OFFSET (3) // 外部寄存器
+#define LS1C_SPI_SFC_PARAM_OFFSET (4) // 参数控制寄存器
+#define LS1C_SPI_SFC_SOFTCS_OFFSET (5) // 片选控制寄存器
+#define LS1C_SPI_SFC_TIMING_OFFSET (6) // 时序控制寄存器
-// �Ĵ���SPCR�е�λ��
+// 寄存器SPCR中的位域
#define LS1C_SPI_SPCR_SPIE_BIT (7)
#define LS1C_SPI_SPCR_SPIE_MASK (0x01 << LS1C_SPI_SPCR_SPIE_BIT)
#define LS1C_SPI_SPCR_SPE_BIT (6)
@@ -67,75 +53,75 @@
#define LS1C_SPI_SPCR_SPR_BIT (0)
#define LS1C_SPI_SPCR_SPR_MASK (0x03 << LS1C_SPI_SPCR_SPR_BIT)
-// �Ĵ���SPSR�е�λ��
+// 寄存器SPSR中的位域
#define LS1C_SPI_SPSR_SPIF_BIT (7)
#define LS1C_SPI_SPSR_SPIF_MASK (0x01 << LS1C_SPI_SPSR_SPIF_BIT)
#define LS1C_SPI_SPSR_WCOL_BIT (6)
#define LS1C_SPI_SPSR_WCOL_MASK (0x01 << LS1C_SPI_SPSR_WCOL_BIT)
-// �Ĵ���SPER�е�λ��
+// 寄存器SPER中的位域
#define LS1C_SPI_SPER_SPRE_BIT (0)
#define LS1C_SPI_SPER_SPRE_MASK (0x3 << LS1C_SPI_SPER_SPRE_BIT)
-// �Ĵ���SFC_SOFTCS��λ��
+// 寄存器SFC_SOFTCS的位域
#define LS1C_SPI_SFC_SOFTCS_CSN_BIT (4)
#define LS1C_SPI_SFC_SOFTCS_CSN_MASK (0x0f << LS1C_SPI_SFC_SOFTCS_CSN_BIT)
#define LS1C_SPI_SFC_SOFTCS_CSEN_BIT (0)
#define LS1C_SPI_SFC_SOFTCS_CSEN_MASK (0x0f << LS1C_SPI_SFC_SOFTCS_CSEN_BIT)
-// ���ͳ�ʱ������ֵ
+// 发送超时的门限值
#define LS1C_SPI_TX_TIMEOUT (20000)
/*
- * ��ȡָ��SPIģ��Ļ���ַ
- * @SPIx SPIģ��ı��
+ * 获取指定SPI模块的基地址
+ * @SPIx SPI模块的编号
*/
-inline void *ls1c_spi_get_base(unsigned char SPIx);
+void *ls1c_spi_get_base(unsigned char SPIx);
/*
- * ����ʱ��
- * @spi_base ����ַ
- * @max_hz ���Ƶ�ʣ���λhz
+ * 设置时钟
+ * @spi_base 基地址
+ * @max_hz 最大频率,单位hz
*/
void ls1c_spi_set_clock(void *spi_base, unsigned long max_hz);
/*
- * ����ͨ��ģʽ(ʱ�Ӽ��Ժ���λ)
- * @spi_base ����ַ
- * @cpol ʱ�Ӽ���
- * @cpha ʱ����λ
+ * 设置通信模式(时钟极性和相位)
+ * @spi_base 基地址
+ * @cpol 时钟极性
+ * @cpha 时钟相位
*/
void ls1c_spi_set_mode(void *spi_base, unsigned char cpol, unsigned char cpha);
/*
- * ����ָ��ƬѡΪָ��״̬
- * @spi_base ����ַ
- * @cs Ƭѡ
- * @new_status Ƭѡ���ŵ���״̬��ȡֵΪ0��1�����ߵ�ƽ��͵�ƽ
+ * 设置指定片选为指定状态
+ * @spi_base 基地址
+ * @cs 片选
+ * @new_status 片选引脚的新状态,取值为0或1,即高电平或低电平
*/
void ls1c_spi_set_cs(void *spi_base, unsigned char cs, int new_status);
/*
- * ͨ��ָ��SPI���ͽ���һ���ֽ�
- * ע�⣬�ڶ������ϵͳ�У��˺�����Ҫ���⡣
- * ����֤�ں�ij�����豸�շ�ij���ֽڵĹ����У����ܱ��л�����������ͬʱ���������ͬһ��SPI�����ϵĴ��豸ͨ��
- * ��Ϊ��о1c��ÿ·SPI�Ͽ��ܽ��в�ͬ�Ĵ��豸��ͨ��Ƶ�ʡ�ģʽ�ȿ��ܲ�ͬ
- * @spi_base ����ַ
- * @tx_ch �����͵�����
- * @ret �յ�������
+ * 通过指定SPI发送接收一个字节
+ * 注意,在多任务的系统中,此函数需要互斥。
+ * 即保证在和某个从设备收发某个字节的过程中,不能被切换到其它任务同时与另外的在同一个SPI总线上的从设备通信
+ * 因为龙芯1c的每路SPI上可能接有不同的从设备,通信频率、模式等可能不同
+ * @spi_base 基地址
+ * @tx_ch 待发送的数据
+ * @ret 收到的数据
*/
unsigned char ls1c_spi_txrx_byte(void *spi_base, unsigned char tx_ch);
/*
- * ��ӡָ��SPIģ������мĴ�����ֵ
- * @spi_base ����ַ
+ * 打印指定SPI模块的所有寄存器的值
+ * @spi_base 基地址
*/
void ls1c_spi_print_all_regs_info(void *spi_base);
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 <ls1c.h>
#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<<LS1C_PWM_INT_SR) ;
+ reg_write_32(ctrl , (volatile unsigned int *)(timer_reg_base + LS1C_PWM_CTRL));
+ ctrl = ctrl & (~(1<<LS1C_PWM_INT_SR)) ;
+ reg_write_32(ctrl , (volatile unsigned int *)(timer_reg_base + LS1C_PWM_CTRL));
+ return ;
+}
+/*
+ * ��ʱ��������
+ * @timer_info ��ʱ����Ϣ
+ */
+void timer_cnt_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<<LS1C_PWM_CNTR_RST);
+ reg_write_32(ctrl , (volatile unsigned int *)(timer_reg_base + LS1C_PWM_CTRL));
+ ctrl = ctrl & (~(1<<LS1C_PWM_CNTR_RST)) ;
+ reg_write_32(ctrl , (volatile unsigned int *)(timer_reg_base + LS1C_PWM_CTRL));
+
+ return ;
+}
+
+/*
+ * ��ʼ����ʱ��������ʼ�ж϶�ʱ
+ * @timer_info ��ʱ���Ͷ�ʱʱ����Ϣ
+ * @hrc ���ж� lrc ���ж� Ϊ1�򿪣�Ϊ0�ر�
+*/
+void timer_int_init(timer_info_t *timer_info, int hrc, int lrc)
+{
+ unsigned int timer_reg_base = 0; // �Ĵ�������ַ
+ unsigned long timer_clk = 0; // Ӳ����ʱ����ʱ��
+ unsigned long h_value, l_value;
+ unsigned int ctrl = 0; // ���ƼĴ����еĿ�����Ϣ
+
+ // ����
+ if (NULL == timer_info)
+ {
+ return ;
+ }
+
+ /*
+ * �Ѷ�ʱʱ�任��Ϊ��������ֵ
+ * ������ֵ = ��ʱ����ʱ�� * ��ʱʱ��(��λns) / 1000000000
+ * ��о1c�Ķ�ʱ��ʱ��ΪAPBʱ�ӣ��ﵽ126Mhz��
+ * Ϊ���������̷����������������ֶ��Ż�����ļ���ʽ��Ҳ���Բ��ø�������
+ */
+ timer_clk = clk_get_apb_rate();
+ l_value = (timer_clk / 1000000) * (timer_info->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 ;
+}
diff --git a/bsp/ls1cdev/libraries/ls1c_timer.h b/bsp/ls1cdev/libraries/ls1c_timer.h
index df38c705f5..9f3f86d5d5 100644
--- a/bsp/ls1cdev/libraries/ls1c_timer.h
+++ b/bsp/ls1cdev/libraries/ls1c_timer.h
@@ -1,3 +1,12 @@
+ /*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * first version
+ */
// Ӳ����ʱ��ͷ�ļ�
@@ -22,18 +31,16 @@ typedef enum
typedef struct
{
ls1c_timer_t timer; // Ӳ����ʱ��
- unsigned long time_ns; // ��ʱʱ��
+ unsigned long time_ns; // �Ͷ�ʱʱ��
+ unsigned long time_h_ns; // �߶�ʱʱ��
}timer_info_t;
-
-
/*
* ��ʼ����ʱ��������ʼ��ʱ
* @timer_info ��ʱ���Ͷ�ʱʱ����Ϣ
*/
void timer_init(timer_info_t *timer_info);
-
/*
* �ж�ָ����ʱ���Ƿ�ʱ
* @timer_info ��ʱ��
@@ -41,15 +48,12 @@ void timer_init(timer_info_t *timer_info);
*/
BOOL timer_is_time_out(timer_info_t *timer_info);
-
/*
* ֹͣ��ʱ��
* @timer_info ��ʱ��
*/
void timer_stop(timer_info_t *timer_info);
-
-
/*
* ��ȡ��ʱ���ӳ�ʼ�������ڵ�ʱ��(ʵ�ּ�ʱ����)����λns
* @timer_info Ӳ����ʱ��
@@ -57,13 +61,29 @@ void timer_stop(timer_info_t *timer_info);
*/
unsigned long timer_get_time_ns(timer_info_t *timer_info);
-
/*
* ��ӡtimer��ؼĴ�����ֵ
* @timer_info Ӳ����ʱ��
*/
void timer_print_regs(timer_info_t *timer_info);
+/*
+ * ��ʱ���ж���
+ * @timer_info ��ʱ����Ϣ
+ */
+void timer_int_clr(timer_info_t *timer_info);
+/*
+ * ��ʱ��������
+ * @timer_info ��ʱ����Ϣ
+ */
+void timer_cnt_clr(timer_info_t *timer_info);
+
+/*
+ * ��ʼ����ʱ��������ʼ�ж϶�ʱ
+ * @timer_info ��ʱ���Ͷ�ʱʱ����Ϣ
+ * @hrc ���ж� lrc ���ж� Ϊ1�򿪣�Ϊ0�ر�
+*/
+void timer_int_init(timer_info_t *timer_info, int hrc, int lrc);
#endif
diff --git a/bsp/ls1cdev/libraries/ls1c_uart.c b/bsp/ls1cdev/libraries/ls1c_uart.c
index baa3b6e3ac..fac2010964 100644
--- a/bsp/ls1cdev/libraries/ls1c_uart.c
+++ b/bsp/ls1cdev/libraries/ls1c_uart.c
@@ -1,3 +1,12 @@
+ /*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * first version
+ */
// 串口相关源码
#include <stdio.h>
diff --git a/bsp/ls1cdev/libraries/ls1c_uart.h b/bsp/ls1cdev/libraries/ls1c_uart.h
index 7d63033684..8d017dd767 100644
--- a/bsp/ls1cdev/libraries/ls1c_uart.h
+++ b/bsp/ls1cdev/libraries/ls1c_uart.h
@@ -1,3 +1,12 @@
+ /*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * first version
+ */
// 串口相关头文件
diff --git a/bsp/ls1cdev/libraries/ls1c_wdog.c b/bsp/ls1cdev/libraries/ls1c_wdog.c
new file mode 100644
index 0000000000..4034281d10
--- /dev/null
+++ b/bsp/ls1cdev/libraries/ls1c_wdog.c
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2019-05-06 sundm75 first version
+ */
+
+#include "ls1c.h"
+#include "ls1c_wdog.h"
+
+/*
+系统先配置看门狗使能位 WDT_EN;
+然后配置看门狗计数器的初始值 WDT_TIMER;
+当设置 WDT_SET 后,计数器开始减计数;
+当还没有减到 0 时,重置看门狗计数器,系统不会重启;
+当看门狗计数器减到 0 时,则系统重启。
+*/
+
+static unsigned int WDT_timer = 0;
+
+/* 暂时为空 */
+unsigned int Wdog_Init(void)
+{
+ return 0;
+}
+
+/* 配置看门狗使能寄存器(WDT_EN) */
+unsigned int Wdog_Enable(void)
+{
+ unsigned int ctrl;
+ ctrl = (WDT_EN);
+ ctrl |= 0x01;
+
+ WDT_EN = ctrl;
+ return 0;
+}
+
+/* 配置看门狗失能寄存器(WDT_EN) */
+unsigned int Wdog_Disable(void)
+{
+ unsigned int ctrl;
+ ctrl = (WDT_EN);
+ ctrl &= ~0x01;
+ WDT_EN = ctrl;
+ return 0;
+}
+
+/* 配置看门狗设置寄存器 (WDT_SET) */
+unsigned int Wdog_Set(void)
+{
+ unsigned int ctrl;
+ ctrl = (WDT_SET);
+ ctrl |= 0x01;
+ WDT_SET = ctrl;
+ return 0;
+}
+
+/* 配置看门狗设置寄存器 (WDT_SET) */
+unsigned int Wdog_Reset(void)
+{
+ unsigned int ctrl;
+ ctrl = (WDT_SET);
+ ctrl &= ~0x01;
+ WDT_SET = ctrl;
+ return 0;
+}
+
+/* 获得看门狗计数器(WDT_timer) 的值*/
+unsigned int Wdog_GetValue(void)
+{
+ unsigned int cnt;
+ cnt = (WDT_TIMER);
+ return cnt;
+}
+
+/* 配置看门狗计数器(WDT_timer)的值*/
+unsigned int Wdog_LoadValue(unsigned int cnt)
+{
+ WDT_TIMER = cnt;
+ WDT_timer = cnt;
+ return 0;
+}
+
+/* 获得看门狗计数器设定值 */
+unsigned int Wdog_GetPreValue(void)
+{
+ return WDT_timer;
+}
diff --git a/bsp/ls1cdev/libraries/ls1c_wdog.h b/bsp/ls1cdev/libraries/ls1c_wdog.h
new file mode 100644
index 0000000000..a4717eedbf
--- /dev/null
+++ b/bsp/ls1cdev/libraries/ls1c_wdog.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2019-05-06 sundm75 first version
+ */
+
+#ifndef _LS1C_WDOG_H_
+#define _LS1C_WDOG_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+unsigned int Wdog_Init(void); // 暂时为空
+unsigned int Wdog_Enable(void); // 看门狗使能寄存器(WDT_EN)
+unsigned int Wdog_Disable(void); // 看门狗失能寄存器(WDT_EN)
+unsigned int Wdog_Set(void); // 看门狗设置寄存器 (WDT_SET)
+unsigned int Wdog_Reset(void); // 看门狗设置寄存器 (WDT_SET)
+unsigned int Wdog_GetValue(void); // 获得看门狗计数器(WDT_timer)
+unsigned int Wdog_LoadValue(unsigned int cnt); // 设置看门狗计数器(WDT_timer)
+unsigned int Wdog_GetPreValue(void); // 获得看门狗计数器设定值
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _LS1C_WDOG_H_ */
+