usbportability.h 4.5 KB

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