diff --git a/bsp/mini2440/SConstruct b/bsp/mini2440/SConstruct index da6b4e589f..97161e70fe 100644 --- a/bsp/mini2440/SConstruct +++ b/bsp/mini2440/SConstruct @@ -35,7 +35,7 @@ if rtconfig.RT_USING_DFS: if rtconfig.RT_USING_LWIP: objs = objs + SConscript(RTT_ROOT + '/net/lwip/SConscript', variant_dir='build/net/lwip', duplicate=0) -src_bsp = ['application.c', 'startup.c', 'board.c'] +src_bsp = ['application.c', 'startup.c', 'board.c','led.c'] src_drv = ['console.c'] if rtconfig.RT_USING_DFS: diff --git a/bsp/mini2440/application.c b/bsp/mini2440/application.c index 24c62ac67b..2695e75cb4 100644 --- a/bsp/mini2440/application.c +++ b/bsp/mini2440/application.c @@ -20,6 +20,7 @@ #include #include +#include "led.h" #ifdef RT_USING_DFS /* dfs init */ @@ -87,23 +88,50 @@ void rt_init_thread_entry(void* parameter) #endif } +void rt_led_thread_entry(void* parameter) +{ + while(1) + { + /* led on 1s */ + rt_hw_led_on(LED2|LED3); + rt_thread_delay(100); + + /* led off 1s */ + rt_hw_led_off(LED2|LED3); + rt_thread_delay(100); + + } +} + int rt_application_init() { rt_thread_t init_thread; + rt_thread_t led_thread; #if (RT_THREAD_PRIORITY_MAX == 32) init_thread = rt_thread_create("init", rt_init_thread_entry, RT_NULL, 2048, 8, 20); + + led_thread = rt_thread_create("led", + rt_led_thread_entry, RT_NULL, + 512, 20, 20); #else init_thread = rt_thread_create("init", rt_init_thread_entry, RT_NULL, 2048, 80, 20); + + led_thread = rt_thread_create("led", + rt_led_thread_entry, RT_NULL, + 512, 200, 20); #endif if (init_thread != RT_NULL) rt_thread_startup(init_thread); + if(led_thread != RT_NULL) + rt_thread_startup(led_thread); + return 0; } diff --git a/bsp/mini2440/board.c b/bsp/mini2440/board.c index 7b6a1d862c..cba3915356 100644 --- a/bsp/mini2440/board.c +++ b/bsp/mini2440/board.c @@ -19,6 +19,7 @@ #include #include "board.h" +#include "led.h" /** * @addtogroup mini2440 @@ -41,7 +42,6 @@ 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); -static rt_uint32_t timer_load_val = 0; #define UART0 ((struct uartport *)U0BASE) struct serial_int_rx uart0_int_rx; @@ -58,9 +58,6 @@ struct rt_device uart0_device; */ void rt_timer_handler(int vector) { - /* reset TDATA0 */ - TCNTB4 = timer_load_val; - rt_tick_increase(); } @@ -115,6 +112,29 @@ void rt_hw_uart_init(void) rt_hw_interrupt_umask(INTUART0); } +/** + * This function will init timer4 for system ticks + */ + void rt_hw_timer_init() + { + /* timer4, pre = 15+1 */ + TCFG0 &= 0xffff00ff; + TCFG0 |= 15 << 8; + /* all are interrupt mode,set Timer 4 MUX 1/4 */ + TCFG1 &= 0xfff0ffff; + TCFG1 |= 0x00010000; + + TCNTB4 = (rt_int32_t)(PCLK / (4 *16* RT_TICK_PER_SECOND)) - 1; + /* manual update */ + TCON = TCON & (~(0x0f<<20)) | (0x02<<20); + /* install interrupt handler */ + rt_hw_interrupt_install(INTTIMER4, rt_timer_handler, RT_NULL); + rt_hw_interrupt_umask(INTTIMER4); + + /* start timer4, reload */ + TCON = TCON & (~(0x0f<<20)) | (0x05<<20); + } + /** * This function will init s3ceb2410 board */ @@ -126,6 +146,9 @@ void rt_hw_board_init() /* Get the clock */ rt_hw_get_clock(); + /* initialize led port */ + rt_hw_led_init(); + /* initialize uart */ rt_hw_uart_init(); @@ -139,12 +162,8 @@ void rt_hw_board_init() rt_hw_touch_init(); #endif - /* install interrupt handler */ - rt_hw_interrupt_install(INTTIMER4, rt_timer_handler, RT_NULL); - rt_hw_interrupt_umask(INTTIMER4); - - /* stop timer */ - /* TCON = 0x0; */ + /* initialize timer4 */ + rt_hw_timer_init(); } /*@}*/ diff --git a/bsp/mini2440/led.c b/bsp/mini2440/led.c new file mode 100644 index 0000000000..246c1cf307 --- /dev/null +++ b/bsp/mini2440/led.c @@ -0,0 +1,35 @@ +/* + * 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://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2009-12-27 rdghx mini2440 + */ + +#include +#include "led.h" + +void rt_hw_led_init(void) +{ + /* GPB5,GPB6,GPB7,GPB8 for LED */ + GPBCON = GPBCON & (~(0xff << 10)) | (0x55 << 10); + GPBUP |= (0x0f << 5); +} + +void rt_hw_led_on(unsigned char value) +{ + GPBDAT &= ~ ((value & 0x0f) << 5); +} + +void rt_hw_led_off(unsigned char value) +{ + GPBDAT |= (value & 0x0f) << 5; +} + + diff --git a/bsp/mini2440/led.h b/bsp/mini2440/led.h new file mode 100644 index 0000000000..874353ebc3 --- /dev/null +++ b/bsp/mini2440/led.h @@ -0,0 +1,28 @@ +/* + * File : led.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 + * 2009-12-27 rdghx mini2440 + */ + +#ifndef __LED_H__ +#define __LED_H__ + +#define LED1 0x01 +#define LED2 0x02 +#define LED3 0x04 +#define LED4 0x08 +#define LED_ALL 0x0f + +void rt_hw_led_init(void); +void rt_hw_led_on(unsigned char value); +void rt_hw_led_off(unsigned char value); + +#endif