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
cs2200_HAL_AVR32_UC3A3_HW_interface.h
Go to the documentation of this file.
1
19 #ifndef _CS2200_HAL_AVR32_UC3A3_HW_INTERFACE_H_
20 #define _CS2200_HAL_AVR32_UC3A3_HW_INTERFACE_H_
21 //===========================| Included libraries |============================
22 // Basic library (I/O)
23 #include <avr32/io.h>
24
25 // Data types
26 #include <inttypes.h>
27
28 // GPIO operations
30 #include "gpio.h"
31
32 //==============================| User settings |==============================
45 #define CS2200_TWI_DEVICE (&AVR32_TWIM0)
46
59 #define CS2200_TWI_CLK_SOURCE 33000000UL
60
68 #define CS2200_TWI_ADDRESS 0b1001110
69
84 #define CS2200_TWI_SDA_PIN AVR32_TWIMS0_TWD_0_0_PIN
85
91 #define CS2200_TWI_SDA_FUNCTION AVR32_TWIMS0_TWD_0_0_FUNCTION
92
98 #define CS2200_TWI_SCL_PIN AVR32_TWIMS0_TWCK_0_0_PIN
99
105 #define CS2200_TWI_SCL_FUNCTION AVR32_TWIMS0_TWCK_0_0_FUNCTION
106
126 #define CS2200_TWI_BAUDRATE 0
127
128 //============================| Structures, enums |============================
135 typedef enum{
136 CS2200_ERROR = -1,
137 CS2200_OK = 0,
138 CS2200_ERROR_TWI_TIMEOUT = 1,
141 CS2200_ERROR_TWI_INVALID_PARAMETER = 2,
144 CS2200_ERROR_TWI_NACK = 3
145 } cs2200_status_t;
146
147
148 //================| Some checks and preprocessor calculations |================
149 // Test TLV address
150 #if (CS2200_TWI_ADDRESS != 0b1001110) &&\
151 (CS2200_TWI_ADDRESS != 0b1001111)
152 #warning "CS2200_TWI_ADDRESS is not set to one of known settings. It is\
153 highly possible that communication with PLL fail!"
154 #endif
155
156 // Test address - can not be higher than 7bits
157 #if CS2200_TWI_ADDRESS > 127
158 #error "CS2200_TWI_ADDRESS can not be higher than 127, because\
159 address in TWI is 7 bit long. Please set correct value."
160 #endif
161
162 // Test if user want auto maximum possible speed
163 #if CS2200_TWI_BAUDRATE == 0
164 #undef CS2200_TWI_BAUDRATE
165 // Check if clock frequency is lower than 200 kHz (baudrate *2)
166 #if CS2200_TWI_CLK_SOURCE < (200000UL)
167 // Set maximum possible baudrate at this sloooow clock
168 #define CS2200_TWI_BAUDRATE (CS2200_TWI_CLK_SOURCE/2)
169 #else
170 // Else we got clock fast enough to get maximum speed
171 #define CS2200_TWI_BAUDRATE 100000UL
172 #endif
173
174 #endif
175
176 // Check baudrate for too high value
177 #if CS2200_TWI_BAUDRATE > (100000UL)
178 #warning "CS2200_TWI_BAUDRATE is higher than 100 000, so communication with\
179 PLL may fail!"
180 #endif
181
182 // Check baudrate for too low value
183 #if CS2200_TWI_BAUDRATE < (10000UL)
184 #warning "CS2200_TWI_BAUDRATE is lower than 10 000. This may cause, that\
185 performance of whole application will be low! Please consider to use higher\
186 speed of TWI."
187 #endif
188
189 // Check buaudrate if is lower then CS2200_CLK_SOURCE
190 #if CS2200_TWI_BAUDRATE > (CS2200_TWI_CLK_SOURCE/2)
191 #error "CS2200_TWI_BAUDRATE can not be higher than (input clock/2) for TWI\
192 module. Please set CS2200_TWI_BAUDRATE to lower value, or set it to 0 and\
193 preprocessor try to set maximum possible speed."
194 #endif
195
196
197 // Calculate prescaller
198 #if (CS2200_TWI_CLK_SOURCE/CS2200_TWI_BAUDRATE/2)<256
199 #define CS2200_TWI_CKDIV 0
200 #define CS2200_TWI_CLDIV (CS2200_TWI_CLK_SOURCE/CS2200_TWI_BAUDRATE/2)
201
202 #elif (CS2200_TWI_CLK_SOURCE/CS2200_TWI_BAUDRATE/4)<256
203 #define CS2200_TWI_CKDIV 1
204 #define CS2200_TWI_CLDIV (CS2200_TWI_CLK_SOURCE/CS2200_TWI_BAUDRATE/4)
205
206 #elif (CS2200_TWI_CLK_SOURCE/CS2200_TWI_BAUDRATE/8)<256
207 #define CS2200_TWI_CKDIV 2
208 #define CS2200_TWI_CLDIV (CS2200_TWI_CLK_SOURCE/CS2200_TWI_BAUDRATE/8)
209
210 #elif (CS2200_TWI_CLK_SOURCE/CS2200_TWI_BAUDRATE/16)<256
211 #define CS2200_TWI_CKDIV 3
212 #define CS2200_TWI_CLDIV (CS2200_TWI_CLK_SOURCE/CS2200_TWI_BAUDRATE/16)
213
214 #elif (CS2200_TWI_CLK_SOURCE/CS2200_TWI_BAUDRATE/32)<256
215 #define CS2200_TWI_CKDIV 4
216 #define CS2200_TWI_CLDIV (CS2200_TWI_CLK_SOURCE/CS2200_TWI_BAUDRATE/32)
217
218 #elif (CS2200_TWI_CLK_SOURCE/CS2200_TWI_BAUDRATE/64)<256
219 #define CS2200_TWI_CKDIV 5
220 #define CS2200_TWI_CLDIV (CS2200_TWI_CLK_SOURCE/CS2200_TWI_BAUDRATE/64)
221
222 #elif (CS2200_TWI_CLK_SOURCE/CS2200_TWI_BAUDRATE/128)<256
223 #define CS2200_TWI_CKDIV 6
224 #define CS2200_TWI_CLDIV (CS2200_TWI_CLK_SOURCE/CS2200_TWI_BAUDRATE/128)
225
226 #elif (CS2200_TWI_CLK_SOURCE/CS2200_TWI_BAUDRATE/256)<256
227 #define CS2200_TWI_CKDIV 7
228 #define CS2200_TWI_CLDIV (CS2200_TWI_CLK_SOURCE/CS2200_TWI_BAUDRATE/256)
229
230 #else
231 // When maximum division is not enough
232 #error "TWI baudrate can not be set this low. Please set\
233 CS2200_TWI_BAUDRATE to higher value, or set it to 0 and\
234 preprocessor try set maximum possible speed."
235 #endif
236
237
238 //================================| Functions |================================
239 cs2200_status_t cs2200_HAL_init(void);
240
241 cs2200_status_t cs2200_HAL_write_data(
242 uint8_t *p_data,
243 uint8_t i_number_of_bytes);
244
245 cs2200_status_t cs2200_HAL_read_data(
246 uint8_t *p_data,
247 uint8_t i_number_of_bytes);
248
249 #endif