move board and mcu into hw folder

This commit is contained in:
hathach 2018-03-02 13:41:35 +07:00
parent 2580b4c6a7
commit 349fa2aed8
250 changed files with 47186 additions and 47134 deletions

View File

@ -83,7 +83,7 @@
<link> <link>
<name>boards</name> <name>boards</name>
<type>2</type> <type>2</type>
<locationURI>PARENT-3-PROJECT_LOC/boards</locationURI> <locationURI>PARENT-3-PROJECT_LOC/hw/boards</locationURI>
</link> </link>
<link> <link>
<name>freertos</name> <name>freertos</name>

View File

@ -281,6 +281,15 @@
</tool> </tool>
</toolChain> </toolChain>
</folderInfo> </folderInfo>
<folderInfo id="com.crt.advproject.config.exe.debug.856400198.1273868481.323365434" name="/" resourcePath="boards">
<toolChain id="com.crt.advproject.toolchain.exe.debug.131197041" name="Code Red MCU Tools" superClass="com.crt.advproject.toolchain.exe.debug" unusedChildren="">
<tool id="com.crt.advproject.cpp.exe.debug.850109969" name="MCU C++ Compiler" superClass="com.crt.advproject.cpp.exe.debug.1586184655"/>
<tool id="com.crt.advproject.gcc.exe.debug.664054820" name="MCU C Compiler" superClass="com.crt.advproject.gcc.exe.debug.1058924021"/>
<tool id="com.crt.advproject.gas.exe.debug.1948558781" name="MCU Assembler" superClass="com.crt.advproject.gas.exe.debug.73154126"/>
<tool id="com.crt.advproject.link.cpp.exe.debug.59650471" name="MCU C++ Linker" superClass="com.crt.advproject.link.cpp.exe.debug.1716426006"/>
<tool id="com.crt.advproject.link.exe.debug.1683979463" name="MCU Linker" superClass="com.crt.advproject.link.exe.debug.2143352384"/>
</toolChain>
</folderInfo>
<sourceEntries> <sourceEntries>
<entry excluding="mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/lpc43xx_lcd.c|mcu/lpc43xx/CMSISv2p10_LPC43xx_DriverLib/src/sdio.c|mcu/lpc43xx/CMSISv2p10_LPC43xx_DriverLib/src/lpc43xx_can.c|mcu/lpc43xx/CMSISv2p10_LPC43xx_DriverLib/src/LCDTerm.c|mcu/lpc175x_6x|mcu/lpc43xx/CMSISv2p10_LPC43xx_DriverLib/src/lpc43xx_evrt.c|mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/lpc43xx_rgu.c|mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/lpc43xx_adc.c|mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/Font5x7.c|mcu/lpc43xx/CMSISv2p10_LPC43xx_DriverLib/src/lpc43xx_gpdma.c|mcu/lpc43xx/CMSISv2p10_LPC43xx_DriverLib/src/lpc43xx_lcd.c|mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/lpc43xx_i2s.c|mcu/lpc43xx/CMSISv2p10_LPC43xx_DriverLib/src/lpc43xx_ssp.c|mcu/lpc43xx/CMSISv2p10_LPC43xx_DriverLib/src/lpc43xx_qei.c|mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/lpc43xx_ssp.c|mcu/lpc43xx/CMSISv2p10_LPC43xx_DriverLib/src/lpc43xx_atimer.c|mcu/lpc43xx/CMSISv2p10_LPC43xx_DriverLib/src/lpc43xx_i2s.c|mcu/lpc43xx/CMSISv2p10_LPC43xx_DriverLib/src/debug_frmwrk.c|mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/lpc43xx_gpdma.c|mcu/lpc43xx/CMSISv2p10_LPC43xx_DriverLib/src/lpc43xx_sct.c|mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/lpc43xx_wwdt.c|mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/lpc43xx_evrt.c|mcu/lpc43xx/CMSISv2p10_LPC43xx_DriverLib/src/lpc43xx_timer.c|mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/lpc43xx_qei.c|mcu/lpc43xx/CMSISv2p10_LPC43xx_DriverLib/src/lpc43xx_adc.c|mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/sdio.c|mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/lpc43xx_mcpwm.c|mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/lpc43xx_atimer.c|mcu/lpc11uxx|mcu/lpc13uxx|mcu/lpc43xx/CMSISv2p10_LPC43xx_DriverLib/src/lpc43xx_rit.c|mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/lpc43xx_sdmmc.c|mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/LCDTerm.c|mcu/lpc43xx/CMSISv2p10_LPC43xx_DriverLib/src/lpc43xx_mcpwm.c|mcu/lpc43xx/CMSISv2p10_LPC43xx_DriverLib/src/lpc43xx_wwdt.c|mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/debug_frmwrk.c|mcu/lpc43xx/CMSISv2p10_LPC43xx_DriverLib/src/lpc43xx_emc.c|mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/lpc43xx_sct.c|mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/lpc43xx_dac.c|mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/lpc43xx_pwr.c|mcu/lpc43xx/CMSISv2p10_LPC43xx_DriverLib/src/lpc43xx_rtc.c|mcu/lpc43xx/CMSISv2p10_LPC43xx_DriverLib/src/lpc43xx_dac.c|mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/lpc43xx_rit.c|mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/lpc43xx_rtc.c|mcu/lpc43xx/CMSISv2p10_LPC43xx_DriverLib/src/Font5x7.c|mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/lpc43xx_sdif.c|mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/lpc43xx_emc.c|mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/lpc43xx_can.c" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/> <entry excluding="mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/lpc43xx_lcd.c|mcu/lpc43xx/CMSISv2p10_LPC43xx_DriverLib/src/sdio.c|mcu/lpc43xx/CMSISv2p10_LPC43xx_DriverLib/src/lpc43xx_can.c|mcu/lpc43xx/CMSISv2p10_LPC43xx_DriverLib/src/LCDTerm.c|mcu/lpc175x_6x|mcu/lpc43xx/CMSISv2p10_LPC43xx_DriverLib/src/lpc43xx_evrt.c|mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/lpc43xx_rgu.c|mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/lpc43xx_adc.c|mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/Font5x7.c|mcu/lpc43xx/CMSISv2p10_LPC43xx_DriverLib/src/lpc43xx_gpdma.c|mcu/lpc43xx/CMSISv2p10_LPC43xx_DriverLib/src/lpc43xx_lcd.c|mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/lpc43xx_i2s.c|mcu/lpc43xx/CMSISv2p10_LPC43xx_DriverLib/src/lpc43xx_ssp.c|mcu/lpc43xx/CMSISv2p10_LPC43xx_DriverLib/src/lpc43xx_qei.c|mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/lpc43xx_ssp.c|mcu/lpc43xx/CMSISv2p10_LPC43xx_DriverLib/src/lpc43xx_atimer.c|mcu/lpc43xx/CMSISv2p10_LPC43xx_DriverLib/src/lpc43xx_i2s.c|mcu/lpc43xx/CMSISv2p10_LPC43xx_DriverLib/src/debug_frmwrk.c|mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/lpc43xx_gpdma.c|mcu/lpc43xx/CMSISv2p10_LPC43xx_DriverLib/src/lpc43xx_sct.c|mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/lpc43xx_wwdt.c|mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/lpc43xx_evrt.c|mcu/lpc43xx/CMSISv2p10_LPC43xx_DriverLib/src/lpc43xx_timer.c|mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/lpc43xx_qei.c|mcu/lpc43xx/CMSISv2p10_LPC43xx_DriverLib/src/lpc43xx_adc.c|mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/sdio.c|mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/lpc43xx_mcpwm.c|mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/lpc43xx_atimer.c|mcu/lpc11uxx|mcu/lpc13uxx|mcu/lpc43xx/CMSISv2p10_LPC43xx_DriverLib/src/lpc43xx_rit.c|mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/lpc43xx_sdmmc.c|mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/LCDTerm.c|mcu/lpc43xx/CMSISv2p10_LPC43xx_DriverLib/src/lpc43xx_mcpwm.c|mcu/lpc43xx/CMSISv2p10_LPC43xx_DriverLib/src/lpc43xx_wwdt.c|mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/debug_frmwrk.c|mcu/lpc43xx/CMSISv2p10_LPC43xx_DriverLib/src/lpc43xx_emc.c|mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/lpc43xx_sct.c|mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/lpc43xx_dac.c|mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/lpc43xx_pwr.c|mcu/lpc43xx/CMSISv2p10_LPC43xx_DriverLib/src/lpc43xx_rtc.c|mcu/lpc43xx/CMSISv2p10_LPC43xx_DriverLib/src/lpc43xx_dac.c|mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/lpc43xx_rit.c|mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/lpc43xx_rtc.c|mcu/lpc43xx/CMSISv2p10_LPC43xx_DriverLib/src/Font5x7.c|mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/lpc43xx_sdif.c|mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/lpc43xx_emc.c|mcu/lpc43xx/CMSIS_LPC43xx_DriverLib/src/lpc43xx_can.c" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
</sourceEntries> </sourceEntries>

View File

@ -83,12 +83,12 @@
<link> <link>
<name>boards</name> <name>boards</name>
<type>2</type> <type>2</type>
<locationURI>PARENT-3-PROJECT_LOC/boards</locationURI> <locationURI>PARENT-3-PROJECT_LOC/hw/boards</locationURI>
</link> </link>
<link> <link>
<name>mcu</name> <name>mcu</name>
<type>2</type> <type>2</type>
<locationURI>PARENT-3-PROJECT_LOC/mcu</locationURI> <locationURI>PARENT-3-PROJECT_LOC/hw/mcu</locationURI>
</link> </link>
<link> <link>
<name>src</name> <name>src</name>

View File

@ -1,109 +1,109 @@
/**************************************************************************/ /**************************************************************************/
/*! /*!
@file ansi_esc_code.h @file ansi_esc_code.h
@author hathach (tinyusb.org) @author hathach (tinyusb.org)
@section LICENSE @section LICENSE
Software License Agreement (BSD License) Software License Agreement (BSD License)
Copyright (c) 2013, hathach (tinyusb.org) Copyright (c) 2013, hathach (tinyusb.org)
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met: modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright 1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright 2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holders nor the 3. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission. derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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 INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This file is part of the tinyusb stack. This file is part of the tinyusb stack.
*/ */
/**************************************************************************/ /**************************************************************************/
/** \ingroup group_board /** \ingroup group_board
* \defgroup group_ansi_esc ANSI Esacpe Code * \defgroup group_ansi_esc ANSI Esacpe Code
* @{ */ * @{ */
#ifndef _TUSB_ANSI_ESC_CODE_H_ #ifndef _TUSB_ANSI_ESC_CODE_H_
#define _TUSB_ANSI_ESC_CODE_H_ #define _TUSB_ANSI_ESC_CODE_H_
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#define CSI_CODE(seq) "\33[" seq #define CSI_CODE(seq) "\33[" seq
#define CSI_SGR(x) CSI_CODE(#x) "m" #define CSI_SGR(x) CSI_CODE(#x) "m"
//------------- Cursor movement -------------// //------------- Cursor movement -------------//
/** \defgroup group_ansi_cursor Cursor Movement /** \defgroup group_ansi_cursor Cursor Movement
* @{ */ * @{ */
#define ANSI_CURSOR_UP(n) CSI_CODE(#n "A") ///< Move cursor up #define ANSI_CURSOR_UP(n) CSI_CODE(#n "A") ///< Move cursor up
#define ANSI_CURSOR_DOWN(n) CSI_CODE(#n "B") ///< Move cursor down #define ANSI_CURSOR_DOWN(n) CSI_CODE(#n "B") ///< Move cursor down
#define ANSI_CURSOR_FORWARD(n) CSI_CODE(#n "C") ///< Move cursor forward #define ANSI_CURSOR_FORWARD(n) CSI_CODE(#n "C") ///< Move cursor forward
#define ANSI_CURSOR_BACKWARD(n) CSI_CODE(#n "D") ///< Move cursor backward #define ANSI_CURSOR_BACKWARD(n) CSI_CODE(#n "D") ///< Move cursor backward
#define ANSI_CURSOR_LINE_DOWN(n) CSI_CODE(#n "E") ///< Move cursor to the beginning of the line (n) down #define ANSI_CURSOR_LINE_DOWN(n) CSI_CODE(#n "E") ///< Move cursor to the beginning of the line (n) down
#define ANSI_CURSOR_LINE_UP(n) CSI_CODE(#n "F") ///< Move cursor to the beginning of the line (n) up #define ANSI_CURSOR_LINE_UP(n) CSI_CODE(#n "F") ///< Move cursor to the beginning of the line (n) up
#define ANSI_CURSOR_POSITION(n, m) CSI_CODE(#n ";" #m "H") ///< Move cursor to position (n, m) #define ANSI_CURSOR_POSITION(n, m) CSI_CODE(#n ";" #m "H") ///< Move cursor to position (n, m)
/** @} */ /** @} */
//------------- Screen -------------// //------------- Screen -------------//
/** \defgroup group_ansi_screen Screen Control /** \defgroup group_ansi_screen Screen Control
* @{ */ * @{ */
#define ANSI_ERASE_SCREEN(n) CSI_CODE(#n "J") ///< Erase the screen #define ANSI_ERASE_SCREEN(n) CSI_CODE(#n "J") ///< Erase the screen
#define ANSI_ERASE_LINE(n) CSI_CODE(#n "K") ///< Erase the line (n) #define ANSI_ERASE_LINE(n) CSI_CODE(#n "K") ///< Erase the line (n)
#define ANSI_SCROLL_UP(n) CSI_CODE(#n "S") ///< Scroll the whole page up (n) lines #define ANSI_SCROLL_UP(n) CSI_CODE(#n "S") ///< Scroll the whole page up (n) lines
#define ANSI_SCROLL_DOWN(n) CSI_CODE(#n "T") ///< Scroll the whole page down (n) lines #define ANSI_SCROLL_DOWN(n) CSI_CODE(#n "T") ///< Scroll the whole page down (n) lines
/** @} */ /** @} */
//------------- Text Color -------------// //------------- Text Color -------------//
/** \defgroup group_ansi_text Text Color /** \defgroup group_ansi_text Text Color
* @{ */ * @{ */
#define ANSI_TEXT_BLACK CSI_SGR(30) #define ANSI_TEXT_BLACK CSI_SGR(30)
#define ANSI_TEXT_RED CSI_SGR(31) #define ANSI_TEXT_RED CSI_SGR(31)
#define ANSI_TEXT_GREEN CSI_SGR(32) #define ANSI_TEXT_GREEN CSI_SGR(32)
#define ANSI_TEXT_YELLOW CSI_SGR(33) #define ANSI_TEXT_YELLOW CSI_SGR(33)
#define ANSI_TEXT_BLUE CSI_SGR(34) #define ANSI_TEXT_BLUE CSI_SGR(34)
#define ANSI_TEXT_MAGENTA CSI_SGR(35) #define ANSI_TEXT_MAGENTA CSI_SGR(35)
#define ANSI_TEXT_CYAN CSI_SGR(36) #define ANSI_TEXT_CYAN CSI_SGR(36)
#define ANSI_TEXT_WHITE CSI_SGR(37) #define ANSI_TEXT_WHITE CSI_SGR(37)
#define ANSI_TEXT_DEFAULT CSI_SGR(39) #define ANSI_TEXT_DEFAULT CSI_SGR(39)
/** @} */ /** @} */
//------------- Background Color -------------// //------------- Background Color -------------//
/** \defgroup group_ansi_background Background Color /** \defgroup group_ansi_background Background Color
* @{ */ * @{ */
#define ANSI_BG_BLACK CSI_SGR(40) #define ANSI_BG_BLACK CSI_SGR(40)
#define ANSI_BG_RED CSI_SGR(41) #define ANSI_BG_RED CSI_SGR(41)
#define ANSI_BG_GREEN CSI_SGR(42) #define ANSI_BG_GREEN CSI_SGR(42)
#define ANSI_BG_YELLOW CSI_SGR(43) #define ANSI_BG_YELLOW CSI_SGR(43)
#define ANSI_BG_BLUE CSI_SGR(44) #define ANSI_BG_BLUE CSI_SGR(44)
#define ANSI_BG_MAGENTA CSI_SGR(45) #define ANSI_BG_MAGENTA CSI_SGR(45)
#define ANSI_BG_CYAN CSI_SGR(46) #define ANSI_BG_CYAN CSI_SGR(46)
#define ANSI_BG_WHITE CSI_SGR(47) #define ANSI_BG_WHITE CSI_SGR(47)
#define ANSI_BG_DEFAULT CSI_SGR(49) #define ANSI_BG_DEFAULT CSI_SGR(49)
/** @} */ /** @} */
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /* _TUSB_ANSI_ESC_CODE_H_ */ #endif /* _TUSB_ANSI_ESC_CODE_H_ */
/** @} */ /** @} */

View File

@ -1,111 +1,111 @@
/**************************************************************************/ /**************************************************************************/
/*! /*!
@file board.c @file board.c
@author hathach (tinyusb.org) @author hathach (tinyusb.org)
@section LICENSE @section LICENSE
Software License Agreement (BSD License) Software License Agreement (BSD License)
Copyright (c) 2013, hathach (tinyusb.org) Copyright (c) 2013, hathach (tinyusb.org)
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met: modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright 1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright 2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holders nor the 3. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission. derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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 INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This file is part of the tinyusb stack. This file is part of the tinyusb stack.
*/ */
/**************************************************************************/ /**************************************************************************/
#include "board.h" #include "board.h"
#include "app_os_prio.h" #include "app_os_prio.h"
#if TUSB_CFG_OS == TUSB_OS_NONE #if TUSB_CFG_OS == TUSB_OS_NONE
volatile uint32_t system_ticks = 0; volatile uint32_t system_ticks = 0;
void SysTick_Handler (void) void SysTick_Handler (void)
{ {
system_ticks++; system_ticks++;
} }
uint32_t tusb_tick_get(void) uint32_t tusb_tick_get(void)
{ {
return system_ticks; return system_ticks;
} }
#endif #endif
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// BLINKING TASK // BLINKING TASK
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
static uint32_t led_blink_interval_ms = 1000; // default is 1 second static uint32_t led_blink_interval_ms = 1000; // default is 1 second
void led_blinking_init(void) void led_blinking_init(void)
{ {
led_blink_interval_ms = 1000; led_blink_interval_ms = 1000;
osal_task_create(led_blinking_task, "blinky", 128, NULL, LED_BLINKING_APP_TASK_PRIO); osal_task_create(led_blinking_task, "blinky", 128, NULL, LED_BLINKING_APP_TASK_PRIO);
} }
void led_blinking_set_interval(uint32_t ms) void led_blinking_set_interval(uint32_t ms)
{ {
led_blink_interval_ms = ms; led_blink_interval_ms = ms;
} }
tusb_error_t led_blinking_subtask(void); tusb_error_t led_blinking_subtask(void);
void led_blinking_task(void* param) void led_blinking_task(void* param)
{ {
(void) param; (void) param;
OSAL_TASK_BEGIN OSAL_TASK_BEGIN
led_blinking_subtask(); led_blinking_subtask();
OSAL_TASK_END OSAL_TASK_END
} }
tusb_error_t led_blinking_subtask(void) tusb_error_t led_blinking_subtask(void)
{ {
OSAL_SUBTASK_BEGIN OSAL_SUBTASK_BEGIN
static uint32_t led_on_mask = 0; static uint32_t led_on_mask = 0;
osal_task_delay(led_blink_interval_ms); osal_task_delay(led_blink_interval_ms);
board_leds(led_on_mask, 1 - led_on_mask); board_leds(led_on_mask, 1 - led_on_mask);
led_on_mask = 1 - led_on_mask; // toggle led_on_mask = 1 - led_on_mask; // toggle
// uint32_t btn_mask; // uint32_t btn_mask;
// btn_mask = board_buttons(); // btn_mask = board_buttons();
// //
// for(uint8_t i=0; i<32; i++) // for(uint8_t i=0; i<32; i++)
// { // {
// if ( BIT_TEST_(btn_mask, i) ) printf("button %d is pressed\n", i); // if ( BIT_TEST_(btn_mask, i) ) printf("button %d is pressed\n", i);
// } // }
OSAL_SUBTASK_END OSAL_SUBTASK_END
} }
// TODO remove legacy cmsis code // TODO remove legacy cmsis code
void check_failed(uint8_t *file, uint32_t line) void check_failed(uint8_t *file, uint32_t line)
{ {
(void) file; (void) file;
(void) line; (void) line;
} }

View File

@ -1,174 +1,174 @@
/**************************************************************************/ /**************************************************************************/
/*! /*!
@file board.h @file board.h
@author hathach (tinyusb.org) @author hathach (tinyusb.org)
@section LICENSE @section LICENSE
Software License Agreement (BSD License) Software License Agreement (BSD License)
Copyright (c) 2013, hathach (tinyusb.org) Copyright (c) 2013, hathach (tinyusb.org)
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met: modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright 1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright 2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holders nor the 3. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission. derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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 INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This file is part of the tinyusb stack. This file is part of the tinyusb stack.
*/ */
/**************************************************************************/ /**************************************************************************/
/** \ingroup group_demo /** \ingroup group_demo
* \defgroup group_board Boards Abstraction Layer * \defgroup group_board Boards Abstraction Layer
* @{ */ * @{ */
#ifndef _TUSB_BOARD_H_ #ifndef _TUSB_BOARD_H_
#define _TUSB_BOARD_H_ #define _TUSB_BOARD_H_
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include "ansi_escape.h" #include "ansi_escape.h"
#include "tusb.h" #include "tusb.h"
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// BOARD DEFINE // BOARD DEFINE
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
/** \defgroup group_supported_board Supported Boards /** \defgroup group_supported_board Supported Boards
* @{ */ * @{ */
#define BOARD_LPCXPRESSO11U14 1114 ///< LPCXpresso 11u14, some APIs requires the base board #define BOARD_LPCXPRESSO11U14 1114 ///< LPCXpresso 11u14, some APIs requires the base board
#define BOARD_LPCXPRESSO11U68 1168 ///< LPC11U37 from microbuilder http://www.microbuilder.eu/Blog/13-03-14/LPC1xxx_1GHZ_Wireless_Board_Preview.aspx #define BOARD_LPCXPRESSO11U68 1168 ///< LPC11U37 from microbuilder http://www.microbuilder.eu/Blog/13-03-14/LPC1xxx_1GHZ_Wireless_Board_Preview.aspx
#define BOARD_LPCXPRESSO1347 1347 ///< LPCXpresso 1347, some APIs requires the base board #define BOARD_LPCXPRESSO1347 1347 ///< LPCXpresso 1347, some APIs requires the base board
#define BOARD_LPCXPRESSO1769 1769 ///< LPCXpresso 1769, some APIs requires the base board #define BOARD_LPCXPRESSO1769 1769 ///< LPCXpresso 1769, some APIs requires the base board
#define BOARD_NGX4330 4330 ///< NGX 4330 Xplorer #define BOARD_NGX4330 4330 ///< NGX 4330 Xplorer
#define BOARD_EA4357 4357 ///< Embedded Artists LPC4357 developer kit #define BOARD_EA4357 4357 ///< Embedded Artists LPC4357 developer kit
#define BOARD_MCB4300 4300 ///< Keil MCB4300 #define BOARD_MCB4300 4300 ///< Keil MCB4300
#define BOARD_HITEX4350 4350 ///< Hitex 4350 #define BOARD_HITEX4350 4350 ///< Hitex 4350
#define BOARD_LPC4357USB 4304 ///< microbuilder.eu #define BOARD_LPC4357USB 4304 ///< microbuilder.eu
#define BOARD_LPCLINK2 4370 ///< LPClink2 uses as LPC4370 development board #define BOARD_LPCLINK2 4370 ///< LPClink2 uses as LPC4370 development board
/** @} */ /** @} */
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// PRINTF TARGET DEFINE // PRINTF TARGET DEFINE
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
/** \defgroup group_printf Printf Retarget /** \defgroup group_printf Printf Retarget
* \brief Retarget the standard stdio printf/getchar to other IOs * \brief Retarget the standard stdio printf/getchar to other IOs
* @{ */ * @{ */
#define PRINTF_TARGET_SEMIHOST 1 ///< Using the semihost support from toolchain, requires no hardware but is the slowest #define PRINTF_TARGET_SEMIHOST 1 ///< Using the semihost support from toolchain, requires no hardware but is the slowest
#define PRINTF_TARGET_UART 2 ///< Using UART as stdio, this is the default for most of the board #define PRINTF_TARGET_UART 2 ///< Using UART as stdio, this is the default for most of the board
#define PRINTF_TARGET_SWO 3 ///< Using non-instructive serial wire output (SWO), is the best option since it does not slow down MCU but requires supported from debugger and IDE #define PRINTF_TARGET_SWO 3 ///< Using non-instructive serial wire output (SWO), is the best option since it does not slow down MCU but requires supported from debugger and IDE
#define PRINTF_TARGET_NONE 4 ///< Using none at all. #define PRINTF_TARGET_NONE 4 ///< Using none at all.
/** @} */ /** @} */
#define PRINTF(...) printf(__VA_ARGS__) #define PRINTF(...) printf(__VA_ARGS__)
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// BOARD INCLUDE // BOARD INCLUDE
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
#if BOARD == BOARD_LPCXPRESSO11U14 #if BOARD == BOARD_LPCXPRESSO11U14
#include "lpcxpresso/board_lpcxpresso11u14.h" #include "lpcxpresso/board_lpcxpresso11u14.h"
#elif BOARD == BOARD_LPCXPRESSO11U68 #elif BOARD == BOARD_LPCXPRESSO11U68
#include "lpcxpresso/board_lpcxpresso11u68.h" #include "lpcxpresso/board_lpcxpresso11u68.h"
#elif BOARD == BOARD_LPCXPRESSO1347 #elif BOARD == BOARD_LPCXPRESSO1347
#include "lpcxpresso/board_lpcxpresso1347.h" #include "lpcxpresso/board_lpcxpresso1347.h"
#elif BOARD == BOARD_LPCXPRESSO1769 #elif BOARD == BOARD_LPCXPRESSO1769
#include "lpcxpresso/board_lpcxpresso1769.h" #include "lpcxpresso/board_lpcxpresso1769.h"
#elif BOARD == BOARD_NGX4330 #elif BOARD == BOARD_NGX4330
#include "ngx/board_ngx4330.h" #include "ngx/board_ngx4330.h"
#elif BOARD == BOARD_EA4357 #elif BOARD == BOARD_EA4357
#include "embedded_artists/ea4357/board_ea4357.h" #include "embedded_artists/ea4357/board_ea4357.h"
#elif BOARD == BOARD_MCB4300 #elif BOARD == BOARD_MCB4300
#include "keil/board_mcb4300.h" #include "keil/board_mcb4300.h"
#elif BOARD == BOARD_HITEX4350 #elif BOARD == BOARD_HITEX4350
#include "hitex/board_hitex4350.h" #include "hitex/board_hitex4350.h"
#elif BOARD == BOARD_LPC4357USB #elif BOARD == BOARD_LPC4357USB
#include "microbuilder/board_lpc4357usb.h" #include "microbuilder/board_lpc4357usb.h"
#elif BOARD == BOARD_LPCLINK2 #elif BOARD == BOARD_LPCLINK2
#include "lpcxpresso/board_lpclink2.h" #include "lpcxpresso/board_lpclink2.h"
#else #else
#error BOARD is not defined or supported yet #error BOARD is not defined or supported yet
#endif #endif
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// Common Configuration // Common Configuration
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
#define CFG_UART_BAUDRATE 115200 ///< Baudrate for UART #define CFG_UART_BAUDRATE 115200 ///< Baudrate for UART
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// Board Common API // Board Common API
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
/** \defgroup group_board_api Board API /** \defgroup group_board_api Board API
* \brief All the board must support these APIs. * \brief All the board must support these APIs.
* @{ */ * @{ */
/// Initialize all required peripherals on board including uart, led, buttons etc ... /// Initialize all required peripherals on board including uart, led, buttons etc ...
void board_init(void); void board_init(void);
/** \brief Turns on and off leds on the board /** \brief Turns on and off leds on the board
* \param[in] on_mask Bitmask for LED's numbers is turning ON * \param[in] on_mask Bitmask for LED's numbers is turning ON
* \param[out] off_mask Bitmask for LED's numbers is turning OFF * \param[out] off_mask Bitmask for LED's numbers is turning OFF
* \note the \a on_mask is more priority then \a off_mask, if an led's number is present on both. * \note the \a on_mask is more priority then \a off_mask, if an led's number is present on both.
* It will be turned ON. * It will be turned ON.
*/ */
void board_leds(uint32_t on_mask, uint32_t off_mask); void board_leds(uint32_t on_mask, uint32_t off_mask);
/** \brief Get the current state of the buttons on the board /** \brief Get the current state of the buttons on the board
* \return Bitmask where a '1' means active (pressed), a '0' means inactive. * \return Bitmask where a '1' means active (pressed), a '0' means inactive.
*/ */
uint32_t board_buttons(void); uint32_t board_buttons(void);
/** \brief Get a character input from UART /** \brief Get a character input from UART
* \return ASCII code of the input character or zero if none. * \return ASCII code of the input character or zero if none.
*/ */
uint8_t board_uart_getchar(void); uint8_t board_uart_getchar(void);
/** \brief Send a character to UART /** \brief Send a character to UART
* \param[in] c the character to be sent * \param[in] c the character to be sent
*/ */
void board_uart_putchar(uint8_t c); void board_uart_putchar(uint8_t c);
/** @} */ /** @} */
//------------- Board Application -------------// //------------- Board Application -------------//
void led_blinking_task(void* param); void led_blinking_task(void* param);
/// Initialize the LED blinking task application. The initial blinking rate is 1 Hert (1 per second) /// Initialize the LED blinking task application. The initial blinking rate is 1 Hert (1 per second)
void led_blinking_init(void); void led_blinking_init(void);
/** \brief Change the blinking rate. /** \brief Change the blinking rate.
* \param[in] ms The interval between on and off. * \param[in] ms The interval between on and off.
*/ */
void led_blinking_set_interval(uint32_t ms); void led_blinking_set_interval(uint32_t ms);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /* _TUSB_BOARD_H_ */ #endif /* _TUSB_BOARD_H_ */
/** @} */ /** @} */

View File

@ -1,153 +1,153 @@
/**************************************************************************/ /**************************************************************************/
/*! /*!
@file board_ea4357.c @file board_ea4357.c
@author hathach (tinyusb.org) @author hathach (tinyusb.org)
@section LICENSE @section LICENSE
Software License Agreement (BSD License) Software License Agreement (BSD License)
Copyright (c) 2013, hathach (tinyusb.org) Copyright (c) 2013, hathach (tinyusb.org)
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met: modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright 1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright 2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holders nor the 3. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission. derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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 INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This file is part of the tinyusb stack. This file is part of the tinyusb stack.
*/ */
/**************************************************************************/ /**************************************************************************/
#include "../../board.h" #include "../../board.h"
#if BOARD == BOARD_EA4357 #if BOARD == BOARD_EA4357
#define BOARD_UART_PORT LPC_USART0 #define BOARD_UART_PORT LPC_USART0
#define BOARD_UART_PIN_PORT 0x0f #define BOARD_UART_PIN_PORT 0x0f
#define BOARD_UART_PIN_TX 10 // PF.10 : UART0_TXD #define BOARD_UART_PIN_TX 10 // PF.10 : UART0_TXD
#define BOARD_UART_PIN_RX 11 // PF.11 : UART0_RXD #define BOARD_UART_PIN_RX 11 // PF.11 : UART0_RXD
static const struct { static const struct {
uint8_t mux_port; uint8_t mux_port;
uint8_t mux_pin; uint8_t mux_pin;
uint8_t gpio_port; uint8_t gpio_port;
uint8_t gpio_pin; uint8_t gpio_pin;
}buttons[] = }buttons[] =
{ {
{0x0a, 3, 4, 10 }, // Joystick up {0x0a, 3, 4, 10 }, // Joystick up
{0x09, 1, 4, 13 }, // Joystick down {0x09, 1, 4, 13 }, // Joystick down
{0x0a, 2, 4, 9 }, // Joystick left {0x0a, 2, 4, 9 }, // Joystick left
{0x09, 0, 4, 12 }, // Joystick right {0x09, 0, 4, 12 }, // Joystick right
{0x0a, 1, 4, 8 }, // Joystick press {0x0a, 1, 4, 8 }, // Joystick press
{0x02, 7, 0, 7 }, // SW6 {0x02, 7, 0, 7 }, // SW6
}; };
enum { enum {
BOARD_BUTTON_COUNT = sizeof(buttons) / sizeof(buttons[0]) BOARD_BUTTON_COUNT = sizeof(buttons) / sizeof(buttons[0])
}; };
void board_init(void) void board_init(void)
{ {
CGU_Init(); CGU_Init();
#if TUSB_CFG_OS == TUSB_OS_NONE // TODO may move to main.c #if TUSB_CFG_OS == TUSB_OS_NONE // TODO may move to main.c
SysTick_Config(CGU_GetPCLKFrequency(CGU_PERIPHERAL_M4CORE) / TUSB_CFG_TICKS_HZ); // 1 msec tick timer SysTick_Config(CGU_GetPCLKFrequency(CGU_PERIPHERAL_M4CORE) / TUSB_CFG_TICKS_HZ); // 1 msec tick timer
#endif #endif
//------------- USB -------------// //------------- USB -------------//
// USB0 Power: EA4357 channel B U20 GPIO26 active low (base board), P2_3 on LPC4357 // USB0 Power: EA4357 channel B U20 GPIO26 active low (base board), P2_3 on LPC4357
scu_pinmux(0x02, 3, MD_PUP | MD_EZI, FUNC7); // USB0 VBus Power scu_pinmux(0x02, 3, MD_PUP | MD_EZI, FUNC7); // USB0 VBus Power
#if TUSB_CFG_CONTROLLER_0_MODE & TUSB_MODE_DEVICE #if TUSB_CFG_CONTROLLER_0_MODE & TUSB_MODE_DEVICE
scu_pinmux(0x09, 5, GPIO_PDN, FUNC4); // P9_5 (GPIO5[18]) (GPIO28 on oem base) as USB connect, active low. scu_pinmux(0x09, 5, GPIO_PDN, FUNC4); // P9_5 (GPIO5[18]) (GPIO28 on oem base) as USB connect, active low.
GPIO_SetDir(5, BIT_(18), 1); GPIO_SetDir(5, BIT_(18), 1);
#endif #endif
// USB1 Power: EA4357 channel A U20 is enabled by SJ5 connected to pad 1-2, no more action required // USB1 Power: EA4357 channel A U20 is enabled by SJ5 connected to pad 1-2, no more action required
// TODO Remove R170, R171, solder a pair of 15K to USB1 D+/D- to test with USB1 Host // TODO Remove R170, R171, solder a pair of 15K to USB1 D+/D- to test with USB1 Host
//------------- LED -------------// //------------- LED -------------//
I2C_Init(LPC_I2C0, 100000); I2C_Init(LPC_I2C0, 100000);
I2C_Cmd(LPC_I2C0, ENABLE); I2C_Cmd(LPC_I2C0, ENABLE);
pca9532_init(); pca9532_init();
//------------- BUTTON -------------// //------------- BUTTON -------------//
for(uint8_t i=0; i<BOARD_BUTTON_COUNT; i++) for(uint8_t i=0; i<BOARD_BUTTON_COUNT; i++)
{ {
scu_pinmux(buttons[i].mux_port, buttons[i].mux_pin, GPIO_NOPULL, FUNC0); scu_pinmux(buttons[i].mux_port, buttons[i].mux_pin, GPIO_NOPULL, FUNC0);
GPIO_SetDir(buttons[i].gpio_port, BIT_(buttons[i].gpio_pin), 0); GPIO_SetDir(buttons[i].gpio_port, BIT_(buttons[i].gpio_pin), 0);
} }
//------------- UART -------------// //------------- UART -------------//
scu_pinmux(BOARD_UART_PIN_PORT, BOARD_UART_PIN_TX, MD_PDN, FUNC1); scu_pinmux(BOARD_UART_PIN_PORT, BOARD_UART_PIN_TX, MD_PDN, FUNC1);
scu_pinmux(BOARD_UART_PIN_PORT, BOARD_UART_PIN_RX, MD_PLN | MD_EZI | MD_ZI, FUNC1); scu_pinmux(BOARD_UART_PIN_PORT, BOARD_UART_PIN_RX, MD_PLN | MD_EZI | MD_ZI, FUNC1);
UART_CFG_Type UARTConfigStruct; UART_CFG_Type UARTConfigStruct;
UART_ConfigStructInit(&UARTConfigStruct); UART_ConfigStructInit(&UARTConfigStruct);
UARTConfigStruct.Baud_rate = CFG_UART_BAUDRATE; UARTConfigStruct.Baud_rate = CFG_UART_BAUDRATE;
UARTConfigStruct.Clock_Speed = 0; UARTConfigStruct.Clock_Speed = 0;
UART_Init(BOARD_UART_PORT, &UARTConfigStruct); UART_Init(BOARD_UART_PORT, &UARTConfigStruct);
UART_TxCmd(BOARD_UART_PORT, ENABLE); // Enable UART Transmit UART_TxCmd(BOARD_UART_PORT, ENABLE); // Enable UART Transmit
//------------- NAND Flash (K9FXX) Size = 128M, Page Size = 2K, Block Size = 128K, Number of Block = 1024 -------------// //------------- NAND Flash (K9FXX) Size = 128M, Page Size = 2K, Block Size = 128K, Number of Block = 1024 -------------//
// nand_init(); // nand_init();
} }
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// LEDS // LEDS
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
void board_leds(uint32_t on_mask, uint32_t off_mask) void board_leds(uint32_t on_mask, uint32_t off_mask)
{ {
pca9532_setLeds( on_mask << 8, off_mask << 8); pca9532_setLeds( on_mask << 8, off_mask << 8);
} }
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// BUTTONS // BUTTONS
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
static bool button_read(uint8_t id) static bool button_read(uint8_t id)
{ {
return !BIT_TEST_( GPIO_ReadValue(buttons[id].gpio_port), buttons[id].gpio_pin ); // button is active low return !BIT_TEST_( GPIO_ReadValue(buttons[id].gpio_port), buttons[id].gpio_pin ); // button is active low
} }
uint32_t board_buttons(void) uint32_t board_buttons(void)
{ {
uint32_t result = 0; uint32_t result = 0;
for(uint8_t i=0; i<BOARD_BUTTON_COUNT; i++) result |= (button_read(i) ? BIT_(i) : 0); for(uint8_t i=0; i<BOARD_BUTTON_COUNT; i++) result |= (button_read(i) ? BIT_(i) : 0);
return result; return result;
} }
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// UART // UART
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
uint8_t board_uart_getchar(void) uint8_t board_uart_getchar(void)
{ {
return UART_ReceiveByte(BOARD_UART_PORT); return UART_ReceiveByte(BOARD_UART_PORT);
} }
void board_uart_putchar(uint8_t c) void board_uart_putchar(uint8_t c)
{ {
UART_Send(BOARD_UART_PORT, &c, 1, BLOCKING); UART_Send(BOARD_UART_PORT, &c, 1, BLOCKING);
} }
#endif #endif

View File

@ -1,65 +1,65 @@
/**************************************************************************/ /**************************************************************************/
/*! /*!
@file board_ea4357.h @file board_ea4357.h
@author hathach (tinyusb.org) @author hathach (tinyusb.org)
@section LICENSE @section LICENSE
Software License Agreement (BSD License) Software License Agreement (BSD License)
Copyright (c) 2013, hathach (tinyusb.org) Copyright (c) 2013, hathach (tinyusb.org)
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met: modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright 1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright 2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holders nor the 3. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission. derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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 INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This file is part of the tinyusb stack. This file is part of the tinyusb stack.
*/ */
/**************************************************************************/ /**************************************************************************/
#ifndef _TUSB_BOARD_EA4357_H_ #ifndef _TUSB_BOARD_EA4357_H_
#define _TUSB_BOARD_EA4357_H_ #define _TUSB_BOARD_EA4357_H_
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "LPC43xx.h" #include "LPC43xx.h"
#include "lpc43xx_scu.h" #include "lpc43xx_scu.h"
#include "lpc43xx_cgu.h" #include "lpc43xx_cgu.h"
#include "lpc43xx_gpio.h" #include "lpc43xx_gpio.h"
#include "lpc43xx_uart.h" #include "lpc43xx_uart.h"
#include "lpc43xx_i2c.h" #include "lpc43xx_i2c.h"
#include "../oem_base_board/pca9532.h" // LEDs #include "../oem_base_board/pca9532.h" // LEDs
//#include "../oem_board/nand.h"a //#include "../oem_board/nand.h"a
//#define CFG_PRINTF_TARGET PRINTF_TARGET_SWO //#define CFG_PRINTF_TARGET PRINTF_TARGET_SWO
#define CFG_PRINTF_TARGET PRINTF_TARGET_UART #define CFG_PRINTF_TARGET PRINTF_TARGET_UART
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /* _TUSB_BOARD_EA4357_H_ */ #endif /* _TUSB_BOARD_EA4357_H_ */

View File

@ -1,480 +1,480 @@
/****************************************************************** /******************************************************************
***** ***** ***** *****
***** Name: cs8900.c ***** ***** Name: cs8900.c *****
***** Ver.: 1.0 ***** ***** Ver.: 1.0 *****
***** Date: 07/05/2001 ***** ***** Date: 07/05/2001 *****
***** Auth: Andreas Dannenberg ***** ***** Auth: Andreas Dannenberg *****
***** HTWK Leipzig ***** ***** HTWK Leipzig *****
***** university of applied sciences ***** ***** university of applied sciences *****
***** Germany ***** ***** Germany *****
***** Func: ethernet packet-driver for use with LAN- ***** ***** Func: ethernet packet-driver for use with LAN- *****
***** controller CS8900 from Crystal/Cirrus Logic ***** ***** controller CS8900 from Crystal/Cirrus Logic *****
***** ***** ***** *****
***** NXP: Module modified for use with NXP ***** ***** NXP: Module modified for use with NXP *****
***** lpc43xx EMAC Ethernet controller ***** ***** lpc43xx EMAC Ethernet controller *****
***** ***** ***** *****
******************************************************************/ ******************************************************************/
#include "../../board.h" #include "../../board.h"
#if BOARD == BOARD_EA4357 #if BOARD == BOARD_EA4357
#include "emac.h" #include "emac.h"
//#include "tcpip.h" //#include "tcpip.h"
#include "LPC43xx.h" #include "LPC43xx.h"
#include "lpc43xx_scu.h" #include "lpc43xx_scu.h"
#include "lpc43xx_rgu.h" #include "lpc43xx_rgu.h"
#define TIMEOUT 100000 #define TIMEOUT 100000
static unsigned short *rptr; static unsigned short *rptr;
static unsigned short *tptr; static unsigned short *tptr;
static unsigned int TxDescIndex = 0; static unsigned int TxDescIndex = 0;
static unsigned int RxDescIndex = 0; static unsigned int RxDescIndex = 0;
// Keil: function added to write PHY // Keil: function added to write PHY
static void write_PHY (unsigned int PhyReg, unsigned short Value) { static void write_PHY (unsigned int PhyReg, unsigned short Value) {
unsigned int tout; unsigned int tout;
/* Write a data 'Value' to PHY register 'PhyReg'. */ /* Write a data 'Value' to PHY register 'PhyReg'. */
while(LPC_ETHERNET->MAC_MII_ADDR & GMII_BUSY); // Check GMII busy bit while(LPC_ETHERNET->MAC_MII_ADDR & GMII_BUSY); // Check GMII busy bit
LPC_ETHERNET->MAC_MII_ADDR = (DP83848C_DEF_ADR<<11) | (PhyReg<<6) | GMII_WRITE; LPC_ETHERNET->MAC_MII_ADDR = (DP83848C_DEF_ADR<<11) | (PhyReg<<6) | GMII_WRITE;
LPC_ETHERNET->MAC_MII_DATA = Value; LPC_ETHERNET->MAC_MII_DATA = Value;
LPC_ETHERNET->MAC_MII_ADDR |= GMII_BUSY; // Start PHY Write Cycle LPC_ETHERNET->MAC_MII_ADDR |= GMII_BUSY; // Start PHY Write Cycle
/* Wait utill operation completed */ /* Wait utill operation completed */
for (tout = 0; tout < MII_WR_TOUT; tout++) { for (tout = 0; tout < MII_WR_TOUT; tout++) {
if ((LPC_ETHERNET->MAC_MII_ADDR & GMII_BUSY) == 0) { if ((LPC_ETHERNET->MAC_MII_ADDR & GMII_BUSY) == 0) {
break; break;
} }
} }
if (tout == MII_WR_TOUT) // Trap the timeout if (tout == MII_WR_TOUT) // Trap the timeout
while(1); while(1);
} }
// Keil: function added to read PHY // Keil: function added to read PHY
static unsigned short read_PHY (unsigned int PhyReg) { static unsigned short read_PHY (unsigned int PhyReg) {
unsigned int tout, val; unsigned int tout, val;
/* Read a PHY register 'PhyReg'. */ /* Read a PHY register 'PhyReg'. */
while(LPC_ETHERNET->MAC_MII_ADDR & GMII_BUSY); // Check GMII busy bit while(LPC_ETHERNET->MAC_MII_ADDR & GMII_BUSY); // Check GMII busy bit
LPC_ETHERNET->MAC_MII_ADDR = (DP83848C_DEF_ADR<<11) | (PhyReg<<6) | GMII_READ; LPC_ETHERNET->MAC_MII_ADDR = (DP83848C_DEF_ADR<<11) | (PhyReg<<6) | GMII_READ;
LPC_ETHERNET->MAC_MII_ADDR |= GMII_BUSY; // Start PHY Read Cycle LPC_ETHERNET->MAC_MII_ADDR |= GMII_BUSY; // Start PHY Read Cycle
/* Wait until operation completed */ /* Wait until operation completed */
for (tout = 0; tout < MII_RD_TOUT; tout++) { for (tout = 0; tout < MII_RD_TOUT; tout++) {
if ((LPC_ETHERNET->MAC_MII_ADDR & GMII_BUSY) == 0) { if ((LPC_ETHERNET->MAC_MII_ADDR & GMII_BUSY) == 0) {
break; break;
} }
} }
if (tout == MII_RD_TOUT) // Trap the timeout if (tout == MII_RD_TOUT) // Trap the timeout
while(1); while(1);
val = LPC_ETHERNET->MAC_MII_DATA; val = LPC_ETHERNET->MAC_MII_DATA;
return (val); return (val);
} }
// Keil: function added to initialize Rx Descriptors // Keil: function added to initialize Rx Descriptors
void rx_descr_init (void) void rx_descr_init (void)
{ {
unsigned int i; unsigned int i;
for (i = 0; i < NUM_RX_DESC; i++) { for (i = 0; i < NUM_RX_DESC; i++) {
RX_DESC_STAT(i) = OWN_BIT; RX_DESC_STAT(i) = OWN_BIT;
RX_DESC_CTRL(i) = ETH_FRAG_SIZE; RX_DESC_CTRL(i) = ETH_FRAG_SIZE;
RX_BUFADDR(i) = RX_BUF(i); RX_BUFADDR(i) = RX_BUF(i);
if (i == (NUM_RX_DESC-1)) // Last Descriptor? if (i == (NUM_RX_DESC-1)) // Last Descriptor?
RX_DESC_CTRL(i) |= RX_END_RING; RX_DESC_CTRL(i) |= RX_END_RING;
} }
/* Set Starting address of RX Descriptor list */ /* Set Starting address of RX Descriptor list */
LPC_ETHERNET->DMA_REC_DES_ADDR = RX_DESC_BASE; LPC_ETHERNET->DMA_REC_DES_ADDR = RX_DESC_BASE;
} }
// Keil: function added to initialize Tx Descriptors // Keil: function added to initialize Tx Descriptors
void tx_descr_init (void) void tx_descr_init (void)
{ {
unsigned int i; unsigned int i;
for (i = 0; i < NUM_TX_DESC; i++) { // Take it out!!!! for (i = 0; i < NUM_TX_DESC; i++) { // Take it out!!!!
TX_DESC_STAT(i) = 0; TX_DESC_STAT(i) = 0;
TX_DESC_CTRL(i) = 0; TX_DESC_CTRL(i) = 0;
TX_BUFADDR(i) = 0; TX_BUFADDR(i) = 0;
} }
for (i = 0; i < NUM_TX_DESC; i++) { for (i = 0; i < NUM_TX_DESC; i++) {
TX_DESC_STAT(i) = TX_LAST_SEGM | TX_FIRST_SEGM; TX_DESC_STAT(i) = TX_LAST_SEGM | TX_FIRST_SEGM;
TX_DESC_CTRL(i) = 0; TX_DESC_CTRL(i) = 0;
TX_BUFADDR(i) = TX_BUF(i); TX_BUFADDR(i) = TX_BUF(i);
if (i == (NUM_TX_DESC-1)) // Last Descriptor? if (i == (NUM_TX_DESC-1)) // Last Descriptor?
TX_DESC_STAT(i) |= TX_END_RING; TX_DESC_STAT(i) |= TX_END_RING;
} }
/* Set Starting address of RX Descriptor list */ /* Set Starting address of RX Descriptor list */
LPC_ETHERNET->DMA_TRANS_DES_ADDR = TX_DESC_BASE; LPC_ETHERNET->DMA_TRANS_DES_ADDR = TX_DESC_BASE;
} }
// configure port-pins for use with LAN-controller, // configure port-pins for use with LAN-controller,
// reset it and send the configuration-sequence // reset it and send the configuration-sequence
void Init_EMAC(void) void Init_EMAC(void)
{ {
int id1, id2, tout, regv; int id1, id2, tout, regv;
unsigned phy_in_use = 0; unsigned phy_in_use = 0;
/* Ethernet pins configuration */ /* Ethernet pins configuration */
#if MII #if MII
scu_pinmux(0xC ,1 , (MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_MDC: PC_1 -> FUNC3 scu_pinmux(0xC ,1 , (MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_MDC: PC_1 -> FUNC3
scu_pinmux(0x1 ,17 , (MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_MDIO: P1_17 -> FUNC3 scu_pinmux(0x1 ,17 , (MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_MDIO: P1_17 -> FUNC3
scu_pinmux(0x1 ,18 , (MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_TXD0: P1_18 -> FUNC3 scu_pinmux(0x1 ,18 , (MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_TXD0: P1_18 -> FUNC3
scu_pinmux(0x1 ,20 , (MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_TXD1: P1_20 -> FUNC3 scu_pinmux(0x1 ,20 , (MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_TXD1: P1_20 -> FUNC3
scu_pinmux(0x1 ,19 , (MD_PLN | MD_EZI | MD_ZI), FUNC0); // ENET_REF: P1_19 -> FUNC0 (default) scu_pinmux(0x1 ,19 , (MD_PLN | MD_EZI | MD_ZI), FUNC0); // ENET_REF: P1_19 -> FUNC0 (default)
// scu_pinmux(0xC ,4 , (MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_TX_EN: PC_4 -> FUNC3 // scu_pinmux(0xC ,4 , (MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_TX_EN: PC_4 -> FUNC3
scu_pinmux(0x0 ,1 , (MD_PLN | MD_EZI | MD_ZI), FUNC6); // ENET_TX_EN: P0_1 -> FUNC6 scu_pinmux(0x0 ,1 , (MD_PLN | MD_EZI | MD_ZI), FUNC6); // ENET_TX_EN: P0_1 -> FUNC6
scu_pinmux(0x1 ,15 , (MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_RXD0: P1_15 -> FUNC3 scu_pinmux(0x1 ,15 , (MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_RXD0: P1_15 -> FUNC3
scu_pinmux(0x0 ,0 , (MD_PLN | MD_EZI | MD_ZI), FUNC2); // ENET_RXD1: P0_0 -> FUNC2 scu_pinmux(0x0 ,0 , (MD_PLN | MD_EZI | MD_ZI), FUNC2); // ENET_RXD1: P0_0 -> FUNC2
// scu_pinmux(0x1 ,16 , (MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_CRS: P1_16 -> FUNC3 // scu_pinmux(0x1 ,16 , (MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_CRS: P1_16 -> FUNC3
scu_pinmux(0x9 ,0 , (MD_PLN | MD_EZI | MD_ZI), FUNC5); // ENET_CRS: P9_0 -> FUNC5 scu_pinmux(0x9 ,0 , (MD_PLN | MD_EZI | MD_ZI), FUNC5); // ENET_CRS: P9_0 -> FUNC5
// scu_pinmux(0xC ,9 , (MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_RX_ER: PC_9 -> FUNC3 // scu_pinmux(0xC ,9 , (MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_RX_ER: PC_9 -> FUNC3
scu_pinmux(0x9 ,1 , (MD_PLN | MD_EZI | MD_ZI), FUNC5); // ENET_RX_ER: P9_1 -> FUNC5 scu_pinmux(0x9 ,1 , (MD_PLN | MD_EZI | MD_ZI), FUNC5); // ENET_RX_ER: P9_1 -> FUNC5
// scu_pinmux(0xC ,8 , (MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_RXDV: PC_8 -> FUNC3 // scu_pinmux(0xC ,8 , (MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_RXDV: PC_8 -> FUNC3
scu_pinmux(0x1 ,16 , (MD_PLN | MD_EZI | MD_ZI), FUNC7); // ENET_RXDV: P1_16 -> FUNC7 scu_pinmux(0x1 ,16 , (MD_PLN | MD_EZI | MD_ZI), FUNC7); // ENET_RXDV: P1_16 -> FUNC7
#else #else
scu_pinmux(0xC ,1 , (MD_EHS | MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_MDC: PC_1 -> FUNC3 scu_pinmux(0xC ,1 , (MD_EHS | MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_MDC: PC_1 -> FUNC3
scu_pinmux(0x1 ,17 , (MD_EHS | MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_MDIO: P1_17 -> FUNC3 scu_pinmux(0x1 ,17 , (MD_EHS | MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_MDIO: P1_17 -> FUNC3
scu_pinmux(0x1 ,18 , (MD_EHS | MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_TXD0: P1_18 -> FUNC3 scu_pinmux(0x1 ,18 , (MD_EHS | MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_TXD0: P1_18 -> FUNC3
scu_pinmux(0x1 ,20 , (MD_EHS | MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_TXD1: P1_20 -> FUNC3 scu_pinmux(0x1 ,20 , (MD_EHS | MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_TXD1: P1_20 -> FUNC3
scu_pinmux(0x1 ,19 , (MD_EHS | MD_PLN | MD_EZI | MD_ZI), FUNC0); // ENET_REF: P1_19 -> FUNC0 (default) scu_pinmux(0x1 ,19 , (MD_EHS | MD_PLN | MD_EZI | MD_ZI), FUNC0); // ENET_REF: P1_19 -> FUNC0 (default)
// scu_pinmux(0xC ,4 , (MD_EHS | MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_TX_EN: PC_4 -> FUNC3 // scu_pinmux(0xC ,4 , (MD_EHS | MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_TX_EN: PC_4 -> FUNC3
scu_pinmux(0x0 ,1 , (MD_PLN | MD_EZI | MD_ZI), FUNC6); // ENET_TX_EN: P0_1 -> FUNC6 scu_pinmux(0x0 ,1 , (MD_PLN | MD_EZI | MD_ZI), FUNC6); // ENET_TX_EN: P0_1 -> FUNC6
scu_pinmux(0x1 ,15 , (MD_EHS | MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_RXD0: P1_15 -> FUNC3 scu_pinmux(0x1 ,15 , (MD_EHS | MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_RXD0: P1_15 -> FUNC3
scu_pinmux(0x0 ,0 , (MD_EHS | MD_PLN | MD_EZI | MD_ZI), FUNC2); // ENET_RXD1: P0_0 -> FUNC2 scu_pinmux(0x0 ,0 , (MD_EHS | MD_PLN | MD_EZI | MD_ZI), FUNC2); // ENET_RXD1: P0_0 -> FUNC2
// scu_pinmux(0x1 ,16 , (MD_EHS | MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_CRS: P1_16 -> FUNC3 // scu_pinmux(0x1 ,16 , (MD_EHS | MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_CRS: P1_16 -> FUNC3
// scu_pinmux(0x9 ,0 , (MD_PLN | MD_EZI | MD_ZI), FUNC5); // ENET_CRS: P9_0 -> FUNC5 // scu_pinmux(0x9 ,0 , (MD_PLN | MD_EZI | MD_ZI), FUNC5); // ENET_CRS: P9_0 -> FUNC5
// scu_pinmux(0xC ,9 , (MD_EHS | MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_RX_ER: PC_9 -> FUNC3 // scu_pinmux(0xC ,9 , (MD_EHS | MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_RX_ER: PC_9 -> FUNC3
// scu_pinmux(0x9 ,1 , (MD_PLN | MD_EZI | MD_ZI), FUNC5); // ENET_RX_ER: P9_1 -> FUNC5 // scu_pinmux(0x9 ,1 , (MD_PLN | MD_EZI | MD_ZI), FUNC5); // ENET_RX_ER: P9_1 -> FUNC5
// scu_pinmux(0xC ,8 , (MD_EHS | MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_RXDV: PC_8 -> FUNC3 // scu_pinmux(0xC ,8 , (MD_EHS | MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_RXDV: PC_8 -> FUNC3
scu_pinmux(0x1 ,16 , (MD_PLN | MD_EZI | MD_ZI), FUNC7); // ENET_RXDV: P1_16 -> FUNC7 scu_pinmux(0x1 ,16 , (MD_PLN | MD_EZI | MD_ZI), FUNC7); // ENET_RXDV: P1_16 -> FUNC7
#endif #endif
#if MII /* Select MII interface */ // check MUXING for new Eagle... #if MII /* Select MII interface */ // check MUXING for new Eagle...
// scu_pinmux(0xC ,6 , (MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_RXD2: PC_6 -> FUNC3 // scu_pinmux(0xC ,6 , (MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_RXD2: PC_6 -> FUNC3
scu_pinmux(0x9 ,3 , (MD_PLN | MD_EZI | MD_ZI), FUNC5); // ENET_RXD2: P9_3 -> FUNC5 scu_pinmux(0x9 ,3 , (MD_PLN | MD_EZI | MD_ZI), FUNC5); // ENET_RXD2: P9_3 -> FUNC5
// scu_pinmux(0xC ,7 , (MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_RXD3: PC_7 -> FUNC3 // scu_pinmux(0xC ,7 , (MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_RXD3: PC_7 -> FUNC3
scu_pinmux(0x9 ,2 , (MD_PLN | MD_EZI | MD_ZI), FUNC5); // ENET_RXD3: P9_2 -> FUNC5 scu_pinmux(0x9 ,2 , (MD_PLN | MD_EZI | MD_ZI), FUNC5); // ENET_RXD3: P9_2 -> FUNC5
scu_pinmux(0xC ,0 , (MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_RXLK: PC_0 -> FUNC3 scu_pinmux(0xC ,0 , (MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_RXLK: PC_0 -> FUNC3
// scu_pinmux(0xC ,2 , (MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_TXD2: PC_2 -> FUNC3 // scu_pinmux(0xC ,2 , (MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_TXD2: PC_2 -> FUNC3
scu_pinmux(0x9 ,4 , (MD_PLN | MD_EZI | MD_ZI), FUNC5); // ENET_TXD2: P9_4 -> FUNC5 scu_pinmux(0x9 ,4 , (MD_PLN | MD_EZI | MD_ZI), FUNC5); // ENET_TXD2: P9_4 -> FUNC5
// scu_pinmux(0xC ,3 , (MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_TXD3: PC_3 -> FUNC3 // scu_pinmux(0xC ,3 , (MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_TXD3: PC_3 -> FUNC3
scu_pinmux(0x9 ,5 , (MD_PLN | MD_EZI | MD_ZI), FUNC5); // ENET_TXD3: P9_5 -> FUNC5 scu_pinmux(0x9 ,5 , (MD_PLN | MD_EZI | MD_ZI), FUNC5); // ENET_TXD3: P9_5 -> FUNC5
// scu_pinmux(0xC ,5 , (MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_TX_ER: PC_5 -> FUNC3 // scu_pinmux(0xC ,5 , (MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_TX_ER: PC_5 -> FUNC3
scu_pinmux(0xC ,5 , (MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_TX_ER: PC_5 -> FUNC3 scu_pinmux(0xC ,5 , (MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET_TX_ER: PC_5 -> FUNC3
// scu_pinmux(0x0 ,1 , (MD_PLN | MD_EZI | MD_ZI), FUNC2); // ENET_COL: P0_1 -> FUNC2 // scu_pinmux(0x0 ,1 , (MD_PLN | MD_EZI | MD_ZI), FUNC2); // ENET_COL: P0_1 -> FUNC2
scu_pinmux(0x9 ,6 , (MD_PLN | MD_EZI | MD_ZI), FUNC5); // ENET_COL: P9_6 -> FUNC5 scu_pinmux(0x9 ,6 , (MD_PLN | MD_EZI | MD_ZI), FUNC5); // ENET_COL: P9_6 -> FUNC5
#else /* Select RMII interface */ #else /* Select RMII interface */
LPC_CREG->CREG6 |= RMII_SELECT; LPC_CREG->CREG6 |= RMII_SELECT;
#endif #endif
RGU_SoftReset(RGU_SIG_ETHERNET); RGU_SoftReset(RGU_SIG_ETHERNET);
while(1){ // Confirm the reset happened while(1){ // Confirm the reset happened
if (LPC_RGU->RESET_ACTIVE_STATUS0 & (1<<ETHERNET_RST)) if (LPC_RGU->RESET_ACTIVE_STATUS0 & (1<<ETHERNET_RST))
break; break;
} }
LPC_ETHERNET->DMA_BUS_MODE |= DMA_SOFT_RESET; // Reset all GMAC Subsystem internal registers and logic LPC_ETHERNET->DMA_BUS_MODE |= DMA_SOFT_RESET; // Reset all GMAC Subsystem internal registers and logic
while(LPC_ETHERNET->DMA_BUS_MODE & DMA_SOFT_RESET); // Wait for software reset completion while(LPC_ETHERNET->DMA_BUS_MODE & DMA_SOFT_RESET); // Wait for software reset completion
/* Put the DP83848C in reset mode */ /* Put the DP83848C in reset mode */
write_PHY (PHY_REG_BMCR, PHY_BMCR_RESET); write_PHY (PHY_REG_BMCR, PHY_BMCR_RESET);
/* Wait for hardware reset to end. */ /* Wait for hardware reset to end. */
for (tout = 0; tout < TIMEOUT; tout++) { for (tout = 0; tout < TIMEOUT; tout++) {
regv = read_PHY (PHY_REG_BMCR); regv = read_PHY (PHY_REG_BMCR);
if (!(regv & PHY_BMCR_RESET)) { if (!(regv & PHY_BMCR_RESET)) {
/* Reset complete */ /* Reset complete */
break; break;
} }
} }
/* Check if this is a DP83848C PHY. */ /* Check if this is a DP83848C PHY. */
id1 = read_PHY (PHY_REG_IDR1); id1 = read_PHY (PHY_REG_IDR1);
id2 = read_PHY (PHY_REG_IDR2); id2 = read_PHY (PHY_REG_IDR2);
if (((id1 << 16) | (id2 & 0xFFF0)) == DP83848C_ID) { if (((id1 << 16) | (id2 & 0xFFF0)) == DP83848C_ID) {
phy_in_use = DP83848C_ID; phy_in_use = DP83848C_ID;
} }
else if (((id1 << 16) | (id2 & 0xFFF0)) == LAN8720_ID) { else if (((id1 << 16) | (id2 & 0xFFF0)) == LAN8720_ID) {
phy_in_use = LAN8720_ID; phy_in_use = LAN8720_ID;
} }
if (phy_in_use != 0) { if (phy_in_use != 0) {
/* Configure the PHY device */ /* Configure the PHY device */
#if !MII #if !MII
write_PHY (PHY_REG_RBR, 0x20); write_PHY (PHY_REG_RBR, 0x20);
#endif #endif
/* Use autonegotiation about the link speed. */ /* Use autonegotiation about the link speed. */
write_PHY (PHY_REG_BMCR, PHY_AUTO_NEG); write_PHY (PHY_REG_BMCR, PHY_AUTO_NEG);
/* Wait to complete Auto_Negotiation. */ /* Wait to complete Auto_Negotiation. */
for (tout = 0; tout < TIMEOUT; tout++) { for (tout = 0; tout < TIMEOUT; tout++) {
regv = read_PHY (PHY_REG_BMSR); regv = read_PHY (PHY_REG_BMSR);
if (regv & PHY_AUTO_NEG_DONE) { if (regv & PHY_AUTO_NEG_DONE) {
/* Autonegotiation Complete. */ /* Autonegotiation Complete. */
break; break;
} }
} }
} }
/* Check the link status. */ /* Check the link status. */
for (tout = 0; tout < TIMEOUT; tout++) { for (tout = 0; tout < TIMEOUT; tout++) {
regv = read_PHY (PHY_REG_STS); regv = read_PHY (PHY_REG_STS);
if (regv & LINK_VALID_STS) { if (regv & LINK_VALID_STS) {
/* Link is on. */ /* Link is on. */
break; break;
} }
} }
// Configure the EMAC with the established parameters // Configure the EMAC with the established parameters
switch (phy_in_use) { switch (phy_in_use) {
case DP83848C_ID: case DP83848C_ID:
/* Configure Full/Half Duplex mode. */ /* Configure Full/Half Duplex mode. */
if (regv & FULL_DUP_STS) { if (regv & FULL_DUP_STS) {
/* Full duplex is enabled. */ /* Full duplex is enabled. */
LPC_ETHERNET->MAC_CONFIG |= MAC_DUPMODE; LPC_ETHERNET->MAC_CONFIG |= MAC_DUPMODE;
} }
/* Configure 100MBit/10MBit mode. */ /* Configure 100MBit/10MBit mode. */
if (~(regv & SPEED_10M_STS)) { if (~(regv & SPEED_10M_STS)) {
/* 100MBit mode. */ /* 100MBit mode. */
LPC_ETHERNET->MAC_CONFIG |= MAC_100MPS; LPC_ETHERNET->MAC_CONFIG |= MAC_100MPS;
} }
// value = ReadFromPHY (PHY_REG_STS); /* PHY Extended Status Register */ // value = ReadFromPHY (PHY_REG_STS); /* PHY Extended Status Register */
// // Now configure for full/half duplex mode // // Now configure for full/half duplex mode
// if (value & 0x0004) { // if (value & 0x0004) {
// // We are in full duplex is enabled mode // // We are in full duplex is enabled mode
// LPC_ETHERNET->MAC2 |= MAC2_FULL_DUP; // LPC_ETHERNET->MAC2 |= MAC2_FULL_DUP;
// LPC_ETHERNET->Command |= CR_FULL_DUP; // LPC_ETHERNET->Command |= CR_FULL_DUP;
// LPC_ETHERNET->IPGT = IPGT_FULL_DUP; // LPC_ETHERNET->IPGT = IPGT_FULL_DUP;
// } // }
// else { // else {
// // Otherwise we are in half duplex mode // // Otherwise we are in half duplex mode
// LPC_ETHERNET->IPGT = IPGT_HALF_DUP; // LPC_ETHERNET->IPGT = IPGT_HALF_DUP;
// } // }
// // Now configure 100MBit or 10MBit mode // // Now configure 100MBit or 10MBit mode
// if (value & 0x0002) { // if (value & 0x0002) {
// // 10MBit mode // // 10MBit mode
// LPC_ETHERNET->SUPP = 0; // LPC_ETHERNET->SUPP = 0;
// } // }
// else { // else {
// // 100MBit mode // // 100MBit mode
// LPC_ETHERNET->SUPP = SUPP_SPEED; // LPC_ETHERNET->SUPP = SUPP_SPEED;
// } // }
break; break;
case LAN8720_ID: case LAN8720_ID:
regv = read_PHY (PHY_REG_SCSR); /* PHY Extended Status Register */ regv = read_PHY (PHY_REG_SCSR); /* PHY Extended Status Register */
// Now configure for full/half duplex mode // Now configure for full/half duplex mode
if (regv & (1<<4)) { /* bit 4: 1 = Full Duplex, 0 = Half Duplex */ if (regv & (1<<4)) { /* bit 4: 1 = Full Duplex, 0 = Half Duplex */
// We are in full duplex is enabled mode // We are in full duplex is enabled mode
LPC_ETHERNET->MAC_CONFIG |= MAC_DUPMODE; LPC_ETHERNET->MAC_CONFIG |= MAC_DUPMODE;
} }
// Now configure 100MBit or 10MBit mode // Now configure 100MBit or 10MBit mode
if (regv & (1<<3)) { /* bit 3: 1 = 100Mbps, 0 = 10Mbps */ if (regv & (1<<3)) { /* bit 3: 1 = 100Mbps, 0 = 10Mbps */
// 100MBit mode // 100MBit mode
LPC_ETHERNET->MAC_CONFIG |= MAC_100MPS; LPC_ETHERNET->MAC_CONFIG |= MAC_100MPS;
} }
break; break;
} }
/* Set the Ethernet MAC Address registers */ /* Set the Ethernet MAC Address registers */
LPC_ETHERNET->MAC_ADDR0_HIGH = (MYMAC_6 << 8) | MYMAC_5; LPC_ETHERNET->MAC_ADDR0_HIGH = (MYMAC_6 << 8) | MYMAC_5;
LPC_ETHERNET->MAC_ADDR0_LOW = (MYMAC_4 << 24) | (MYMAC_3 << 16) | (MYMAC_2 << 8) | MYMAC_1; LPC_ETHERNET->MAC_ADDR0_LOW = (MYMAC_4 << 24) | (MYMAC_3 << 16) | (MYMAC_2 << 8) | MYMAC_1;
/* Initialize Descriptor Lists */ /* Initialize Descriptor Lists */
rx_descr_init(); rx_descr_init();
tx_descr_init(); tx_descr_init();
/* Configure Filter */ /* Configure Filter */
LPC_ETHERNET->MAC_FRAME_FILTER = MAC_PROMISCUOUS | MAC_RECEIVEALL; LPC_ETHERNET->MAC_FRAME_FILTER = MAC_PROMISCUOUS | MAC_RECEIVEALL;
/* Enable Receiver and Transmitter */ /* Enable Receiver and Transmitter */
LPC_ETHERNET->MAC_CONFIG |= (MAC_TX_ENABLE | MAC_RX_ENABLE); LPC_ETHERNET->MAC_CONFIG |= (MAC_TX_ENABLE | MAC_RX_ENABLE);
/* Enable interrupts */ /* Enable interrupts */
//LPC_ETHERNET->DMA_INT_EN = DMA_INT_NOR_SUM | DMA_INT_RECEIVE | DMA_INT_TRANSMIT; //LPC_ETHERNET->DMA_INT_EN = DMA_INT_NOR_SUM | DMA_INT_RECEIVE | DMA_INT_TRANSMIT;
/* Start Transmission & Receive processes */ /* Start Transmission & Receive processes */
LPC_ETHERNET->DMA_OP_MODE |= (DMA_SS_TRANSMIT | DMA_SS_RECEIVE ); LPC_ETHERNET->DMA_OP_MODE |= (DMA_SS_TRANSMIT | DMA_SS_RECEIVE );
} }
// reads a word in little-endian byte order from RX_BUFFER // reads a word in little-endian byte order from RX_BUFFER
unsigned short ReadFrame_EMAC(void) unsigned short ReadFrame_EMAC(void)
{ {
return (*rptr++); return (*rptr++);
} }
// easyWEB internal function // easyWEB internal function
// help function to swap the byte order of a WORD // help function to swap the byte order of a WORD
unsigned short SwapBytes(unsigned short Data) unsigned short SwapBytes(unsigned short Data)
{ {
return (Data >> 8) | (Data << 8); return (Data >> 8) | (Data << 8);
} }
// reads a word in big-endian byte order from RX_FRAME_PORT // reads a word in big-endian byte order from RX_FRAME_PORT
// (useful to avoid permanent byte-swapping while reading // (useful to avoid permanent byte-swapping while reading
// TCP/IP-data) // TCP/IP-data)
unsigned short ReadFrameBE_EMAC(void) unsigned short ReadFrameBE_EMAC(void)
{ {
unsigned short ReturnValue; unsigned short ReturnValue;
ReturnValue = SwapBytes (*rptr++); ReturnValue = SwapBytes (*rptr++);
return (ReturnValue); return (ReturnValue);
} }
// copies bytes from frame port to MCU-memory // copies bytes from frame port to MCU-memory
// NOTES: * an odd number of byte may only be transfered // NOTES: * an odd number of byte may only be transfered
// if the frame is read to the end! // if the frame is read to the end!
// * MCU-memory MUST start at word-boundary // * MCU-memory MUST start at word-boundary
void CopyFromFrame_EMAC(void *Dest, unsigned short Size) void CopyFromFrame_EMAC(void *Dest, unsigned short Size)
{ {
unsigned short * piDest; // Keil: Pointer added to correct expression unsigned short * piDest; // Keil: Pointer added to correct expression
piDest = Dest; // Keil: Line added piDest = Dest; // Keil: Line added
while (Size > 1) { while (Size > 1) {
*piDest++ = ReadFrame_EMAC(); *piDest++ = ReadFrame_EMAC();
Size -= 2; Size -= 2;
} }
if (Size) { // check for leftover byte... if (Size) { // check for leftover byte...
*(unsigned char *)piDest = (char)ReadFrame_EMAC();// the LAN-Controller will return 0 *(unsigned char *)piDest = (char)ReadFrame_EMAC();// the LAN-Controller will return 0
} // for the highbyte } // for the highbyte
} }
// does a dummy read on frame-I/O-port // does a dummy read on frame-I/O-port
// NOTE: only an even number of bytes is read! // NOTE: only an even number of bytes is read!
void DummyReadFrame_EMAC(unsigned short Size) // discards an EVEN number of bytes void DummyReadFrame_EMAC(unsigned short Size) // discards an EVEN number of bytes
{ // from RX-fifo { // from RX-fifo
while (Size > 1) { while (Size > 1) {
ReadFrame_EMAC(); ReadFrame_EMAC();
Size -= 2; Size -= 2;
} }
} }
// Reads the length of the received ethernet frame and checks if the // Reads the length of the received ethernet frame and checks if the
// destination address is a broadcast message or not // destination address is a broadcast message or not
// returns the frame length // returns the frame length
unsigned short StartReadFrame(void) { unsigned short StartReadFrame(void) {
unsigned short RxLen; unsigned short RxLen;
if ((RX_DESC_STAT(RxDescIndex) & OWN_BIT) == 0) { if ((RX_DESC_STAT(RxDescIndex) & OWN_BIT) == 0) {
RxLen = (RX_DESC_STAT(RxDescIndex) >> 16) & 0x03FFF; RxLen = (RX_DESC_STAT(RxDescIndex) >> 16) & 0x03FFF;
rptr = (unsigned short *)RX_BUFADDR(RxDescIndex); rptr = (unsigned short *)RX_BUFADDR(RxDescIndex);
return(RxLen); return(RxLen);
} }
return 0; return 0;
} }
void EndReadFrame(void) { void EndReadFrame(void) {
RX_DESC_STAT(RxDescIndex) = OWN_BIT; RX_DESC_STAT(RxDescIndex) = OWN_BIT;
RxDescIndex++; RxDescIndex++;
if (RxDescIndex == NUM_RX_DESC) if (RxDescIndex == NUM_RX_DESC)
RxDescIndex = 0; RxDescIndex = 0;
} }
unsigned int CheckFrameReceived(void) { // Packet received ? unsigned int CheckFrameReceived(void) { // Packet received ?
if ((RX_DESC_STAT(RxDescIndex) & OWN_BIT) == 0) if ((RX_DESC_STAT(RxDescIndex) & OWN_BIT) == 0)
return(1); return(1);
else else
return(0); return(0);
} }
// requests space in EMAC memory for storing an outgoing frame // requests space in EMAC memory for storing an outgoing frame
void RequestSend(unsigned short FrameSize) void RequestSend(unsigned short FrameSize)
{ {
tptr = (unsigned short *)TX_BUFADDR(TxDescIndex); tptr = (unsigned short *)TX_BUFADDR(TxDescIndex);
TX_DESC_CTRL(TxDescIndex) = FrameSize; TX_DESC_CTRL(TxDescIndex) = FrameSize;
} }
// check if ethernet controller is ready to accept the // check if ethernet controller is ready to accept the
// frame we want to send // frame we want to send
unsigned int Rdy4Tx(void) unsigned int Rdy4Tx(void)
{ {
return (1); // the ethernet controller transmits much faster return (1); // the ethernet controller transmits much faster
} // than the CPU can load its buffers } // than the CPU can load its buffers
// writes a word in little-endian byte order to TX_BUFFER // writes a word in little-endian byte order to TX_BUFFER
void WriteFrame_EMAC(unsigned short Data) void WriteFrame_EMAC(unsigned short Data)
{ {
*tptr++ = Data; *tptr++ = Data;
} }
// copies bytes from MCU-memory to frame port // copies bytes from MCU-memory to frame port
// NOTES: * an odd number of byte may only be transfered // NOTES: * an odd number of byte may only be transfered
// if the frame is written to the end! // if the frame is written to the end!
// * MCU-memory MUST start at word-boundary // * MCU-memory MUST start at word-boundary
void CopyToFrame_EMAC(void *Source, unsigned int Size) void CopyToFrame_EMAC(void *Source, unsigned int Size)
{ {
unsigned short * piSource; unsigned short * piSource;
// unsigned int idx; // unsigned int idx;
piSource = Source; piSource = Source;
Size = (Size + 1) & 0xFFFE; // round Size up to next even number Size = (Size + 1) & 0xFFFE; // round Size up to next even number
while (Size > 0) { while (Size > 0) {
WriteFrame_EMAC(*piSource++); WriteFrame_EMAC(*piSource++);
Size -= 2; Size -= 2;
} }
TX_DESC_STAT(TxDescIndex) |= OWN_BIT; TX_DESC_STAT(TxDescIndex) |= OWN_BIT;
LPC_ETHERNET->DMA_TRANS_POLL_DEMAND = 1; // Wake Up the DMA if it's in Suspended Mode LPC_ETHERNET->DMA_TRANS_POLL_DEMAND = 1; // Wake Up the DMA if it's in Suspended Mode
TxDescIndex++; TxDescIndex++;
if (TxDescIndex == NUM_TX_DESC) if (TxDescIndex == NUM_TX_DESC)
TxDescIndex = 0; TxDescIndex = 0;
} }
#endif #endif

View File

@ -1,157 +1,157 @@
#ifndef __EMAC_H #ifndef __EMAC_H
#define __EMAC_H #define __EMAC_H
/* Configuration */ /* Configuration */
/* Interface Selection */ /* Interface Selection */
#define MII 0 // =0 RMII - =1 MII #define MII 0 // =0 RMII - =1 MII
/* MAC Configuration */ /* MAC Configuration */
#define MYMAC_1 0x1EU /* our ethernet (MAC) address */ #define MYMAC_1 0x1EU /* our ethernet (MAC) address */
#define MYMAC_2 0x30U /* (MUST be unique in LAN!) */ #define MYMAC_2 0x30U /* (MUST be unique in LAN!) */
#define MYMAC_3 0x6cU #define MYMAC_3 0x6cU
#define MYMAC_4 0xa2U #define MYMAC_4 0xa2U
#define MYMAC_5 0x45U #define MYMAC_5 0x45U
#define MYMAC_6 0x5eU #define MYMAC_6 0x5eU
#define ETH_FRAG_SIZE 1536 #define ETH_FRAG_SIZE 1536
#define NUM_RX_DESC 3 #define NUM_RX_DESC 3
#define NUM_TX_DESC 3 #define NUM_TX_DESC 3
/* End of Configuration */ /* End of Configuration */
/* EMAC Descriptors and Buffers located in 16K SRAM */ /* EMAC Descriptors and Buffers located in 16K SRAM */
/* Rx Descriptors */ /* Rx Descriptors */
#define RX_DESC_BASE 0x20008000 #define RX_DESC_BASE 0x20008000
#define RX_STAT_BASE RX_DESC_BASE #define RX_STAT_BASE RX_DESC_BASE
#define RX_CTRL_BASE (RX_STAT_BASE + 4) #define RX_CTRL_BASE (RX_STAT_BASE + 4)
#define RX_BUFADDR_BASE (RX_CTRL_BASE + 4) #define RX_BUFADDR_BASE (RX_CTRL_BASE + 4)
#define RX_NEXTDESC_BASE (RX_BUFADDR_BASE + 4) #define RX_NEXTDESC_BASE (RX_BUFADDR_BASE + 4)
#define RX_BUF_BASE (RX_DESC_BASE + NUM_RX_DESC*16) #define RX_BUF_BASE (RX_DESC_BASE + NUM_RX_DESC*16)
#define RX_DESC_STAT(i) (*(unsigned int *)(RX_STAT_BASE + 16*i)) #define RX_DESC_STAT(i) (*(unsigned int *)(RX_STAT_BASE + 16*i))
#define RX_DESC_CTRL(i) (*(unsigned int *)(RX_CTRL_BASE + 16*i)) #define RX_DESC_CTRL(i) (*(unsigned int *)(RX_CTRL_BASE + 16*i))
#define RX_BUFADDR(i) (*(unsigned int *)(RX_BUFADDR_BASE + 16*i)) #define RX_BUFADDR(i) (*(unsigned int *)(RX_BUFADDR_BASE + 16*i))
#define RX_NEXTDESC(i) (*(unsigned int *)(RX_NEXTDESC_BASE + 16*i)) #define RX_NEXTDESC(i) (*(unsigned int *)(RX_NEXTDESC_BASE + 16*i))
#define RX_BUF(i) (RX_BUF_BASE + ETH_FRAG_SIZE*i) #define RX_BUF(i) (RX_BUF_BASE + ETH_FRAG_SIZE*i)
/* Tx Descriptors */ /* Tx Descriptors */
#define TX_DESC_BASE RX_BUF_BASE + (ETH_FRAG_SIZE * NUM_RX_DESC) #define TX_DESC_BASE RX_BUF_BASE + (ETH_FRAG_SIZE * NUM_RX_DESC)
#define TX_STAT_BASE TX_DESC_BASE #define TX_STAT_BASE TX_DESC_BASE
#define TX_CTRL_BASE (TX_STAT_BASE + 4) #define TX_CTRL_BASE (TX_STAT_BASE + 4)
#define TX_BUFADDR_BASE (TX_CTRL_BASE + 4) #define TX_BUFADDR_BASE (TX_CTRL_BASE + 4)
#define TX_NEXTDESC_BASE (TX_BUFADDR_BASE + 4) #define TX_NEXTDESC_BASE (TX_BUFADDR_BASE + 4)
#define TX_BUF_BASE (TX_DESC_BASE + NUM_TX_DESC*16) #define TX_BUF_BASE (TX_DESC_BASE + NUM_TX_DESC*16)
#define TX_DESC_STAT(i) (*(unsigned int *)(TX_STAT_BASE + 16*i)) #define TX_DESC_STAT(i) (*(unsigned int *)(TX_STAT_BASE + 16*i))
#define TX_DESC_CTRL(i) (*(unsigned int *)(TX_CTRL_BASE + 16*i)) #define TX_DESC_CTRL(i) (*(unsigned int *)(TX_CTRL_BASE + 16*i))
#define TX_BUFADDR(i) (*(unsigned int *)(TX_BUFADDR_BASE + 16*i)) #define TX_BUFADDR(i) (*(unsigned int *)(TX_BUFADDR_BASE + 16*i))
#define TX_NEXTDESC(i) (*(unsigned int *)(TX_NEXTDESC_BASE + 16*i)) #define TX_NEXTDESC(i) (*(unsigned int *)(TX_NEXTDESC_BASE + 16*i))
#define TX_BUF(i) (TX_BUF_BASE + ETH_FRAG_SIZE*i) #define TX_BUF(i) (TX_BUF_BASE + ETH_FRAG_SIZE*i)
/* Descriptors Fields bits */ /* Descriptors Fields bits */
#define OWN_BIT (1U<<31) /* Own bit in RDES0 & TDES0 */ #define OWN_BIT (1U<<31) /* Own bit in RDES0 & TDES0 */
#define RX_END_RING (1<<15) /* Receive End of Ring bit in RDES1 */ #define RX_END_RING (1<<15) /* Receive End of Ring bit in RDES1 */
#define RX_NXTDESC_FLAG (1<<14) /* Second Address Chained bit in RDES1 */ #define RX_NXTDESC_FLAG (1<<14) /* Second Address Chained bit in RDES1 */
#define TX_LAST_SEGM (1<<29) /* Last Segment bit in TDES0 */ #define TX_LAST_SEGM (1<<29) /* Last Segment bit in TDES0 */
#define TX_FIRST_SEGM (1<<28) /* First Segment bit in TDES0 */ #define TX_FIRST_SEGM (1<<28) /* First Segment bit in TDES0 */
#define TX_END_RING (1<<21) /* Transmit End of Ring bit in TDES0 */ #define TX_END_RING (1<<21) /* Transmit End of Ring bit in TDES0 */
#define TX_NXTDESC_FLAG (1<<20) /* Second Address Chained bit in TDES0 */ #define TX_NXTDESC_FLAG (1<<20) /* Second Address Chained bit in TDES0 */
/* EMAC Control and Status bits */ /* EMAC Control and Status bits */
#define MAC_RX_ENABLE (1<<2) /* Receiver Enable in MAC_CONFIG reg */ #define MAC_RX_ENABLE (1<<2) /* Receiver Enable in MAC_CONFIG reg */
#define MAC_TX_ENABLE (1<<3) /* Transmitter Enable in MAC_CONFIG reg */ #define MAC_TX_ENABLE (1<<3) /* Transmitter Enable in MAC_CONFIG reg */
#define MAC_PADCRC_STRIP (1<<7) /* Automatic Pad-CRC Stripping in MAC_CONFIG reg */ #define MAC_PADCRC_STRIP (1<<7) /* Automatic Pad-CRC Stripping in MAC_CONFIG reg */
#define MAC_DUPMODE (1<<11) /* Duplex Mode in MAC_CONFIG reg */ #define MAC_DUPMODE (1<<11) /* Duplex Mode in MAC_CONFIG reg */
#define MAC_100MPS (1<<14) /* Speed is 100Mbps in MAC_CONFIG reg */ #define MAC_100MPS (1<<14) /* Speed is 100Mbps in MAC_CONFIG reg */
#define MAC_PROMISCUOUS (1U<<0) /* Promiscuous Mode bit in MAC_FRAME_FILTER reg */ #define MAC_PROMISCUOUS (1U<<0) /* Promiscuous Mode bit in MAC_FRAME_FILTER reg */
#define MAC_DIS_BROAD (1U<<5) /* Disable Broadcast Frames bit in MAC_FRAME_FILTER reg */ #define MAC_DIS_BROAD (1U<<5) /* Disable Broadcast Frames bit in MAC_FRAME_FILTER reg */
#define MAC_RECEIVEALL (1U<<31) /* Receive All bit in MAC_FRAME_FILTER reg */ #define MAC_RECEIVEALL (1U<<31) /* Receive All bit in MAC_FRAME_FILTER reg */
#define DMA_SOFT_RESET 0x01 /* Software Reset bit in DMA_BUS_MODE reg */ #define DMA_SOFT_RESET 0x01 /* Software Reset bit in DMA_BUS_MODE reg */
#define DMA_SS_RECEIVE (1<<1) /* Start/Stop Receive bit in DMA_OP_MODE reg */ #define DMA_SS_RECEIVE (1<<1) /* Start/Stop Receive bit in DMA_OP_MODE reg */
#define DMA_SS_TRANSMIT (1<<13) /* Start/Stop Transmission bit in DMA_OP_MODE reg */ #define DMA_SS_TRANSMIT (1<<13) /* Start/Stop Transmission bit in DMA_OP_MODE reg */
#define DMA_INT_TRANSMIT (1<<0) /* Transmit Interrupt Enable bit in DMA_INT_EN reg */ #define DMA_INT_TRANSMIT (1<<0) /* Transmit Interrupt Enable bit in DMA_INT_EN reg */
#define DMA_INT_OVERFLOW (1<<4) /* Overflow Interrupt Enable bit in DMA_INT_EN reg */ #define DMA_INT_OVERFLOW (1<<4) /* Overflow Interrupt Enable bit in DMA_INT_EN reg */
#define DMA_INT_UNDERFLW (1<<5) /* Underflow Interrupt Enable bit in DMA_INT_EN reg */ #define DMA_INT_UNDERFLW (1<<5) /* Underflow Interrupt Enable bit in DMA_INT_EN reg */
#define DMA_INT_RECEIVE (1<<6) /* Receive Interrupt Enable bit in DMA_INT_EN reg */ #define DMA_INT_RECEIVE (1<<6) /* Receive Interrupt Enable bit in DMA_INT_EN reg */
#define DMA_INT_ABN_SUM (1<<15) /* Abnormal Interrupt Summary Enable bit in DMA_INT_EN reg */ #define DMA_INT_ABN_SUM (1<<15) /* Abnormal Interrupt Summary Enable bit in DMA_INT_EN reg */
#define DMA_INT_NOR_SUM (1<<16) /* Normal Interrupt Summary Enable bit in DMA_INT_EN reg */ #define DMA_INT_NOR_SUM (1<<16) /* Normal Interrupt Summary Enable bit in DMA_INT_EN reg */
/* MII Management Command Register */ /* MII Management Command Register */
#define GMII_READ (0<<1) /* GMII Read PHY */ #define GMII_READ (0<<1) /* GMII Read PHY */
#define GMII_WRITE (1<<1) /* GMII Write PHY */ #define GMII_WRITE (1<<1) /* GMII Write PHY */
#define GMII_BUSY 0x00000001 /* GMII is Busy / Start Read/Write */ #define GMII_BUSY 0x00000001 /* GMII is Busy / Start Read/Write */
#define MII_WR_TOUT 0x00050000 /* MII Write timeout count */ #define MII_WR_TOUT 0x00050000 /* MII Write timeout count */
#define MII_RD_TOUT 0x00050000 /* MII Read timeout count */ #define MII_RD_TOUT 0x00050000 /* MII Read timeout count */
/* MII Management Address Register */ /* MII Management Address Register */
#define MADR_PHY_ADR 0x00001F00 /* PHY Address Mask */ #define MADR_PHY_ADR 0x00001F00 /* PHY Address Mask */
/* DP83848C PHY Registers */ /* DP83848C PHY Registers */
#define PHY_REG_BMCR 0x00 /* Basic Mode Control Register */ #define PHY_REG_BMCR 0x00 /* Basic Mode Control Register */
#define PHY_REG_BMSR 0x01 /* Basic Mode Status Register */ #define PHY_REG_BMSR 0x01 /* Basic Mode Status Register */
#define PHY_REG_IDR1 0x02 /* PHY Identifier 1 */ #define PHY_REG_IDR1 0x02 /* PHY Identifier 1 */
#define PHY_REG_IDR2 0x03 /* PHY Identifier 2 */ #define PHY_REG_IDR2 0x03 /* PHY Identifier 2 */
#define PHY_REG_ANAR 0x04 /* Auto-Negotiation Advertisement */ #define PHY_REG_ANAR 0x04 /* Auto-Negotiation Advertisement */
#define PHY_REG_ANLPAR 0x05 /* Auto-Neg. Link Partner Abitily */ #define PHY_REG_ANLPAR 0x05 /* Auto-Neg. Link Partner Abitily */
#define PHY_REG_ANER 0x06 /* Auto-Neg. Expansion Register */ #define PHY_REG_ANER 0x06 /* Auto-Neg. Expansion Register */
#define PHY_REG_ANNPTR 0x07 /* Auto-Neg. Next Page TX */ #define PHY_REG_ANNPTR 0x07 /* Auto-Neg. Next Page TX */
/* PHY Extended Registers */ /* PHY Extended Registers */
#define PHY_REG_STS 0x10 /* Status Register */ #define PHY_REG_STS 0x10 /* Status Register */
#define PHY_REG_MICR 0x11 /* MII Interrupt Control Register */ #define PHY_REG_MICR 0x11 /* MII Interrupt Control Register */
#define PHY_REG_MISR 0x12 /* MII Interrupt Status Register */ #define PHY_REG_MISR 0x12 /* MII Interrupt Status Register */
#define PHY_REG_FCSCR 0x14 /* False Carrier Sense Counter */ #define PHY_REG_FCSCR 0x14 /* False Carrier Sense Counter */
#define PHY_REG_RECR 0x15 /* Receive Error Counter */ #define PHY_REG_RECR 0x15 /* Receive Error Counter */
#define PHY_REG_PCSR 0x16 /* PCS Sublayer Config. and Status */ #define PHY_REG_PCSR 0x16 /* PCS Sublayer Config. and Status */
#define PHY_REG_RBR 0x17 /* RMII and Bypass Register */ #define PHY_REG_RBR 0x17 /* RMII and Bypass Register */
#define PHY_REG_LEDCR 0x18 /* LED Direct Control Register */ #define PHY_REG_LEDCR 0x18 /* LED Direct Control Register */
#define PHY_REG_PHYCR 0x19 /* PHY Control Register */ #define PHY_REG_PHYCR 0x19 /* PHY Control Register */
#define PHY_REG_10BTSCR 0x1A /* 10Base-T Status/Control Register */ #define PHY_REG_10BTSCR 0x1A /* 10Base-T Status/Control Register */
#define PHY_REG_CDCTRL1 0x1B /* CD Test Control and BIST Extens. */ #define PHY_REG_CDCTRL1 0x1B /* CD Test Control and BIST Extens. */
#define PHY_REG_EDCR 0x1D /* Energy Detect Control Register */ #define PHY_REG_EDCR 0x1D /* Energy Detect Control Register */
/* PHY Control and Status bits */ /* PHY Control and Status bits */
#define PHY_FULLD_100M 0x2100 /* Full Duplex 100Mbit */ #define PHY_FULLD_100M 0x2100 /* Full Duplex 100Mbit */
#define PHY_HALFD_100M 0x2000 /* Half Duplex 100Mbit */ #define PHY_HALFD_100M 0x2000 /* Half Duplex 100Mbit */
#define PHY_FULLD_10M 0x0100 /* Full Duplex 10Mbit */ #define PHY_FULLD_10M 0x0100 /* Full Duplex 10Mbit */
#define PHY_HALFD_10M 0x0000 /* Half Duplex 10MBit */ #define PHY_HALFD_10M 0x0000 /* Half Duplex 10MBit */
#define PHY_AUTO_NEG 0x1000 /* Select Auto Negotiation */ #define PHY_AUTO_NEG 0x1000 /* Select Auto Negotiation */
#define PHY_AUTO_NEG_DONE 0x0020 /* AutoNegotiation Complete in BMSR PHY reg */ #define PHY_AUTO_NEG_DONE 0x0020 /* AutoNegotiation Complete in BMSR PHY reg */
#define PHY_BMCR_RESET 0x8000 /* Reset bit at BMCR PHY reg */ #define PHY_BMCR_RESET 0x8000 /* Reset bit at BMCR PHY reg */
#define LINK_VALID_STS 0x0001 /* Link Valid Status at REG_STS PHY reg */ #define LINK_VALID_STS 0x0001 /* Link Valid Status at REG_STS PHY reg */
#define FULL_DUP_STS 0x0004 /* Full Duplex Status at REG_STS PHY reg */ #define FULL_DUP_STS 0x0004 /* Full Duplex Status at REG_STS PHY reg */
#define SPEED_10M_STS 0x0002 /* 10Mbps Status at REG_STS PHY reg */ #define SPEED_10M_STS 0x0002 /* 10Mbps Status at REG_STS PHY reg */
#define DP83848C_DEF_ADR 0x01 /* Default PHY device address */ #define DP83848C_DEF_ADR 0x01 /* Default PHY device address */
#define DP83848C_ID 0x20005C90 /* PHY Identifier (without Rev. info */ #define DP83848C_ID 0x20005C90 /* PHY Identifier (without Rev. info */
#define LAN8720_ID 0x0007C0F0 /* PHY Identifier */ #define LAN8720_ID 0x0007C0F0 /* PHY Identifier */
#define PHY_REG_SCSR 0x1F /* PHY Special Control/Status Register */ #define PHY_REG_SCSR 0x1F /* PHY Special Control/Status Register */
/* Misc */ /* Misc */
#define ETHERNET_RST 22 /* Reset Output for EMAC at RGU */ #define ETHERNET_RST 22 /* Reset Output for EMAC at RGU */
#define RMII_SELECT 0x04 /* Select RMII in EMACCFG */ #define RMII_SELECT 0x04 /* Select RMII in EMACCFG */
/* Prototypes */ /* Prototypes */
void Init_EMAC(void); void Init_EMAC(void);
unsigned short ReadFrameBE_EMAC(void); unsigned short ReadFrameBE_EMAC(void);
void CopyToFrame_EMAC(void *Source, unsigned int Size); void CopyToFrame_EMAC(void *Source, unsigned int Size);
void CopyFromFrame_EMAC(void *Dest, unsigned short Size); void CopyFromFrame_EMAC(void *Dest, unsigned short Size);
void DummyReadFrame_EMAC(unsigned short Size); void DummyReadFrame_EMAC(unsigned short Size);
unsigned short StartReadFrame(void); unsigned short StartReadFrame(void);
void EndReadFrame(void); void EndReadFrame(void);
unsigned int CheckFrameReceived(void); unsigned int CheckFrameReceived(void);
void RequestSend(unsigned short FrameSize); void RequestSend(unsigned short FrameSize);
unsigned int Rdy4Tx(void); unsigned int Rdy4Tx(void);
#endif #endif

View File

@ -1,36 +1,36 @@
/***************************************************************************** /*****************************************************************************
* *
* Copyright(C) 2011, Embedded Artists AB * Copyright(C) 2011, Embedded Artists AB
* All rights reserved. * All rights reserved.
* *
****************************************************************************** ******************************************************************************
* Software that is described herein is for illustrative purposes only * Software that is described herein is for illustrative purposes only
* which provides customers with programming information regarding the * which provides customers with programming information regarding the
* products. This software is supplied "AS IS" without any warranties. * products. This software is supplied "AS IS" without any warranties.
* Embedded Artists AB assumes no responsibility or liability for the * Embedded Artists AB assumes no responsibility or liability for the
* use of the software, conveys no license or title under any patent, * use of the software, conveys no license or title under any patent,
* copyright, or mask work right to the product. Embedded Artists AB * copyright, or mask work right to the product. Embedded Artists AB
* reserves the right to make changes in the software without * reserves the right to make changes in the software without
* notification. Embedded Artists AB also make no representation or * notification. Embedded Artists AB also make no representation or
* warranty that such application will be suitable for the specified * warranty that such application will be suitable for the specified
* use without further testing or modification. * use without further testing or modification.
*****************************************************************************/ *****************************************************************************/
#ifndef __NAND_H #ifndef __NAND_H
#define __NAND_H #define __NAND_H
#define NAND_NUM_BLOCKS (1024) #define NAND_NUM_BLOCKS (1024)
extern uint32_t nand_init (void); extern uint32_t nand_init (void);
extern uint32_t nand_getPageSize(void); extern uint32_t nand_getPageSize(void);
extern uint32_t nand_getBlockSize(void); extern uint32_t nand_getBlockSize(void);
extern uint32_t nand_getRedundantSize(void); extern uint32_t nand_getRedundantSize(void);
extern uint32_t nand_isBlockValid(uint32_t blockNum); extern uint32_t nand_isBlockValid(uint32_t blockNum);
uint32_t nand_readPage(uint32_t block, uint32_t page, uint8_t* pageBuf); uint32_t nand_readPage(uint32_t block, uint32_t page, uint8_t* pageBuf);
uint32_t nand_writePage(uint32_t block, uint32_t page, uint8_t* pageBuf); uint32_t nand_writePage(uint32_t block, uint32_t page, uint8_t* pageBuf);
uint32_t nand_eraseBlock(uint32_t block); uint32_t nand_eraseBlock(uint32_t block);
#endif /* end __NAND_H */ #endif /* end __NAND_H */
/**************************************************************************** /****************************************************************************
** End Of File ** End Of File
*****************************************************************************/ *****************************************************************************/

View File

@ -1,272 +1,272 @@
/***************************************************************************** /*****************************************************************************
* *
* Copyright(C) 2011, Embedded Artists AB * Copyright(C) 2011, Embedded Artists AB
* All rights reserved. * All rights reserved.
* *
****************************************************************************** ******************************************************************************
* Software that is described herein is for illustrative purposes only * Software that is described herein is for illustrative purposes only
* which provides customers with programming information regarding the * which provides customers with programming information regarding the
* products. This software is supplied "AS IS" without any warranties. * products. This software is supplied "AS IS" without any warranties.
* Embedded Artists AB assumes no responsibility or liability for the * Embedded Artists AB assumes no responsibility or liability for the
* use of the software, conveys no license or title under any patent, * use of the software, conveys no license or title under any patent,
* copyright, or mask work right to the product. Embedded Artists AB * copyright, or mask work right to the product. Embedded Artists AB
* reserves the right to make changes in the software without * reserves the right to make changes in the software without
* notification. Embedded Artists AB also make no representation or * notification. Embedded Artists AB also make no representation or
* warranty that such application will be suitable for the specified * warranty that such application will be suitable for the specified
* use without further testing or modification. * use without further testing or modification.
*****************************************************************************/ *****************************************************************************/
/****************************************************************************** /******************************************************************************
* Includes * Includes
*****************************************************************************/ *****************************************************************************/
#include "../../board.h" #include "../../board.h"
#if BOARD == BOARD_EA4357 #if BOARD == BOARD_EA4357
#include "LPC43xx.h" #include "LPC43xx.h"
#include "lpc_types.h" #include "lpc_types.h"
#include "lpc43xx_scu.h" #include "lpc43xx_scu.h"
#include "lpc43xx_timer.h" #include "lpc43xx_timer.h"
#include "lpc43xx_cgu.h" #include "lpc43xx_cgu.h"
#include "sdram.h" #include "sdram.h"
#include <string.h> #include <string.h>
/****************************************************************************** /******************************************************************************
* Defines and typedefs * Defines and typedefs
*****************************************************************************/ *****************************************************************************/
/* SDRAM refresh time to 16 clock num */ /* SDRAM refresh time to 16 clock num */
#define EMC_SDRAM_REFRESH(freq,time) \ #define EMC_SDRAM_REFRESH(freq,time) \
(((uint64_t)((uint64_t)time * freq)/16000000000ull)+1) (((uint64_t)((uint64_t)time * freq)/16000000000ull)+1)
/****************************************************************************** /******************************************************************************
* External global variables * External global variables
*****************************************************************************/ *****************************************************************************/
/****************************************************************************** /******************************************************************************
* Local variables * Local variables
*****************************************************************************/ *****************************************************************************/
/****************************************************************************** /******************************************************************************
* Local Functions * Local Functions
*****************************************************************************/ *****************************************************************************/
/*-------------------------PRIVATE FUNCTIONS------------------------------*/ /*-------------------------PRIVATE FUNCTIONS------------------------------*/
/********************************************************************* /*********************************************************************
* @brief Calculate EMC Clock from nano second * @brief Calculate EMC Clock from nano second
* @param[in] freq - frequency of EMC Clk * @param[in] freq - frequency of EMC Clk
* @param[in] time - nano second * @param[in] time - nano second
* @return None * @return None
**********************************************************************/ **********************************************************************/
uint32_t NS2CLK(uint32_t freq, uint32_t time){ uint32_t NS2CLK(uint32_t freq, uint32_t time){
return (((uint64_t)time*freq/1000000000)); return (((uint64_t)time*freq/1000000000));
} }
static void pinConfig(void) static void pinConfig(void)
{ {
/* Set up EMC pin */ /* Set up EMC pin */
scu_pinmux( 2 , 9 , MD_PLN_FAST , 3 );//A0 scu_pinmux( 2 , 9 , MD_PLN_FAST , 3 );//A0
scu_pinmux( 2 , 10 , MD_PLN_FAST , 3 );//A1 scu_pinmux( 2 , 10 , MD_PLN_FAST , 3 );//A1
scu_pinmux( 2 , 11 , MD_PLN_FAST , 3 );//A2 scu_pinmux( 2 , 11 , MD_PLN_FAST , 3 );//A2
scu_pinmux( 2 , 12 , MD_PLN_FAST , 3 );//A3 scu_pinmux( 2 , 12 , MD_PLN_FAST , 3 );//A3
scu_pinmux( 2 , 13 , MD_PLN_FAST , 3 );//A4 scu_pinmux( 2 , 13 , MD_PLN_FAST , 3 );//A4
scu_pinmux( 1 , 0 , MD_PLN_FAST , 2 );//A5 scu_pinmux( 1 , 0 , MD_PLN_FAST , 2 );//A5
scu_pinmux( 1 , 1 , MD_PLN_FAST , 2 );//A6 scu_pinmux( 1 , 1 , MD_PLN_FAST , 2 );//A6
scu_pinmux( 1 , 2 , MD_PLN_FAST , 2 );//A7 scu_pinmux( 1 , 2 , MD_PLN_FAST , 2 );//A7
scu_pinmux( 2 , 8 , MD_PLN_FAST , 3 );//A8 scu_pinmux( 2 , 8 , MD_PLN_FAST , 3 );//A8
scu_pinmux( 2 , 7 , MD_PLN_FAST , 3 );//A9 scu_pinmux( 2 , 7 , MD_PLN_FAST , 3 );//A9
scu_pinmux( 2 , 6 , MD_PLN_FAST , 2 );//A10 scu_pinmux( 2 , 6 , MD_PLN_FAST , 2 );//A10
scu_pinmux( 2 , 2 , MD_PLN_FAST , 2 );//A11 scu_pinmux( 2 , 2 , MD_PLN_FAST , 2 );//A11
scu_pinmux( 2 , 1 , MD_PLN_FAST , 2 );//A12 scu_pinmux( 2 , 1 , MD_PLN_FAST , 2 );//A12
scu_pinmux( 2 , 0 , MD_PLN_FAST , 2 );//A13 scu_pinmux( 2 , 0 , MD_PLN_FAST , 2 );//A13
scu_pinmux( 6 , 8 , MD_PLN_FAST , 1 );//A14 scu_pinmux( 6 , 8 , MD_PLN_FAST , 1 );//A14
scu_pinmux( 6 , 7 , MD_PLN_FAST , 1 );//A15 scu_pinmux( 6 , 7 , MD_PLN_FAST , 1 );//A15
scu_pinmux( 13 , 16 , MD_PLN_FAST , 2 );//A16 scu_pinmux( 13 , 16 , MD_PLN_FAST , 2 );//A16
scu_pinmux( 13 , 15 , MD_PLN_FAST , 2 );//A17 scu_pinmux( 13 , 15 , MD_PLN_FAST , 2 );//A17
scu_pinmux( 14 , 0 , MD_PLN_FAST , 3 );//A18 scu_pinmux( 14 , 0 , MD_PLN_FAST , 3 );//A18
scu_pinmux( 14 , 1 , MD_PLN_FAST , 3 );//A19 scu_pinmux( 14 , 1 , MD_PLN_FAST , 3 );//A19
scu_pinmux( 14 , 2 , MD_PLN_FAST , 3 );//A20 scu_pinmux( 14 , 2 , MD_PLN_FAST , 3 );//A20
scu_pinmux( 14 , 3 , MD_PLN_FAST , 3 );//A21 scu_pinmux( 14 , 3 , MD_PLN_FAST , 3 );//A21
scu_pinmux( 14 , 4 , MD_PLN_FAST , 3 );//A22 scu_pinmux( 14 , 4 , MD_PLN_FAST , 3 );//A22
scu_pinmux( 10 , 4 , MD_PLN_FAST , 3 );//A23 scu_pinmux( 10 , 4 , MD_PLN_FAST , 3 );//A23
scu_pinmux( 1 , 7 , MD_PLN_FAST , 3 );//D0 scu_pinmux( 1 , 7 , MD_PLN_FAST , 3 );//D0
scu_pinmux( 1 , 8 , MD_PLN_FAST , 3 );//D1 scu_pinmux( 1 , 8 , MD_PLN_FAST , 3 );//D1
scu_pinmux( 1 , 9 , MD_PLN_FAST , 3 );//D2 scu_pinmux( 1 , 9 , MD_PLN_FAST , 3 );//D2
scu_pinmux( 1 , 10 , MD_PLN_FAST , 3 );//D3 scu_pinmux( 1 , 10 , MD_PLN_FAST , 3 );//D3
scu_pinmux( 1 , 11 , MD_PLN_FAST , 3 );//D4 scu_pinmux( 1 , 11 , MD_PLN_FAST , 3 );//D4
scu_pinmux( 1 , 12 , MD_PLN_FAST , 3 );//D5 scu_pinmux( 1 , 12 , MD_PLN_FAST , 3 );//D5
scu_pinmux( 1 , 13 , MD_PLN_FAST , 3 );//D6 scu_pinmux( 1 , 13 , MD_PLN_FAST , 3 );//D6
scu_pinmux( 1 , 14 , MD_PLN_FAST , 3 );//D7 scu_pinmux( 1 , 14 , MD_PLN_FAST , 3 );//D7
scu_pinmux( 5 , 4 , MD_PLN_FAST , 2 );//D8 scu_pinmux( 5 , 4 , MD_PLN_FAST , 2 );//D8
scu_pinmux( 5 , 5 , MD_PLN_FAST , 2 );//D9 scu_pinmux( 5 , 5 , MD_PLN_FAST , 2 );//D9
scu_pinmux( 5 , 6 , MD_PLN_FAST , 2 );//D10 scu_pinmux( 5 , 6 , MD_PLN_FAST , 2 );//D10
scu_pinmux( 5 , 7 , MD_PLN_FAST , 2 );//D11 scu_pinmux( 5 , 7 , MD_PLN_FAST , 2 );//D11
scu_pinmux( 5 , 0 , MD_PLN_FAST , 2 );//D12 scu_pinmux( 5 , 0 , MD_PLN_FAST , 2 );//D12
scu_pinmux( 5 , 1 , MD_PLN_FAST , 2 );//D13 scu_pinmux( 5 , 1 , MD_PLN_FAST , 2 );//D13
scu_pinmux( 5 , 2 , MD_PLN_FAST , 2 );//D14 scu_pinmux( 5 , 2 , MD_PLN_FAST , 2 );//D14
scu_pinmux( 5 , 3 , MD_PLN_FAST , 2 );//D15 scu_pinmux( 5 , 3 , MD_PLN_FAST , 2 );//D15
scu_pinmux( 13 , 2 , MD_PLN_FAST , 2 );//D16 scu_pinmux( 13 , 2 , MD_PLN_FAST , 2 );//D16
scu_pinmux( 13 , 3 , MD_PLN_FAST , 2 );//D17 scu_pinmux( 13 , 3 , MD_PLN_FAST , 2 );//D17
scu_pinmux( 13 , 4 , MD_PLN_FAST , 2 );//D18 scu_pinmux( 13 , 4 , MD_PLN_FAST , 2 );//D18
scu_pinmux( 13 , 5 , MD_PLN_FAST , 2 );//D19 scu_pinmux( 13 , 5 , MD_PLN_FAST , 2 );//D19
scu_pinmux( 13 , 6 , MD_PLN_FAST , 2 );//D20 scu_pinmux( 13 , 6 , MD_PLN_FAST , 2 );//D20
scu_pinmux( 13 , 7 , MD_PLN_FAST , 2 );//D21 scu_pinmux( 13 , 7 , MD_PLN_FAST , 2 );//D21
scu_pinmux( 13 , 8 , MD_PLN_FAST , 2 );//D22 scu_pinmux( 13 , 8 , MD_PLN_FAST , 2 );//D22
scu_pinmux( 13 , 9 , MD_PLN_FAST , 2 );//D23 scu_pinmux( 13 , 9 , MD_PLN_FAST , 2 );//D23
scu_pinmux( 14 , 5 , MD_PLN_FAST , 3 );//D24 scu_pinmux( 14 , 5 , MD_PLN_FAST , 3 );//D24
scu_pinmux( 14 , 6 , MD_PLN_FAST , 3 );//D25 scu_pinmux( 14 , 6 , MD_PLN_FAST , 3 );//D25
scu_pinmux( 14 , 7 , MD_PLN_FAST , 3 );//D26 scu_pinmux( 14 , 7 , MD_PLN_FAST , 3 );//D26
scu_pinmux( 14 , 8 , MD_PLN_FAST , 3 );//D27 scu_pinmux( 14 , 8 , MD_PLN_FAST , 3 );//D27
scu_pinmux( 14 , 9 , MD_PLN_FAST , 3 );//D28 scu_pinmux( 14 , 9 , MD_PLN_FAST , 3 );//D28
scu_pinmux( 14 , 10 , MD_PLN_FAST , 3 );//D29 scu_pinmux( 14 , 10 , MD_PLN_FAST , 3 );//D29
scu_pinmux( 14 , 11 , MD_PLN_FAST , 3 );//D30 scu_pinmux( 14 , 11 , MD_PLN_FAST , 3 );//D30
scu_pinmux( 14 , 12 , MD_PLN_FAST , 3 );//D31 scu_pinmux( 14 , 12 , MD_PLN_FAST , 3 );//D31
scu_pinmux( 1 , 3 , MD_PLN_FAST , 3 );//OE scu_pinmux( 1 , 3 , MD_PLN_FAST , 3 );//OE
scu_pinmux( 1 , 6 , MD_PLN_FAST , 3 );//WE scu_pinmux( 1 , 6 , MD_PLN_FAST , 3 );//WE
scu_pinmux( 1 , 4 , MD_PLN_FAST , 3 );//BLS0 scu_pinmux( 1 , 4 , MD_PLN_FAST , 3 );//BLS0
scu_pinmux( 6 , 6 , MD_PLN_FAST , 1 );//BLS1 scu_pinmux( 6 , 6 , MD_PLN_FAST , 1 );//BLS1
scu_pinmux( 13 , 13 , MD_PLN_FAST , 2 );//BLS2 scu_pinmux( 13 , 13 , MD_PLN_FAST , 2 );//BLS2
scu_pinmux( 13 , 10 , MD_PLN_FAST , 2 );//BLS3 scu_pinmux( 13 , 10 , MD_PLN_FAST , 2 );//BLS3
scu_pinmux( 1 , 5 , MD_PLN_FAST , 3 );//CS0 scu_pinmux( 1 , 5 , MD_PLN_FAST , 3 );//CS0
scu_pinmux( 6 , 3 , MD_PLN_FAST , 3 );//CS1 scu_pinmux( 6 , 3 , MD_PLN_FAST , 3 );//CS1
scu_pinmux( 13 , 12 , MD_PLN_FAST , 2 );//CS2 scu_pinmux( 13 , 12 , MD_PLN_FAST , 2 );//CS2
scu_pinmux( 13 , 11 , MD_PLN_FAST , 2 );//CS3 scu_pinmux( 13 , 11 , MD_PLN_FAST , 2 );//CS3
scu_pinmux( 6 , 4 , MD_PLN_FAST , 3 );//CAS scu_pinmux( 6 , 4 , MD_PLN_FAST , 3 );//CAS
scu_pinmux( 6 , 5 , MD_PLN_FAST , 3 );//RAS scu_pinmux( 6 , 5 , MD_PLN_FAST , 3 );//RAS
scu_pinmux( 6 , 9 , MD_PLN_FAST , 3 );//DYCS0 scu_pinmux( 6 , 9 , MD_PLN_FAST , 3 );//DYCS0
scu_pinmux( 6 , 1 , MD_PLN_FAST , 1 );//DYCS1 scu_pinmux( 6 , 1 , MD_PLN_FAST , 1 );//DYCS1
scu_pinmux( 13 , 14 , MD_PLN_FAST , 2 );//DYCS2 scu_pinmux( 13 , 14 , MD_PLN_FAST , 2 );//DYCS2
scu_pinmux( 15 , 14 , MD_PLN_FAST , 3 );//DYCS3 scu_pinmux( 15 , 14 , MD_PLN_FAST , 3 );//DYCS3
scu_pinmux( 6 , 11 , MD_PLN_FAST , 3 );//CKEOUT0 scu_pinmux( 6 , 11 , MD_PLN_FAST , 3 );//CKEOUT0
scu_pinmux( 6 , 2 , MD_PLN_FAST , 1 );//CKEOUT1 scu_pinmux( 6 , 2 , MD_PLN_FAST , 1 );//CKEOUT1
scu_pinmux( 13 , 1 , MD_PLN_FAST , 2 );//CKEOUT2 scu_pinmux( 13 , 1 , MD_PLN_FAST , 2 );//CKEOUT2
scu_pinmux( 14 , 15 , MD_PLN_FAST , 3 );//CKEOUT3 scu_pinmux( 14 , 15 , MD_PLN_FAST , 3 );//CKEOUT3
scu_pinmux( 6 , 12 , MD_PLN_FAST , 3 );//DQMOUT0 scu_pinmux( 6 , 12 , MD_PLN_FAST , 3 );//DQMOUT0
scu_pinmux( 6 , 10 , MD_PLN_FAST , 3 );//DQMOUT1 scu_pinmux( 6 , 10 , MD_PLN_FAST , 3 );//DQMOUT1
scu_pinmux( 13 , 0 , MD_PLN_FAST , 2 );//DQMOUT2 scu_pinmux( 13 , 0 , MD_PLN_FAST , 2 );//DQMOUT2
scu_pinmux( 14 , 13 , MD_PLN_FAST , 3 );//DQMOUT3 scu_pinmux( 14 , 13 , MD_PLN_FAST , 3 );//DQMOUT3
} }
/****************************************************************************** /******************************************************************************
* Public Functions * Public Functions
*****************************************************************************/ *****************************************************************************/
/****************************************************************************** /******************************************************************************
* *
* Description: * Description:
* Initialize the SDRAM * Initialize the SDRAM
* *
*****************************************************************************/ *****************************************************************************/
uint32_t sdram_init (void) uint32_t sdram_init (void)
{ {
uint32_t pclk, temp; uint32_t pclk, temp;
uint64_t tmpclk; uint64_t tmpclk;
pinConfig(); //Full 32-bit Data bus, 24-bit Address pinConfig(); //Full 32-bit Data bus, 24-bit Address
/* Select EMC clock-out */ /* Select EMC clock-out */
LPC_SCU->SFSCLK_0 = MD_PLN_FAST; LPC_SCU->SFSCLK_0 = MD_PLN_FAST;
LPC_SCU->SFSCLK_1 = MD_PLN_FAST; LPC_SCU->SFSCLK_1 = MD_PLN_FAST;
LPC_SCU->SFSCLK_2 = MD_PLN_FAST; LPC_SCU->SFSCLK_2 = MD_PLN_FAST;
LPC_SCU->SFSCLK_3 = MD_PLN_FAST; LPC_SCU->SFSCLK_3 = MD_PLN_FAST;
LPC_EMC->CONTROL = 0x00000001; LPC_EMC->CONTROL = 0x00000001;
LPC_EMC->CONFIG = 0x00000000; LPC_EMC->CONFIG = 0x00000000;
LPC_EMC->DYNAMICCONFIG0 = 1<<14 | 0<<12 | 2<<9 | 1<<7; /* 256Mb, 8Mx32, 4 banks, row=12, column=9 */ LPC_EMC->DYNAMICCONFIG0 = 1<<14 | 0<<12 | 2<<9 | 1<<7; /* 256Mb, 8Mx32, 4 banks, row=12, column=9 */
pclk = CGU_GetPCLKFrequency(CGU_PERIPHERAL_M4CORE); pclk = CGU_GetPCLKFrequency(CGU_PERIPHERAL_M4CORE);
LPC_EMC->DYNAMICRASCAS0 = 0x00000202; /* 2 RAS, 2 CAS latency */ LPC_EMC->DYNAMICRASCAS0 = 0x00000202; /* 2 RAS, 2 CAS latency */
LPC_EMC->DYNAMICREADCONFIG = 0x00000001; /* Command delayed strategy, using EMCCLKDELAY */ LPC_EMC->DYNAMICREADCONFIG = 0x00000001; /* Command delayed strategy, using EMCCLKDELAY */
LPC_EMC->DYNAMICRP = NS2CLK(pclk, 20); LPC_EMC->DYNAMICRP = NS2CLK(pclk, 20);
LPC_EMC->DYNAMICRAS = NS2CLK(pclk, 42); LPC_EMC->DYNAMICRAS = NS2CLK(pclk, 42);
LPC_EMC->DYNAMICSREX = NS2CLK(pclk, 63); LPC_EMC->DYNAMICSREX = NS2CLK(pclk, 63);
LPC_EMC->DYNAMICAPR = 0x00000005; LPC_EMC->DYNAMICAPR = 0x00000005;
LPC_EMC->DYNAMICDAL = 0x00000005; LPC_EMC->DYNAMICDAL = 0x00000005;
LPC_EMC->DYNAMICWR = 2; LPC_EMC->DYNAMICWR = 2;
LPC_EMC->DYNAMICRC = NS2CLK(pclk, 63); LPC_EMC->DYNAMICRC = NS2CLK(pclk, 63);
LPC_EMC->DYNAMICRFC = NS2CLK(pclk, 63); LPC_EMC->DYNAMICRFC = NS2CLK(pclk, 63);
LPC_EMC->DYNAMICXSR = NS2CLK(pclk, 63); LPC_EMC->DYNAMICXSR = NS2CLK(pclk, 63);
LPC_EMC->DYNAMICRRD = NS2CLK(pclk, 14); LPC_EMC->DYNAMICRRD = NS2CLK(pclk, 14);
LPC_EMC->DYNAMICMRD = 0x00000002; LPC_EMC->DYNAMICMRD = 0x00000002;
TIM_Waitus(100); /* wait 100ms */ TIM_Waitus(100); /* wait 100ms */
LPC_EMC->DYNAMICCONTROL = 0x00000183; /* Issue NOP command */ LPC_EMC->DYNAMICCONTROL = 0x00000183; /* Issue NOP command */
TIM_Waitus(200); /* wait 200ms */ TIM_Waitus(200); /* wait 200ms */
LPC_EMC->DYNAMICCONTROL = 0x00000103; /* Issue PALL command */ LPC_EMC->DYNAMICCONTROL = 0x00000103; /* Issue PALL command */
LPC_EMC->DYNAMICREFRESH = EMC_SDRAM_REFRESH(pclk,70); /* ( n * 16 ) -> 32 clock cycles */ LPC_EMC->DYNAMICREFRESH = EMC_SDRAM_REFRESH(pclk,70); /* ( n * 16 ) -> 32 clock cycles */
//for(i = 0; i < 0x80; i++); /* wait 128 AHB clock cycles */ //for(i = 0; i < 0x80; i++); /* wait 128 AHB clock cycles */
TIM_Waitus(200); /* wait 200ms */ TIM_Waitus(200); /* wait 200ms */
tmpclk = (uint64_t)15625*(uint64_t)pclk/1000000000/16; tmpclk = (uint64_t)15625*(uint64_t)pclk/1000000000/16;
LPC_EMC->DYNAMICREFRESH = tmpclk; /* ( n * 16 ) -> 736 clock cycles -> 15.330uS at 48MHz <= 15.625uS ( 64ms / 4096 row ) */ LPC_EMC->DYNAMICREFRESH = tmpclk; /* ( n * 16 ) -> 736 clock cycles -> 15.330uS at 48MHz <= 15.625uS ( 64ms / 4096 row ) */
LPC_EMC->DYNAMICCONTROL = 0x00000083; /* Issue MODE command */ LPC_EMC->DYNAMICCONTROL = 0x00000083; /* Issue MODE command */
//Timing for 48/60/72MHZ Bus //Timing for 48/60/72MHZ Bus
temp = *((volatile uint32_t *)(SDRAM_BASE | (2<<4| 2)<<(9+2+2))); /* 4 burst, 2 CAS latency */ temp = *((volatile uint32_t *)(SDRAM_BASE | (2<<4| 2)<<(9+2+2))); /* 4 burst, 2 CAS latency */
temp = temp; temp = temp;
LPC_EMC->DYNAMICCONTROL = 0x00000000; /* Issue NORMAL command */ LPC_EMC->DYNAMICCONTROL = 0x00000000; /* Issue NORMAL command */
//[re]enable buffers //[re]enable buffers
LPC_EMC->DYNAMICCONFIG0 |= 1<<19; LPC_EMC->DYNAMICCONFIG0 |= 1<<19;
return TRUE; return TRUE;
} }
uint32_t sdram_test( void ) uint32_t sdram_test( void )
{ {
volatile uint32_t *wr_ptr; volatile uint32_t *wr_ptr;
volatile uint16_t *short_wr_ptr; volatile uint16_t *short_wr_ptr;
uint32_t data; uint32_t data;
uint32_t i, j; uint32_t i, j;
wr_ptr = (uint32_t *)SDRAM_BASE; wr_ptr = (uint32_t *)SDRAM_BASE;
short_wr_ptr = (uint16_t *)wr_ptr; short_wr_ptr = (uint16_t *)wr_ptr;
/* 16 bit write */ /* 16 bit write */
for (i = 0; i < SDRAM_SIZE/0x40000; i++) for (i = 0; i < SDRAM_SIZE/0x40000; i++)
{ {
for (j = 0; j < 0x100; j++) for (j = 0; j < 0x100; j++)
{ {
*short_wr_ptr++ = (i + j) & 0xFFFF; *short_wr_ptr++ = (i + j) & 0xFFFF;
*short_wr_ptr++ = ((i + j) + 1) & 0xFFFF; *short_wr_ptr++ = ((i + j) + 1) & 0xFFFF;
} }
} }
/* Verifying */ /* Verifying */
wr_ptr = (uint32_t *)SDRAM_BASE; wr_ptr = (uint32_t *)SDRAM_BASE;
for (i = 0; i < SDRAM_SIZE/0x40000; i++) for (i = 0; i < SDRAM_SIZE/0x40000; i++)
{ {
for (j = 0; j < 0x100; j++) for (j = 0; j < 0x100; j++)
{ {
data = *wr_ptr; data = *wr_ptr;
if (data != (((((i + j) + 1) & 0xFFFF) << 16) | ((i + j) & 0xFFFF))) if (data != (((((i + j) + 1) & 0xFFFF) << 16) | ((i + j) & 0xFFFF)))
{ {
return 0x0; return 0x0;
} }
wr_ptr++; wr_ptr++;
} }
} }
return 0x1; return 0x1;
} }
#endif #endif

View File

@ -1,31 +1,31 @@
/***************************************************************************** /*****************************************************************************
* *
* Copyright(C) 2011, Embedded Artists AB * Copyright(C) 2011, Embedded Artists AB
* All rights reserved. * All rights reserved.
* *
****************************************************************************** ******************************************************************************
* Software that is described herein is for illustrative purposes only * Software that is described herein is for illustrative purposes only
* which provides customers with programming information regarding the * which provides customers with programming information regarding the
* products. This software is supplied "AS IS" without any warranties. * products. This software is supplied "AS IS" without any warranties.
* Embedded Artists AB assumes no responsibility or liability for the * Embedded Artists AB assumes no responsibility or liability for the
* use of the software, conveys no license or title under any patent, * use of the software, conveys no license or title under any patent,
* copyright, or mask work right to the product. Embedded Artists AB * copyright, or mask work right to the product. Embedded Artists AB
* reserves the right to make changes in the software without * reserves the right to make changes in the software without
* notification. Embedded Artists AB also make no representation or * notification. Embedded Artists AB also make no representation or
* warranty that such application will be suitable for the specified * warranty that such application will be suitable for the specified
* use without further testing or modification. * use without further testing or modification.
*****************************************************************************/ *****************************************************************************/
#ifndef __SDRAM_H #ifndef __SDRAM_H
#define __SDRAM_H #define __SDRAM_H
#define SDRAM_SIZE 0x2000000 /* 256Mbit = 32MB */ #define SDRAM_SIZE 0x2000000 /* 256Mbit = 32MB */
#define SDRAM_BASE 0x28000000 /*CS0*/ #define SDRAM_BASE 0x28000000 /*CS0*/
extern uint32_t sdram_init(void); extern uint32_t sdram_init(void);
extern uint32_t sdram_test(void); extern uint32_t sdram_test(void);
#endif /* end __SDRAM_H */ #endif /* end __SDRAM_H */
/**************************************************************************** /****************************************************************************
** End Of File ** End Of File
*****************************************************************************/ *****************************************************************************/

View File

@ -1,349 +1,349 @@
/***************************************************************************** /*****************************************************************************
* *
* Copyright(C) 2011, Embedded Artists AB * Copyright(C) 2011, Embedded Artists AB
* All rights reserved. * All rights reserved.
* *
****************************************************************************** ******************************************************************************
* Software that is described herein is for illustrative purposes only * Software that is described herein is for illustrative purposes only
* which provides customers with programming information regarding the * which provides customers with programming information regarding the
* products. This software is supplied "AS IS" without any warranties. * products. This software is supplied "AS IS" without any warranties.
* Embedded Artists AB assumes no responsibility or liability for the * Embedded Artists AB assumes no responsibility or liability for the
* use of the software, conveys no license or title under any patent, * use of the software, conveys no license or title under any patent,
* copyright, or mask work right to the product. Embedded Artists AB * copyright, or mask work right to the product. Embedded Artists AB
* reserves the right to make changes in the software without * reserves the right to make changes in the software without
* notification. Embedded Artists AB also make no representation or * notification. Embedded Artists AB also make no representation or
* warranty that such application will be suitable for the specified * warranty that such application will be suitable for the specified
* use without further testing or modification. * use without further testing or modification.
*****************************************************************************/ *****************************************************************************/
/* /*
* NOTE: I2C must have been initialized before calling any functions in this * NOTE: I2C must have been initialized before calling any functions in this
* file. * file.
*/ */
/****************************************************************************** /******************************************************************************
* Includes * Includes
*****************************************************************************/ *****************************************************************************/
#include "../../board.h" #include "../../board.h"
#if BOARD == BOARD_EA4357 #if BOARD == BOARD_EA4357
#include "lpc43xx_i2c.h" #include "lpc43xx_i2c.h"
#include "lpc43xx_cgu.h" #include "lpc43xx_cgu.h"
#include "lpc_types.h" #include "lpc_types.h"
#include "pca9532.h" #include "pca9532.h"
/****************************************************************************** /******************************************************************************
* Defines and typedefs * Defines and typedefs
*****************************************************************************/ *****************************************************************************/
#define I2C_PORT (LPC_I2C0) #define I2C_PORT (LPC_I2C0)
#define LS_MODE_ON 0x01 #define LS_MODE_ON 0x01
#define LS_MODE_BLINK0 0x02 #define LS_MODE_BLINK0 0x02
#define LS_MODE_BLINK1 0x03 #define LS_MODE_BLINK1 0x03
/****************************************************************************** /******************************************************************************
* External global variables * External global variables
*****************************************************************************/ *****************************************************************************/
/****************************************************************************** /******************************************************************************
* Local variables * Local variables
*****************************************************************************/ *****************************************************************************/
static uint16_t blink0Shadow = 0; static uint16_t blink0Shadow = 0;
static uint16_t blink1Shadow = 0; static uint16_t blink1Shadow = 0;
static uint16_t ledStateShadow = 0; static uint16_t ledStateShadow = 0;
/****************************************************************************** /******************************************************************************
* Local Functions * Local Functions
*****************************************************************************/ *****************************************************************************/
static Status I2CWrite(uint32_t addr, uint8_t* buf, uint32_t len) static Status I2CWrite(uint32_t addr, uint8_t* buf, uint32_t len)
{ {
I2C_M_SETUP_Type i2cData; I2C_M_SETUP_Type i2cData;
i2cData.sl_addr7bit = addr; i2cData.sl_addr7bit = addr;
i2cData.tx_data = buf; i2cData.tx_data = buf;
i2cData.tx_length = len; i2cData.tx_length = len;
i2cData.rx_data = NULL; i2cData.rx_data = NULL;
i2cData.rx_length = 0; i2cData.rx_length = 0;
i2cData.retransmissions_max = 3; i2cData.retransmissions_max = 3;
return I2C_MasterTransferData(I2C_PORT, &i2cData, I2C_TRANSFER_POLLING); return I2C_MasterTransferData(I2C_PORT, &i2cData, I2C_TRANSFER_POLLING);
} }
static Status I2CRead(uint32_t addr, uint8_t* buf, uint32_t len) static Status I2CRead(uint32_t addr, uint8_t* buf, uint32_t len)
{ {
I2C_M_SETUP_Type i2cData; I2C_M_SETUP_Type i2cData;
i2cData.sl_addr7bit = addr; i2cData.sl_addr7bit = addr;
i2cData.tx_data = NULL; i2cData.tx_data = NULL;
i2cData.tx_length = 0; i2cData.tx_length = 0;
i2cData.rx_data = buf; i2cData.rx_data = buf;
i2cData.rx_length = len; i2cData.rx_length = len;
i2cData.retransmissions_max = 3; i2cData.retransmissions_max = 3;
return I2C_MasterTransferData(I2C_PORT, &i2cData, I2C_TRANSFER_POLLING); return I2C_MasterTransferData(I2C_PORT, &i2cData, I2C_TRANSFER_POLLING);
} }
static void setLsStates(uint16_t states, uint8_t* ls, uint8_t mode) static void setLsStates(uint16_t states, uint8_t* ls, uint8_t mode)
{ {
#define IS_LED_SET(bit, x) ( ( ((x) & (bit)) != 0 ) ? 1 : 0 ) #define IS_LED_SET(bit, x) ( ( ((x) & (bit)) != 0 ) ? 1 : 0 )
int i = 0; int i = 0;
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
ls[i] |= ( (IS_LED_SET(0x0001, states)*mode << 0) ls[i] |= ( (IS_LED_SET(0x0001, states)*mode << 0)
| (IS_LED_SET(0x0002, states)*mode << 2) | (IS_LED_SET(0x0002, states)*mode << 2)
| (IS_LED_SET(0x0004, states)*mode << 4) | (IS_LED_SET(0x0004, states)*mode << 4)
| (IS_LED_SET(0x0008, states)*mode << 6) ); | (IS_LED_SET(0x0008, states)*mode << 6) );
states >>= 4; states >>= 4;
} }
} }
static void setLeds(void) static void setLeds(void)
{ {
uint8_t buf[5]; uint8_t buf[5];
uint8_t ls[4] = {0,0,0,0}; uint8_t ls[4] = {0,0,0,0};
uint16_t states = ledStateShadow; uint16_t states = ledStateShadow;
/* LEDs in On/Off state */ /* LEDs in On/Off state */
setLsStates(states, ls, LS_MODE_ON); setLsStates(states, ls, LS_MODE_ON);
/* set the LEDs that should blink */ /* set the LEDs that should blink */
setLsStates(blink0Shadow, ls, LS_MODE_BLINK0); setLsStates(blink0Shadow, ls, LS_MODE_BLINK0);
setLsStates(blink1Shadow, ls, LS_MODE_BLINK1); setLsStates(blink1Shadow, ls, LS_MODE_BLINK1);
buf[0] = PCA9532_LS0 | PCA9532_AUTO_INC; buf[0] = PCA9532_LS0 | PCA9532_AUTO_INC;
buf[1] = ls[0]; buf[1] = ls[0];
buf[2] = ls[1]; buf[2] = ls[1];
buf[3] = ls[2]; buf[3] = ls[2];
buf[4] = ls[3]; buf[4] = ls[3];
I2CWrite(PCA9532_I2C_ADDR, buf, 5); I2CWrite(PCA9532_I2C_ADDR, buf, 5);
} }
/****************************************************************************** /******************************************************************************
* Public Functions * Public Functions
*****************************************************************************/ *****************************************************************************/
/****************************************************************************** /******************************************************************************
* *
* Description: * Description:
* Initialize the PCA9532 Device * Initialize the PCA9532 Device
* *
*****************************************************************************/ *****************************************************************************/
void pca9532_init (void) void pca9532_init (void)
{ {
/* nothing to initialize */ /* nothing to initialize */
} }
/****************************************************************************** /******************************************************************************
* *
* Description: * Description:
* Get the LED states * Get the LED states
* *
* Params: * Params:
* [in] shadow - TRUE if the states should be retrieved from the shadow * [in] shadow - TRUE if the states should be retrieved from the shadow
* variables. The shadow variable are updated when any * variables. The shadow variable are updated when any
* of setLeds, setBlink0Leds and/or setBlink1Leds are * of setLeds, setBlink0Leds and/or setBlink1Leds are
* called. * called.
* *
* FALSE if the state should be retrieved from the PCA9532 * FALSE if the state should be retrieved from the PCA9532
* device. A blinkin LED may be reported as on or off * device. A blinkin LED may be reported as on or off
* depending on the state when calling the function. * depending on the state when calling the function.
* *
* Returns: * Returns:
* A mask where a 1 indicates that a LED is on (or blinking). * A mask where a 1 indicates that a LED is on (or blinking).
* *
*****************************************************************************/ *****************************************************************************/
uint16_t pca9532_getLedState (uint32_t shadow) uint16_t pca9532_getLedState (uint32_t shadow)
{ {
uint8_t buf[2]; uint8_t buf[2];
uint16_t ret = 0; uint16_t ret = 0;
if (shadow) { if (shadow) {
/* a blink LED is reported as on*/ /* a blink LED is reported as on*/
ret = (ledStateShadow | blink0Shadow | blink1Shadow); ret = (ledStateShadow | blink0Shadow | blink1Shadow);
} }
else { else {
/* /*
* A blinking LED may be reported as on or off depending on * A blinking LED may be reported as on or off depending on
* its state when reading the Input register. * its state when reading the Input register.
*/ */
buf[0] = PCA9532_INPUT0; buf[0] = PCA9532_INPUT0;
I2CWrite(PCA9532_I2C_ADDR, buf, 1); I2CWrite(PCA9532_I2C_ADDR, buf, 1);
I2CRead(PCA9532_I2C_ADDR, buf, 1); I2CRead(PCA9532_I2C_ADDR, buf, 1);
ret = buf[0]; ret = buf[0];
buf[0] = PCA9532_INPUT1; buf[0] = PCA9532_INPUT1;
I2CWrite(PCA9532_I2C_ADDR, buf, 1); I2CWrite(PCA9532_I2C_ADDR, buf, 1);
I2CRead(PCA9532_I2C_ADDR, buf, 1); I2CRead(PCA9532_I2C_ADDR, buf, 1);
ret |= (buf[0] << 8); ret |= (buf[0] << 8);
/* invert since LEDs are active low */ /* invert since LEDs are active low */
ret = ((~ret) & 0xFFFF); ret = ((~ret) & 0xFFFF);
} }
return (ret & ~PCA9532_NOT_USED); return (ret & ~PCA9532_NOT_USED);
} }
/****************************************************************************** /******************************************************************************
* *
* Description: * Description:
* Set LED states (on or off). * Set LED states (on or off).
* *
* Params: * Params:
* [in] ledOnMask - The LEDs that should be turned on. This mask has * [in] ledOnMask - The LEDs that should be turned on. This mask has
* priority over ledOffMask * priority over ledOffMask
* [in] ledOffMask - The LEDs that should be turned off. * [in] ledOffMask - The LEDs that should be turned off.
* *
*****************************************************************************/ *****************************************************************************/
void pca9532_setLeds (uint16_t ledOnMask, uint16_t ledOffMask) void pca9532_setLeds (uint16_t ledOnMask, uint16_t ledOffMask)
{ {
/* turn off leds */ /* turn off leds */
ledStateShadow &= (~(ledOffMask) & 0xffff); ledStateShadow &= (~(ledOffMask) & 0xffff);
/* ledOnMask has priority over ledOffMask */ /* ledOnMask has priority over ledOffMask */
ledStateShadow |= ledOnMask; ledStateShadow |= ledOnMask;
/* turn off blinking */ /* turn off blinking */
blink0Shadow &= (~(ledOffMask) & 0xffff); blink0Shadow &= (~(ledOffMask) & 0xffff);
blink1Shadow &= (~(ledOffMask) & 0xffff); blink1Shadow &= (~(ledOffMask) & 0xffff);
setLeds(); setLeds();
} }
/****************************************************************************** /******************************************************************************
* *
* Description: * Description:
* Set the blink period for PWM0. Valid values are 0 - 255 where 0 * Set the blink period for PWM0. Valid values are 0 - 255 where 0
* means 152 Hz and 255 means 0.59 Hz. A value of 151 means 1 Hz. * means 152 Hz and 255 means 0.59 Hz. A value of 151 means 1 Hz.
* *
* Params: * Params:
* [in] period - the period for pwm0 * [in] period - the period for pwm0
* *
*****************************************************************************/ *****************************************************************************/
void pca9532_setBlink0Period(uint8_t period) void pca9532_setBlink0Period(uint8_t period)
{ {
uint8_t buf[2]; uint8_t buf[2];
buf[0] = PCA9532_PSC0; buf[0] = PCA9532_PSC0;
buf[1] = period; buf[1] = period;
I2CWrite(PCA9532_I2C_ADDR, buf, 2); I2CWrite(PCA9532_I2C_ADDR, buf, 2);
} }
/****************************************************************************** /******************************************************************************
* *
* Description: * Description:
* Set the duty cycle for PWM0. Valid values are 0 - 100. 25 means the LED * Set the duty cycle for PWM0. Valid values are 0 - 100. 25 means the LED
* is on 25% of the period. * is on 25% of the period.
* *
* Params: * Params:
* [in] duty - duty cycle * [in] duty - duty cycle
* *
*****************************************************************************/ *****************************************************************************/
void pca9532_setBlink0Duty(uint8_t duty) void pca9532_setBlink0Duty(uint8_t duty)
{ {
uint8_t buf[2]; uint8_t buf[2];
uint32_t tmp = duty; uint32_t tmp = duty;
if (tmp > 100) { if (tmp > 100) {
tmp = 100; tmp = 100;
} }
tmp = (256 * tmp)/100; tmp = (256 * tmp)/100;
buf[0] = PCA9532_PWM0; buf[0] = PCA9532_PWM0;
buf[1] = tmp; buf[1] = tmp;
I2CWrite(PCA9532_I2C_ADDR, buf, 2); I2CWrite(PCA9532_I2C_ADDR, buf, 2);
} }
/****************************************************************************** /******************************************************************************
* *
* Description: * Description:
* Set the LEDs that should blink with rate and duty cycle from PWM0. * Set the LEDs that should blink with rate and duty cycle from PWM0.
* Blinking is turned off with pca9532_setLeds. * Blinking is turned off with pca9532_setLeds.
* *
* Params: * Params:
* [in] ledMask - LEDs that should blink. * [in] ledMask - LEDs that should blink.
* *
*****************************************************************************/ *****************************************************************************/
void pca9532_setBlink0Leds(uint16_t ledMask) void pca9532_setBlink0Leds(uint16_t ledMask)
{ {
blink0Shadow |= ledMask; blink0Shadow |= ledMask;
setLeds(); setLeds();
} }
/****************************************************************************** /******************************************************************************
* *
* Description: * Description:
* Set the blink period for PWM1. Valid values are 0 - 255 where 0 * Set the blink period for PWM1. Valid values are 0 - 255 where 0
* means 152 Hz and 255 means 0.59 Hz. A value of 151 means 1 Hz. * means 152 Hz and 255 means 0.59 Hz. A value of 151 means 1 Hz.
* *
* Params: * Params:
* [in] period - The period for PWM1 * [in] period - The period for PWM1
* *
*****************************************************************************/ *****************************************************************************/
void pca9532_setBlink1Period(uint8_t period) void pca9532_setBlink1Period(uint8_t period)
{ {
uint8_t buf[2]; uint8_t buf[2];
buf[0] = PCA9532_PSC1; buf[0] = PCA9532_PSC1;
buf[1] = period; buf[1] = period;
I2CWrite(PCA9532_I2C_ADDR, buf, 2); I2CWrite(PCA9532_I2C_ADDR, buf, 2);
} }
/****************************************************************************** /******************************************************************************
* *
* Description: * Description:
* Set the duty cycle for PWM1. Valid values are 0 - 100. 25 means the LED * Set the duty cycle for PWM1. Valid values are 0 - 100. 25 means the LED
* is on 25% of the period. * is on 25% of the period.
* *
* Params: * Params:
* [in] duty - duty cycle. * [in] duty - duty cycle.
* *
*****************************************************************************/ *****************************************************************************/
void pca9532_setBlink1Duty(uint8_t duty) void pca9532_setBlink1Duty(uint8_t duty)
{ {
uint8_t buf[2]; uint8_t buf[2];
uint32_t tmp = duty; uint32_t tmp = duty;
if (tmp > 100) { if (tmp > 100) {
tmp = 100; tmp = 100;
} }
tmp = (256 * tmp)/100; tmp = (256 * tmp)/100;
buf[0] = PCA9532_PWM1; buf[0] = PCA9532_PWM1;
buf[1] = tmp; buf[1] = tmp;
I2CWrite(PCA9532_I2C_ADDR, buf, 2); I2CWrite(PCA9532_I2C_ADDR, buf, 2);
} }
/****************************************************************************** /******************************************************************************
* *
* Description: * Description:
* Set the LEDs that should blink with rate and duty cycle from PWM1. * Set the LEDs that should blink with rate and duty cycle from PWM1.
* Blinking is turned off with pca9532_setLeds. * Blinking is turned off with pca9532_setLeds.
* *
* Params: * Params:
* [in] ledMask - LEDs that should blink. * [in] ledMask - LEDs that should blink.
* *
*****************************************************************************/ *****************************************************************************/
void pca9532_setBlink1Leds(uint16_t ledMask) void pca9532_setBlink1Leds(uint16_t ledMask)
{ {
blink1Shadow |= ledMask; blink1Shadow |= ledMask;
setLeds(); setLeds();
} }
#endif #endif

View File

@ -1,126 +1,126 @@
/**************************************************************************/ /**************************************************************************/
/*! /*!
@file board_lpclink2.c @file board_lpclink2.c
@author hathach (tinyusb.org) @author hathach (tinyusb.org)
@section LICENSE @section LICENSE
Software License Agreement (BSD License) Software License Agreement (BSD License)
Copyright (c) 2013, hathach (tinyusb.org) Copyright (c) 2013, hathach (tinyusb.org)
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met: modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright 1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright 2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holders nor the 3. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission. derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This file is part of the tinyusb stack. This file is part of the tinyusb stack.
*/ */
/**************************************************************************/ /**************************************************************************/
#include "../board.h" #include "../board.h"
#if BOARD == BOARD_LPCLINK2 #if BOARD == BOARD_LPCLINK2
#define BOARD_UART_PORT LPC_USART0 #define BOARD_UART_PORT LPC_USART0
#define BOARD_UART_PIN_PORT 0x0f #define BOARD_UART_PIN_PORT 0x0f
#define BOARD_UART_PIN_TX 10 // PF.10 : UART0_TXD #define BOARD_UART_PIN_TX 10 // PF.10 : UART0_TXD
#define BOARD_UART_PIN_RX 11 // PF.11 : UART0_RXD #define BOARD_UART_PIN_RX 11 // PF.11 : UART0_RXD
#define BOARD_MAX_LEDS 1 #define BOARD_MAX_LEDS 1
const static struct { const static struct {
uint8_t port; uint8_t port;
uint8_t pin; uint8_t pin;
}leds[BOARD_MAX_LEDS] = { {0, 8} }; }leds[BOARD_MAX_LEDS] = { {0, 8} };
void board_init(void) void board_init(void)
{ {
CGU_Init(); CGU_Init();
#if TUSB_CFG_OS == TUSB_OS_NONE // TODO may move to main.c #if TUSB_CFG_OS == TUSB_OS_NONE // TODO may move to main.c
SysTick_Config(CGU_GetPCLKFrequency(CGU_PERIPHERAL_M4CORE) / TUSB_CFG_TICKS_HZ); // 1 msec tick timer SysTick_Config(CGU_GetPCLKFrequency(CGU_PERIPHERAL_M4CORE) / TUSB_CFG_TICKS_HZ); // 1 msec tick timer
#endif #endif
//------------- USB -------------// //------------- USB -------------//
//------------- LED -------------// //------------- LED -------------//
for (uint8_t i=0; i<BOARD_MAX_LEDS; i++) for (uint8_t i=0; i<BOARD_MAX_LEDS; i++)
{ {
scu_pinmux(leds[i].port, leds[i].pin, MD_PUP|MD_EZI|MD_ZI, FUNC0); scu_pinmux(leds[i].port, leds[i].pin, MD_PUP|MD_EZI|MD_ZI, FUNC0);
GPIO_SetDir(leds[i].port, BIT_(leds[i].pin), 1); // output GPIO_SetDir(leds[i].port, BIT_(leds[i].pin), 1); // output
} }
#if CFG_UART_ENABLE #if CFG_UART_ENABLE
//------------- UART -------------// //------------- UART -------------//
scu_pinmux(BOARD_UART_PIN_PORT, BOARD_UART_PIN_TX, MD_PDN, FUNC1); scu_pinmux(BOARD_UART_PIN_PORT, BOARD_UART_PIN_TX, MD_PDN, FUNC1);
scu_pinmux(BOARD_UART_PIN_PORT, BOARD_UART_PIN_RX, MD_PLN | MD_EZI | MD_ZI, FUNC1); scu_pinmux(BOARD_UART_PIN_PORT, BOARD_UART_PIN_RX, MD_PLN | MD_EZI | MD_ZI, FUNC1);
UART_CFG_Type UARTConfigStruct; UART_CFG_Type UARTConfigStruct;
UART_ConfigStructInit(&UARTConfigStruct); UART_ConfigStructInit(&UARTConfigStruct);
UARTConfigStruct.Baud_rate = CFG_UART_BAUDRATE; UARTConfigStruct.Baud_rate = CFG_UART_BAUDRATE;
UARTConfigStruct.Clock_Speed = 0; UARTConfigStruct.Clock_Speed = 0;
UART_Init(BOARD_UART_PORT, &UARTConfigStruct); UART_Init(BOARD_UART_PORT, &UARTConfigStruct);
UART_TxCmd(BOARD_UART_PORT, ENABLE); // Enable UART Transmit UART_TxCmd(BOARD_UART_PORT, ENABLE); // Enable UART Transmit
#endif #endif
} }
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// LEDS // LEDS
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
void board_leds(uint32_t on_mask, uint32_t off_mask) void board_leds(uint32_t on_mask, uint32_t off_mask)
{ {
for (uint32_t i=0; i<BOARD_MAX_LEDS; i++) for (uint32_t i=0; i<BOARD_MAX_LEDS; i++)
{ {
if ( on_mask & BIT_(i)) if ( on_mask & BIT_(i))
{ {
GPIO_SetValue(leds[i].port, BIT_(leds[i].pin)); GPIO_SetValue(leds[i].port, BIT_(leds[i].pin));
}else if ( off_mask & BIT_(i)) // on_mask take precedence over off_mask }else if ( off_mask & BIT_(i)) // on_mask take precedence over off_mask
{ {
GPIO_ClearValue(leds[i].port, BIT_(leds[i].pin)); GPIO_ClearValue(leds[i].port, BIT_(leds[i].pin));
} }
} }
} }
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// UART // UART
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
#if CFG_UART_ENABLE #if CFG_UART_ENABLE
uint32_t board_uart_send(uint8_t *buffer, uint32_t length) uint32_t board_uart_send(uint8_t *buffer, uint32_t length)
{ {
return UART_Send(BOARD_UART_PORT, buffer, length, BLOCKING); return UART_Send(BOARD_UART_PORT, buffer, length, BLOCKING);
} }
uint32_t board_uart_recv(uint8_t *buffer, uint32_t length) uint32_t board_uart_recv(uint8_t *buffer, uint32_t length)
{ {
return UART_Receive(BOARD_UART_PORT, buffer, length, BLOCKING); return UART_Receive(BOARD_UART_PORT, buffer, length, BLOCKING);
} }
uint8_t board_uart_getchar(void) uint8_t board_uart_getchar(void)
{ {
return UART_ReceiveByte(BOARD_UART_PORT); return UART_ReceiveByte(BOARD_UART_PORT);
} }
#endif #endif
#endif #endif

View File

@ -1,59 +1,59 @@
/**************************************************************************/ /**************************************************************************/
/*! /*!
@file board_lpclink2.h @file board_lpclink2.h
@author hathach (tinyusb.org) @author hathach (tinyusb.org)
@section LICENSE @section LICENSE
Software License Agreement (BSD License) Software License Agreement (BSD License)
Copyright (c) 2013, hathach (tinyusb.org) Copyright (c) 2013, hathach (tinyusb.org)
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met: modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright 1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright 2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holders nor the 3. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission. derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This file is part of the tinyusb stack. This file is part of the tinyusb stack.
*/ */
/**************************************************************************/ /**************************************************************************/
#ifndef _TUSB_BOARD_LPCLINK2_H_ #ifndef _TUSB_BOARD_LPCLINK2_H_
#define _TUSB_BOARD_LPCLINK2_H_ #define _TUSB_BOARD_LPCLINK2_H_
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "LPC43xx.h" #include "LPC43xx.h"
#include "lpc43xx_scu.h" #include "lpc43xx_scu.h"
#include "lpc43xx_cgu.h"a #include "lpc43xx_cgu.h"a
#include "lpc43xx_gpio.h" #include "lpc43xx_gpio.h"
#include "lpc43xx_uart.h" #include "lpc43xx_uart.h"
#include "lpc43xx_i2c.h" #include "lpc43xx_i2c.h"
#define CFG_PRINTF_TARGET PRINTF_TARGET_UART #define CFG_PRINTF_TARGET PRINTF_TARGET_UART
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /* _TUSB_BOARD_LPCLINK2_H_ */ #endif /* _TUSB_BOARD_LPCLINK2_H_ */

View File

@ -1,114 +1,114 @@
/**************************************************************************/ /**************************************************************************/
/*! /*!
@file board_rf1ghznode.c @file board_rf1ghznode.c
@author hathach (tinyusb.org) @author hathach (tinyusb.org)
@section LICENSE @section LICENSE
Software License Agreement (BSD License) Software License Agreement (BSD License)
Copyright (c) 2013, hathach (tinyusb.org) Copyright (c) 2013, hathach (tinyusb.org)
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met: modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright 1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright 2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holders nor the 3. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission. derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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 INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This file is part of the tinyusb stack. This file is part of the tinyusb stack.
*/ */
/**************************************************************************/ /**************************************************************************/
#include "../board.h" #include "../board.h"
#if BOARD == BOARD_LPCXPRESSO11U68 #if BOARD == BOARD_LPCXPRESSO11U68
#define LED_PORT (1) #define LED_PORT (1)
#define LED_PIN (31) #define LED_PIN (31)
#define LED_ON (0) #define LED_ON (0)
#define LED_OFF (1) #define LED_OFF (1)
const static struct { const static struct {
uint8_t port; uint8_t port;
uint8_t pin; uint8_t pin;
} buttons[] = { { 0, 1 } }; } buttons[] = { { 0, 1 } };
enum { enum {
BOARD_BUTTON_COUNT = sizeof(buttons) / sizeof(buttons[0]) BOARD_BUTTON_COUNT = sizeof(buttons) / sizeof(buttons[0])
}; };
void board_init(void) void board_init(void)
{ {
SystemInit(); SystemInit();
#if TUSB_CFG_OS == TUSB_OS_NONE // TODO may move to main.c #if TUSB_CFG_OS == TUSB_OS_NONE // TODO may move to main.c
SysTick_Config(SystemCoreClock / TUSB_CFG_TICKS_HZ); // 1 msec tick timer SysTick_Config(SystemCoreClock / TUSB_CFG_TICKS_HZ); // 1 msec tick timer
#endif #endif
GPIOInit(); GPIOInit();
//------------- LED -------------// //------------- LED -------------//
GPIOSetDir(LED_PORT, LED_PIN, 1); GPIOSetDir(LED_PORT, LED_PIN, 1);
//------------- BUTTON -------------// //------------- BUTTON -------------//
for(uint8_t i=0; i<BOARD_BUTTON_COUNT; i++) GPIOSetDir(buttons[i].port, buttons[i].pin, 0); for(uint8_t i=0; i<BOARD_BUTTON_COUNT; i++) GPIOSetDir(buttons[i].port, buttons[i].pin, 0);
//------------- UART -------------// //------------- UART -------------//
UARTInit(CFG_UART_BAUDRATE); UARTInit(CFG_UART_BAUDRATE);
} }
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// LEDS // LEDS
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
void board_leds(uint32_t on_mask, uint32_t off_mask) void board_leds(uint32_t on_mask, uint32_t off_mask)
{ {
if (on_mask & BIT_(0)) if (on_mask & BIT_(0))
{ {
GPIOSetBitValue(LED_PORT, LED_PIN, LED_ON); GPIOSetBitValue(LED_PORT, LED_PIN, LED_ON);
}else if (off_mask & BIT_(0)) }else if (off_mask & BIT_(0))
{ {
GPIOSetBitValue(LED_PORT, LED_PIN, LED_OFF); GPIOSetBitValue(LED_PORT, LED_PIN, LED_OFF);
} }
} }
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// Buttons // Buttons
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
uint32_t board_buttons(void) uint32_t board_buttons(void)
{ {
// for(uint8_t i=0; i<BOARD_BUTTON_COUNT; i++) GPIOGetPinValue(buttons[i].port, buttons[i].pin); // for(uint8_t i=0; i<BOARD_BUTTON_COUNT; i++) GPIOGetPinValue(buttons[i].port, buttons[i].pin);
return GPIOGetPinValue(buttons[0].port, buttons[0].pin) ? 0 : 1; // button is active low return GPIOGetPinValue(buttons[0].port, buttons[0].pin) ? 0 : 1; // button is active low
} }
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// UART // UART
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
void board_uart_putchar(uint8_t c) void board_uart_putchar(uint8_t c)
{ {
UARTSend(&c, 1); UARTSend(&c, 1);
} }
uint8_t board_uart_getchar(void) uint8_t board_uart_getchar(void)
{ {
// *buffer = get_key(); TODO cannot find available code for uart getchar // *buffer = get_key(); TODO cannot find available code for uart getchar
return 0; return 0;
} }
#endif #endif

View File

@ -1,57 +1,57 @@
/**************************************************************************/ /**************************************************************************/
/*! /*!
@file board_lpcxpresso11u68.h @file board_lpcxpresso11u68.h
@author hathach (tinyusb.org) @author hathach (tinyusb.org)
@section LICENSE @section LICENSE
Software License Agreement (BSD License) Software License Agreement (BSD License)
Copyright (c) 2013, hathach (tinyusb.org) Copyright (c) 2013, hathach (tinyusb.org)
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met: modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright 1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright 2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holders nor the 3. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission. derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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 INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This file is part of the tinyusb stack. This file is part of the tinyusb stack.
*/ */
/**************************************************************************/ /**************************************************************************/
#ifndef _TUSB_BOARD_LPCXPRESSO11U68_H_ #ifndef _TUSB_BOARD_LPCXPRESSO11U68_H_
#define _TUSB_BOARD_LPCXPRESSO11U68_H_ #define _TUSB_BOARD_LPCXPRESSO11U68_H_
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "LPC11Uxx.h" #include "LPC11Uxx.h"
#include "lpc11uxx_gpio.h" #include "lpc11uxx_gpio.h"
#include "lpc11uxx_uart.h" #include "lpc11uxx_uart.h"
//#define CFG_PRINTF_TARGET PRINTF_TARGET_SEMIHOST //#define CFG_PRINTF_TARGET PRINTF_TARGET_SEMIHOST
#define CFG_PRINTF_TARGET PRINTF_TARGET_UART #define CFG_PRINTF_TARGET PRINTF_TARGET_UART
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /* _TUSB_BOARD_LPCXPRESSO11U68_H_ */ #endif /* _TUSB_BOARD_LPCXPRESSO11U68_H_ */

View File

@ -1,132 +1,132 @@
/**************************************************************************/ /**************************************************************************/
/*! /*!
@file board_lpcexpresso1347.c @file board_lpcexpresso1347.c
@author hathach (tinyusb.org) @author hathach (tinyusb.org)
@section LICENSE @section LICENSE
Software License Agreement (BSD License) Software License Agreement (BSD License)
Copyright (c) 2013, hathach (tinyusb.org) Copyright (c) 2013, hathach (tinyusb.org)
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met: modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright 1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright 2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holders nor the 3. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission. derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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 INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This file is part of the tinyusb stack. This file is part of the tinyusb stack.
*/ */
/**************************************************************************/ /**************************************************************************/
#include "../board.h" #include "../board.h"
#if BOARD == BOARD_LPCXPRESSO1347 #if BOARD == BOARD_LPCXPRESSO1347
#define LED_PORT (0) #define LED_PORT (0)
#define LED_PIN (7) #define LED_PIN (7)
#define LED_ON (1) #define LED_ON (1)
#define LED_OFF (0) #define LED_OFF (0)
const static struct { const static struct {
uint8_t port; uint8_t port;
uint8_t pin; uint8_t pin;
} buttons[] = } buttons[] =
{ {
{1, 22 }, // Joystick up {1, 22 }, // Joystick up
{1, 20 }, // Joystick down {1, 20 }, // Joystick down
{1, 23 }, // Joystick left {1, 23 }, // Joystick left
{1, 21 }, // Joystick right {1, 21 }, // Joystick right
{1, 19 }, // Joystick press {1, 19 }, // Joystick press
{0, 1 }, // SW3 {0, 1 }, // SW3
// {1, 4 }, // SW4 (require to remove J28) // {1, 4 }, // SW4 (require to remove J28)
}; };
enum { enum {
BOARD_BUTTON_COUNT = sizeof(buttons) / sizeof(buttons[0]) BOARD_BUTTON_COUNT = sizeof(buttons) / sizeof(buttons[0])
}; };
void board_init(void) void board_init(void)
{ {
SystemInit(); SystemInit();
#if TUSB_CFG_OS == TUSB_OS_NONE // TODO may move to main.c #if TUSB_CFG_OS == TUSB_OS_NONE // TODO may move to main.c
SysTick_Config(SystemCoreClock / TUSB_CFG_TICKS_HZ); // 1 msec tick timer SysTick_Config(SystemCoreClock / TUSB_CFG_TICKS_HZ); // 1 msec tick timer
#endif #endif
GPIOInit(); GPIOInit();
//------------- LED -------------// //------------- LED -------------//
GPIOSetDir(LED_PORT, LED_PIN, 1); GPIOSetDir(LED_PORT, LED_PIN, 1);
//------------- BUTTON -------------// //------------- BUTTON -------------//
for(uint8_t i=0; i<BOARD_BUTTON_COUNT; i++) GPIOSetDir(buttons[i].port, BIT_(buttons[i].pin), 0); for(uint8_t i=0; i<BOARD_BUTTON_COUNT; i++) GPIOSetDir(buttons[i].port, BIT_(buttons[i].pin), 0);
//------------- UART -------------// //------------- UART -------------//
UARTInit(CFG_UART_BAUDRATE); UARTInit(CFG_UART_BAUDRATE);
} }
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// LEDS // LEDS
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
void board_leds(uint32_t on_mask, uint32_t off_mask) void board_leds(uint32_t on_mask, uint32_t off_mask)
{ {
if (on_mask & BIT_(0)) if (on_mask & BIT_(0))
{ {
GPIOSetBitValue(LED_PORT, LED_PIN, LED_ON); GPIOSetBitValue(LED_PORT, LED_PIN, LED_ON);
}else if (off_mask & BIT_(0)) }else if (off_mask & BIT_(0))
{ {
GPIOSetBitValue(LED_PORT, LED_PIN, LED_OFF); GPIOSetBitValue(LED_PORT, LED_PIN, LED_OFF);
} }
} }
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// BUTTONS // BUTTONS
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
static bool button_read(uint8_t id) static bool button_read(uint8_t id)
{ {
return !GPIOGetPinValue(buttons[id].port, buttons[id].pin); // button is active low return !GPIOGetPinValue(buttons[id].port, buttons[id].pin); // button is active low
} }
uint32_t board_buttons(void) uint32_t board_buttons(void)
{ {
uint32_t result = 0; uint32_t result = 0;
for(uint8_t i=0; i<BOARD_BUTTON_COUNT; i++) result |= (button_read(i) ? BIT_(i) : 0); for(uint8_t i=0; i<BOARD_BUTTON_COUNT; i++) result |= (button_read(i) ? BIT_(i) : 0);
return result; return result;
} }
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// UART // UART
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
void board_uart_putchar(uint8_t c) void board_uart_putchar(uint8_t c)
{ {
UARTSend(&c, 1); UARTSend(&c, 1);
} }
uint8_t board_uart_getchar(void) uint8_t board_uart_getchar(void)
{ {
return 0; return 0;
} }
#endif #endif

View File

@ -1,56 +1,56 @@
/**************************************************************************/ /**************************************************************************/
/*! /*!
@file board_lpcxpresso1347.h @file board_lpcxpresso1347.h
@author hathach (tinyusb.org) @author hathach (tinyusb.org)
@section LICENSE @section LICENSE
Software License Agreement (BSD License) Software License Agreement (BSD License)
Copyright (c) 2013, hathach (tinyusb.org) Copyright (c) 2013, hathach (tinyusb.org)
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met: modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright 1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright 2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holders nor the 3. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission. derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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 INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This file is part of the tinyusb stack. This file is part of the tinyusb stack.
*/ */
/**************************************************************************/ /**************************************************************************/
#ifndef _TUSB_BOARD_LPCXPRESSO1347_H_ #ifndef _TUSB_BOARD_LPCXPRESSO1347_H_
#define _TUSB_BOARD_LPCXPRESSO1347_H_ #define _TUSB_BOARD_LPCXPRESSO1347_H_
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "LPC13Uxx.h" #include "LPC13Uxx.h"
#include "gpio.h" #include "gpio.h"
#include "uart.h" #include "uart.h"
#define CFG_PRINTF_TARGET PRINTF_TARGET_UART #define CFG_PRINTF_TARGET PRINTF_TARGET_UART
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /* _TUSB_BOARD_LPCXPRESSO1347_H_ */ #endif /* _TUSB_BOARD_LPCXPRESSO1347_H_ */

View File

@ -1,159 +1,159 @@
/**************************************************************************/ /**************************************************************************/
/*! /*!
@file board_lpcxpresso1769.c @file board_lpcxpresso1769.c
@author hathach (tinyusb.org) @author hathach (tinyusb.org)
@section LICENSE @section LICENSE
Software License Agreement (BSD License) Software License Agreement (BSD License)
Copyright (c) 2013, hathach (tinyusb.org) Copyright (c) 2013, hathach (tinyusb.org)
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met: modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright 1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright 2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holders nor the 3. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission. derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This file is part of the tinyusb stack. This file is part of the tinyusb stack.
*/ */
/**************************************************************************/ /**************************************************************************/
#include "../board.h" #include "../board.h"
#if BOARD == BOARD_LPCXPRESSO1769 #if BOARD == BOARD_LPCXPRESSO1769
#define BOARD_LED_PORT (0) #define BOARD_LED_PORT (0)
#define BOARD_LED_PIN (22) #define BOARD_LED_PIN (22)
const static struct { const static struct {
uint8_t port; uint8_t port;
uint8_t pin; uint8_t pin;
} buttons[] = } buttons[] =
{ {
{2, 3 }, // Joystick up {2, 3 }, // Joystick up
{0, 15 }, // Joystick down {0, 15 }, // Joystick down
{2, 4 }, // Joystick left {2, 4 }, // Joystick left
{0, 16 }, // Joystick right {0, 16 }, // Joystick right
{0, 17 }, // Joystick press {0, 17 }, // Joystick press
{0, 4 }, // SW3 {0, 4 }, // SW3
// {1, 31 }, // SW4 (require to remove J28) // {1, 31 }, // SW4 (require to remove J28)
}; };
enum { enum {
BOARD_BUTTON_COUNT = sizeof(buttons) / sizeof(buttons[0]) BOARD_BUTTON_COUNT = sizeof(buttons) / sizeof(buttons[0])
}; };
#define BOARD_UART_PORT LPC_UART3 #define BOARD_UART_PORT LPC_UART3
void board_init(void) void board_init(void)
{ {
SystemInit(); SystemInit();
#if TUSB_CFG_OS == TUSB_OS_NONE // TODO may move to main.c #if TUSB_CFG_OS == TUSB_OS_NONE // TODO may move to main.c
SysTick_Config(SystemCoreClock / TUSB_CFG_TICKS_HZ); // 1 msec tick timer SysTick_Config(SystemCoreClock / TUSB_CFG_TICKS_HZ); // 1 msec tick timer
#endif #endif
//------------- LED -------------// //------------- LED -------------//
GPIO_SetDir(BOARD_LED_PORT, BIT_(BOARD_LED_PIN), 1); GPIO_SetDir(BOARD_LED_PORT, BIT_(BOARD_LED_PIN), 1);
//------------- BUTTON -------------// //------------- BUTTON -------------//
for(uint8_t i=0; i<BOARD_BUTTON_COUNT; i++) GPIO_SetDir(buttons[i].port, BIT_(buttons[i].pin), 0); for(uint8_t i=0; i<BOARD_BUTTON_COUNT; i++) GPIO_SetDir(buttons[i].port, BIT_(buttons[i].pin), 0);
#if MODE_DEVICE_SUPPORTED #if MODE_DEVICE_SUPPORTED
//------------- USB Device -------------// //------------- USB Device -------------//
// VBUS sense is wrongly connected to P0_5 (instead of P1_30). So we need to always pull P1_30 to high // VBUS sense is wrongly connected to P0_5 (instead of P1_30). So we need to always pull P1_30 to high
// so that USB device block can work. However, Device Controller (thus tinyusb) cannot able to determine // so that USB device block can work. However, Device Controller (thus tinyusb) cannot able to determine
// if device is disconnected or not // if device is disconnected or not
PINSEL_ConfigPin( &(PINSEL_CFG_Type) { PINSEL_ConfigPin( &(PINSEL_CFG_Type) {
.Portnum = 1, .Pinnum = 30, .Portnum = 1, .Pinnum = 30,
.Funcnum = 2, .Pinmode = PINSEL_PINMODE_PULLUP} ); .Funcnum = 2, .Pinmode = PINSEL_PINMODE_PULLUP} );
//P0_21 instead of P2_9 as USB connect //P0_21 instead of P2_9 as USB connect
#endif #endif
//------------- UART -------------// //------------- UART -------------//
PINSEL_CFG_Type PinCfg = PINSEL_CFG_Type PinCfg =
{ {
.Portnum = 0, .Portnum = 0,
.Pinnum = 0, // TXD is P0.0 .Pinnum = 0, // TXD is P0.0
.Funcnum = 2, .Funcnum = 2,
.OpenDrain = 0, .OpenDrain = 0,
.Pinmode = 0 .Pinmode = 0
}; };
PINSEL_ConfigPin(&PinCfg); PINSEL_ConfigPin(&PinCfg);
PinCfg.Portnum = 0; PinCfg.Portnum = 0;
PinCfg.Pinnum = 1; // RXD is P0.1 PinCfg.Pinnum = 1; // RXD is P0.1
PINSEL_ConfigPin(&PinCfg); PINSEL_ConfigPin(&PinCfg);
UART_CFG_Type UARTConfigStruct; UART_CFG_Type UARTConfigStruct;
UART_ConfigStructInit(&UARTConfigStruct); UART_ConfigStructInit(&UARTConfigStruct);
UARTConfigStruct.Baud_rate = CFG_UART_BAUDRATE; UARTConfigStruct.Baud_rate = CFG_UART_BAUDRATE;
UART_Init(BOARD_UART_PORT, &UARTConfigStruct); UART_Init(BOARD_UART_PORT, &UARTConfigStruct);
UART_TxCmd(BOARD_UART_PORT, ENABLE); // Enable UART Transmit UART_TxCmd(BOARD_UART_PORT, ENABLE); // Enable UART Transmit
} }
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// LEDS // LEDS
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
void board_leds(uint32_t on_mask, uint32_t off_mask) void board_leds(uint32_t on_mask, uint32_t off_mask)
{ {
if (on_mask & BIT_(0)) if (on_mask & BIT_(0))
{ {
GPIO_SetValue(BOARD_LED_PORT, BIT_(BOARD_LED_PIN)); GPIO_SetValue(BOARD_LED_PORT, BIT_(BOARD_LED_PIN));
}else if (off_mask & BIT_(0)) }else if (off_mask & BIT_(0))
{ {
GPIO_ClearValue(BOARD_LED_PORT, BIT_(BOARD_LED_PIN)); GPIO_ClearValue(BOARD_LED_PORT, BIT_(BOARD_LED_PIN));
} }
} }
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// BUTTONS // BUTTONS
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
static bool button_read(uint8_t id) static bool button_read(uint8_t id)
{ {
return !BIT_TEST_( GPIO_ReadValue(buttons[id].port), buttons[id].pin ); // button is active low return !BIT_TEST_( GPIO_ReadValue(buttons[id].port), buttons[id].pin ); // button is active low
} }
uint32_t board_buttons(void) uint32_t board_buttons(void)
{ {
uint32_t result = 0; uint32_t result = 0;
for(uint8_t i=0; i<BOARD_BUTTON_COUNT; i++) result |= (button_read(i) ? BIT_(i) : 0); for(uint8_t i=0; i<BOARD_BUTTON_COUNT; i++) result |= (button_read(i) ? BIT_(i) : 0);
return result; return result;
} }
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// UART // UART
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
void board_uart_putchar(uint8_t c) void board_uart_putchar(uint8_t c)
{ {
UART_Send(BOARD_UART_PORT, &c, 1, BLOCKING); UART_Send(BOARD_UART_PORT, &c, 1, BLOCKING);
} }
uint8_t board_uart_getchar(void) uint8_t board_uart_getchar(void)
{ {
return UART_ReceiveByte(BOARD_UART_PORT); return UART_ReceiveByte(BOARD_UART_PORT);
} }
#endif #endif

View File

@ -1,130 +1,130 @@
/**************************************************************************/ /**************************************************************************/
/*! /*!
@file board_lpc4357usb.c @file board_lpc4357usb.c
@author hathach (tinyusb.org) @author hathach (tinyusb.org)
@section LICENSE @section LICENSE
Software License Agreement (BSD License) Software License Agreement (BSD License)
Copyright (c) 2013, hathach (tinyusb.org) Copyright (c) 2013, hathach (tinyusb.org)
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met: modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright 1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright 2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holders nor the 3. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission. derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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 INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This file is part of the tinyusb stack. This file is part of the tinyusb stack.
*/ */
/**************************************************************************/ /**************************************************************************/
#include "../board.h" #include "../board.h"
#if BOARD == BOARD_LPC4357USB #if BOARD == BOARD_LPC4357USB
#define BOARD_UART_PORT (LPC_USART0) #define BOARD_UART_PORT (LPC_USART0)
#define BOARD_UART_PIN_PORT (0x0F) #define BOARD_UART_PIN_PORT (0x0F)
#define BOARD_UART_PIN_TX (10) // PF.10 : UART0_TXD #define BOARD_UART_PIN_TX (10) // PF.10 : UART0_TXD
#define BOARD_UART_PIN_RX (11) // PF.11 : UART0_RXD #define BOARD_UART_PIN_RX (11) // PF.11 : UART0_RXD
#define BOARD_LED0_PORT (0x0C) #define BOARD_LED0_PORT (0x0C)
#define BOARD_LED0_PIN (2) // PC.2 = User LED #define BOARD_LED0_PIN (2) // PC.2 = User LED
#define BOARD_LED0_FUNCTION (4) // GPIO multiplexed as function 4 on PC.2 #define BOARD_LED0_FUNCTION (4) // GPIO multiplexed as function 4 on PC.2
#define BOARD_LED0_GPIO_PORT (6) #define BOARD_LED0_GPIO_PORT (6)
#define BOARD_LED0_GPIO_PIN (1) // PC.2 = GPIO 6[1] #define BOARD_LED0_GPIO_PIN (1) // PC.2 = GPIO 6[1]
void board_init(void) void board_init(void)
{ {
CGU_Init(); CGU_Init();
/* Setup the systick time for 1ms ticks */ /* Setup the systick time for 1ms ticks */
SysTick_Config(CGU_GetPCLKFrequency(CGU_PERIPHERAL_M4CORE) / TUSB_CFG_TICKS_HZ); SysTick_Config(CGU_GetPCLKFrequency(CGU_PERIPHERAL_M4CORE) / TUSB_CFG_TICKS_HZ);
/* Configure LED0 as GPIO */ /* Configure LED0 as GPIO */
scu_pinmux(BOARD_LED0_PORT, BOARD_LED0_PIN, MD_PDN, BOARD_LED0_FUNCTION); scu_pinmux(BOARD_LED0_PORT, BOARD_LED0_PIN, MD_PDN, BOARD_LED0_FUNCTION);
GPIO_SetDir(BOARD_LED0_GPIO_PORT, (1 << BOARD_LED0_GPIO_PIN), 1); GPIO_SetDir(BOARD_LED0_GPIO_PORT, (1 << BOARD_LED0_GPIO_PIN), 1);
/* Configure TRACE pins */ /* Configure TRACE pins */
scu_pinmux(0xF, 4, MD_PDN, 0x2); /* PF_4 = TRACECLK */ scu_pinmux(0xF, 4, MD_PDN, 0x2); /* PF_4 = TRACECLK */
scu_pinmux(0x7, 4, MD_PDN, 0x5); /* P7_4 = TRACEDATA[0] */ scu_pinmux(0x7, 4, MD_PDN, 0x5); /* P7_4 = TRACEDATA[0] */
scu_pinmux(0x7, 5, MD_PDN, 0x5); /* P7_5 = TRACEDATA[1] */ scu_pinmux(0x7, 5, MD_PDN, 0x5); /* P7_5 = TRACEDATA[1] */
scu_pinmux(0x7, 6, MD_PDN, 0x5); /* P7_6 = TRACEDATA[2] */ scu_pinmux(0x7, 6, MD_PDN, 0x5); /* P7_6 = TRACEDATA[2] */
scu_pinmux(0x7, 7, MD_PDN, 0x5); /* P7_7 = TRACEDATA[3] */ scu_pinmux(0x7, 7, MD_PDN, 0x5); /* P7_7 = TRACEDATA[3] */
// USB0 Power: EA4357 channel B U20 GPIO26 active low (base board), P2_3 on LPC4357 // USB0 Power: EA4357 channel B U20 GPIO26 active low (base board), P2_3 on LPC4357
scu_pinmux(0x2, 3, MD_PUP | MD_EZI, FUNC7); // USB0 VBus Power scu_pinmux(0x2, 3, MD_PUP | MD_EZI, FUNC7); // USB0 VBus Power
// 1.5Kohm pull-up resistor is needed on the USB DP data signal. GPIO28 (base), P9_5 (LPC4357) controls // 1.5Kohm pull-up resistor is needed on the USB DP data signal. GPIO28 (base), P9_5 (LPC4357) controls
//scu_pinmux(0x9, 5, MD_PUP|MD_EZI|MD_ZI, FUNC4); // GPIO5[18] //scu_pinmux(0x9, 5, MD_PUP|MD_EZI|MD_ZI, FUNC4); // GPIO5[18]
//GPIO_SetDir(5, BIT_(18), 1); // output //GPIO_SetDir(5, BIT_(18), 1); // output
//GPIO_ClearValue(5, BIT_(18)); //GPIO_ClearValue(5, BIT_(18));
/* Init I2C @ 400kHz */ /* Init I2C @ 400kHz */
I2C_Init(LPC_I2C0, 400000); I2C_Init(LPC_I2C0, 400000);
I2C_Cmd(LPC_I2C0, ENABLE); I2C_Cmd(LPC_I2C0, ENABLE);
#if CFG_UART_ENABLE #if CFG_UART_ENABLE
//------------- UART init -------------// //------------- UART init -------------//
scu_pinmux(BOARD_UART_PIN_PORT, BOARD_UART_PIN_TX, MD_PDN , FUNC1); scu_pinmux(BOARD_UART_PIN_PORT, BOARD_UART_PIN_TX, MD_PDN , FUNC1);
scu_pinmux(BOARD_UART_PIN_PORT, BOARD_UART_PIN_RX, MD_PLN|MD_EZI|MD_ZI, FUNC1); scu_pinmux(BOARD_UART_PIN_PORT, BOARD_UART_PIN_RX, MD_PLN|MD_EZI|MD_ZI, FUNC1);
UART_CFG_Type UARTConfigStruct; UART_CFG_Type UARTConfigStruct;
UART_ConfigStructInit(&UARTConfigStruct); UART_ConfigStructInit(&UARTConfigStruct);
UARTConfigStruct.Baud_rate = CFG_UART_BAUDRATE; UARTConfigStruct.Baud_rate = CFG_UART_BAUDRATE;
UARTConfigStruct.Clock_Speed = 0; UARTConfigStruct.Clock_Speed = 0;
UART_Init(BOARD_UART_PORT, &UARTConfigStruct); UART_Init(BOARD_UART_PORT, &UARTConfigStruct);
UART_TxCmd(BOARD_UART_PORT, ENABLE); // Enable UART Transmit UART_TxCmd(BOARD_UART_PORT, ENABLE); // Enable UART Transmit
#endif #endif
} }
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// LEDS // LEDS
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
void board_leds(uint32_t on_mask, uint32_t off_mask) void board_leds(uint32_t on_mask, uint32_t off_mask)
{ {
if (on_mask & 0x01) if (on_mask & 0x01)
{ {
LPC_GPIO_PORT->SET[BOARD_LED0_GPIO_PORT] = (1 << BOARD_LED0_GPIO_PIN); LPC_GPIO_PORT->SET[BOARD_LED0_GPIO_PORT] = (1 << BOARD_LED0_GPIO_PIN);
} }
if (off_mask & 0x01) if (off_mask & 0x01)
{ {
LPC_GPIO_PORT->CLR[BOARD_LED0_GPIO_PORT] = (1 << BOARD_LED0_GPIO_PIN); LPC_GPIO_PORT->CLR[BOARD_LED0_GPIO_PORT] = (1 << BOARD_LED0_GPIO_PIN);
} }
} }
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// UART // UART
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
#if CFG_UART_ENABLE #if CFG_UART_ENABLE
uint32_t board_uart_send(uint8_t *buffer, uint32_t length) uint32_t board_uart_send(uint8_t *buffer, uint32_t length)
{ {
return UART_Send(BOARD_UART_PORT, buffer, length, BLOCKING); return UART_Send(BOARD_UART_PORT, buffer, length, BLOCKING);
} }
uint32_t board_uart_recv(uint8_t *buffer, uint32_t length) uint32_t board_uart_recv(uint8_t *buffer, uint32_t length)
{ {
return UART_Receive(BOARD_UART_PORT, buffer, length, BLOCKING); return UART_Receive(BOARD_UART_PORT, buffer, length, BLOCKING);
} }
#endif #endif
#endif #endif

View File

@ -1,158 +1,158 @@
/**************************************************************************/ /**************************************************************************/
/*! /*!
@file board_ngx4330.c @file board_ngx4330.c
@author hathach (tinyusb.org) @author hathach (tinyusb.org)
@section LICENSE @section LICENSE
Software License Agreement (BSD License) Software License Agreement (BSD License)
Copyright (c) 2013, hathach (tinyusb.org) Copyright (c) 2013, hathach (tinyusb.org)
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met: modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright 1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright 2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holders nor the 3. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission. derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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 INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This file is part of the tinyusb stack. This file is part of the tinyusb stack.
*/ */
/**************************************************************************/ /**************************************************************************/
#include "../board.h" #include "../board.h"
#if BOARD == BOARD_NGX4330 #if BOARD == BOARD_NGX4330
#define BOARD_UART_PORT LPC_USART0 #define BOARD_UART_PORT LPC_USART0
const static struct { const static struct {
uint8_t mux_port; uint8_t mux_port;
uint8_t mux_pin; uint8_t mux_pin;
uint8_t gpio_port; uint8_t gpio_port;
uint8_t gpio_pin; uint8_t gpio_pin;
}leds[] = { {2, 11, 1, 11}, {2, 12, 1,12} }; }leds[] = { {2, 11, 1, 11}, {2, 12, 1,12} };
enum { enum {
BOARD_MAX_LEDS = sizeof(leds) / sizeof(leds[0]) BOARD_MAX_LEDS = sizeof(leds) / sizeof(leds[0])
}; };
const static struct { const static struct {
uint8_t mux_port; uint8_t mux_port;
uint8_t mux_pin; uint8_t mux_pin;
uint8_t gpio_port; uint8_t gpio_port;
uint8_t gpio_pin; uint8_t gpio_pin;
}buttons[] = { {0x02, 7, 0, 7 } }; }buttons[] = { {0x02, 7, 0, 7 } };
enum { enum {
BOARD_BUTTON_COUNT = sizeof(buttons) / sizeof(buttons[0]) BOARD_BUTTON_COUNT = sizeof(buttons) / sizeof(buttons[0])
}; };
void board_init(void) void board_init(void)
{ {
CGU_Init(); CGU_Init();
#if TUSB_CFG_OS == TUSB_OS_NONE // TODO may move to main.c #if TUSB_CFG_OS == TUSB_OS_NONE // TODO may move to main.c
SysTick_Config( CGU_GetPCLKFrequency(CGU_PERIPHERAL_M4CORE)/TUSB_CFG_TICKS_HZ ); /* 1 ms Timer */ SysTick_Config( CGU_GetPCLKFrequency(CGU_PERIPHERAL_M4CORE)/TUSB_CFG_TICKS_HZ ); /* 1 ms Timer */
#endif #endif
//------------- USB Bus power HOST ONLY-------------// //------------- USB Bus power HOST ONLY-------------//
scu_pinmux(0x1, 7, MD_PUP | MD_EZI, FUNC4); // P1_7 USB0_PWR_EN, USB0 VBus function Xplorer scu_pinmux(0x1, 7, MD_PUP | MD_EZI, FUNC4); // P1_7 USB0_PWR_EN, USB0 VBus function Xplorer
scu_pinmux(0x2, 6, MD_PUP | MD_EZI, FUNC4); // P2_6 is configured as GPIO5[6] for USB1_PWR_EN scu_pinmux(0x2, 6, MD_PUP | MD_EZI, FUNC4); // P2_6 is configured as GPIO5[6] for USB1_PWR_EN
GPIO_SetDir (5, BIT_(6), 1); // GPIO5[6] is output GPIO_SetDir (5, BIT_(6), 1); // GPIO5[6] is output
GPIO_SetValue (5, BIT_(6)); // GPIO5[6] output high GPIO_SetValue (5, BIT_(6)); // GPIO5[6] output high
//------------- LED -------------// //------------- LED -------------//
for (uint8_t i=0; i<BOARD_MAX_LEDS; i++) for (uint8_t i=0; i<BOARD_MAX_LEDS; i++)
{ {
scu_pinmux(leds[i].mux_port, leds[i].mux_pin, MD_PUP|MD_EZI|MD_ZI, FUNC0); scu_pinmux(leds[i].mux_port, leds[i].mux_pin, MD_PUP|MD_EZI|MD_ZI, FUNC0);
GPIO_SetDir(leds[i].gpio_port, BIT_(leds[i].gpio_pin), 1); // output GPIO_SetDir(leds[i].gpio_port, BIT_(leds[i].gpio_pin), 1); // output
} }
//------------- BUTTONS -------------// //------------- BUTTONS -------------//
for(uint8_t i=0; i<BOARD_BUTTON_COUNT; i++) for(uint8_t i=0; i<BOARD_BUTTON_COUNT; i++)
{ {
scu_pinmux(buttons[i].mux_port, buttons[i].mux_pin, GPIO_NOPULL, FUNC0); scu_pinmux(buttons[i].mux_port, buttons[i].mux_pin, GPIO_NOPULL, FUNC0);
GPIO_SetDir(buttons[i].gpio_port, BIT_(buttons[i].gpio_pin), 0); GPIO_SetDir(buttons[i].gpio_port, BIT_(buttons[i].gpio_pin), 0);
} }
//------------- UART init -------------// //------------- UART init -------------//
scu_pinmux(0x6 ,4, MD_PDN | MD_EZI, FUNC2); // UART0_TXD scu_pinmux(0x6 ,4, MD_PDN | MD_EZI, FUNC2); // UART0_TXD
scu_pinmux(0x6 ,5, MD_PDN | MD_EZI, FUNC2); // UART0_RXD scu_pinmux(0x6 ,5, MD_PDN | MD_EZI, FUNC2); // UART0_RXD
UART_CFG_Type UARTConfigStruct; UART_CFG_Type UARTConfigStruct;
UART_ConfigStructInit(&UARTConfigStruct); // default: baud = 9600, 8 bit data, 1 stop bit, no parity UART_ConfigStructInit(&UARTConfigStruct); // default: baud = 9600, 8 bit data, 1 stop bit, no parity
UARTConfigStruct.Baud_rate = CFG_UART_BAUDRATE; // Re-configure baudrate UARTConfigStruct.Baud_rate = CFG_UART_BAUDRATE; // Re-configure baudrate
UARTConfigStruct.Clock_Speed = 0; UARTConfigStruct.Clock_Speed = 0;
UART_Init(BOARD_UART_PORT, &UARTConfigStruct); UART_Init(BOARD_UART_PORT, &UARTConfigStruct);
UART_TxCmd(BOARD_UART_PORT, ENABLE); // Enable UART UART_TxCmd(BOARD_UART_PORT, ENABLE); // Enable UART
} }
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// LEDS // LEDS
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
void board_leds(uint32_t on_mask, uint32_t off_mask) void board_leds(uint32_t on_mask, uint32_t off_mask)
{ {
for (uint32_t i=0; i<BOARD_MAX_LEDS; i++) for (uint32_t i=0; i<BOARD_MAX_LEDS; i++)
{ {
if ( on_mask & BIT_(i)) if ( on_mask & BIT_(i))
{ {
GPIO_SetValue(leds[i].gpio_port, BIT_(leds[i].gpio_pin)); GPIO_SetValue(leds[i].gpio_port, BIT_(leds[i].gpio_pin));
}else if ( off_mask & BIT_(i)) // on_mask take precedence over off_mask }else if ( off_mask & BIT_(i)) // on_mask take precedence over off_mask
{ {
GPIO_ClearValue(leds[i].gpio_port, BIT_(leds[i].gpio_pin)); GPIO_ClearValue(leds[i].gpio_port, BIT_(leds[i].gpio_pin));
} }
} }
} }
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// BUTTONS // BUTTONS
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
static bool button_read(uint8_t id) static bool button_read(uint8_t id)
{ {
return !BIT_TEST_( GPIO_ReadValue(buttons[id].gpio_port), buttons[id].gpio_pin ); // button is active low return !BIT_TEST_( GPIO_ReadValue(buttons[id].gpio_port), buttons[id].gpio_pin ); // button is active low
} }
uint32_t board_buttons(void) uint32_t board_buttons(void)
{ {
uint32_t result = 0; uint32_t result = 0;
for(uint8_t i=0; i<BOARD_BUTTON_COUNT; i++) result |= (button_read(i) ? BIT_(i) : 0); for(uint8_t i=0; i<BOARD_BUTTON_COUNT; i++) result |= (button_read(i) ? BIT_(i) : 0);
return result; return result;
} }
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// UART // UART
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
uint8_t board_uart_getchar(void) uint8_t board_uart_getchar(void)
{ {
return UART_ReceiveByte(BOARD_UART_PORT); return UART_ReceiveByte(BOARD_UART_PORT);
} }
void board_uart_putchar(uint8_t c) void board_uart_putchar(uint8_t c)
{ {
UART_Send(BOARD_UART_PORT, &c, 1, BLOCKING); UART_Send(BOARD_UART_PORT, &c, 1, BLOCKING);
} }
#endif #endif

View File

@ -1,163 +1,163 @@
/**************************************************************************/ /**************************************************************************/
/*! /*!
@file printf_retarget.c @file printf_retarget.c
@author hathach (tinyusb.org) @author hathach (tinyusb.org)
@section LICENSE @section LICENSE
Software License Agreement (BSD License) Software License Agreement (BSD License)
Copyright (c) 2013, hathach (tinyusb.org) Copyright (c) 2013, hathach (tinyusb.org)
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met: modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright 1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright 2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holders nor the 3. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission. derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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 INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This file is part of the tinyusb stack. This file is part of the tinyusb stack.
*/ */
/**************************************************************************/ /**************************************************************************/
#include "board.h" #include "board.h"
#if CFG_PRINTF_TARGET != PRINTF_TARGET_SEMIHOST #if CFG_PRINTF_TARGET != PRINTF_TARGET_SEMIHOST
#if CFG_PRINTF_TARGET == PRINTF_TARGET_UART #if CFG_PRINTF_TARGET == PRINTF_TARGET_UART
#define retarget_getchar() board_uart_getchar() #define retarget_getchar() board_uart_getchar()
#define retarget_putchar(c) board_uart_putchar(c); #define retarget_putchar(c) board_uart_putchar(c);
#elif CFG_PRINTF_TARGET == PRINTF_TARGET_SWO #elif CFG_PRINTF_TARGET == PRINTF_TARGET_SWO
volatile int32_t ITM_RxBuffer; // keil variable to read from SWO volatile int32_t ITM_RxBuffer; // keil variable to read from SWO
#define retarget_getchar() ITM_ReceiveChar() #define retarget_getchar() ITM_ReceiveChar()
#define retarget_putchar(c) ITM_SendChar(c) #define retarget_putchar(c) ITM_SendChar(c)
#else #else
#error Target is not implemented yet #error Target is not implemented yet
#endif #endif
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// LPCXPRESSO / RED SUITE // LPCXPRESSO / RED SUITE
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
#if defined __CODE_RED #if defined __CODE_RED
#if CFG_PRINTF_TARGET == PRINTF_TARGET_SWO #if CFG_PRINTF_TARGET == PRINTF_TARGET_SWO
#error author does not know how to retarget SWO with lpcxpresso/red-suite #error author does not know how to retarget SWO with lpcxpresso/red-suite
#endif #endif
// Called by bottom level of printf routine within RedLib C library to write // 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 // a character. With the default semihosting stub, this would write the character
// to the debugger console window . But this version writes // to the debugger console window . But this version writes
// the character to the UART. // the character to the UART.
int __sys_write (int iFileHandle, char *buf, int length) int __sys_write (int iFileHandle, char *buf, int length)
{ {
(void) iFileHandle; (void) iFileHandle;
for (int i=0; i<length; i++) for (int i=0; i<length; i++)
{ {
if (buf[i] == '\n') retarget_putchar('\r'); if (buf[i] == '\n') retarget_putchar('\r');
retarget_putchar( buf[i] ); retarget_putchar( buf[i] );
} }
return length; return length;
} }
// Called by bottom level of scanf routine within RedLib C library to read // Called by bottom level of scanf routine within RedLib C library to read
// a character. With the default semihosting stub, this would read the character // a character. With the default semihosting stub, this would read the character
// from the debugger console window (which acts as stdin). But this version reads // from the debugger console window (which acts as stdin). But this version reads
// the character from the UART. // the character from the UART.
int __sys_readc (void) int __sys_readc (void)
{ {
return (int) retarget_getchar(); return (int) retarget_getchar();
} }
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// KEIL // KEIL
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
#elif defined __CC_ARM // keil #elif defined __CC_ARM // keil
struct __FILE { struct __FILE {
uint32_t handle; uint32_t handle;
}; };
void _ttywrch(int ch) void _ttywrch(int ch)
{ {
if ( ch == '\n' ) retarget_putchar('\r'); if ( ch == '\n' ) retarget_putchar('\r');
retarget_putchar(ch); retarget_putchar(ch);
} }
int fgetc(FILE *f) int fgetc(FILE *f)
{ {
return retarget_getchar(); return retarget_getchar();
} }
int fputc(int ch, FILE *f) int fputc(int ch, FILE *f)
{ {
_ttywrch(ch); _ttywrch(ch);
return ch; return ch;
} }
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// IAR // IAR
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
#elif defined __ICCARM__ // TODO could not able to retarget to UART with IAR #elif defined __ICCARM__ // TODO could not able to retarget to UART with IAR
#if CFG_PRINTF_TARGET == PRINTF_TARGET_UART #if CFG_PRINTF_TARGET == PRINTF_TARGET_UART
#include <stddef.h> #include <stddef.h>
size_t __write(int handle, const unsigned char *buf, size_t length) size_t __write(int handle, const unsigned char *buf, size_t length)
{ {
/* Check for the command to flush all handles */ /* Check for the command to flush all handles */
if (handle == -1) return 0; if (handle == -1) return 0;
/* Check for stdout and stderr (only necessary if FILE descriptors are enabled.) */ /* Check for stdout and stderr (only necessary if FILE descriptors are enabled.) */
if (handle != 1 && handle != 2) return -1; if (handle != 1 && handle != 2) return -1;
for (size_t i=0; i<length; i++) for (size_t i=0; i<length; i++)
{ {
if (buf[i] == '\n') retarget_putchar('\r'); if (buf[i] == '\n') retarget_putchar('\r');
retarget_putchar( buf[i] ); retarget_putchar( buf[i] );
} }
return length; return length;
} }
size_t __read(int handle, unsigned char *buf, size_t bufSize) size_t __read(int handle, unsigned char *buf, size_t bufSize)
{ {
/* Check for stdin (only necessary if FILE descriptors are enabled) */ /* Check for stdin (only necessary if FILE descriptors are enabled) */
if (handle != 0) return -1; if (handle != 0) return -1;
size_t i; size_t i;
for (i=0; i<bufSize; i++) for (i=0; i<bufSize; i++)
{ {
uint8_t ch = board_uart_getchar(); uint8_t ch = board_uart_getchar();
if (ch == 0) break; if (ch == 0) break;
buf[i] = ch; buf[i] = ch;
} }
return i; return i;
} }
#endif #endif
#endif #endif
#endif // CFG_PRINTF_TARGET != PRINTF_TARGET_SEMIHOST #endif // CFG_PRINTF_TARGET != PRINTF_TARGET_SEMIHOST

View File

@ -1,64 +1,64 @@
/**************************************************************************** /****************************************************************************
* $Id:: gpio.h 6172 2011-01-13 18:22:51Z usb00423 $ * $Id:: gpio.h 6172 2011-01-13 18:22:51Z usb00423 $
* Project: NXP LPC11Uxx software example * Project: NXP LPC11Uxx software example
* *
* Description: * Description:
* This file contains definition and prototype for GPIO. * This file contains definition and prototype for GPIO.
* *
**************************************************************************** ****************************************************************************
* Software that is described herein is for illustrative purposes only * Software that is described herein is for illustrative purposes only
* which provides customers with programming information regarding the * which provides customers with programming information regarding the
* products. This software is supplied "AS IS" without any warranties. * products. This software is supplied "AS IS" without any warranties.
* NXP Semiconductors assumes no responsibility or liability for the * NXP Semiconductors assumes no responsibility or liability for the
* use of the software, conveys no license or title under any patent, * use of the software, conveys no license or title under any patent,
* copyright, or mask work right to the product. NXP Semiconductors * copyright, or mask work right to the product. NXP Semiconductors
* reserves the right to make changes in the software without * reserves the right to make changes in the software without
* notification. NXP Semiconductors also make no representation or * notification. NXP Semiconductors also make no representation or
* warranty that such application will be suitable for the specified * warranty that such application will be suitable for the specified
* use without further testing or modification. * use without further testing or modification.
****************************************************************************/ ****************************************************************************/
#ifndef __GPIO_H #ifndef __GPIO_H
#define __GPIO_H #define __GPIO_H
#define CHANNEL0 0 #define CHANNEL0 0
#define CHANNEL1 1 #define CHANNEL1 1
#define CHANNEL2 2 #define CHANNEL2 2
#define CHANNEL3 3 #define CHANNEL3 3
#define CHANNEL4 4 #define CHANNEL4 4
#define CHANNEL5 5 #define CHANNEL5 5
#define CHANNEL6 6 #define CHANNEL6 6
#define CHANNEL7 7 #define CHANNEL7 7
#define PORT0 0 #define PORT0 0
#define PORT1 1 #define PORT1 1
#define GROUP0 0 #define GROUP0 0
#define GROUP1 1 #define GROUP1 1
void FLEX_INT0_IRQHandler(void); void FLEX_INT0_IRQHandler(void);
void FLEX_INT1_IRQHandler(void); void FLEX_INT1_IRQHandler(void);
void FLEX_INT2_IRQHandler(void); void FLEX_INT2_IRQHandler(void);
void FLEX_INT3_IRQHandler(void); void FLEX_INT3_IRQHandler(void);
void FLEX_INT4_IRQHandler(void); void FLEX_INT4_IRQHandler(void);
void FLEX_INT5_IRQHandler(void); void FLEX_INT5_IRQHandler(void);
void FLEX_INT6_IRQHandler(void); void FLEX_INT6_IRQHandler(void);
void FLEX_INT7_IRQHandler(void); void FLEX_INT7_IRQHandler(void);
void GINT0_IRQHandler(void); void GINT0_IRQHandler(void);
void GINT1_IRQHandler(void); void GINT1_IRQHandler(void);
void GPIOInit( void ); void GPIOInit( void );
void GPIOSetFlexInterrupt( uint32_t channelNum, uint32_t portNum, uint32_t bitPosi, void GPIOSetFlexInterrupt( uint32_t channelNum, uint32_t portNum, uint32_t bitPosi,
uint32_t sense, uint32_t event ); uint32_t sense, uint32_t event );
void GPIOFlexIntEnable( uint32_t channelNum, uint32_t event ); void GPIOFlexIntEnable( uint32_t channelNum, uint32_t event );
void GPIOFlexIntDisable( uint32_t channelNum, uint32_t event ); void GPIOFlexIntDisable( uint32_t channelNum, uint32_t event );
uint32_t GPIOFlexIntStatus( uint32_t channelNum ); uint32_t GPIOFlexIntStatus( uint32_t channelNum );
void GPIOFlexIntClear( uint32_t channelNum ); void GPIOFlexIntClear( uint32_t channelNum );
void GPIOSetGroupedInterrupt( uint32_t groupNum, uint32_t *bitPattern, uint32_t logic, void GPIOSetGroupedInterrupt( uint32_t groupNum, uint32_t *bitPattern, uint32_t logic,
uint32_t sense, uint32_t *eventPattern ); uint32_t sense, uint32_t *eventPattern );
uint32_t GPIOGetPinValue( uint32_t portNum, uint32_t bitPosi ); uint32_t GPIOGetPinValue( uint32_t portNum, uint32_t bitPosi );
void GPIOSetBitValue( uint32_t portNum, uint32_t bitPosi, uint32_t bitVal ); void GPIOSetBitValue( uint32_t portNum, uint32_t bitPosi, uint32_t bitVal );
void GPIOSetDir( uint32_t portNum, uint32_t bitPosi, uint32_t dir ); void GPIOSetDir( uint32_t portNum, uint32_t bitPosi, uint32_t dir );
#endif /* end __GPIO_H */ #endif /* end __GPIO_H */
/***************************************************************************** /*****************************************************************************
** End Of File ** End Of File
******************************************************************************/ ******************************************************************************/

View File

@ -1,238 +1,238 @@
/***************************************************************************** /*****************************************************************************
* uart.c: UART API file for NXP LPC11xx Family Microprocessors * uart.c: UART API file for NXP LPC11xx Family Microprocessors
* *
* Copyright(C) 2008, NXP Semiconductor * Copyright(C) 2008, NXP Semiconductor
* All rights reserved. * All rights reserved.
* *
* History * History
* 2009.12.07 ver 1.00 Preliminary version, first Release * 2009.12.07 ver 1.00 Preliminary version, first Release
* *
******************************************************************************/ ******************************************************************************/
#include <stdint.h> #include <stdint.h>
#include "LPC11Uxx.h" #include "LPC11Uxx.h"
#include "lpc11uxx_uart.h" #include "lpc11uxx_uart.h"
volatile uint32_t UARTStatus; volatile uint32_t UARTStatus;
volatile uint8_t UARTTxEmpty = 1; volatile uint8_t UARTTxEmpty = 1;
volatile uint8_t UARTBuffer[BUFSIZE]; volatile uint8_t UARTBuffer[BUFSIZE];
volatile uint32_t UARTCount = 0; volatile uint32_t UARTCount = 0;
/***************************************************************************** /*****************************************************************************
** Function name: UART_IRQHandler ** Function name: UART_IRQHandler
** **
** Descriptions: UART interrupt handler ** Descriptions: UART interrupt handler
** **
** parameters: None ** parameters: None
** Returned value: None ** Returned value: None
** **
*****************************************************************************/ *****************************************************************************/
void UART_IRQHandler(void) void UART_IRQHandler(void)
{ {
uint8_t IIRValue, LSRValue; uint8_t IIRValue, LSRValue;
uint8_t Dummy = Dummy; uint8_t Dummy = Dummy;
IIRValue = LPC_USART->IIR; IIRValue = LPC_USART->IIR;
IIRValue >>= 1; /* skip pending bit in IIR */ IIRValue >>= 1; /* skip pending bit in IIR */
IIRValue &= 0x07; /* check bit 1~3, interrupt identification */ IIRValue &= 0x07; /* check bit 1~3, interrupt identification */
if (IIRValue == IIR_RLS) /* Receive Line Status */ if (IIRValue == IIR_RLS) /* Receive Line Status */
{ {
LSRValue = LPC_USART->LSR; LSRValue = LPC_USART->LSR;
/* Receive Line Status */ /* Receive Line Status */
if (LSRValue & (LSR_OE | LSR_PE | LSR_FE | LSR_RXFE | LSR_BI)) if (LSRValue & (LSR_OE | LSR_PE | LSR_FE | LSR_RXFE | LSR_BI))
{ {
/* There are errors or break interrupt */ /* There are errors or break interrupt */
/* Read LSR will clear the interrupt */ /* Read LSR will clear the interrupt */
UARTStatus = LSRValue; UARTStatus = LSRValue;
Dummy = LPC_USART->RBR; /* Dummy read on RX to clear Dummy = LPC_USART->RBR; /* Dummy read on RX to clear
interrupt, then bail out */ interrupt, then bail out */
return; return;
} }
if (LSRValue & LSR_RDR) /* Receive Data Ready */ if (LSRValue & LSR_RDR) /* Receive Data Ready */
{ {
/* If no error on RLS, normal ready, save into the data buffer. */ /* If no error on RLS, normal ready, save into the data buffer. */
/* Note: read RBR will clear the interrupt */ /* Note: read RBR will clear the interrupt */
UARTBuffer[UARTCount++] = LPC_USART->RBR; UARTBuffer[UARTCount++] = LPC_USART->RBR;
if (UARTCount == BUFSIZE) if (UARTCount == BUFSIZE)
{ {
UARTCount = 0; /* buffer overflow */ UARTCount = 0; /* buffer overflow */
} }
} }
} }
else if (IIRValue == IIR_RDA) /* Receive Data Available */ else if (IIRValue == IIR_RDA) /* Receive Data Available */
{ {
/* Receive Data Available */ /* Receive Data Available */
UARTBuffer[UARTCount++] = LPC_USART->RBR; UARTBuffer[UARTCount++] = LPC_USART->RBR;
if (UARTCount == BUFSIZE) if (UARTCount == BUFSIZE)
{ {
UARTCount = 0; /* buffer overflow */ UARTCount = 0; /* buffer overflow */
} }
} }
else if (IIRValue == IIR_CTI) /* Character timeout indicator */ else if (IIRValue == IIR_CTI) /* Character timeout indicator */
{ {
/* Character Time-out indicator */ /* Character Time-out indicator */
UARTStatus |= 0x100; /* Bit 9 as the CTI error */ UARTStatus |= 0x100; /* Bit 9 as the CTI error */
} }
else if (IIRValue == IIR_THRE) /* THRE, transmit holding register empty */ else if (IIRValue == IIR_THRE) /* THRE, transmit holding register empty */
{ {
/* THRE interrupt */ /* THRE interrupt */
LSRValue = LPC_USART->LSR; /* Check status in the LSR to see if LSRValue = LPC_USART->LSR; /* Check status in the LSR to see if
valid data in U0THR or not */ valid data in U0THR or not */
if (LSRValue & LSR_THRE) if (LSRValue & LSR_THRE)
{ {
UARTTxEmpty = 1; UARTTxEmpty = 1;
} }
else else
{ {
UARTTxEmpty = 0; UARTTxEmpty = 0;
} }
} }
return; return;
} }
#if MODEM_TEST #if MODEM_TEST
/***************************************************************************** /*****************************************************************************
** Function name: ModemInit ** Function name: ModemInit
** **
** Descriptions: Initialize UART0 port as modem, setup pin select. ** Descriptions: Initialize UART0 port as modem, setup pin select.
** **
** parameters: None ** parameters: None
** Returned value: None ** Returned value: None
** **
*****************************************************************************/ *****************************************************************************/
void ModemInit( void ) void ModemInit( void )
{ {
LPC_IOCON->PIO2_0 &= ~0x07; /* UART I/O config */ LPC_IOCON->PIO2_0 &= ~0x07; /* UART I/O config */
LPC_IOCON->PIO2_0 |= 0x01; /* UART DTR */ LPC_IOCON->PIO2_0 |= 0x01; /* UART DTR */
LPC_IOCON->PIO0_7 &= ~0x07; /* UART I/O config */ LPC_IOCON->PIO0_7 &= ~0x07; /* UART I/O config */
LPC_IOCON->PIO0_7 |= 0x01; /* UART CTS */ LPC_IOCON->PIO0_7 |= 0x01; /* UART CTS */
LPC_IOCON->PIO1_5 &= ~0x07; /* UART I/O config */ LPC_IOCON->PIO1_5 &= ~0x07; /* UART I/O config */
LPC_IOCON->PIO1_5 |= 0x01; /* UART RTS */ LPC_IOCON->PIO1_5 |= 0x01; /* UART RTS */
#if 1 #if 1
LPC_IOCON->DSR_LOC = 0; LPC_IOCON->DSR_LOC = 0;
LPC_IOCON->PIO2_1 &= ~0x07; /* UART I/O config */ LPC_IOCON->PIO2_1 &= ~0x07; /* UART I/O config */
LPC_IOCON->PIO2_1 |= 0x01; /* UART DSR */ LPC_IOCON->PIO2_1 |= 0x01; /* UART DSR */
LPC_IOCON->DCD_LOC = 0; LPC_IOCON->DCD_LOC = 0;
LPC_IOCON->PIO2_2 &= ~0x07; /* UART I/O config */ LPC_IOCON->PIO2_2 &= ~0x07; /* UART I/O config */
LPC_IOCON->PIO2_2 |= 0x01; /* UART DCD */ LPC_IOCON->PIO2_2 |= 0x01; /* UART DCD */
LPC_IOCON->RI_LOC = 0; LPC_IOCON->RI_LOC = 0;
LPC_IOCON->PIO2_3 &= ~0x07; /* UART I/O config */ LPC_IOCON->PIO2_3 &= ~0x07; /* UART I/O config */
LPC_IOCON->PIO2_3 |= 0x01; /* UART RI */ LPC_IOCON->PIO2_3 |= 0x01; /* UART RI */
#else #else
LPC_IOCON->DSR_LOC = 1; LPC_IOCON->DSR_LOC = 1;
LPC_IOCON->PIO3_1 &= ~0x07; /* UART I/O config */ LPC_IOCON->PIO3_1 &= ~0x07; /* UART I/O config */
LPC_IOCON->PIO3_1 |= 0x01; /* UART DSR */ LPC_IOCON->PIO3_1 |= 0x01; /* UART DSR */
LPC_IOCON->DCD_LOC = 1; LPC_IOCON->DCD_LOC = 1;
LPC_IOCON->PIO3_2 &= ~0x07; /* UART I/O config */ LPC_IOCON->PIO3_2 &= ~0x07; /* UART I/O config */
LPC_IOCON->PIO3_2 |= 0x01; /* UART DCD */ LPC_IOCON->PIO3_2 |= 0x01; /* UART DCD */
LPC_IOCON->RI_LOC = 1; LPC_IOCON->RI_LOC = 1;
LPC_IOCON->PIO3_3 &= ~0x07; /* UART I/O config */ LPC_IOCON->PIO3_3 &= ~0x07; /* UART I/O config */
LPC_IOCON->PIO3_3 |= 0x01; /* UART RI */ LPC_IOCON->PIO3_3 |= 0x01; /* UART RI */
#endif #endif
LPC_USART->MCR = 0xC0; /* Enable Auto RTS and Auto CTS. */ LPC_USART->MCR = 0xC0; /* Enable Auto RTS and Auto CTS. */
return; return;
} }
#endif #endif
/***************************************************************************** /*****************************************************************************
** Function name: UARTInit ** Function name: UARTInit
** **
** Descriptions: Initialize UART0 port, setup pin select, ** Descriptions: Initialize UART0 port, setup pin select,
** clock, parity, stop bits, FIFO, etc. ** clock, parity, stop bits, FIFO, etc.
** **
** parameters: UART baudrate ** parameters: UART baudrate
** Returned value: None ** Returned value: None
** **
*****************************************************************************/ *****************************************************************************/
void UARTInit(uint32_t baudrate) void UARTInit(uint32_t baudrate)
{ {
uint32_t Fdiv; uint32_t Fdiv;
uint32_t regVal; uint32_t regVal;
UARTTxEmpty = 1; UARTTxEmpty = 1;
UARTCount = 0; UARTCount = 0;
NVIC_DisableIRQ(UART_IRQn); NVIC_DisableIRQ(UART_IRQn);
LPC_IOCON->PIO0_18 &= ~0x07; /* UART I/O config */ LPC_IOCON->PIO0_18 &= ~0x07; /* UART I/O config */
LPC_IOCON->PIO0_18 |= 0x01; /* UART RXD */ LPC_IOCON->PIO0_18 |= 0x01; /* UART RXD */
LPC_IOCON->PIO0_19 &= ~0x07; LPC_IOCON->PIO0_19 &= ~0x07;
LPC_IOCON->PIO0_19 |= 0x01; /* UART TXD */ LPC_IOCON->PIO0_19 |= 0x01; /* UART TXD */
/* Enable UART clock */ /* Enable UART clock */
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<12); LPC_SYSCON->SYSAHBCLKCTRL |= (1<<12);
LPC_SYSCON->UARTCLKDIV = 0x1; /* divided by 1 */ LPC_SYSCON->UARTCLKDIV = 0x1; /* divided by 1 */
LPC_USART->LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */ LPC_USART->LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
regVal = LPC_SYSCON->UARTCLKDIV; regVal = LPC_SYSCON->UARTCLKDIV;
Fdiv = (((SystemCoreClock*LPC_SYSCON->SYSAHBCLKDIV)/regVal)/16)/baudrate ; /*baud rate */ Fdiv = (((SystemCoreClock*LPC_SYSCON->SYSAHBCLKDIV)/regVal)/16)/baudrate ; /*baud rate */
LPC_USART->DLM = Fdiv / 256; LPC_USART->DLM = Fdiv / 256;
LPC_USART->DLL = Fdiv % 256; LPC_USART->DLL = Fdiv % 256;
LPC_USART->LCR = 0x03; /* DLAB = 0 */ LPC_USART->LCR = 0x03; /* DLAB = 0 */
LPC_USART->FCR = 0x07; /* Enable and reset TX and RX FIFO. */ LPC_USART->FCR = 0x07; /* Enable and reset TX and RX FIFO. */
/* Read to clear the line status. */ /* Read to clear the line status. */
regVal = LPC_USART->LSR; regVal = LPC_USART->LSR;
/* Ensure a clean start, no data in either TX or RX FIFO. */ /* Ensure a clean start, no data in either TX or RX FIFO. */
// CodeRed - added parentheses around comparison in operand of & // CodeRed - added parentheses around comparison in operand of &
while (( LPC_USART->LSR & (LSR_THRE|LSR_TEMT)) != (LSR_THRE|LSR_TEMT) ); while (( LPC_USART->LSR & (LSR_THRE|LSR_TEMT)) != (LSR_THRE|LSR_TEMT) );
while ( LPC_USART->LSR & LSR_RDR ) while ( LPC_USART->LSR & LSR_RDR )
{ {
regVal = LPC_USART->RBR; /* Dump data from RX FIFO */ regVal = LPC_USART->RBR; /* Dump data from RX FIFO */
} }
/* Enable the UART Interrupt */ /* Enable the UART Interrupt */
NVIC_EnableIRQ(UART_IRQn); NVIC_EnableIRQ(UART_IRQn);
#if CONFIG_UART_ENABLE_INTERRUPT==1 #if CONFIG_UART_ENABLE_INTERRUPT==1
#if CONFIG_UART_ENABLE_TX_INTERRUPT==1 #if CONFIG_UART_ENABLE_TX_INTERRUPT==1
LPC_USART->IER = IER_RBR | IER_THRE | IER_RLS; /* Enable UART interrupt */ LPC_USART->IER = IER_RBR | IER_THRE | IER_RLS; /* Enable UART interrupt */
#else #else
LPC_USART->IER = IER_RBR | IER_RLS; /* Enable UART interrupt */ LPC_USART->IER = IER_RBR | IER_RLS; /* Enable UART interrupt */
#endif #endif
#endif #endif
return; return;
} }
/***************************************************************************** /*****************************************************************************
** Function name: UARTSend ** Function name: UARTSend
** **
** Descriptions: Send a block of data to the UART 0 port based ** Descriptions: Send a block of data to the UART 0 port based
** on the data length ** on the data length
** **
** parameters: buffer pointer, and data length ** parameters: buffer pointer, and data length
** Returned value: None ** Returned value: None
** **
*****************************************************************************/ *****************************************************************************/
void UARTSend(uint8_t *BufferPtr, uint32_t Length) void UARTSend(uint8_t *BufferPtr, uint32_t Length)
{ {
while ( Length != 0 ) while ( Length != 0 )
{ {
/* THRE status, contain valid data */ /* THRE status, contain valid data */
#if CONFIG_UART_ENABLE_TX_INTERRUPT==1 #if CONFIG_UART_ENABLE_TX_INTERRUPT==1
/* Below flag is set inside the interrupt handler when THRE occurs. */ /* Below flag is set inside the interrupt handler when THRE occurs. */
while ( !(UARTTxEmpty & 0x01) ); while ( !(UARTTxEmpty & 0x01) );
LPC_USART->THR = *BufferPtr; LPC_USART->THR = *BufferPtr;
UARTTxEmpty = 0; /* not empty in the THR until it shifts out */ UARTTxEmpty = 0; /* not empty in the THR until it shifts out */
#else #else
while ( !(LPC_USART->LSR & LSR_THRE) ); while ( !(LPC_USART->LSR & LSR_THRE) );
LPC_USART->THR = *BufferPtr; LPC_USART->THR = *BufferPtr;
#endif #endif
BufferPtr++; BufferPtr++;
Length--; Length--;
} }
return; return;
} }
/****************************************************************************** /******************************************************************************
** End Of File ** End Of File
******************************************************************************/ ******************************************************************************/

View File

@ -1,55 +1,55 @@
/***************************************************************************** /*****************************************************************************
* uart.h: Header file for NXP LPC1xxx Family Microprocessors * uart.h: Header file for NXP LPC1xxx Family Microprocessors
* *
* Copyright(C) 2008, NXP Semiconductor * Copyright(C) 2008, NXP Semiconductor
* All rights reserved. * All rights reserved.
* *
* History * History
* 2009.12.07 ver 1.00 Preliminary version, first Release * 2009.12.07 ver 1.00 Preliminary version, first Release
* *
******************************************************************************/ ******************************************************************************/
#ifndef __UART_H #ifndef __UART_H
#define __UART_H #define __UART_H
#define RS485_ENABLED 0 #define RS485_ENABLED 0
#define TX_INTERRUPT 0 /* 0 if TX uses polling, 1 interrupt driven. */ #define TX_INTERRUPT 0 /* 0 if TX uses polling, 1 interrupt driven. */
#define MODEM_TEST 0 #define MODEM_TEST 0
#define IER_RBR 0x01 #define IER_RBR 0x01
#define IER_THRE 0x02 #define IER_THRE 0x02
#define IER_RLS 0x04 #define IER_RLS 0x04
#define IIR_PEND 0x01 #define IIR_PEND 0x01
#define IIR_RLS 0x03 #define IIR_RLS 0x03
#define IIR_RDA 0x02 #define IIR_RDA 0x02
#define IIR_CTI 0x06 #define IIR_CTI 0x06
#define IIR_THRE 0x01 #define IIR_THRE 0x01
#define LSR_RDR 0x01 #define LSR_RDR 0x01
#define LSR_OE 0x02 #define LSR_OE 0x02
#define LSR_PE 0x04 #define LSR_PE 0x04
#define LSR_FE 0x08 #define LSR_FE 0x08
#define LSR_BI 0x10 #define LSR_BI 0x10
#define LSR_THRE 0x20 #define LSR_THRE 0x20
#define LSR_TEMT 0x40 #define LSR_TEMT 0x40
#define LSR_RXFE 0x80 #define LSR_RXFE 0x80
#define BUFSIZE 0x40 #define BUFSIZE 0x40
/* RS485 mode definition. */ /* RS485 mode definition. */
#define RS485_NMMEN (0x1<<0) #define RS485_NMMEN (0x1<<0)
#define RS485_RXDIS (0x1<<1) #define RS485_RXDIS (0x1<<1)
#define RS485_AADEN (0x1<<2) #define RS485_AADEN (0x1<<2)
#define RS485_SEL (0x1<<3) #define RS485_SEL (0x1<<3)
#define RS485_DCTRL (0x1<<4) #define RS485_DCTRL (0x1<<4)
#define RS485_OINV (0x1<<5) #define RS485_OINV (0x1<<5)
void ModemInit( void ); void ModemInit( void );
void UARTInit(uint32_t Baudrate); void UARTInit(uint32_t Baudrate);
void UART_IRQHandler(void); void UART_IRQHandler(void);
void UARTSend(uint8_t *BufferPtr, uint32_t Length); void UARTSend(uint8_t *BufferPtr, uint32_t Length);
#endif /* end __UART_H */ #endif /* end __UART_H */
/***************************************************************************** /*****************************************************************************
** End Of File ** End Of File
******************************************************************************/ ******************************************************************************/

View File

@ -1,19 +1,19 @@
; ************************************************************* ; *************************************************************
; *** Scatter-Loading Description File generated by uVision *** ; *** Scatter-Loading Description File generated by uVision ***
; ************************************************************* ; *************************************************************
LR_IROM1 0x00000000 0x00020000 { ; load region size_region LR_IROM1 0x00000000 0x00020000 { ; load region size_region
ER_IROM1 0x00000000 0x00020000 { ; load address = execution address ER_IROM1 0x00000000 0x00020000 { ; load address = execution address
*.o (RESET, +First) *.o (RESET, +First)
*(InRoot$$Sections) *(InRoot$$Sections)
.ANY (+RO) .ANY (+RO)
} }
RW_IRAM1 0x10000000 0x00002000 { ; RW data RW_IRAM1 0x10000000 0x00002000 { ; RW data
.ANY (+RW +ZI) .ANY (+RW +ZI)
} }
RW_IRAM2 0x20004000 0x00000800 { RW_IRAM2 0x20004000 0x00000800 {
*(USBRAM_SECTION) *(USBRAM_SECTION)
} }
} }

View File

@ -1,64 +1,64 @@
/**************************************************************************** /****************************************************************************
* $Id:: gpio.h 6172 2011-01-13 18:22:51Z usb00423 $ * $Id:: gpio.h 6172 2011-01-13 18:22:51Z usb00423 $
* Project: NXP LPC13Uxx software example * Project: NXP LPC13Uxx software example
* *
* Description: * Description:
* This file contains definition and prototype for GPIO. * This file contains definition and prototype for GPIO.
* *
**************************************************************************** ****************************************************************************
* Software that is described herein is for illustrative purposes only * Software that is described herein is for illustrative purposes only
* which provides customers with programming information regarding the * which provides customers with programming information regarding the
* products. This software is supplied "AS IS" without any warranties. * products. This software is supplied "AS IS" without any warranties.
* NXP Semiconductors assumes no responsibility or liability for the * NXP Semiconductors assumes no responsibility or liability for the
* use of the software, conveys no license or title under any patent, * use of the software, conveys no license or title under any patent,
* copyright, or mask work right to the product. NXP Semiconductors * copyright, or mask work right to the product. NXP Semiconductors
* reserves the right to make changes in the software without * reserves the right to make changes in the software without
* notification. NXP Semiconductors also make no representation or * notification. NXP Semiconductors also make no representation or
* warranty that such application will be suitable for the specified * warranty that such application will be suitable for the specified
* use without further testing or modification. * use without further testing or modification.
****************************************************************************/ ****************************************************************************/
#ifndef __GPIO_H #ifndef __GPIO_H
#define __GPIO_H #define __GPIO_H
#define CHANNEL0 0 #define CHANNEL0 0
#define CHANNEL1 1 #define CHANNEL1 1
#define CHANNEL2 2 #define CHANNEL2 2
#define CHANNEL3 3 #define CHANNEL3 3
#define CHANNEL4 4 #define CHANNEL4 4
#define CHANNEL5 5 #define CHANNEL5 5
#define CHANNEL6 6 #define CHANNEL6 6
#define CHANNEL7 7 #define CHANNEL7 7
#define PORT0 0 #define PORT0 0
#define PORT1 1 #define PORT1 1
#define GROUP0 0 #define GROUP0 0
#define GROUP1 1 #define GROUP1 1
void PIN_INT0_IRQHandler(void); void PIN_INT0_IRQHandler(void);
void PIN_INT1_IRQHandler(void); void PIN_INT1_IRQHandler(void);
void PIN_INT2_IRQHandler(void); void PIN_INT2_IRQHandler(void);
void PIN_INT3_IRQHandler(void); void PIN_INT3_IRQHandler(void);
void PIN_INT4_IRQHandler(void); void PIN_INT4_IRQHandler(void);
void PIN_INT5_IRQHandler(void); void PIN_INT5_IRQHandler(void);
void PIN_INT6_IRQHandler(void); void PIN_INT6_IRQHandler(void);
void PIN_INT7_IRQHandler(void); void PIN_INT7_IRQHandler(void);
void GINT0_IRQHandler(void); void GINT0_IRQHandler(void);
void GINT1_IRQHandler(void); void GINT1_IRQHandler(void);
void GPIOInit( void ); void GPIOInit( void );
void GPIOSetPinInterrupt( uint32_t channelNum, uint32_t portNum, uint32_t bitPosi, void GPIOSetPinInterrupt( uint32_t channelNum, uint32_t portNum, uint32_t bitPosi,
uint32_t sense, uint32_t event ); uint32_t sense, uint32_t event );
void GPIOPinIntEnable( uint32_t channelNum, uint32_t event ); void GPIOPinIntEnable( uint32_t channelNum, uint32_t event );
void GPIOPinIntDisable( uint32_t channelNum, uint32_t event ); void GPIOPinIntDisable( uint32_t channelNum, uint32_t event );
uint32_t GPIOPinIntStatus( uint32_t channelNum ); uint32_t GPIOPinIntStatus( uint32_t channelNum );
void GPIOPinIntClear( uint32_t channelNum ); void GPIOPinIntClear( uint32_t channelNum );
void GPIOSetGroupedInterrupt( uint32_t groupNum, uint32_t *bitPattern, uint32_t logic, void GPIOSetGroupedInterrupt( uint32_t groupNum, uint32_t *bitPattern, uint32_t logic,
uint32_t sense, uint32_t *eventPattern ); uint32_t sense, uint32_t *eventPattern );
uint32_t GPIOGetPinValue( uint32_t portNum, uint32_t bitPosi ); uint32_t GPIOGetPinValue( uint32_t portNum, uint32_t bitPosi );
void GPIOSetBitValue( uint32_t portNum, uint32_t bitPosi, uint32_t bitVal ); void GPIOSetBitValue( uint32_t portNum, uint32_t bitPosi, uint32_t bitVal );
void GPIOSetDir( uint32_t portNum, uint32_t bitPosi, uint32_t dir ); void GPIOSetDir( uint32_t portNum, uint32_t bitPosi, uint32_t dir );
#endif /* end __GPIO_H */ #endif /* end __GPIO_H */
/***************************************************************************** /*****************************************************************************
** End Of File ** End Of File
******************************************************************************/ ******************************************************************************/

View File

@ -1,52 +1,52 @@
/**************************************************************************** /****************************************************************************
* $Id:: type.h 6172 2011-01-13 18:22:51Z usb00423 $ * $Id:: type.h 6172 2011-01-13 18:22:51Z usb00423 $
* Project: NXP LPC13Uxx software example * Project: NXP LPC13Uxx software example
* *
* Description: * Description:
* This file contains different type definition. * This file contains different type definition.
* *
**************************************************************************** ****************************************************************************
* Software that is described herein is for illustrative purposes only * Software that is described herein is for illustrative purposes only
* which provides customers with programming information regarding the * which provides customers with programming information regarding the
* products. This software is supplied "AS IS" without any warranties. * products. This software is supplied "AS IS" without any warranties.
* NXP Semiconductors assumes no responsibility or liability for the * NXP Semiconductors assumes no responsibility or liability for the
* use of the software, conveys no license or title under any patent, * use of the software, conveys no license or title under any patent,
* copyright, or mask work right to the product. NXP Semiconductors * copyright, or mask work right to the product. NXP Semiconductors
* reserves the right to make changes in the software without * reserves the right to make changes in the software without
* notification. NXP Semiconductors also make no representation or * notification. NXP Semiconductors also make no representation or
* warranty that such application will be suitable for the specified * warranty that such application will be suitable for the specified
* use without further testing or modification. * use without further testing or modification.
****************************************************************************/ ****************************************************************************/
#ifndef __TYPE_H__ #ifndef __TYPE_H__
#define __TYPE_H__ #define __TYPE_H__
#if defined (__GNUC__) #if defined (__GNUC__)
#include <stdint.h> #include <stdint.h>
#else #else
/* exact-width signed integer types */ /* exact-width signed integer types */
typedef signed char int8_t; typedef signed char int8_t;
typedef signed short int int16_t; typedef signed short int int16_t;
typedef signed int int32_t; typedef signed int int32_t;
//typedef signed __int64 int64_t; //typedef signed __int64 int64_t;
/* exact-width unsigned integer types */ /* exact-width unsigned integer types */
typedef unsigned char uint8_t; typedef unsigned char uint8_t;
typedef unsigned short int uint16_t; typedef unsigned short int uint16_t;
typedef unsigned int uint32_t; typedef unsigned int uint32_t;
//typedef unsigned __int64 uint64_t; //typedef unsigned __int64 uint64_t;
#endif #endif
#ifndef NULL #ifndef NULL
#define NULL ((void *)0) #define NULL ((void *)0)
#endif #endif
#ifndef FALSE #ifndef FALSE
#define FALSE (0) #define FALSE (0)
#endif #endif
#ifndef TRUE #ifndef TRUE
#define TRUE (1) #define TRUE (1)
#endif #endif
#endif /* __TYPE_H__ */ #endif /* __TYPE_H__ */

View File

@ -1,72 +1,72 @@
/**************************************************************************** /****************************************************************************
* $Id:: uart.h 6172 2011-01-13 18:22:51Z usb00423 $ * $Id:: uart.h 6172 2011-01-13 18:22:51Z usb00423 $
* Project: NXP LPC13Uxx software example * Project: NXP LPC13Uxx software example
* *
* Description: * Description:
* This file contains definition and prototype for UART configuration. * This file contains definition and prototype for UART configuration.
* *
**************************************************************************** ****************************************************************************
* Software that is described herein is for illustrative purposes only * Software that is described herein is for illustrative purposes only
* which provides customers with programming information regarding the * which provides customers with programming information regarding the
* products. This software is supplied "AS IS" without any warranties. * products. This software is supplied "AS IS" without any warranties.
* NXP Semiconductors assumes no responsibility or liability for the * NXP Semiconductors assumes no responsibility or liability for the
* use of the software, conveys no license or title under any patent, * use of the software, conveys no license or title under any patent,
* copyright, or mask work right to the product. NXP Semiconductors * copyright, or mask work right to the product. NXP Semiconductors
* reserves the right to make changes in the software without * reserves the right to make changes in the software without
* notification. NXP Semiconductors also make no representation or * notification. NXP Semiconductors also make no representation or
* warranty that such application will be suitable for the specified * warranty that such application will be suitable for the specified
* use without further testing or modification. * use without further testing or modification.
****************************************************************************/ ****************************************************************************/
#ifndef __UART_H #ifndef __UART_H
#define __UART_H #define __UART_H
#define AUTOBAUD_ENABLE 0 #define AUTOBAUD_ENABLE 0
#define FDR_CALIBRATION 0 #define FDR_CALIBRATION 0
#define RS485_ENABLED 0 #define RS485_ENABLED 0
#define TX_INTERRUPT 0 /* 0 if TX uses polling, 1 interrupt driven. */ #define TX_INTERRUPT 0 /* 0 if TX uses polling, 1 interrupt driven. */
#define MODEM_TEST 0 #define MODEM_TEST 0
#define IER_RBR (0x01<<0) #define IER_RBR (0x01<<0)
#define IER_THRE (0x01<<1) #define IER_THRE (0x01<<1)
#define IER_RLS (0x01<<2) #define IER_RLS (0x01<<2)
#define IER_ABEO (0x01<<8) #define IER_ABEO (0x01<<8)
#define IER_ABTO (0x01<<9) #define IER_ABTO (0x01<<9)
#define IIR_PEND 0x01 #define IIR_PEND 0x01
#define IIR_RLS 0x03 #define IIR_RLS 0x03
#define IIR_RDA 0x02 #define IIR_RDA 0x02
#define IIR_CTI 0x06 #define IIR_CTI 0x06
#define IIR_THRE 0x01 #define IIR_THRE 0x01
#define IIR_ABEO (0x01<<8) #define IIR_ABEO (0x01<<8)
#define IIR_ABTO (0x01<<9) #define IIR_ABTO (0x01<<9)
#define LSR_RDR (0x01<<0) #define LSR_RDR (0x01<<0)
#define LSR_OE (0x01<<1) #define LSR_OE (0x01<<1)
#define LSR_PE (0x01<<2) #define LSR_PE (0x01<<2)
#define LSR_FE (0x01<<3) #define LSR_FE (0x01<<3)
#define LSR_BI (0x01<<4) #define LSR_BI (0x01<<4)
#define LSR_THRE (0x01<<5) #define LSR_THRE (0x01<<5)
#define LSR_TEMT (0x01<<6) #define LSR_TEMT (0x01<<6)
#define LSR_RXFE (0x01<<7) #define LSR_RXFE (0x01<<7)
#define BUFSIZE 0x40 #define BUFSIZE 0x40
/* RS485 mode definition. */ /* RS485 mode definition. */
#define RS485_NMMEN (0x1<<0) #define RS485_NMMEN (0x1<<0)
#define RS485_RXDIS (0x1<<1) #define RS485_RXDIS (0x1<<1)
#define RS485_AADEN (0x1<<2) #define RS485_AADEN (0x1<<2)
#define RS485_SEL (0x1<<3) #define RS485_SEL (0x1<<3)
#define RS485_DCTRL (0x1<<4) #define RS485_DCTRL (0x1<<4)
#define RS485_OINV (0x1<<5) #define RS485_OINV (0x1<<5)
void ModemInit( void ); void ModemInit( void );
void UARTInit(uint32_t Baudrate); void UARTInit(uint32_t Baudrate);
void USART_IRQHandler(void); void USART_IRQHandler(void);
void UARTSend(uint8_t *BufferPtr, uint32_t Length); void UARTSend(uint8_t *BufferPtr, uint32_t Length);
void print_string( uint8_t *str_ptr ); void print_string( uint8_t *str_ptr );
uint8_t get_key( void ); uint8_t get_key( void );
#endif /* end __UART_H */ #endif /* end __UART_H */
/***************************************************************************** /*****************************************************************************
** End Of File ** End Of File
******************************************************************************/ ******************************************************************************/

View File

@ -1,437 +1,437 @@
/**************************************************************************** /****************************************************************************
* $Id:: uart.c 7125 2011-04-15 00:22:12Z usb01267 $ * $Id:: uart.c 7125 2011-04-15 00:22:12Z usb01267 $
* Project: NXP LPC13Uxx UART example * Project: NXP LPC13Uxx UART example
* *
* Description: * Description:
* This file contains UART code example which include UART * This file contains UART code example which include UART
* initialization, UART interrupt handler, and related APIs for * initialization, UART interrupt handler, and related APIs for
* UART access. * UART access.
* *
**************************************************************************** ****************************************************************************
* Software that is described herein is for illustrative purposes only * Software that is described herein is for illustrative purposes only
* which provides customers with programming information regarding the * which provides customers with programming information regarding the
* products. This software is supplied "AS IS" without any warranties. * products. This software is supplied "AS IS" without any warranties.
* NXP Semiconductors assumes no responsibility or liability for the * NXP Semiconductors assumes no responsibility or liability for the
* use of the software, conveys no license or title under any patent, * use of the software, conveys no license or title under any patent,
* copyright, or mask work right to the product. NXP Semiconductors * copyright, or mask work right to the product. NXP Semiconductors
* reserves the right to make changes in the software without * reserves the right to make changes in the software without
* notification. NXP Semiconductors also make no representation or * notification. NXP Semiconductors also make no representation or
* warranty that such application will be suitable for the specified * warranty that such application will be suitable for the specified
* use without further testing or modification. * use without further testing or modification.
* Permission to use, copy, modify, and distribute this software and its * Permission to use, copy, modify, and distribute this software and its
* documentation is hereby granted, under NXP Semiconductors' * documentation is hereby granted, under NXP Semiconductors'
* relevant copyright in the software, without fee, provided that it * relevant copyright in the software, without fee, provided that it
* is used in conjunction with NXP Semiconductors microcontrollers. This * is used in conjunction with NXP Semiconductors microcontrollers. This
* copyright, permission, and disclaimer notice must appear in all copies of * copyright, permission, and disclaimer notice must appear in all copies of
* this code. * this code.
****************************************************************************/ ****************************************************************************/
#include "LPC13Uxx.h" #include "LPC13Uxx.h"
#include "type.h" #include "type.h"
#include "uart.h" #include "uart.h"
volatile uint32_t UARTStatus; volatile uint32_t UARTStatus;
volatile uint8_t UARTTxEmpty = 1; volatile uint8_t UARTTxEmpty = 1;
volatile uint8_t UARTBuffer[BUFSIZE]; volatile uint8_t UARTBuffer[BUFSIZE];
volatile uint32_t UARTCount = 0; volatile uint32_t UARTCount = 0;
#if AUTOBAUD_ENABLE #if AUTOBAUD_ENABLE
volatile uint32_t UARTAutoBaud = 0, AutoBaudTimeout = 0; volatile uint32_t UARTAutoBaud = 0, AutoBaudTimeout = 0;
#endif #endif
/***************************************************************************** /*****************************************************************************
** Function name: USART_IRQHandler ** Function name: USART_IRQHandler
** **
** Descriptions: USART interrupt handler ** Descriptions: USART interrupt handler
** **
** parameters: None ** parameters: None
** Returned value: None ** Returned value: None
** **
*****************************************************************************/ *****************************************************************************/
void USART_IRQHandler(void) void USART_IRQHandler(void)
{ {
uint8_t IIRValue, LSRValue; uint8_t IIRValue, LSRValue;
uint8_t Dummy = Dummy; uint8_t Dummy = Dummy;
IIRValue = LPC_USART->IIR; IIRValue = LPC_USART->IIR;
IIRValue >>= 1; /* skip pending bit in IIR */ IIRValue >>= 1; /* skip pending bit in IIR */
IIRValue &= 0x07; /* check bit 1~3, interrupt identification */ IIRValue &= 0x07; /* check bit 1~3, interrupt identification */
if (IIRValue == IIR_RLS) /* Receive Line Status */ if (IIRValue == IIR_RLS) /* Receive Line Status */
{ {
LSRValue = LPC_USART->LSR; LSRValue = LPC_USART->LSR;
/* Receive Line Status */ /* Receive Line Status */
if (LSRValue & (LSR_OE | LSR_PE | LSR_FE | LSR_RXFE | LSR_BI)) if (LSRValue & (LSR_OE | LSR_PE | LSR_FE | LSR_RXFE | LSR_BI))
{ {
/* There are errors or break interrupt */ /* There are errors or break interrupt */
/* Read LSR will clear the interrupt */ /* Read LSR will clear the interrupt */
UARTStatus = LSRValue; UARTStatus = LSRValue;
Dummy = LPC_USART->RBR; /* Dummy read on RX to clear Dummy = LPC_USART->RBR; /* Dummy read on RX to clear
interrupt, then bail out */ interrupt, then bail out */
return; return;
} }
if (LSRValue & LSR_RDR) /* Receive Data Ready */ if (LSRValue & LSR_RDR) /* Receive Data Ready */
{ {
/* If no error on RLS, normal ready, save into the data buffer. */ /* If no error on RLS, normal ready, save into the data buffer. */
/* Note: read RBR will clear the interrupt */ /* Note: read RBR will clear the interrupt */
UARTBuffer[UARTCount++] = LPC_USART->RBR; UARTBuffer[UARTCount++] = LPC_USART->RBR;
if (UARTCount == BUFSIZE) if (UARTCount == BUFSIZE)
{ {
UARTCount = 0; /* buffer overflow */ UARTCount = 0; /* buffer overflow */
} }
} }
} }
else if (IIRValue == IIR_RDA) /* Receive Data Available */ else if (IIRValue == IIR_RDA) /* Receive Data Available */
{ {
/* Receive Data Available */ /* Receive Data Available */
UARTBuffer[UARTCount++] = LPC_USART->RBR; UARTBuffer[UARTCount++] = LPC_USART->RBR;
if (UARTCount == BUFSIZE) if (UARTCount == BUFSIZE)
{ {
UARTCount = 0; /* buffer overflow */ UARTCount = 0; /* buffer overflow */
} }
} }
else if (IIRValue == IIR_CTI) /* Character timeout indicator */ else if (IIRValue == IIR_CTI) /* Character timeout indicator */
{ {
/* Character Time-out indicator */ /* Character Time-out indicator */
UARTStatus |= 0x100; /* Bit 9 as the CTI error */ UARTStatus |= 0x100; /* Bit 9 as the CTI error */
} }
else if (IIRValue == IIR_THRE) /* THRE, transmit holding register empty */ else if (IIRValue == IIR_THRE) /* THRE, transmit holding register empty */
{ {
/* THRE interrupt */ /* THRE interrupt */
LSRValue = LPC_USART->LSR; /* Check status in the LSR to see if LSRValue = LPC_USART->LSR; /* Check status in the LSR to see if
valid data in U0THR or not */ valid data in U0THR or not */
if (LSRValue & LSR_THRE) if (LSRValue & LSR_THRE)
{ {
UARTTxEmpty = 1; UARTTxEmpty = 1;
} }
else else
{ {
UARTTxEmpty = 0; UARTTxEmpty = 0;
} }
} }
#if AUTOBAUD_ENABLE #if AUTOBAUD_ENABLE
if (LPC_USART->IIR & IIR_ABEO) /* End of Auto baud */ if (LPC_USART->IIR & IIR_ABEO) /* End of Auto baud */
{ {
LPC_USART->IER &= ~IIR_ABEO; LPC_USART->IER &= ~IIR_ABEO;
/* clear bit ABEOInt in the IIR by set ABEOIntClr in the ACR register */ /* clear bit ABEOInt in the IIR by set ABEOIntClr in the ACR register */
LPC_USART->ACR |= IIR_ABEO; LPC_USART->ACR |= IIR_ABEO;
UARTAutoBaud = 1; UARTAutoBaud = 1;
} }
else if (LPC_USART->IIR & IIR_ABTO)/* Auto baud time out */ else if (LPC_USART->IIR & IIR_ABTO)/* Auto baud time out */
{ {
LPC_USART->IER &= ~IIR_ABTO; LPC_USART->IER &= ~IIR_ABTO;
AutoBaudTimeout = 1; AutoBaudTimeout = 1;
/* clear bit ABTOInt in the IIR by set ABTOIntClr in the ACR register */ /* clear bit ABTOInt in the IIR by set ABTOIntClr in the ACR register */
LPC_USART->ACR |= IIR_ABTO; LPC_USART->ACR |= IIR_ABTO;
} }
#endif #endif
return; return;
} }
#if MODEM_TEST #if MODEM_TEST
/***************************************************************************** /*****************************************************************************
** Function name: ModemInit ** Function name: ModemInit
** **
** Descriptions: Initialize UART0 port as modem, setup pin select. ** Descriptions: Initialize UART0 port as modem, setup pin select.
** **
** parameters: None ** parameters: None
** Returned value: None ** Returned value: None
** **
*****************************************************************************/ *****************************************************************************/
void ModemInit( void ) void ModemInit( void )
{ {
LPC_IOCON->PIO0_7 &= ~0x07; /* UART I/O config */ LPC_IOCON->PIO0_7 &= ~0x07; /* UART I/O config */
LPC_IOCON->PIO0_7 |= 0x01; /* UART CTS */ LPC_IOCON->PIO0_7 |= 0x01; /* UART CTS */
LPC_IOCON->PIO0_17 &= ~0x07; /* UART I/O config */ LPC_IOCON->PIO0_17 &= ~0x07; /* UART I/O config */
LPC_IOCON->PIO0_17 |= 0x01; /* UART RTS */ LPC_IOCON->PIO0_17 |= 0x01; /* UART RTS */
#if 1 #if 1
LPC_IOCON->PIO1_13 &= ~0x07; /* UART I/O config */ LPC_IOCON->PIO1_13 &= ~0x07; /* UART I/O config */
LPC_IOCON->PIO1_13 |= 0x01; /* UART DTR */ LPC_IOCON->PIO1_13 |= 0x01; /* UART DTR */
LPC_IOCON->PIO1_14 &= ~0x07; /* UART I/O config */ LPC_IOCON->PIO1_14 &= ~0x07; /* UART I/O config */
LPC_IOCON->PIO1_14 |= 0x01; /* UART DSR */ LPC_IOCON->PIO1_14 |= 0x01; /* UART DSR */
LPC_IOCON->PIO1_15 &= ~0x07; /* UART I/O config */ LPC_IOCON->PIO1_15 &= ~0x07; /* UART I/O config */
LPC_IOCON->PIO1_15 |= 0x01; /* UART DCD */ LPC_IOCON->PIO1_15 |= 0x01; /* UART DCD */
LPC_IOCON->PIO1_16 &= ~0x07; /* UART I/O config */ LPC_IOCON->PIO1_16 &= ~0x07; /* UART I/O config */
LPC_IOCON->PIO1_16 |= 0x01; /* UART RI */ LPC_IOCON->PIO1_16 |= 0x01; /* UART RI */
#else #else
LPC_IOCON->PIO1_19 &= ~0x07; /* UART I/O config */ LPC_IOCON->PIO1_19 &= ~0x07; /* UART I/O config */
LPC_IOCON->PIO1_19 |= 0x01; /* UART DTR */ LPC_IOCON->PIO1_19 |= 0x01; /* UART DTR */
LPC_IOCON->PIO1_20 &= ~0x07; /* UART I/O config */ LPC_IOCON->PIO1_20 &= ~0x07; /* UART I/O config */
LPC_IOCON->PIO1_20 |= 0x01; /* UART DSR */ LPC_IOCON->PIO1_20 |= 0x01; /* UART DSR */
LPC_IOCON->PIO1_21 &= ~0x07; /* UART I/O config */ LPC_IOCON->PIO1_21 &= ~0x07; /* UART I/O config */
LPC_IOCON->PIO1_21 |= 0x01; /* UART DCD */ LPC_IOCON->PIO1_21 |= 0x01; /* UART DCD */
LPC_IOCON->PIO1_22 &= ~0x07; /* UART I/O config */ LPC_IOCON->PIO1_22 &= ~0x07; /* UART I/O config */
LPC_IOCON->PIO1_22 |= 0x01; /* UART RI */ LPC_IOCON->PIO1_22 |= 0x01; /* UART RI */
#endif #endif
LPC_USART->MCR = 0xC0; /* Enable Auto RTS and Auto CTS. */ LPC_USART->MCR = 0xC0; /* Enable Auto RTS and Auto CTS. */
return; return;
} }
#endif #endif
/*********************************************************************** /***********************************************************************
* *
* Function: uart_set_divisors * Function: uart_set_divisors
* *
* Purpose: Determines best dividers to get a target clock rate * Purpose: Determines best dividers to get a target clock rate
* *
* Processing: * Processing:
* See function. * See function.
* *
* Parameters: * Parameters:
* UARTClk : UART clock * UARTClk : UART clock
* baudrate : Desired UART baud rate * baudrate : Desired UART baud rate
* *
* Outputs: * Outputs:
* baudrate : Sets the estimated buadrate value in DLL, DLM, and FDR. * baudrate : Sets the estimated buadrate value in DLL, DLM, and FDR.
* *
* Returns: Error status. * Returns: Error status.
* *
* Notes: None * Notes: None
* *
**********************************************************************/ **********************************************************************/
uint32_t uart_set_divisors(uint32_t UARTClk, uint32_t baudrate) uint32_t uart_set_divisors(uint32_t UARTClk, uint32_t baudrate)
{ {
uint32_t uClk; uint32_t uClk;
uint32_t calcBaudrate = 0; uint32_t calcBaudrate = 0;
uint32_t temp = 0; uint32_t temp = 0;
uint32_t mulFracDiv, dividerAddFracDiv; uint32_t mulFracDiv, dividerAddFracDiv;
uint32_t diviser = 0 ; uint32_t diviser = 0 ;
uint32_t mulFracDivOptimal = 1; uint32_t mulFracDivOptimal = 1;
uint32_t dividerAddOptimal = 0; uint32_t dividerAddOptimal = 0;
uint32_t diviserOptimal = 0; uint32_t diviserOptimal = 0;
uint32_t relativeError = 0; uint32_t relativeError = 0;
uint32_t relativeOptimalError = 100000; uint32_t relativeOptimalError = 100000;
/* get UART block clock */ /* get UART block clock */
uClk = UARTClk >> 4; /* div by 16 */ uClk = UARTClk >> 4; /* div by 16 */
/* In the Uart IP block, baud rate is calculated using FDR and DLL-DLM registers /* In the Uart IP block, baud rate is calculated using FDR and DLL-DLM registers
* The formula is : * The formula is :
* BaudRate= uClk * (mulFracDiv/(mulFracDiv+dividerAddFracDiv) / (16 * (DLL) * BaudRate= uClk * (mulFracDiv/(mulFracDiv+dividerAddFracDiv) / (16 * (DLL)
* It involves floating point calculations. That's the reason the formulae are adjusted with * It involves floating point calculations. That's the reason the formulae are adjusted with
* Multiply and divide method.*/ * Multiply and divide method.*/
/* The value of mulFracDiv and dividerAddFracDiv should comply to the following expressions: /* The value of mulFracDiv and dividerAddFracDiv should comply to the following expressions:
* 0 < mulFracDiv <= 15, 0 <= dividerAddFracDiv <= 15 */ * 0 < mulFracDiv <= 15, 0 <= dividerAddFracDiv <= 15 */
for (mulFracDiv = 1; mulFracDiv <= 15; mulFracDiv++) for (mulFracDiv = 1; mulFracDiv <= 15; mulFracDiv++)
{ {
for (dividerAddFracDiv = 0; dividerAddFracDiv <= 15; dividerAddFracDiv++) for (dividerAddFracDiv = 0; dividerAddFracDiv <= 15; dividerAddFracDiv++)
{ {
temp = (mulFracDiv * uClk) / ((mulFracDiv + dividerAddFracDiv)); temp = (mulFracDiv * uClk) / ((mulFracDiv + dividerAddFracDiv));
diviser = temp / baudrate; diviser = temp / baudrate;
if ((temp % baudrate) > (baudrate / 2)) if ((temp % baudrate) > (baudrate / 2))
diviser++; diviser++;
if (diviser > 2 && diviser < 65536) if (diviser > 2 && diviser < 65536)
{ {
calcBaudrate = temp / diviser; calcBaudrate = temp / diviser;
if (calcBaudrate <= baudrate) if (calcBaudrate <= baudrate)
relativeError = baudrate - calcBaudrate; relativeError = baudrate - calcBaudrate;
else else
relativeError = calcBaudrate - baudrate; relativeError = calcBaudrate - baudrate;
if ((relativeError < relativeOptimalError)) if ((relativeError < relativeOptimalError))
{ {
mulFracDivOptimal = mulFracDiv ; mulFracDivOptimal = mulFracDiv ;
dividerAddOptimal = dividerAddFracDiv; dividerAddOptimal = dividerAddFracDiv;
diviserOptimal = diviser; diviserOptimal = diviser;
relativeOptimalError = relativeError; relativeOptimalError = relativeError;
if (relativeError == 0) if (relativeError == 0)
break; break;
} }
} /* End of if */ } /* End of if */
} /* end of inner for loop */ } /* end of inner for loop */
if (relativeError == 0) if (relativeError == 0)
break; break;
} /* end of outer for loop */ } /* end of outer for loop */
if (relativeOptimalError < (baudrate / 30)) if (relativeOptimalError < (baudrate / 30))
{ {
/* Set the `Divisor Latch Access Bit` and enable so the DLL/DLM access*/ /* Set the `Divisor Latch Access Bit` and enable so the DLL/DLM access*/
/* Initialise the `Divisor latch LSB` and `Divisor latch MSB` registers */ /* Initialise the `Divisor latch LSB` and `Divisor latch MSB` registers */
LPC_USART->DLM = (diviserOptimal >> 8) & 0xFF; LPC_USART->DLM = (diviserOptimal >> 8) & 0xFF;
LPC_USART->DLL = diviserOptimal & 0xFF; LPC_USART->DLL = diviserOptimal & 0xFF;
/* Initialise the Fractional Divider Register */ /* Initialise the Fractional Divider Register */
LPC_USART->FDR = ((mulFracDivOptimal & 0xF) << 4) | (dividerAddOptimal & 0xF); LPC_USART->FDR = ((mulFracDivOptimal & 0xF) << 4) | (dividerAddOptimal & 0xF);
return( TRUE ); return( TRUE );
} }
return ( FALSE ); return ( FALSE );
} }
/***************************************************************************** /*****************************************************************************
** Function name: UARTInit ** Function name: UARTInit
** **
** Descriptions: Initialize UART0 port, setup pin select, ** Descriptions: Initialize UART0 port, setup pin select,
** clock, parity, stop bits, FIFO, etc. ** clock, parity, stop bits, FIFO, etc.
** **
** parameters: UART baudrate ** parameters: UART baudrate
** Returned value: None ** Returned value: None
** **
*****************************************************************************/ *****************************************************************************/
void UARTInit(uint32_t baudrate) void UARTInit(uint32_t baudrate)
{ {
#if !AUTOBAUD_ENABLE #if !AUTOBAUD_ENABLE
uint32_t Fdiv; uint32_t Fdiv;
#endif #endif
volatile uint32_t regVal; volatile uint32_t regVal;
UARTTxEmpty = 1; UARTTxEmpty = 1;
UARTCount = 0; UARTCount = 0;
NVIC_DisableIRQ(USART_IRQn); NVIC_DisableIRQ(USART_IRQn);
/* Select only one location from below. */ /* Select only one location from below. */
#if 1 #if 1
LPC_IOCON->PIO0_18 &= ~0x07; /* UART I/O config */ LPC_IOCON->PIO0_18 &= ~0x07; /* UART I/O config */
LPC_IOCON->PIO0_18 |= 0x01; /* UART RXD */ LPC_IOCON->PIO0_18 |= 0x01; /* UART RXD */
LPC_IOCON->PIO0_19 &= ~0x07; LPC_IOCON->PIO0_19 &= ~0x07;
LPC_IOCON->PIO0_19 |= 0x01; /* UART TXD */ LPC_IOCON->PIO0_19 |= 0x01; /* UART TXD */
#endif #endif
#if 0 #if 0
LPC_IOCON->PIO1_14 &= ~0x07; /* UART I/O config */ LPC_IOCON->PIO1_14 &= ~0x07; /* UART I/O config */
LPC_IOCON->PIO1_14 |= 0x03; /* UART RXD */ LPC_IOCON->PIO1_14 |= 0x03; /* UART RXD */
LPC_IOCON->PIO1_13 &= ~0x07; LPC_IOCON->PIO1_13 &= ~0x07;
LPC_IOCON->PIO1_13 |= 0x03; /* UART TXD */ LPC_IOCON->PIO1_13 |= 0x03; /* UART TXD */
#endif #endif
#if 0 #if 0
LPC_IOCON->PIO1_17 &= ~0x07; /* UART I/O config */ LPC_IOCON->PIO1_17 &= ~0x07; /* UART I/O config */
LPC_IOCON->PIO1_17 |= 0x02; /* UART RXD */ LPC_IOCON->PIO1_17 |= 0x02; /* UART RXD */
LPC_IOCON->PIO1_18 &= ~0x07; LPC_IOCON->PIO1_18 &= ~0x07;
LPC_IOCON->PIO1_18 |= 0x02; /* UART TXD */ LPC_IOCON->PIO1_18 |= 0x02; /* UART TXD */
#endif #endif
#if 0 #if 0
LPC_IOCON->PIO1_26 &= ~0x07; /* UART I/O config */ LPC_IOCON->PIO1_26 &= ~0x07; /* UART I/O config */
LPC_IOCON->PIO1_26 |= 0x02; /* UART RXD */ LPC_IOCON->PIO1_26 |= 0x02; /* UART RXD */
LPC_IOCON->PIO1_27 &= ~0x07; LPC_IOCON->PIO1_27 &= ~0x07;
LPC_IOCON->PIO1_27 |= 0x02; /* UART TXD */ LPC_IOCON->PIO1_27 |= 0x02; /* UART TXD */
#endif #endif
/* Enable UART clock */ /* Enable UART clock */
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<12); LPC_SYSCON->SYSAHBCLKCTRL |= (1<<12);
LPC_SYSCON->UARTCLKDIV = 0x1; /* divided by 1 */ LPC_SYSCON->UARTCLKDIV = 0x1; /* divided by 1 */
LPC_USART->LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */ LPC_USART->LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
#if !AUTOBAUD_ENABLE #if !AUTOBAUD_ENABLE
#if FDR_CALIBRATION #if FDR_CALIBRATION
if ( uart_set_divisors(SystemCoreClock/LPC_SYSCON->UARTCLKDIV, baudrate) != TRUE ) if ( uart_set_divisors(SystemCoreClock/LPC_SYSCON->UARTCLKDIV, baudrate) != TRUE )
{ {
Fdiv = ((SystemCoreClock/LPC_SYSCON->UARTCLKDIV)/16)/baudrate ; /*baud rate */ Fdiv = ((SystemCoreClock/LPC_SYSCON->UARTCLKDIV)/16)/baudrate ; /*baud rate */
LPC_USART->DLM = Fdiv / 256; LPC_USART->DLM = Fdiv / 256;
LPC_USART->DLL = Fdiv % 256; LPC_USART->DLL = Fdiv % 256;
LPC_USART->FDR = 0x10; /* Default */ LPC_USART->FDR = 0x10; /* Default */
} }
#else #else
Fdiv = ((SystemCoreClock/LPC_SYSCON->UARTCLKDIV)/16)/baudrate ; /*baud rate */ Fdiv = ((SystemCoreClock/LPC_SYSCON->UARTCLKDIV)/16)/baudrate ; /*baud rate */
LPC_USART->DLM = Fdiv / 256; LPC_USART->DLM = Fdiv / 256;
LPC_USART->DLL = Fdiv % 256; LPC_USART->DLL = Fdiv % 256;
LPC_USART->FDR = 0x10; /* Default */ LPC_USART->FDR = 0x10; /* Default */
#endif #endif
#endif #endif
LPC_USART->LCR = 0x03; /* DLAB = 0 */ LPC_USART->LCR = 0x03; /* DLAB = 0 */
LPC_USART->FCR = 0x07; /* Enable and reset TX and RX FIFO. */ LPC_USART->FCR = 0x07; /* Enable and reset TX and RX FIFO. */
/* Read to clear the line status. */ /* Read to clear the line status. */
regVal = LPC_USART->LSR; regVal = LPC_USART->LSR;
/* Ensure a clean start, no data in either TX or RX FIFO. */ /* Ensure a clean start, no data in either TX or RX FIFO. */
while (( LPC_USART->LSR & (LSR_THRE|LSR_TEMT)) != (LSR_THRE|LSR_TEMT) ); while (( LPC_USART->LSR & (LSR_THRE|LSR_TEMT)) != (LSR_THRE|LSR_TEMT) );
while ( LPC_USART->LSR & LSR_RDR ) while ( LPC_USART->LSR & LSR_RDR )
{ {
regVal = LPC_USART->RBR; /* Dump data from RX FIFO */ regVal = LPC_USART->RBR; /* Dump data from RX FIFO */
} }
/* Enable the UART Interrupt */ /* Enable the UART Interrupt */
NVIC_EnableIRQ(USART_IRQn); NVIC_EnableIRQ(USART_IRQn);
#if TX_INTERRUPT #if TX_INTERRUPT
LPC_USART->IER = IER_RBR | IER_THRE | IER_RLS; /* Enable UART interrupt */ LPC_USART->IER = IER_RBR | IER_THRE | IER_RLS; /* Enable UART interrupt */
#else #else
LPC_USART->IER = IER_RBR | IER_RLS; /* Enable UART interrupt */ LPC_USART->IER = IER_RBR | IER_RLS; /* Enable UART interrupt */
#endif #endif
#if AUTOBAUD_ENABLE #if AUTOBAUD_ENABLE
LPC_USART->IER |= IER_ABEO | IER_ABTO; LPC_USART->IER |= IER_ABEO | IER_ABTO;
#endif #endif
return; return;
} }
/***************************************************************************** /*****************************************************************************
** Function name: UARTSend ** Function name: UARTSend
** **
** Descriptions: Send a block of data to the UART 0 port based ** Descriptions: Send a block of data to the UART 0 port based
** on the data length ** on the data length
** **
** parameters: buffer pointer, and data length ** parameters: buffer pointer, and data length
** Returned value: None ** Returned value: None
** **
*****************************************************************************/ *****************************************************************************/
void UARTSend(uint8_t *BufferPtr, uint32_t Length) void UARTSend(uint8_t *BufferPtr, uint32_t Length)
{ {
while ( Length != 0 ) while ( Length != 0 )
{ {
/* THRE status, contain valid data */ /* THRE status, contain valid data */
#if !TX_INTERRUPT #if !TX_INTERRUPT
while ( !(LPC_USART->LSR & LSR_THRE) ); while ( !(LPC_USART->LSR & LSR_THRE) );
LPC_USART->THR = *BufferPtr; LPC_USART->THR = *BufferPtr;
#else #else
/* Below flag is set inside the interrupt handler when THRE occurs. */ /* Below flag is set inside the interrupt handler when THRE occurs. */
while ( !(UARTTxEmpty & 0x01) ); while ( !(UARTTxEmpty & 0x01) );
LPC_USART->THR = *BufferPtr; LPC_USART->THR = *BufferPtr;
UARTTxEmpty = 0; /* not empty in the THR until it shifts out */ UARTTxEmpty = 0; /* not empty in the THR until it shifts out */
#endif #endif
BufferPtr++; BufferPtr++;
Length--; Length--;
} }
return; return;
} }
/***************************************************************************** /*****************************************************************************
** Function name: print_string ** Function name: print_string
** **
** Descriptions: print out string on the terminal ** Descriptions: print out string on the terminal
** **
** parameters: pointer to the string end with NULL char. ** parameters: pointer to the string end with NULL char.
** Returned value: none. ** Returned value: none.
** **
*****************************************************************************/ *****************************************************************************/
void print_string( uint8_t *str_ptr ) void print_string( uint8_t *str_ptr )
{ {
while(*str_ptr != 0x00) while(*str_ptr != 0x00)
{ {
while((LPC_USART->LSR & 0x60) != 0x60); while((LPC_USART->LSR & 0x60) != 0x60);
LPC_USART->THR = *str_ptr; LPC_USART->THR = *str_ptr;
str_ptr++; str_ptr++;
} }
return; return;
} }
/***************************************************************************** /*****************************************************************************
** Function name: get_key ** Function name: get_key
** **
** Descriptions: Get a character from the terminal ** Descriptions: Get a character from the terminal
** **
** parameters: None ** parameters: None
** Returned value: character, zero is none. ** Returned value: character, zero is none.
** **
*****************************************************************************/ *****************************************************************************/
uint8_t get_key( void ) uint8_t get_key( void )
{ {
uint8_t dummy; uint8_t dummy;
while ( !(LPC_USART->LSR & 0x01) ); while ( !(LPC_USART->LSR & 0x01) );
dummy = LPC_USART->RBR; dummy = LPC_USART->RBR;
if ((dummy>=65) && (dummy<=90)) if ((dummy>=65) && (dummy<=90))
{ {
/* convert capital to non-capital character, A2a, B2b, C2c. */ /* convert capital to non-capital character, A2a, B2b, C2c. */
dummy +=32; dummy +=32;
} }
/* echo */ /* echo */
LPC_USART->THR = dummy; LPC_USART->THR = dummy;
return(dummy); return(dummy);
} }
/****************************************************************************** /******************************************************************************
** End Of File ** End Of File
******************************************************************************/ ******************************************************************************/

View File

@ -1,18 +1,18 @@
; ************************************************************* ; *************************************************************
; *** Scatter-Loading Description File generated by uVision *** ; *** Scatter-Loading Description File generated by uVision ***
; ************************************************************* ; *************************************************************
LR_IROM1 0x00000000 0x00010000 { ; load region size_region LR_IROM1 0x00000000 0x00010000 { ; load region size_region
ER_IROM1 0x00000000 0x00010000 { ; load address = execution address ER_IROM1 0x00000000 0x00010000 { ; load address = execution address
*.o (RESET, +First) *.o (RESET, +First)
*(InRoot$$Sections) *(InRoot$$Sections)
.ANY (+RO) .ANY (+RO)
} }
RW_IRAM1 0x10000000 0x00002000 { ; RW data RW_IRAM1 0x10000000 0x00002000 { ; RW data
.ANY (+RW +ZI) .ANY (+RW +ZI)
} }
RW_IRAM2 0x20004000 0x00000800 { RW_IRAM2 0x20004000 0x00000800 {
*(USBRAM_SECTION) *(USBRAM_SECTION)
} }
} }

Some files were not shown because too many files have changed in this diff Show More