Refactor to use new protocol module and sipo.
[bertos.git] / bertos / cpu / arm / io / at91_twi.h
1 /**
2  * \file
3  * <!--
4  * This file is part of BeRTOS.
5  *
6  * Bertos is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  * As a special exception, you may use this file as part of a free software
21  * library without restriction.  Specifically, if other files instantiate
22  * templates or use macros or inline functions from this file, or you compile
23  * this file and link it with other files to produce an executable, this
24  * file does not by itself cause the resulting executable to be covered by
25  * the GNU General Public License.  This exception does not however
26  * invalidate any other reasons why the executable file might be covered by
27  * the GNU General Public License.
28  *
29  * Copyright 2008 Develer S.r.l. (http://www.develer.com/)
30  *
31  * -->
32  *
33  *
34  * \author Francesco Sacchi <batt@develer.com>
35  *
36  * AT91SAM7 Two wire interface.
37  * This file is based on NUT/OS implementation. See license below.
38  */
39
40 /*
41  * Copyright (C) 2006 by egnite Software GmbH. All rights reserved.
42  *
43  * Redistribution and use in source and binary forms, with or without
44  * modification, are permitted provided that the following conditions
45  * are met:
46  *
47  * 1. Redistributions of source code must retain the above copyright
48  *    notice, this list of conditions and the following disclaimer.
49  * 2. Redistributions in binary form must reproduce the above copyright
50  *    notice, this list of conditions and the following disclaimer in the
51  *    documentation and/or other materials provided with the distribution.
52  * 3. Neither the name of the copyright holders nor the names of
53  *    contributors may be used to endorse or promote products derived
54  *    from this software without specific prior written permission.
55  *
56  * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS
57  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
58  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
59  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE
60  * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
61  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
62  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
63  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
64  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
65  * OR TORT (*((reg32_t *)(INCLUDING NEGLIGENCE OR OTHERWISE))) ARISING IN ANY WAY OUT OF
66  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
67  * SUCH DAMAGE.
68  *
69  * For additional information see http://www.ethernut.de/
70  */
71
72 #ifndef AT91_TWI_H
73 #define AT91_TWI_H
74
75
76 /**
77  * TWI Control Register.
78  * \{
79  */
80 #define TWI_CR_OFF              0x00000000      ///< Control register offset.
81 #define TWI_CR      (*((reg32_t *)(TWI_BASE + TWI_CR_OFF)))     ///< Control register address.
82 #define TWI_START                        0      ///< Send start condition.
83 #define TWI_STOP                         1      ///< Send stop condition.
84 #define TWI_MSEN                         2      ///< Enable master mode.
85 #define TWI_MSDIS                        3      ///< Disable master mode.
86 /*
87 #define TWI_SVEN                         4      ///< Enable slave mode.
88 #define TWI_SVDIS                        5      ///< Disable slave mode.
89 */
90 #define TWI_SWRST                        7      ///< Software reset.
91 /*\}*/
92
93 /**
94  * TWI Master Mode Register.
95  * \{
96  */
97 #define TWI_MMR_OFF             0x00000004      ///< Master mode register offset.
98 #define TWI_MMR     (*((reg32_t *)(TWI_BASE + TWI_MMR_OFF)))    ///< Master mode register address.
99 #define TWI_IADRSZ_SHIFT                 8      ///< Internal device address size shift.
100 #define TWI_IADRSZ              0x00000300      ///< Internal device address size mask.
101 #define TWI_IADRSZ_NONE         0x00000000      ///< No internal device address.
102 #define TWI_IADRSZ_1BYTE        0x00000100      ///< One byte internal device address.
103 #define TWI_IADRSZ_2BYTE        0x00000200      ///< Two byte internal device address.
104 #define TWI_IADRSZ_3BYTE        0x00000300      ///< Three byte internal device address.
105 #define TWI_MREAD                       12      ///< Master read direction.
106 #define TWI_DADR                0x007F0000      ///< Device address mask.
107 #define TWI_DADR_SHIFT                  16      ///< Device address LSB.
108 /*\}*/
109
110 /**
111  * TWI Internal Address Register.
112  * \{
113  */
114 #define TWI_IADR_OFF           0x0000000C       ///< Internal address register offset.
115 #define TWI_IADR   (*((reg32_t *)(TWI_BASE + TWI_IADR_OFF)))  ///< Internal address register address.
116 #define TWI_IADR_MASK           0x00FFFFFF      ///< Internal address mask.
117 #define TWI_IADR_SHIFT                   0      ///< Internal address LSB.
118 /*\}*/
119
120 /**
121  * TWI Clock Waveform Generator Register.
122  * \{
123  */
124 #define TWI_CWGR_OFF             0x00000010     ///< Clock waveform generator register offset.
125 #define TWI_CWGR    (*((reg32_t *)(TWI_BASE + TWI_CWGR_OFF)))   ///< Clock waveform generator register address.
126 #define TWI_CLDIV                0x000000FF     ///< Clock low divider mask.
127 #define TWI_CLDIV_SHIFT                   0     ///< Clock low divider LSB.
128 #define TWI_CHDIV                0x0000FF00     ///< Clock high divider mask.
129 #define TWI_CHDIV_SHIFT                   8     ///< Clock high divider LSB.
130 #define TWI_CKDIV                0x00070000     ///< Clock divider mask.
131 #define TWI_CKDIV_SHIFT                  16     ///< Clock divider LSB.
132 /*\}*/
133
134 /**
135  * TWI Status and Interrupt Registers.
136  * \{
137  */
138 #define TWI_SR_OFF              0x00000020      ///< Status register offset.
139 #define TWI_SR      (*((reg32_t *)(TWI_BASE + TWI_SR_OFF)))     ///< Status register address.
140
141 #define TWI_IER_OFF             0x00000024      ///< Interrupt enable register offset.
142 #define TWI_IER     (*((reg32_t *)(TWI_BASE + TWI_IER_OFF)))    ///< Interrupt enable register address.
143
144 #define TWI_IDR_OFF             0x00000028      ///< Interrupt disable register offset.
145 #define TWI_IDR     (*((reg32_t *)(TWI_BASE + TWI_IDR_OFF)))    ///< Interrupt disable register address.
146
147 #define TWI_IMR_OFF             0x0000002C      ///< Interrupt mask register offset.
148 #define TWI_IMR     (*((reg32_t *)(TWI_BASE + TWI_IMR_OFF)))    ///< Interrupt mask register address.
149
150 #define TWI_TXCOMP                       0      ///< Transmission completed.
151 #define TWI_RXRDY                        1      ///< Receive holding register ready.
152 #define TWI_TXRDY                        2      ///< Transmit holding register ready.
153
154 /*
155 #define TWI_SVREAD              0x00000008      ///< Slave read.
156 #define TWI_SVACC               0x00000010      ///< Slave access.
157 #define TWI_GACC                0x00000020      ///< General call access.
158 */
159
160 #if CPU_ARM_SAM7X
161 #define TWI_OVRE                         6      ///< Overrun error.
162 #define TWI_UNRE                         7      ///< Underrun error.
163 #endif
164
165 #define TWI_NACK                         8      ///< Not acknowledged.
166 /*
167 #define TWI_ARBLST              0x00000200      ///< Arbitration lost.
168 #define TWI_SCLWS               0x00000400      ///< Clock wait state.
169 #define TWI_EOSACC              0x00000800      ///< End of slave access.
170 */
171 /*\}*/
172
173 /**
174  * TWI Receive Holding Register.
175  * \{
176  */
177 #define TWI_RHR_OFF             0x00000030      ///< Receive holding register offset.
178 #define TWI_RHR     (*((reg32_t *)(TWI_BASE + TWI_RHR_OFF)))    ///< Receive holding register address.
179 /*\}*/
180
181 /**
182  * TWI Transmit Holding Register.
183  * \{
184  */
185 #define TWI_THR_OFF             0x00000034      ///< Transmit holding register offset.
186 #define TWI_THR     (*((reg32_t *)(TWI_BASE + TWI_THR_OFF)))    ///< Transmit holding register address.
187 /*\}*/
188
189
190 #endif /* AT91_TWI_H */