Robobo
USB_device.h
1 /* ----------------------------------------------------------------------------
2  * SAM Software Package License
3  * ----------------------------------------------------------------------------
4  * Copyright (c) 2011-2012, Atmel Corporation
5  *
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following condition is met:
10  *
11  * - Redistributions of source code must retain the above copyright notice,
12  * this list of conditions and the disclaimer below.
13  *
14  * Atmel's name may not be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
20  * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  * ----------------------------------------------------------------------------
28  */
29 
30 #ifndef USB_DEVICE_H_INCLUDED
31 #define USB_DEVICE_H_INCLUDED
32 
33 #include <stdint.h>
34 
35 extern void UDD_WaitIN(void);
36 extern void UDD_WaitOUT(void);
37 extern void UDD_ClearIN(void);
38 extern void UDD_ClearOUT(void);
39 extern uint32_t UDD_WaitForINOrOUT(void);
40 extern void UDD_ClearRxFlag(unsigned char bEndpoint);
41 extern uint32_t UDD_ReceivedSetupInt(void);
42 extern void UDD_ClearSetupInt(void);
43 extern uint32_t UDD_ReadWriteAllowed(uint32_t ep);
44 extern uint32_t UDD_FifoByteCount(uint32_t ep);
45 extern uint8_t UDD_FifoFree(void);
46 extern void UDD_ReleaseRX(uint32_t ep);
47 extern void UDD_ReleaseTX(uint32_t ep);
48 extern uint8_t UDD_FrameNumber(void);
49 extern uint8_t UDD_GetConfiguration(void);
50 
51 extern uint32_t UDD_Send(uint32_t ep, const void* data, uint32_t len);
52 extern void UDD_Send8(uint32_t ep, uint8_t data );
53 extern uint8_t UDD_Recv8(uint32_t ep);
54 extern void UDD_Recv(uint32_t ep, uint8_t* data, uint32_t len);
55 
56 extern void UDD_InitEndpoints(const uint32_t* eps_table, const uint32_t ul_eps_table_size);
57 extern void UDD_InitControl(int end);
58 extern uint32_t UDD_Init(void);
59 extern void UDD_InitEP( uint32_t ul_ep, uint32_t ul_ep_cfg );
60 
61 extern void UDD_Attach(void);
62 extern void UDD_Detach(void);
63 
64 extern void UDD_SetStack(void (*pf_isr)(void));
65 extern void UDD_SetAddress(uint32_t addr);
66 extern void UDD_Stall(void);
67 extern uint32_t UDD_GetFrameNumber(void);
68 
72 
74 typedef unsigned char Bool;
75 #ifndef __cplusplus
76 #if !defined(__bool_true_false_are_defined)
77 typedef unsigned char bool;
78 #endif
79 #endif
80 typedef int8_t S8;
81 typedef uint8_t U8;
82 typedef int16_t S16;
83 typedef uint16_t U16;
84 typedef uint16_t le16_t;
85 typedef uint16_t be16_t;
86 typedef int32_t S32;
87 typedef uint32_t U32;
88 typedef uint32_t le32_t;
89 typedef uint32_t be32_t;
90 typedef int64_t S64;
91 typedef uint64_t U64;
92 typedef float F32;
93 typedef double F64;
94 typedef uint32_t iram_size_t;
95 
97 
100 
109 #define Rd_bits( value, mask) ((value) & (mask))
110 
119 #define Wr_bits(lvalue, mask, bits) ((lvalue) = ((lvalue) & ~(mask)) |\
120  ((bits ) & (mask)))
121 
129 #define Tst_bits( value, mask) (Rd_bits(value, mask) != 0)
130 
138 #define Clr_bits(lvalue, mask) ((lvalue) &= ~(mask))
139 
147 #define Set_bits(lvalue, mask) ((lvalue) |= (mask))
148 
156 #define Tgl_bits(lvalue, mask) ((lvalue) ^= (mask))
157 
165 #define Rd_bitfield( value, mask) (Rd_bits( value, mask) >> ctz(mask))
166 
175 #define Wr_bitfield(lvalue, mask, bitfield) (Wr_bits(lvalue, mask, (U32)(bitfield) << ctz(mask)))
176 
178 
190 
192 #define TPASTE2( a, b) a##b
193 #define TPASTE3( a, b, c) a##b##c
194 #define TPASTE4( a, b, c, d) a##b##c##d
195 #define TPASTE5( a, b, c, d, e) a##b##c##d##e
196 #define TPASTE6( a, b, c, d, e, f) a##b##c##d##e##f
197 #define TPASTE7( a, b, c, d, e, f, g) a##b##c##d##e##f##g
198 #define TPASTE8( a, b, c, d, e, f, g, h) a##b##c##d##e##f##g##h
199 #define TPASTE9( a, b, c, d, e, f, g, h, i) a##b##c##d##e##f##g##h##i
200 #define TPASTE10(a, b, c, d, e, f, g, h, i, j) a##b##c##d##e##f##g##h##i##j
201 
203 
214 
216 #define ATPASTE2( a, b) TPASTE2( a, b)
217 #define ATPASTE3( a, b, c) TPASTE3( a, b, c)
218 #define ATPASTE4( a, b, c, d) TPASTE4( a, b, c, d)
219 #define ATPASTE5( a, b, c, d, e) TPASTE5( a, b, c, d, e)
220 #define ATPASTE6( a, b, c, d, e, f) TPASTE6( a, b, c, d, e, f)
221 #define ATPASTE7( a, b, c, d, e, f, g) TPASTE7( a, b, c, d, e, f, g)
222 #define ATPASTE8( a, b, c, d, e, f, g, h) TPASTE8( a, b, c, d, e, f, g, h)
223 #define ATPASTE9( a, b, c, d, e, f, g, h, i) TPASTE9( a, b, c, d, e, f, g, h, i)
224 #define ATPASTE10(a, b, c, d, e, f, g, h, i, j) TPASTE10(a, b, c, d, e, f, g, h, i, j)
225 
227 
234 #if (defined __GNUC__) || (defined __CC_ARM)
235 # define ctz(u) __builtin_ctz(u)
236 #else
237 # define ctz(u) ((u) & (1ul << 0) ? 0 : \
238  (u) & (1ul << 1) ? 1 : \
239  (u) & (1ul << 2) ? 2 : \
240  (u) & (1ul << 3) ? 3 : \
241  (u) & (1ul << 4) ? 4 : \
242  (u) & (1ul << 5) ? 5 : \
243  (u) & (1ul << 6) ? 6 : \
244  (u) & (1ul << 7) ? 7 : \
245  (u) & (1ul << 8) ? 8 : \
246  (u) & (1ul << 9) ? 9 : \
247  (u) & (1ul << 10) ? 10 : \
248  (u) & (1ul << 11) ? 11 : \
249  (u) & (1ul << 12) ? 12 : \
250  (u) & (1ul << 13) ? 13 : \
251  (u) & (1ul << 14) ? 14 : \
252  (u) & (1ul << 15) ? 15 : \
253  (u) & (1ul << 16) ? 16 : \
254  (u) & (1ul << 17) ? 17 : \
255  (u) & (1ul << 18) ? 18 : \
256  (u) & (1ul << 19) ? 19 : \
257  (u) & (1ul << 20) ? 20 : \
258  (u) & (1ul << 21) ? 21 : \
259  (u) & (1ul << 22) ? 22 : \
260  (u) & (1ul << 23) ? 23 : \
261  (u) & (1ul << 24) ? 24 : \
262  (u) & (1ul << 25) ? 25 : \
263  (u) & (1ul << 26) ? 26 : \
264  (u) & (1ul << 27) ? 27 : \
265  (u) & (1ul << 28) ? 28 : \
266  (u) & (1ul << 29) ? 29 : \
267  (u) & (1ul << 30) ? 30 : \
268  (u) & (1ul << 31) ? 31 : \
269  32)
270 #endif
271 
284 
292 #if (defined __GNUC__) || (defined __CC_ARM)
293 # define clz(u) __builtin_clz(u)
294 #elif (defined __ICCARM__)
295 # define clz(u) __CLZ(u)
296 #else
297 # define clz(u) (((u) == 0) ? 32 : \
298  ((u) & (1ul << 31)) ? 0 : \
299  ((u) & (1ul << 30)) ? 1 : \
300  ((u) & (1ul << 29)) ? 2 : \
301  ((u) & (1ul << 28)) ? 3 : \
302  ((u) & (1ul << 27)) ? 4 : \
303  ((u) & (1ul << 26)) ? 5 : \
304  ((u) & (1ul << 25)) ? 6 : \
305  ((u) & (1ul << 24)) ? 7 : \
306  ((u) & (1ul << 23)) ? 8 : \
307  ((u) & (1ul << 22)) ? 9 : \
308  ((u) & (1ul << 21)) ? 10 : \
309  ((u) & (1ul << 20)) ? 11 : \
310  ((u) & (1ul << 19)) ? 12 : \
311  ((u) & (1ul << 18)) ? 13 : \
312  ((u) & (1ul << 17)) ? 14 : \
313  ((u) & (1ul << 16)) ? 15 : \
314  ((u) & (1ul << 15)) ? 16 : \
315  ((u) & (1ul << 14)) ? 17 : \
316  ((u) & (1ul << 13)) ? 18 : \
317  ((u) & (1ul << 12)) ? 19 : \
318  ((u) & (1ul << 11)) ? 20 : \
319  ((u) & (1ul << 10)) ? 21 : \
320  ((u) & (1ul << 9)) ? 22 : \
321  ((u) & (1ul << 8)) ? 23 : \
322  ((u) & (1ul << 7)) ? 24 : \
323  ((u) & (1ul << 6)) ? 25 : \
324  ((u) & (1ul << 5)) ? 26 : \
325  ((u) & (1ul << 4)) ? 27 : \
326  ((u) & (1ul << 3)) ? 28 : \
327  ((u) & (1ul << 2)) ? 29 : \
328  ((u) & (1ul << 1)) ? 30 : \
329  31)
330 #endif
331 
343 
353 #define Abs(a) (((a) < 0 ) ? -(a) : (a))
354 
364 #define Min(a, b) (((a) < (b)) ? (a) : (b))
365 
375 #define Max(a, b) (((a) > (b)) ? (a) : (b))
376 
377 // abs() is already defined by stdlib.h
378 
388 #define min(a, b) Min(a, b)
389 
399 #define max(a, b) Max(a, b)
400 
402 
403 #endif /* USB_DEVICE_H_INCLUDED */
union emac_rx_addr addr
Definition: emac.h:123