summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2013-01-17 01:09:58 +0700
committerhathach <[email protected]>2013-01-17 01:09:58 +0700
commitaae51e985f3518652b4eddcf3713510436dc3b2c (patch)
tree436050d612c519e08daadbd10f4b918515609c79
parent53739ccd28478144ce9cde9d16410175a79a518d (diff)
refractor board and start to add support for SWO retarget
-rw-r--r--demos/bsp/boards/board.h39
-rw-r--r--demos/bsp/boards/board_at86rf2xx.c17
-rw-r--r--demos/bsp/boards/board_at86rf2xx.h77
-rw-r--r--demos/bsp/boards/board_lpcxpresso1347.c17
-rw-r--r--demos/bsp/boards/board_lpcxpresso1347.h75
-rw-r--r--demos/bsp/boards/board_ngx4330.c9
-rw-r--r--demos/bsp/boards/printf_retarget.c2
-rw-r--r--demos/device/keyboard/.cproject2
8 files changed, 192 insertions, 46 deletions
diff --git a/demos/bsp/boards/board.h b/demos/bsp/boards/board.h
index b5fd17dbe..ea5e0aaa6 100644
--- a/demos/bsp/boards/board.h
+++ b/demos/bsp/boards/board.h
@@ -57,31 +57,38 @@
#include <stdint.h>
-#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 310f16c13..476efdce7 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 000000000..49fab2ead
--- /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 c4565765e..931313575 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 000000000..f9a9aa768
--- /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 f8d90eb20..f4efef99c 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 f53da4d1f..cafc74b58 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 2d74a4777..b8689bdc9 100644
--- a/demos/device/keyboard/.cproject
+++ b/demos/device/keyboard/.cproject
@@ -27,7 +27,7 @@
<folderInfo id="com.crt.advproject.config.exe.debug.856400198." name="/" resourcePath="">
<toolChain errorParsers="" id="com.crt.advproject.toolchain.exe.debug.469819926" name="Code Red MCU Tools" superClass="com.crt.advproject.toolchain.exe.debug">
<targetPlatform binaryParser="org.eclipse.cdt.core.ELF;org.eclipse.cdt.core.GNU_ELF" id="com.crt.advproject.platform.exe.debug.548956113" name="ARM-based MCU (Debug)" superClass="com.crt.advproject.platform.exe.debug"/>
- <builder buildPath="${workspace_loc:/device_keyboard/Debug}" enableAutoBuild="false" errorParsers="org.eclipse.cdt.core.GmakeErrorParser;org.eclipse.cdt.core.CWDLocator" id="com.crt.advproject.builder.exe.debug.1029932398" incrementalBuildTarget="all" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="com.crt.advproject.builder.exe.debug"/>
+ <builder buildPath="${workspace_loc:/device_keyboard/Debug}" enableAutoBuild="false" enabledIncrementalBuild="true" errorParsers="org.eclipse.cdt.core.GmakeErrorParser;org.eclipse.cdt.core.CWDLocator" id="com.crt.advproject.builder.exe.debug.1029932398" incrementalBuildTarget="all" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="com.crt.advproject.builder.exe.debug"/>
<tool id="com.crt.advproject.cpp.exe.debug.1119457813" name="MCU C++ Compiler" superClass="com.crt.advproject.cpp.exe.debug"/>
<tool command="arm-none-eabi-gcc" commandLinePattern="${COMMAND} ${FLAGS} ${CFLAGS} ${OUTPUT_FLAG}${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}" errorParsers="org.eclipse.cdt.core.GCCErrorParser" id="com.crt.advproject.gcc.exe.debug.2040685134" name="MCU C Compiler" superClass="com.crt.advproject.gcc.exe.debug">
<option id="com.crt.advproject.gcc.arch.658802474" name="Architecture" superClass="com.crt.advproject.gcc.arch" value="com.crt.advproject.gcc.target.cm3" valueType="enumerated"/>