blob: 1dd9e45cc0b3e543ffd39f0b2ad5b75aa45233a8 [file] [log] [blame]
Christina Quast53b21052014-12-09 15:34:35 +01001/* ----------------------------------------------------------------------------
2 * ATMEL Microcontroller Software Support
3 * ----------------------------------------------------------------------------
4 * Copyright (c) 2009, 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 * \file
32 *
33 * \par Purpose
34 *
35 * This module provides several definitions and methods for using an USART
36 * peripheral.
37 *
38 * \par Usage
39 *
40 * -# Enable the USART peripheral clock in the PMC.
41 * -# Enable the required USART PIOs (see pio.h).
42 * -# Configure the UART by calling USART_Configure.
43 * -# Enable the transmitter and/or the receiver of the USART using
44 * USART_SetTransmitterEnabled and USART_SetReceiverEnabled.
45 * -# Send data through the USART using the USART_Write and
46 * USART_WriteBuffer methods.
47 * -# Receive data from the USART using the USART_Read and
48 * USART_ReadBuffer functions; the availability of data can be polled
49 * with USART_IsDataAvailable.
50 * -# Disable the transmitter and/or the receiver of the USART with
51 * USART_SetTransmitterEnabled and USART_SetReceiverEnabled.
52 */
53
54#ifndef _USART_
55#define _USART_
56
57/*------------------------------------------------------------------------------
58 * Headers
59 *------------------------------------------------------------------------------*/
60
61#include "chip.h"
62
63#include <stdint.h>
64
65/*------------------------------------------------------------------------------
66 * Definitions
67 *------------------------------------------------------------------------------*/
68
69/** \section USART_mode USART modes
70 * This section lists several common operating modes for an USART peripheral.
71 *
72 * \b Modes
73 * - USART_MODE_ASYNCHRONOUS
74 * - USART_MODE_IRDA
75 */
76
77/** Basic asynchronous mode, i.e. 8 bits no parity.*/
78#define USART_MODE_ASYNCHRONOUS (US_MR_CHRL_8_BIT | US_MR_PAR_NO)
79
80/** IRDA mode*/
81#define USART_MODE_IRDA (AT91C_US_USMODE_IRDA | AT91C_US_CHRL_8_BITS | AT91C_US_PAR_NONE | AT91C_US_FILTER)
82
83/** SPI mode*/
84#define AT91C_US_USMODE_SPIM 0xE
85#define US_SPI_CPOL_0 (0x0<<16)
86#define US_SPI_CPHA_0 (0x0<<8)
87#define US_SPI_CPOL_1 (0x1<<16)
88#define US_SPI_CPHA_1 (0x1<<8)
89#define US_SPI_BPMODE_0 (US_SPI_CPOL_0|US_SPI_CPHA_1)
90#define US_SPI_BPMODE_1 (US_SPI_CPOL_0|US_SPI_CPHA_0)
91#define US_SPI_BPMODE_2 (US_SPI_CPOL_1|US_SPI_CPHA_1)
92#define US_SPI_BPMODE_3 (US_SPI_CPOL_1|US_SPI_CPHA_0)
93
94#ifdef __cplusplus
95 extern "C" {
96#endif
97
98/*------------------------------------------------------------------------------*/
99/* Exported functions */
100/*------------------------------------------------------------------------------*/
101
102extern void USART_Configure( Usart *usart, uint32_t mode, uint32_t baudrate, uint32_t masterClock ) ;
103extern uint32_t USART_GetStatus( Usart *usart ) ;
104extern void USART_EnableIt( Usart *usart,uint32_t mode ) ;
105extern void USART_DisableIt( Usart *usart,uint32_t mode ) ;
106extern void USART_SetTransmitterEnabled( Usart *usart, uint8_t enabled ) ;
107
108extern void USART_SetReceiverEnabled( Usart *usart, uint8_t enabled ) ;
109
110extern void USART_Write( Usart *usart, uint16_t data, volatile uint32_t timeOut ) ;
111
112extern uint8_t USART_WriteBuffer( Usart *usart, void *buffer, uint32_t size ) ;
113
114extern uint16_t USART_Read( Usart *usart, volatile uint32_t timeOut ) ;
115
116extern uint8_t USART_ReadBuffer( Usart *usart, void *buffer, uint32_t size ) ;
117
118extern uint8_t USART_IsDataAvailable( Usart *usart ) ;
119
120extern void USART_SetIrdaFilter(Usart *pUsart, uint8_t filter);
121
122extern void USART_PutChar( Usart *usart, uint8_t c ) ;
123
124extern uint32_t USART_IsRxReady( Usart *usart ) ;
125
126extern uint8_t USART_GetChar( Usart *usart ) ;
127
128#ifdef __cplusplus
129}
130#endif
131
132#endif /* #ifndef _USART_ */
133