diff options
| author | xph <[email protected]> | 2020-04-09 16:35:28 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-04-09 16:35:28 +0800 |
| commit | ca7f01d79b3e0a997c771cec298e4ebd65b75809 (patch) | |
| tree | 3d2c48aae7203b14038ba7b98b500b5343ed7f2a /bsp/ls1cdev | |
| parent | f763f8e7284b0492c5a65ad0abf94ee1963d7dcc (diff) | |
| parent | baa3145bfe61b3330b6a160523cc5470fa5db3a7 (diff) | |
Merge pull request #1 from RT-Thread/master
sync rtt
Diffstat (limited to 'bsp/ls1cdev')
77 files changed, 3386 insertions, 1382 deletions
diff --git a/bsp/ls1cdev/.config b/bsp/ls1cdev/.config index 91f9c2f0c3..abde28ef80 100644 --- a/bsp/ls1cdev/.config +++ b/bsp/ls1cdev/.config @@ -13,13 +13,23 @@ CONFIG_RT_THREAD_PRIORITY_32=y # CONFIG_RT_THREAD_PRIORITY_256 is not set CONFIG_RT_THREAD_PRIORITY_MAX=32 CONFIG_RT_TICK_PER_SECOND=1000 -CONFIG_RT_DEBUG=y CONFIG_RT_USING_OVERFLOW_CHECK=y -CONFIG_RT_DEBUG_INIT=0 -CONFIG_RT_DEBUG_THREAD=0 CONFIG_RT_USING_HOOK=y +CONFIG_RT_IDLE_HOOK_LIST_SIZE=4 CONFIG_IDLE_THREAD_STACK_SIZE=1024 # CONFIG_RT_USING_TIMER_SOFT is not set +CONFIG_RT_DEBUG=y +CONFIG_RT_DEBUG_COLOR=y +# CONFIG_RT_DEBUG_INIT_CONFIG is not set +# CONFIG_RT_DEBUG_THREAD_CONFIG is not set +# CONFIG_RT_DEBUG_SCHEDULER_CONFIG is not set +# CONFIG_RT_DEBUG_IPC_CONFIG is not set +# CONFIG_RT_DEBUG_TIMER_CONFIG is not set +# CONFIG_RT_DEBUG_IRQ_CONFIG is not set +# CONFIG_RT_DEBUG_MEM_CONFIG is not set +# CONFIG_RT_DEBUG_SLAB_CONFIG is not set +# CONFIG_RT_DEBUG_MEMHEAP_CONFIG is not set +# CONFIG_RT_DEBUG_MODULE_CONFIG is not set # # Inter-Thread communication @@ -47,11 +57,11 @@ CONFIG_RT_USING_HEAP=y # Kernel Device Object # CONFIG_RT_USING_DEVICE=y +# CONFIG_RT_USING_DEVICE_OPS is not set CONFIG_RT_USING_INTERRUPT_INFO=y CONFIG_RT_USING_CONSOLE=y CONFIG_RT_CONSOLEBUF_SIZE=128 CONFIG_RT_CONSOLE_DEVICE_NAME="uart2" -# CONFIG_RT_USING_MODULE is not set # # RT-Thread Components @@ -59,6 +69,7 @@ CONFIG_RT_CONSOLE_DEVICE_NAME="uart2" CONFIG_RT_USING_COMPONENTS_INIT=y CONFIG_RT_USING_USER_MAIN=y CONFIG_RT_MAIN_THREAD_STACK_SIZE=2048 +CONFIG_RT_MAIN_THREAD_PRIORITY=10 # # C++ features @@ -92,6 +103,7 @@ CONFIG_DFS_USING_WORKDIR=y CONFIG_DFS_FILESYSTEMS_MAX=2 CONFIG_DFS_FILESYSTEM_TYPES_MAX=2 CONFIG_DFS_FD_MAX=4 +# CONFIG_RT_USING_DFS_MNTTABLE is not set CONFIG_RT_USING_DFS_ELMFAT=y # @@ -110,7 +122,6 @@ CONFIG_RT_DFS_ELM_MAX_SECTOR_SIZE=512 # CONFIG_RT_DFS_ELM_USE_ERASE is not set CONFIG_RT_DFS_ELM_REENTRANT=y # CONFIG_RT_USING_DFS_DEVFS is not set -# CONFIG_RT_USING_DFS_NET is not set # CONFIG_RT_USING_DFS_ROMFS is not set # CONFIG_RT_USING_DFS_RAMFS is not set # CONFIG_RT_USING_DFS_UFFS is not set @@ -121,9 +132,11 @@ CONFIG_RT_DFS_ELM_REENTRANT=y # Device Drivers # CONFIG_RT_USING_DEVICE_IPC=y +CONFIG_RT_PIPE_BUFSZ=512 CONFIG_RT_USING_SERIAL=y +CONFIG_RT_SERIAL_USING_DMA=y CONFIG_RT_USING_CAN=y -CONFIG_RT_CAN_USING_HDR=y +# CONFIG_RT_CAN_USING_HDR is not set # CONFIG_RT_USING_HWTIMER is not set # CONFIG_RT_USING_CPUTIME is not set CONFIG_RT_USING_I2C=y @@ -132,6 +145,8 @@ CONFIG_RT_USING_PIN=y # CONFIG_RT_USING_PWM is not set # CONFIG_RT_USING_MTD_NOR is not set # CONFIG_RT_USING_MTD_NAND is not set +# CONFIG_RT_USING_MTD is not set +# CONFIG_RT_USING_PM is not set # CONFIG_RT_USING_RTC is not set # CONFIG_RT_USING_SDIO is not set CONFIG_RT_USING_SPI=y @@ -142,10 +157,14 @@ CONFIG_RT_USING_SPI_MSD=y # CONFIG_RT_USING_ENC28J60 is not set # CONFIG_RT_USING_SPI_WIFI is not set # CONFIG_RT_USING_WDT is not set -# CONFIG_RT_USING_WIFI is not set # CONFIG_RT_USING_AUDIO is not set # +# Using WiFi +# +# CONFIG_RT_USING_WIFI is not set + +# # Using USB # # CONFIG_RT_USING_USB_HOST is not set @@ -157,10 +176,16 @@ CONFIG_RT_USING_SPI_MSD=y CONFIG_RT_USING_LIBC=y CONFIG_RT_USING_PTHREADS=y # CONFIG_RT_USING_POSIX is not set +# CONFIG_RT_USING_MODULE is not set + +# +# Network +# # -# Network stack +# Socket abstraction layer # +# CONFIG_RT_USING_SAL is not set # # light weight TCP/IP stack @@ -168,6 +193,7 @@ CONFIG_RT_USING_PTHREADS=y CONFIG_RT_USING_LWIP=y CONFIG_RT_USING_LWIP141=y # CONFIG_RT_USING_LWIP202 is not set +# CONFIG_RT_USING_LWIP210 is not set CONFIG_RT_LWIP_IGMP=y CONFIG_RT_LWIP_ICMP=y # CONFIG_RT_LWIP_SNMP is not set @@ -210,11 +236,18 @@ CONFIG_LWIP_SO_SNDTIMEO=1 CONFIG_LWIP_SO_RCVBUF=1 # CONFIG_RT_LWIP_NETIF_LOOPBACK is not set CONFIG_LWIP_NETIF_LOOPBACK=0 +# CONFIG_RT_LWIP_STATS is not set +# CONFIG_RT_LWIP_DEBUG is not set # # Modbus master and slave stack # # CONFIG_RT_USING_MODBUS is not set + +# +# AT commands +# +# CONFIG_RT_USING_AT is not set # CONFIG_LWIP_USING_DHCPD is not set # @@ -227,6 +260,7 @@ CONFIG_LWIP_NETIF_LOOPBACK=0 # # CONFIG_RT_USING_LOGTRACE is not set # CONFIG_RT_USING_RYM is not set +# CONFIG_RT_USING_ULOG is not set # # RT-Thread online packages @@ -318,8 +352,8 @@ CONFIG_RT_USING_UART2=y CONFIG_RT_UART_RX_BUFFER_SIZE=64 CONFIG_RT_USING_GMAC_INT_MODE=y # CONFIG_RT_USING_FPU is not set -CONFIG_RT_USING_SPI0=y -CONFIG_RT_USING_SPI1=y +# CONFIG_RT_USING_SPI0 is not set +# CONFIG_RT_USING_SPI1 is not set CONFIG_RT_USING_I2C1=y CONFIG_RT_USING_I2C2=y CONFIG_USING_BXCAN0=y diff --git a/bsp/ls1cdev/Kconfig b/bsp/ls1cdev/Kconfig index 23ecbb3190..6cd2409db4 100644 --- a/bsp/ls1cdev/Kconfig +++ b/bsp/ls1cdev/Kconfig @@ -1,83 +1,126 @@ mainmenu "RT-Thread Configuration" - -config $BSP_DIR +config BSP_DIR string option env="BSP_ROOT" default "." -config $RTT_DIR +config RTT_DIR string option env="RTT_ROOT" default "../.." - -config $PKGS_DIR + +config PKGS_DIR string option env="PKGS_ROOT" default "packages" source "$RTT_DIR/Kconfig" +source "$RTT_DIR/libcpu/mips/common/Kconfig" source "$PKGS_DIR/Kconfig" +config SOC_1C300 + bool + select RT_USING_COMPONENTS_INIT + select RT_USING_USER_MAIN + default y + +choice + prompt "Board Type" + config RT_LS1C_OPENLOONGSON + bool "OpenLoongson Board" + config RT_LS1C_BAICAIBOARD + bool "Baicai Board" +endchoice + config RT_USING_SELF_BOOT bool "Enable RT-Thread run without bootloader" default n - + +if RT_USING_SELF_BOOT + config RT_SELF_BOOT_DEBUG + bool "Debug self boot code" + default n +endif + if RT_USING_SERIAL config RT_USING_UART2 bool "Using RT_USING_UART2" - default y + default y +config RT_USING_UART1 + bool "Using RT_USING_UART1" + default y +config RT_USING_UART3 + bool "Using RT_USING_UART3" + default n config RT_UART_RX_BUFFER_SIZE - int "The rx buffer size" + int "The rx buffer size" default 64 if RT_USING_SERIAL - default 64 -endif + default 64 +endif config RT_USING_GMAC_INT_MODE bool "Using RT_USING_GMAC_INT_MODE" default y - -config RT_USING_FPU - bool "Using RT_USING_FPU" - default y - + config RT_USING_SPI0 bool "Enable SPI0" select RT_USING_SPI - default y + default y config RT_USING_SPI1 bool "Enable SPI1" select RT_USING_SPI - default y - + default y + if RT_USING_I2C config RT_USING_I2C1 bool "Enable I2C1" default y - + config RT_USING_I2C2 - bool "Enable I2C2" - default y + bool "Enable I2C2" + default y endif - + config USING_BXCAN0 bool "Enable CAN0" select RT_USING_CAN - default y - + default y + config USING_BXCAN1 bool "Enable CAN1" select RT_USING_CAN - default y + default y if RT_USING_CAN config RT_CAN_USING_HDR bool "Using RT_CAN_USING_HDR" select RT_USING_CAN - default y -endif + default y +endif + +choice + prompt "Touch format" + default NO_TOUCH + + config NO_TOUCH + bool "with no touch" + +if RT_USING_RTGUI + config XPT2046_USING_TOUCH + bool "with XPT2046 touch" +endif + + config TINA_USING_TOUCH + bool "with TINA touch" +endchoice + +if RT_USING_RTC +config RT_RTC_NAME + string "RT_RTC_NAME" + default "RTC" +endif -
\ No newline at end of file diff --git a/bsp/ls1cdev/SConstruct b/bsp/ls1cdev/SConstruct index a2f2cae178..4ea8c066ec 100644 --- a/bsp/ls1cdev/SConstruct +++ b/bsp/ls1cdev/SConstruct @@ -14,11 +14,12 @@ TARGET = 'rtthread.' + rtconfig.TARGET_EXT rtconfig.AFLAGS += ' -I' + str(Dir('#')) +DefaultEnvironment(tools=[]) env = Environment(tools = ['mingw'], - AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS, - CC = rtconfig.CC, CCFLAGS = rtconfig.CFLAGS, - AR = rtconfig.AR, ARFLAGS = '-rc', - LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS) + AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS, + CC = rtconfig.CC, CCFLAGS = rtconfig.CFLAGS, + AR = rtconfig.AR, ARFLAGS = '-rc', + LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS) env.PrependENVPath('PATH', rtconfig.EXEC_PATH) Export('RTT_ROOT') @@ -28,9 +29,9 @@ Export('rtconfig') objs = PrepareBuilding(env, RTT_ROOT) if GetDepend('RT_USING_SELF_BOOT'): - rtconfig.LFLAGS += " -Ttext 0x80010000" + rtconfig.LFLAGS += " -Ttext 0x80000000" else: - rtconfig.LFLAGS += " -Ttext 0x80200000" + rtconfig.LFLAGS += " -Ttext 0x80200000" env.Replace(LINKFLAGS = rtconfig.LFLAGS) if GetDepend('RT_USING_FPU'): @@ -38,9 +39,9 @@ if GetDepend('RT_USING_FPU'): env['ASFLAGS'] = env['ASFLAGS'].replace('-msoft-float', '-mhard-float') env['CXXFLAGS'] = env['CXXFLAGS'].replace('-msoft-float', '-mhard-float') env['LINKFLAGS'] = env['LINKFLAGS'].replace('-msoft-float', '-mhard-float') - + if GetDepend('RT_USING_RTGUI'): objs = objs + SConscript(RTT_ROOT + '/examples/gui/SConscript', variant_dir='build/examples/gui', duplicate=0) - + # make a building DoBuilding(TARGET, objs) diff --git a/bsp/ls1cdev/applications/main.c b/bsp/ls1cdev/applications/main.c index c3d6bbd31b..fac004d832 100644 --- a/bsp/ls1cdev/applications/main.c +++ b/bsp/ls1cdev/applications/main.c @@ -1,21 +1,7 @@ /* - * File : main.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2008 - 2017, 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 @@ -26,5 +12,6 @@ int main(int argc, char** argv) { + return 0; } diff --git a/bsp/ls1cdev/drivers/SConscript b/bsp/ls1cdev/drivers/SConscript index 2363e655a8..33310b6d7e 100644 --- a/bsp/ls1cdev/drivers/SConscript +++ b/bsp/ls1cdev/drivers/SConscript @@ -1,14 +1,10 @@ from building import * cwd = GetCurrentDir() -src = Glob('*.c') +src = Glob('*.c') + Glob('*.cpp') + Glob('*_gcc.S') CPPPATH = [cwd] - -if GetDepend('RT_USING_RTGUI') == False: - SrcRemove(src, 'touch.c') - group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH) objs = [] diff --git a/bsp/ls1cdev/drivers/board.c b/bsp/ls1cdev/drivers/board.c index a7100a04c4..b000daafc5 100644 --- a/bsp/ls1cdev/drivers/board.c +++ b/bsp/ls1cdev/drivers/board.c @@ -1,92 +1,27 @@ /* - * File : board.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006-2012, RT-Thread Develop Team + * Copyright (c) 2006-2018, RT-Thread Development Team * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rt-thread.org/license/LICENSE + * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes * 2010-06-25 Bernard first version * 2011-08-08 lgnq modified for Loongson LS1B * 2015-07-06 chinesebear modified for Loongson LS1C + * 2019-12-04 Jiaxun Yang Adapt new generic MIPS code */ #include <rtthread.h> #include <rthw.h> +#include <mips.h> #include "board.h" #include "drv_uart.h" #include "ls1c.h" -#define A_K0BASE 0x80000000 - extern unsigned char __bss_end; - -extern void tlb_refill_exception(void); -extern void general_exception(void); -extern void irq_exception(void); -extern void rt_hw_cache_init(void); -extern void invalidate_writeback_dcache_all(void); -extern void invalidate_icache_all(void); - - -/** - * @addtogroup Loongson LS1B - */ - -/*@{*/ - -/** - * This is the timer interrupt service routine. - */ -void rt_hw_timer_handler(void) -{ - unsigned int count; - - count = read_c0_compare(); - write_c0_compare(count); - write_c0_count(0); - - /* increase a OS tick */ - rt_tick_increase(); -} - -/** - * This function will initial OS timer - */ -void rt_hw_timer_init(void) -{ - write_c0_compare(CPU_HZ/2/RT_TICK_PER_SECOND); - write_c0_count(0); -} - - -/** - * init hardware FPU - */ -void rt_hw_fpu_init(void) -{ - rt_uint32_t c0_status = 0; - rt_uint32_t c1_status = 0; - - // 使能协处理器1--FPU - c0_status = read_c0_status(); - c0_status |= (ST0_CU1 | ST0_FR); - write_c0_status(c0_status); - - // 配置FPU - c1_status = read_c1_status(); - c1_status |= (FPU_CSR_FS | FPU_CSR_FO | FPU_CSR_FN); // set FS, FO, FN - c1_status &= ~(FPU_CSR_ALL_E); // disable exception - c1_status = (c1_status & (~FPU_CSR_RM)) | FPU_CSR_RN; // set RN - write_c1_status(c1_status); - - return ; -} +#define RT_HW_HEAP_END (0x80000000 + MEM_SIZE) /** @@ -94,35 +29,24 @@ void rt_hw_fpu_init(void) */ void rt_hw_board_init(void) { - /* init cache */ - rt_hw_cache_init(); - - /* init hardware interrupt */ - rt_hw_interrupt_init(); - - /* clear bev */ - write_c0_status(read_c0_status()&(~(1<<22))); - - /* copy vector */ - rt_memcpy((void *)A_K0BASE, tlb_refill_exception, 0x80); - rt_memcpy((void *)(A_K0BASE + 0x180), general_exception, 0x80); - rt_memcpy((void *)(A_K0BASE + 0x200), irq_exception, 0x80); - - invalidate_writeback_dcache_all(); - invalidate_icache_all(); - + /* init hardware interrupt */ + rt_hw_exception_init(); + + /* init hardware interrupt */ + rt_hw_interrupt_init(); + #ifdef RT_USING_HEAP - rt_system_heap_init((void*)&__bss_end, (void*)RT_HW_HEAP_END); + rt_system_heap_init((void*)&__bss_end, (void*)RT_HW_HEAP_END); #endif #ifdef RT_USING_SERIAL - /* init hardware UART device */ - rt_hw_uart_init(); + /* init hardware UART device */ + rt_hw_uart_init(); #endif #ifdef RT_USING_CONSOLE - /* set console device */ - rt_console_set_device(RT_CONSOLE_DEVICE_NAME); + /* set console device */ + rt_console_set_device(RT_CONSOLE_DEVICE_NAME); #endif /* init operating system timer */ rt_hw_timer_init(); diff --git a/bsp/ls1cdev/drivers/board.h b/bsp/ls1cdev/drivers/board.h index 8124eae7a5..089384e348 100644 --- a/bsp/ls1cdev/drivers/board.h +++ b/bsp/ls1cdev/drivers/board.h @@ -1,26 +1,62 @@ /* - * File : board.h - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006-2012, RT-Thread Develop Team + * Copyright (c) 2006-2018, RT-Thread Development Team * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rt-thread.org/license/LICENSE + * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes * 2010-06-25 Bernard first version * 2011-08-08 lgnq modified for Loongson LS1B * 2015-07-06 chinesebear modified for Loongson LS1C + * 2019-12-04 Jiaxun Yang Add board config defines */ #ifndef __BOARD_H__ #define __BOARD_H__ +#include <rtconfig.h> +#ifndef __ASSEMBLY__ void rt_hw_board_init(void); +#endif + +/* +* SDRAM config +* +* Take IS42S16400 SDRAM chip as a example +* The specfication is +* Size 8MB +* WIDTH: 16 bits +* COL WIDTH: 8 bits, so we should take the 8 power of 2, it's 256 +* ROW WIDTH: 12 bits, so we take the 12 power of 2, it's 4K +* +* Please reference macro SD_PARA0 and SDRAM registers intruduction +* in user's manual to edit the SDRAM config. +*/ + +#if defined(RT_LS1C_BAICAIBOARD) +/* 8MByte IS42S16400 appeared in bacai_board V1.x V2.x */ +#define MEM_SIZE (0x800000) +#define SDRAM_WIDTH (WIDTH_16) +#define SDRAM_COL (COL_256) +#define SDRAM_ROW (ROW_4K) +#elif defined(RT_LS1C_OPENLOONGSON) +/* 32MByte appeared in SmartLoong board */ +#define MEM_SIZE (0x2000000) +#define SDRAM_WIDTH (WIDTH_16) +#define SDRAM_COL (COL_512) +#define SDRAM_ROW (ROW_8K) +#else +#error Unknown Board +#endif + +/* Early Debug config */ +#define EARLY_DEBUG /* UART2 serial print debug in early stage */ +#define EARLY_DEBUG_BAUD (115200) -/* 32M SDRAM */ -#define RT_HW_HEAP_END (0x80000000 + 32 * 1024 * 1024) -#define CPU_HZ (252 * 1000000) +/* Clock config */ +#define CPU_HZ (252 * 1000000) +#define PLL_MULT (0x54) /* When external clock is 24Mhz PLL=504Mhz */ +#define SDRAM_DIV (0) /* SDRAM is CPU divided by 2*/ +#define CPU_DIV (2) /* CPU clock is PLL divided by 2 */ #endif diff --git a/bsp/ls1cdev/drivers/display_controller.c b/bsp/ls1cdev/drivers/display_controller.c index a09fe0269f..2a0bfcc619 100644 --- a/bsp/ls1cdev/drivers/display_controller.c +++ b/bsp/ls1cdev/drivers/display_controller.c @@ -1,237 +1,242 @@ /* - * File :display_controller.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2017, 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 + * Date Author Notes * 2011-08-09 lgnq first version for LS1B DC * 2015-07-06 chinesebear modified for loongson 1c * 2018-01-06 sundm75 modified for smartloong */ + #include <rtthread.h> -#include <rtthread.h> #include "display_controller.h" #include "../../libraries/ls1c_pwm.h" #include "../../libraries/ls1c_public.h" #include "../../libraries/ls1c_gpio.h" #include "../../libraries/ls1c_pin.h" -#ifdef RT_USING_RTGUI - +#if (defined PKG_USING_GUIENGINE) || (defined RT_USING_RTGUI) struct vga_struct vga_mode[] = { - {/*"480x272_60.00"*/ 111000, 480, 482, 523, 525, 272, 274, 284, 286, }, - {/*"640x480_70.00"*/ 28560, 640, 664, 728, 816, 480, 481, 484, 500, }, - {/*"640x640_60.00"*/ 33100, 640, 672, 736, 832, 640, 641, 644, 663, }, - {/*"640x768_60.00"*/ 39690, 640, 672, 736, 832, 768, 769, 772, 795, }, - {/*"640x800_60.00"*/ 42130, 640, 680, 744, 848, 800, 801, 804, 828, }, - {/*"800x480_70.00"*/ 35840, 800, 832, 912, 1024, 480, 481, 484, 500, }, - {/*"800x600_60.00"*/ 38220, 800, 832, 912, 1024, 600, 601, 604, 622, }, - {/*"800x640_60.00"*/ 40730, 800, 832, 912, 1024, 640, 641, 644, 663, }, - {/*"832x600_60.00"*/ 40010, 832, 864, 952, 1072, 600, 601, 604, 622, }, - {/*"832x608_60.00"*/ 40520, 832, 864, 952, 1072, 608, 609, 612, 630, }, - {/*"1024x480_60.00"*/ 38170, 1024, 1048, 1152, 1280, 480, 481, 484, 497, }, - {/*"1024x600_60.00"*/ 48960, 1024, 1064, 1168, 1312, 600, 601, 604, 622, }, - {/*"1024x640_60.00"*/ 52830, 1024, 1072, 1176, 1328, 640, 641, 644, 663, }, - {/*"1024x768_60.00"*/ 64110, 1024, 1080, 1184, 1344, 768, 769, 772, 795, }, - {/*"1152x764_60.00"*/ 71380, 1152, 1208, 1328, 1504, 764, 765, 768, 791, }, - {/*"1280x800_60.00"*/ 83460, 1280, 1344, 1480, 1680, 800, 801, 804, 828, }, - {/*"1280x1024_55.00"*/ 98600, 1280, 1352, 1488, 1696, 1024, 1025, 1028, 1057, }, - {/*"1440x800_60.00"*/ 93800, 1440, 1512, 1664, 1888, 800, 801, 804, 828, }, - {/*"1440x900_67.00"*/ 120280, 1440, 1528, 1680, 1920, 900, 901, 904, 935, }, + {/*"480x272_60.00"*/ 111000, 480, 482, 523, 525, 272, 274, 284, 286, }, + {/*"640x480_70.00"*/ 28560, 640, 664, 728, 816, 480, 481, 484, 500, }, + {/*"640x640_60.00"*/ 33100, 640, 672, 736, 832, 640, 641, 644, 663, }, + {/*"640x768_60.00"*/ 39690, 640, 672, 736, 832, 768, 769, 772, 795, }, + {/*"640x800_60.00"*/ 42130, 640, 680, 744, 848, 800, 801, 804, 828, }, + {/*"800x480_70.00"*/ 35840, 800, 832, 912, 1024, 480, 481, 484, 500, }, + {/*"800x600_60.00"*/ 38220, 800, 832, 912, 1024, 600, 601, 604, 622, }, + {/*"800x640_60.00"*/ 40730, 800, 832, 912, 1024, 640, 641, 644, 663, }, + {/*"832x600_60.00"*/ 40010, 832, 864, 952, 1072, 600, 601, 604, 622, }, + {/*"832x608_60.00"*/ 40520, 832, 864, 952, 1072, 608, 609, 612, 630, }, + {/*"1024x480_60.00"*/ 38170, 1024, 1048, 1152, 1280, 480, 481, 484, 497, }, + {/*"1024x600_60.00"*/ 48960, 1024, 1064, 1168, 1312, 600, 601, 604, 622, }, + {/*"1024x640_60.00"*/ 52830, 1024, 1072, 1176, 1328, 640, 641, 644, 663, }, + {/*"1024x768_60.00"*/ 64110, 1024, 1080, 1184, 1344, 768, 769, 772, 795, }, + {/*"1152x764_60.00"*/ 71380, 1152, 1208, 1328, 1504, 764, 765, 768, 791, }, + {/*"1280x800_60.00"*/ 83460, 1280, 1344, 1480, 1680, 800, 801, 804, 828, }, + {/*"1280x1024_55.00"*/ 98600, 1280, 1352, 1488, 1696, 1024, 1025, 1028, 1057, }, + {/*"1440x800_60.00"*/ 93800, 1440, 1512, 1664, 1888, 800, 801, 804, 828, }, + {/*"1440x900_67.00"*/ 120280, 1440, 1528, 1680, 1920, 900, 901, 904, 935, }, }; +static volatile int fb_index = 0; + ALIGN(16) volatile rt_uint16_t _rt_framebuffer[FB_YSIZE][FB_XSIZE]; +volatile rt_uint16_t _rt_framebuffer0[FB_YSIZE][FB_XSIZE]; +volatile rt_uint16_t _rt_framebuffer1[FB_YSIZE][FB_XSIZE]; static struct rt_device_graphic_info _dc_info; static void pwminit(void) { pwm_info_t pwm_info; pwm_info.gpio = LS1C_PWM0_GPIO06; // pwm引脚位gpio06 - pwm_info.mode = PWM_MODE_NORMAL; // 正常模式--连续输出pwm波形 - pwm_info.duty = 0.85; // pwm占空比 85% - pwm_info.period_ns = 5*1000*1000; // pwm周期5ms + pwm_info.mode = PWM_MODE_NORMAL; // 正常模式--连续输出pwm波形 + pwm_info.duty = 0.85; // pwm占空比 85% + pwm_info.period_ns = 5*1000*1000; // pwm周期5ms - /*pwm初始化,初始化后立即产生pwm波形*/ - pwm_init(&pwm_info); + /*pwm初始化,初始化后立即产生pwm波形*/ + pwm_init(&pwm_info); - /* 使能pwm */ - pwm_enable(&pwm_info); + /* 使能pwm */ + pwm_enable(&pwm_info); } int caclulate_freq(rt_uint32_t XIN, rt_uint32_t PCLK) { - rt_uint32_t divider_int; - rt_uint32_t needed_pixclk; - rt_uint32_t pll_clk, pix_div; - rt_uint32_t regval; + rt_uint32_t divider_int; + rt_uint32_t needed_pixclk; + rt_uint32_t pll_clk, pix_div; + rt_uint32_t regval; - pll_clk = PLL_FREQ; // 读CPU的 PLL及SDRAM 分频系数 - pll_clk =( pll_clk>>8 )& 0xff; - pll_clk = XIN * pll_clk / 4 ; - pix_div = PLL_DIV_PARAM;//读CPU的 CPU/CAMERA/DC 分频系数 - pix_div = (pix_div>>24)&0xff; - rt_kprintf("old pll_clk=%d, pix_div=%d\n", pll_clk, pix_div); + pll_clk = PLL_FREQ; // 读CPU的 PLL及SDRAM 分频系数 + pll_clk =( pll_clk>>8 )& 0xff; + pll_clk = XIN * pll_clk / 4 ; + pix_div = PLL_DIV_PARAM;//读CPU的 CPU/CAMERA/DC 分频系数 + pix_div = (pix_div>>24)&0xff; + rt_kprintf("old pll_clk=%d, pix_div=%d\n", pll_clk, pix_div); - divider_int = pll_clk/(1000000) *PCLK/1000; - if(divider_int%1000>=500) - divider_int = divider_int/1000+1; - else - divider_int = divider_int/1000; - rt_kprintf("divider_int = %d\n", divider_int); - - /* check whether divisor is too small. */ - if (divider_int < 1) { - rt_kprintf("Warning: clock source is too slow.Try smaller resolution\n"); - divider_int = 1; - } - else if(divider_int > 100) { - rt_kprintf("Warning: clock source is too fast.Try smaller resolution\n"); - divider_int = 100; - } - /* 配置分频寄存器 */ - { - rt_uint32_t regval = 0; - regval = PLL_DIV_PARAM; - /*首先需要把分频使能位清零 */ - regval &= ~0x80000030; //PIX_DIV_VALID PIX_SEL 置0 - regval &= ~(0x3f<<24); //PIX_DIV 清零 - regval |= divider_int << 24; - PLL_DIV_PARAM = regval; - regval |= 0x80000030; //PIX_DIV_VALID PIX_SEL 置1 - PLL_DIV_PARAM = regval; - } - rt_kprintf("new PLL_FREQ=0x%x, PLL_DIV_PARAM=0x%x\n", PLL_FREQ, PLL_DIV_PARAM); - rt_thread_delay(10); - return 0; + divider_int = pll_clk/(1000000) *PCLK/1000; + if(divider_int%1000>=500) + divider_int = divider_int/1000+1; + else + divider_int = divider_int/1000; + rt_kprintf("divider_int = %d\n", divider_int); + + /* check whether divisor is too small. */ + if (divider_int < 1) { + rt_kprintf("Warning: clock source is too slow.Try smaller resolution\n"); + divider_int = 1; + } + else if(divider_int > 100) { + rt_kprintf("Warning: clock source is too fast.Try smaller resolution\n"); + divider_int = 100; + } + /* 配置分频寄存器 */ + { + rt_uint32_t regval = 0; + regval = PLL_DIV_PARAM; + /*首先需要把分频使能位清零 */ + regval &= ~0x80000030; //PIX_DIV_VALID PIX_SEL 置0 + regval &= ~(0x3f<<24); //PIX_DIV 清零 + regval |= divider_int << 24; + PLL_DIV_PARAM = regval; + regval |= 0x80000030; //PIX_DIV_VALID PIX_SEL 置1 + PLL_DIV_PARAM = regval; + } + rt_kprintf("new PLL_FREQ=0x%x, PLL_DIV_PARAM=0x%x\n", PLL_FREQ, PLL_DIV_PARAM); + rt_thread_delay(10); + return 0; } static rt_err_t rt_dc_init(rt_device_t dev) { - int i, out, mode=-1; - int val; - - rt_kprintf("PWM initied\n"); - /* Set the back light PWM. */ - pwminit(); - - for (i=0; i<sizeof(vga_mode)/sizeof(struct vga_struct); i++) - { - if (vga_mode[i].hr == FB_XSIZE && vga_mode[i].vr == FB_YSIZE) - { - mode=i; - /* 计算时钟 配置频率*/ - caclulate_freq(OSC, vga_mode[i].pclk); - break; - } - } + int i, out, mode=-1; + int val; + + rt_kprintf("PWM initied\n"); + /* Set the back light PWM. */ + pwminit(); + + for (i=0; i<sizeof(vga_mode)/sizeof(struct vga_struct); i++) + { + if (vga_mode[i].hr == FB_XSIZE && vga_mode[i].vr == FB_YSIZE) + { + mode=i; + /* 计算时钟 配置频率*/ + caclulate_freq(OSC, vga_mode[i].pclk); + break; + } + } - if (mode<0) - { - rt_kprintf("\n\n\nunsupported framebuffer resolution\n\n\n"); - return; - } + if (mode<0) + { + rt_kprintf("\n\n\nunsupported framebuffer resolution\n\n\n"); + return RT_ERROR; + } - DC_FB_CONFIG = 0x0; - DC_FB_CONFIG = 0x3; // // framebuffer configuration RGB565 - DC_FB_BUFFER_ADDR0 = (rt_uint32_t)_rt_framebuffer - 0x80000000; - DC_FB_BUFFER_ADDR1 = (rt_uint32_t)_rt_framebuffer - 0x80000000; - DC_DITHER_CONFIG = 0x0; //颜色抖动配置寄存器 - DC_DITHER_TABLE_LOW = 0x0; //颜色抖动查找表低位寄存器 - DC_DITHER_TABLE_HIGH = 0x0; //颜色抖动查找表高位寄存器 - DC_PANEL_CONFIG = 0x80001311; //液晶面板配置寄存器 - DC_PANEL_TIMING = 0x0; + DC_FB_CONFIG = 0x0; + DC_FB_CONFIG = 0x3; // // framebuffer configuration RGB565 + DC_DITHER_CONFIG = 0x0; //颜色抖动配置寄存器 + DC_DITHER_TABLE_LOW = 0x0; //颜色抖动查找表低位寄存器 + DC_DITHER_TABLE_HIGH = 0x0; //颜色抖动查找表高位寄存器 + DC_PANEL_CONFIG = 0x80001311; //液晶面板配置寄存器 + DC_PANEL_TIMING = 0x0; - DC_HDISPLAY = (vga_mode[mode].hfl<<16) | vga_mode[mode].hr; - DC_HSYNC = 0x40000000 | (vga_mode[mode].hse<<16) | vga_mode[mode].hss; - DC_VDISPLAY = (vga_mode[mode].vfl<<16) | vga_mode[mode].vr; - DC_VSYNC = 0x40000000 | (vga_mode[mode].vse<<16) | vga_mode[mode].vss; + DC_HDISPLAY = (vga_mode[mode].hfl<<16) | vga_mode[mode].hr; + DC_HSYNC = 0x40000000 | (vga_mode[mode].hse<<16) | vga_mode[mode].hss; + DC_VDISPLAY = (vga_mode[mode].vfl<<16) | vga_mode[mode].vr; + DC_VSYNC = 0x40000000 | (vga_mode[mode].vse<<16) | vga_mode[mode].vss; #if defined(CONFIG_VIDEO_32BPP) - DC_FB_CONFIG = 0x00100105; - DC_FB_BUFFER_STRIDE = FB_XSIZE*4; + DC_FB_CONFIG = 0x00100105; + DC_FB_BUFFER_STRIDE = FB_XSIZE*4; #elif defined(CONFIG_VIDEO_24BPP) - DC_FB_CONFIG = 0x00100104; - DC_FB_BUFFER_STRIDE = (FB_XSIZE*4+255)&(~255); + DC_FB_CONFIG = 0x00100104; + DC_FB_BUFFER_STRIDE = (FB_XSIZE*4+255)&(~255); #elif defined(CONFIG_VIDEO_16BPP)// 使用这个选项 - DC_FB_CONFIG = 0x00100103; - DC_FB_BUFFER_STRIDE = (FB_XSIZE*2+255)&(~255); + DC_FB_CONFIG = 0x00100103; + DC_FB_BUFFER_STRIDE = (FB_XSIZE*2+0x7f)&(~0x7f); #elif defined(CONFIG_VIDEO_15BPP) - DC_FB_CONFIG = 0x00100102; - DC_FB_BUFFER_STRIDE = (FB_XSIZE*2+255)&(~255); + DC_FB_CONFIG = 0x00100102; + DC_FB_BUFFER_STRIDE = (FB_XSIZE*2+255)&(~255); #elif defined(CONFIG_VIDEO_12BPP) - DC_FB_CONFIG = 0x00100101; - DC_FB_BUFFER_STRIDE = (FB_XSIZE*2+255)&(~255); + DC_FB_CONFIG = 0x00100101; + DC_FB_BUFFER_STRIDE = (FB_XSIZE*2+255)&(~255); #else - DC_FB_CONFIG = 0x00100104; - DC_FB_BUFFER_STRIDE = (FB_XSIZE*4+255)&(~255); + DC_FB_CONFIG = 0x00100104; + DC_FB_BUFFER_STRIDE = (FB_XSIZE*4+255)&(~255); #endif - return RT_EOK; + return RT_EOK; } static rt_err_t rt_dc_control(rt_device_t dev, int cmd, void *args) { - switch (cmd) - { - case RTGRAPHIC_CTRL_RECT_UPDATE: - break; - case RTGRAPHIC_CTRL_POWERON: - break; - case RTGRAPHIC_CTRL_POWEROFF: - break; - case RTGRAPHIC_CTRL_GET_INFO: - rt_memcpy(args, &_dc_info, sizeof(_dc_info)); - break; - case RTGRAPHIC_CTRL_SET_MODE: - break; - } + switch (cmd) + { + case RTGRAPHIC_CTRL_RECT_UPDATE: + { + if (fb_index == 0) + { + DC_FB_BUFFER_ADDR0 = (rt_uint32_t)_rt_framebuffer1 - 0x80000000; + DC_FB_BUFFER_ADDR1 = (rt_uint32_t)_rt_framebuffer1 - 0x80000000; + rt_memcpy((void *)_rt_framebuffer1, (const void *)_rt_framebuffer, sizeof(_rt_framebuffer)); + rt_memcpy((void *)_rt_framebuffer1, (const void *)_rt_framebuffer, sizeof(_rt_framebuffer)); + fb_index =1; + } + else + { + DC_FB_BUFFER_ADDR0 = (rt_uint32_t)_rt_framebuffer0 - 0x80000000; + DC_FB_BUFFER_ADDR1 = (rt_uint32_t)_rt_framebuffer0 - 0x80000000; + rt_memcpy((void *)_rt_framebuffer0, (const void *)_rt_framebuffer, sizeof(_rt_framebuffer)); + rt_memcpy((void *)_rt_framebuffer0, (const void *)_rt_framebuffer, sizeof(_rt_framebuffer)); + fb_index =0; + } + break; + } + case RTGRAPHIC_CTRL_POWERON: + break; + case RTGRAPHIC_CTRL_POWEROFF: + break; + case RTGRAPHIC_CTRL_GET_INFO: + rt_memcpy(args, &_dc_info, sizeof(_dc_info)); + break; + case RTGRAPHIC_CTRL_SET_MODE: + break; + } - return RT_EOK; + return RT_EOK; } void rt_hw_dc_init(void) { - rt_device_t dc = rt_malloc(sizeof(struct rt_device)); - if (dc == RT_NULL) - { - rt_kprintf("dc == RT_NULL\n"); - return; /* no memory yet */ - } + rt_device_t dc = rt_malloc(sizeof(struct rt_device)); + if (dc == RT_NULL) + { + rt_kprintf("dc == RT_NULL\n"); + return; /* no memory yet */ + } - _dc_info.bits_per_pixel = 16; - _dc_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565P; - _dc_info.framebuffer = (rt_uint8_t*)HW_FB_ADDR; - _dc_info.width = FB_XSIZE; - _dc_info.height = FB_YSIZE; + _dc_info.bits_per_pixel = 16; + _dc_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565; + _dc_info.framebuffer = (rt_uint8_t*)HW_FB_ADDR; + _dc_info.width = FB_XSIZE; + _dc_info.height = FB_YSIZE; - /* init device structure */ - dc->type = RT_Device_Class_Graphic; - dc->init = rt_dc_init; - dc->open = RT_NULL; - dc->close = RT_NULL; - dc->control = rt_dc_control; - dc->user_data = (void*)&_dc_info; - - /* register Display Controller device to RT-Thread */ - rt_device_register(dc, "dc", RT_DEVICE_FLAG_RDWR); - - rt_device_init(dc); + /* init device structure */ + dc->type = RT_Device_Class_Graphic; + dc->init = rt_dc_init; + dc->open = RT_NULL; + dc->close = RT_NULL; + dc->control = rt_dc_control; + dc->user_data = (void*)&_dc_info; + + /* register Display Controller device to RT-Thread */ + rt_device_register(dc, "dc", RT_DEVICE_FLAG_RDWR); + + rt_device_init(dc); } #include <rtgui/driver.h> diff --git a/bsp/ls1cdev/drivers/display_controller.h b/bsp/ls1cdev/drivers/display_controller.h index ad252a9c2f..39f6ae8d52 100644 --- a/bsp/ls1cdev/drivers/display_controller.h +++ b/bsp/ls1cdev/drivers/display_controller.h @@ -1,11 +1,7 @@ /* - * File : display_controller.h - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006-2012, RT-Thread Develop Team + * Copyright (c) 2006-2018, RT-Thread Development Team * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rt-thread.org/license/LICENSE + * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes @@ -20,7 +16,7 @@ #include <rtthread.h> #include "ls1c.h" -#define DC_BASE 0xBC301240 //Display Controller +#define DC_BASE 0xBC301240 //Display Controller /* Frame Buffer registers */ #define DC_FB_CONFIG __REG32(DC_BASE + 0x000) @@ -51,9 +47,9 @@ struct vga_struct { - long pclk; - int hr,hss,hse,hfl; - int vr,vss,vse,vfl; + long pclk; + int hr,hss,hse,hfl; + int vr,vss,vse,vfl; }; #endif diff --git a/bsp/ls1cdev/drivers/drv_can.c b/bsp/ls1cdev/drivers/drv_can.c index 92095d0669..66388b4ea8 100644 --- a/bsp/ls1cdev/drivers/drv_can.c +++ b/bsp/ls1cdev/drivers/drv_can.c @@ -1,21 +1,7 @@ /* - * File : drv_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 @@ -119,6 +105,7 @@ static rt_err_t setfilter(struct ls1c_bxcan *pbxcan, struct rt_can_filter_config } return RT_EOK; } + static void bxcan0_filter_init(struct rt_can_device *can) { struct ls1c_bxcan *pbxcan; @@ -242,14 +229,13 @@ static void bxcan0_hw_init(void) #ifdef USING_BXCAN1 static void bxcan1_hw_init(void) { - pin_set_purpose(56, PIN_PURPOSE_GPIO); - pin_set_purpose(57, PIN_PURPOSE_GPIO); - pin_set_remap(56, PIN_REMAP_DEFAULT); - pin_set_remap(57, PIN_REMAP_DEFAULT); + pin_set_purpose(56, PIN_PURPOSE_OTHER); + pin_set_purpose(57, PIN_PURPOSE_OTHER); + pin_set_remap(56, PIN_REMAP_THIRD); + pin_set_remap(57, PIN_REMAP_THIRD); } #endif - static rt_err_t configure(struct rt_can_device *can, struct can_configure *cfg) { CAN_TypeDef *pbxcan; @@ -444,7 +430,7 @@ void ls1c_can0_irqhandler(int irq, void *param) rt_kprintf("\r\nCan0 int TX happened!\r\n"); } /*数据溢出中断*/ - else if (( status & CAN_IR_TI) == CAN_IR_DOI) + else if (( status & CAN_IR_DOI) == CAN_IR_DOI) { rt_hw_can_isr(&bxcan0, RT_CAN_EVENT_RXOF_IND); rt_kprintf("\r\nCan0 int RX OF happened!\r\n"); @@ -484,7 +470,7 @@ void ls1c_can1_irqhandler(int irq, void *param) rt_kprintf("\r\nCan1 int TX happened!\r\n"); } /*数据溢出中断*/ - else if (( status & CAN_IR_TI) == CAN_IR_DOI) + else if (( status & CAN_IR_DOI) == CAN_IR_DOI) { rt_hw_can_isr(&bxcan1, RT_CAN_EVENT_RXOF_IND); rt_kprintf("\r\nCan1 int RX OF happened!\r\n"); @@ -515,7 +501,7 @@ int ls1c_bxcan_init(void) rt_kprintf("\r\ncan0 register! \r\n"); rt_hw_interrupt_install(LS1C_CAN0_IRQ,( rt_isr_handler_t)bxcan0data.irq , RT_NULL, "can0"); - rt_hw_interrupt_umask(LS1C_CAN0_IRQ); + rt_hw_interrupt_umask(LS1C_CAN0_IRQ); #endif #ifdef USING_BXCAN1 bxcan1.config.baud_rate = CAN250kBaud; diff --git a/bsp/ls1cdev/drivers/drv_can.h b/bsp/ls1cdev/drivers/drv_can.h index 0d846dee25..7d5d1604d4 100644 --- a/bsp/ls1cdev/drivers/drv_can.h +++ b/bsp/ls1cdev/drivers/drv_can.h @@ -1,21 +1,7 @@ /* - * File : bxcan.h - * 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 diff --git a/bsp/ls1cdev/drivers/drv_gpio.c b/bsp/ls1cdev/drivers/drv_gpio.c index 3a21b54a33..2203db7775 100644 --- a/bsp/ls1cdev/drivers/drv_gpio.c +++ b/bsp/ls1cdev/drivers/drv_gpio.c @@ -1,21 +1,7 @@ /* - * File : drv_gpio.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 @@ -87,8 +73,24 @@ rt_err_t ls1c_pin_attach_irq(struct rt_device *device, rt_int32_t pin, { unsigned int gpio = pin; char irq_name[10]; - - gpio_set_irq_type(gpio, mode); + rt_uint32_t type; + switch (mode) + { + case PIN_IRQ_MODE_RISING: + type=IRQ_TYPE_EDGE_RISING; + break; + case PIN_IRQ_MODE_FALLING: + type=IRQ_TYPE_EDGE_FALLING; + break; + case PIN_IRQ_MODE_HIGH_LEVEL: + type=IRQ_TYPE_LEVEL_HIGH; + break; + case PIN_IRQ_MODE_LOW_LEVEL: + type=IRQ_TYPE_LEVEL_LOW; + break; + } + gpio_set_irq_type(gpio, type); + rt_sprintf(irq_name, "PIN_%d", gpio); rt_hw_interrupt_install(LS1C_GPIO_TO_IRQ(gpio), (rt_isr_handler_t)hdr, args, irq_name); diff --git a/bsp/ls1cdev/drivers/drv_gpio.h b/bsp/ls1cdev/drivers/drv_gpio.h index ab67d9f32a..33fc0f18ed 100644 --- a/bsp/ls1cdev/drivers/drv_gpio.h +++ b/bsp/ls1cdev/drivers/drv_gpio.h @@ -1,21 +1,7 @@ /* - * File : drv_gpio.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/drivers/drv_i2c.c b/bsp/ls1cdev/drivers/drv_i2c.c index 998f0f6ec3..374b625c70 100644 --- a/bsp/ls1cdev/drivers/drv_i2c.c +++ b/bsp/ls1cdev/drivers/drv_i2c.c @@ -1,25 +1,11 @@ /* - * File : drv_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 - * 2017-11-14 ��Ϊ�� first version + * 2017-11-14 勤为本 first version */ #include <rtthread.h> @@ -30,8 +16,8 @@ #include "../libraries/ls1c_delay.h" -#define LS1C_I2C_SCL (57) // gpio57 -#define LS1C_I2C_SDA (56) // gpio56 +#define LS1C_I2C_SCL (51) // gpio57 +#define LS1C_I2C_SDA (50) // gpio56 #define LS1C_SET_GPIO_MODE @@ -104,8 +90,8 @@ static const struct rt_i2c_bit_ops bit_ops = { .udelay = ls1c_udelay, - .delay_us = 20, // ��ֵΪ����(us) - .timeout = 10, // ��λΪtick + .delay_us = 20, // 此值为周期(us) + .timeout = 10, // 单位为tick }; @@ -118,7 +104,7 @@ int ls1c_i2c_init(void) ls1c_i2c_gpio_init(); - rt_i2c_bit_add_bus(&bus, "i2c2"); + rt_i2c_bit_add_bus(&bus, "i2c3"); return RT_EOK; } diff --git a/bsp/ls1cdev/drivers/drv_i2c.h b/bsp/ls1cdev/drivers/drv_i2c.h index 6d07039c2e..cbacdbb0f5 100644 --- a/bsp/ls1cdev/drivers/drv_i2c.h +++ b/bsp/ls1cdev/drivers/drv_i2c.h @@ -1,34 +1,17 @@ /* - * File : drv_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 - * 2017-11-14 ��Ϊ�� first version + * 2017-11-14 勤为本 first version */ #ifndef LS1C_DRV_I2C_H #define LS1C_DRV_I2C_H - int ls1c_i2c_init(void); - - #endif diff --git a/bsp/ls1cdev/drivers/drv_pwm.c b/bsp/ls1cdev/drivers/drv_pwm.c new file mode 100644 index 0000000000..779a7e52b9 --- /dev/null +++ b/bsp/ls1cdev/drivers/drv_pwm.c @@ -0,0 +1,178 @@ +/* + * Copyright (c) 2006-2018, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2018-12-04 Sundm75 the first version + */ +#include <stdint.h> +#include <string.h> +#include <stdlib.h> + +#include <rtthread.h> +#include <rtdevice.h> + +#include "ls1c.h" +#include "../libraries/ls1c_public.h" +#include "../libraries/ls1c_regs.h" +#include "../libraries/ls1c_clock.h" +#include "../libraries/ls1c_pwm.h" +#include "../libraries/ls1c_pin.h" + +#define PWM_CHANNEL_MAX (4) /* 0-3*/ + +#ifdef RT_USING_PWM + +struct rt_ls1c_pwm +{ + struct rt_device_pwm parent; + + rt_uint32_t period[PWM_CHANNEL_MAX]; + rt_uint32_t pulse[PWM_CHANNEL_MAX]; +}; + +static struct rt_ls1c_pwm _ls1c_pwm_device; + +static rt_err_t set(struct rt_device_pwm *device, struct rt_pwm_configuration *configuration) +{ + rt_err_t result = RT_EOK; + struct rt_ls1c_pwm *ls1c_pwm_device = (struct rt_ls1c_pwm *)device; + + if (configuration->channel > (PWM_CHANNEL_MAX - 1)) + { + result = -RT_EIO; + goto _exit; + } + + rt_kprintf("drv_pwm.c set channel %d: period: %d, pulse: %d\n", configuration->channel, configuration->period, configuration->pulse); + + ls1c_pwm_device->period[configuration->channel] = configuration->period; + ls1c_pwm_device->pulse[configuration->channel] = configuration->pulse; + +_exit: + return result; +} + +static rt_err_t get(struct rt_device_pwm *device, struct rt_pwm_configuration *configuration) +{ + rt_err_t result = RT_EOK; + struct rt_ls1c_pwm *ls1c_pwm_device = (struct rt_ls1c_pwm *)device; + + if (configuration->channel > (PWM_CHANNEL_MAX - 1)) + { + result = -RT_EIO; + goto _exit; + } + + configuration->period = ls1c_pwm_device->period[configuration->channel]; + configuration->pulse = ls1c_pwm_device->pulse[configuration->channel]; + rt_kprintf("drv_pwm.c get channel %d: period: %d, pulse: %d\n", configuration->channel, configuration->period, configuration->pulse); + +_exit: + return result; +} + +static rt_err_t control(struct rt_device_pwm *device, int cmd, void *arg) +{ + rt_err_t result = RT_EOK; + struct rt_pwm_configuration * configuration = (struct rt_pwm_configuration *)arg; + + rt_kprintf("drv_pwm.c control cmd: %d. \n", cmd); + + if (cmd == PWM_CMD_ENABLE) + { + rt_kprintf("PWM_CMD_ENABLE\n"); + + pwm_info_t pwm_info; + switch ( configuration->channel) + { + case 0: + pwm_info.gpio = LS1C_PWM0_GPIO06; + //pwm_info.gpio = LS1C_PWM0_GPIO04; + break; + case 1: + pwm_info.gpio = LS1C_PWM1_GPIO92; + //pwm_info.gpio = LS1C_PWM1_GPIO05; + break; + case 2: + pwm_info.gpio = LS1C_PWM2_GPIO52; + //pwm_info.gpio = LS1C_PWM2_GPIO46; + break; + case 3: + pwm_info.gpio = LS1C_PWM3_GPIO47; + //pwm_info.gpio = LS1C_PWM3_GPIO53; + break; + default: + break; + } + pwm_info.mode = PWM_MODE_NORMAL; + pwm_info.duty = ( (float)configuration->pulse ) / ((float)configuration->period ); + pwm_info.period_ns = configuration->period; + pwm_init(&pwm_info); + pwm_enable(&pwm_info); + } + else if (cmd == PWM_CMD_DISABLE) + { + rt_kprintf("PWM_CMD_DISABLE\n"); + pwm_info_t pwm_info; + switch ( configuration->channel) + { + case 0: + pwm_info.gpio = LS1C_PWM0_GPIO06; + //pwm_info.gpio = LS1C_PWM0_GPIO04; + break; + case 1: + pwm_info.gpio = LS1C_PWM1_GPIO92; + //pwm_info.gpio = LS1C_PWM1_GPIO05; + break; + case 2: + pwm_info.gpio = LS1C_PWM2_GPIO52; + //pwm_info.gpio = LS1C_PWM2_GPIO46; + break; + case 3: + pwm_info.gpio = LS1C_PWM3_GPIO47; + //pwm_info.gpio = LS1C_PWM3_GPIO53; + break; + default: + break; + } + pwm_info.mode = PWM_MODE_NORMAL; + pwm_info.duty = ( (float)configuration->pulse ) / ((float)configuration->period ); + pwm_info.period_ns = configuration->period; + pwm_init(&pwm_info); + pwm_disable(&pwm_info); + } + else if (cmd == PWM_CMD_SET) + { + rt_kprintf("PWM_CMD_SET\n"); + result = set(device, (struct rt_pwm_configuration *)arg); + } + else if (cmd == PWM_CMD_GET) + { + rt_kprintf("PWM_CMD_GET\n"); + result = get(device, (struct rt_pwm_configuration *)arg); + } + + return result; +} + +static const struct rt_pwm_ops pwm_ops = +{ + control, +}; + +int rt_hw_pwm_init(void) +{ + int ret = RT_EOK; + + /* add pwm initial. */ + + ret = rt_device_pwm_register(&_ls1c_pwm_device.parent, "pwm", &pwm_ops, RT_NULL); + + return ret; +} +INIT_DEVICE_EXPORT(rt_hw_pwm_init); + +#endif /*RT_USING_PWM*/ diff --git a/bsp/ls1cdev/drivers/drv_pwm.h b/bsp/ls1cdev/drivers/drv_pwm.h new file mode 100644 index 0000000000..427ba0c619 --- /dev/null +++ b/bsp/ls1cdev/drivers/drv_pwm.h @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2006-2018, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2018-12-04 Sundm75 the first version + */ + +#ifndef LS1C_DRV_PWM_H +#define LS1C_DRV_PWM_H + +int ls1c_pwm_init(void); + +#endif /*DRV_CAN_H_*/ diff --git a/bsp/ls1cdev/drivers/drv_rtc.c b/bsp/ls1cdev/drivers/drv_rtc.c new file mode 100644 index 0000000000..0569992c61 --- /dev/null +++ b/bsp/ls1cdev/drivers/drv_rtc.c @@ -0,0 +1,177 @@ +/* + * Copyright (c) 2006-2018, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2018-05-05 sundm75 first version + */ + +/* Includes ------------------------------------------------------------------*/ +#include "board.h" +#include "drv_rtc.h" +#include <rtdevice.h> + +#include "../libraries/ls1c_regs.h" +#include "../libraries/ls1c_rtc.h" + +//#define RT_RTC_DEBUG + +#if defined(RT_USING_RTC) +#ifdef RT_RTC_DEBUG +#define rtc_debug(format,args...) rt_kprintf(format, ##args) +#else +#define rtc_debug(format,args...) +#endif + +static struct rt_device rtc; + +RTC_TypeDef * RTC_Handler; + +static time_t get_timestamp(void) +{ + struct tm tm_new = {0}; + RTC_TimeTypeDef rtcDate; + + RTC_GetTime(RTC_Handler, &rtcDate); + + tm_new.tm_sec = rtcDate.Seconds; + tm_new.tm_min = rtcDate.Minutes; + tm_new.tm_hour = rtcDate.Hours; + + tm_new.tm_mday = rtcDate.Date; + tm_new.tm_mon = rtcDate.Month- 1; + tm_new.tm_year = rtcDate.Year + 2000 - 1900; + + return mktime(&tm_new); +} + +static int set_timestamp(time_t timestamp) +{ + struct tm *p_tm; + RTC_TimeTypeDef rtcDate; + + p_tm = localtime(×tamp); + + rtcDate.Seconds= p_tm->tm_sec ; + rtcDate.Minutes= p_tm->tm_min ; + rtcDate.Hours= p_tm->tm_hour; + + rtcDate.Date= p_tm->tm_mday; + rtcDate.Month= p_tm->tm_mon + 1; + rtcDate.Year= p_tm->tm_year + 1900 - 2000; + + RTC_SetTime(RTC_Handler, &rtcDate); + rt_kprintf("\r\nrtcDate is %d.%d.%d - %d:%d:%d",rtcDate.Year, rtcDate.Month, rtcDate.Date, rtcDate.Hours, rtcDate.Minutes, rtcDate.Seconds); + return RT_EOK; +} + +rt_uint8_t RTC_Init(void) +{ + RTC_Handler = RTC; + return 0; +} + +static rt_err_t rt_rtc_open(rt_device_t dev, rt_uint16_t oflag) +{ + if (dev->rx_indicate != RT_NULL) + { + /* Open Interrupt */ + } + + return RT_EOK; +} + +static rt_size_t rt_rtc_read( + rt_device_t dev, + rt_off_t pos, + void* buffer, + rt_size_t size) +{ + + return 0; +} + + /** + * This function configure RTC device. + * + * @param dev, pointer to device descriptor. + * @param cmd, RTC control command. + * + * @return the error code. + */ +static rt_err_t rt_rtc_control(rt_device_t dev, int cmd, void *args) +{ + rt_err_t result; + RT_ASSERT(dev != RT_NULL); + switch (cmd) + { + case RT_DEVICE_CTRL_RTC_GET_TIME: + + *(rt_uint32_t *)args = get_timestamp(); + rtc_debug("RTC: get rtc_time %x\n", *(rt_uint32_t *)args); + break; + + case RT_DEVICE_CTRL_RTC_SET_TIME: + { + result = set_timestamp(*(rt_uint32_t *)args); + rtc_debug("RTC: set rtc_time %x\n", *(rt_uint32_t *)args); + } + break; + } + + return result; +} + + /** + * This function register RTC device. + * + * @param device, pointer to device descriptor. + * @param name, device name. + * @param flag, configuration flags. + * + * @return the error code. + */ +rt_err_t rt_hw_rtc_register( + rt_device_t device, + const char *name, + rt_uint32_t flag) +{ + RT_ASSERT(device != RT_NULL); + + device->type = RT_Device_Class_RTC; + device->rx_indicate = RT_NULL; + device->tx_complete = RT_NULL; + device->init = RT_NULL; + device->open = rt_rtc_open; + device->close = RT_NULL; + device->read = rt_rtc_read; + device->write = RT_NULL; + device->control = rt_rtc_control; + device->user_data = RT_NULL; /* no private */ + + /* register a character device */ + return rt_device_register(device, name, RT_DEVICE_FLAG_RDWR | flag); +} + + /** + * This function initialize RTC module related hardware and register RTC device to kernel. + * + * @param none. + * + * @return the error code. + */ +int rt_hw_rtc_init(void) +{ + RTC_Init(); + /* register rtc device */ + rt_hw_rtc_register(&rtc, RT_RTC_NAME, 0); + return RT_EOK; +} +INIT_BOARD_EXPORT(rt_hw_rtc_init); +#endif + + + + diff --git a/bsp/ls1cdev/drivers/drv_rtc.h b/bsp/ls1cdev/drivers/drv_rtc.h new file mode 100644 index 0000000000..cea8ebe633 --- /dev/null +++ b/bsp/ls1cdev/drivers/drv_rtc.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2006-2018, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2018-05-05 sundm75 first version + */ + +#ifndef __DRV_RTC_H__ +#define __DRV_RTC_H__ + +#include <rtthread.h> +#include <rtdevice.h> + +int rt_hw_rtc_init(void); + +#endif diff --git a/bsp/ls1cdev/drivers/drv_spi.c b/bsp/ls1cdev/drivers/drv_spi.c index 4b81d55d71..3cc2212850 100644 --- a/bsp/ls1cdev/drivers/drv_spi.c +++ b/bsp/ls1cdev/drivers/drv_spi.c @@ -25,13 +25,14 @@ #include <rtthread.h> #include <drivers/spi.h> +#include <rthw.h> #include "drv_spi.h" +#include "ls1c_public.h" +#include "spi_msd.h" +#include "dfs_fs.h" #include "../libraries/ls1c_pin.h" #ifdef RT_USING_SPI - -//#define DEBUG - #ifdef DEBUG #define DEBUG_PRINTF(...) rt_kprintf(__VA_ARGS__) #else @@ -265,20 +266,24 @@ int ls1c_hw_spi_init(void) #ifdef RT_USING_SPI0 /* attach cs */ { - static struct rt_spi_device spi_device0; - static struct rt_spi_device spi_device1; - static struct rt_spi_device spi_device2; - static struct ls1c_spi_cs spi_cs0; - static struct ls1c_spi_cs spi_cs1; - static struct ls1c_spi_cs spi_cs2; - - /* spi02: CS2 SD Card*/ - spi_cs2.cs = LS1C_SPI_CS_2; - rt_spi_bus_attach_device(&spi_device2, "spi02", "spi0", (void *)&spi_cs2); - spi_cs1.cs = LS1C_SPI_CS_1; - rt_spi_bus_attach_device(&spi_device1, "spi01", "spi0", (void *)&spi_cs1); - spi_cs0.cs = LS1C_SPI_CS_0; - rt_spi_bus_attach_device(&spi_device0, "spi00", "spi0", (void *)&spi_cs0); + static struct rt_spi_device spi_device0; + static struct rt_spi_device spi_device1; + static struct rt_spi_device spi_device2; + static struct rt_spi_device spi_device3; + static struct ls1c_spi_cs spi_cs0; + static struct ls1c_spi_cs spi_cs1; + static struct ls1c_spi_cs spi_cs2; + static struct ls1c_spi_cs spi_cs3; + /* spi02: CS2 SD Card*/ + spi_cs2.cs = LS1C_SPI_CS_2; + rt_spi_bus_attach_device(&spi_device2, "spi02", "spi0", (void *)&spi_cs2); + spi_cs1.cs = LS1C_SPI_CS_1; + rt_spi_bus_attach_device(&spi_device1, "spi01", "spi0", (void *)&spi_cs1); + spi_cs0.cs = LS1C_SPI_CS_0; + rt_spi_bus_attach_device(&spi_device0, "spi00", "spi0", (void *)&spi_cs0); + spi_cs3.cs = LS1C_SPI_CS_3; + rt_spi_bus_attach_device(&spi_device3, "spi03", "spi0", (void*)&spi_cs3); + msd_init("sd0", "spi02"); } #endif #ifdef RT_USING_SPI1 @@ -296,5 +301,21 @@ int ls1c_hw_spi_init(void) INIT_BOARD_EXPORT(ls1c_hw_spi_init); +static int board_sd_init(void) +{ + #if defined(RT_USING_DFS) && defined(RT_USING_DFS_ELMFAT) + /* mount sd card fat partition 1 as root directory */ + if( dfs_mount("sd0", "/", "elm", 0, 0) == 0) + { + rt_kprintf("File System initialized!\n"); + } + else + { + rt_kprintf("File System initialzation failed!\n"); + } + #endif /* RT_USING_DFS && RT_USING_DFS_ELMFAT */ +} +INIT_APP_EXPORT(board_sd_init); + #endif diff --git a/bsp/ls1cdev/drivers/drv_spi.h b/bsp/ls1cdev/drivers/drv_spi.h index 94fbb58097..8b1aa315be 100644 --- a/bsp/ls1cdev/drivers/drv_spi.h +++ b/bsp/ls1cdev/drivers/drv_spi.h @@ -1,25 +1,11 @@ /* - * File : drv_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-11-02 ��Ϊ�� first version + * 2017-11-02 勤为本 first version */ #ifndef LS1C_DRV_SPI_H @@ -43,9 +29,9 @@ struct ls1c_spi_cs /* - * ��ʼ����ע����о1c��spi���� - * @SPI SPI���ߣ�����LS1C_SPI_0�� LS1C_SPI_1 - * @spi_bus_name �������� + * 初始化并注册龙芯1c的spi总线 + * @SPI SPI总线,比如LS1C_SPI_0, LS1C_SPI_1 + * @spi_bus_name 总线名字 * @ret */ rt_err_t ls1c_spi_bus_register(rt_uint8_t SPI, const char *spi_bus_name); diff --git a/bsp/ls1cdev/drivers/drv_touch.c b/bsp/ls1cdev/drivers/drv_touch.c new file mode 100644 index 0000000000..092260aaed --- /dev/null +++ b/bsp/ls1cdev/drivers/drv_touch.c @@ -0,0 +1,270 @@ +/* + * Copyright (c) 2006-2018, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2018-02-08 Zhangyihong the first version + * 2018-10-29 XY + * 2019-04-11 sundm75 modify for ls1c300 & RTGUI + */ + +#include "drv_touch.h" + +#define TOUCH_I2C_NAME "i2c1" + +#ifndef TOUCH_SAMPLE_HZ +#define TOUCH_SAMPLE_HZ (50) +#endif + +#ifndef TOUCH_I2C_NAME +#error "Please define touch i2c name!" +#endif + +#ifdef TINA_USING_TOUCH +#if (defined PKG_USING_GUIENGINE) || (defined RT_USING_RTGUI) +#include <rtgui/event.h> +#include <rtgui/rtgui_server.h> +#endif + +#if 0 +#define TPDEBUG rt_kprintf +#else +#define TPDEBUG(...) +#endif + +static rt_slist_t _driver_list; +static struct rt_i2c_bus_device *i2c_bus = RT_NULL; + +static void post_down_event(rt_uint16_t x, rt_uint16_t y, rt_uint32_t id) +{ +#if (defined PKG_USING_GUIENGINE) || (defined RT_USING_RTGUI) + rt_err_t result; + struct rtgui_event_mouse emouse; + + emouse.parent.sender = RT_NULL; + emouse.wid = RT_NULL; + + emouse.parent.type = RTGUI_EVENT_MOUSE_BUTTON; + emouse.button = RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN; + emouse.x = x; + emouse.y = y; +#ifdef PKG_USING_GUIENGINE + emouse.ts = rt_tick_get(); + emouse.id = id; +#endif + +#ifdef PKG_USING_GUIENGINE + do + { + result = rtgui_server_post_event(&emouse.parent, sizeof(emouse)); + if (result != RT_EOK) + { + rt_thread_delay(RT_TICK_PER_SECOND / TOUCH_SAMPLE_HZ); + } + } + while (result != RT_EOK); +#else + rtgui_server_post_event(&emouse.parent, sizeof(emouse)); +#endif + + TPDEBUG("[TP] touch down [%d, %d]\n", emouse.x, emouse.y); +#endif +} + +static void post_motion_event(rt_uint16_t x, rt_uint16_t y, rt_uint32_t id) +{ +#if (defined PKG_USING_GUIENGINE) || (defined RT_USING_RTGUI) + struct rtgui_event_mouse emouse; + + emouse.parent.sender = RT_NULL; + emouse.wid = RT_NULL; + + emouse.button = RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN; + emouse.parent.type = RTGUI_EVENT_MOUSE_MOTION; + emouse.x = x; + emouse.y = y; +#ifdef PKG_USING_GUIENGINE + emouse.ts = rt_tick_get(); + emouse.id = id; +#endif + rtgui_server_post_event(&emouse.parent, sizeof(emouse)); + TPDEBUG("[TP] touch motion [%d, %d]\n", emouse.x, emouse.y); +#endif +} + +static void post_up_event(rt_uint16_t x, rt_uint16_t y, rt_uint32_t id) +{ +#if (defined PKG_USING_GUIENGINE) || (defined RT_USING_RTGUI) + rt_err_t result; + struct rtgui_event_mouse emouse; + + emouse.parent.sender = RT_NULL; + emouse.wid = RT_NULL; + + emouse.parent.type = RTGUI_EVENT_MOUSE_BUTTON; + emouse.button = RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_UP; + emouse.x = x; + emouse.y = y; +#ifdef PKG_USING_GUIENGINE + emouse.ts = rt_tick_get(); + emouse.id = id; +#endif + +#ifdef PKG_USING_GUIENGINE + do + { + result = rtgui_server_post_event(&emouse.parent, sizeof(emouse)); + if (result != RT_EOK) + { + rt_thread_delay(RT_TICK_PER_SECOND / TOUCH_SAMPLE_HZ); + } + } + while (result != RT_EOK); +#else + rtgui_server_post_event(&emouse.parent, sizeof(emouse)); +#endif + + TPDEBUG("[TP] touch up [%d, %d]\n", emouse.x, emouse.y); +#endif +} + +static void touch_run(void* parameter) +{ + rt_tick_t emouse_id = 0; + struct touch_message msg; + rt_slist_t *driver_list = NULL; + struct touch_driver *current_driver = RT_NULL; + + i2c_bus = rt_i2c_bus_device_find(TOUCH_I2C_NAME); + RT_ASSERT(i2c_bus); + + if(rt_device_open(&i2c_bus->parent, RT_DEVICE_OFLAG_RDWR) != RT_EOK) + { + return; + } + + rt_slist_for_each(driver_list, &_driver_list) + { + current_driver = (struct touch_driver *)driver_list; + if(current_driver->probe(i2c_bus) == RT_TRUE) + { + break; + } + current_driver = RT_NULL; + } + + if(current_driver == RT_NULL) + { + rt_kprintf("[TP] No touch pad or driver.\n"); + rt_device_close((rt_device_t)i2c_bus); + + return; + } + + current_driver->ops->init(i2c_bus); + + while (1) + { + if (rt_sem_take(current_driver->isr_sem, RT_WAITING_FOREVER) != RT_EOK) + { + continue; + } + + if (current_driver->ops->read_point(&msg) != RT_EOK) + { + continue; + } + + switch (msg.event) + { + case TOUCH_EVENT_MOVE: + post_motion_event(msg.x, msg.y, emouse_id); + break; + + case TOUCH_EVENT_DOWN: + emouse_id = rt_tick_get(); + post_down_event(msg.x, msg.y, emouse_id); + break; + + case TOUCH_EVENT_UP: + post_up_event(msg.x, msg.y, emouse_id); + break; + + default: + break; + } + + rt_thread_delay(RT_TICK_PER_SECOND / TOUCH_SAMPLE_HZ); + } +} + +rt_err_t rt_touch_drivers_register(touch_driver_t drv) +{ + RT_ASSERT(drv != RT_NULL); + RT_ASSERT(drv->ops != RT_NULL); + RT_ASSERT(drv->probe != RT_NULL); + + rt_slist_append(&_driver_list, &drv->list); + + return RT_EOK; +} + +static int rt_touch_list_init(void) +{ + rt_slist_init(&_driver_list); + + return RT_EOK; +} +INIT_BOARD_EXPORT(rt_touch_list_init); + +static int rt_touch_init(void) +{ + rt_thread_t thread = RT_NULL; + + thread = rt_thread_create("touch", touch_run, RT_NULL, 2048, 28, 20); + if(thread) + { + return rt_thread_startup(thread); + } + + return RT_ERROR; +} +INIT_APP_EXPORT(rt_touch_init); + +int rt_touch_read(rt_uint16_t addr, void *cmd_buf, size_t cmd_len, void *data_buf, size_t data_len) +{ + struct rt_i2c_msg msgs[2]; + + msgs[0].addr = addr; + msgs[0].flags = RT_I2C_WR; + msgs[0].buf = cmd_buf; + msgs[0].len = cmd_len; + + msgs[1].addr = addr; + msgs[1].flags = RT_I2C_RD; + msgs[1].buf = data_buf; + msgs[1].len = data_len; + + if (rt_i2c_transfer(i2c_bus, msgs, 2) == 2) + return 0; + else + return -1; +} + +int rt_touch_write(rt_uint16_t addr, void *data_buf, size_t data_len) +{ + struct rt_i2c_msg msgs[1]; + + msgs[0].addr = addr; + msgs[0].flags = RT_I2C_WR; + msgs[0].buf = data_buf; + msgs[0].len = data_len; + + if (rt_i2c_transfer(i2c_bus, msgs, 1) == 1) + return 0; + else + return -1; +} +#endif diff --git a/bsp/ls1cdev/drivers/drv_touch.h b/bsp/ls1cdev/drivers/drv_touch.h new file mode 100644 index 0000000000..1ae4c71549 --- /dev/null +++ b/bsp/ls1cdev/drivers/drv_touch.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2006-2018, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2018-02-08 Zhangyihong the first version + * 2018-10-29 XY + */ + +#ifndef __DRV_TOUCH_H__ +#define __DRV_TOUCH_H__ + +#include "rtthread.h" +#include "rtdevice.h" + +#define TOUCH_EVENT_UP (0x01) +#define TOUCH_EVENT_DOWN (0x02) +#define TOUCH_EVENT_MOVE (0x03) +#define TOUCH_EVENT_NONE (0x80) + +struct touch_message +{ + rt_uint16_t x; + rt_uint16_t y; + rt_uint8_t event; +}; +typedef struct touch_message *touch_message_t; + +struct touch_ops +{ + void (*init)(struct rt_i2c_bus_device *); + void (*deinit)(void); + rt_err_t (*read_point)(touch_message_t); +}; +typedef struct touch_ops *touch_ops_t; + +struct touch_driver +{ + rt_slist_t list; + rt_bool_t (*probe)(struct rt_i2c_bus_device *i2c_bus); + rt_sem_t isr_sem; + touch_ops_t ops; + void *user_data; +}; +typedef struct touch_driver *touch_driver_t; + +rt_err_t rt_touch_drivers_register(touch_driver_t drv); + +int rt_touch_read(rt_uint16_t addr, void *cmd_buf, size_t cmd_len, void *data_buf, size_t data_len); +int rt_touch_write(rt_uint16_t addr, void *data_buf, size_t data_len); + +#endif diff --git a/bsp/ls1cdev/drivers/drv_touch_gt9xx.c b/bsp/ls1cdev/drivers/drv_touch_gt9xx.c new file mode 100644 index 0000000000..801ec762cb --- /dev/null +++ b/bsp/ls1cdev/drivers/drv_touch_gt9xx.c @@ -0,0 +1,234 @@ +/* + * Copyright (c) 2006-2018, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2018-02-08 Zhangyihong the first version + * 2018-04-03 XY gt9xx for 1024 * 600 + * 2018-04-14 liu2guang optimize int and rst to pin framework + * 2017-08-08 XY imxrt1052 + * 2018-10-29 XY + */ + +#include "drv_touch.h" +#include "string.h" + +#ifdef TINA_USING_TOUCH + +#define TP_INT_PIN 89 +#define TP_RST_PIN 87 + +#ifndef TP_INT_PIN +#error "Please config touch panel INT pin." +#endif +#ifndef TP_RST_PIN +#error "Please config touch panel RST pin." +#endif + +#ifndef IIC_RETRY_NUM +#define IIC_RETRY_NUM 2 +#endif + +#define GT9xx_TS_ADDR (0x5D) + +#define gt9xx_READ_XY_REG (0x814E) /* 坐标寄存器 */ +#define gt9xx_CLEARBUF_REG (0x814E) /* 清除坐标寄存器 */ +#define gt9xx_CONFIG_REG (0x8047) /* 配置参数寄存器 */ +#define gt9xx_COMMAND_REG (0x8040) /* 实时命令 */ +#define gt9xx_PRODUCT_ID_REG (0x8140) /* 产品ID */ +#define gt9xx_VENDOR_ID_REG (0x814A) /* 当前模组选项信息 */ +#define gt9xx_CONFIG_VERSION_REG (0x8047) /* 配置文件版本号 */ +#define gt9xx_CONFIG_CHECKSUM_REG (0x80FF) /* 配置文件校验码 */ +#define gt9xx_FIRMWARE_VERSION_REG (0x8144) /* 固件版本号 */ + +#if 0 +#define TPDEBUG rt_kprintf +#else +#define TPDEBUG(...) +#endif + +static struct touch_driver gt9xx_driver; + +void gt9xx_hw_reset(rt_uint8_t address) +{ + rt_tick_t delay = rt_tick_from_millisecond(30); + + rt_pin_mode(TP_RST_PIN, PIN_MODE_OUTPUT); + rt_pin_mode(TP_INT_PIN, PIN_MODE_OUTPUT); + + if (address == 0x5D) + { + rt_pin_write(TP_RST_PIN, PIN_LOW); + rt_pin_write(TP_INT_PIN, PIN_LOW); + rt_thread_delay(delay); + rt_pin_write(TP_RST_PIN, PIN_HIGH); + rt_pin_write(TP_INT_PIN, PIN_LOW); + rt_thread_delay(delay); + rt_pin_write(TP_INT_PIN, PIN_LOW); + rt_thread_delay(delay); + rt_pin_write(TP_INT_PIN, PIN_HIGH); + } + else + { + rt_pin_write(TP_RST_PIN, PIN_LOW); + rt_pin_write(TP_INT_PIN, PIN_HIGH); + rt_thread_delay(delay); + rt_pin_write(TP_RST_PIN, PIN_HIGH); + rt_pin_write(TP_INT_PIN, PIN_HIGH); + rt_thread_delay(delay); + rt_pin_write(TP_INT_PIN, PIN_LOW); + rt_thread_delay(delay); + rt_pin_write(TP_INT_PIN, PIN_HIGH); + } +} + +static void gt9xx_soft_reset(struct rt_i2c_bus_device *i2c_bus) +{ + rt_uint8_t buf[3]; + + buf[0] = (rt_uint8_t)((gt9xx_COMMAND_REG >> 8) & 0xFF); + buf[1] = (rt_uint8_t)(gt9xx_COMMAND_REG & 0xFF); + buf[2] = 0x02; + rt_touch_write(GT9xx_TS_ADDR, buf, 3); +} + +static rt_bool_t gt9xx_probe(struct rt_i2c_bus_device *i2c_bus) +{ + rt_uint8_t cmd[2]; + rt_uint8_t buffer[5] = {0}; + + gt9xx_hw_reset(GT9xx_TS_ADDR); + //gt9xx_soft_reset(i2c_bus); + rt_thread_delay(RT_TICK_PER_SECOND / 5); + + cmd[0] = (rt_uint8_t)((gt9xx_PRODUCT_ID_REG >> 8) & 0xFF); + cmd[1] = (rt_uint8_t)(gt9xx_PRODUCT_ID_REG & 0xFF); + if (rt_touch_read(GT9xx_TS_ADDR, &cmd, 2, buffer, 4) != 0) + { + TPDEBUG("[TP] %s failed!\n", __func__); + return RT_FALSE; + } + + buffer[4] = '\0'; + + TPDEBUG("%#X %#X %#X %#X %#X\n", buffer[0], buffer[1], buffer[2], buffer[3], buffer[4]); + + if(!rt_strcmp((const char*)buffer, "911")) + { + rt_kprintf("[TP] Found chip gt911\n"); + return RT_TRUE; + } + else if(!rt_strcmp((const char*)buffer, "9147")) + { + rt_kprintf("[TP] Found chip gt9147\n"); + return RT_TRUE; + } + else if(!rt_strcmp((const char*)buffer, "9157")) + { + rt_kprintf("[TP] Found chip gt9157\n"); + return RT_TRUE; + } + else + { + rt_kprintf("[TP] Uknow chip gt9xx device: [%s]\n", buffer); + } + + return RT_FALSE; +} + +static void gt9xx_init(struct rt_i2c_bus_device *i2c_bus) +{ + rt_uint8_t buf = 0; + rt_uint8_t cmd[2]; + + gt9xx_driver.isr_sem = rt_sem_create("gt9xx", 0, RT_IPC_FLAG_FIFO); + RT_ASSERT(gt9xx_driver.isr_sem); + + cmd[0] = (rt_uint8_t)((gt9xx_CONFIG_VERSION_REG >> 8) & 0xFF); + cmd[1] = (rt_uint8_t)(gt9xx_CONFIG_VERSION_REG & 0xFF); + rt_touch_read(GT9xx_TS_ADDR, &cmd, 2, &buf, 1); + rt_kprintf("[TP] GT9xx Config version: 0x%02X\n", buf); + + cmd[0] = (rt_uint8_t)((gt9xx_VENDOR_ID_REG >> 8) & 0xFF); + cmd[1] = (rt_uint8_t)(gt9xx_VENDOR_ID_REG & 0xFF); + rt_touch_read(GT9xx_TS_ADDR, &cmd, 2, &buf, 1); + rt_kprintf("[TP] GT9xx Sensor id: 0x%02X\n", buf); + + rt_sem_release(gt9xx_driver.isr_sem); +} + +static void gt9xx_deinit(void) +{ + rt_sem_delete(gt9xx_driver.isr_sem); +} + +static rt_err_t gt9xx_read_point(touch_message_t msg) +{ + rt_uint8_t cmd[2]; + rt_uint8_t buf[8] = {0}; + static rt_uint8_t s_tp_down = 0; + + cmd[0] = (rt_uint8_t)((gt9xx_READ_XY_REG >> 8) & 0xFF); + cmd[1] = (rt_uint8_t)(gt9xx_READ_XY_REG & 0xFF); + rt_touch_read(GT9xx_TS_ADDR, &cmd, 2, buf, 8); + + if((buf[0] & 0x01) == 0) + { + if(s_tp_down) + { + s_tp_down = 0; + msg->event = TOUCH_EVENT_UP; + } + else + { + msg->event = TOUCH_EVENT_NONE; + } + } + else + { + msg->x = ((rt_uint16_t)buf[3] << 8) | buf[2]; + msg->y = ((rt_uint16_t)buf[5] << 8) | buf[4]; + + if(s_tp_down) + { + msg->event = TOUCH_EVENT_MOVE; + } + else + { + msg->event = TOUCH_EVENT_DOWN; + s_tp_down = 1; + } + } + + buf[0] = ((gt9xx_CLEARBUF_REG >> 8) & 0xFF); + buf[1] = (gt9xx_CLEARBUF_REG & 0xFF); + buf[2] = 0x00; + rt_touch_write(GT9xx_TS_ADDR, buf, 3); + + rt_sem_release(gt9xx_driver.isr_sem); + + return RT_EOK; +} + +struct touch_ops gt9xx_ops = +{ + .init = gt9xx_init, + .deinit = gt9xx_deinit, + .read_point = gt9xx_read_point, +}; + +static int gt9xx_driver_register(void) +{ + gt9xx_driver.probe = gt9xx_probe; + gt9xx_driver.ops = >9xx_ops; + gt9xx_driver.user_data = RT_NULL; + + rt_touch_drivers_register(>9xx_driver); + + return RT_EOK; +} +INIT_ENV_EXPORT(gt9xx_driver_register); + +#endif diff --git a/bsp/ls1cdev/drivers/drv_uart.c b/bsp/ls1cdev/drivers/drv_uart.c index de0fe1f852..0578eea4fc 100644 --- a/bsp/ls1cdev/drivers/drv_uart.c +++ b/bsp/ls1cdev/drivers/drv_uart.c @@ -1,21 +1,7 @@ /* - * File : drv_uart.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2008 - 2016, 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 @@ -131,7 +117,7 @@ static void uart_irq_handler(int vector, void *param) } -static const struct rt_uart_ops stm32_uart_ops = +static const struct rt_uart_ops ls1c_uart_ops = { ls1c_uart_configure, ls1c_uart_control, @@ -146,8 +132,26 @@ struct rt_uart_ls1c uart2 = LS1C_UART2_IRQ, }; struct rt_serial_device serial2; +#endif /* RT_USING_UART2 */ + +#if defined(RT_USING_UART1) +struct rt_uart_ls1c uart1 = +{ + LS1C_UART1, + LS1C_UART1_IRQ, +}; +struct rt_serial_device serial1; #endif /* RT_USING_UART1 */ +#if defined(RT_USING_UART3) +struct rt_uart_ls1c uart3 = +{ + LS1C_UART3, + LS1C_UART3_IRQ, +}; +struct rt_serial_device serial3; +#endif /* RT_USING_UART3 */ + void rt_hw_uart_init(void) { struct rt_uart_ls1c *uart; @@ -156,7 +160,7 @@ void rt_hw_uart_init(void) #ifdef RT_USING_UART2 uart = &uart2; - serial2.ops = &stm32_uart_ops; + serial2.ops = &ls1c_uart_ops; serial2.config = config; pin_set_purpose(36, PIN_PURPOSE_OTHER); @@ -166,12 +170,55 @@ void rt_hw_uart_init(void) rt_hw_interrupt_install(uart->IRQ, uart_irq_handler, &serial2, "UART2"); - /* register UART1 device */ + /* register UART2 device */ rt_hw_serial_register(&serial2, "uart2", //RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_DMA_RX, RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX, uart); +#endif /* RT_USING_UART2 */ + +#ifdef RT_USING_UART1 + uart = &uart1; + + serial1.ops = &ls1c_uart_ops; + serial1.config = config; + + pin_set_purpose(2, PIN_PURPOSE_OTHER); + pin_set_purpose(3, PIN_PURPOSE_OTHER); + pin_set_remap(2, PIN_REMAP_FOURTH); + pin_set_remap(3, PIN_REMAP_FOURTH); + + rt_hw_interrupt_install(uart->IRQ, uart_irq_handler, &serial1, "UART1"); + + /* register UART1 device */ + rt_hw_serial_register(&serial1, + "uart1", + //RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_DMA_RX, + RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX, + uart); #endif /* RT_USING_UART1 */ + +#ifdef RT_USING_UART3 + uart = &uart3; + + serial3.ops = &ls1c_uart_ops; + serial3.config = config; + + pin_set_purpose(0, PIN_PURPOSE_OTHER); + pin_set_purpose(1, PIN_PURPOSE_OTHER); + pin_set_remap(0, PIN_REMAP_FOURTH); + pin_set_remap(1, PIN_REMAP_FOURTH); + + rt_hw_interrupt_install(uart->IRQ, uart_irq_handler, &serial3, "UART3"); + + /* register UART1 device */ + rt_hw_serial_register(&serial3, + "uart3", + //RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_DMA_RX, + RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX, + uart); +#endif /* RT_USING_UART3 */ + } diff --git a/bsp/ls1cdev/drivers/drv_uart.h b/bsp/ls1cdev/drivers/drv_uart.h index 2c6553bffd..dcc90ea3f9 100644 --- a/bsp/ls1cdev/drivers/drv_uart.h +++ b/bsp/ls1cdev/drivers/drv_uart.h @@ -1,21 +1,7 @@ /* - * File : drv_uart.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 @@ -26,6 +12,7 @@ #define __DRV_UART_H__ #include "ls1c.h" +#include <rthw.h> #define DEV_CLK 252000000 // 252MHz #define UART_BAUDRATE 115200 @@ -45,43 +32,43 @@ #define UART11_BASE 0xBFE4Cb00 /* UART registers */ -#define UART_DAT(base) __REG8(base + 0x00) -#define UART_IER(base) __REG8(base + 0x01) -#define UART_IIR(base) __REG8(base + 0x02) -#define UART_FCR(base) __REG8(base + 0x02) -#define UART_LCR(base) __REG8(base + 0x03) -#define UART_MCR(base) __REG8(base + 0x04) -#define UART_LSR(base) __REG8(base + 0x05) -#define UART_MSR(base) __REG8(base + 0x06) +#define UART_DAT(base) HWREG8(base + 0x00) +#define UART_IER(base) HWREG8(base + 0x01) +#define UART_IIR(base) HWREG8(base + 0x02) +#define UART_FCR(base) HWREG8(base + 0x02) +#define UART_LCR(base) HWREG8(base + 0x03) +#define UART_MCR(base) HWREG8(base + 0x04) +#define UART_LSR(base) HWREG8(base + 0x05) +#define UART_MSR(base) HWREG8(base + 0x06) -#define UART_LSB(base) __REG8(base + 0x00) -#define UART_MSB(base) __REG8(base + 0x01) +#define UART_LSB(base) HWREG8(base + 0x00) +#define UART_MSB(base) HWREG8(base + 0x01) /* UART0 registers */ -#define UART0_DAT __REG8(UART0_BASE + 0x00) -#define UART0_IER __REG8(UART0_BASE + 0x01) -#define UART0_IIR __REG8(UART0_BASE + 0x02) -#define UART0_FCR __REG8(UART0_BASE + 0x02) -#define UART0_LCR __REG8(UART0_BASE + 0x03) -#define UART0_MCR __REG8(UART0_BASE + 0x04) -#define UART0_LSR __REG8(UART0_BASE + 0x05) -#define UART0_MSR __REG8(UART0_BASE + 0x06) +#define UART0_DAT HWREG8(UART0_BASE + 0x00) +#define UART0_IER HWREG8(UART0_BASE + 0x01) +#define UART0_IIR HWREG8(UART0_BASE + 0x02) +#define UART0_FCR HWREG8(UART0_BASE + 0x02) +#define UART0_LCR HWREG8(UART0_BASE + 0x03) +#define UART0_MCR HWREG8(UART0_BASE + 0x04) +#define UART0_LSR HWREG8(UART0_BASE + 0x05) +#define UART0_MSR HWREG8(UART0_BASE + 0x06) -#define UART0_LSB __REG8(UART0_BASE + 0x00) -#define UART0_MSB __REG8(UART0_BASE + 0x01) +#define UART0_LSB HWREG8(UART0_BASE + 0x00) +#define UART0_MSB HWREG8(UART0_BASE + 0x01) /* UART1 registers */ -#define UART1_DAT __REG8(UART1_BASE + 0x00) -#define UART1_IER __REG8(UART1_BASE + 0x01) -#define UART1_IIR __REG8(UART1_BASE + 0x02) -#define UART1_FCR __REG8(UART1_BASE + 0x02) -#define UART1_LCR __REG8(UART1_BASE + 0x03) -#define UART1_MCR __REG8(UART1_BASE + 0x04) -#define UART1_LSR __REG8(UART1_BASE + 0x05) -#define UART1_MSR __REG8(UART1_BASE + 0x06) +#define UART1_DAT HWREG8(UART1_BASE + 0x00) +#define UART1_IER HWREG8(UART1_BASE + 0x01) +#define UART1_IIR HWREG8(UART1_BASE + 0x02) +#define UART1_FCR HWREG8(UART1_BASE + 0x02) +#define UART1_LCR HWREG8(UART1_BASE + 0x03) +#define UART1_MCR HWREG8(UART1_BASE + 0x04) +#define UART1_LSR HWREG8(UART1_BASE + 0x05) +#define UART1_MSR HWREG8(UART1_BASE + 0x06) -#define UART1_LSB __REG8(UART1_BASE + 0x00) -#define UART1_MSB __REG8(UART1_BASE + 0x01) +#define UART1_LSB HWREG8(UART1_BASE + 0x00) +#define UART1_MSB HWREG8(UART1_BASE + 0x01) /* UART interrupt enable register value */ #define UARTIER_IME (1 << 3) diff --git a/bsp/ls1cdev/drivers/drv_wdt.c b/bsp/ls1cdev/drivers/drv_wdt.c new file mode 100644 index 0000000000..4a42220000 --- /dev/null +++ b/bsp/ls1cdev/drivers/drv_wdt.c @@ -0,0 +1,199 @@ +/* + * 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 <rtthread.h> +#include <rtdevice.h> + +#ifdef RT_USING_WDT + +#include <drivers/watchdog.h> +#include "drv_wdt.h" + +#include "ls1c_wdog.h" +#include "ls1c_clock.h" + +typedef enum +{ + RESTENABLE = 0x0, + INTERRUPTENABLE = 0x1, +}wdt_enable_mode; + +static rt_uint32_t heartbeat = 0; + +static rt_err_t wdt_stop(void) +{ + rt_err_t ret = RT_EOK; + + Wdog_Reset(); + ret = (rt_err_t) Wdog_Disable(); + if (ret != RT_EOK) + { + rt_kprintf("Wdog_Disable error!\n"); + return RT_ERROR; + } + return ret; +} + +static rt_err_t wdt_start(int mode) +{ + rt_err_t ret = RT_EOK; + wdt_enable_mode wdt_mode = RESTENABLE; + + ret = (rt_err_t) Wdog_Disable(); + if (ret != RT_EOK) + { + rt_kprintf("Wdog_Disable error!\n"); + return RT_ERROR; + } + + if((mode == RESTENABLE) || (mode == INTERRUPTENABLE)) + { + wdt_mode = mode; + } + Wdog_Enable(); + Wdog_Set(); + if (ret != RT_EOK) + { + rt_kprintf("Wdog_Enable error!\n"); + return RT_ERROR; + } + + return ret; +} + +static rt_err_t wdt_keepalive(void) +{ + rt_err_t ret = RT_EOK; + rt_uint32_t index = 0; + + index = heartbeat * clk_get_apb_rate(); + ret = (rt_err_t) Wdog_LoadValue(index); + Wdog_Set(); + if (ret != 0) + { + rt_kprintf("LS1C_Wdog_ClrTimeout error!\n"); + return RT_ERROR; + } + + return ret; +} + +static rt_uint32_t wdt_get_timeleft(void) +{ + rt_uint32_t cnt = 0; + rt_uint32_t second = 0; + + cnt = (rt_uint32_t) Wdog_GetValue(); + second = cnt/clk_get_apb_rate(); + + return second; +} + +static rt_err_t wdt_set_timeout(rt_uint32_t second) +{ + rt_err_t ret = RT_EOK; + rt_uint32_t index = 0; + + index = second * clk_get_apb_rate(); + ret = (rt_err_t) Wdog_LoadValue(index); + if (ret != RT_EOK) + { + rt_kprintf("Wdog_LoadValue error!\n"); + return RT_ERROR; + } + return ret; +} + +static rt_err_t watchdog_init(rt_watchdog_t *wdt) +{ + struct wdt_driver *wdt_drv = wdt->parent.user_data; + if (wdt_drv->in_use) return -RT_EBUSY; + + Wdog_Init(); + + return RT_EOK; +} + +static rt_err_t watchdog_ctrl(rt_watchdog_t *wdt, int cmd, void *arg) +{ + rt_uint32_t val; + int mode; + + switch (cmd) + { + case RT_DEVICE_CTRL_WDT_START: + mode = *((int *)(arg)); + wdt_start(mode); + break; + + case RT_DEVICE_CTRL_WDT_STOP: + Wdog_Disable(); + break; + + case RT_DEVICE_CTRL_WDT_KEEPALIVE: + wdt_keepalive(); + break; + + case RT_DEVICE_CTRL_WDT_SET_TIMEOUT: + heartbeat = *((rt_uint32_t *)(arg)); + wdt_set_timeout(heartbeat); + break; + + case RT_DEVICE_CTRL_WDT_GET_TIMEOUT: + arg = &heartbeat; + break; + + case RT_DEVICE_CTRL_WDT_GET_TIMELEFT: + val = (rt_uint32_t) wdt_get_timeleft(); + arg = &val; + break; + + default: + return -RT_EIO; + } + return RT_EOK; +} + +struct rt_watchdog_ops watchdog_ops = +{ + .init = &watchdog_init, + .control = &watchdog_ctrl, +}; + +int wdt_exit(void *priv_data) +{ + return 0; +} + +int rt_hw_wdt_init(void) +{ + rt_watchdog_t *wdt_dev; + struct wdt_driver *wdt_drv; + + wdt_drv = (struct wdt_driver *)rt_malloc(sizeof(struct wdt_driver)); + rt_memset(wdt_drv, 0, sizeof(struct wdt_driver)); + + wdt_dev = (rt_watchdog_t *)rt_malloc(sizeof(rt_watchdog_t)); + + if (wdt_dev == RT_NULL) + { + rt_kprintf("ERROR: %s rt_watchdog_t malloc failed\n", __func__); + } + + wdt_dev->ops = &watchdog_ops; + + rt_hw_watchdog_register(wdt_dev, "wdt", RT_DEVICE_OFLAG_RDWR, wdt_drv); + + return 0; +} + +INIT_BOARD_EXPORT(rt_hw_wdt_init); + +#endif diff --git a/bsp/ls1cdev/drivers/drv_wdt.h b/bsp/ls1cdev/drivers/drv_wdt.h new file mode 100644 index 0000000000..a017edb19a --- /dev/null +++ b/bsp/ls1cdev/drivers/drv_wdt.h @@ -0,0 +1,23 @@ +/* + * 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 WDT_H_ +#define WDT_H_ + +struct wdt_driver +{ + unsigned long in_use; + + void* priv; +}; + +int rt_hw_wdt_init(void); + +#endif /* WDT_H_ */ diff --git a/bsp/ls1cdev/drivers/hw_i2c.c b/bsp/ls1cdev/drivers/hw_i2c.c index 6d427701ed..1f63df1ab9 100644 --- a/bsp/ls1cdev/drivers/hw_i2c.c +++ b/bsp/ls1cdev/drivers/hw_i2c.c @@ -1,24 +1,10 @@ /* - * File :hw_i2c.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2017, 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 + * Date Author Notes * 2018-01-04 Sundm75 the first version */ @@ -40,31 +26,31 @@ rt_size_t rt_i2c_master_xfer(struct rt_i2c_bus_device *bus, rt_uint32_t num) { struct ls1c_i2c_bus * i2c_bus = (struct ls1c_i2c_bus *)bus; - ls1c_i2c_info_t i2c_info; + ls1c_i2c_info_t i2c_info; struct rt_i2c_msg *msg; int i; rt_int32_t ret = RT_EOK; i2c_info.clock = 50000; // 50kb/s - i2c_info.I2Cx = i2c_bus->u32Module; - i2c_init(&i2c_info); - + i2c_info.I2Cx = i2c_bus->u32Module; + i2c_init(&i2c_info); + for (i = 0; i < num; i++) { msg = &msgs[i]; if (msg->flags == RT_I2C_RD) { - i2c_send_start_and_addr(&i2c_info, msg->addr, LS1C_I2C_DIRECTION_READ); - i2c_receive_ack(&i2c_info); - i2c_receive_data(&i2c_info, (rt_uint8_t *)msg->buf, msg->len); - i2c_send_stop(&i2c_info); - } + i2c_send_start_and_addr(&i2c_info, msg->addr, LS1C_I2C_DIRECTION_READ); + i2c_receive_ack(&i2c_info); + i2c_receive_data(&i2c_info, (rt_uint8_t *)msg->buf, msg->len); + i2c_send_stop(&i2c_info); + } else if(msg->flags == RT_I2C_WR) { - i2c_send_start_and_addr(&i2c_info, msg->addr, LS1C_I2C_DIRECTION_WRITE); - i2c_receive_ack(&i2c_info); - i2c_send_data(&i2c_info, (rt_uint8_t *)msg->buf, msg->len); - i2c_send_stop(&i2c_info); - } + i2c_send_start_and_addr(&i2c_info, msg->addr, LS1C_I2C_DIRECTION_WRITE); + i2c_receive_ack(&i2c_info); + i2c_send_data(&i2c_info, (rt_uint8_t *)msg->buf, msg->len); + i2c_send_stop(&i2c_info); + } ret++; } return ret; diff --git a/bsp/ls1cdev/drivers/hw_i2c.h b/bsp/ls1cdev/drivers/hw_i2c.h index 1bd4e991ed..cc3e25506f 100644 --- a/bsp/ls1cdev/drivers/hw_i2c.h +++ b/bsp/ls1cdev/drivers/hw_i2c.h @@ -1,21 +1,7 @@ /* - * File : hw_i2c.h - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2017, 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/drivers/net/SConscript b/bsp/ls1cdev/drivers/net/SConscript index 1eea3171de..7e5532099e 100644 --- a/bsp/ls1cdev/drivers/net/SConscript +++ b/bsp/ls1cdev/drivers/net/SConscript @@ -5,6 +5,12 @@ src = Glob('*.c') CPPPATH = [cwd] +if GetDepend('RT_USING_LWIP') == False: + SrcRemove(src, 'mii.c') + SrcRemove(src, 'synopGMAC.c') + SrcRemove(src, 'synopGMAC_Dev.c') + SrcRemove(src, 'synopGMAC_plat.c') + group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH) diff --git a/bsp/ls1cdev/drivers/net/mii.c b/bsp/ls1cdev/drivers/net/mii.c index b53592f87e..43ade097cf 100644 --- a/bsp/ls1cdev/drivers/net/mii.c +++ b/bsp/ls1cdev/drivers/net/mii.c @@ -1,21 +1,7 @@ /* - * File : mii.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) chinesebear + * 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/drivers/net/mii.h b/bsp/ls1cdev/drivers/net/mii.h index cbdd3d5cef..24563834ec 100644 --- a/bsp/ls1cdev/drivers/net/mii.h +++ b/bsp/ls1cdev/drivers/net/mii.h @@ -1,21 +1,7 @@ /* - * File : mii.h - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) chinesebear + * 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/drivers/net/synopGMAC.c b/bsp/ls1cdev/drivers/net/synopGMAC.c index 3ddc1af583..da8c3c89fb 100644 --- a/bsp/ls1cdev/drivers/net/synopGMAC.c +++ b/bsp/ls1cdev/drivers/net/synopGMAC.c @@ -1,21 +1,7 @@ /* - * File : synopGMAC.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) chinesebear + * 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 @@ -586,47 +572,37 @@ struct pbuf *rt_eth_rx(rt_device_t device) } /*Handle the Receive Descriptors*/ - // do{ - desc_index = synopGMAC_get_rx_qptr(gmacdev, &status, &dma_addr1, NULL, &data1, &dma_addr2, NULL, &data2); - - if (desc_index >= 0 && data1 != 0) - { - DEBUG_MES("Received Data at Rx Descriptor %d for skb 0x%08x whose status is %08x\n", desc_index, dma_addr1, status); - - if (synopGMAC_is_rx_desc_valid(status) || SYNOP_PHY_LOOPBACK) - { - pbuf = pbuf_alloc(PBUF_LINK, MAX_ETHERNET_PAYLOAD, PBUF_RAM); - if (pbuf == 0) rt_kprintf("===error in pbuf_alloc\n"); - - - dma_addr1 = plat_dma_map_single(gmacdev, (void *)data1, RX_BUF_SIZE); - len = synopGMAC_get_rx_desc_frame_length(status); //Not interested in Ethernet CRC bytes - rt_memcpy(pbuf->payload, (char *)data1, len); - DEBUG_MES("==get pkg len: %d\n", len); - } - else - { - rt_kprintf("s: %08x\n", status); - adapter->synopGMACNetStats.rx_errors++; - adapter->synopGMACNetStats.collisions += synopGMAC_is_rx_frame_collision(status); - adapter->synopGMACNetStats.rx_crc_errors += synopGMAC_is_rx_crc(status); - adapter->synopGMACNetStats.rx_frame_errors += synopGMAC_is_frame_dribbling_errors(status); - adapter->synopGMACNetStats.rx_length_errors += synopGMAC_is_rx_frame_length_errors(status); - } - - desc_index = synopGMAC_set_rx_qptr(gmacdev, dma_addr1, RX_BUF_SIZE, (u32)data1, 0, 0, 0); - - if (desc_index < 0) + desc_index = synopGMAC_get_rx_qptr(gmacdev, &status, &dma_addr1, NULL, &data1, &dma_addr2, NULL, &data2); + if (desc_index >= 0 && data1 != 0) { + DEBUG_MES("Received Data at Rx Descriptor %d for skb 0x%08x whose status is %08x\n", desc_index, dma_addr1, status); + if (synopGMAC_is_rx_desc_valid(status) || SYNOP_PHY_LOOPBACK) + { + dma_addr1 = plat_dma_map_single(gmacdev, (void *)data1, RX_BUF_SIZE); + len = synopGMAC_get_rx_desc_frame_length(status)-4; //Not interested in Ethernet CRC bytes + pbuf = pbuf_alloc(PBUF_LINK, len, PBUF_RAM); + if (pbuf == 0) rt_kprintf("===error in pbuf_alloc\n"); + rt_memcpy(pbuf->payload, (char *)data1, len); + DEBUG_MES("==get pkg len: %d\n", len); + } + else + { + rt_kprintf("s: %08x\n", status); + adapter->synopGMACNetStats.rx_errors++; + adapter->synopGMACNetStats.collisions += synopGMAC_is_rx_frame_collision(status); + adapter->synopGMACNetStats.rx_crc_errors += synopGMAC_is_rx_crc(status); + adapter->synopGMACNetStats.rx_frame_errors += synopGMAC_is_frame_dribbling_errors(status); + adapter->synopGMACNetStats.rx_length_errors += synopGMAC_is_rx_frame_length_errors(status); + } + desc_index = synopGMAC_set_rx_qptr(gmacdev, dma_addr1, RX_BUF_SIZE, (u32)data1, 0, 0, 0); + if (desc_index < 0) + { #if SYNOP_RX_DEBUG - rt_kprintf("Cannot set Rx Descriptor for data1 %08x\n", (u32)data1); + rt_kprintf("Cannot set Rx Descriptor for data1 %08x\n", (u32)data1); #endif - plat_free_memory((void *)data1); + plat_free_memory((void *)data1); + } } - - } - - // }while(desc_index >= 0); rt_sem_release(&sem_lock); DEBUG_MES("%s : before return \n", __FUNCTION__); return pbuf; @@ -979,6 +955,8 @@ int rt_hw_eth_init(void) eth_device_init(&(eth_dev.parent), "e0"); + eth_device_linkchange(ð_dev.parent, RT_TRUE); //linkup the e0 for lwip to check + return 0; } diff --git a/bsp/ls1cdev/drivers/net/synopGMAC.h b/bsp/ls1cdev/drivers/net/synopGMAC.h index d4d06e6a65..e244c14892 100644 --- a/bsp/ls1cdev/drivers/net/synopGMAC.h +++ b/bsp/ls1cdev/drivers/net/synopGMAC.h @@ -1,21 +1,7 @@ /* - * File : synopGMAC.h - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) chinesebear + * 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/drivers/net/synopGMAC_Dev.c b/bsp/ls1cdev/drivers/net/synopGMAC_Dev.c index 6c5b4a2cde..a41038f35c 100644 --- a/bsp/ls1cdev/drivers/net/synopGMAC_Dev.c +++ b/bsp/ls1cdev/drivers/net/synopGMAC_Dev.c @@ -1,33 +1,7 @@ -/** \file - * This file defines the synopsys GMAC device dependent functions. - * Most of the operations on the GMAC device are available in this file. - * Functions for initiliasing and accessing MAC/DMA/PHY registers and the DMA descriptors - * are encapsulated in this file. The functions are platform/host/OS independent. - * These functions in turn use the low level device dependent (HAL) functions to - * access the register space. - * \internal - * ------------------------REVISION HISTORY--------------------------------- - * Synopsys 01/Aug/2007 Created - */ - /* - * File : synopGMAC_Dev.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) chinesebear - * - * 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: * Date Author Notes diff --git a/bsp/ls1cdev/drivers/net/synopGMAC_Dev.h b/bsp/ls1cdev/drivers/net/synopGMAC_Dev.h index 25c7814a16..74bc850d86 100644 --- a/bsp/ls1cdev/drivers/net/synopGMAC_Dev.h +++ b/bsp/ls1cdev/drivers/net/synopGMAC_Dev.h @@ -1,32 +1,7 @@ -/**\file - * This file defines the function prototypes for the Synopsys GMAC device and the - * Marvell 88E1011/88E1011S integrated 10/100/1000 Gigabit Ethernet Transceiver. - * Since the phy register mapping are standardised, the phy register map and the - * bit definitions remain the same for other phy as well. - * This also defines some of the Ethernet related parmeters. - * \internal - * -----------------------------REVISION HISTORY------------------------------------ - * Synopsys 01/Aug/2007 Created - */ - /* - * File : synopGMAC_Dev.h - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) chinesebear - * - * 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: * Date Author Notes diff --git a/bsp/ls1cdev/drivers/net/synopGMAC_Host.h b/bsp/ls1cdev/drivers/net/synopGMAC_Host.h index 05f289c8c7..e6d31d551d 100644 --- a/bsp/ls1cdev/drivers/net/synopGMAC_Host.h +++ b/bsp/ls1cdev/drivers/net/synopGMAC_Host.h @@ -1,21 +1,7 @@ /* - * File : synopGMAC_Host.h - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) chinesebear + * 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/drivers/net/synopGMAC_debug.h b/bsp/ls1cdev/drivers/net/synopGMAC_debug.h index 9e65d1d945..9766587e1a 100644 --- a/bsp/ls1cdev/drivers/net/synopGMAC_debug.h +++ b/bsp/ls1cdev/drivers/net/synopGMAC_debug.h @@ -1,21 +1,7 @@ /* - * File : synopGMAC_debug.h - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) chinesebear + * 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/drivers/net/synopGMAC_network_interface.h b/bsp/ls1cdev/drivers/net/synopGMAC_network_interface.h index e93ab6a66e..8ded91d359 100644 --- a/bsp/ls1cdev/drivers/net/synopGMAC_network_interface.h +++ b/bsp/ls1cdev/drivers/net/synopGMAC_network_interface.h @@ -1,30 +1,7 @@ -/** \file - * Header file for the nework dependent functionality. - * The function prototype listed here are linux dependent. - * - * \internal - * ---------------------------REVISION HISTORY------------------- - * Synopsys 01/Aug/2007 Created - */ - /* - * File : synopGMAC_network_interface.h - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) chinesebear - * - * 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: * Date Author Notes diff --git a/bsp/ls1cdev/drivers/net/synopGMAC_plat.c b/bsp/ls1cdev/drivers/net/synopGMAC_plat.c index 8f70ad99d7..3dfbe077d7 100644 --- a/bsp/ls1cdev/drivers/net/synopGMAC_plat.c +++ b/bsp/ls1cdev/drivers/net/synopGMAC_plat.c @@ -1,34 +1,7 @@ -/**\file - * This file defines the wrapper for the platform/OS related functions - * The function definitions needs to be modified according to the platform - * and the Operating system used. - * This file should be handled with greatest care while porting the driver - * to a different platform running different operating system other than - * Linux 2.6.xx. - * \internal - * ----------------------------REVISION HISTORY----------------------------- - * Synopsys 01/Aug/2007 Created - */ - - /* - * File : synopGMAC_plat.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) chinesebear - * - * 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: * Date Author Notes diff --git a/bsp/ls1cdev/drivers/net/synopGMAC_plat.h b/bsp/ls1cdev/drivers/net/synopGMAC_plat.h index 1b1283f2fc..173015a53f 100644 --- a/bsp/ls1cdev/drivers/net/synopGMAC_plat.h +++ b/bsp/ls1cdev/drivers/net/synopGMAC_plat.h @@ -1,33 +1,7 @@ -/**\file - * This file serves as the wrapper for the platform/OS dependent functions - * It is needed to modify these functions accordingly based on the platform and the - * OS. Whenever the synopsys GMAC driver ported on to different platform, this file - * should be handled at most care. - * The corresponding function definitions for non-inline functions are available in - * synopGMAC_plat.c file. - * \internal - * -------------------------------------REVISION HISTORY--------------------------- - * Synopsys 01/Aug/2007 Created - */ - /* - * File : synopGMAC_plat.h - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) chinesebear - * - * 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: * Date Author Notes @@ -65,14 +39,6 @@ typedef int bool; //typedef unsigned long dma_addr_t; -//sw -/* write/read MMIO register */ -#define writeb(val, addr) (*(volatile u8*)(addr) = (val)) -#define writew(val, addr) (*(volatile u16*)(addr) = (val)) -#define writel(val, addr) (*(volatile u32*)(addr) = (val)) -#define readb(addr) (*(volatile u8*)(addr)) -#define readw(addr) (*(volatile u16*)(addr)) -#define readl(addr) (*(volatile u32*)(addr)) #define KUSEG_ADDR 0x0 diff --git a/bsp/ls1cdev/drivers/net/synopGMAC_types.h b/bsp/ls1cdev/drivers/net/synopGMAC_types.h index d808bec846..88504eebf7 100644 --- a/bsp/ls1cdev/drivers/net/synopGMAC_types.h +++ b/bsp/ls1cdev/drivers/net/synopGMAC_types.h @@ -1,21 +1,7 @@ /* - * File : synopGMAC_types.h - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) chinesebear + * 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/drivers/selfboot.h b/bsp/ls1cdev/drivers/selfboot.h new file mode 100644 index 0000000000..def9e38229 --- /dev/null +++ b/bsp/ls1cdev/drivers/selfboot.h @@ -0,0 +1,168 @@ +/* + * Copyright (c) 2006-2019, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2019-12-04 Jiaxun Yang Initial version + */ + +#ifndef __RT_LS1C_SELFBOOT_H +#define __RT_LS1C_SELFBOOT_H + +/* SDRAM PARAM macro */ +#define SD_FREQ (((APB_CLK / 4) * (PLL_MULT / CPU_DIV)) / SDRAM_PARAM_DIV_NUM) + + +/* SDRAM ROW */ +#define ROW_1K 0x7 +#define ROW_2K 0x0 +#define ROW_4K 0x1 +#define ROW_8K 0x2 +#define ROW_16K 0x3 +/* SDRAM COL */ +#define COL_256 0x7 +#define COL_512 0x0 +#define COL_1K 0x1 +#define COL_2K 0x2 +#define COL_4K 0x3 +/* SDRAM WIDTH */ +#define WIDTH_8 0x0 +#define WIDTH_16 0x1 +#define WIDTH_32 0x2 + +#define TRCD 3 +#define TCL 3 +#define TRP 3 +#define TRFC 8 +#define TRAS 6 +#define TREF 0x818 +#define TWR 2 + +#define DEF_SEL 0x1 +#define DEF_SEL_N 0x0 +#define HANG_UP 0x1 +#define HANG_UP_N 0x0 +#define CFG_VALID 0x1 + +#include "board.h" + +#define SD_PARA0 (0x7f<<25 | \ + (TRAS << 21) | \ + (TRFC << 17) | (TRP << 14) | (TCL << 11) | \ + (TRCD << 8) | (SDRAM_WIDTH << 6) | (SDRAM_COL << 3) | \ + SDRAM_ROW) + +#define SD_PARA1 ((HANG_UP_N << 8) | (DEF_SEL_N << 7) | (TWR << 5) | (TREF >> 7)) + +#define SD_PARA1_EN ((CFG_VALID << 9) | (HANG_UP_N << 8) | \ + (DEF_SEL_N << 7) | (TWR << 5) | (TREF >> 7)) + +#define LS1C_CBUS_FIRST1 0xBFE011C4 +#define LS1C_UART2_BASE 0xBFE48000 + +/* UART register offset*/ +#define LS1C_UART_DAT_OFFSET (0) +#define LS1C_UART_IER_OFFSET (1) +#define LS1C_UART_IIR_OFFSET (2) +#define LS1C_UART_FCR_OFFSET (2) +#define LS1C_UART_LCR_OFFSET (3) +#define LS1C_UART_MCR_OFFSET (4) +#define LS1C_UART_LSR_OFFSET (5) +#define LS1C_UART_MSR_OFFSET (6) + +#define LS1C_UART_LSB_OFFSET (0) +#define LS1C_UART_MSB_OFFSET (1) + +/* interrupt enable register */ +#define IER_IRxE 0x1 +#define IER_ITxE 0x2 +#define IER_ILE 0x4 +#define IER_IME 0x8 + +/* interrupt identification register */ +#define IIR_IMASK 0xf /* mask */ +#define IIR_RXTOUT 0xc /* receive timeout */ +#define IIR_RLS 0x6 /* receive line status */ +#define IIR_RXRDY 0x4 /* receive ready */ +#define IIR_TXRDY 0x2 /* transmit ready */ +#define IIR_NOPEND 0x1 /* nothing */ +#define IIR_MLSC 0x0 /* modem status */ +#define IIR_FIFO_MASK 0xc0 /* set if FIFOs are enabled */ + +/* fifo control register */ +#define FIFO_ENABLE 0x01 /* enable fifo */ +#define FIFO_RCV_RST 0x02 /* reset receive fifo */ +#define FIFO_XMT_RST 0x04 /* reset transmit fifo */ +#define FIFO_DMA_MODE 0x08 /* enable dma mode */ +#define FIFO_TRIGGER_1 0x00 /* trigger at 1 char */ +#define FIFO_TRIGGER_4 0x40 /* trigger at 4 chars */ +#define FIFO_TRIGGER_8 0x80 /* trigger at 8 chars */ +#define FIFO_TRIGGER_14 0xc0 /* trigger at 14 chars */ + +/* character format control register */ +#define CFCR_DLAB 0x80 /* divisor latch */ +#define CFCR_SBREAK 0x40 /* send break */ +#define CFCR_PZERO 0x30 /* zero parity */ +#define CFCR_PONE 0x20 /* one parity */ +#define CFCR_PEVEN 0x10 /* even parity */ +#define CFCR_PODD 0x00 /* odd parity */ +#define CFCR_PENAB 0x08 /* parity enable */ +#define CFCR_STOPB 0x04 /* 2 stop bits */ +#define CFCR_8BITS 0x03 /* 8 data bits */ +#define CFCR_7BITS 0x02 /* 7 data bits */ +#define CFCR_6BITS 0x01 /* 6 data bits */ +#define CFCR_5BITS 0x00 /* 5 data bits */ + +/* modem control register */ +#define MCR_LOOPBACK 0x10 /* loopback */ +#define MCR_IENABLE 0x08 /* output 2 = int enable */ +#define MCR_DRS 0x04 /* output 1 = xxx */ +#define MCR_RTS 0x02 /* enable RTS */ +#define MCR_DTR 0x01 /* enable DTR */ + +/* line status register */ +#define LSR_RCV_FIFO 0x80 /* error in receive fifo */ +#define LSR_TSRE 0x40 /* transmitter empty */ +#define LSR_TXRDY 0x20 /* transmitter ready */ +#define LSR_BI 0x10 /* break detected */ +#define LSR_FE 0x08 /* framing error */ +#define LSR_PE 0x04 /* parity error */ +#define LSR_OE 0x02 /* overrun error */ +#define LSR_RXRDY 0x01 /* receiver ready */ +#define LSR_RCV_MASK 0x1f + + +/* External clock frequency */ +#define AHB_CLK (24000000) +#define APB_CLK (AHB_CLK) + + +/* START_FREQ register bits */ +#define M_PLL_SHIFT (8) +#define M_PLL (0xff << M_PLL_SHIFT) +#define FRAC_N_SHIFT (16) +#define FRAC_N (0xff << FRAC_N_SHIFT) +#define DIV_SDRAM_SHIFT (0) +#define DIV_SDRAM (0x3 << DIV_SDRAM_SHIFT) + +/* CLK_DIV_PARAM register bits */ +#define DIV_PIX_EN (0x1 << 31) +#define DIV_PIX (0x7f << 24) +#define DIV_CAM_EN (0x1 << 23) +#define DIV_CAM (0x7f << 16) +#define DIV_CPU_EN (0x1 << 15) +#define DIV_CPU (0x7f << 8) +#define DIV_PIX_VALID (0x1 << 5) +#define DIV_PIX_SEL (0x1 << 4) +#define DIV_CAM_VALID (0x1 << 3) +#define DIV_CAM_SEL (0x1 << 2) +#define DIV_CPU_VALID (0x1 << 1) +#define DIV_CPU_SEL (0x1 << 0) + +#define DIV_PIX_SHIFT (24) +#define DIV_CAM_SHIFT (16) +#define DIV_CPU_SHIFT (8) + +#endif diff --git a/bsp/ls1cdev/drivers/selfboot_gcc.S b/bsp/ls1cdev/drivers/selfboot_gcc.S new file mode 100644 index 0000000000..03dfc206d4 --- /dev/null +++ b/bsp/ls1cdev/drivers/selfboot_gcc.S @@ -0,0 +1,549 @@ +/* + * Copyright (c) 2006-2019, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Origin Authors: Loongson Technology Corporation Limited, + * caogos <[email protected]>, Jiaxun Yang <[email protected]>, + * + * Also thanks to Liu Shiwei <[email protected]> and other Loongson + * Community developers. + * + * Change Logs: + * Date Author Notes + * 2019-12-04 Jiaxun Yang Initial version + */ + +#include <rtconfig.h> + +#ifdef RT_USING_SELF_BOOT + +#ifndef __ASSEMBLY__ +#define __ASSEMBLY__ +#endif + +#include <mips.h> +#include "selfboot.h" +#include "ls1c.h" +#include "cache.h" + +/* + * Register usage: + * + * s0 link versus load offset, used to relocate absolute adresses. + * s1 free + * s2 memory size + * s3 free + * s4 free + * s5 dbg + * s6 sdCfg + * s7 rasave + * s8 free + */ + +#define tmpsize s1 +#define msize s2 +#define bonito s4 +#define dbg s5 +#define sdCfg s6 + + +/* Macros */ +#ifdef RT_SELF_BOOT_DEBUG +#define PRINTSTR(str) \ + .pushsection .selfboot_data; .align 4; 98: .asciz str; .popsection; la a0, 98b; bal stringserial; nop +#else +#define PRINTSTR(x) +#endif + +#define DELAY(count) \ + li v0, count; \ +99: \ + bnez v0, 99b;\ + addiu v0, -1 + +.section ".selfboot", "ax" +.set noreorder +.set mips32 +.globl _start +.extern start +_start: + +/* NMI/Reset vector starts here*/ + mtc0 zero, CP0_STATUS /* set cp0 status register to zero */ + mtc0 zero, CP0_CAUSE /* set cp0 cause register to zero */ + + li t0, ST0_BEV /* set exception vector to in flash location */ + mtc0 t0, CP0_STATUS + + /* Speed up SPI reading */ + li t0, 0xbfe80000 /* load SPI0 controler base address to t0 */ + li t1, 0x17 /* load "div 4, fast_read + burst_en + memory_en double I/O" to + * to t0 for write, not all the flash chips support this mode */ + sb t1, 0x4(t0) /* set sfc_param register */ + li t1, 0x05 + sb t1, 0x6(t0) /* set sfc_timing register */ + + bal locate /* branch out of vector and get current address to ra */ + nop + +/* in-flash exception vectors start here */ +/* save the exception types to a0 and print out PANIC message in exc_common */ +#define EXC_TLB_REFILL 0x0 +#define EXC_CACHE_ERR 0x1 +#define EXC_GEN 0x2 +#define EXC_INT 0x3 + +.org 0x200 /* 0xbfc00200 TLB_REFILL exception */ + li a0, EXC_TLB_REFILL + b exc_common + nop + +.org 0x300 /* 0xbfc00300 Cache Error exception */ + li a0, EXC_CACHE_ERR + b exc_common + nop + +.org 0x380 /* 0xbfc00300 General exception */ + li a0,EXC_GEN + b exc_common + nop + +.org 0x400 /* 0xbfc00400 Interrupt exception */ + li a0, EXC_INT + b exc_common + nop + +1: /* impossible to reach here, so make a dead loop */ + b 1b + nop + +exc_common: /* try one cause and pass to next */ + li s1, EXC_TLB_REFILL + bne a0, s1, 1f + nop + PRINTSTR("\r\nEARLY_PANIC: Exception TLB Refill") + b print_cause + nop +1: + li s1, EXC_CACHE_ERR + bne a0, s1, 1f + nop + PRINTSTR("\r\nEARLY_PANIC: CACHE Error: ") + mfc0 a0, CP0_CACHEERR + bal hexserial + nop + b print_cause + nop +1: + li s1, EXC_GEN + bne a0, s1, 1f + nop + PRINTSTR("\r\nEARLY_PANIC: General Exception") + b print_cause + nop +1: + li s1, EXC_INT + bne a0, s1, print_cause /* if all exceptions in a0 not reached, + * print_cause directly*/ + nop + PRINTSTR("\r\nEARLY_PANIC: Interrupt Exception") +print_cause: + PRINTSTR("\r\nCAUSE=") + mfc0 a0, CP0_CAUSE + bal hexserial + nop + + PRINTSTR("\r\nSTATUS=") + mfc0 a0, CP0_STATUS + bal hexserial + nop + + PRINTSTR("\r\nERRORPC=") + mfc0 a0, CP0_ERROREPC + bal hexserial + nop + + PRINTSTR("\r\nEPC=") + mfc0 a0, CP0_EPC + bal hexserial + nop + + PRINTSTR("\r\nBADADDR=") + mfc0 a0, CP0_BADVADDR + bal hexserial + nop + + PRINTSTR("\r\nEARLY: LOOP! Noting to do") +1: /* Make a dead loop here, wait user to reset the MCU */ + b 1b + nop + +/* locate here, continue the start progress */ + +locate: + /* fix the absolute address by ra */ + la s0, start /* s0 = start */ + subu s0, ra, s0 /* s0 = ra - s0 */ + and s0, 0xffff0000 /* s0 = s0 & 0xffff0000 */ + + li t0, 0xbfe78030 /* load PLL/SDRAM freq config register base to t0 */ + li t2, (0x80000008 | (PLL_MULT << 8) | (0x3 << 2) | SDRAM_DIV) /* Set PLL + * MULT and PLL DIV */ + li t3, (0x00008003 | (CPU_DIV << 8)) /* set CPU DEV */ + + li t1, 0x2 + sw t1, 0x4(t0) /* disable CPU_DIV_VALID firstly for adjustment */ + sw t2, 0x0(t0) /* write START_FREQ */ + sw t3, 0x4(t0) /* write CLK_DIV_PARAM */ + +/* start to initialize debug uart port */ + la v0, LS1C_UART2_BASE /* load UART2 base to v0, only UART2 can be debug port */ +1: + li v1, FIFO_ENABLE|FIFO_RCV_RST|FIFO_XMT_RST|FIFO_TRIGGER_4 /* clear Rx,Tx FIFO + * declear 4 bit int trigger */ + sb v1, LS1C_UART_FCR_OFFSET(v0) /* write FCR (FIFO control register) */ + li v1, CFCR_DLAB /* reach freq div register */ + sb v1, LS1C_UART_LCR_OFFSET(v0) /* write LCR (Line control register)*/ + /* Set UART2 reuse with GPIO36,37*/ + li a0, LS1C_CBUS_FIRST1 /* load CBUS_FIRST1 offset to a0 */ + lw a1, 0x10(a0) /* load value from CBUS_SECOND1 to a1 */ + ori a1, 0x30 /* a1 |= 0x30, GPIO36,37 as secondary function */ + sw a1, 0x10(a0) /* write back modified CBUS_SECOND1 from a1 */ + /* Caculate PLL and bit rate */ + li a0, 0xbfe78030 /* load START_FREQ register address to a0 */ + lw a1, 0(a0) /* load value from START_FREQ to a1*/ + srl a1, 8 /* a1 >>= 8 */ + andi a1, 0xff /* a1 &= 0xff, as a1=PLL_MULT */ + li a2, APB_CLK /* a2 = APB_CLK = 24Mhz (External Clock Freq) */ + srl a2, 2 /* a2 = a2 >> 2 = APB_CLK/4 */ + multu a1, a2 /* hilo = a1 * a2 = PLL_MULT * APB_CLK /4 */ + mflo v1 /* v1 = lo. put low 32 bit of a1 * a2 to v1 as PLL freq */ + /* Determine if we need to devide the clock */ + lw a1, 4(a0) /* load value frm CLK_DIV_PARAM to a1 */ + andi a2, a1, DIV_CPU_SEL /* a2 = a1 & DIV_CPU_SEL, if CPU_SEL=1, devide the clock, + * if CPU_SEL=0, bypass the clock */ + bnez a2, 1f /* if (a2 != 0), branch to next tag 1 */ + nop + li v1, APB_CLK /* v1 = APB_CLK */ + b 3f + nop +1: /* Determine if the CPU_DIV is valid*/ + andi a2, a1, DIV_CPU_EN /* a2 = a1 & DIV_CPU_EN */ + bnez a2, 2f /* if (a2 != 0), branch to next tag 2 */ + nop + srl v1, 1 /* v1 >>= 1, so v1 = APB_CLK/4 * PLL_MULT/2 */ + b 3f + nop +2: /* caculate CPU freq */ + andi a1, DIV_CPU /* a1 &= DIV_CPU */ + srl a1, DIV_CPU_SHIFT /* a1 >>= DIV_CPU_SHIFT */ + divu v1, a1 /* lo = v1/a1, hi = v1 % a1 */ + mflo v1 /* v1 = lo, CPU Freq */ +3: + li a1, (16 * EARLY_DEBUG_BAUD) /* a1 = 16 * BIT RATE */ + divu v1, v1, a1 /* v1 = v1 / a1 */ + srl v1, 1 /* v1 >>= 1 */ + sb v1, LS1C_UART_LSB_OFFSET(v0) /* write 8bit low into LSB */ + srl v1, 8 /* v1 >>= 8 */ + sb v1, LS1C_UART_MSB_OFFSET(v0) /* write 8bit low into MSB */ + + li v1, CFCR_8BITS /* 8n1, no check */ + sb v1, LS1C_UART_LCR_OFFSET(v0) /* write to LCR (Line Control Register) */ + +#ifdef EARLY_DEBUG_UART_FLOW_CTRL + li v1, MCR_DTR|MCR_RTS /* valid DTR and RTS */ + sb v1, LS1C_UART_MCR_OFFSET(v0) /* write to MCR (MODEM Control Register) */ +#endif + + li v1, 0x0 /* disable all the interruptions */ + sb v1, LS1C_UART_IER_OFFSET(v0) /* write to IER (Interruptions Enable Registers) */ + + PRINTSTR("\r\INFO: Loongson 1C300 Starting :) \r\n") + + /* disable all GPIOs for conflict functions */ + li a0,0xbfd00000 + sw zero,0x10c0(a0) /* disable GPIO 0-31 */ + sw zero,0x10c4(a0) /* disable GPIO 32-63 */ + sw zero,0x10c8(a0) /* disable GPIO 64-95 */ + sw zero,0x10cc(a0) + + li t0, 0xffffffff + sw t0, 0x10d0(a0) + sw t0, 0x10d4(a0) + sw t0, 0x10d8(a0) + sw t0, 0x10dc(a0) + + sw t0, 0x10f0(a0) + sw t0, 0x10f4(a0) + sw t0, 0x10f8(a0) + sw t0, 0x10fc(a0) + + PRINTSTR("\r\INFO: All GPIOs are disabled\r\n") + + /* SDRAM initialize starts here */ + + li msize, MEM_SIZE + +#ifdef EJTAG_SEL_AS_SDRAM_CS1 + li a0, 0xbfd011c0 + lw a1, 0x40(a0) + ori a1, 0x01 + sw a1, 0x40(a0) + PRINTSTR("\r\INFO: EJTAG_SEL PIN as SDRAM_CS1\r\n") +#endif + +/* +* recommanded by user manual, we should write SD_CONFIG[31:0] first, then +* write SD_CONFIG[63:32]. Repeat writing for three times, valid the config in +* the last time. +*/ + +/* write first time */ +li t1, 0xbfd00410 /* load SD_CONFIG[31:0] address to t1 */ +li a1, SD_PARA0 /* get the memory config from macro SD_PARA0 */ +sw a1, 0x0(t1) /* write to SD_CONFIG[31:0] */ +li a1, SD_PARA1 +sw a1, 0x4(t1) /* write to SD_CONFIG[63:32] with offset */ +PRINTSTR("\r\INFO: SDRAM Config Pass1\r\n") + +/* write second time,the same */ +li a1, SD_PARA0 +sw a1, 0x0(t1) +li a1, SD_PARA1 +sw a1, 0x4(t1) +PRINTSTR("\r\INFO: SDRAM Config Pass2\r\n") + +/* write third time, enable controller this time */ +li a1, SD_PARA0 +sw a1, 0x0(t1) +li a1, SD_PARA1_EN /* enable it */ +sw a1, 0x4(t1) +PRINTSTR("\r\INFO: SDRAM initialize compeleted\r\n") + + +/* initialize cache */ +bal cache_init /* branch to cache_init */ +nop + +/* enable cache */ +mfc0 a0, CP0_CONFIG /* load cp0 config to a0 */ +and a0, a0, ~((1<<12) | 7) /* a0 = a0 & ~((1<<12) | 7) */ +or a0, a0, 2 /* a0 |= 2 */ +mtc0 a0, CP0_CONFIG /* write back to CP0 config */ + +/* +* relocate: copy selfboot code to memory in kseg0, fix PC and jump to kseg0. +* in order to speed up the copy progress, we will execute copy code in kseg0 +*/ + +PRINTSTR("\r\INFO: Relocating") +la t0, text_copy_start /* load the adress of start tag to t0 */ +move t2, t0 +addu t0, s0 /* correct t0 address in rom by s0 */ +la t1, text_copy_end + +selfboot_copy_loop: +lw v0, (t0) /* copy from memory address in t0 to register v0 */ +sw v0, (t2) /* write data in register v0 to memory address t0 */ +addiu t0, 0x4 /* t0 moves forward 4 bytes */ +addiu t2, 0x4 /* t2 moves forward 4 bytes */ +ble t2, t1, selfboot_copy_loop /* if t1 <= t2 loop to continue the copy */ +nop + +la t0, text_copy_start /* load start address to t0 */ +jr t0 /* jump to 122 in kseg0 to start copy code progress */ +nop + +text_copy_start: +/* Copy code to memory*/ +la a0, start /* load address of start symbol to a0 */ +addu a1, a0, s0 /* correct a0 to address in flash */ +la a2, _edata /* load symbol _edata address to a2 */ +subu t1, a2, a0 /* t1 = a2 - a0, the space of text area */ + +move t0, a0 /* the start address in ram */ +move t1, a1 /* the start address in rom */ +move t2, a2 /* the end address in rom (symbol _edata) */ + +/* copy text section */ +1: +and t3, t0, 0x0000ffff /* t3 = t0 & 0x0000ffff, get low 16 bit */ +bnez t3, 2f /* if t3 != 0, jump to next tag 2 */ +nop +2: +lw t3, 0(t1) /* copy 4 bit from memory address t1 to register t3 */ +nop +sw t3, 0(t0) /* copy 4 bit from register t3 to memory address in t0 */ +addu t0, 4 /* t0 move forward 4 bytes */ +addu t1, 4 /* t1 move forward 4 bytes */ +bne t2, t0, 1b /* if t2 != t0, branch to last tag 1 to continue copy */ +nop +/* copy text section done. */ + +move a0, msize /* a0 = msize, will be passed to main */ +srl a0, 20 /* a0 >>= 20, convert to unit in MB */ + +/* execute main */ +la v0, _rtthread_entry /* load address of function main to v0 */ +jalr v0 /* call address in v0, congrats! all low_level things done! + * switch brain out of assembly */ +nop +text_copy_end: /* end of self-copy in memory */ + +loop: /* impossible to reach here, make a dead loop */ +b loop +nop + +/* functions here */ + +LEAF(stringserial) /* print out the string in address passed in a0 */ + nop + move a2, ra /* save the return address to a2 */ + addu a1, a0, s0 /* correct the address in ROM */ + lbu a0, 0(a1) /* read the first byte in memory address a1 to a0 */ +1: + beqz a0, 2f /* if a0 == 0, jump to next tag 2, empty char */ + nop + bal tgt_putchar /* print a char */ + addiu a1, 1 /* a1 += 1 move forward to next byte */ + b 1b /* branch to the last tag 1, continue */ + lbu a0, 0(a1) /* load the next bit from address a1 to a0, in delay solt, + * will be execuated before branch */ +2: + j a2 /* return */ + nop +END(stringserial) + + +LEAF(hexserial) /* print out single hex char passed in register a0 */ + nop + move a2, ra /* move return address from ra to a2 */ + move a1, a0 /* move hex char from register a0 to a1 */ + li a3, 7 /* load 7 to a3 */ +1: + rol a0, a1, 4 /* rotate left ward shift for 4 bit in a1 to a0 */ + move a1, a0 + and a0, 0xf + la v0, hexchar + +.pushsection .selfboot_data +.align 4 +hexchar: + .ascii "0123456789abcdef" +.popsection +.align 4 + + addu v0, s0 + addu v0, a0 + bal tgt_putchar + lbu a0, 0(v0) + + bnez a3, 1b + addu a3, -1 + + j a2 + nop +END(hexserial) + +LEAF(tgt_putchar) /* print out a char in a0 */ + la v0, LS1C_UART2_BASE /* load UART register address to a0 */ + lbu v1, LS1C_UART_LSR_OFFSET(v0) /* load value from LSR to v0 */ +1: + and v1, LSR_TXRDY /* v1 &= LSR_TXRDY determine wether we can send by TFE bit */ + beqz v1, 1b /* if (v1 == 0) jump to last 1 tag, waiting until TFE is 1 */ + lbu v1, LS1C_UART_LSR_OFFSET(v0) /* load value from LSR to v0 again, in delay solt */ + + sb a0, LS1C_UART_DAT_OFFSET(v0) /* write a0 into DAT, send out */ + j ra /* */ + nop +END(tgt_putchar) + +LEAF(CPU_SetSR) /* modify SR value, arg 1 = set bits, arg 2 = clear bits. */ + mfc0 v0, CP0_STATUS + not v1, a1 + and v1, v0 + or v1, a0 + mtc0 v1, CP0_STATUS + nop + nop + nop + nop + nop + nop + nop + nop + j ra + nop +END(CPU_SetSR) + +cache_init: + move t1, ra +####part 2#### +cache_detect_4way: + mfc0 t4, CP0_CONFIG,1 /* move CP0 CONFIG to t4 */ + lui v0, 0x7 /* v0 = 0x7 << 16 */ + and v0, t4, v0 /* v0 = t4 & v0 */ + srl t3, v0, 16 /* t3 = v0 >> 16 Icache组相联数 IA */ + + li t5, 0x800 //32*64 + srl v1, t4,22 //v1 = t4 >> 22 + andi v1, 7 //Icache每路的组数 64x2^S IS + sll t5, v1 //InstCacheSetSize + sll t5, t3 //t5 InstCacheSize + + + andi v0, t4, 0x0380 + srl t7, v0, 7 //DA + + li t6, 0x800 // 32*64 + srl v1, t4,13 + andi v1, 7 //DS + sll t6, v1 // DataCacheSetSize + sll t6, t7 // t5 DataCacheSize + +####part 3#### + lui a0, 0x8000 //a0 = 0x8000 << 16 + addu a1, $0, t5 + addu a2, $0, t6 +cache_init_d2way: +/* a0=0x80000000, a1=icache_size, a2=dcache_size */ +/* a3, v0 and v1 used as local registers */ + mtc0 $0, CP0_TAGHI + addu v0, $0, a0 /* v0 = 0 + a0 */ + addu v1, a0, a2 /* v1 = a0 + a2 */ +1: slt a3, v0, v1 /* a3 = v0 < v1 ? 1 : 0 */ + beq a3, $0, 1f /* if (a3 == 0) goto 1f */ + nop + mtc0 $0, CP0_TAGLO + cache Index_Store_Tag_D, 0x0(v0) /* 1 way */ +4: beq $0, $0, 1b + addiu v0, v0, 0x20 +1: +cache_flush_i2way: + addu v0, $0, a0 + addu v1, a0, a1 +1: + slt a3, v0, v1 + beq a3, $0, 1f + nop + cache Index_Invalidate_I, 0x0(v0) /* 1 way */ +4: + beq $0, $0, 1b + addiu v0, v0, 0x20 +1: +cache_flush_d2way: + addu v0, $0, a0 + addu v1, a0, a2 +1: slt a3, v0, v1 + beq a3, $0, 1f + nop + cache Index_Writeback_Inv_D, 0x0(v0) /* 1 way */ +4: beq $0, $0, 1b + addiu v0, v0, 0x20 + +1: +cache_init_finish: + jr t1 + nop +#endif diff --git a/bsp/ls1cdev/drivers/touch.c b/bsp/ls1cdev/drivers/touch.c index 249e7682bf..37a4b19213 100644 --- a/bsp/ls1cdev/drivers/touch.c +++ b/bsp/ls1cdev/drivers/touch.c @@ -1,21 +1,7 @@ /* - * File : touch.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 @@ -32,7 +18,7 @@ #include "drv_spi.h" #include "touch.h" -#ifdef RT_USING_RTGUI +#ifdef XPT2046_USING_TOUCH #include <rtgui/calibration.h> #include <rtgui/event.h> @@ -40,8 +26,9 @@ #include <rtgui/rtgui_server.h> #include <rtgui/rtgui_system.h> -//����Ļ ����Ҫ _ILI_HORIZONTAL_DIRECTION_ -//����Ļ ��Ҫ _ILI_HORIZONTAL_DIRECTION_ + +//竖屏幕 不需要 _ILI_HORIZONTAL_DIRECTION_ +//横屏幕 需要 _ILI_HORIZONTAL_DIRECTION_ //#define _ILI_HORIZONTAL_DIRECTION_ @@ -57,7 +44,7 @@ TOUCH INT: 84 */ #define IS_TOUCH_UP() gpio_get(TOUCH_INT_PIN) -#define led_gpio 52 // led1ָʾ +#define led_gpio 52 // led1指示 #define DUMMY 0x00 @@ -97,7 +84,7 @@ s A2-A0 MODE SER/DFR PD1-PD0 #define TOUCH_MSR_Y (START | MEASURE_Y | MODE_12BIT | DIFFERENTIAL | POWER_MODE0) -/* ���¶���XPT2046 �Ĵ�����λ��*/ +/* 以下定义XPT2046 的触摸屏位置*/ #if defined(_ILI_HORIZONTAL_DIRECTION_) #define MIN_X_DEFAULT 2047 #define MAX_X_DEFAULT 47 @@ -117,7 +104,7 @@ s A2-A0 MODE SER/DFR PD1-PD0 #define SH 10 // Valve value -/*�궨�� */ +/*宏定义 */ #define TOUCH_SPI_X SPI1 #define TOUCH_INT_PIN 84 #define TOUCH_CS_PIN 49 @@ -126,21 +113,21 @@ s A2-A0 MODE SER/DFR PD1-PD0 #define TOUCH_MOSI_PIN 48 -/*�����ṹ�彫��Ҫ�õ��Ķ������д��*/ +/*创建结构体将需要用到的东西进行打包*/ struct rtgui_touch_device { - struct rt_device parent; /* ����ע���豸*/ + struct rt_device parent; /* 用于注册设备*/ - rt_uint16_t x, y; /* ��¼��ȡ����λ��ֵ */ + rt_uint16_t x, y; /* 记录读取到的位置值 */ - rt_bool_t calibrating; /* ����У��־ */ - rt_touch_calibration_func_t calibration_func;/* �������� ����ָ�� */ + rt_bool_t calibrating; /* 触摸校准标志 */ + rt_touch_calibration_func_t calibration_func;/* 触摸函数 函数指针 */ - rt_uint16_t min_x, max_x; /* У�� X ������С ���ֵ */ - rt_uint16_t min_y, max_y; /* У�� Y ������С ���ֵ */ + rt_uint16_t min_x, max_x; /* 校准后 X 方向最小 最大值 */ + rt_uint16_t min_y, max_y; /* 校准后 Y 方向最小 最大值 */ - struct rt_spi_device * spi_device; /* SPI �豸 ����ͨ�� */ - struct rt_event event; /* �¼�ͬ�������ڡ����жϡ� */ + struct rt_spi_device * spi_device; /* SPI 设备 用于通信 */ + struct rt_event event; /* 事件同步,用于“笔中断” */ }; static struct rtgui_touch_device *touch = RT_NULL; @@ -230,14 +217,14 @@ static void rtgui_touch_calculate(void) /* read touch */ { rt_uint8_t i, j, k, min; - rt_uint16_t temp; + rt_uint16_t temp; rt_uint16_t tmpxy[2][SAMP_CNT]; rt_uint8_t send_buffer[1]; rt_uint8_t recv_buffer[2]; for(i=0; i<SAMP_CNT; i++) { send_buffer[0] = TOUCH_MSR_X; - touch_send_then_recv(touch->spi_device, send_buffer, 1, recv_buffer, 2); + touch_send_then_recv(touch->spi_device, send_buffer, 1, recv_buffer, 2); rt_kprintf("touch x: %d ",(recv_buffer[0]*256|recv_buffer[1])>>4); #if defined(_ILI_HORIZONTAL_DIRECTION_) tmpxy[1][i] = (recv_buffer[0]<<8)|recv_buffer[1] ; @@ -249,7 +236,7 @@ static void rtgui_touch_calculate(void) #endif send_buffer[0] = TOUCH_MSR_Y; touch_send_then_recv(touch->spi_device, send_buffer, 1, recv_buffer, 2); - rt_kprintf("touch y: %d \n",(recv_buffer[0]*256|recv_buffer[1])>>4); + rt_kprintf("touch y: %d \n",(recv_buffer[0]*256|recv_buffer[1])>>4); #if defined(_ILI_HORIZONTAL_DIRECTION_) tmpxy[0][i] = (recv_buffer[0]<<8)|recv_buffer[1] ; @@ -259,46 +246,46 @@ static void rtgui_touch_calculate(void) tmpxy[1][i] >>= 4; #endif } - /*�ٴδ����ж�*/ + /*再次打开触摸中断*/ send_buffer[0] = 1 << 7; - touch_send_then_recv(touch->spi_device, send_buffer, 1, recv_buffer, 2); + touch_send_then_recv(touch->spi_device, send_buffer, 1, recv_buffer, 2); touch_send_then_recv(touch->spi_device, send_buffer, 1, recv_buffer, 2); /* calculate average */ - { - rt_uint32_t total_x = 0; - rt_uint32_t total_y = 0; - for(k=0; k<2; k++) - { - // sorting the ADC value - for(i=0; i<SAMP_CNT-1; i++) - { - min=i; - for (j=i+1; j<SAMP_CNT; j++) - { - if (tmpxy[k][min] > tmpxy[k][j]) - min=j; - } - temp = tmpxy[k][i]; - tmpxy[k][i] = tmpxy[k][min]; - tmpxy[k][min] = temp; - } - //check value for Valve value - if((tmpxy[k][SAMP_CNT_DIV2+1]-tmpxy[k][SAMP_CNT_DIV2-2]) > SH) - { - return; - } - } - total_x=tmpxy[0][SAMP_CNT_DIV2-2]+tmpxy[0][SAMP_CNT_DIV2-1]+tmpxy[0][SAMP_CNT_DIV2]+tmpxy[0][SAMP_CNT_DIV2+1]; - total_y=tmpxy[1][SAMP_CNT_DIV2-2]+tmpxy[1][SAMP_CNT_DIV2-1]+tmpxy[1][SAMP_CNT_DIV2]+tmpxy[1][SAMP_CNT_DIV2+1]; - //calculate average value - touch->x=total_x>>2; - touch->y=total_y>>2; + { + rt_uint32_t total_x = 0; + rt_uint32_t total_y = 0; + for(k=0; k<2; k++) + { + // sorting the ADC value + for(i=0; i<SAMP_CNT-1; i++) + { + min=i; + for (j=i+1; j<SAMP_CNT; j++) + { + if (tmpxy[k][min] > tmpxy[k][j]) + min=j; + } + temp = tmpxy[k][i]; + tmpxy[k][i] = tmpxy[k][min]; + tmpxy[k][min] = temp; + } + //check value for Valve value + if((tmpxy[k][SAMP_CNT_DIV2+1]-tmpxy[k][SAMP_CNT_DIV2-2]) > SH) + { + return; + } + } + total_x=tmpxy[0][SAMP_CNT_DIV2-2]+tmpxy[0][SAMP_CNT_DIV2-1]+tmpxy[0][SAMP_CNT_DIV2]+tmpxy[0][SAMP_CNT_DIV2+1]; + total_y=tmpxy[1][SAMP_CNT_DIV2-2]+tmpxy[1][SAMP_CNT_DIV2-1]+tmpxy[1][SAMP_CNT_DIV2]+tmpxy[1][SAMP_CNT_DIV2+1]; + //calculate average value + touch->x=total_x>>2; + touch->y=total_y>>2; rt_kprintf("touch->x:%d touch->y:%d\r\n", touch->x, touch->y); } /* calculate average */ } /* read touch */ /* if it's not in calibration status */ - /*����ֵ����*/ + /*触摸值缩放*/ if (touch->calibrating != RT_TRUE) { if (touch->max_x > touch->min_x) @@ -322,19 +309,19 @@ static void rtgui_touch_calculate(void) } } #include "ls1c_regs.h" -#define TOUCH_INT_EN __REG32(LS1C_INT4_EN) +#define TOUCH_INT_EN __REG32(LS1C_INT4_EN) rt_inline void touch_int_cmd(rt_bool_t NewState) { - if(NewState == RT_TRUE) - { - //TOUCH_INT_EN |= (1<<(TOUCH_INT_PIN-64)); - reg_set_one_bit(LS1C_INT4_EN, 1<<(TOUCH_INT_PIN-64)); - } - else - { - //TOUCH_INT_EN &=(~ (1<<(TOUCH_INT_PIN-64))); - reg_clr_one_bit(LS1C_INT4_EN, 1<<(TOUCH_INT_PIN-64)); - } + if(NewState == RT_TRUE) + { + //TOUCH_INT_EN |= (1<<(TOUCH_INT_PIN-64)); + reg_set_one_bit(LS1C_INT4_EN, 1<<(TOUCH_INT_PIN-64)); + } + else + { + //TOUCH_INT_EN &=(~ (1<<(TOUCH_INT_PIN-64))); + reg_clr_one_bit(LS1C_INT4_EN, 1<<(TOUCH_INT_PIN-64)); + } } @@ -342,29 +329,29 @@ void ls1c_touch_irqhandler(void) /* TouchScreen */ { if(gpio_get(TOUCH_INT_PIN)==0) { - /* ���������º���� */ - if (gpio_level_low == gpio_get(led_gpio)) - gpio_set(led_gpio, gpio_level_high); - else - gpio_set(led_gpio, gpio_level_low); - touch_int_cmd(RT_FALSE); - rt_event_send(&touch->event, 1); + /* 触摸屏按下后操作 */ + if (gpio_level_low == gpio_get(led_gpio)) + gpio_set(led_gpio, gpio_level_high); + else + gpio_set(led_gpio, gpio_level_low); + touch_int_cmd(RT_FALSE); + rt_event_send(&touch->event, 1); } } -/*�ܽų�ʼ���������жϴ�SPI1 CS0 �豸*/ +/*管脚初始化,配置中断打开SPI1 CS0 设备*/ rt_inline void touch_init(void) -{ - unsigned int touch_int_gpio = TOUCH_INT_PIN; // �������ж� +{ + unsigned int touch_int_gpio = TOUCH_INT_PIN; // 触摸屏中断 int touch_irq = LS1C_GPIO_TO_IRQ(touch_int_gpio); - // ��ʼ�������ж� + // 初始化按键中断 gpio_set_irq_type(touch_int_gpio, IRQ_TYPE_EDGE_FALLING); rt_hw_interrupt_install(touch_irq, ls1c_touch_irqhandler, RT_NULL, "touch"); rt_hw_interrupt_umask(touch_irq); gpio_init(touch_int_gpio, gpio_mode_input); - // ��ʼ��led + // 初始化led gpio_init(led_gpio, gpio_mode_output); gpio_set(led_gpio, gpio_level_high); } @@ -374,9 +361,9 @@ rt_inline void touch_init(void) static rt_err_t rtgui_touch_init (rt_device_t dev) { rt_uint8_t send; - rt_uint8_t recv_buffer[2]; + rt_uint8_t recv_buffer[2]; struct rtgui_touch_device * touch_device = (struct rtgui_touch_device *)dev; - + touch_init(); rt_kprintf("touch_init ...\n"); send = START | DIFFERENTIAL | POWER_MODE0; @@ -433,7 +420,7 @@ static void touch_thread_entry(void *parameter) while(1) { - /* ���յ������ж��¼� */ + /* 接收到触摸中断事件 */ if(rt_event_recv(&touch->event, 1, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, @@ -445,7 +432,7 @@ static void touch_thread_entry(void *parameter) { if (IS_TOUCH_UP()) { - /* ������̧�� */ + /* 触摸笔抬起 */ /* touch up */ emouse.button = (RTGUI_MOUSE_BUTTON_LEFT |RTGUI_MOUSE_BUTTON_UP); @@ -461,14 +448,14 @@ static void touch_thread_entry(void *parameter) if ((touch->calibrating == RT_TRUE) && (touch->calibration_func != RT_NULL)) { - /* ����У���� */ + /* 触摸校准处理 */ /* callback function */ touch->calibration_func(emouse.x, emouse.y); - + } else { - /* ��ui���ʹ������� */ + /* 向ui发送触摸坐标 */ rtgui_server_post_event(&emouse.parent, sizeof(struct rtgui_event_mouse)); } rt_kprintf("touch up: (%d, %d)\n", emouse.x, emouse.y); @@ -503,7 +490,7 @@ static void touch_thread_entry(void *parameter) emouse.x = touch->x; emouse.y = touch->y; _set_mouse_position(emouse.x, emouse.y); - /* ������ */ + /* 光标跟随 */ /* init mouse button */ emouse.button = (RTGUI_MOUSE_BUTTON_LEFT |RTGUI_MOUSE_BUTTON_DOWN); @@ -519,7 +506,7 @@ static void touch_thread_entry(void *parameter) { touch_previous.x = touch->x; touch_previous.y = touch->y; - /* ��ui���ʹ������� */ + /* 向ui发送触摸坐标 */ rtgui_server_post_event(&emouse.parent, sizeof(struct rtgui_event_mouse)); if(touch_down == RT_FALSE) { @@ -545,24 +532,24 @@ static void touch_thread_entry(void *parameter) rt_err_t rtgui_touch_hw_init(const char * spi_device_name) { - rt_uint32_t arg[2]; - struct rt_device * spi_device; - struct rt_thread * touch_thread; - rt_err_t err; + rt_uint32_t arg[2]; + struct rt_device * spi_device; + struct rt_thread * touch_thread; + rt_err_t err; - rt_kprintf("spi1 cs0 start...\n"); - spi_device = rt_device_find("spi10"); - if(spi_device == RT_NULL) - { - rt_kprintf("Did not find spi1, exit thread....\n"); - return; - } - err = rt_device_open(spi_device, RT_DEVICE_OFLAG_RDWR); - if(err != RT_EOK) - { - rt_kprintf("Open spi1 failed %08X, exit thread....\n", err); - return; - } + rt_kprintf("spi1 cs0 start...\n"); + spi_device = rt_device_find("spi10"); + if(spi_device == RT_NULL) + { + rt_kprintf("Did not find spi1, exit thread....\n"); + return; + } + err = rt_device_open(spi_device, RT_DEVICE_OFLAG_RDWR); + if(err != RT_EOK) + { + rt_kprintf("Open spi1 failed %08X, exit thread....\n", err); + return; + } /* config spi */ { @@ -573,7 +560,7 @@ rt_err_t rtgui_touch_hw_init(const char * spi_device_name) rt_spi_configure((struct rt_spi_device *)spi_device, &cfg); } - touch = (struct rtgui_touch_device*)rt_malloc (sizeof(struct rtgui_touch_device)); + touch = (struct rtgui_touch_device*)rt_malloc (sizeof(struct rtgui_touch_device)); if (touch == RT_NULL) return RT_ENOMEM; /* no memory yet */ /* clear device structure */ @@ -597,7 +584,7 @@ rt_err_t rtgui_touch_hw_init(const char * spi_device_name) /* register touch device to RT-Thread */ rt_device_register(&(touch->parent), "touch", RT_DEVICE_FLAG_RDWR); - + touch_thread = rt_thread_create("touch_thread", touch_thread_entry, RT_NULL, diff --git a/bsp/ls1cdev/drivers/touch.h b/bsp/ls1cdev/drivers/touch.h index 0892d2858f..5dac833510 100644 --- a/bsp/ls1cdev/drivers/touch.h +++ b/bsp/ls1cdev/drivers/touch.h @@ -1,21 +1,7 @@ /* - * File : touch.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_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_ */ + diff --git a/bsp/ls1cdev/ls1c_ram.lds b/bsp/ls1cdev/ls1c_ram.lds index 9fa91ba5df..38aabfe012 100644 --- a/bsp/ls1cdev/ls1c_ram.lds +++ b/bsp/ls1cdev/ls1c_ram.lds @@ -12,6 +12,7 @@ * 2010-05-17 swkyer first version * 2010-09-04 bernard move the beginning entry to 0x80200000 * 2018-05-12 zhuangwei use -Ttext + * 2019-12-04 Jiaxun Yang Adapt new memory layout */ OUTPUT_ARCH(mips) @@ -20,13 +21,19 @@ GROUP(-lgcc -lc) ENTRY(_start) SECTIONS { - . = 0x80000000 ; - . = ALIGN(4); .text : { - start = ABSOLUTE(.); - *(.start); + start = ABSOLUTE(.); + *(.selfboot); + *(.selfboot_data); + . = ALIGN(4); + __selfboot_end = .; + . = ALIGN(0x1000); + __ebase_entry = .; + KEEP(*(.exc_vectors)) + __ebase_end = .; + *(.start); *(.text) *(.text.*) *(.rodata) @@ -74,6 +81,15 @@ SECTIONS *(.sdata) *(.sdata.*) } + _edata = .; + + .stack : + { + . = ALIGN(8); + _system_stack_start = .; + . = . + 0x400; /* 1kb system stack */ + _system_stack = .; + } .sbss : { diff --git a/bsp/ls1cdev/rtconfig.h b/bsp/ls1cdev/rtconfig.h index 7562dd00d3..a2bac5d6f0 100644 --- a/bsp/ls1cdev/rtconfig.h +++ b/bsp/ls1cdev/rtconfig.h @@ -11,12 +11,13 @@ #define RT_THREAD_PRIORITY_32 #define RT_THREAD_PRIORITY_MAX 32 #define RT_TICK_PER_SECOND 1000 -#define RT_DEBUG #define RT_USING_OVERFLOW_CHECK -#define RT_DEBUG_INIT 0 -#define RT_DEBUG_THREAD 0 #define RT_USING_HOOK +#define RT_USING_IDLE_HOOK +#define RT_IDLE_HOOK_LIST_SIZE 4 #define IDLE_THREAD_STACK_SIZE 1024 +#define RT_DEBUG +#define RT_DEBUG_COLOR /* Inter-Thread communication */ @@ -40,12 +41,14 @@ #define RT_USING_CONSOLE #define RT_CONSOLEBUF_SIZE 128 #define RT_CONSOLE_DEVICE_NAME "uart2" +#define RT_VER_NUM 0x40002 /* RT-Thread Components */ #define RT_USING_COMPONENTS_INIT #define RT_USING_USER_MAIN #define RT_MAIN_THREAD_STACK_SIZE 2048 +#define RT_MAIN_THREAD_PRIORITY 10 /* C++ features */ @@ -72,25 +75,15 @@ #define DFS_FILESYSTEMS_MAX 2 #define DFS_FILESYSTEM_TYPES_MAX 2 #define DFS_FD_MAX 4 -#define RT_USING_DFS_ELMFAT - -/* elm-chan's FatFs, Generic FAT Filesystem Module */ - -#define RT_DFS_ELM_CODE_PAGE 936 -#define RT_DFS_ELM_WORD_ACCESS -#define RT_DFS_ELM_USE_LFN_0 -#define RT_DFS_ELM_USE_LFN 0 -#define RT_DFS_ELM_MAX_LFN 64 -#define RT_DFS_ELM_DRIVES 2 -#define RT_DFS_ELM_MAX_SECTOR_SIZE 512 -#define RT_DFS_ELM_REENTRANT /* Device Drivers */ #define RT_USING_DEVICE_IPC +#define RT_PIPE_BUFSZ 512 #define RT_USING_SERIAL +#define RT_SERIAL_USING_DMA +#define RT_SERIAL_RB_BUFSZ 64 #define RT_USING_CAN -#define RT_CAN_USING_HDR #define RT_USING_I2C #define RT_USING_I2C_BITOPS #define RT_USING_PIN @@ -104,49 +97,20 @@ #define RT_USING_LIBC #define RT_USING_PTHREADS +#define PTHREAD_NUM_MAX 8 -/* Network stack */ +/* Network */ -/* light weight TCP/IP stack */ +/* Socket abstraction layer */ -#define RT_USING_LWIP -#define RT_USING_LWIP141 -#define RT_LWIP_IGMP -#define RT_LWIP_ICMP -#define RT_LWIP_DNS -#define RT_LWIP_DHCP -#define IP_SOF_BROADCAST 1 -#define IP_SOF_BROADCAST_RECV 1 -/* Static IPv4 Address */ +/* Network interface device */ -#define RT_LWIP_IPADDR "192.168.1.254" -#define RT_LWIP_GWADDR "192.168.1.1" -#define RT_LWIP_MSKADDR "255.255.255.0" -#define RT_LWIP_UDP -#define RT_LWIP_TCP -#define RT_MEMP_NUM_NETCONN 8 -#define RT_LWIP_PBUF_NUM 4 -#define RT_LWIP_RAW_PCB_NUM 4 -#define RT_LWIP_UDP_PCB_NUM 4 -#define RT_LWIP_TCP_PCB_NUM 3 -#define RT_LWIP_TCP_SEG_NUM 40 -#define RT_LWIP_TCP_SND_BUF 4096 -#define RT_LWIP_TCP_WND 2048 -#define RT_LWIP_TCPTHREAD_PRIORITY 12 -#define RT_LWIP_TCPTHREAD_MBOX_SIZE 8 -#define RT_LWIP_TCPTHREAD_STACKSIZE 4096 -#define RT_LWIP_ETHTHREAD_PRIORITY 14 -#define RT_LWIP_ETHTHREAD_STACKSIZE 512 -#define RT_LWIP_ETHTHREAD_MBOX_SIZE 8 -#define LWIP_NETIF_STATUS_CALLBACK 1 -#define SO_REUSE 1 -#define LWIP_SO_RCVTIMEO 1 -#define LWIP_SO_SNDTIMEO 1 -#define LWIP_SO_RCVBUF 1 -#define LWIP_NETIF_LOOPBACK 0 -/* Modbus master and slave stack */ +/* light weight TCP/IP stack */ + + +/* AT commands */ /* VBUS(Virtual Software BUS) */ @@ -155,12 +119,10 @@ /* Utilities */ -/* RT-Thread online packages */ +/* RT-Thread MIPS CPU */ -/* system packages */ - -/* RT-Thread GUI Engine */ +/* RT-Thread online packages */ /* IoT - internet of things */ @@ -173,6 +135,9 @@ /* Wiced WiFi */ +/* IoT Cloud */ + + /* security packages */ @@ -185,19 +150,27 @@ /* tools packages */ +/* system packages */ + + +/* peripheral libraries and drivers */ + + /* miscellaneous packages */ -/* example package: hello */ +/* samples: kernel and components samples */ +#define SOC_1C300 +#define RT_LS1C_BAICAIBOARD +#define RT_USING_SELF_BOOT +#define RT_SELF_BOOT_DEBUG #define RT_USING_UART2 +#define RT_USING_UART1 #define RT_UART_RX_BUFFER_SIZE 64 #define RT_USING_GMAC_INT_MODE -#define RT_USING_SPI0 -#define RT_USING_SPI1 #define RT_USING_I2C1 #define RT_USING_I2C2 -#define USING_BXCAN0 -#define USING_BXCAN1 +#define NO_TOUCH #endif diff --git a/bsp/ls1cdev/rtconfig.py b/bsp/ls1cdev/rtconfig.py index 6420cc45bb..be5da5d30a 100644 --- a/bsp/ls1cdev/rtconfig.py +++ b/bsp/ls1cdev/rtconfig.py @@ -2,7 +2,7 @@ import os # CPU options ARCH='mips' -CPU ='loongson_1c' +CPU ='gs232' # toolchains options CROSS_TOOL = 'gcc' @@ -12,8 +12,8 @@ if os.getenv('RTT_CC'): if CROSS_TOOL == 'gcc': PLATFORM = 'gcc' -# EXEC_PATH = "/opt/mips-2015.05/bin" - EXEC_PATH = r'D:\mgc\embedded\codebench\bin' + EXEC_PATH = "/opt/mips-2016.05/bin" +# EXEC_PATH = r'D:\mgc\embedded\codebench\bin' else: print('================ERROR===========================') print('Not support %s yet!' % CROSS_TOOL) @@ -41,7 +41,7 @@ READELF = PREFIX + 'readelf' DEVICE = ' -mips32 -msoft-float -mfp32' CFLAGS = DEVICE + ' -EL -G0 -mno-abicalls -fno-pic -fno-builtin -fno-exceptions -ffunction-sections -fomit-frame-pointer' -AFLAGS = ' -c' + DEVICE + ' -EL -fno-pic -fno-builtin -mno-abicalls -x assembler-with-cpp -DSYSTEM_STACK=0x80003fe8' +AFLAGS = ' -c' + DEVICE + ' -EL -fno-pic -fno-builtin -mno-abicalls -x assembler-with-cpp' LFLAGS = DEVICE + ' -nostartfiles -EL -Wl,--gc-sections,-Map=rtthread.map,-cref,-u,Reset_Handler -T ls1c_ram.lds' CPATH = '' |
