From 9a7caed323b8f111b5e9ad7e22462a12516ae1d6 Mon Sep 17 00:00:00 2001 From: zhuangwei123 Date: Sat, 12 May 2018 19:33:32 +0800 Subject: [PATCH] =?UTF-8?q?[bsp/ls1cdev]=E6=B7=BB=E5=8A=A0=E8=87=AA?= =?UTF-8?q?=E5=BC=95=E5=AF=BC=E7=89=B9=E6=80=A7=EF=BC=8C=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E9=80=89=E9=A1=B9=201=E3=80=81=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E8=87=AA=E5=BC=95=E5=AF=BC=E7=89=B9=E6=80=A7=EF=BC=8C?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=85=8D=E7=BD=AE=E9=80=89=E9=A1=B9=202?= =?UTF-8?q?=E3=80=81=E4=BF=AE=E5=A4=8Dcpuport.c=E7=9A=84bug=203=E3=80=81?= =?UTF-8?q?=E4=BF=AE=E5=A4=8Dls1c=5Fpin.c=E4=B8=8D=E8=83=BD=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E5=A4=8D=E7=94=A8=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bsp/ls1cdev/.config | 43 ++++-- bsp/ls1cdev/SConstruct | 9 ++ bsp/ls1cdev/drivers/board.c | 5 +- bsp/ls1cdev/drivers/net/synopGMAC.c | 16 ++- bsp/ls1cdev/kconfig | 4 + bsp/ls1cdev/libraries/ls1c_pin.c | 204 ++++++++++++++-------------- bsp/ls1cdev/ls1c_ram.lds | 10 +- bsp/ls1cdev/rtconfig.h | 16 ++- libcpu/mips/loongson_1c/sdram_cfg.h | 85 ++++++++++++ 9 files changed, 263 insertions(+), 129 deletions(-) create mode 100644 libcpu/mips/loongson_1c/sdram_cfg.h diff --git a/bsp/ls1cdev/.config b/bsp/ls1cdev/.config index a16ee472b4..e851e39127 100644 --- a/bsp/ls1cdev/.config +++ b/bsp/ls1cdev/.config @@ -228,20 +228,6 @@ CONFIG_LWIP_NETIF_LOOPBACK=0 # RT-Thread online packages # -# -# system packages -# - -# -# RT-Thread GUI Engine -# -# CONFIG_PKG_USING_GUIENGINE is not set -# CONFIG_PKG_USING_LVGL is not set -# CONFIG_PKG_USING_LWEXT4 is not set -# CONFIG_PKG_USING_PARTITION is not set -# CONFIG_PKG_USING_SQLITE is not set -# CONFIG_PKG_USING_RTI is not set - # # IoT - internet of things # @@ -271,6 +257,7 @@ CONFIG_LWIP_NETIF_LOOPBACK=0 # CONFIG_PKG_USING_COAP is not set # CONFIG_PKG_USING_NOPOLL is not set # CONFIG_PKG_USING_NETUTILS is not set +# CONFIG_PKG_USING_ONENET is not set # # security packages @@ -289,6 +276,7 @@ CONFIG_LWIP_NETIF_LOOPBACK=0 # multimedia packages # # CONFIG_PKG_USING_OPENMV is not set +# CONFIG_PKG_USING_MUPDF is not set # # tools packages @@ -299,6 +287,26 @@ CONFIG_LWIP_NETIF_LOOPBACK=0 # CONFIG_PKG_USING_SYSTEMVIEW is not set # CONFIG_PKG_USING_IPERF is not set +# +# system packages +# + +# +# RT-Thread GUI Engine +# +# CONFIG_PKG_USING_GUIENGINE is not set +# CONFIG_PKG_USING_LWEXT4 is not set +# CONFIG_PKG_USING_PARTITION is not set +# CONFIG_PKG_USING_SQLITE is not set +# CONFIG_PKG_USING_RTI is not set +# CONFIG_PKG_USING_LITTLEVGL2RTT is not set + +# +# peripheral libraries and drivers +# +# CONFIG_PKG_USING_STM32F4_HAL is not set +# CONFIG_PKG_USING_STM32F4_DRIVERS is not set + # # miscellaneous packages # @@ -306,13 +314,18 @@ CONFIG_LWIP_NETIF_LOOPBACK=0 # CONFIG_PKG_USING_MINILZO is not set # CONFIG_PKG_USING_QUICKLZ is not set # CONFIG_PKG_USING_MULTIBUTTON is not set -# CONFIG_PKG_USING_SAMPLES is not set # CONFIG_PKG_USING_CANFESTIVAL is not set +# +# sample package +# +# CONFIG_PKG_USING_SAMPLES is not set + # # example package: hello # # CONFIG_PKG_USING_HELLO is not set +# CONFIG_RT_USING_SELF_BOOT is not set CONFIG_RT_USING_UART2=y CONFIG_RT_UART_RX_BUFFER_SIZE=64 CONFIG_RT_USING_GMAC_INT_MODE=y diff --git a/bsp/ls1cdev/SConstruct b/bsp/ls1cdev/SConstruct index 17e1d15db3..3096becfc7 100644 --- a/bsp/ls1cdev/SConstruct +++ b/bsp/ls1cdev/SConstruct @@ -12,6 +12,8 @@ from building import * TARGET = 'rtthread.' + rtconfig.TARGET_EXT +rtconfig.AFLAGS += ' -I' + str(Dir('#')) + env = Environment(tools = ['mingw'], AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS, CC = rtconfig.CC, CCFLAGS = rtconfig.CFLAGS, @@ -24,6 +26,13 @@ Export('rtconfig') # prepare building environment objs = PrepareBuilding(env, RTT_ROOT) + +if GetDepend('RT_USING_SELF_BOOT'): + rtconfig.LFLAGS += " -Ttext 0x80010000" +else: + rtconfig.LFLAGS += " -Ttext 0x80200000" +env.Replace(LINKFLAGS = rtconfig.LFLAGS) + if GetDepend('RT_USING_RTGUI'): objs = objs + SConscript(RTT_ROOT + '/examples/gui/SConscript', variant_dir='build/examples/gui', duplicate=0) diff --git a/bsp/ls1cdev/drivers/board.c b/bsp/ls1cdev/drivers/board.c index 64f0db56ab..a7100a04c4 100644 --- a/bsp/ls1cdev/drivers/board.c +++ b/bsp/ls1cdev/drivers/board.c @@ -100,6 +100,9 @@ void rt_hw_board_init(void) /* 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); @@ -109,7 +112,7 @@ void rt_hw_board_init(void) invalidate_icache_all(); #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 diff --git a/bsp/ls1cdev/drivers/net/synopGMAC.c b/bsp/ls1cdev/drivers/net/synopGMAC.c index 7e665d3964..6aff98d22b 100644 --- a/bsp/ls1cdev/drivers/net/synopGMAC.c +++ b/bsp/ls1cdev/drivers/net/synopGMAC.c @@ -31,6 +31,8 @@ #include "mii.c" #include "synopGMAC_debug.h" #include +#include "ls1c_pin.h" + #define RMII #define Gmac_base 0xbfe10000 @@ -865,10 +867,22 @@ int rt_hw_eth_init(void) u64 base_addr = Gmac_base; struct synopGMACNetworkAdapter * synopGMACadapter; static u8 mac_addr0[6] = DEFAULT_MAC_ADDRESS; - + int index; + rt_sem_init(&sem_ack, "tx_ack", 1, RT_IPC_FLAG_FIFO); rt_sem_init(&sem_lock, "eth_lock", 1, RT_IPC_FLAG_FIFO); + for(index=21; index<=30;index++) + { + pin_set_purpose(index, PIN_PURPOSE_OTHER); + pin_set_remap(index, PIN_REMAP_DEFAULT); + } + pin_set_purpose(35, PIN_PURPOSE_OTHER); + pin_set_remap(35, PIN_REMAP_DEFAULT); + *((volatile unsigned int *)0xbfd00424) &= ~(7 << 28); + *((volatile unsigned int *)0xbfd00424) |= (1 << 30); //wl rmii + + memset(ð_dev, 0, sizeof(eth_dev)); synopGMACadapter = (struct synopGMACNetworkAdapter * )plat_alloc_memory(sizeof (struct synopGMACNetworkAdapter)); diff --git a/bsp/ls1cdev/kconfig b/bsp/ls1cdev/kconfig index 9e9a7e9520..23ecbb3190 100644 --- a/bsp/ls1cdev/kconfig +++ b/bsp/ls1cdev/kconfig @@ -19,6 +19,10 @@ config $PKGS_DIR source "$RTT_DIR/Kconfig" source "$PKGS_DIR/Kconfig" +config RT_USING_SELF_BOOT + bool "Enable RT-Thread run without bootloader" + default n + if RT_USING_SERIAL config RT_USING_UART2 bool "Using RT_USING_UART2" diff --git a/bsp/ls1cdev/libraries/ls1c_pin.c b/bsp/ls1cdev/libraries/ls1c_pin.c index 15b4157b15..81f56c0b0c 100644 --- a/bsp/ls1cdev/libraries/ls1c_pin.c +++ b/bsp/ls1cdev/libraries/ls1c_pin.c @@ -1,4 +1,4 @@ -// 引脚功能(普通gpio,pwm,复用等)相关接口 +// 寮曡剼鍔熻兘(鏅歡pio锛宲wm锛屽鐢ㄧ瓑)鐩稿叧鎺ュ彛 #include "ls1c_public.h" @@ -8,21 +8,21 @@ /* - * 把指定pin设置为指定用途(普通gpio,非gpio) - * @gpio gpio引脚编号 - * @purpose 用途 + * 鎶婃寚瀹歱in璁剧疆涓烘寚瀹氱敤閫(鏅歡pio锛岄潪gpio) + * @gpio gpio寮曡剼缂栧彿 + * @purpose 鐢ㄩ */ void pin_set_purpose(unsigned int gpio, pin_purpose_t purpose) { - volatile unsigned int *gpio_cfgx; // GPIO_CFGx寄存器 + volatile unsigned int *gpio_cfgx; // GPIO_CFGx瀵勫瓨鍣 unsigned int pin = GPIO_GET_PIN(gpio); gpio_cfgx = gpio_get_cfg_reg(gpio); - if (PIN_PURPOSE_GPIO == purpose) // 引脚用作普通gpio + if (PIN_PURPOSE_GPIO == purpose) // 寮曡剼鐢ㄤ綔鏅歡pio { reg_set_one_bit(gpio_cfgx, pin); } - else // 引脚用作其它功能(非gpio) + else // 寮曡剼鐢ㄤ綔鍏跺畠鍔熻兘(闈瀏pio) { reg_clr_one_bit(gpio_cfgx, pin); } @@ -33,116 +33,118 @@ void pin_set_purpose(unsigned int gpio, pin_purpose_t purpose) /* - * 设置指定pin为第n复用 - * @gpio gpio编号 - * @remap 第n复用 + * 璁剧疆鎸囧畾pin涓虹n澶嶇敤 + * @gpio gpio缂栧彿 + * @remap 绗琻澶嶇敤 */ void pin_set_remap(unsigned int gpio, pin_remap_t remap) { - volatile unsigned int *reg = NULL; // 复用寄存器 + volatile unsigned int *reg = NULL; // 澶嶇敤瀵勫瓨鍣 unsigned int port = GPIO_GET_PORT(gpio); unsigned int pin = GPIO_GET_PIN(gpio); - int i; + int i; - /*指定全部pin复用为0*/ - for(i =0; i <=4; i++) - { - reg = (volatile unsigned int *)((LS1C_CBUS_FIRST0)+((port)*0x04)+((i)*0x10)); - // 置0 - reg_clr_one_bit(reg, pin); - } + /*鎸囧畾鍏ㄩ儴pin澶嶇敤涓0*/ + for (i = 0; i <= 4; i++) + { + reg = (volatile unsigned int *)((LS1C_CBUS_FIRST0) + ((port) * 0x04) + ((i) * 0x10)); + // 缃0 + reg_clr_one_bit(reg, pin); + } + + if (remap == PIN_REMAP_DEFAULT) return; switch (port) { - case 0: - switch (remap) - { - case PIN_REMAP_FIRST: - reg = (volatile unsigned int *)LS1C_CBUS_FIRST0; - break; - case PIN_REMAP_SECOND: - reg = (volatile unsigned int *)LS1C_CBUS_SECOND0; - break; - case PIN_REMAP_THIRD: - reg = (volatile unsigned int *)LS1C_CBUS_THIRD0; - break; - case PIN_REMAP_FOURTH: - reg = (volatile unsigned int *)LS1C_CBUS_FOURTH0; - break; - case PIN_REMAP_FIFTH: - reg = (volatile unsigned int *)LS1C_CBUS_FIFTH0; - break; - } + case 0: + switch (remap) + { + case PIN_REMAP_FIRST: + reg = (volatile unsigned int *)LS1C_CBUS_FIRST0; break; - - case 1: - switch (remap) - { - case PIN_REMAP_FIRST: - reg = (volatile unsigned int *)LS1C_CBUS_FIRST1; - break; - case PIN_REMAP_SECOND: - reg = (volatile unsigned int *)LS1C_CBUS_SECOND1; - break; - case PIN_REMAP_THIRD: - reg = (volatile unsigned int *)LS1C_CBUS_THIRD1; - break; - case PIN_REMAP_FOURTH: - reg = (volatile unsigned int *)LS1C_CBUS_FOURTH1; - break; - case PIN_REMAP_FIFTH: - reg = (volatile unsigned int *)LS1C_CBUS_FIFTH1; - break; - } + case PIN_REMAP_SECOND: + reg = (volatile unsigned int *)LS1C_CBUS_SECOND0; break; - - case 2: - switch (remap) - { - case PIN_REMAP_FIRST: - reg = (volatile unsigned int *)LS1C_CBUS_FIRST2; - break; - case PIN_REMAP_SECOND: - reg = (volatile unsigned int *)LS1C_CBUS_SECOND2; - break; - case PIN_REMAP_THIRD: - reg = (volatile unsigned int *)LS1C_CBUS_THIRD2; - break; - case PIN_REMAP_FOURTH: - reg = (volatile unsigned int *)LS1C_CBUS_FOURTH2; - break; - case PIN_REMAP_FIFTH: - reg = (volatile unsigned int *)LS1C_CBUS_FIFTH2; - break; - } + case PIN_REMAP_THIRD: + reg = (volatile unsigned int *)LS1C_CBUS_THIRD0; break; - - case 3: - switch (remap) - { - case PIN_REMAP_FIRST: - reg = (volatile unsigned int *)LS1C_CBUS_FIRST3; - break; - case PIN_REMAP_SECOND: - reg = (volatile unsigned int *)LS1C_CBUS_SECOND3; - break; - case PIN_REMAP_THIRD: - reg = (volatile unsigned int *)LS1C_CBUS_THIRD3; - break; - case PIN_REMAP_FOURTH: - reg = (volatile unsigned int *)LS1C_CBUS_FOURTH3; - break; - case PIN_REMAP_FIFTH: - reg = (volatile unsigned int *)LS1C_CBUS_FIFTH3; - break; - } + case PIN_REMAP_FOURTH: + reg = (volatile unsigned int *)LS1C_CBUS_FOURTH0; break; + case PIN_REMAP_FIFTH: + reg = (volatile unsigned int *)LS1C_CBUS_FIFTH0; + break; + } + break; - default: - return ; + case 1: + switch (remap) + { + case PIN_REMAP_FIRST: + reg = (volatile unsigned int *)LS1C_CBUS_FIRST1; + break; + case PIN_REMAP_SECOND: + reg = (volatile unsigned int *)LS1C_CBUS_SECOND1; + break; + case PIN_REMAP_THIRD: + reg = (volatile unsigned int *)LS1C_CBUS_THIRD1; + break; + case PIN_REMAP_FOURTH: + reg = (volatile unsigned int *)LS1C_CBUS_FOURTH1; + break; + case PIN_REMAP_FIFTH: + reg = (volatile unsigned int *)LS1C_CBUS_FIFTH1; + break; + } + break; + + case 2: + switch (remap) + { + case PIN_REMAP_FIRST: + reg = (volatile unsigned int *)LS1C_CBUS_FIRST2; + break; + case PIN_REMAP_SECOND: + reg = (volatile unsigned int *)LS1C_CBUS_SECOND2; + break; + case PIN_REMAP_THIRD: + reg = (volatile unsigned int *)LS1C_CBUS_THIRD2; + break; + case PIN_REMAP_FOURTH: + reg = (volatile unsigned int *)LS1C_CBUS_FOURTH2; + break; + case PIN_REMAP_FIFTH: + reg = (volatile unsigned int *)LS1C_CBUS_FIFTH2; + break; + } + break; + + case 3: + switch (remap) + { + case PIN_REMAP_FIRST: + reg = (volatile unsigned int *)LS1C_CBUS_FIRST3; + break; + case PIN_REMAP_SECOND: + reg = (volatile unsigned int *)LS1C_CBUS_SECOND3; + break; + case PIN_REMAP_THIRD: + reg = (volatile unsigned int *)LS1C_CBUS_THIRD3; + break; + case PIN_REMAP_FOURTH: + reg = (volatile unsigned int *)LS1C_CBUS_FOURTH3; + break; + case PIN_REMAP_FIFTH: + reg = (volatile unsigned int *)LS1C_CBUS_FIFTH3; + break; + } + break; + + default: + return ; } - // 置1 + // 缃1 reg_set_one_bit(reg, pin); return ; diff --git a/bsp/ls1cdev/ls1c_ram.lds b/bsp/ls1cdev/ls1c_ram.lds index a941b0d52b..9fa91ba5df 100644 --- a/bsp/ls1cdev/ls1c_ram.lds +++ b/bsp/ls1cdev/ls1c_ram.lds @@ -11,6 +11,7 @@ * Date Author Notes * 2010-05-17 swkyer first version * 2010-09-04 bernard move the beginning entry to 0x80200000 + * 2018-05-12 zhuangwei use -Ttext */ OUTPUT_ARCH(mips) @@ -19,16 +20,13 @@ GROUP(-lgcc -lc) ENTRY(_start) SECTIONS { - . = 0x80200000 ; - - .start : - { - *(.start); - } + . = 0x80000000 ; . = ALIGN(4); .text : { + start = ABSOLUTE(.); + *(.start); *(.text) *(.text.*) *(.rodata) diff --git a/bsp/ls1cdev/rtconfig.h b/bsp/ls1cdev/rtconfig.h index 72df0a83ef..18aa303c4b 100644 --- a/bsp/ls1cdev/rtconfig.h +++ b/bsp/ls1cdev/rtconfig.h @@ -156,11 +156,6 @@ /* RT-Thread online packages */ -/* system packages */ - -/* RT-Thread GUI Engine */ - - /* IoT - internet of things */ @@ -184,9 +179,20 @@ /* tools packages */ +/* system packages */ + +/* RT-Thread GUI Engine */ + + +/* peripheral libraries and drivers */ + + /* miscellaneous packages */ +/* sample package */ + + /* example package: hello */ #define RT_USING_UART2 diff --git a/libcpu/mips/loongson_1c/sdram_cfg.h b/libcpu/mips/loongson_1c/sdram_cfg.h new file mode 100644 index 0000000000..3f88f26623 --- /dev/null +++ b/libcpu/mips/loongson_1c/sdram_cfg.h @@ -0,0 +1,85 @@ + +#ifndef __OPENLOONGSON_SDRAM_CFG_H +#define __OPENLOONGSON_SDRAM_CFG_H + + +//#define SD_FREQ (6 * PLL_M) / (2 * SDRAM_PARAM_DIV_NUM) +#define SD_FREQ (((APB_CLK / 4) * (PLL_MULT / CPU_DIV)) / SDRAM_PARAM_DIV_NUM) + + +/* 棰楃矑琛屾暟 */ +#define ROW_1K 0x7 +#define ROW_2K 0x0 +#define ROW_4K 0x1 +#define ROW_8K 0x2 +#define ROW_16K 0x3 +/* 棰楃矑鍒楁暟 */ +#define COL_256 0x7 +#define COL_512 0x0 +#define COL_1K 0x1 +#define COL_2K 0x2 +#define COL_4K 0x3 +/* 棰楃矑浣嶅 */ +#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 + + +#if 0 +// 鐧借彍鏉8MB +/* + 浠ュ瀷鍙蜂负IS42S16400鐨凷DRAM涓轰緥锛 + 鐗╃悊鍙傛暟涓猴紝 + 瀹归噺锛8MB + 浣嶅锛16浣 + 鍒楀锛8浣嶏紝鍗2鐨8娆℃柟锛屽嵆256 + 琛屽锛12浣嶏紝鍗2鐨12娆℃柟锛屽嵆4K + + 鎵浠ワ紝 + 棰楃矑鐨勪綅瀹=WIDTH_16 + 棰楃矑鐨勫垪鏁=COL_256 + 棰楃矑鐨勮鏁=ROW_4K + + 鍐嶇粨鍚堝畯SD_PARA0鍜岃姱鐗囨墜鍐屼腑瀵勫瓨鍣⊿D_CONFIG锛岀浉淇′竴鐪嬪氨鑳芥槑鐧 + 鏇挎崲瀹廠D_PARA0涓殑琛屽銆佸垪瀹藉拰浣嶅 +*/ +#define SDRAM_WIDTH (WIDTH_16) +#define SDRAM_COL (COL_256) +#define SDRAM_ROW (ROW_4K) + +#else + +// 鏅洪緳32MByte +#define SDRAM_WIDTH (WIDTH_16) +#define SDRAM_COL (COL_512) +#define SDRAM_ROW (ROW_8K) + +#endif + +#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)) + + +#endif