]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M7_SAMV71_Xplained_IAR_Keil/libchip_samv7/include/usart.h
Final V8.2.1 release ready for tagging:
[freertos] / FreeRTOS / Demo / CORTEX_M7_SAMV71_Xplained_IAR_Keil / libchip_samv7 / include / usart.h
1 /* ----------------------------------------------------------------------------\r
2  *         SAM Software Package License \r
3  * ----------------------------------------------------------------------------\r
4  * Copyright (c) 2011, Atmel Corporation\r
5  *\r
6  * All rights reserved.\r
7  *\r
8  * Redistribution and use in source and binary forms, with or without\r
9  * modification, are permitted provided that the following conditions are met:\r
10  *\r
11  * - Redistributions of source code must retain the above copyright notice,\r
12  * this list of conditions and the disclaimer below.\r
13  *\r
14  * Atmel's name may not be used to endorse or promote products derived from\r
15  * this software without specific prior written permission.\r
16  *\r
17  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR\r
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE\r
20  * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,\r
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\r
23  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\r
24  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
25  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\r
26  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
27  * ----------------------------------------------------------------------------\r
28  */\r
29 \r
30 /**\r
31  * \file\r
32  *\r
33  * \par Purpose\r
34  *\r
35  * This module provides several definitions and methods for using an USART\r
36  * peripheral.\r
37  *\r
38  * \par Usage\r
39  *\r
40  * -# Enable the USART peripheral clock in the PMC.\r
41  * -# Enable the required USART PIOs (see pio.h).\r
42  * -# Configure the UART by calling USART_Configure.\r
43  * -# Enable the transmitter and/or the receiver of the USART using\r
44  *    USART_SetTransmitterEnabled and USART_SetReceiverEnabled.\r
45  * -# Send data through the USART using the USART_Write methods.\r
46  * -# Receive data from the USART using the USART_Read functions; the availability of data can be polled\r
47  *    with USART_IsDataAvailable.\r
48  * -# Disable the transmitter and/or the receiver of the USART with\r
49  *    USART_SetTransmitterEnabled and USART_SetReceiverEnabled.\r
50  */\r
51 \r
52 #ifndef _USART_\r
53 #define _USART_\r
54 \r
55 /*------------------------------------------------------------------------------\r
56  *         Headers\r
57  *------------------------------------------------------------------------------*/\r
58 \r
59 #include "chip.h"\r
60 \r
61 #include <stdint.h>\r
62 \r
63 /*------------------------------------------------------------------------------\r
64  *         Definitions\r
65  *------------------------------------------------------------------------------*/\r
66 \r
67 /** \section USART_mode USART modes\r
68  * This section lists several common operating modes for an USART peripheral.\r
69  *\r
70  * \b Modes\r
71  * - USART_MODE_ASYNCHRONOUS\r
72  * - USART_MODE_IRDA\r
73  */\r
74 \r
75 /** Basic asynchronous mode, i.e. 8 bits no parity.*/\r
76 #define USART_MODE_ASYNCHRONOUS        (US_MR_CHRL_8_BIT | US_MR_PAR_NO)\r
77 \r
78 /** IRDA mode*/\r
79 #define USART_MODE_IRDA \\r
80     (US_MR_USART_MODE_IRDA | US_MR_CHRL_8_BIT | US_MR_PAR_NO | US_MR_FILTER)\r
81 \r
82 /** SPI mode*/\r
83 #define AT91C_US_USMODE_SPIM     0xE\r
84 #define US_SPI_CPOL_0           (0x0<<16)\r
85 #define US_SPI_CPHA_0            (0x0<<8)\r
86 #define US_SPI_CPOL_1            (0x1<<16)\r
87 #define US_SPI_CPHA_1            (0x1<<8)\r
88 #define US_SPI_BPMODE_0    (US_SPI_CPOL_0|US_SPI_CPHA_1)\r
89 #define US_SPI_BPMODE_1    (US_SPI_CPOL_0|US_SPI_CPHA_0)\r
90 #define US_SPI_BPMODE_2    (US_SPI_CPOL_1|US_SPI_CPHA_1)\r
91 #define US_SPI_BPMODE_3    (US_SPI_CPOL_1|US_SPI_CPHA_0)\r
92 \r
93 #ifdef __cplusplus\r
94  extern "C" {\r
95 #endif\r
96 \r
97 /*------------------------------------------------------------------------------*/\r
98 /*         Exported functions                                                   */\r
99 /*------------------------------------------------------------------------------*/\r
100 \r
101 extern void USART_Configure( Usart *pUsart, uint32_t mode, uint32_t baudrate, uint32_t masterClock ) ;\r
102 extern uint32_t USART_GetStatus( Usart *usart ) ;\r
103 extern void USART_EnableIt( Usart *usart,uint32_t mode ) ;\r
104 extern void USART_DisableIt( Usart *usart,uint32_t mode ) ;\r
105 extern uint32_t USART_GetItMask( Usart * usart ) ;\r
106 extern void USART_SetTransmitterEnabled( Usart *usart, uint8_t enabled ) ;\r
107 \r
108 extern void USART_SetReceiverEnabled( Usart *usart, uint8_t enabled ) ;\r
109 \r
110 extern void USART_SetRTSEnabled(Usart *usart, uint8_t enabled);\r
111 \r
112 extern void USART_Write( Usart *usart, uint16_t data, volatile uint32_t timeOut ) ;\r
113 \r
114 extern uint16_t USART_Read( Usart *usart, volatile uint32_t timeOut ) ;\r
115 \r
116 extern uint8_t USART_IsDataAvailable( Usart *usart ) ;\r
117 \r
118 extern void USART_SetIrdaFilter(Usart *pUsart, uint8_t filter);\r
119 \r
120 extern void USART_PutChar( Usart *usart, uint8_t c ) ;\r
121 \r
122 extern uint32_t USART_IsRxReady( Usart *usart ) ;\r
123 \r
124 extern uint8_t USART_GetChar( Usart *usart ) ;\r
125 \r
126 #ifdef __cplusplus\r
127 }\r
128 #endif\r
129 \r
130 #endif /* #ifndef _USART_ */\r
131 \r