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
uart.c
Go to the documentation of this file.
1
/*
2
* @brief UART interrupt example with ring buffers
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 "chip.h"
33
#include "board.h"
34
#include "string.h"
35
64
/*****************************************************************************
65
* Private types/enumerations/variables
66
****************************************************************************/
67
68
/* Transmit and receive ring buffers */
69
STATIC
RINGBUFF_T
txring
,
rxring
;
70
71
/* Ring buffer size */
72
#define UART_RB_SIZE 64
73
74
/* Transmit and receive buffers */
75
static
uint8_t
rxbuff
[
UART_RB_SIZE
],
txbuff
[
UART_RB_SIZE
];
76
77
const
char
inst1
[] =
"LPC13xx UART example using ring buffers\r\n"
;
78
const
char
inst2
[] =
"Press a key to echo it back or ESC to quit\r\n"
;
79
80
/*****************************************************************************
81
* Public types/enumerations/variables
82
****************************************************************************/
83
84
/*****************************************************************************
85
* Private functions
86
****************************************************************************/
87
88
/*****************************************************************************
89
* Public functions
90
****************************************************************************/
91
96
void
UART_IRQHandler
(
void
)
97
{
98
/* Want to handle any errors? Do it here. */
99
100
/* Use default ring buffer handler. Override this with your own
101
code if you need more capability. */
102
Chip_UART_IRQRBHandler
(
LPC_USART
, &
rxring
, &
txring
);
103
}
104
109
int
main
(
void
)
110
{
111
uint8_t key;
112
113
Board_Init
();
114
Board_UART_Init
();
115
116
/* Setup UART for 115.2K8N1 */
117
Chip_UART_Init
(
LPC_USART
);
118
Chip_UART_SetBaud
(
LPC_USART
, 115200);
119
Chip_UART_ConfigData
(
LPC_USART
, (
UART_LCR_WLEN8
|
UART_LCR_SBS_1BIT
));
120
Chip_UART_SetupFIFOS
(
LPC_USART
, (
UART_FCR_FIFO_EN
|
UART_FCR_TRG_LEV2
));
121
Chip_UART_TXEnable
(
LPC_USART
);
122
123
/* Before using the ring buffers, initialize them using the ring
124
buffer init function */
125
RingBuffer_Init
(&
rxring
,
rxbuff
, 1,
UART_RB_SIZE
);
126
RingBuffer_Init
(&
txring
,
txbuff
, 1,
UART_RB_SIZE
);
127
128
/* Enable receive data and line status interrupt */
129
Chip_UART_IntEnable
(
LPC_USART
, (
UART_IER_RBRINT
|
UART_IER_RLSINT
));
130
131
/* preemption = 1, sub-priority = 1 */
132
NVIC_SetPriority(UART0_IRQn, 1);
133
NVIC_EnableIRQ(UART0_IRQn);
134
135
/* Initial message sent using blocking method to prevent ring
136
buffer overflow */
137
Chip_UART_SendBlocking
(
LPC_USART
,
inst1
,
sizeof
(
inst1
) - 1);
138
Chip_UART_SendRB
(
LPC_USART
, &
txring
,
inst2
,
sizeof
(
inst2
) - 1);
139
140
/* Poll the receive ring buffer for the ESC (ASCII 27) key */
141
key = 0;
142
while
(key != 27) {
143
if
(
Chip_UART_ReadRB
(
LPC_USART
, &
rxring
, &key, 1) > 0) {
144
/* Wrap value back around */
145
Chip_UART_SendRB
(
LPC_USART
, &
txring
, (
const
uint8_t *) &key, 1);
146
}
147
}
148
149
/* DeInitialize UART0 peripheral */
150
NVIC_DisableIRQ(UART0_IRQn);
151
Chip_UART_DeInit
(
LPC_USART
);
152
153
return
1;
154
}
155
applications
lpc13xx
examples
periph
periph_uart
uart.c
Generated on Fri May 10 2013 10:42:08 for LPCOpen Platform by
1.8.2