usbdrv/usbportability.h

changeset 0
9e9b2c78bd31
equal deleted inserted replaced
-1:000000000000 0:9e9b2c78bd31
1 /* Name: usbportability.h
2 * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers
3 * Author: Christian Starkjohann
4 * Creation Date: 2008-06-17
5 * Tabsize: 4
6 * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
7 * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
8 */
9
10 /*
11 General Description:
12 This header is intended to contain all (or at least most of) the compiler
13 and library dependent stuff. The C code is written for avr-gcc and avr-libc.
14 The API of other development environments is converted to gcc's and avr-libc's
15 API by means of defines.
16
17 This header also contains all system includes since they depend on the
18 development environment.
19
20 Thanks to Oleg Semyonov for his help with the IAR tools port!
21 */
22
23 #ifndef __usbportability_h_INCLUDED__
24 #define __usbportability_h_INCLUDED__
25
26 /* We check explicitly for IAR and CodeVision. Default is avr-gcc/avr-libc. */
27
28 /* ------------------------------------------------------------------------- */
29 #if defined __IAR_SYSTEMS_ICC__ || defined __IAR_SYSTEMS_ASM__ /* check for IAR */
30 /* ------------------------------------------------------------------------- */
31
32 #ifndef ENABLE_BIT_DEFINITIONS
33 # define ENABLE_BIT_DEFINITIONS 1 /* Enable bit definitions */
34 #endif
35
36 /* Include IAR headers */
37 #include <ioavr.h>
38 #ifndef __IAR_SYSTEMS_ASM__
39 # include <inavr.h>
40 #endif
41
42 #define __attribute__(arg) /* not supported on IAR */
43
44 #ifdef __IAR_SYSTEMS_ASM__
45 # define __ASSEMBLER__ /* IAR does not define standard macro for asm */
46 #endif
47
48 #ifdef __HAS_ELPM__
49 # define PROGMEM __farflash
50 #else
51 # define PROGMEM __flash
52 #endif
53
54 #define USB_READ_FLASH(addr) (*(PROGMEM char *)(addr))
55
56 /* The following definitions are not needed by the driver, but may be of some
57 * help if you port a gcc based project to IAR.
58 */
59 #define cli() __disable_interrupt()
60 #define sei() __enable_interrupt()
61 #define wdt_reset() __watchdog_reset()
62 #define _BV(x) (1 << (x))
63
64 /* assembler compatibility macros */
65 #define nop2 rjmp $+2 /* jump to next instruction */
66 #define XL r26
67 #define XH r27
68 #define YL r28
69 #define YH r29
70 #define ZL r30
71 #define ZH r31
72 #define lo8(x) LOW(x)
73 #define hi8(x) (((x)>>8) & 0xff) /* not HIGH to allow XLINK to make a proper range check */
74
75 /* Depending on the device you use, you may get problems with the way usbdrv.h
76 * handles the differences between devices. Since IAR does not use #defines
77 * for MCU registers, we can't check for the existence of a particular
78 * register with an #ifdef. If the autodetection mechanism fails, include
79 * definitions for the required USB_INTR_* macros in your usbconfig.h. See
80 * usbconfig-prototype.h and usbdrv.h for details.
81 */
82
83 /* ------------------------------------------------------------------------- */
84 #elif __CODEVISIONAVR__ /* check for CodeVision AVR */
85 /* ------------------------------------------------------------------------- */
86 /* This port is not working (yet) */
87
88 /* #define F_CPU _MCU_CLOCK_FREQUENCY_ seems to be defined automatically */
89
90 #include <io.h>
91 #include <delay.h>
92
93 #define __attribute__(arg) /* not supported on IAR */
94
95 #define PROGMEM __flash
96 #define USB_READ_FLASH(addr) (*(PROGMEM char *)(addr))
97
98 #ifndef __ASSEMBLER__
99 static inline void cli(void)
100 {
101 #asm("cli");
102 }
103 static inline void sei(void)
104 {
105 #asm("sei");
106 }
107 #endif
108 #define _delay_ms(t) delay_ms(t)
109 #define _BV(x) (1 << (x))
110 #define USB_CFG_USE_SWITCH_STATEMENT 1 /* macro for if() cascase fails for unknown reason */
111
112 #define macro .macro
113 #define endm .endmacro
114 #define nop2 rjmp .+0 /* jump to next instruction */
115
116 /* ------------------------------------------------------------------------- */
117 #else /* default development environment is avr-gcc/avr-libc */
118 /* ------------------------------------------------------------------------- */
119
120 #include <avr/io.h>
121 #ifdef __ASSEMBLER__
122 # define _VECTOR(N) __vector_ ## N /* io.h does not define this for asm */
123 #else
124 # include <avr/pgmspace.h>
125 #endif
126
127 #if USB_CFG_DRIVER_FLASH_PAGE
128 # define USB_READ_FLASH(addr) pgm_read_byte_far(((long)USB_CFG_DRIVER_FLASH_PAGE << 16) | (long)(addr))
129 #else
130 # define USB_READ_FLASH(addr) pgm_read_byte(addr)
131 #endif
132
133 #define macro .macro
134 #define endm .endm
135 #define nop2 rjmp .+0 /* jump to next instruction */
136
137 #endif /* development environment */
138
139 /* for conveniecne, ensure that PRG_RDB exists */
140 #ifndef PRG_RDB
141 # define PRG_RDB(addr) USB_READ_FLASH(addr)
142 #endif
143 #endif /* __usbportability_h_INCLUDED__ */

mercurial