diff options
Diffstat (limited to 'bsp')
| -rw-r--r-- | bsp/lpc43xx/M0/applications/application.c | 69 | ||||
| -rw-r--r-- | bsp/lpc43xx/M0/applications/board.c | 2 | ||||
| -rw-r--r-- | bsp/lpc43xx/M0/applications/vbus_conf.h | 13 | ||||
| -rw-r--r-- | bsp/lpc43xx/M0/applications/vbus_drv.c | 57 | ||||
| -rw-r--r-- | bsp/lpc43xx/M0/applications/vbus_hw.h | 53 | ||||
| -rw-r--r-- | bsp/lpc43xx/M0/rtconfig.h | 3 | ||||
| -rw-r--r-- | bsp/lpc43xx/M0/rtthread-lpc43xx.ld | 6 | ||||
| -rw-r--r-- | bsp/lpc43xx/M0/rtthread_lpc43xx.sct | 3 | ||||
| -rw-r--r-- | bsp/lpc43xx/M0/vbus_local_conf.h | 8 | ||||
| -rw-r--r-- | bsp/lpc43xx/M4/applications/application.c | 75 | ||||
| -rw-r--r-- | bsp/lpc43xx/M4/applications/board.c | 1 | ||||
| -rw-r--r-- | bsp/lpc43xx/M4/applications/vbus_conf.h | 13 | ||||
| -rw-r--r-- | bsp/lpc43xx/M4/applications/vbus_drv.c | 57 | ||||
| -rw-r--r-- | bsp/lpc43xx/M4/applications/vbus_hw.h | 53 | ||||
| -rw-r--r-- | bsp/lpc43xx/M4/rtconfig.h | 3 | ||||
| -rw-r--r-- | bsp/lpc43xx/M4/rtthread-lpc43xx.ld | 7 | ||||
| -rw-r--r-- | bsp/lpc43xx/M4/rtthread_lpc43xx.sct | 3 | ||||
| -rw-r--r-- | bsp/lpc43xx/M4/vbus_local_conf.h | 8 |
18 files changed, 391 insertions, 43 deletions
diff --git a/bsp/lpc43xx/M0/applications/application.c b/bsp/lpc43xx/M0/applications/application.c index 209b7071b1..8e861873c8 100644 --- a/bsp/lpc43xx/M0/applications/application.c +++ b/bsp/lpc43xx/M0/applications/application.c @@ -33,38 +33,67 @@ /* thread phase init */ void rt_init_thread_entry(void *parameter) { +#ifdef RT_USING_LOGTRACE + log_trace_init(); + log_trace_set_device(RT_CONSOLE_DEVICE_NAME); +#endif + #ifdef RT_USING_FINSH /* initialize finsh */ finsh_system_init(); finsh_set_device(RT_CONSOLE_DEVICE_NAME); #endif + +#ifdef RT_USING_VBUS + rt_vbus_do_init(); +#endif } + /*the led thread*/ ALIGN(RT_ALIGN_SIZE) -static rt_uint8_t led_stack[ 512 ]; +static rt_uint8_t led_stack[1024]; static struct rt_thread led_thread; static void led_thread_entry(void *parameter) { - rt_uint8_t led_value = 0; rt_device_t led_dev; + rt_device_t vbus_dev; + rt_err_t err; + rt_led_hw_init(); + led_dev = rt_device_find("led"); if (led_dev == RT_NULL) { - rt_kprintf("can not find the led device!\n"); + rt_kprintf("can not find the led device\n"); + return; + } + + vbus_dev = rt_device_find("vecho"); + if (vbus_dev == RT_NULL) + { + rt_kprintf("can not find the vbus device\n"); + return; + } + + err = rt_device_open(vbus_dev, RT_DEVICE_OFLAG_RDWR); + if (err != RT_EOK) + { + rt_kprintf("open vbus failed: %d\n", err); return; } + while (1) { - /* led0 on */ - led_value = 1; - led_dev->write(led_dev, 1, &led_value, 1); - rt_thread_delay(RT_TICK_PER_SECOND / 2); /* sleep 0.5 second and switch to other thread */ + rt_uint8_t led_value; + int len; - /* led0 off */ - led_value = 0; - led_dev->write(led_dev, 1, &led_value, 1); - rt_thread_delay(RT_TICK_PER_SECOND / 2); + len = rt_device_read(vbus_dev, 0, &led_value, sizeof(led_value)); + if (len <= 0) + { + rt_kprintf("vbus read err: %d, %d\n", len, rt_get_errno()); + } + + led_dev->write(led_dev, 1, &led_value, sizeof(led_value)); } } @@ -74,17 +103,15 @@ int rt_application_init(void) rt_err_t result; tid = rt_thread_create("init", rt_init_thread_entry, RT_NULL, - 2048, RT_THREAD_PRIORITY_MAX / 3, 20); - if (tid != RT_NULL) rt_thread_startup(tid); + 2048, 3, 20); + if (tid != RT_NULL) + rt_thread_startup(tid); + /* init led thread */ - result = rt_thread_init(&led_thread, - "led", - led_thread_entry, - RT_NULL, - (rt_uint8_t *)&led_stack[0], - sizeof(led_stack), - 20, - 5); + result = rt_thread_init(&led_thread, "led", + led_thread_entry, RT_NULL, + (rt_uint8_t *)&led_stack[0], sizeof(led_stack), + 20, 5); if (result == RT_EOK) { rt_thread_startup(&led_thread); diff --git a/bsp/lpc43xx/M0/applications/board.c b/bsp/lpc43xx/M0/applications/board.c index c3377aac2a..324e1bc7ae 100644 --- a/bsp/lpc43xx/M0/applications/board.c +++ b/bsp/lpc43xx/M0/applications/board.c @@ -62,5 +62,7 @@ void rt_hw_board_init() /* setup the console device */ rt_console_set_device(RT_CONSOLE_DEVICE_NAME); + + rt_kprintf("timer compval: %d\n", LPC_RITIMER->COMPVAL); } diff --git a/bsp/lpc43xx/M0/applications/vbus_conf.h b/bsp/lpc43xx/M0/applications/vbus_conf.h new file mode 100644 index 0000000000..62bec83227 --- /dev/null +++ b/bsp/lpc43xx/M0/applications/vbus_conf.h @@ -0,0 +1,13 @@ +#ifndef __VBUS_CONF_H__ +#define __VBUS_CONF_H__ + +/* Number of blocks in VBus. The total size of VBus is + * RT_VMM_RB_BLK_NR * 64byte * 2. */ +#define RT_VMM_RB_BLK_NR 20 + +/* We don't use the IRQ number to trigger IRQ in this BSP. */ +#define RT_VBUS_GUEST_VIRQ 0 +#define RT_VBUS_HOST_VIRQ 0 + +#endif /* end of include guard: __VBUS_CONF_H__ */ + diff --git a/bsp/lpc43xx/M0/applications/vbus_drv.c b/bsp/lpc43xx/M0/applications/vbus_drv.c new file mode 100644 index 0000000000..ad9c8f9210 --- /dev/null +++ b/bsp/lpc43xx/M0/applications/vbus_drv.c @@ -0,0 +1,57 @@ +#include <rtthread.h> + +#ifdef RT_USING_VBUS +#include <rtdevice.h> +#include <vbus.h> +#include <board.h> + +struct rt_vbus_ring rt_vbus_rings[2] SECTION("vbus_ring"); + +int rt_vbus_do_init(void) +{ + return rt_vbus_init(&rt_vbus_rings[1], &rt_vbus_rings[0]); +} +INIT_COMPONENT_EXPORT(rt_vbus_do_init); + +int rt_vbus_hw_init(void) +{ + NVIC_ClearPendingIRQ(M0_M4CORE_IRQn); + NVIC_EnableIRQ(M0_M4CORE_IRQn); + return 0; +} + +void M4CORE_IRQHandler(void) +{ + LPC_CREG->M4TXEVENT = 0; + rt_vbus_isr(M0_M4CORE_IRQn, RT_NULL); +} + +int rt_vbus_hw_eoi(int irqnr, void *param) +{ + /* Nothing to do here as we cleared the interrupt in IRQHandler. */ + return 0; +} + +struct rt_vbus_dev rt_vbus_chn_devx[] = { + { + .req = + { + .prio = 30, + .name = "vecho", + .is_server = 0, + .recv_wm.low = RT_VMM_RB_BLK_NR / 3, + .recv_wm.high = RT_VMM_RB_BLK_NR * 2 / 3, + .post_wm.low = RT_VMM_RB_BLK_NR / 3, + .post_wm.high = RT_VMM_RB_BLK_NR * 2 / 3, + } + }, + { + .req = + { + .name = RT_NULL, + } + }, +}; + +#endif /* RT_USING_VBUS */ + diff --git a/bsp/lpc43xx/M0/applications/vbus_hw.h b/bsp/lpc43xx/M0/applications/vbus_hw.h new file mode 100644 index 0000000000..758d2e9e5c --- /dev/null +++ b/bsp/lpc43xx/M0/applications/vbus_hw.h @@ -0,0 +1,53 @@ +/* + * VMM Bus + * + * COPYRIGHT (C) 2014, Shanghai Real-Thread Technology Co., Ltd + * + * This file is part of RT-Thread (http://www.rt-thread.org) + * + * All rights reserved. + * + * 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. + * + * Change Logs: + * Date Author Notes + * 2014-04-15 Grissiom init commit + */ + +#include <rtthread.h> +#include <board.h> + +rt_inline void rt_vbus_tick(unsigned int target_cpu, unsigned int irqnr) +{ + __SEV(); +} + +/* Read memory barrier. */ +rt_inline void rt_vbus_smp_rmb(void) +{ + __DMB(); +} + +/* Write memory barrier. */ +rt_inline void rt_vbus_smp_wmb(void) +{ + __DSB(); +} + +/* General memory barrier. */ +rt_inline void rt_vbus_smp_mb(void) +{ + __DSB(); +} diff --git a/bsp/lpc43xx/M0/rtconfig.h b/bsp/lpc43xx/M0/rtconfig.h index a1ac5509ab..77846191fc 100644 --- a/bsp/lpc43xx/M0/rtconfig.h +++ b/bsp/lpc43xx/M0/rtconfig.h @@ -224,7 +224,8 @@ #define RT_LWIP_MSKADDR3 0 // </section> - +#define RT_USING_VBUS +#define RT_USING_LOGTRACE // </RDTConfigurator> diff --git a/bsp/lpc43xx/M0/rtthread-lpc43xx.ld b/bsp/lpc43xx/M0/rtthread-lpc43xx.ld index 3419e6f235..e8ef2fe490 100644 --- a/bsp/lpc43xx/M0/rtthread-lpc43xx.ld +++ b/bsp/lpc43xx/M0/rtthread-lpc43xx.ld @@ -8,6 +8,7 @@ MEMORY { CODE (rx) : ORIGIN = 0x1B000000, LENGTH = 0x00080000 DATA (rw) : ORIGIN = 0x10080000, LENGTH = 0x00008000 + AHBRAM (rw) : ORIGIN = 0x20000000, LENGTH = 0x00010000 } ENTRY(Reset_Handler) _system_stack_size = 0x200; @@ -95,6 +96,11 @@ SECTIONS } > DATA __bss_end = .; + .vbus_ring (NOLOAD) : + { + *(vbus_ring) + } > AHBRAM + _end = .; /* Stabs debugging sections. */ diff --git a/bsp/lpc43xx/M0/rtthread_lpc43xx.sct b/bsp/lpc43xx/M0/rtthread_lpc43xx.sct index 2232a4aa9b..d0fd443a85 100644 --- a/bsp/lpc43xx/M0/rtthread_lpc43xx.sct +++ b/bsp/lpc43xx/M0/rtthread_lpc43xx.sct @@ -11,5 +11,8 @@ LR_IROM2 0x1B000000 0x00080000 { ; load region size_region RW_IRAM2 0x10080000 0x00008000 { ; RW data
.ANY (+RW +ZI)
}
+ RW_AHBRAM 0x20000000 0x00010000 { ; RW data
+ * (vbus_ring)
+ }
}
diff --git a/bsp/lpc43xx/M0/vbus_local_conf.h b/bsp/lpc43xx/M0/vbus_local_conf.h new file mode 100644 index 0000000000..571c51e612 --- /dev/null +++ b/bsp/lpc43xx/M0/vbus_local_conf.h @@ -0,0 +1,8 @@ +#ifndef __VBUS_LOCAL_CONF_H__ +#define __VBUS_LOCAL_CONF_H__ + +#define RT_VBUS_USING_FLOW_CONTROL + +#define RT_VBUS_USING_TESTS + +#endif /* end of include guard: __VBUS_LOCAL_CONF_H__ */ diff --git a/bsp/lpc43xx/M4/applications/application.c b/bsp/lpc43xx/M4/applications/application.c index 8ca6f823f1..6575991895 100644 --- a/bsp/lpc43xx/M4/applications/application.c +++ b/bsp/lpc43xx/M4/applications/application.c @@ -58,12 +58,26 @@ static void _boot_M0(void) /* thread phase init */ void rt_init_thread_entry(void *parameter) { + /* + *register unsigned int _msp __asm("msp"); + *register unsigned int _psp __asm("psp"); + *rt_kprintf("msp@ %p, psp@ %p\n", _msp, _psp); + */ +#ifdef RT_USING_LOGTRACE + log_trace_init(); + log_trace_set_device(RT_CONSOLE_DEVICE_NAME); +#endif + #ifdef RT_USING_FINSH /* initialize finsh */ finsh_system_init(); finsh_set_device(RT_CONSOLE_DEVICE_NAME); #endif +#ifdef RT_USING_VBUS + rt_vbus_do_init(); +#endif + _boot_M0(); } @@ -73,26 +87,49 @@ static rt_uint8_t led_stack[ 512 ]; static struct rt_thread led_thread; static void led_thread_entry(void *parameter) { - rt_uint8_t led_value = 0; + rt_uint8_t led_value; rt_device_t led_dev; + rt_device_t vbus_dev; + rt_err_t err; + rt_led_hw_init(); + led_dev = rt_device_find("led"); if (led_dev == RT_NULL) { - rt_kprintf("can not find the led device!\n"); + rt_kprintf("can not find the led device\n"); + return; + } + + vbus_dev = rt_device_find("vecho"); + if (vbus_dev == RT_NULL) + { + rt_kprintf("can not find the vbus device\n"); + return; + } + + err = rt_device_open(vbus_dev, RT_DEVICE_OFLAG_RDWR); + if (err != RT_EOK) + { + rt_kprintf("open vbus failed: %d\n", err); return; } + + led_value = 0; while (1) { - /* led0 on */ - led_value = 1; - led_dev->write(led_dev, 0, &led_value, 1); - rt_thread_delay(RT_TICK_PER_SECOND / 2); /* sleep 0.5 second and switch to other thread */ + int len; + + led_dev->write(led_dev, 0, &led_value, sizeof(led_value)); - /* led0 off */ - led_value = 0; - led_dev->write(led_dev, 0, &led_value, 1); - rt_thread_delay(RT_TICK_PER_SECOND / 2); + led_value = !led_value; + len = rt_device_write(vbus_dev, 0, &led_value, sizeof(led_value)); + if (len <= 0) + { + rt_kprintf("vbus write err: %d, %d\n", len, rt_get_errno()); + } + + rt_thread_delay(1000); } } @@ -102,17 +139,15 @@ int rt_application_init(void) rt_err_t result; tid = rt_thread_create("init", rt_init_thread_entry, RT_NULL, - 2048, RT_THREAD_PRIORITY_MAX / 3, 20); - if (tid != RT_NULL) rt_thread_startup(tid); + 2048, 3, 20); + if (tid != RT_NULL) + rt_thread_startup(tid); + /* init led thread */ - result = rt_thread_init(&led_thread, - "led", - led_thread_entry, - RT_NULL, - (rt_uint8_t *)&led_stack[0], - sizeof(led_stack), - 20, - 5); + result = rt_thread_init(&led_thread, "led", + led_thread_entry, RT_NULL, + (rt_uint8_t *)&led_stack[0], sizeof(led_stack), + 20, 5); if (result == RT_EOK) { rt_thread_startup(&led_thread); diff --git a/bsp/lpc43xx/M4/applications/board.c b/bsp/lpc43xx/M4/applications/board.c index b7d3ead87e..3358e52c96 100644 --- a/bsp/lpc43xx/M4/applications/board.c +++ b/bsp/lpc43xx/M4/applications/board.c @@ -65,6 +65,7 @@ void rt_hw_board_init() /* setup the console device */ rt_console_set_device(RT_CONSOLE_DEVICE_NAME); + rt_kprintf("timer compval: %d\n", SystemCoreClock / RT_TICK_PER_SECOND - 1); #if LPC_EXT_SDRAM == 1 lpc_sdram_hw_init(); diff --git a/bsp/lpc43xx/M4/applications/vbus_conf.h b/bsp/lpc43xx/M4/applications/vbus_conf.h new file mode 100644 index 0000000000..62bec83227 --- /dev/null +++ b/bsp/lpc43xx/M4/applications/vbus_conf.h @@ -0,0 +1,13 @@ +#ifndef __VBUS_CONF_H__ +#define __VBUS_CONF_H__ + +/* Number of blocks in VBus. The total size of VBus is + * RT_VMM_RB_BLK_NR * 64byte * 2. */ +#define RT_VMM_RB_BLK_NR 20 + +/* We don't use the IRQ number to trigger IRQ in this BSP. */ +#define RT_VBUS_GUEST_VIRQ 0 +#define RT_VBUS_HOST_VIRQ 0 + +#endif /* end of include guard: __VBUS_CONF_H__ */ + diff --git a/bsp/lpc43xx/M4/applications/vbus_drv.c b/bsp/lpc43xx/M4/applications/vbus_drv.c new file mode 100644 index 0000000000..6d85a2e11e --- /dev/null +++ b/bsp/lpc43xx/M4/applications/vbus_drv.c @@ -0,0 +1,57 @@ +#include <rtthread.h> + +#ifdef RT_USING_VBUS +#include <rtdevice.h> +#include <vbus.h> +#include <board.h> + +struct rt_vbus_ring rt_vbus_rings[2] SECTION("vbus_ring"); + +int rt_vbus_do_init(void) +{ + return rt_vbus_init(&rt_vbus_rings[0], &rt_vbus_rings[1]); +} +INIT_COMPONENT_EXPORT(rt_vbus_do_init); + +int rt_vbus_hw_init(void) +{ + NVIC_ClearPendingIRQ(M0CORE_IRQn); + NVIC_EnableIRQ(M0CORE_IRQn); + return 0; +} + +void M0CORE_IRQHandler(void) +{ + LPC_CREG->M0TXEVENT = 0; + rt_vbus_isr(M0CORE_IRQn, RT_NULL); +} + +int rt_vbus_hw_eoi(int irqnr, void *param) +{ + /* Nothing to do here as we cleared the interrupt in IRQHandler. */ + return 0; +} + +struct rt_vbus_dev rt_vbus_chn_devx[] = { + { + .req = + { + .prio = 30, + .name = "vecho", + .is_server = 1, + .recv_wm.low = RT_VMM_RB_BLK_NR / 3, + .recv_wm.high = RT_VMM_RB_BLK_NR * 2 / 3, + .post_wm.low = RT_VMM_RB_BLK_NR / 3, + .post_wm.high = RT_VMM_RB_BLK_NR * 2 / 3, + } + }, + { + .req = + { + .name = RT_NULL, + } + }, +}; + +#endif /* RT_USING_VBUS */ + diff --git a/bsp/lpc43xx/M4/applications/vbus_hw.h b/bsp/lpc43xx/M4/applications/vbus_hw.h new file mode 100644 index 0000000000..758d2e9e5c --- /dev/null +++ b/bsp/lpc43xx/M4/applications/vbus_hw.h @@ -0,0 +1,53 @@ +/* + * VMM Bus + * + * COPYRIGHT (C) 2014, Shanghai Real-Thread Technology Co., Ltd + * + * This file is part of RT-Thread (http://www.rt-thread.org) + * + * All rights reserved. + * + * 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. + * + * Change Logs: + * Date Author Notes + * 2014-04-15 Grissiom init commit + */ + +#include <rtthread.h> +#include <board.h> + +rt_inline void rt_vbus_tick(unsigned int target_cpu, unsigned int irqnr) +{ + __SEV(); +} + +/* Read memory barrier. */ +rt_inline void rt_vbus_smp_rmb(void) +{ + __DMB(); +} + +/* Write memory barrier. */ +rt_inline void rt_vbus_smp_wmb(void) +{ + __DSB(); +} + +/* General memory barrier. */ +rt_inline void rt_vbus_smp_mb(void) +{ + __DSB(); +} diff --git a/bsp/lpc43xx/M4/rtconfig.h b/bsp/lpc43xx/M4/rtconfig.h index fb65f5bf3d..31854ca2fc 100644 --- a/bsp/lpc43xx/M4/rtconfig.h +++ b/bsp/lpc43xx/M4/rtconfig.h @@ -223,7 +223,8 @@ #define RT_LWIP_MSKADDR3 0 // </section> - +#define RT_USING_VBUS +#define RT_USING_LOGTRACE // </RDTConfigurator> diff --git a/bsp/lpc43xx/M4/rtthread-lpc43xx.ld b/bsp/lpc43xx/M4/rtthread-lpc43xx.ld index 81d1655b52..63057abc40 100644 --- a/bsp/lpc43xx/M4/rtthread-lpc43xx.ld +++ b/bsp/lpc43xx/M4/rtthread-lpc43xx.ld @@ -9,6 +9,7 @@ MEMORY CODE (rx) : ORIGIN = 0x1A000000, LENGTH = 0x00080000 M0CODE (rx) : ORIGIN = 0x1B000000, LENGTH = 0x00080000 DATA (rw) : ORIGIN = 0x10000000, LENGTH = 0x00008000 + AHBRAM (rw) : ORIGIN = 0x20000000, LENGTH = 0x00010000 } ENTRY(Reset_Handler) _system_stack_size = 0x200; @@ -97,6 +98,12 @@ SECTIONS } > DATA __bss_end = .; + .vbus_ring (NOLOAD) : + { + *(vbus_ring) + } > AHBRAM + + .text.M0CODE : { *(M0_CODE) diff --git a/bsp/lpc43xx/M4/rtthread_lpc43xx.sct b/bsp/lpc43xx/M4/rtthread_lpc43xx.sct index c483ea87d2..238ca28c6e 100644 --- a/bsp/lpc43xx/M4/rtthread_lpc43xx.sct +++ b/bsp/lpc43xx/M4/rtthread_lpc43xx.sct @@ -11,6 +11,9 @@ LR_IROM1 0x1A000000 0x00080000 { ; load region size_region RW_IRAM1 0x10000000 0x00008000 { ; RW data
.ANY (+RW +ZI)
}
+ RW_AHBRAM 0x20000000 0x00010000 { ; RW data
+ * (vbus_ring)
+ }
}
LR_IROM2 0x1B000000 0x00080000 {
diff --git a/bsp/lpc43xx/M4/vbus_local_conf.h b/bsp/lpc43xx/M4/vbus_local_conf.h new file mode 100644 index 0000000000..571c51e612 --- /dev/null +++ b/bsp/lpc43xx/M4/vbus_local_conf.h @@ -0,0 +1,8 @@ +#ifndef __VBUS_LOCAL_CONF_H__ +#define __VBUS_LOCAL_CONF_H__ + +#define RT_VBUS_USING_FLOW_CONTROL + +#define RT_VBUS_USING_TESTS + +#endif /* end of include guard: __VBUS_LOCAL_CONF_H__ */ |
