]> git.sur5r.net Git - freertos/blob - Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/twi/twi.h
Start to re-arrange files to include FreeRTOS+ in main download.
[freertos] / Demo / CORTEX_AT91SAM3U256_IAR / AT91Lib / peripherals / twi / twi.h
1 /* ----------------------------------------------------------------------------\r
2  *         ATMEL Microcontroller Software Support\r
3  * ----------------------------------------------------------------------------\r
4  * Copyright (c) 2008, 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 /// \unit\r
32 ///\r
33 /// !Purpose\r
34 ///\r
35 /// Interface for configuration the Two Wire Interface (TWI) peripheral.\r
36 ///\r
37 /// !Usage\r
38 ///\r
39 /// -# Configures a TWI peripheral to operate in master mode, at the given\r
40 /// frequency (in Hz) using TWI_ConfigureMaster().\r
41 /// -# or if hardware possible, configures a TWI peripheral to operate in \r
42 /// slave mode, at the given frequency (in Hz) using TWI_ConfigureSlave().\r
43 /// -# Sends a STOP condition on the TWI using TWI_Stop().\r
44 /// -# Starts a read operation on the TWI bus with the specified slave using\r
45 /// TWI_StartRead(). Data must then be read using TWI_ReadByte() whenever \r
46 /// a byte is available (poll using TWI_ByteReceived()).\r
47 /// -# Starts a write operation on the TWI to access the selected slave using\r
48 /// TWI_StartWrite(). A byte of data must be provided to start the write;\r
49 /// other bytes are written next. \r
50 /// -# Sends a byte of data to one of the TWI slaves on the bus using TWI_WriteByte().\r
51 /// This function must be called once before TWI_StartWrite() with the first byte of data\r
52 /// to send, then it shall be called repeatedly after that to send the remaining bytes.\r
53 /// -# Check if a byte has been received and can be read on the given TWI\r
54 /// peripheral using TWI_ByteReceived(). \r
55 /// Check if a byte has been sent using TWI_ByteSent().\r
56 /// -# Check if the current transmission is complete (the STOP has been sent)\r
57 /// using TWI_TransferComplete().\r
58 /// -# Enables & disable the selected interrupts sources on a TWI peripheral\r
59 /// using TWI_EnableIt() and TWI_DisableIt().\r
60 /// -# Get current status register of the given TWI peripheral using\r
61 /// TWI_GetStatus(). Get current status register of the given TWI peripheral, but\r
62 /// masking interrupt sources which are not currently enabled using \r
63 /// TWI_GetMaskedStatus().\r
64 //------------------------------------------------------------------------------\r
65 \r
66 #ifndef TWI_H\r
67 #define TWI_H\r
68 \r
69 //------------------------------------------------------------------------------\r
70 //         Headers\r
71 //------------------------------------------------------------------------------\r
72 \r
73 #include <board.h>\r
74 \r
75 //------------------------------------------------------------------------------\r
76 //         Global definitions\r
77 //------------------------------------------------------------------------------\r
78 \r
79 // Missing AT91C_TWI_TXRDY definition.\r
80 #ifndef AT91C_TWI_TXRDY\r
81     #define AT91C_TWI_TXRDY   AT91C_TWI_TXRDY_MASTER\r
82 #endif\r
83 \r
84 // Missing AT91C_TWI_TXCOMP definition.\r
85 #ifndef AT91C_TWI_TXCOMP\r
86     #define AT91C_TWI_TXCOMP  AT91C_TWI_TXCOMP_MASTER\r
87 #endif\r
88 \r
89 //------------------------------------------------------------------------------\r
90 //         Global macros\r
91 //------------------------------------------------------------------------------\r
92 \r
93 /// Returns 1 if the TXRDY bit (ready to transmit data) is set in the given\r
94 /// status register value.\r
95 #define TWI_STATUS_TXRDY(status) ((status & AT91C_TWI_TXRDY) == AT91C_TWI_TXRDY)\r
96 \r
97 /// Returns 1 if the RXRDY bit (ready to receive data) is set in the given\r
98 /// status register value.\r
99 #define TWI_STATUS_RXRDY(status) ((status & AT91C_TWI_RXRDY) == AT91C_TWI_RXRDY)\r
100 \r
101 /// Returns 1 if the TXCOMP bit (transfer complete) is set in the given\r
102 /// status register value.\r
103 #define TWI_STATUS_TXCOMP(status) ((status & AT91C_TWI_TXCOMP) == AT91C_TWI_TXCOMP)\r
104 \r
105 //------------------------------------------------------------------------------\r
106 //         Global functions\r
107 //------------------------------------------------------------------------------\r
108 \r
109 extern void TWI_ConfigureMaster(AT91S_TWI *pTwi, unsigned int twck, unsigned int mck);\r
110 \r
111 #ifdef AT91C_TWI_SVEN  // TWI slave\r
112 extern void TWI_ConfigureSlave(AT91S_TWI *pTwi, unsigned char slaveAddress);\r
113 #endif\r
114 \r
115 extern void TWI_Stop(AT91S_TWI *pTwi);\r
116 \r
117 extern void TWI_StartRead(\r
118     AT91S_TWI *pTwi,\r
119     unsigned char address,\r
120     unsigned int iaddress,\r
121     unsigned char isize);\r
122 \r
123 extern unsigned char TWI_ReadByte(AT91S_TWI *pTwi);\r
124 \r
125 extern void TWI_WriteByte(AT91S_TWI *pTwi, unsigned char byte);\r
126 \r
127 extern void TWI_StartWrite(\r
128     AT91S_TWI *pTwi,\r
129     unsigned char address,\r
130     unsigned int iaddress,\r
131     unsigned char isize,\r
132     unsigned char byte);\r
133 \r
134 extern unsigned char TWI_ByteReceived(AT91S_TWI *pTwi);\r
135 \r
136 extern unsigned char TWI_ByteSent(AT91S_TWI *pTwi);\r
137 \r
138 extern unsigned char TWI_TransferComplete(AT91S_TWI *pTwi);\r
139 \r
140 extern void TWI_EnableIt(AT91S_TWI *pTwi, unsigned int sources);\r
141 \r
142 extern void TWI_DisableIt(AT91S_TWI *pTwi, unsigned int sources);\r
143 \r
144 extern unsigned int TWI_GetStatus(AT91S_TWI *pTwi);\r
145 \r
146 extern unsigned int TWI_GetMaskedStatus(AT91S_TWI *pTwi);\r
147 \r
148 extern void TWI_SendSTOPCondition(AT91S_TWI *pTwi);\r
149 \r
150 #endif //#ifndef TWI_H\r