diff options
| author | [email protected] <[email protected]> | 2011-12-17 04:14:22 +0000 |
|---|---|---|
| committer | [email protected] <[email protected]> | 2011-12-17 04:14:22 +0000 |
| commit | 08f25161d9f988eaefd37e4d06fe244bed381418 (patch) | |
| tree | 61a9b5df13376536407ea824304956700781d7e7 /bsp/microblaze | |
| parent | 43ece86f1122fbc8603b9dba02e3be66522114f7 (diff) | |
porting for microblaze. nl1031
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1843 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'bsp/microblaze')
| -rwxr-xr-x | bsp/microblaze/application.c | 26 | ||||
| -rwxr-xr-x | bsp/microblaze/board.c | 232 | ||||
| -rwxr-xr-x | bsp/microblaze/board.h | 22 | ||||
| -rwxr-xr-x | bsp/microblaze/rtconfig.h | 190 | ||||
| -rwxr-xr-x | bsp/microblaze/startup.c | 120 |
5 files changed, 590 insertions, 0 deletions
diff --git a/bsp/microblaze/application.c b/bsp/microblaze/application.c new file mode 100755 index 0000000000..46e5ef6232 --- /dev/null +++ b/bsp/microblaze/application.c @@ -0,0 +1,26 @@ +/* + * File : app.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 + * 2006-06-05 Bernard the first version + */ + +/** + * @addtogroup sam7s + */ +/*@{*/
+#include <rtthread.h>
+ +int rt_application_init() +{ + return 0; +} + +/*@}*/ diff --git a/bsp/microblaze/board.c b/bsp/microblaze/board.c new file mode 100755 index 0000000000..d0f54e0013 --- /dev/null +++ b/bsp/microblaze/board.c @@ -0,0 +1,232 @@ +/* + * File : board.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 + * 2006-08-23 Bernard first implementation + * + * 2011-12-17 nl1031 for MacroBlaze + * + */ + +#include <rtthread.h> +#include <rthw.h> + +#include "xbasic_types.h" +#include "board.h" +#include "xgpio.h" +#include "xparameters.h" +#include "xuartlite.h" +#include "xtmrctr.h" +#include "xintc.h" +#include "xstatus.h" +#include "xuartlite_l.h" +#include "xintc_l.h" + +#ifdef RT_USING_UART1 +#include "serial.h" +#endif + +#define TIMER_CNTR_0 0 +#define PIV (XPAR_PROC_BUS_0_FREQ_HZ / RT_TICK_PER_SECOND) +#define LEDS_DEVICE_ID XPAR_LEDS_4BITS_DEVICE_ID +#define RS232_DEVICE_ID XPAR_USB_UART_DEVICE_ID + +#ifdef RT_USING_UART1 +#define USB_UART_BASE ((struct uartport *)XPAR_USB_UART_BASEADDR) +#endif + +/* Global Variables: */ +XTmrCtr timer; /* The instance of the timer */ +XGpio gpio_output; /* The driver instance for GPIO Device configured as O/P */ +XUartLite uart_lite; /* Instance of the UartLite device */ +XIntc int_ctl; /* The instance of the Interrupt Controller */ +static rt_uint32_t led_data; + + + +static void rt_hw_board_led_init(void); + +/** + * This function will init led on the board + */ +static void rt_hw_board_led_init() +{ + rt_uint32_t status; + led_data = 0; + status = XGpio_Initialize(&gpio_output, LEDS_DEVICE_ID); + if (status != XST_SUCCESS) + { + return; + } + + /* + * Set the direction for all signals to be outputs + */ + XGpio_SetDataDirection(&gpio_output, 1, 0x0); + /* + * Set the GPIO outputs to high + */ + XGpio_DiscreteWrite(&gpio_output, 1, 3); +} + +/** + * This function will take the led on board on. + * + * @param n the number nth led + */ +void rt_hw_board_led_on(rt_uint32_t led) +{ + led_data |= led; + XGpio_DiscreteWrite(&gpio_output, 1, led_data); +} + +/** + * This function will take the led on board off. + * + * @param n the number nth led + */ +void rt_hw_board_led_off(rt_uint32_t led) +{ + led_data &= ~led; + XGpio_DiscreteWrite(&gpio_output, 1, led_data); +} + + +void rt_hw_led_flash(void) +{ + rt_uint32_t i; + + rt_hw_board_led_off(1); + for (i = 0; i < 20000; i ++); + + rt_hw_board_led_on(1); + for (i = 0; i < 20000; i ++); +} + + +#ifdef RT_USING_CONSOLE + +/* + * RT-Thread Console Interface, used by rt_kprintf + */ +/** + * This function is used to display a string on console, normally, it's + * invoked by rt_kprintf + * + * @param str the displayed string + */ +void rt_hw_console_output(const char* str) +{ + while (*str) + { + + /* Transmit Character */ + XUartLite_SendByte(STDOUT_BASEADDRESS, *str); + if (*str == '\n') + XUartLite_SendByte(STDOUT_BASEADDRESS, '\r'); + str++; + } +} + +static void rt_hw_console_init() +{ + rt_uint32_t status; + + /* + * Initialize the UartLite driver so that it is ready to use. + */ + status = XUartLite_Initialize(&uart_lite, RS232_DEVICE_ID); + if (status != XST_SUCCESS) + { + return; + } + +} +#endif + + +void rt_hw_timer_handler(void) +{ + rt_uint32_t csr; + csr = XTmrCtr_ReadReg(timer.BaseAddress, TIMER_CNTR_0, XTC_TCSR_OFFSET); + /* + * Check if timer expired and interrupt occured + */ + if (csr & XTC_CSR_INT_OCCURED_MASK) + { + rt_tick_increase(); + XTmrCtr_WriteReg(timer.BaseAddress, TIMER_CNTR_0, XTC_TCSR_OFFSET, csr | XTC_CSR_INT_OCCURED_MASK); + } + +} + + +/* +********************************************************************************************************* +* rt_intc_init() +* +* Description: This function intializes the interrupt controller by registering the appropriate handler +* functions and enabling interrupts. +* +* Arguments : None +* +* Returns : None +********************************************************************************************************* +*/ + +void rt_intc_init (void) +{ + XStatus status; + + XIntc_MasterDisable(XPAR_INTC_0_BASEADDR); + + status = XIntc_Initialize(&int_ctl, XPAR_INTC_0_DEVICE_ID); + + /* install interrupt handler */ + rt_hw_interrupt_install(XPAR_INTC_0_TMRCTR_0_VEC_ID, (rt_isr_handler_t)rt_hw_timer_handler, RT_NULL); + rt_hw_interrupt_umask(XPAR_INTC_0_TMRCTR_0_VEC_ID); + + XIntc_Start(&int_ctl, XIN_REAL_MODE); + +} + + +void rt_tmr_init (void) +{ + rt_uint32_t ctl; + XStatus status; + + status = XTmrCtr_Initialize(&timer,XPAR_AXI_TIMER_0_DEVICE_ID); + XTmrCtr_WriteReg(timer.BaseAddress, TIMER_CNTR_0, XTC_TLR_OFFSET, PIV); + ctl = XTC_CSR_ENABLE_TMR_MASK | XTC_CSR_ENABLE_INT_MASK | XTC_CSR_AUTO_RELOAD_MASK | XTC_CSR_DOWN_COUNT_MASK; + XTmrCtr_WriteReg(timer.BaseAddress, TIMER_CNTR_0, XTC_TCSR_OFFSET, ctl); +} + + + +/** + * This function will initial SPARTAN 6 LX9 board. + */ +void rt_hw_board_init() +{ + /* init hardware console */ + rt_hw_console_init(); + + /* init led */ + rt_hw_board_led_init(); + + /* init intc */ + rt_intc_init(); + + /* timer init */ + rt_tmr_init(); + + +} diff --git a/bsp/microblaze/board.h b/bsp/microblaze/board.h new file mode 100755 index 0000000000..9e542c17c5 --- /dev/null +++ b/bsp/microblaze/board.h @@ -0,0 +1,22 @@ +/* + * 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://openlab.rt-thread.com/license/LICENSE + * + */ + +#ifndef __BOARD_H__ +#define __BOARD_H__ + + +#define MCK 50000000 + +void rt_hw_board_led_on(rt_uint32_t); +void rt_hw_board_led_off(rt_uint32_t); +void rt_hw_board_init(void); + +#endif diff --git a/bsp/microblaze/rtconfig.h b/bsp/microblaze/rtconfig.h new file mode 100755 index 0000000000..674de50c4d --- /dev/null +++ b/bsp/microblaze/rtconfig.h @@ -0,0 +1,190 @@ +/* RT-Thread config file */
+#ifndef __RTTHREAD_CFG_H__
+#define __RTTHREAD_CFG_H__
+
+#define IDLE_THREAD_STACK_SIZE 2048
+
+/* RT_NAME_MAX*/
+#define RT_NAME_MAX 32
+
+/* RT_ALIGN_SIZE*/
+#define RT_ALIGN_SIZE 4
+
+/* PRIORITY_MAX*/
+#define RT_THREAD_PRIORITY_MAX 32
+
+/* Tick per Second*/
+#define RT_TICK_PER_SECOND 100
+
+
+/* SECTION: RT_DEBUG */
+/* Thread Debug*/
+/* #define RT_THREAD_DEBUG */
+
+/* Using Hook*/
+#define RT_USING_HOOK
+
+/* SECTION: IPC */
+/* Using Semaphore*/
+#define RT_USING_SEMAPHORE
+
+/* Using Mutex*/
+#define RT_USING_MUTEX
+
+/* Using Event*/
+#define RT_USING_EVENT
+
+/* Using Faset Event*/
+/* #define RT_USING_FASTEVENT */
+
+/* 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
+
+/* buffer size for UART reception*/
+#define RT_UART_RX_BUFFER_SIZE 64
+
+/* buffer size for UART transmission*/
+#define RT_UART_TX_BUFFER_SIZE 64
+
+/* Using UART1*/
+#define RT_USING_UART1
+
+/* Using UART1*/
+/* #define RT_USING_UART2 */
+
+/* Using UART1*/
+/* #define RT_USING_UART3 */
+
+/* SECTION: Console options */
+#define RT_USING_CONSOLE
+/* the buffer size of console*/
+#define RT_CONSOLEBUF_SIZE 256
+
+/* SECTION: FinSH shell options */
+/* Using FinSH as Shell*/
+#define RT_USING_FINSH
+/* use symbol table */
+#define FINSH_USING_SYMTAB
+#define FINSH_USING_DESCRIPTION
+#define FINSH_THREAD_STACK_SIZE 8192
+#define RT_USING_TC
+
+
+/* SECTION: a runtime libc library */
+/* a runtime libc library*/
+/* #define RT_USING_NEWLIB */
+#define RT_USING_MINILIBC
+
+/* SECTION: C++ support */
+/* Using C++ support*/
+/* #define RT_USING_CPLUSPLUS */
+
+/* SECTION: RTGUI support */
+/* using RTGUI support*/
+/* #define RT_USING_RTGUI */
+
+/* SECTION: Device filesystem support */
+/* using DFS support*/
+/* #define RT_USING_DFS */
+
+/* SECTION: EFSL filesystem support */
+/* using EFSL filesystem support*/
+/* #define RT_USING_EFSL */
+
+/* SECTION: lwip, a lighwight TCP/IP protocol stack */
+/* Using lighweight TCP/IP protocol stack*/
+/* #define RT_USING_LWIP */
+
+/* Using webserver goahead support*/
+/* #define RT_USING_WEBSERVER */
+
+/* Using ftpserver support*/
+/* #define RT_USING_FTPSERVER */
+
+/* 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 10240
+
+/* Enable SNMP protocol*/
+/* #define RT_LWIP_SNMP */
+
+/* Using DHCP*/
+/* #define RT_LWIP_DHCP */
+
+/* ip address of target*/
+#define RT_LWIP_IPADDR0 192
+#define RT_LWIP_IPADDR1 168
+#define RT_LWIP_IPADDR2 0
+#define RT_LWIP_IPADDR3 30
+
+/* gateway address of target*/
+#define RT_LWIP_GWADDR0 192
+#define RT_LWIP_GWADDR1 168
+#define RT_LWIP_GWADDR2 0
+#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
+
+/* 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 8
+
+/* 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
+
+#endif
diff --git a/bsp/microblaze/startup.c b/bsp/microblaze/startup.c new file mode 100755 index 0000000000..16a23394bd --- /dev/null +++ b/bsp/microblaze/startup.c @@ -0,0 +1,120 @@ +/* + * 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 + * 2006-08-31 Bernard first implementation + * 2011-12-17 nl1031 for MicroBlaze + */ + +#include <rthw.h> +#include <rtthread.h> + +//#include <AT91SAM7S.h> +#include "board.h"
+ +#ifdef RT_USING_FINSH
+#include <finsh.h>
+extern void finsh_system_init(void);
+#endif
+ +extern void rt_hw_led_flash(void); + + +/*@{*/ +#ifdef __CC_ARM
+extern int Image$$RW_IRAM1$$ZI$$Limit;
+#endif
+
+#ifdef __GNUC__ +extern unsigned char __bss_start; +extern unsigned char __bss_end; +#endif
+ +extern void rt_hw_interrupt_init(void); +extern int rt_application_init(void); +#ifdef RT_USING_DEVICE
+extern rt_err_t rt_hw_serial_init(void);
+#endif
+ +/** + * This function will startup RT-Thread RTOS. + */ +void rtthread_startup(void) +{ + /* init hardware interrupt */ + rt_hw_interrupt_init();
+ + /* init board */ + rt_hw_board_init(); + + rt_show_version(); + + /* init tick */ + rt_system_tick_init(); + + /* init kernel object */ + rt_system_object_init(); + + /* init timer system */ + rt_system_timer_init(); + +#ifdef RT_USING_HEAP
+#ifdef __CC_ARM
+ rt_system_heap_init((void*)&Image$$RW_IRAM1$$ZI$$Limit, (void*)0x204000);
+#elif __ICCARM__
+ rt_system_heap_init(__segment_end("HEAP"), (void*)0x204000);
+#else
+ rt_system_heap_init((void*)&__bss_end, (void*)(&__bss_end+0x4000)); +#endif
+#endif
+ + /* init scheduler system */ + rt_system_scheduler_init(); + +#ifdef RT_USING_HOOK /* if the hook is used */ + /* set idle thread hook */ + rt_thread_idle_sethook(rt_hw_led_flash); +#endif
+ +//#ifdef RT_USING_DEVICE
+ /* init hardware serial device */
+ rt_hw_serial_init();
+ /* init all device */
+ rt_device_init_all();
+//#endif
+ + /* init application */ + rt_application_init(); + +#ifdef RT_USING_FINSH + /* init finsh */ + finsh_system_init(); + finsh_set_device("uart1"); +#endif + + /* init idle thread */ + rt_thread_idle_init(); + + /* start scheduler */ + rt_system_scheduler_start(); + + /* never reach here */ + return ; +}
+ +int main (void)
+{
+ /* invoke rtthread_startup */
+ rtthread_startup();
+
+ return 0;
+}
+ +/*@}*/ |
