source: Initial setup
This commit is contained in:
188
source/lpc_board_nxp_lpcxpresso_11u68/src/board.c
Normal file
188
source/lpc_board_nxp_lpcxpresso_11u68/src/board.c
Normal file
@@ -0,0 +1,188 @@
|
||||
/*
|
||||
* @brief NXP LPCXpresso 11U68 board file
|
||||
*
|
||||
* @note
|
||||
* Copyright(C) NXP Semiconductors, 2013
|
||||
* All rights reserved.
|
||||
*
|
||||
* @par
|
||||
* Software that is described herein is for illustrative purposes only
|
||||
* which provides customers with programming information regarding the
|
||||
* LPC products. This software is supplied "AS IS" without any warranties of
|
||||
* any kind, and NXP Semiconductors and its licensor disclaim any and
|
||||
* all warranties, express or implied, including all implied warranties of
|
||||
* merchantability, fitness for a particular purpose and non-infringement of
|
||||
* intellectual property rights. NXP Semiconductors assumes no responsibility
|
||||
* or liability for the use of the software, conveys no license or rights under any
|
||||
* patent, copyright, mask work right, or any other intellectual property rights in
|
||||
* or to any products. NXP Semiconductors reserves the right to make changes
|
||||
* in the software without notification. NXP Semiconductors also makes no
|
||||
* representation or warranty that such application will be suitable for the
|
||||
* specified use without further testing or modification.
|
||||
*
|
||||
* @par
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation is hereby granted, under NXP Semiconductors' and its
|
||||
* licensor's relevant copyrights in the software, without fee, provided that it
|
||||
* is used in conjunction with NXP Semiconductors microcontrollers. This
|
||||
* copyright, permission, and disclaimer notice must appear in all copies of
|
||||
* this code.
|
||||
*/
|
||||
|
||||
#include "board.h"
|
||||
#include "retarget.h"
|
||||
|
||||
/*****************************************************************************
|
||||
* Private types/enumerations/variables
|
||||
****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* Public types/enumerations/variables
|
||||
****************************************************************************/
|
||||
|
||||
/* System oscillator rate and RTC oscillator rate */
|
||||
const uint32_t OscRateIn = 12000000;
|
||||
const uint32_t RTCOscRateIn = 32768;
|
||||
|
||||
/*****************************************************************************
|
||||
* Private functions
|
||||
****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* Public functions
|
||||
****************************************************************************/
|
||||
|
||||
/* Sends a character on the UART */
|
||||
void Board_UARTPutChar(char ch)
|
||||
{
|
||||
#if defined(DEBUG_UART)
|
||||
Chip_UART0_SendBlocking(DEBUG_UART, &ch, 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Gets a character from the UART, returns EOF if no character is ready */
|
||||
int Board_UARTGetChar(void)
|
||||
{
|
||||
#if defined(DEBUG_UART)
|
||||
uint8_t data;
|
||||
|
||||
if (Chip_UART0_Read(DEBUG_UART, &data, 1) == 1) {
|
||||
return (int) data;
|
||||
}
|
||||
#endif
|
||||
return EOF;
|
||||
}
|
||||
|
||||
/* Outputs a string on the debug UART */
|
||||
void Board_UARTPutSTR(char *str)
|
||||
{
|
||||
#if defined(DEBUG_UART)
|
||||
while (*str != '\0') {
|
||||
Board_UARTPutChar(*str++);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Initialize debug output via UART for board */
|
||||
void Board_Debug_Init(void)
|
||||
{
|
||||
#if defined(DEBUG_UART)
|
||||
Chip_UART0_Init(DEBUG_UART);
|
||||
Chip_UART0_SetBaud(DEBUG_UART, 115200);
|
||||
Chip_UART0_ConfigData(DEBUG_UART, (UART0_LCR_WLEN8 | UART0_LCR_SBS_1BIT));
|
||||
Chip_UART0_SetupFIFOS(DEBUG_UART, (UART0_FCR_FIFO_EN | UART0_FCR_TRG_LEV2));
|
||||
Chip_UART0_TXEnable(DEBUG_UART);
|
||||
#endif
|
||||
}
|
||||
|
||||
#define MAXLEDS 3
|
||||
static const uint8_t ledports[MAXLEDS] = {2, 2, 2};
|
||||
static const uint8_t ledpins[MAXLEDS] = {17, 16, 18};
|
||||
|
||||
/* Initializes board LED(s) */
|
||||
static void Board_LED_Init(void)
|
||||
{
|
||||
int idx;
|
||||
|
||||
for (idx = 0; idx < MAXLEDS; idx++) {
|
||||
/* Set the GPIO as output with initial state off (high) */
|
||||
Chip_GPIO_SetPinDIROutput(LPC_GPIO, ledports[idx], ledpins[idx]);
|
||||
Chip_GPIO_SetPinState(LPC_GPIO, ledports[idx], ledpins[idx], true);
|
||||
}
|
||||
}
|
||||
|
||||
/* Sets the state of a board LED to on or off */
|
||||
void Board_LED_Set(uint8_t LEDNumber, bool On)
|
||||
{
|
||||
if (LEDNumber < MAXLEDS) {
|
||||
/* Toggle state, low is on, high is off */
|
||||
Chip_GPIO_SetPinState(LPC_GPIO, ledports[LEDNumber], ledpins[LEDNumber], !On);
|
||||
}
|
||||
}
|
||||
|
||||
/* Returns the current state of a board LED */
|
||||
bool Board_LED_Test(uint8_t LEDNumber)
|
||||
{
|
||||
bool state = false;
|
||||
|
||||
if (LEDNumber < MAXLEDS) {
|
||||
state = !Chip_GPIO_GetPinState(LPC_GPIO, ledports[LEDNumber], ledpins[LEDNumber]);
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
/* Toggles the current state of a board LED */
|
||||
void Board_LED_Toggle(uint8_t LEDNumber)
|
||||
{
|
||||
if (LEDNumber < MAXLEDS) {
|
||||
Chip_GPIO_SetPinToggle(LPC_GPIO, ledports[LEDNumber], ledpins[LEDNumber]);
|
||||
}
|
||||
}
|
||||
|
||||
/* Set up and initialize all required blocks and functions related to the
|
||||
board hardware */
|
||||
void Board_Init(void)
|
||||
{
|
||||
/* Sets up DEBUG UART */
|
||||
DEBUGINIT();
|
||||
|
||||
/* Initialize GPIO */
|
||||
Chip_GPIO_Init(LPC_GPIO);
|
||||
|
||||
/* Initialize LEDs */
|
||||
Board_LED_Init();
|
||||
}
|
||||
|
||||
/* Baseboard joystick buttons */
|
||||
#define NUM_BUTTONS 5
|
||||
static const uint8_t portButton[NUM_BUTTONS] = {0, 0, 0, 2, 2};
|
||||
static const uint8_t pinButton[NUM_BUTTONS] = {17, 20, 21, 2, 19};
|
||||
static const uint8_t stateButton[NUM_BUTTONS] = {JOY_PRESS, JOY_RIGHT, JOY_UP,
|
||||
JOY_DOWN, JOY_LEFT};
|
||||
|
||||
/* Initialize Joystick */
|
||||
void Board_Joystick_Init(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* IOCON states already selected in SystemInit(), GPIO setup only. Pullups
|
||||
are external, so IOCON with no states */
|
||||
for (i = 0; i < NUM_BUTTONS; i++) {
|
||||
Chip_GPIO_SetPinDIRInput(LPC_GPIO, portButton[i], pinButton[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/* Get Joystick status */
|
||||
uint8_t Joystick_GetStatus(void)
|
||||
{
|
||||
uint8_t i, ret = 0;
|
||||
|
||||
for (i = 0; i < NUM_BUTTONS; i++) {
|
||||
if ((Chip_GPIO_GetPinState(LPC_GPIO, portButton[i], pinButton[i])) == false) {
|
||||
ret |= stateButton[i];
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
186
source/lpc_board_nxp_lpcxpresso_11u68/src/board_sysinit.c
Normal file
186
source/lpc_board_nxp_lpcxpresso_11u68/src/board_sysinit.c
Normal file
@@ -0,0 +1,186 @@
|
||||
/*
|
||||
* @brief NXP LPCXpresso 11U68 Sysinit file
|
||||
*
|
||||
* @note
|
||||
* Copyright(C) NXP Semiconductors, 2013
|
||||
* All rights reserved.
|
||||
*
|
||||
* @par
|
||||
* Software that is described herein is for illustrative purposes only
|
||||
* which provides customers with programming information regarding the
|
||||
* LPC products. This software is supplied "AS IS" without any warranties of
|
||||
* any kind, and NXP Semiconductors and its licensor disclaim any and
|
||||
* all warranties, express or implied, including all implied warranties of
|
||||
* merchantability, fitness for a particular purpose and non-infringement of
|
||||
* intellectual property rights. NXP Semiconductors assumes no responsibility
|
||||
* or liability for the use of the software, conveys no license or rights under any
|
||||
* patent, copyright, mask work right, or any other intellectual property rights in
|
||||
* or to any products. NXP Semiconductors reserves the right to make changes
|
||||
* in the software without notification. NXP Semiconductors also makes no
|
||||
* representation or warranty that such application will be suitable for the
|
||||
* specified use without further testing or modification.
|
||||
*
|
||||
* @par
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation is hereby granted, under NXP Semiconductors' and its
|
||||
* licensor's relevant copyrights in the software, without fee, provided that it
|
||||
* is used in conjunction with NXP Semiconductors microcontrollers. This
|
||||
* copyright, permission, and disclaimer notice must appear in all copies of
|
||||
* this code.
|
||||
*/
|
||||
|
||||
#include "board.h"
|
||||
#include "string.h"
|
||||
|
||||
/* The System initialization code is called prior to the application and
|
||||
initializes the board for run-time operation. Board initialization
|
||||
includes clock setup and default pin muxing configuration. */
|
||||
|
||||
/*****************************************************************************
|
||||
* Private types/enumerations/variables
|
||||
****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* Public types/enumerations/variables
|
||||
****************************************************************************/
|
||||
|
||||
/* Pin muxing table, only items that need changing from their default pin
|
||||
state are in this table. Not every pin is mapped. */
|
||||
STATIC const PINMUX_GRP_T pinmuxing[] = {
|
||||
/* LPCXpresso pin - Base board function - Mapped function */
|
||||
/* RESET-PIO0_0 - PIO/RESET (pin 4) - Reset */
|
||||
/* PIO0_1-ISP_EN - PIO (pin 51) - GPIO input */
|
||||
/* PIO0_2-SSP0_SSEL - PIO/SSEL (pin 8) - GPIO output for SSP0 CS */
|
||||
/* PIO0_3-VBUS - - USB VBUS */
|
||||
{0, 3, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGMODE_EN)},
|
||||
/* PIO0_4-I2C_SCL - PIO/I2C-SCL (pin 41) - I2C0 SCL */
|
||||
{0, 4, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGMODE_EN)},
|
||||
/* PIO0_5-I2C_SDA - PIO/I2C-SDA (pin 40) - I2C0 SDA */
|
||||
{0, 5, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGMODE_EN)},
|
||||
/* PIO0_6 - - GPIO */
|
||||
/* PIO0_7 - PIO (pin 11) - GPIO */
|
||||
/* PIO0_8-SSP0_MISO - PIO/MISO (pin 6) - SSP0 MISO */
|
||||
{0, 8, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGMODE_EN)},
|
||||
/* PIO0_9-SSP0_MOSI - PIO/MOSI (pin 5) - SSP0 MOSI */
|
||||
{0, 9, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGMODE_EN)},
|
||||
/* SWCLK-PIO0_10 - - SWCLK */
|
||||
/* PIO0_11-ADC_9 - PIO/AD5 (pin 20) - ADC_9 */
|
||||
{0, 11, (IOCON_FUNC2 | IOCON_MODE_INACT)},
|
||||
/* PIO0_12-ADC_8 - PIO/AD4/SWDIO (pin 19) - ADC_8 */
|
||||
{0, 12, (IOCON_FUNC2 | IOCON_MODE_INACT)},
|
||||
/* PIO0_13-ADC_7 - PIO/AD3 (pin 18) - ADC_7 */
|
||||
{0, 13, (IOCON_FUNC2 | IOCON_MODE_INACT)},
|
||||
/* PIO0_14-ADC_6 - PIO/AD2 (pin 17) - ADC_6 */
|
||||
{0, 14, (IOCON_FUNC2 | IOCON_MODE_INACT)},
|
||||
/* PIO0_16-WAKEUP - - GPIO input */
|
||||
/* PIO0_17 - PIO (pin 12) - GPIO */
|
||||
/* TO_MUX_PIO0_18-ISP_RX - PIO/RXD (pin 10) - UART0 RX */
|
||||
{0, 18, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGMODE_EN)},
|
||||
/* PIO0_19-ISP_TX - PIO/TXD (pin 9) - UART0 TX */
|
||||
{0, 19, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGMODE_EN)},
|
||||
/* PIO0_20 - PIO (pin 13) - GPIO */
|
||||
/* PIO0_21 - PIO (pin 14) - GPIO */
|
||||
/* PIO0_22 - PIO (pin 21) - GPIO */
|
||||
/* PIO0_23-ADC_1 - PIO/AD1 (pin 16) - ADC_1 */
|
||||
{0, 23, (IOCON_FUNC1 | IOCON_MODE_INACT)},
|
||||
/* PIO1_0 - PIO (pin 22) - GPIO */
|
||||
/* PIO1_1 - PIO/USB_CONNECT (pin 23) - GPIO */
|
||||
/* PIO1_2 - PIO/SWCLK (pin 24) - SWCLK */
|
||||
/* PIO1_3 - PIO (pin 25) - GPIO */
|
||||
/* PIO1_4 - PIO (pin 26) - GPIO */
|
||||
/* PIO1_5 - PIO (pin 27) - GPIO */
|
||||
/* PIO1_6 - PIO (pin 53) - GPIO */
|
||||
/* PIO1_7 - PIO (pin 52) - GPIO */
|
||||
/* PIO1_8 - PIO (pin 50) - GPIO */
|
||||
/* PIO1_9-ADC_0 - PIO/AD0 (pin 15) - ADC_0 */
|
||||
{1, 9, (IOCON_FUNC1 | IOCON_MODE_INACT)},
|
||||
/* PIO1_10 - PIO (pin 49) - GPIO */
|
||||
/* PIO1_11-I2C1_SCL - - I2C1 SCL */
|
||||
{1, 11, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGMODE_EN)},
|
||||
/* PIO1_12 - PIO/USB_VBUS (pin 39) - GPIO input */
|
||||
/* PIO1_13 - PIO (pin 38) - GPIO output */
|
||||
/* PIO1_14-I2C_SDA - - I2C SDA */
|
||||
{1, 14, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGMODE_EN)},
|
||||
/* PIO1_15 - PIO (pin 48) - GPIO */
|
||||
/* PIO1_16 - - GPIO */
|
||||
/* PIO1_17 - - GPIO */
|
||||
/* PIO1_18 - - GPIO input, with pullup */
|
||||
/* PIO1_19 - - GPIO */
|
||||
/* PIO1_20-SSP1_SCK - - SSP1 CLK */
|
||||
{1, 20, (IOCON_FUNC2 | IOCON_MODE_INACT | IOCON_DIGMODE_EN)},
|
||||
/* PIO1_21-SSP1_MISO - - SSP1 MISO */
|
||||
{1, 21, (IOCON_FUNC2 | IOCON_MODE_INACT | IOCON_DIGMODE_EN)},
|
||||
/* PIO1_22-SSP1_MOSI - - SSP1 MOSI */
|
||||
{1, 22, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGMODE_EN)},
|
||||
/* PIO1_23-SSP1_SSEL - - SSP1 SSEL */
|
||||
{1, 23, (IOCON_FUNC2 | IOCON_MODE_INACT | IOCON_DIGMODE_EN)},
|
||||
/* PIO1_24-CT32B0_MAT0 - - GPIO input, with pullup */
|
||||
/* PIO1_25 - - GPIO */
|
||||
/* PIO1_26-CT32B0_MAT2 - - CT32B0_MAT2 */
|
||||
{1, 26, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGMODE_EN)},
|
||||
/* PIO1_27-CT32B0_MAT3 - - CT32B0_MAT3 */
|
||||
{1, 27, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGMODE_EN)},
|
||||
/* PIO1_28 - - GPIO */
|
||||
/* PIO1_29-SSP0_SCK - PIO/SCK (pin 7) - SSP0 CLK */
|
||||
{1, 29, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGMODE_EN)},
|
||||
/* PIO1_30 - - GPIO */
|
||||
/* PIO1_31 - - GPIO */
|
||||
/* PIO2_0 - - XTALIN */
|
||||
{2, 0, (IOCON_FUNC1 | IOCON_MODE_INACT)},
|
||||
/* PIO2_1 - - XTALOUT */
|
||||
{2, 1, (IOCON_FUNC1 | IOCON_MODE_INACT)},
|
||||
/* PIO2_2-SCT0_OUT1 - PIO (pin 46) - GPIO */
|
||||
/* PIO2_3-CT32B0_MAT1 - - CT32B0_MAT1 */
|
||||
{2, 3, (IOCON_FUNC2 | IOCON_MODE_INACT | IOCON_DIGMODE_EN)},
|
||||
/* PIO2_4 - - GPIO */
|
||||
/* PIO2_5 - - GPIO */
|
||||
/* PIO2_6 - - GPIO */
|
||||
/* PIO2_7-SCT0_OUT2 - PIO (pin 47) - GPIO */
|
||||
/* PIO2_8 - - GPIO */
|
||||
/* PIO2_9 - - GPIO */
|
||||
/* PIO2_10 - - GPIO */
|
||||
/* PIO2_11 - - GPIO */
|
||||
/* PIO2_12 - - GPIO */
|
||||
/* PIO2_13 - - GPIO */
|
||||
/* PIO2_14 - - GPIO */
|
||||
/* PIO2_15 - - GPIO */
|
||||
/* PIO2_16-SCT1_OUT0 - PIO/MAT=PWM (pin 42) - LED1 GREEN */
|
||||
/* PIO2_17-SCT1_OUT1 - PIO/MAT=PWM (pin 43) - LED0 RED */
|
||||
/* PIO2_18-SCT1_OUT2 - PIO (pin 44) - LED2 BLUE */
|
||||
/* PIO2_19-SCT1_OUT3 - PIO (pin 45) - GPIO */
|
||||
/* PIO2_20 - - GPIO */
|
||||
/* PIO2_21 - - GPIO */
|
||||
/* PIO2_22 - - GPIO */
|
||||
/* PIO2_23 - - GPIO */
|
||||
};
|
||||
|
||||
/*****************************************************************************
|
||||
* Private functions
|
||||
****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* Public functions
|
||||
****************************************************************************/
|
||||
|
||||
/* Sets up system pin muxing */
|
||||
void Board_SetupMuxing(void)
|
||||
{
|
||||
/* Enable IOCON clock */
|
||||
Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_IOCON);
|
||||
|
||||
Chip_IOCON_SetPinMuxing(LPC_IOCON, pinmuxing, sizeof(pinmuxing) / sizeof(PINMUX_GRP_T));
|
||||
}
|
||||
|
||||
/* Set up and initialize clocking prior to call to main */
|
||||
void Board_SetupClocking(void)
|
||||
{
|
||||
Chip_SetupXtalClocking();
|
||||
}
|
||||
|
||||
/* Set up and initialize hardware prior to call to main */
|
||||
void Board_SystemInit(void)
|
||||
{
|
||||
/* Setup system clocking and muxing */
|
||||
Board_SetupMuxing();/* Muxing first as it sets up ext oscillator pins */
|
||||
Board_SetupClocking();
|
||||
}
|
||||
251
source/lpc_board_nxp_lpcxpresso_11u68/src/retarget.h
Normal file
251
source/lpc_board_nxp_lpcxpresso_11u68/src/retarget.h
Normal file
@@ -0,0 +1,251 @@
|
||||
/*
|
||||
* @brief IO redirection support
|
||||
*
|
||||
* This file adds re-direction support to the library for various
|
||||
* projects. It can be configured in one of 3 ways - no redirection,
|
||||
* redirection via a UART, or redirection via semihosting. If DEBUG
|
||||
* is not defined, all printf statements will do nothing with the
|
||||
* output being throw away. If DEBUG is defined, then the choice of
|
||||
* output is selected by the DEBUG_SEMIHOSTING define. If the
|
||||
* DEBUG_SEMIHOSTING is not defined, then output is redirected via
|
||||
* the UART. If DEBUG_SEMIHOSTING is defined, then output will be
|
||||
* attempted to be redirected via semihosting. If the UART method
|
||||
* is used, then the Board_UARTPutChar and Board_UARTGetChar
|
||||
* functions must be defined to be used by this driver and the UART
|
||||
* must already be initialized to the correct settings.
|
||||
*
|
||||
* @note
|
||||
* Copyright(C) NXP Semiconductors, 2012
|
||||
* All rights reserved.
|
||||
*
|
||||
* @par
|
||||
* Software that is described herein is for illustrative purposes only
|
||||
* which provides customers with programming information regarding the
|
||||
* LPC products. This software is supplied "AS IS" without any warranties of
|
||||
* any kind, and NXP Semiconductors and its licensor disclaim any and
|
||||
* all warranties, express or implied, including all implied warranties of
|
||||
* merchantability, fitness for a particular purpose and non-infringement of
|
||||
* intellectual property rights. NXP Semiconductors assumes no responsibility
|
||||
* or liability for the use of the software, conveys no license or rights under any
|
||||
* patent, copyright, mask work right, or any other intellectual property rights in
|
||||
* or to any products. NXP Semiconductors reserves the right to make changes
|
||||
* in the software without notification. NXP Semiconductors also makes no
|
||||
* representation or warranty that such application will be suitable for the
|
||||
* specified use without further testing or modification.
|
||||
*
|
||||
* @par
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation is hereby granted, under NXP Semiconductors' and its
|
||||
* licensor's relevant copyrights in the software, without fee, provided that it
|
||||
* is used in conjunction with NXP Semiconductors microcontrollers. This
|
||||
* copyright, permission, and disclaimer notice must appear in all copies of
|
||||
* this code.
|
||||
*/
|
||||
|
||||
#include "board.h"
|
||||
|
||||
/* Keil (Realview) support */
|
||||
#if defined(__CC_ARM)
|
||||
|
||||
#include <stdio.h>
|
||||
#include <rt_misc.h>
|
||||
|
||||
#if defined(DEBUG_ENABLE)
|
||||
#if defined(DEBUG_SEMIHOSTING)
|
||||
#define ITM_Port8(n) (*((volatile unsigned char *) (0xE0000000 + 4 * n)))
|
||||
#define ITM_Port16(n) (*((volatile unsigned short *) (0xE0000000 + 4 * n)))
|
||||
#define ITM_Port32(n) (*((volatile unsigned long *) (0xE0000000 + 4 * n)))
|
||||
|
||||
#define DEMCR (*((volatile unsigned long *) (0xE000EDFC)))
|
||||
#define TRCENA 0x01000000
|
||||
|
||||
/* Write to SWO */
|
||||
void _ttywrch(int ch)
|
||||
{
|
||||
if (DEMCR & TRCENA) {
|
||||
while (ITM_Port32(0) == 0) {}
|
||||
ITM_Port8(0) = ch;
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
static INLINE void BoardOutChar(char ch)
|
||||
{
|
||||
Board_UARTPutChar(ch);
|
||||
}
|
||||
|
||||
#endif /* defined(DEBUG_SEMIHOSTING) */
|
||||
#endif /* defined(DEBUG_ENABLE) */
|
||||
|
||||
struct __FILE {
|
||||
int handle;
|
||||
};
|
||||
|
||||
FILE __stdout;
|
||||
FILE __stdin;
|
||||
FILE __stderr;
|
||||
|
||||
void *_sys_open(const char *name, int openmode)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fputc(int c, FILE *f)
|
||||
{
|
||||
#if defined(DEBUG_ENABLE)
|
||||
#if defined(DEBUG_SEMIHOSTING)
|
||||
_ttywrch(c);
|
||||
#else
|
||||
BoardOutChar((char) c);
|
||||
#endif
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fgetc(FILE *f)
|
||||
{
|
||||
#if defined(DEBUG_ENABLE) && !defined(DEBUG_SEMIHOSTING)
|
||||
return Board_UARTGetChar();
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
int ferror(FILE *f)
|
||||
{
|
||||
return EOF;
|
||||
}
|
||||
|
||||
void _sys_exit(int return_code)
|
||||
{
|
||||
label:
|
||||
__WFI();
|
||||
goto label; /* endless loop */
|
||||
}
|
||||
|
||||
#endif /* defined (__CC_ARM) */
|
||||
|
||||
/* IAR support */
|
||||
#if defined(__ICCARM__)
|
||||
/*******************
|
||||
*
|
||||
* Copyright 1998-2003 IAR Systems. All rights reserved.
|
||||
*
|
||||
* $Revision: 30870 $
|
||||
*
|
||||
* This is a template implementation of the "__write" function used by
|
||||
* the standard library. Replace it with a system-specific
|
||||
* implementation.
|
||||
*
|
||||
* The "__write" function should output "size" number of bytes from
|
||||
* "buffer" in some application-specific way. It should return the
|
||||
* number of characters written, or _LLIO_ERROR on failure.
|
||||
*
|
||||
* If "buffer" is zero then __write should perform flushing of
|
||||
* internal buffers, if any. In this case "handle" can be -1 to
|
||||
* indicate that all handles should be flushed.
|
||||
*
|
||||
* The template implementation below assumes that the application
|
||||
* provides the function "MyLowLevelPutchar". It should return the
|
||||
* character written, or -1 on failure.
|
||||
*
|
||||
********************/
|
||||
|
||||
#include <yfuns.h>
|
||||
|
||||
#if defined(DEBUG_ENABLE) && !defined(DEBUG_SEMIHOSTING)
|
||||
|
||||
_STD_BEGIN
|
||||
|
||||
#pragma module_name = "?__write"
|
||||
|
||||
/*
|
||||
If the __write implementation uses internal buffering, uncomment
|
||||
the following line to ensure that we are called with "buffer" as 0
|
||||
(i.e. flush) when the application terminates. */
|
||||
size_t __write(int handle, const unsigned char *buffer, size_t size)
|
||||
{
|
||||
#if defined(DEBUG_ENABLE)
|
||||
size_t nChars = 0;
|
||||
|
||||
if (buffer == 0) {
|
||||
/*
|
||||
This means that we should flush internal buffers. Since we
|
||||
don't we just return. (Remember, "handle" == -1 means that all
|
||||
handles should be flushed.)
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* This template only writes to "standard out" and "standard err",
|
||||
for all other file handles it returns failure. */
|
||||
if (( handle != _LLIO_STDOUT) && ( handle != _LLIO_STDERR) ) {
|
||||
return _LLIO_ERROR;
|
||||
}
|
||||
|
||||
for ( /* Empty */; size != 0; --size) {
|
||||
Board_UARTPutChar(*buffer++);
|
||||
++nChars;
|
||||
}
|
||||
|
||||
return nChars;
|
||||
#else
|
||||
return size;
|
||||
#endif /* defined(DEBUG_ENABLE) */
|
||||
}
|
||||
|
||||
_STD_END
|
||||
#endif
|
||||
|
||||
#endif /* defined (__ICCARM__) */
|
||||
|
||||
#if defined( __GNUC__ )
|
||||
/* Include stdio.h to pull in __REDLIB_INTERFACE_VERSION__ */
|
||||
#include <stdio.h>
|
||||
|
||||
#if (__REDLIB_INTERFACE_VERSION__ >= 20000)
|
||||
/* We are using new Redlib_v2 semihosting interface */
|
||||
#define WRITEFUNC __sys_write
|
||||
#define READFUNC __sys_readc
|
||||
#else
|
||||
/* We are using original Redlib semihosting interface */
|
||||
#define WRITEFUNC __write
|
||||
#define READFUNC __readc
|
||||
#endif
|
||||
|
||||
#if defined(DEBUG_ENABLE)
|
||||
#if defined(DEBUG_SEMIHOSTING)
|
||||
/* Do nothing, semihosting is enabled by default in LPCXpresso */
|
||||
#endif /* defined(DEBUG_SEMIHOSTING) */
|
||||
#endif /* defined(DEBUG_ENABLE) */
|
||||
|
||||
#if !defined(DEBUG_SEMIHOSTING)
|
||||
int WRITEFUNC(int iFileHandle, char *pcBuffer, int iLength)
|
||||
{
|
||||
#if defined(DEBUG_ENABLE)
|
||||
unsigned int i;
|
||||
for (i = 0; i < iLength; i++) {
|
||||
Board_UARTPutChar(pcBuffer[i]);
|
||||
}
|
||||
#endif
|
||||
|
||||
return iLength;
|
||||
}
|
||||
|
||||
/* 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
|
||||
from the debugger console window (which acts as stdin). But this version reads
|
||||
the character from the LPC1768/RDB1768 UART. */
|
||||
int READFUNC(void)
|
||||
{
|
||||
#if defined(DEBUG_ENABLE)
|
||||
char c = Board_UARTGetChar();
|
||||
return (int) c;
|
||||
|
||||
#else
|
||||
return (int) -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* !defined(DEBUG_SEMIHOSTING) */
|
||||
#endif /* defined ( __GNUC__ ) */
|
||||
Reference in New Issue
Block a user