Sonochan II 0.1

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
tlv320aic33_HAL_AVR32_UC3A3_HW_interface.h
Go to the documentation of this file.
1
20 #ifndef _TLV320AIC33_HAL_AVR32_UC3A3_HW_INTERFACE_H_
21 #define _TLV320AIC33_HAL_AVR32_UC3A3_HW_INTERFACE_H_
22 //===========================| Included libraries |============================
23 // Basic library (I/O)
24 #include <avr32/io.h>
25
26 // Data types
27 #include <inttypes.h>
28
29 // GPIO operations
31 #include "gpio.h"
32 //==============================| User settings |==============================
45 #define TLV320AIC33_TWI_DEVICE (&AVR32_TWIM0)
46
59 #define TLV320AIC33_TWI_CLK_SOURCE 33000000UL
60
69 #define TLV320AIC33_TWI_ADDRESS 0b0011000
70
85 #define TLV320AIC33_TWI_SDA_PIN AVR32_TWIMS0_TWD_0_0_PIN
86
92 #define TLV320AIC33_TWI_SDA_FUNCTION AVR32_TWIMS0_TWD_0_0_FUNCTION
93
99 #define TLV320AIC33_TWI_SCL_PIN AVR32_TWIMS0_TWCK_0_0_PIN
100
106 #define TLV320AIC33_TWI_SCL_FUNCTION AVR32_TWIMS0_TWCK_0_0_FUNCTION
107
127 #define TLV320AIC33_TWI_BAUDRATE 0
128
129 //============================| Structures, enums |============================
136 typedef enum{
137 TLV320AIC33_ERROR = -1,
138 TLV320AIC33_OK = 0,
139 TLV320AIC33_ERROR_TWI_TIMEOUT = 1,
142 TLV320AIC33_ERROR_TWI_INVALID_PARAMETER = 2,
145 TLV320AIC33_ERROR_TWI_NACK = 3
146 } TLV320AIC33_status_t;
147
148 //================| Some checks and preprocessor calculations |================
150
151 // Test address - can not be higher than 7bits
152 #if TLV320AIC33_TWI_ADDRESS > 127
153 #error "TLV320AIC33_TWI_ADDRESS can not be higher than 127, because\
154 address in TWI is 7 bit long. Please set correct value."
155 #endif
156
157 // Test if user want auto maximum possible speed
158 #if TLV320AIC33_TWI_BAUDRATE == 0
159 #undef TLV320AIC33_TWI_BAUDRATE
160 // Check if clock frequency is lower than 200 kHz (baudrate *2)
161 #if TLV320AIC33_TWI_CLK_SOURCE < (200000UL)
162 // Set maximum possible baudrate at this sloooow clock
163 #define TLV320AIC33_TWI_BAUDRATE (TLV320AIC33_TWI_CLK_SOURCE/2)
164 #else
165 // Else we got clock fast enough to get maximum speed
166 #define TLV320AIC33_TWI_BAUDRATE 100000UL
167 #endif
168
169 #endif
170
171 // Check baudrate for too high value
172 #if TLV320AIC33_TWI_BAUDRATE > (100000UL)
173 #warning "TLV320AIC33_TWI_BAUDRATE is higher than 100 000, so communication with\
174 PLL may fail!"
175 #endif
176
177 // Check baudrate for too low value
178 #if TLV320AIC33_TWI_BAUDRATE < (10000UL)
179 #warning "TLV320AIC33_TWI_BAUDRATE is lower than 10 000. This may cause, that\
180 performance of whole application will be low! Please consider to use higher\
181 speed of TWI."
182 #endif
183
184 // Check buaudrate if is lower then TLV320AIC33_CLK_SOURCE
185 #if TLV320AIC33_TWI_BAUDRATE > (TLV320AIC33_TWI_CLK_SOURCE/2)
186 #error "TLV320AIC33_TWI_BAUDRATE can not be higher than (input clock/2) for TWI\
187 module. Please set TLV320AIC33_TWI_BAUDRATE to lower value, or set it to 0 and\
188 preprocessor try to set maximum possible speed."
189 #endif
190
191
192 // Calculate prescaller
193 #if (TLV320AIC33_TWI_CLK_SOURCE/TLV320AIC33_TWI_BAUDRATE/2)<256
194 #define TLV320AIC33_TWI_CKDIV 0
195 #define TLV320AIC33_TWI_CLDIV (TLV320AIC33_TWI_CLK_SOURCE/TLV320AIC33_TWI_BAUDRATE/2)
196
197 #elif (TLV320AIC33_TWI_CLK_SOURCE/TLV320AIC33_TWI_BAUDRATE/4)<256
198 #define TLV320AIC33_TWI_CKDIV 1
199 #define TLV320AIC33_TWI_CLDIV (TLV320AIC33_TWI_CLK_SOURCE/TLV320AIC33_TWI_BAUDRATE/4)
200
201 #elif (TLV320AIC33_TWI_CLK_SOURCE/TLV320AIC33_TWI_BAUDRATE/8)<256
202 #define TLV320AIC33_TWI_CKDIV 2
203 #define TLV320AIC33_TWI_CLDIV (TLV320AIC33_TWI_CLK_SOURCE/TLV320AIC33_TWI_BAUDRATE/8)
204
205 #elif (TLV320AIC33_TWI_CLK_SOURCE/TLV320AIC33_TWI_BAUDRATE/16)<256
206 #define TLV320AIC33_TWI_CKDIV 3
207 #define TLV320AIC33_TWI_CLDIV (TLV320AIC33_TWI_CLK_SOURCE/TLV320AIC33_TWI_BAUDRATE/16)
208
209 #elif (TLV320AIC33_TWI_CLK_SOURCE/TLV320AIC33_TWI_BAUDRATE/32)<256
210 #define TLV320AIC33_TWI_CKDIV 4
211 #define TLV320AIC33_TWI_CLDIV (TLV320AIC33_TWI_CLK_SOURCE/TLV320AIC33_TWI_BAUDRATE/32)
212
213 #elif (TLV320AIC33_TWI_CLK_SOURCE/TLV320AIC33_TWI_BAUDRATE/64)<256
214 #define TLV320AIC33_TWI_CKDIV 5
215 #define TLV320AIC33_TWI_CLDIV (TLV320AIC33_TWI_CLK_SOURCE/TLV320AIC33_TWI_BAUDRATE/64)
216
217 #elif (TLV320AIC33_TWI_CLK_SOURCE/TLV320AIC33_TWI_BAUDRATE/128)<256
218 #define TLV320AIC33_TWI_CKDIV 6
219 #define TLV320AIC33_TWI_CLDIV (TLV320AIC33_TWI_CLK_SOURCE/TLV320AIC33_TWI_BAUDRATE/128)
220
221 #elif (TLV320AIC33_TWI_CLK_SOURCE/TLV320AIC33_TWI_BAUDRATE/256)<256
222 #define TLV320AIC33_TWI_CKDIV 7
223 #define TLV320AIC33_TWI_CLDIV (TLV320AIC33_TWI_CLK_SOURCE/TLV320AIC33_TWI_BAUDRATE/256)
224
225 #else
226 // When maximum division is not enough
227 #error "TWI baudrate can not be set this low. Please set\
228 TLV320AIC33_TWI_BAUDRATE to higher value, or set it to 0 and\
229 preprocessor try set maximum possible speed."
230 #endif
231
232
233 //================================| Functions |================================
234 TLV320AIC33_status_t tlv320aic33_HAL_init(void);
235
236 TLV320AIC33_status_t tlv320aic33_HAL_write_data(
237 uint8_t i_register_number,
238 uint8_t i_data);
239
240 TLV320AIC33_status_t tlv320aic33_HAL_read_data(
241 uint8_t i_register_number,
242 uint8_t *p_data);
243
244
245
246 #endif