1 |
608 |
jeremybenn |
/* ----------------------------------------------------------------------------
|
2 |
|
|
* ATMEL Microcontroller Software Support
|
3 |
|
|
* ----------------------------------------------------------------------------
|
4 |
|
|
* Copyright (c) 2008, Atmel Corporation
|
5 |
|
|
*
|
6 |
|
|
* All rights reserved.
|
7 |
|
|
*
|
8 |
|
|
* Redistribution and use in source and binary forms, with or without
|
9 |
|
|
* modification, are permitted provided that the following conditions are met:
|
10 |
|
|
*
|
11 |
|
|
* - Redistributions of source code must retain the above copyright notice,
|
12 |
|
|
* this list of conditions and the disclaimer below.
|
13 |
|
|
*
|
14 |
|
|
* Atmel's name may not be used to endorse or promote products derived from
|
15 |
|
|
* this software without specific prior written permission.
|
16 |
|
|
*
|
17 |
|
|
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
18 |
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
19 |
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
20 |
|
|
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
21 |
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 |
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
23 |
|
|
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
24 |
|
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
25 |
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
26 |
|
|
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27 |
|
|
* ----------------------------------------------------------------------------
|
28 |
|
|
*/
|
29 |
|
|
|
30 |
|
|
//------------------------------------------------------------------------------
|
31 |
|
|
/// \dir
|
32 |
|
|
/// !Purpose
|
33 |
|
|
///
|
34 |
|
|
/// This module provides several definitions and methods for using an USART
|
35 |
|
|
/// peripheral.
|
36 |
|
|
///
|
37 |
|
|
/// !Usage
|
38 |
|
|
/// -# Enable the USART peripheral clock in the PMC.
|
39 |
|
|
/// -# Enable the required USART PIOs (see pio.h).
|
40 |
|
|
/// -# Configure the UART by calling USART_Configure.
|
41 |
|
|
/// -# Enable the transmitter and/or the receiver of the USART using
|
42 |
|
|
/// USART_SetTransmitterEnabled and USART_SetReceiverEnabled.
|
43 |
|
|
/// -# Send data through the USART using the USART_Write and
|
44 |
|
|
/// USART_WriteBuffer methods.
|
45 |
|
|
/// -# Receive data from the USART using the USART_Read and
|
46 |
|
|
/// USART_ReadBuffer functions; the availability of data can be polled
|
47 |
|
|
/// with USART_IsDataAvailable.
|
48 |
|
|
/// -# Disable the transmitter and/or the receiver of the USART with
|
49 |
|
|
/// USART_SetTransmitterEnabled and USART_SetReceiverEnabled.
|
50 |
|
|
//------------------------------------------------------------------------------
|
51 |
|
|
|
52 |
|
|
#ifndef USART_H
|
53 |
|
|
#define USART_H
|
54 |
|
|
|
55 |
|
|
//------------------------------------------------------------------------------
|
56 |
|
|
// Headers
|
57 |
|
|
//------------------------------------------------------------------------------
|
58 |
|
|
|
59 |
|
|
#include <board.h>
|
60 |
|
|
|
61 |
|
|
//------------------------------------------------------------------------------
|
62 |
|
|
// Definitions
|
63 |
|
|
//------------------------------------------------------------------------------
|
64 |
|
|
|
65 |
|
|
//------------------------------------------------------------------------------
|
66 |
|
|
/// \page "USART modes"
|
67 |
|
|
/// This page lists several common operating modes for an USART peripheral.
|
68 |
|
|
///
|
69 |
|
|
/// !Modes
|
70 |
|
|
/// - USART_MODE_ASYNCHRONOUS
|
71 |
|
|
|
72 |
|
|
/// Basic asynchronous mode, i.e. 8 bits no parity.
|
73 |
|
|
#define USART_MODE_ASYNCHRONOUS (AT91C_US_CHRL_8_BITS | AT91C_US_PAR_NONE)
|
74 |
|
|
//------------------------------------------------------------------------------
|
75 |
|
|
|
76 |
|
|
//------------------------------------------------------------------------------
|
77 |
|
|
// Exported functions
|
78 |
|
|
//------------------------------------------------------------------------------
|
79 |
|
|
|
80 |
|
|
extern void USART_Configure(
|
81 |
|
|
AT91S_USART *usart,
|
82 |
|
|
unsigned int mode,
|
83 |
|
|
unsigned int baudrate,
|
84 |
|
|
unsigned int masterClock);
|
85 |
|
|
|
86 |
|
|
extern void USART_SetTransmitterEnabled(AT91S_USART *usart, unsigned char enabled);
|
87 |
|
|
|
88 |
|
|
extern void USART_SetReceiverEnabled(AT91S_USART *usart, unsigned char enabled);
|
89 |
|
|
|
90 |
|
|
extern void USART_Write(
|
91 |
|
|
AT91S_USART *usart,
|
92 |
|
|
unsigned short data,
|
93 |
|
|
volatile unsigned int timeOut);
|
94 |
|
|
|
95 |
|
|
extern unsigned char USART_WriteBuffer(
|
96 |
|
|
AT91S_USART *usart,
|
97 |
|
|
void *buffer,
|
98 |
|
|
unsigned int size);
|
99 |
|
|
|
100 |
|
|
extern unsigned short USART_Read(
|
101 |
|
|
AT91S_USART *usart,
|
102 |
|
|
volatile unsigned int timeOut);
|
103 |
|
|
|
104 |
|
|
extern unsigned char USART_ReadBuffer(
|
105 |
|
|
AT91S_USART *usart,
|
106 |
|
|
void *buffer,
|
107 |
|
|
unsigned int size);
|
108 |
|
|
|
109 |
|
|
extern unsigned char USART_IsDataAvailable(AT91S_USART *usart);
|
110 |
|
|
|
111 |
|
|
#endif //#ifndef USART_H
|
112 |
|
|
|