From aae51e985f3518652b4eddcf3713510436dc3b2c Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 17 Jan 2013 01:09:58 +0700 Subject: [PATCH] refractor board and start to add support for SWO retarget --- demos/bsp/boards/board.h | 39 ++++++++----- demos/bsp/boards/board_at86rf2xx.c | 17 ++---- demos/bsp/boards/board_at86rf2xx.h | 77 +++++++++++++++++++++++++ demos/bsp/boards/board_lpcxpresso1347.c | 17 ++---- demos/bsp/boards/board_lpcxpresso1347.h | 75 ++++++++++++++++++++++++ demos/bsp/boards/board_ngx4330.c | 9 ++- demos/bsp/boards/printf_retarget.c | 2 +- demos/device/keyboard/.cproject | 2 +- 8 files changed, 192 insertions(+), 46 deletions(-) create mode 100644 demos/bsp/boards/board_at86rf2xx.h create mode 100644 demos/bsp/boards/board_lpcxpresso1347.h diff --git a/demos/bsp/boards/board.h b/demos/bsp/boards/board.h index b5fd17db..ea5e0aaa 100644 --- a/demos/bsp/boards/board.h +++ b/demos/bsp/boards/board.h @@ -57,31 +57,38 @@ #include -#define BSP_TICKS_PER_SECOND 1000 -#define BSP_UART_ENABLE 1 -#define BSP_UART_BAUDRATE 115200 +#define BOARD_AT86RF2XX 0 +#define BOARD_LPCXPRESSO1347 1 +#define BOARD_NGX4330 2 - -/// n-th Bit -#ifndef BIT_ -#define BIT_(n) (1 << (n)) -#endif - -#define BOARD_AT86RF2XX 0 -#define BOARD_LPCXPRESSO1347 1 -#define BOARD_NGX4330 2 +#define PRINTF_TARGET_DEBUG_CONSOLE 0 // IDE semihosting console +#define PRINTF_TARGET_UART 1 +#define PRINTF_TARGET_SWO 2 // aka SWV, ITM #if BOARD == BOARD_NGX4330 - + #include "board_ngx4330.h" #elif BOARD == BOARD_LPCXPRESSO1347 - + #include "board_lpcxpresso1347.h" #elif BOARD == BOARD_AT86RF2XX - + #include "board_at86rf2xx.h" #else #error BOARD is not defined or supported yet #endif -/// Init board peripherals : Clock, UART, LEDs, Buttons +//--------------------------------------------------------------------+ +// Common Configuration +//--------------------------------------------------------------------+ +#define CFG_TICKS_PER_SECOND 1000 + +#if CFG_PRINTF_TARGET == PRINTF_TARGET_UART + #define CFG_UART_ENABLE 1 + #define CFG_UART_BAUDRATE 115200 +#endif + +//--------------------------------------------------------------------+ +// Board Common API +//--------------------------------------------------------------------+ +// Init board peripherals : Clock, UART, LEDs, Buttons void board_init(void); void board_leds(uint32_t mask, uint32_t state); uint32_t board_uart_send(uint8_t *buffer, uint32_t length); diff --git a/demos/bsp/boards/board_at86rf2xx.c b/demos/bsp/boards/board_at86rf2xx.c index 310f16c1..476efdce 100644 --- a/demos/bsp/boards/board_at86rf2xx.c +++ b/demos/bsp/boards/board_at86rf2xx.c @@ -39,26 +39,17 @@ #if BOARD == BOARD_AT86RF2XX -#include "LPC11Uxx.h" -#include "lpc11uxx/gpio.h" -#include "lpc11uxx/uart.h" - -#define CFG_LED_PORT (1) -#define CFG_LED_PIN (31) -#define CFG_LED_ON (0) -#define CFG_LED_OFF (1) - void board_init(void) { SystemInit(); - SysTick_Config(SystemCoreClock / BSP_TICKS_PER_SECOND); // 1 msec tick timer + SysTick_Config(SystemCoreClock / CFG_TICKS_PER_SECOND); // 1 msec tick timer GPIOInit(); GPIOSetDir(CFG_LED_PORT, CFG_LED_PIN, 1); board_leds(0x01, 0); // turn off the led first -#if BSP_UART_ENABLE - UARTInit(BSP_UART_BAUDRATE); +#if CFG_UART_ENABLE + UARTInit(CFG_UART_BAUDRATE); #endif } @@ -74,7 +65,7 @@ void board_leds(uint32_t mask, uint32_t state) //--------------------------------------------------------------------+ // UART //--------------------------------------------------------------------+ -#if BSP_UART_ENABLE +#if CFG_UART_ENABLE uint32_t board_uart_send(uint8_t *buffer, uint32_t length) { UARTSend(buffer, length); diff --git a/demos/bsp/boards/board_at86rf2xx.h b/demos/bsp/boards/board_at86rf2xx.h new file mode 100644 index 00000000..49fab2ea --- /dev/null +++ b/demos/bsp/boards/board_at86rf2xx.h @@ -0,0 +1,77 @@ +/* + * board_at86rf2xx.h + * + * Created on: Jan 17, 2013 + * Author: hathach + */ + +/* + * Software License Agreement (BSD License) + * Copyright (c) 2012, hathach (tinyusb.net) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the tiny usb stack. + */ + +/** \file + * \brief TBD + * + * \note TBD + */ + +/** \ingroup TBD + * \defgroup TBD + * \brief TBD + * + * @{ + */ + +#ifndef _TUSB_BOARD_AT86RF2XX_H_ +#define _TUSB_BOARD_AT86RF2XX_H_ + +#ifdef __cplusplus + extern "C" { +#endif + +#include "LPC11Uxx.h" +#include "lpc11uxx/gpio.h" +#include "lpc11uxx/uart.h" + +#define CFG_PRINTF_TARGET PRINTF_TARGET_UART + +#define CFG_LED_PORT (1) +#define CFG_LED_PIN (31) +#define CFG_LED_ON (0) +#define CFG_LED_OFF (1) + +#define CFG_PRINTF_TARGET PRINTF_TARGET_UART + +#ifdef __cplusplus + } +#endif + +#endif /* _TUSB_BOARD_AT86RF2XX_H_ */ + +/** @} */ diff --git a/demos/bsp/boards/board_lpcxpresso1347.c b/demos/bsp/boards/board_lpcxpresso1347.c index c4565765..93131357 100644 --- a/demos/bsp/boards/board_lpcxpresso1347.c +++ b/demos/bsp/boards/board_lpcxpresso1347.c @@ -39,27 +39,18 @@ #if BOARD == BOARD_LPCXPRESSO1347 -#include "LPC13Uxx.h" -#include "lpc13uxx/gpio.h" -#include "lpc13uxx/uart.h" - -#define CFG_LED_PORT (0) -#define CFG_LED_PIN (7) -#define CFG_LED_ON (1) -#define CFG_LED_OFF (0) - void board_init(void) { SystemInit(); - SysTick_Config(SystemCoreClock / BSP_TICKS_PER_SECOND); // 1 msec tick timer + SysTick_Config(SystemCoreClock / CFG_TICKS_PER_SECOND); // 1 msec tick timer GPIOInit(); // Leds Init GPIOSetDir(CFG_LED_PORT, CFG_LED_PIN, 1); LPC_GPIO->CLR[CFG_LED_PORT] = (1 << CFG_LED_PIN); -#if BSP_UART_ENABLE - UARTInit(BSP_UART_BAUDRATE); +#if CFG_UART_ENABLE + UARTInit(CFG_UART_BAUDRATE); #endif } @@ -77,7 +68,7 @@ void board_leds(uint32_t mask, uint32_t state) //--------------------------------------------------------------------+ // UART //--------------------------------------------------------------------+ -#if BSP_UART_ENABLE +#if CFG_UART_ENABLE uint32_t board_uart_send(uint8_t *buffer, uint32_t length) { UARTSend(buffer, length); diff --git a/demos/bsp/boards/board_lpcxpresso1347.h b/demos/bsp/boards/board_lpcxpresso1347.h new file mode 100644 index 00000000..f9a9aa76 --- /dev/null +++ b/demos/bsp/boards/board_lpcxpresso1347.h @@ -0,0 +1,75 @@ +/* + * board_lpcxpresso1347.h + * + * Created on: Jan 17, 2013 + * Author: hathach + */ + +/* + * Software License Agreement (BSD License) + * Copyright (c) 2012, hathach (tinyusb.net) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the tiny usb stack. + */ + +/** \file + * \brief TBD + * + * \note TBD + */ + +/** \ingroup TBD + * \defgroup TBD + * \brief TBD + * + * @{ + */ + +#ifndef _TUSB_BOARD_LPCXPRESSO1347_H_ +#define _TUSB_BOARD_LPCXPRESSO1347_H_ + +#ifdef __cplusplus + extern "C" { +#endif + +#include "LPC13Uxx.h" +#include "lpc13uxx/gpio.h" +#include "lpc13uxx/uart.h" + +#define CFG_LED_PORT (0) +#define CFG_LED_PIN (7) +#define CFG_LED_ON (1) +#define CFG_LED_OFF (0) + +#define CFG_PRINTF_TARGET PRINTF_TARGET_UART + +#ifdef __cplusplus + } +#endif + +#endif /* _TUSB_BOARD_LPCXPRESSO1347_H_ */ + +/** @} */ diff --git a/demos/bsp/boards/board_ngx4330.c b/demos/bsp/boards/board_ngx4330.c index f8d90eb2..f4efef99 100644 --- a/demos/bsp/boards/board_ngx4330.c +++ b/demos/bsp/boards/board_ngx4330.c @@ -49,6 +49,11 @@ #include "lpc43xx_i2s.h" #include "lpc43xx_emc.h" +// TODO abstract later: n-th Bit +#ifndef BIT_ +#define BIT_(n) (1 << (n)) +#endif + #define BOARD_MAX_LEDS 2 const static struct { uint8_t port; @@ -58,7 +63,7 @@ const static struct { void board_init(void) { CGU_Init(); - SysTick_Config( CGU_GetPCLKFrequency(CGU_PERIPHERAL_M4CORE)/BSP_TICKS_PER_SECOND ); /* 1 ms Timer */ + SysTick_Config( CGU_GetPCLKFrequency(CGU_PERIPHERAL_M4CORE)/CFG_TICKS_PER_SECOND ); /* 1 ms Timer */ // USB Pin init /* Turn on 5V USB VBUS TODO Should be Host-only */ @@ -83,7 +88,7 @@ void board_init(void) scu_pinmux(0x6 ,5, MD_PDN|MD_EZI, FUNC2); // UART0_RXD UART_ConfigStructInit(&UARTConfigStruct); // default: baud = 9600, 8 bit data, 1 stop bit, no parity - UARTConfigStruct.Baud_rate = BSP_UART_BAUDRATE; // Re-configure baudrate + UARTConfigStruct.Baud_rate = CFG_UART_BAUDRATE; // Re-configure baudrate UART_Init((LPC_USARTn_Type*) LPC_USART0, &UARTConfigStruct); // Initialize UART port UART_TxCmd((LPC_USARTn_Type*) LPC_USART0, ENABLE); // Enable UART diff --git a/demos/bsp/boards/printf_retarget.c b/demos/bsp/boards/printf_retarget.c index f53da4d1..cafc74b5 100644 --- a/demos/bsp/boards/printf_retarget.c +++ b/demos/bsp/boards/printf_retarget.c @@ -40,7 +40,7 @@ //-------------------------------------------------------------------- + // LPCXpresso printf redirection + //-------------------------------------------------------------------- + -#if BSP_UART_ENABLE +#if CFG_PRINTF_TARGET != PRINTF_TARGET_DEBUG_CONSOLE // Called by bottom level of printf routine within RedLib C library to write // a character. With the default semihosting stub, this would write the character // to the debugger console window . But this version writes diff --git a/demos/device/keyboard/.cproject b/demos/device/keyboard/.cproject index 2d74a477..b8689bdc 100644 --- a/demos/device/keyboard/.cproject +++ b/demos/device/keyboard/.cproject @@ -27,7 +27,7 @@ - +