summaryrefslogtreecommitdiff
path: root/bsp
diff options
context:
space:
mode:
author[email protected] <[email protected]>2011-04-05 12:49:01 +0000
committer[email protected] <[email protected]>2011-04-05 12:49:01 +0000
commitc84fc53783e8adeff28a57aedcc57a7f5202c166 (patch)
tree1e0daf4c01d67ab97609b585f4a96543fa5b6274 /bsp
parent8d77fe70dc8a93576933402d609e09a9768ec552 (diff)
add at91sam926x porting.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1364 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'bsp')
-rwxr-xr-xbsp/at91sam9260/SConscript22
-rwxr-xr-xbsp/at91sam9260/SConstruct37
-rwxr-xr-xbsp/at91sam9260/application.c101
-rwxr-xr-xbsp/at91sam9260/at91sam9260_ram.ld85
-rwxr-xr-xbsp/at91sam9260/board.c247
-rwxr-xr-xbsp/at91sam9260/board.h24
-rwxr-xr-xbsp/at91sam9260/console.c180
-rwxr-xr-xbsp/at91sam9260/led.c63
-rwxr-xr-xbsp/at91sam9260/led.h8
-rwxr-xr-xbsp/at91sam9260/rtconfig.h239
-rwxr-xr-xbsp/at91sam9260/rtconfig.py82
-rwxr-xr-xbsp/at91sam9260/startup.c150
12 files changed, 1238 insertions, 0 deletions
diff --git a/bsp/at91sam9260/SConscript b/bsp/at91sam9260/SConscript
new file mode 100755
index 0000000000..a0bba9c156
--- /dev/null
+++ b/bsp/at91sam9260/SConscript
@@ -0,0 +1,22 @@
+import rtconfig
+Import('RTT_ROOT')
+from building import *
+
+src_bsp = ['application.c', 'startup.c', 'board.c']
+src_drv = ['console.c']
+
+if GetDepend('RT_USING_LED'):
+ src_drv += ['led.c']
+
+#if GetDepend('RT_USING_DFS'):
+ #src_drv += ['sdcard.c']
+
+if GetDepend('RT_USING_LWIP'):
+ src_drv += ['macb.c']
+
+
+src = File(src_bsp + src_drv)
+CPPPATH = [RTT_ROOT + '/bsp/at91sam9260']
+group = DefineGroup('Startup', src, depend = [''], CPPPATH = CPPPATH)
+
+Return('group')
diff --git a/bsp/at91sam9260/SConstruct b/bsp/at91sam9260/SConstruct
new file mode 100755
index 0000000000..8894d33852
--- /dev/null
+++ b/bsp/at91sam9260/SConstruct
@@ -0,0 +1,37 @@
+import os
+import sys
+import rtconfig
+
+RTT_ROOT = os.path.normpath(os.getcwd() + '/../..')
+sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
+from building import *
+
+TARGET = 'rtthread-at91sam9260.' + rtconfig.TARGET_EXT
+
+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)
+env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
+
+Export('RTT_ROOT')
+Export('rtconfig')
+
+# prepare building environment
+objs = PrepareBuilding(env, RTT_ROOT)
+
+if GetDepend('RT_USING_WEBSERVER'):
+ objs = objs + SConscript(RTT_ROOT + '/components/net/webserver/SConscript', variant_dir='build/net/webserver', duplicate=0)
+
+if GetDepend('RT_USING_RTGUI'):
+ objs = objs + SConscript(RTT_ROOT + '/examples/gui/SConscript', variant_dir='build/examples/gui', duplicate=0)
+
+# libc testsuite
+objs = objs + SConscript(RTT_ROOT + '/examples/libc/SConscript', variant_dir='build/examples/libc', duplicate=0)
+
+# build program
+env.Program(TARGET, objs)
+
+# end building
+EndBuilding(TARGET)
diff --git a/bsp/at91sam9260/application.c b/bsp/at91sam9260/application.c
new file mode 100755
index 0000000000..97841bdc8d
--- /dev/null
+++ b/bsp/at91sam9260/application.c
@@ -0,0 +1,101 @@
+/*
+ * File : application.c
+ * This file is part of RT-Thread RTOS
+ * COPYRIGHT (C) 2006, 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
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2011-01-13 weety first version
+ */
+
+/**
+ * @addtogroup at91sam9260
+ */
+/*@{*/
+
+#include <rtthread.h>
+
+#ifdef RT_USING_LED
+#include "led.h"
+#endif
+
+#ifdef RT_USING_LED
+void rt_led_thread_entry(void* parameter)
+{
+ rt_uint8_t cnt = 0;
+ led_init();
+ while(1)
+ {
+ /* light on leds for one second */
+ rt_thread_delay(40);
+ cnt++;
+ if (cnt&0x01)
+ led_on(1);
+ else
+ led_off(1);
+ if (cnt&0x02)
+ led_on(2);
+ else
+ led_off(2);
+ if (cnt&0x04)
+ led_on(3);
+ else
+ led_off(3);
+
+ }
+}
+#endif
+
+int rt_application_init()
+{
+#ifdef RT_USING_LED
+ rt_thread_t led_thread;
+
+#if (RT_THREAD_PRIORITY_MAX == 32)
+
+
+ led_thread = rt_thread_create("led",
+ rt_led_thread_entry, RT_NULL,
+ 512, 20, 20);
+
+#else
+
+
+ led_thread = rt_thread_create("led",
+ rt_led_thread_entry, RT_NULL,
+ 512, 200, 20);
+
+#endif
+
+
+ if(led_thread != RT_NULL)
+ rt_thread_startup(led_thread);
+#endif
+
+ return 0;
+}
+
+/* NFSv3 Initialization */
+#if defined(RT_USING_DFS) && defined(RT_USING_LWIP) && defined(RT_USING_DFS_NFS)
+#include <dfs_nfs.h>
+void nfs_start(void)
+{
+ nfs_init();
+
+ if (dfs_mount(RT_NULL, "/nfs", "nfs", 0, RT_NFS_HOST_EXPORT) == 0)
+ {
+ rt_kprintf("NFSv3 File System initialized!\n");
+ }
+ else
+ rt_kprintf("NFSv3 File System initialzation failed!\n");
+}
+
+#include "finsh.h"
+FINSH_FUNCTION_EXPORT(nfs_start, start net filesystem);
+#endif
+
+/*@}*/
diff --git a/bsp/at91sam9260/at91sam9260_ram.ld b/bsp/at91sam9260/at91sam9260_ram.ld
new file mode 100755
index 0000000000..9f3fbfc45c
--- /dev/null
+++ b/bsp/at91sam9260/at91sam9260_ram.ld
@@ -0,0 +1,85 @@
+OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
+OUTPUT_ARCH(arm)
+ENTRY(_start)
+SECTIONS
+{
+ . = 0x20000000;
+
+ . = ALIGN(4);
+ .text :
+ {
+ *(.init)
+ *(.text)
+ *(.gnu.linkonce.t*)
+
+ /* section information for finsh shell */
+ . = ALIGN(4);
+ __fsymtab_start = .;
+ KEEP(*(FSymTab))
+ __fsymtab_end = .;
+ . = ALIGN(4);
+ __vsymtab_start = .;
+ KEEP(*(VSymTab))
+ __vsymtab_end = .;
+ . = ALIGN(4);
+
+ /* section information for modules */
+ . = ALIGN(4);
+ __rtmsymtab_start = .;
+ KEEP(*(RTMSymTab))
+ __rtmsymtab_end = .;
+ }
+
+ . = ALIGN(4);
+ .rodata : { *(.rodata) *(.rodata.*) *(.gnu.linkonce.r*) *(.eh_frame) }
+
+ . = ALIGN(4);
+ .ctors :
+ {
+ PROVIDE(__ctors_start__ = .);
+ KEEP(*(SORT(.ctors.*)))
+ KEEP(*(.ctors))
+ PROVIDE(__ctors_end__ = .);
+ }
+
+ .dtors :
+ {
+ PROVIDE(__dtors_start__ = .);
+ KEEP(*(SORT(.dtors.*)))
+ KEEP(*(.dtors))
+ PROVIDE(__dtors_end__ = .);
+ }
+
+ . = ALIGN(4);
+ .data :
+ {
+ *(.data)
+ *(.data.*)
+ *(.gnu.linkonce.d*)
+ }
+
+ . = ALIGN(4);
+ .nobss : { *(.nobss) }
+
+ . = 0x20300000;
+ . = ALIGN(4);
+ __bss_start = .;
+ .bss : { *(.bss) }
+ __bss_end = .;
+
+ /* stabs debugging sections. */
+ .stab 0 : { *(.stab) }
+ .stabstr 0 : { *(.stabstr) }
+ .stab.excl 0 : { *(.stab.excl) }
+ .stab.exclstr 0 : { *(.stab.exclstr) }
+ .stab.index 0 : { *(.stab.index) }
+ .stab.indexstr 0 : { *(.stab.indexstr) }
+ .comment 0 : { *(.comment) }
+ .debug_abbrev 0 : { *(.debug_abbrev) }
+ .debug_info 0 : { *(.debug_info) }
+ .debug_line 0 : { *(.debug_line) }
+ .debug_pubnames 0 : { *(.debug_pubnames) }
+ .debug_aranges 0 : { *(.debug_aranges) }
+
+ _end = .;
+}
diff --git a/bsp/at91sam9260/board.c b/bsp/at91sam9260/board.c
new file mode 100755
index 0000000000..98db2f825f
--- /dev/null
+++ b/bsp/at91sam9260/board.c
@@ -0,0 +1,247 @@
+/*
+ * File : board.c
+ * This file is part of RT-Thread RTOS
+ * COPYRIGHT (C) 2006 - 2009 RT-Thread Develop 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
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2011-01-13 weety first version
+ */
+
+#include <rtthread.h>
+#include <rthw.h>
+
+#include "board.h"
+
+/**
+ * @addtogroup at91sam9260
+ */
+/*@{*/
+
+
+extern void rt_hw_clock_init(void);
+extern void rt_hw_mmu_init(void);
+
+extern void rt_hw_get_clock(void);
+extern void rt_hw_set_dividor(rt_uint8_t hdivn, rt_uint8_t pdivn);
+extern void rt_hw_set_clock(rt_uint8_t sdiv, rt_uint8_t pdiv, rt_uint8_t mdiv);
+
+/*set debug serial port*/
+//#define USE_UART1
+//#define USE_UART3
+#define USE_DBGU
+
+#define DBGU ((struct uartport *)0xfffff200)
+#define UART1 ((struct uartport *)AT91SAM9260_BASE_US1)
+#define UART3 ((struct uartport *)AT91SAM9260_BASE_US3)
+struct serial_int_rx uart0_int_rx;
+struct serial_device uart0 =
+{
+ //UART0,
+ DBGU,
+ //UART1,
+ //UART3,
+ &uart0_int_rx,
+ RT_NULL
+};
+struct rt_device uart0_device;
+
+
+
+/**
+ * This function will handle serial
+ */
+void rt_serial_handler(int vector)
+{
+ #ifdef USE_UART1
+ int status;
+ status = readl(AT91SAM9260_BASE_US1+AT91_US_CSR);
+ if (!(status & readl(AT91SAM9260_BASE_US1+AT91_US_IMR)))
+ {
+ return;
+ }
+ #endif
+ #ifdef USE_UART3
+ at91_sys_read(AT91_USART3+AT91_US_CSR);
+ #endif
+ rt_hw_serial_isr(&uart0_device);
+
+}
+
+/**
+ * This function will handle init uart
+ */
+void rt_hw_uart_init(void)
+{
+ rt_uint32_t cd;
+ #ifdef USE_UART1
+ #define BAUDRATE 115200
+ //rt_uint32_t uart_rate;
+ //at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9260_ID_PIOB);
+ at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9260_ID_US1);
+ at91_sys_write(AT91_PIOB + PIO_IDR, (1<<6)|(1<<7));
+ at91_sys_write(AT91_PIOB + PIO_PUER, (1<<6));
+ at91_sys_write(AT91_PIOB + PIO_PUDR, (1<<7));
+ at91_sys_write(AT91_PIOB + PIO_ASR, (1<<6)|(1<<7));
+ at91_sys_write(AT91_PIOB + PIO_PDR, (1<<6)|(1<<7));
+ writel(AT91_US_RSTTX | AT91_US_RSTRX | AT91_US_RXDIS | AT91_US_TXDIS, AT91SAM9260_BASE_US1 + AT91_US_CR);
+ writel( AT91_US_USMODE_NORMAL | AT91_US_USCLKS_MCK | AT91_US_CHRL_8 | AT91_US_PAR_NONE | AT91_US_NBSTOP_1 | AT91_US_CHMODE_NORMAL, AT91SAM9260_BASE_US1 + AT91_US_MR);//0x100108c0
+ //at91_sys_write(AT91_USART1 + AT91_US_MR, 0x000008c0);//0x100108c0
+ cd = (clk_get_rate(clk_get("mck")) / 16 + BAUDRATE/2) / BAUDRATE;
+ writel(cd, AT91SAM9260_BASE_US1 + AT91_US_BRGR);
+ writel(AT91_US_RXEN | AT91_US_TXEN, AT91SAM9260_BASE_US1 + AT91_US_CR);
+
+ writel(0x1, AT91SAM9260_BASE_US1 + AT91_US_IER);
+ /* install interrupt handler */
+ rt_hw_interrupt_install(AT91SAM9260_ID_US1, rt_serial_handler, RT_NULL);
+ rt_hw_interrupt_umask(AT91SAM9260_ID_US1);
+ #endif
+ #ifdef USE_UART3
+ #define BAUDRATE 115200
+ //rt_uint32_t uart_rate;
+ at91_sys_write(AT91_PMC_PCER, 1<<AT91SAM9260_ID_US3);
+ at91_sys_write(AT91_PIOB+0x04, (1<<10)|(1<<11));
+ at91_sys_write(AT91_PIOB+0x70, (1<<10)|(1<<11));
+ writel(AT91_US_RSTTX | AT91_US_RSTRX | AT91_US_RXDIS | AT91_US_TXDIS, AT91SAM9260_BASE_US1 + AT91_US_CR);
+ writel( AT91_US_USMODE_NORMAL | AT91_US_USCLKS_MCK | AT91_US_CHRL_8 | AT91_US_PAR_NONE | AT91_US_NBSTOP_1 | AT91_US_CHMODE_NORMAL, AT91SAM9260_BASE_US3 + AT91_US_MR);
+ cd = (clk_get_rate(clk_get("mck")) / 16 + BAUDRATE/2) / BAUDRATE;
+ writel(cd, AT91SAM9260_BASE_US3 + AT91_US_BRGR);
+ writel(AT91_US_RXEN | AT91_US_TXEN, AT91SAM9260_BASE_US3 + AT91_US_CR);
+
+ writel(0x1, AT91SAM9260_BASE_US3 + AT91_US_IER);
+ /* install interrupt handler */
+ rt_hw_interrupt_install(AT91SAM9260_ID_US3, rt_serial_handler, RT_NULL);
+ rt_hw_interrupt_umask(AT91SAM9260_ID_US3);
+
+ #endif
+ #ifdef USE_DBGU
+ #define BAUDRATE 115200
+ //rt_uint32_t cd;
+ at91_sys_write(AT91_PIOB + PIO_IDR, (1<<14)|(1<<15));
+ //at91_sys_write(AT91_PIOB + PIO_PUER, (1<<6));
+ at91_sys_write(AT91_PIOB + PIO_PUDR, (1<<14)|(1<<15));
+ at91_sys_write(AT91_PIOB + PIO_ASR, (1<<14)|(1<<15));
+ at91_sys_write(AT91_PIOB + PIO_PDR, (1<<14)|(1<<15));
+ at91_sys_write(AT91_PMC_PCER, 1 << AT91_ID_SYS);
+ at91_sys_write(AT91_DBGU + AT91_US_CR, AT91_US_RSTTX | AT91_US_RSTRX | AT91_US_RXDIS | AT91_US_TXDIS);
+ at91_sys_write(AT91_DBGU + AT91_US_IDR, 0xffffffff);
+ at91_sys_write(AT91_DBGU + AT91_US_MR, AT91_US_USMODE_NORMAL | AT91_US_PAR_NONE);
+ cd = (clk_get_rate(clk_get("mck")) / 16 + BAUDRATE/2) / BAUDRATE;
+ at91_sys_write(AT91_DBGU + AT91_US_BRGR, cd);
+ at91_sys_write(AT91_DBGU + AT91_US_CR, AT91_US_RXEN | AT91_US_TXEN);
+
+ at91_sys_read(AT91_DBGU + AT91_US_CSR); //read for clearing interrupt
+ at91_sys_write(AT91_DBGU + AT91_US_IER, 0x1);
+ #endif
+}
+
+#define PIT_CPIV(x) ((x) & AT91_PIT_CPIV)
+#define PIT_PICNT(x) (((x) & AT91_PIT_PICNT) >> 20)
+
+static rt_uint32_t pit_cycle; /* write-once */
+static rt_uint32_t pit_cnt; /* access only w/system irq blocked */
+
+/**
+ * This function will handle rtos timer
+ */
+void rt_timer_handler(int vector)
+{
+ #ifdef USE_DBGU
+ if (at91_sys_read(AT91_DBGU + AT91_US_CSR) & 0x1) {
+ //rt_kprintf("DBGU interrupt occur\n");
+ rt_serial_handler(1);
+ }
+ #endif
+ if (at91_sys_read(AT91_PIT_SR) & AT91_PIT_PITS) {
+ unsigned nr_ticks;
+
+ /* Get number of ticks performed before irq, and ack it */
+ nr_ticks = PIT_PICNT(at91_sys_read(AT91_PIT_PIVR));
+ rt_tick_increase();
+ }
+}
+
+static void at91sam926x_pit_reset(void)
+{
+ /* Disable timer and irqs */
+ at91_sys_write(AT91_PIT_MR, 0);
+
+ /* Clear any pending interrupts, wait for PIT to stop counting */
+ while (PIT_CPIV(at91_sys_read(AT91_PIT_PIVR)) != 0)
+ ;
+
+ /* Start PIT but don't enable IRQ */
+ //at91_sys_write(AT91_PIT_MR, (pit_cycle - 1) | AT91_PIT_PITEN);
+ pit_cnt += pit_cycle * PIT_PICNT(at91_sys_read(AT91_PIT_PIVR));
+ at91_sys_write(AT91_PIT_MR, (pit_cycle - 1) | AT91_PIT_PITEN
+ | AT91_PIT_PITIEN);
+ rt_kprintf("PIT_MR=0x%08x\n", at91_sys_read(AT91_PIT_MR));
+}
+
+/*
+ * Set up both clocksource and clockevent support.
+ */
+static void at91sam926x_pit_init(void)
+{
+ rt_uint32_t pit_rate;
+ rt_uint32_t bits;
+
+ /*
+ * Use our actual MCK to figure out how many MCK/16 ticks per
+ * 1/HZ period (instead of a compile-time constant LATCH).
+ */
+ pit_rate = clk_get_rate(clk_get("mck")) / 16;
+ rt_kprintf("pit_rate=%dHZ\n", pit_rate);
+ pit_cycle = (pit_rate + RT_TICK_PER_SECOND/2) / RT_TICK_PER_SECOND;
+
+ /* Initialize and enable the timer */
+ at91sam926x_pit_reset();
+
+}
+
+/**
+ * This function will init pit for system ticks
+ */
+ void rt_hw_timer_init()
+ {
+ at91sam926x_pit_init();
+
+ /* install interrupt handler */
+ rt_hw_interrupt_install(AT91_ID_SYS, rt_timer_handler, RT_NULL);
+ rt_hw_interrupt_umask(AT91_ID_SYS);
+
+ }
+
+ void at91_tc1_init()
+ {
+ at91_sys_write(AT91_PMC_PCER, 1<<AT91SAM9260_ID_TC0);
+ writel(AT91_TC_TC0XC0S_NONE | AT91_TC_TC1XC1S_NONE | AT91_TC_TC2XC2S_NONE, AT91SAM9260_BASE_TCB0 + AT91_TC_BMR);
+ writel(AT91_TC_CLKDIS, AT91SAM9260_BASE_TC0 + AT91_TC_CCR);
+ writel(AT91_TC_TIMER_CLOCK4, AT91SAM9260_BASE_TC0 + AT91_TC_CMR);
+ writel(0xffff, AT91SAM9260_BASE_TC0 + AT91_TC_CV);
+ }
+
+/**
+ * This function will init at91sam9260 board
+ */
+void rt_hw_board_init()
+{
+ /* initialize the system clock */
+ rt_hw_clock_init();
+
+ /* initialize uart */
+ rt_hw_uart_init();
+
+ /* initialize mmu */
+ //rt_hw_mmu_init();
+
+ /* initialize timer0 */
+ rt_hw_timer_init();
+
+}
+
+/*@}*/
diff --git a/bsp/at91sam9260/board.h b/bsp/at91sam9260/board.h
new file mode 100755
index 0000000000..7c2a89fbb2
--- /dev/null
+++ b/bsp/at91sam9260/board.h
@@ -0,0 +1,24 @@
+/*
+ * File : board.h
+ * This file is part of RT-Thread RTOS
+ * COPYRIGHT (C) 2006, RT-Thread Develop 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
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2011-01-13 weety add board.h to this bsp
+ */
+
+#ifndef __BOARD_H__
+#define __BOARD_H__
+
+#include <at91sam926x.h>
+#include <serial.h>
+
+void rt_hw_board_init(void);
+//void rt_hw_sdcard_init(void);
+
+#endif
diff --git a/bsp/at91sam9260/console.c b/bsp/at91sam9260/console.c
new file mode 100755
index 0000000000..03836fb014
--- /dev/null
+++ b/bsp/at91sam9260/console.c
@@ -0,0 +1,180 @@
+#include <rtthread.h>
+
+#include <serial.h>
+
+#define RT_CONSOLE_WIDTH 240
+#define RT_CONSOLE_HEIGHT 320
+
+#define RT_CONSOLE_FONT_WIDTH 8
+#define RT_CONSOLE_FONT_HEIGHT 16
+
+#define RT_CONSOLE_COL (RT_CONSOLE_WIDTH/RT_CONSOLE_FONT_WIDTH)
+#define RT_CONSOLE_ROW (RT_CONSOLE_HEIGHT/RT_CONSOLE_FONT_HEIGHT)
+
+#define RT_CONSOLE_TAB 4
+
+#define RT_CONSOLE_FOREPIXEL (0x001f)
+
+extern struct serial_device uart0;
+
+struct rt_console
+{
+ rt_uint8_t* video_ptr;
+ rt_uint8_t* font_ptr;
+
+ /* bpp and pixel of width */
+ rt_uint8_t bpp;
+ rt_uint32_t pitch;
+
+ /* current cursor */
+ rt_uint8_t current_col;
+ rt_uint8_t current_row;
+};
+struct rt_console console;
+
+void rt_hw_console_init(rt_uint8_t* video_ptr, rt_uint8_t* font_ptr, rt_uint8_t bpp);
+void rt_hw_console_newline(void);
+void rt_hw_console_putc(char c);
+void rt_hw_console_clear(void);
+
+void rt_hw_console_init(rt_uint8_t* video_ptr, rt_uint8_t* font_ptr, rt_uint8_t bpp)
+{
+ rt_memset(&console, 0, sizeof(struct rt_console));
+
+ console.video_ptr = video_ptr;
+ console.font_ptr = font_ptr;
+ console.bpp = bpp;
+ console.pitch = console.bpp * RT_CONSOLE_WIDTH;
+
+ rt_hw_console_clear();
+}
+
+void rt_hw_console_putc(char c)
+{
+ switch (c)
+ {
+ case 10:
+ case 11:
+ case 12:
+ case 13:
+ /* to next line */
+ rt_hw_console_newline();
+ console.current_col = 0;
+ break;
+
+ case 9:
+ console.current_col += RT_CONSOLE_TAB;
+ break;
+
+ default:
+ {
+ rt_uint8_t* font_ptr;
+ register rt_uint32_t cursor;
+ register rt_uint32_t i, j;
+
+ if (console.current_col == RT_CONSOLE_COL)
+ {
+ rt_hw_console_newline();
+ console.current_col = 0;
+
+ rt_hw_console_putc(c);
+ return;
+ }
+
+ font_ptr = console.font_ptr + c * RT_CONSOLE_FONT_HEIGHT;
+ cursor = (console.current_row * RT_CONSOLE_FONT_HEIGHT) * console.pitch
+ + console.current_col * RT_CONSOLE_FONT_WIDTH * console.bpp;
+
+ for (i = 0; i < RT_CONSOLE_FONT_HEIGHT; i ++ )
+ {
+ for (j = 0; j < RT_CONSOLE_FONT_WIDTH; j ++)
+ {
+ if ( ((font_ptr[i] >> (7-j)) & 0x01) != 0 )
+ {
+ /* draw a pixel */
+ rt_uint8_t *ptr = &(console.video_ptr[cursor + i * console.pitch + j * console.bpp]);
+ switch(console.bpp)
+ {
+ case 1:
+ *ptr = RT_CONSOLE_FOREPIXEL;
+ break;
+ case 2:
+ *(rt_uint16_t*)ptr = RT_CONSOLE_FOREPIXEL;
+ break;
+ case 3:
+ ptr[0] = RT_CONSOLE_FOREPIXEL & 0xff;
+ ptr[1] = (RT_CONSOLE_FOREPIXEL >> 8) & 0xff;
+ ptr[2] = (RT_CONSOLE_FOREPIXEL >> 16) & 0xff;
+ break;
+ case 4:
+ *(rt_uint32_t*)ptr = RT_CONSOLE_FOREPIXEL;
+ break;
+ }
+ }
+ }
+ }
+
+ console.current_col ++;
+ }
+ break;
+ }
+}
+
+void rt_hw_console_newline()
+{
+ console.current_row ++;
+ if (console.current_row >= RT_CONSOLE_ROW)
+ {
+ rt_uint32_t i;
+
+ /* scroll to next line */
+ for (i = 0; i < RT_CONSOLE_ROW - 1; i ++)
+ {
+ rt_memcpy(console.video_ptr + i * RT_CONSOLE_FONT_HEIGHT * console.pitch,
+ console.video_ptr + (i + 1) * RT_CONSOLE_FONT_HEIGHT * console.pitch,
+ RT_CONSOLE_FONT_HEIGHT * console.pitch);
+ }
+
+ /* clear last line */
+ rt_memset(console.video_ptr + (RT_CONSOLE_ROW - 1) * RT_CONSOLE_FONT_HEIGHT * console.pitch,
+ 0,
+ RT_CONSOLE_FONT_HEIGHT * console.pitch);
+
+ console.current_row = RT_CONSOLE_ROW - 1;
+ }
+}
+
+void rt_hw_console_clear()
+{
+ console.current_col = 0;
+ console.current_row = 0;
+
+ rt_memset(console.video_ptr, 0, RT_CONSOLE_HEIGHT * console.pitch);
+}
+
+/* write one character to serial, must not trigger interrupt */
+void rt_hw_serial_putc(const char c)
+{
+ /*
+ to be polite with serial console add a line feed
+ to the carriage return character
+ */
+ if (c=='\n')rt_hw_serial_putc('\r');
+
+ while (!(uart0.uart_device->USART_CSR & TXRDY));
+ uart0.uart_device->USART_THR = (c & 0x1FF);
+}
+
+/**
+ * This function is used by rt_kprintf to display a string on console.
+ *
+ * @param str the displayed string
+ */
+void rt_hw_console_output(const char* str)
+{
+ while (*str)
+ {
+ rt_hw_serial_putc(*str++);
+ }
+}
+
diff --git a/bsp/at91sam9260/led.c b/bsp/at91sam9260/led.c
new file mode 100755
index 0000000000..f3fddcce53
--- /dev/null
+++ b/bsp/at91sam9260/led.c
@@ -0,0 +1,63 @@
+/*
+ * File : led.c
+ * This file is part of RT-Thread RTOS
+ * COPYRIGHT (C) 2006, RT-Thread Develop Team
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://openlab.rt-thread.com/license/LICENSE
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2011-01-13 weety first version
+ */
+
+#include <rtthread.h>
+#include <at91sam926x.h>
+#include "led.h"
+
+void led_init(void)
+{
+ at91_sys_write(AT91_PIOC, (1<<8)|(1<<11)|(1<<6));
+ at91_sys_write(AT91_PIOC+0x10, (1<<8)|(1<<11)|(1<<6));
+ at91_sys_write(AT91_PIOC+0x64, (1<<8)|(1<<11)|(1<<6));
+ at91_sys_write(AT91_PIOC+0x30, (1<<8)|(1<<11)|(1<<6));
+}
+
+void led_on(int num)
+{
+ switch(num)
+ {
+ case 1:
+ at91_sys_write(AT91_PIOC+0x34, 1<<8);
+ break;
+ case 2:
+ at91_sys_write(AT91_PIOC+0x34, 1<<11);
+ break;
+ case 3:
+ at91_sys_write(AT91_PIOC+0x34, 1<<6);
+ break;
+ default:
+ break;
+ }
+
+}
+
+void led_off(int num)
+{
+ switch(num)
+ {
+ case 1:
+ at91_sys_write(AT91_PIOC+0x30, 1<<8);
+ break;
+ case 2:
+ at91_sys_write(AT91_PIOC+0x30, 1<<11);
+ break;
+ case 3:
+ at91_sys_write(AT91_PIOC+0x30, 1<<6);
+ break;
+ default:
+ break;
+ }
+ //at91_sys_write(AT91_PIOC+0x30, 1<<8);
+}
diff --git a/bsp/at91sam9260/led.h b/bsp/at91sam9260/led.h
new file mode 100755
index 0000000000..71fd6947e6
--- /dev/null
+++ b/bsp/at91sam9260/led.h
@@ -0,0 +1,8 @@
+#ifndef __LED_H__
+#define __LED_H__
+
+void led_init(void);
+void led_on(int num);
+void led_off(int num);
+
+#endif
diff --git a/bsp/at91sam9260/rtconfig.h b/bsp/at91sam9260/rtconfig.h
new file mode 100755
index 0000000000..62ecadef21
--- /dev/null
+++ b/bsp/at91sam9260/rtconfig.h
@@ -0,0 +1,239 @@
+/* RT-Thread config file */
+#ifndef __RTTHREAD_CFG_H__
+#define __RTTHREAD_CFG_H__
+
+/* RT_NAME_MAX*/
+#define RT_NAME_MAX 32
+
+/* RT_ALIGN_SIZE*/
+#define RT_ALIGN_SIZE 4
+
+/* PRIORITY_MAX */
+#define RT_THREAD_PRIORITY_MAX 256
+
+/* Tick per Second */
+#define RT_TICK_PER_SECOND 100
+
+/* SECTION: RT_DEBUG */
+/* Thread Debug */
+#define RT_DEBUG
+//#define SCHEDULER_DEBUG
+/* #define RT_THREAD_DEBUG */
+
+#define RT_USING_OVERFLOW_CHECK
+
+/* Using Hook */
+#define RT_USING_HOOK
+
+/* Using Software Timer */
+#define RT_USING_TIMER_SOFT
+#define RT_TIMER_THREAD_PRIO 8
+#define RT_TIMER_THREAD_STACK_SIZE 512
+#define RT_TIMER_TICK_PER_SECOND 10
+
+/* SECTION: IPC */
+/* Using Semaphore */
+#define RT_USING_SEMAPHORE
+
+/* Using Mutex */
+#define RT_USING_MUTEX
+
+/* Using Event */
+#define RT_USING_EVENT
+
+/* Using MailBox */
+#define RT_USING_MAILBOX
+
+/* Using Message Queue */
+#define RT_USING_MESSAGEQUEUE
+
+/* SECTION: Memory Management */
+/* Using Memory Pool Management*/
+#define RT_USING_MEMPOOL
+
+/* Using Dynamic Heap Management */
+#define RT_USING_HEAP
+
+/* Using Small MM */
+/* #define RT_USING_SMALL_MEM */
+
+/* Using SLAB Allocator */
+#define RT_USING_SLAB
+
+/* SECTION: Device System */
+/* Using Device System */
+#define RT_USING_DEVICE
+
+/* Using Module System */
+#define RT_USING_MODULE
+#define RT_USING_LIBDL
+
+/* SECTION: Console options */
+#define RT_USING_CONSOLE
+/* the buffer size of console */
+#define RT_CONSOLEBUF_SIZE 128
+
+/* SECTION: finsh, a C-Express shell */
+/* Using FinSH as Shell*/
+#define RT_USING_FINSH
+/* Using symbol table */
+#define FINSH_USING_SYMTAB
+#define FINSH_USING_DESCRIPTION
+#define FINSH_THREAD_STACK_SIZE 4096
+
+/* SECTION: the runtime libc library */
+/* the runtime libc library */
+#define RT_USING_NEWLIB
+#define RT_USING_PTHREADS
+
+/* SECTION: C++ support */
+/* Using C++ support */
+/* #define RT_USING_CPLUSPLUS */
+
+/* SECTION: Device filesystem support */
+/* using DFS support */
+#define RT_USING_DFS
+#define RT_USING_DFS_ELMFAT
+/* use long file name feature */
+#define RT_DFS_ELM_USE_LFN 1
+/* the max number of file length */
+#define RT_DFS_ELM_MAX_LFN 128
+/* #define RT_USING_DFS_YAFFS2 */
+#define RT_USING_DFS_DEVFS
+
+#define RT_USING_DFS_NFS
+#define RT_NFS_HOST_EXPORT "192.168.1.5:/"
+
+#define DFS_USING_WORKDIR
+
+/* the max number of mounted filesystem */
+#define DFS_FILESYSTEMS_MAX 4
+/* the max number of opened files */
+#define DFS_FD_MAX 16
+/* the max number of cached sector */
+#define DFS_CACHE_MAX_NUM 4
+
+/* Enable freemodbus protocol stack*/
+/* #define RT_USING_MODBUS */
+
+//#define RT_USING_LED
+
+/* SECTION: lwip, a lightweight TCP/IP protocol stack */
+/* Using lightweight TCP/IP protocol stack */
+//#define RT_USING_LWIP
+#define RT_LWIP_DNS
+
+/* Trace LwIP protocol */
+// #define RT_LWIP_DEBUG
+
+/* Enable ICMP protocol */
+#define RT_LWIP_ICMP
+
+/* Enable IGMP protocol */
+#define RT_LWIP_IGMP
+
+/* Enable UDP protocol */
+#define RT_LWIP_UDP
+
+/* Enable TCP protocol */
+#define RT_LWIP_TCP
+
+/* the number of simulatenously active TCP connections*/
+#define RT_LWIP_TCP_PCB_NUM 5
+
+/* TCP sender buffer space */
+#define RT_LWIP_TCP_SND_BUF 1024*10
+
+/* TCP receive window. */
+#define RT_LWIP_TCP_WND 1024
+
+/* Enable SNMP protocol */
+/* #define RT_LWIP_SNMP */
+
+/* Using DHCP */
+/* #define RT_LWIP_DHCP */
+
+#define RT_LWIP_DNS
+
+/* ip address of target */
+#define RT_LWIP_IPADDR0 192
+#define RT_LWIP_IPADDR1 168
+#define RT_LWIP_IPADDR2 1
+#define RT_LWIP_IPADDR3 30
+
+/* gateway address of target */
+#define RT_LWIP_GWADDR0 192
+#define RT_LWIP_GWADDR1 168
+#define RT_LWIP_GWADDR2 1
+#define RT_LWIP_GWADDR3 1
+
+/* mask address of target */
+#define RT_LWIP_MSKADDR0 255
+#define RT_LWIP_MSKADDR1 255
+#define RT_LWIP_MSKADDR2 255
+#define RT_LWIP_MSKADDR3 0
+
+/* the number of blocks for pbuf */
+#define RT_LWIP_PBUF_NUM 16
+
+/* the number of simultaneously queued TCP */
+#define RT_LWIP_TCP_SEG_NUM 40
+
+/* thread priority of tcpip thread */
+#define RT_LWIP_TCPTHREAD_PRIORITY 128
+
+/* mail box size of tcpip thread to wait for */
+#define RT_LWIP_TCPTHREAD_MBOX_SIZE 32
+
+/* thread stack size of tcpip thread */
+#define RT_LWIP_TCPTHREAD_STACKSIZE 4096
+
+/* thread priority of ethnetif thread */
+#define RT_LWIP_ETHTHREAD_PRIORITY 144
+
+/* mail box size of ethnetif thread to wait for */
+#define RT_LWIP_ETHTHREAD_MBOX_SIZE 32
+
+/* thread stack size of ethnetif thread */
+#define RT_LWIP_ETHTHREAD_STACKSIZE 1024
+
+
+/* SECTION: RTGUI support */
+/* using RTGUI support */
+/* #define RT_USING_RTGUI */
+
+/* name length of RTGUI object */
+//#define RTGUI_NAME_MAX 16
+/* support 16 weight font */
+//#define RTGUI_USING_FONT16
+/* support 16 weight font */
+//#define RTGUI_USING_FONT12
+/* support Chinese font */
+//#define RTGUI_USING_FONTHZ
+/* use DFS as file interface */
+//#define RTGUI_USING_DFS_FILERW
+/* use font file as Chinese font */
+/* #define RTGUI_USING_HZ_FILE */
+/* use Chinese bitmap font */
+//#define RTGUI_USING_HZ_BMP
+/* use small size in RTGUI */
+/* #define RTGUI_USING_SMALL_SIZE */
+/* use mouse cursor */
+/* #define RTGUI_USING_MOUSE_CURSOR */
+
+/* SECTION: FTK support */
+/* using FTK support */
+/* #define RT_USING_FTK */
+
+/*
+ * Note on FTK:
+ *
+ * FTK depends :
+ * #define RT_USING_NEWLIB
+ * #define DFS_USING_WORKDIR
+ *
+ * And the maximal length must great than 64
+ * #define RT_DFS_ELM_MAX_LFN 128
+ */
+
+#endif
diff --git a/bsp/at91sam9260/rtconfig.py b/bsp/at91sam9260/rtconfig.py
new file mode 100755
index 0000000000..3386afa13f
--- /dev/null
+++ b/bsp/at91sam9260/rtconfig.py
@@ -0,0 +1,82 @@
+
+# toolchains options
+ARCH = 'arm'
+CPU = 'at91sam926x'
+TextBase = '0x20000000'
+
+CROSS_TOOL = 'gcc'
+
+if CROSS_TOOL == 'gcc':
+ PLATFORM = 'gcc'
+ EXEC_PATH = '/opt/arm-2010q1/bin/'
+elif CROSS_TOOL == 'keil':
+ PLATFORM = 'armcc'
+ EXEC_PATH = 'E:/Keil'
+#BUILD = 'debug'
+BUILD = 'release'
+
+if PLATFORM == 'gcc':
+ # toolchains
+ PREFIX = 'arm-none-eabi-'
+ #PREFIX = 'arm-none-linux-gnueabi-'
+ CC = PREFIX + 'gcc'
+ AS = PREFIX + 'gcc'
+ AR = PREFIX + 'ar'
+ LINK = PREFIX + 'gcc'
+ TARGET_EXT = 'axf'
+ SIZE = PREFIX + 'size'
+ OBJDUMP = PREFIX + 'objdump'
+ OBJCPY = PREFIX + 'objcopy'
+
+ DEVICE = ' -mcpu=arm926ej-s'
+ CFLAGS = DEVICE
+ AFLAGS = ' -c' + DEVICE + ' -x assembler-with-cpp' + ' -DTEXT_BASE=' + TextBase
+ LFLAGS = DEVICE + ' -Wl,--gc-sections,-Map=rtthread_at91sam9260.map,-cref,-u,_start -T at91sam9260_ram.ld' + ' -Ttext ' + TextBase
+
+ CPATH = ''
+ LPATH = ''
+
+ if BUILD == 'debug':
+ CFLAGS += ' -O0 -gdwarf-2'
+ AFLAGS += ' -gdwarf-2'
+ else:
+ CFLAGS += ' -O2'
+
+ POST_ACTION = OBJCPY + ' -O binary $TARGET rtthread.bin\n' + SIZE + ' $TARGET \n'
+
+elif PLATFORM == 'armcc':
+ # toolchains
+ CC = 'armcc'
+ AS = 'armasm'
+ AR = 'armar'
+ LINK = 'armlink'
+ TARGET_EXT = 'axf'
+
+ DEVICE = ' --device DARMSS9'
+ CFLAGS = DEVICE + ' --apcs=interwork --diag_suppress=870'
+ AFLAGS = DEVICE
+ LFLAGS = DEVICE + ' --strict --info sizes --info totals --info unused --info veneers --list rtthread-at91sam9260.map --ro-base 0x20000000 --entry Entry_Point --first Entry_Point'
+
+ CFLAGS += ' -I"' + EXEC_PATH + '/ARM/RV31/INC"'
+ LFLAGS += ' --libpath "' + EXEC_PATH + '/ARM/RV31/LIB"'
+
+ EXEC_PATH += '/arm/bin40/'
+
+ if BUILD == 'debug':
+ CFLAGS += ' -g -O0'
+ AFLAGS += ' -g'
+ else:
+ CFLAGS += ' -O2'
+
+ POST_ACTION = 'fromelf --bin $TARGET --output rtthread.bin \nfromelf -z $TARGET'
+
+elif PLATFORM == 'iar':
+ # toolchains
+ CC = 'armcc'
+ AS = 'armasm'
+ AR = 'armar'
+ LINK = 'armlink'
+
+ CFLAGS = ''
+ AFLAGS = ''
+ LFLAGS = ''
diff --git a/bsp/at91sam9260/startup.c b/bsp/at91sam9260/startup.c
new file mode 100755
index 0000000000..30130cc76a
--- /dev/null
+++ b/bsp/at91sam9260/startup.c
@@ -0,0 +1,150 @@
+/*
+ * File : startup.c
+ * This file is part of RT-Thread RTOS
+ * COPYRIGHT (C) 2006, RT-Thread Develop 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
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2011-01-13 weety first version
+ */
+
+#include <rthw.h>
+#include <rtthread.h>
+
+#include <at91sam926x.h>
+#ifdef RT_USING_FINSH
+#include <finsh.h>
+#endif
+
+extern void rt_hw_interrupt_init(void);
+extern void rt_hw_board_init(void);
+extern void rt_serial_init(void);
+extern void rt_system_timer_init(void);
+extern void rt_system_scheduler_init(void);
+extern void rt_thread_idle_init(void);
+extern void rt_hw_cpu_icache_enable(void);
+extern void rt_show_version(void);
+extern void rt_system_heap_init(void*, void*);
+extern void rt_hw_finsh_init(void);
+extern void rt_application_init(void);
+
+extern struct serial_device uart0;
+extern struct rt_device uart0_device;
+
+/**
+ * @addtogroup at91sam9260
+ */
+
+/*@{*/
+#if defined(__CC_ARM)
+ extern int Image$$ER_ZI$$ZI$$Base;
+ extern int Image$$ER_ZI$$ZI$$Length;
+ extern int Image$$ER_ZI$$ZI$$Limit;
+#elif (defined (__GNUC__))
+ rt_uint8_t _irq_stack_start[1024];
+ rt_uint8_t _fiq_stack_start[1024];
+ rt_uint8_t _undefined_stack_start[512];
+ rt_uint8_t _abort_stack_start[512];
+ rt_uint8_t _svc_stack_start[1024] SECTION(".nobss");
+ extern unsigned char __bss_start;
+ extern unsigned char __bss_end;
+#endif
+
+#ifdef RT_USING_FINSH
+extern void finsh_system_init(void);
+#endif
+
+
+/**
+ * This function will startup RT-Thread RTOS.
+ */
+void rtthread_startup(void)
+{
+ rt_uint32_t UNUSED level;
+
+ /* disable interrupt first */
+ level = rt_hw_interrupt_disable();
+ /* enable cpu cache */
+ rt_hw_cpu_icache_enable();
+ rt_hw_cpu_dcache_enable();
+
+ /* initialize hardware interrupt */
+ rt_hw_interrupt_init();
+
+ /* initialize board */
+ rt_hw_board_init();
+
+ /* show version */
+ rt_show_version();
+
+ /* initialize tick */
+ rt_system_tick_init();
+
+ /* initialize kernel object */
+ rt_system_object_init();
+
+ /* initialize timer system */
+ rt_system_timer_init();
+
+ /* initialize heap memory system */
+#ifdef __CC_ARM
+ rt_system_heap_init((void*)&Image$$ER_ZI$$ZI$$Limit, (void*)0x24000000);
+#else
+ rt_system_heap_init((void*)&__bss_end, (void*)0x23f00000);
+#endif
+
+#ifdef RT_USING_MODULE
+ /* initialize module system*/
+ rt_system_module_init();
+#endif
+
+ /* initialize scheduler system */
+ rt_system_scheduler_init();
+
+#ifdef RT_USING_DEVICE
+ /* register uart1 */
+ rt_hw_serial_register(&uart0_device, "uart0",
+ RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_STREAM | RT_DEVICE_FLAG_INT_RX,
+ &uart0);
+
+#ifdef RT_USING_DFS
+ //rt_hw_sdcard_init();
+#endif
+
+#ifdef RT_USING_LWIP
+ rt_hw_macb_init();
+#endif
+
+ /*init all registed devices */
+ rt_device_init_all();
+#endif
+
+ /* initialize application */
+ rt_application_init();
+
+#ifdef RT_USING_FINSH
+ /* initialize finsh */
+ finsh_system_init();
+#ifdef RT_USING_DEVICE
+ finsh_set_device("uart0");
+#endif
+#endif
+
+ /* initialize system timer thread */
+ rt_system_timer_thread_init();
+
+ /* initialize idle thread */
+ rt_thread_idle_init();
+
+ /* start scheduler */
+ rt_system_scheduler_start();
+
+ /* never reach here */
+ return ;
+}
+
+/*@}*/