LPCOpen Platform
v1.03
LPCOpen Platform for NXP LPC Microcontrollers
Main Page
Modules
Data Structures
Files
Related Pages
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Groups
Pages
board_nxp_xpresso_812.c
Go to the documentation of this file.
1
/*
2
* @brief NXP XPresso 812 board file
3
*
4
* @note
5
* Copyright(C) NXP Semiconductors, 2012
6
* All rights reserved.
7
*
8
* @par
9
* Software that is described herein is for illustrative purposes only
10
* which provides customers with programming information regarding the
11
* LPC products. This software is supplied "AS IS" without any warranties of
12
* any kind, and NXP Semiconductors and its licensor disclaim any and
13
* all warranties, express or implied, including all implied warranties of
14
* merchantability, fitness for a particular purpose and non-infringement of
15
* intellectual property rights. NXP Semiconductors assumes no responsibility
16
* or liability for the use of the software, conveys no license or rights under any
17
* patent, copyright, mask work right, or any other intellectual property rights in
18
* or to any products. NXP Semiconductors reserves the right to make changes
19
* in the software without notification. NXP Semiconductors also makes no
20
* representation or warranty that such application will be suitable for the
21
* specified use without further testing or modification.
22
*
23
* @par
24
* Permission to use, copy, modify, and distribute this software and its
25
* documentation is hereby granted, under NXP Semiconductors' and its
26
* licensor's relevant copyrights in the software, without fee, provided that it
27
* is used in conjunction with NXP Semiconductors microcontrollers. This
28
* copyright, permission, and disclaimer notice must appear in all copies of
29
* this code.
30
*/
31
32
#include "
board.h
"
33
#include "string.h"
34
39
/*****************************************************************************
40
* Private types/enumerations/variables
41
****************************************************************************/
42
43
#define RED_LED_PORT_BIT 7
44
#define BLUE_LED_PORT_BIT 16
45
#define GREEN_LED_PORT_BIT 17
46
47
static
const
uint8_t
LED_BITS
[] = {
RED_LED_PORT_BIT
,
BLUE_LED_PORT_BIT
,
GREEN_LED_PORT_BIT
};
48
49
/*****************************************************************************
50
* Public types/enumerations/variables
51
****************************************************************************/
52
53
/*****************************************************************************
54
* Private functions
55
****************************************************************************/
56
57
/* Initialize the LEDs on the NXP LPC812 XPresso Board */
58
static
void
Board_LED_Init
(
void
)
59
{
60
uint8_t i;
61
for
(i = 0; i <
sizeof
(
LED_BITS
); i++) {
62
Chip_GPIO_WriteDirBit
(
LPC_GPIO_PORT
,
LPC8XX_PORT_NUM
,
LED_BITS
[i],
true
);
63
Chip_GPIO_WritePortBit
(
LPC_GPIO_PORT
,
LPC8XX_PORT_NUM
,
LED_BITS
[i], (
bool
)
true
);
64
}
65
}
66
67
/*****************************************************************************
68
* Public functions
69
****************************************************************************/
70
71
/* Set the LED to the state of "On" */
72
void
Board_LED_Set
(uint8_t LEDNumber,
bool
On
)
73
{
74
Chip_GPIO_WritePortBit
(
LPC_GPIO_PORT
,
LPC8XX_PORT_NUM
,
LED_BITS
[LEDNumber], (
bool
) !On);
75
}
76
77
/* Return the state of LEDNumber */
78
bool
Board_LED_Test
(uint8_t LEDNumber)
79
{
80
return
(
bool
) !
Chip_GPIO_ReadPortBit
(
LPC_GPIO_PORT
,
LPC8XX_PORT_NUM
,
LED_BITS
[LEDNumber]);
81
}
82
83
/* System Clock Frequency (Core Clock) */
84
uint32_t
SystemCoreClock
;
85
86
/*
87
* Update system core clock rate, should be called if the system has
88
* a clock rate change
89
*/
90
void
SystemCoreClockUpdate
(
void
)
91
{
92
/* CPU core speed */
93
SystemCoreClock
=
Chip_Clock_GetSystemClockRate
();
94
}
95
96
/* Board UART Initialisation function */
97
void
Board_UART_Init
(
LPC_USART_T
*pUART)
98
{
99
/* Enable the clock to the Switch Matrix */
100
Chip_Clock_EnablePeriphClock
(
SYSCTL_CLOCK_SWM
);
101
Chip_Clock_SetUARTClockDiv
(1);
/* divided by 1 */
102
if
(pUART ==
LPC_USART0
) {
103
/*connect the U0_TXD_O and U0_RXD_I signals to port pins(P0.4, P0.0) */
104
Chip_SWM_FixedPinEnable
(
ACMP_I1
,
DISABLE
);
105
Chip_SWM_MovablePinAssign
(
SWM_U0_TXD_O
,
PIO4
);
106
Chip_SWM_MovablePinAssign
(
SWM_U0_RXD_I
,
PIO0
);
107
/* Enable USART0 clock */
108
Chip_Clock_EnablePeriphClock
(
SYSCTL_CLOCK_UART0
);
// FIXME UART clocking and reset need to be part of CHIP driver
109
/* Peripheral reset control to USART0, a "1" bring it out of reset. */
110
Chip_SYSCTL_PeriphReset
(
RESET_USART0
);
111
}
112
else
if
(pUART ==
LPC_USART1
) {
113
/*connect the U1_TXD_O and U1_RXD_I signals to port pins(P0.13, P0.14) */
114
Chip_SWM_MovablePinAssign
(
SWM_U1_TXD_O
,
PIO13
);
115
Chip_SWM_MovablePinAssign
(
SWM_U1_RXD_I
,
PIO14
);
116
/* Enable USART1 clock */
117
Chip_Clock_EnablePeriphClock
(
SYSCTL_CLOCK_UART1
);
// FIXME UART clocking and reset need to be part of CHIP driver
118
/* Peripheral reset control to USART1, a "1" bring it out of reset. */
119
Chip_SYSCTL_PeriphReset
(
RESET_USART1
);
120
}
121
else
{
122
/*connect the U2_TXD_O and U2_RXD_I signals to port pins(P0.13, P0.14) */
123
Chip_SWM_MovablePinAssign
(
SWM_U2_TXD_O
,
PIO13
);
124
Chip_SWM_MovablePinAssign
(
SWM_U2_RXD_I
,
PIO14
);
125
/* Enable USART2 clock */
126
Chip_Clock_EnablePeriphClock
(
SYSCTL_CLOCK_UART2
);
// FIXME UART clocking and reset need to be part of CHIP driver
127
/* Peripheral reset control to USART2, a "1" bring it out of reset. */
128
Chip_SYSCTL_PeriphReset
(
RESET_USART2
);
129
}
130
}
131
132
/* Initialize pin muxing for SPI interface */
133
void
Board_SPI_Init
(
LPC_SPI_T
*pSPI)
134
{
135
/* Enable the clock to the Switch Matrix */
136
Chip_Clock_EnablePeriphClock
(
SYSCTL_CLOCK_SWM
);
137
if
(pSPI ==
LPC_SPI0
) {
138
/*
139
* Initialize SSP0 pins connect
140
* SCK0: PINASSIGN3[31:24] : Select P0.12
141
* MOSI: PINASSIGN4[7:0] : Select P0.14
142
* MISO0: PINASSIGN4[15:8]: Select P0.6
143
* SSEL0: PINASSIGN4[23:16] : Select P0.13
144
*/
145
Chip_SWM_FixedPinEnable
(
VDDCMP
,
DISABLE
);
146
Chip_SWM_MovablePinAssign
(
SWM_SPI0_SCK_IO
,
PIO12
);
147
Chip_SWM_MovablePinAssign
(
SWM_SPI0_MOSI_IO
,
PIO14
);
148
Chip_SWM_MovablePinAssign
(
SWM_SPI0_MISO_IO
,
PIO6
);
149
Chip_SWM_MovablePinAssign
(
SWM_SPI0_SSEL_IO
,
PIO13
);
150
151
}
152
else
{
153
/*
154
* Initialize SSP0 pins connect
155
* SCK1: PINASSIGN4[31:24]: Select P0.12
156
* MOSI1: PINASSIGN5[7:0]: Select P0.14
157
* MISO1: PINASSIGN5[15:8] : Select P0.6
158
* SSEL1: PINASSIGN5[23:16]: Select P0.13
159
*/
160
Chip_SWM_FixedPinEnable
(
VDDCMP
,
DISABLE
);
161
Chip_SWM_MovablePinAssign
(
SWM_SPI1_SCK_IO
,
PIO12
);
162
Chip_SWM_MovablePinAssign
(
SWM_SPI1_MOSI_IO
,
PIO14
);
163
Chip_SWM_MovablePinAssign
(
SWM_SPI1_MISO_IO
,
PIO6
);
164
Chip_SWM_MovablePinAssign
(
SWM_SPI1_SSEL_IO
,
PIO13
);
165
}
166
/* Disable the clock to the Switch Matrix to save power */
167
Chip_Clock_DisablePeriphClock
(
SYSCTL_CLOCK_SWM
);
168
}
169
170
/* Initializes clock and pin muxing for I2C interface */
171
void
Board_I2C_Init
(
void
)
172
{
173
/* Enable the clock to the Switch Matrix */
174
Chip_Clock_EnablePeriphClock
(
SYSCTL_CLOCK_SWM
);
175
/* Connect the I2C_SDA and I2C_SCL signals to port pins(P0.10, P0.11) */
176
Chip_SWM_MovablePinAssign
(
SWM_I2C_SDA_IO
,
PIO10
);
177
Chip_SWM_MovablePinAssign
(
SWM_I2C_SCL_IO
,
PIO11
);
178
179
/* Enable Fast Mode Plus for I2C pins */
180
Chip_IOCON_PinSetI2CMode
(
LPC_IOCON
,
PIO10
,
PIN_I2CMODE_FASTPLUS
);
181
Chip_IOCON_PinSetI2CMode
(
LPC_IOCON
,
PIO11
,
PIN_I2CMODE_FASTPLUS
);
182
}
183
184
/* Sends a character on the UART */
185
void
Board_UARTPutChar
(
char
ch)
186
{
187
#if defined(DEBUG_UART)
188
while
(
Chip_UART_SendByte
(
DEBUG_UART
, (uint8_t) ch) ==
ERROR
) {}
189
#endif
190
}
191
192
/* Gets a character from the UART, returns EOF if no character is ready */
193
int
Board_UARTGetChar
(
void
)
194
{
195
#if defined(DEBUG_UART)
196
uint8_t data;
197
198
if
(
Chip_UART_ReceiveByte
(
DEBUG_UART
, &data) ==
SUCCESS
) {
199
return
(
int
) data;
200
}
201
#endif
202
return
EOF
;
203
}
204
205
/* Outputs a string on the debug UART */
206
void
Board_UARTPutSTR
(
char
*str)
207
{
208
#if defined(DEBUG_UART)
209
while
(*str !=
'\0'
) {
210
Board_UARTPutChar
(*str++);
211
}
212
#endif
213
}
214
215
/* Initialize debug output via UART for board */
216
void
Board_Debug_Init
(
void
)
217
{
218
#if defined(DEBUG_UART)
219
Board_UART_Init
(
DEBUG_UART
);
220
221
222
Chip_UART_ConfigData
(
DEBUG_UART
,
UART_DATALEN_8
,
UART_PARITY_NONE
,
UART_STOPLEN_1
);
223
Chip_UART_SetBaudRate
(
DEBUG_UART
, 115200);
224
Chip_UART_Init
(
DEBUG_UART
);
225
#endif
226
}
227
228
/* Set up and initialize all required blocks and functions related to the
229
board hardware */
230
void
Board_Init
(
void
)
231
{
232
/* Initialize the system core clock variable */
233
SystemCoreClockUpdate
();
234
235
/* Sets up DEBUG UART */
236
DEBUGINIT
();
237
238
/* Initialize GPIO */
239
Chip_GPIO_Init
(
LPC_GPIO_PORT
);
240
241
/* Initialize the LEDs */
242
Board_LED_Init
();
243
}
244
software
lpc_core
lpc_board
boards_8xx
nxp_xpresso_812
board_nxp_xpresso_812.c
Generated on Fri May 10 2013 10:42:11 for LPCOpen Platform by
1.8.2