Xmega Application Note


usb_drv.h

Go to the documentation of this file.
00001 /* This file has been prepared for Doxygen automatic documentation generation.*/
00048 #ifndef _USB_DRV_H_
00049 #define _USB_DRV_H_
00050 
00051 /****************************** DEFINES ***************************************/
00052 
00053 #define MAX_EP_NB             7
00054 
00055 #define EP_CONTROL            0
00056 #define EP_1                  1
00057 #define EP_2                  2
00058 #define EP_3                  3
00059 #define EP_4                  4
00060 #define EP_5                  5
00061 #define EP_6                  6
00062 #define EP_7                  7
00063 
00064 #define PIPE_CONTROL          0
00065 #define PIPE_0                0
00066 #define PIPE_1                1
00067 #define PIPE_2                2
00068 #define PIPE_3                3
00069 #define PIPE_4                4
00070 #define PIPE_5                5
00071 #define PIPE_6                6
00072 #define PIPE_7                7
00073 
00074 /* USB EndPoint Mask*/
00075 #define MSK_EP_DIR            0x7F
00076 #define MSK_UADD              0x7F
00077 #define MSK_EPTYPE            0xC0
00078 #define MSK_EPSIZE            0x70
00079 #define MSK_EPBK              0x0C
00080 #define MSK_DTSEQ             0x0C
00081 #define MSK_NBUSYBK           0x03
00082 #define MSK_CURRBK            0x03
00083 #define MSK_DAT               0xFF  /* UEDATX */
00084 #define MSK_BYCTH             0x07  /* UEBCHX */
00085 #define MSK_BYCTL             0xFF  /* UEBCLX */
00086 #define MSK_EPINT             0x7F  /* UEINT */
00087 #define MSK_HADDR             0xFF  /* UHADDR */
00088 
00089 /* USB Pipe Mask */
00090 #define MSK_PNUM              0x07  /* UPNUM */
00091 #define MSK_PRST              0x7F  /* UPRST */
00092 #define MSK_PTYPE             0xC0  /* UPCFG0X */
00093 #define MSK_PTOKEN            0x30
00094 #define MSK_PEPNUM            0x0F
00095 
00096 #define MSK_PSIZE             0x70  /* UPCFG1X */
00097 #define MSK_PBK               0x0C
00098 #define MSK_NBUSYBK           0x03
00099 #define MSK_ERROR             0x1F
00100 
00101 #define MSK_PTYPE             0xC0  /* UPCFG0X */
00102 #define MSK_PTOKEN            0x30
00103 #define MSK_TOKEN_SETUP       0x30
00104 #define MSK_TOKEN_IN          0x10
00105 #define MSK_TOKEN_OUT         0x20
00106 #define MSK_PEPNUM            0x0F
00107 
00108 #define MSK_PSIZE             0x70  /* UPCFG1X */
00109 #define MSK_PBK               0x0C
00110 
00111 /* Enums used to enable and configure an endpoint. */
00112 
00113 typedef enum ep_type{
00114         TYPE_CONTROL        = 0x00,
00115         TYPE_ISOCHRONOUS    = 0x01,
00116         TYPE_BULK           = 0x02,
00117         TYPE_INTERRUPT      = 0x03
00118 }e_ep_type;
00119 
00120 typedef enum ep_dir{
00121         DIRECTION_OUT       = 0x00,
00122         DIRECTION_IN        = 0x01
00123 }e_ep_dir;
00124 
00125 typedef enum ep_size{
00126         SIZE_8              = 0x00,
00127         SIZE_16             = 0x01,
00128         SIZE_32             = 0x02,
00129         SIZE_64             = 0x03,
00130         SIZE_128            = 0x04,
00131         SIZE_256            = 0x05,
00132         SIZE_512            = 0x06,
00133         SIZE_1024           = 0x07
00134 }e_ep_size;
00135 
00136 typedef enum ep_bank{
00137         ONE_BANK            = 0x00,
00138         TWO_BANKS           = 0x01
00139 }e_ep_bank;
00140 
00141 typedef enum ep_nyet{
00142         NYET_DISABLED       = 0x00,
00143         NYET_ENABLED        = 0x01
00144 }e_ep_nyet;
00145 
00146 typedef enum ep_token{
00147         TOKEN_SETUP         = 0x00,
00148         TOKEN_IN            = 0x01,
00149         TOKEN_OUT           = 0x02
00150 }e_ep_token;
00151 
00152 
00153 /****************************** MACROS ****************************************/
00154 
00155 #define Usb_build_ep_config0(type, dir, nyet)    ((type<<6) | (nyet<<1) | (dir))
00156 #define Usb_build_ep_config1(size, bank)         ((size<<4) | (bank<<2))
00157 
00158 #define usb_configure_endpoint(num, type, dir, size, bank, nyet)             \
00159               ( Usb_select_endpoint(num),                                    \
00160                 usb_config_ep(Usb_build_ep_config0(type, dir, nyet),         \
00161                 Usb_build_ep_config1(size, bank)    ))
00162 
00163 
00165 #define Usb_enable_regulator()          (UHWCON |= (1<<UVREGE))
00166 
00168 #define Usb_disable_regulator()         (UHWCON &= ~(1<<UVREGE))
00169 
00171 #define Is_usb_regulator_enabled()      ((UHWCON &  (1<<UVREGE))  ? true : false)
00172 
00173 
00175 #define Usb_enable_uid_pin()            (UHWCON |= (1<<UIDE))
00176 
00178 #define Usb_disable_uid_pin()           (UHWCON &= ~(1<<UIDE))
00179 
00181 #define Usb_force_device_mode()         (Usb_disable_uid_pin(), UHWCON |= (1<<UIMOD))
00182 
00184 #define Usb_force_host_mode()           (Usb_disable_uid_pin(), UHWCON &= ~(1<<UIMOD))
00185 
00187 #define Usb_enable_uvcon_pin()          (UHWCON |= (1<<UVCONE))
00188 
00190 #define Usb_disable_uvcon_pin()         (UHWCON &= ~(1<<UVCONE))
00191 
00193 #define Usb_full_speed_mode()           (UHWCON |= (1<<UDSS))
00194 
00196 #define Usb_low_speed_mode()            (UHWCON &= ~(1<<UDSS))
00197 
00199 #define Usb_enable()                  (USBCON |= ((1<<USBE) | (1<<OTGPADE)))
00200 
00202 #define Usb_disable()                 (USBCON &= ~((1<<USBE) | (1<<OTGPADE)))
00203 #define Is_usb_enabled()              ((USBCON  &   (1<<USBE))   ? true : false)
00204 
00206 #define Usb_enable_vbus_pad()         (USBCON |= (1<<OTGPADE))
00207 
00209 #define Usb_disable_vbus_pad()        (USBCON &= ~(1<<OTGPADE))
00210 
00211 #define Usb_select_device()           (USBCON  &= ~(1<<HOST))
00212 #define Usb_select_host()             (USBCON  |=  (1<<HOST))
00213 #define Is_usb_host_enabled()         ((USBCON  &   (1<<HOST))   ? true : false)
00214 
00216 #define Usb_freeze_clock()            (USBCON  |=  (1<<FRZCLK))
00217 #define Usb_unfreeze_clock()          (USBCON  &= ~(1<<FRZCLK))
00218 #define Is_usb_clock_freezed()        ((USBCON  &   (1<<FRZCLK)) ? true : false)
00219 
00220 #define Usb_enable_id_interrupt()     (USBCON  |=  (1<<IDTE))
00221 #define Usb_disable_id_interrupt()    (USBCON  &= ~(1<<IDTE))
00222 #define Is_usb_id_interrupt_enabled() ((USBCON &  (1<<IDTE))     ? true : false)
00223 #define Is_usb_id_device()            ((USBSTA &   (1<<ID))      ? true : false)
00224 #define Usb_ack_id_transition()       (USBINT  = ~(1<<IDTI))
00225 #define Is_usb_id_transition()        ((USBINT &   (1<<IDTI))    ? true : false)
00226 
00227 #define Usb_enable_vbus_interrupt()   (USBCON  |=  (1<<VBUSTE))
00228 #define Usb_disable_vbus_interrupt()  (USBCON  &= ~(1<<VBUSTE))
00229 #define Is_usb_vbus_interrupt_enabled() ((USBCON &  (1<<VBUSTE))     ? true : false)
00230 #define Is_usb_vbus_high()            ((USBSTA &   (1<<VBUS))    ? true : false)
00231 #define Is_usb_vbus_low()             ((USBSTA &   (1<<VBUS))    ? false : true)
00232 #define Usb_ack_vbus_transition()     (USBINT  = ~(1<<VBUSTI))
00233 #define Is_usb_vbus_transition()      ((USBINT &   (1<<VBUSTI))  ? true : false)
00234 
00236 #define Usb_get_general_interrupt()      (USBINT & (USBCON & MSK_IDTE_VBUSTE))
00237 
00239 #define Usb_ack_all_general_interrupt()  (USBINT = ~(USBCON & MSK_IDTE_VBUSTE))
00240 #define Usb_ack_cache_id_transition(x)   ((x)  &= ~(1<<IDTI))
00241 #define Usb_ack_cache_vbus_transition(x) ((x)  &= ~(1<<VBUSTI))
00242 #define Is_usb_cache_id_transition(x)    (((x) &   (1<<IDTI))  )
00243 #define Is_usb_cache_vbus_transition(x)  (((x) &   (1<<VBUSTI)))
00244 
00246 #define Usb_get_otg_interrupt()            (OTGINT & OTGIEN)
00247 
00249 #define Usb_ack_all_otg_interrupt()        (OTGINT = ~OTGIEN)
00250 #define Is_otg_cache_bconnection_error(x)  (((x) &   MSK_BCERRI))
00251 #define Usb_ack_cache_bconnection_error(x) ((x)  &= ~MSK_BCERRI)
00252 
00253 #define Usb_enter_dpram_mode()        (UDPADDH =  (1<<DPACC))
00254 #define Usb_exit_dpram_mode()         (UDPADDH =  (uint8_t)~(1<<DPACC))
00255 #define Usb_set_dpram_address(addr)   (UDPADDH =  (1<<DPACC) + ((Uint16)addr >> 8), UDPADDL = (uint8_t)addr)
00256 #define Usb_write_dpram_byte(val)     (UEDATX=val)
00257 #define Usb_read_dpram_byte()                     (UEDATX)
00258 
00260 #define Usb_enable_vbus()             (OTGCON  |=  (1<<VBUSREQ))
00261 
00263 #define Usb_disable_vbus()            (OTGCON  |=  (1<<VBUSRQC))
00264 
00266 #define Usb_enable_manual_vbus()      (PORTE|=0x80,DDRE|=0x80,Usb_disable_uvcon_pin())
00267 
00269 #define Usb_device_initiate_hnp()     (OTGCON  |=  (1<<HNPREQ))
00270 
00272 #define Usb_host_accept_hnp()         (OTGCON  |=  (1<<HNPREQ))
00273 
00275 #define Usb_host_reject_hnp()         (OTGCON  &= ~(1<<HNPREQ))
00276 
00278 #define Usb_device_initiate_srp()     (OTGCON  |=  (1<<SRPREQ))
00279 
00281 #define Usb_select_vbus_srp_method()  (OTGCON  |=  (1<<SRPSEL))
00282 
00284 #define Usb_select_data_srp_method()  (OTGCON  &= ~(1<<SRPSEL))
00285 
00287 #define Usb_enable_vbus_hw_control()  (OTGCON  &= ~(1<<VBUSHWC))
00288 
00290 #define Usb_disable_vbus_hw_control() (OTGCON  |=  (1<<VBUSHWC))
00291 
00293 #define Is_usb_vbus_enabled()         ((OTGCON &   (1<<VBUSREQ)) ? true : false)
00294 
00296 #define Is_usb_hnp()                  ((OTGCON &   (1<<HNPREQ))  ? true : false)
00297 
00299 #define Is_usb_device_srp()           ((OTGCON &   (1<<SRPREQ))  ? true : false)
00300 
00302 #define Usb_enable_suspend_time_out_interrupt()   (OTGIEN  |=  (1<<STOE))
00303 
00305 #define Usb_disable_suspend_time_out_interrupt()  (OTGIEN  &= ~(1<<STOE))
00306 #define Is_suspend_time_out_interrupt_enabled()   ((OTGIEN &  (1<<STOE))   ? true : false)
00307 
00309 #define Usb_ack_suspend_time_out_interrupt()      (OTGINT  &= ~(1<<STOI))
00310 
00312 #define Is_usb_suspend_time_out_interrupt()       ((OTGINT &   (1<<STOI))    ? true : false)
00313 
00315 #define Usb_enable_hnp_error_interrupt()          (OTGIEN  |=  (1<<HNPERRE))
00316 
00318 #define Usb_disable_hnp_error_interrupt()         (OTGIEN  &= ~(1<<HNPERRE))
00319 
00320 #define Is_hnp_error_interrupt_enabled()          ((OTGIEN &  (1<<HNPERRE))   ? true : false)
00321 
00323 #define Usb_ack_hnp_error_interrupt()             (OTGINT  &= ~(1<<HNPERRI))
00324 
00326 #define Is_usb_hnp_error_interrupt()              ((OTGINT &   (1<<HNPERRI)) ? true : false)
00327 
00329 #define Usb_enable_role_exchange_interrupt()      (OTGIEN  |=  (1<<ROLEEXE))
00330 
00332 #define Usb_disable_role_exchange_interrupt()     (OTGIEN  &= ~(1<<ROLEEXE))
00333 #define Is_role_exchange_interrupt_enabled()      ((OTGIEN &  (1<<ROLEEXE))   ? true : false)
00334 
00336 #define Usb_ack_role_exchange_interrupt()         (OTGINT  &= ~(1<<ROLEEXI))
00337 
00339 #define Is_usb_role_exchange_interrupt()          ((OTGINT &   (1<<ROLEEXI)) ? true : false)
00340 
00342 #define Usb_enable_bconnection_error_interrupt()  (OTGIEN  |=  (1<<BCERRE))
00343 
00345 #define Usb_disable_bconnection_error_interrupt() (OTGIEN  &= ~(1<<BCERRE))
00346 #define Is_bconnection_error_interrupt_enabled()  ((OTGIEN &  (1<<BCERRE))   ? true : false)
00347 
00349 #define Usb_ack_bconnection_error_interrupt()     (OTGINT  &= ~(1<<BCERRI))
00350 
00352 #define Is_usb_bconnection_error_interrupt()      ((OTGINT &   (1<<BCERRI))  ? true : false)
00353 
00355 #define Usb_enable_vbus_error_interrupt()         (OTGIEN  |=  (1<<VBERRE))
00356 
00358 #define Usb_disable_vbus_error_interrupt()        (OTGIEN  &= ~(1<<VBERRE))
00359 #define Is_vbus_error_interrupt_enabled()         ((OTGIEN &  (1<<VBERRE))   ? true : false)
00360 
00362 #define Usb_ack_vbus_error_interrupt()            (OTGINT  &= ~(1<<VBERRI))
00363 
00365 #define Is_usb_vbus_error_interrupt()             ((OTGINT &   (1<<VBERRI))  ? true : false)
00366 
00368 #define Usb_enable_srp_interrupt()                (OTGIEN  |=  (1<<SRPE))
00369 
00371 #define Usb_disable_srp_interrupt()               (OTGIEN  &= ~(1<<SRPE))
00372 #define Is_srp_interrupt_enabled()                ((OTGIEN &  (1<<SRPE))   ? true : false)
00373 
00375 #define Usb_ack_srp_interrupt()                   (OTGINT  &= ~(1<<SRPI))
00376 
00378 #define Is_usb_srp_interrupt()                    ((OTGINT &   (1<<SRPI))    ? true : false)
00379 
00380 
00381 
00383 #define Usb_initiate_remote_wake_up()             (UDCON   |=  (1<<RMWKUP))
00384 
00386 #define Usb_detach()                              (UDCON   |=  (1<<DETACH))
00387 
00389 #define Usb_attach()                              (UDCON   &= ~(1<<DETACH))
00390 
00392 #define Is_usb_pending_remote_wake_up()           ((UDCON & (1<<RMWKUP)) ? true : false)
00393 
00395 #define Is_usb_detached()                         ((UDCON & (1<<DETACH)) ? true : false)
00396 
00398 #define Usb_get_device_interrupt()                (UDINT   &   (1<<UDIEN))
00399 
00401 #define Usb_ack_all_device_interrupt()            (UDINT   =  ~(1<<UDIEN))
00402 
00404 #define Usb_enable_remote_wake_up_interrupt()     (UDIEN   |=  (1<<UPRSME))
00405 
00407 #define Usb_disable_remote_wake_up_interrupt()    (UDIEN   &= ~(1<<UPRSME))
00408 #define Is_remote_wake_up_interrupt_enabled()     ((UDIEN &  (1<<UPRSME))   ? true : false)
00409 
00411 #define Usb_ack_remote_wake_up_start()            (UDINT   = ~(1<<UPRSMI))
00412 
00414 #define Is_usb_remote_wake_up_start()             ((UDINT &   (1<<UPRSMI))  ? true : false)
00415 
00417 #define Usb_enable_resume_interrupt()             (UDIEN   |=  (1<<EORSME))
00418 
00420 #define Usb_disable_resume_interrupt()            (UDIEN   &= ~(1<<EORSME))
00421 #define Is_resume_interrupt_enabled()             ((UDIEN &  (1<<EORSME))   ? true : false)
00422 
00424 #define Usb_ack_resume()                          (UDINT   = ~(1<<EORSMI))
00425 
00427 #define Is_usb_resume()                           ((UDINT &   (1<<EORSMI))  ? true : false)
00428 
00430 #define Usb_enable_wake_up_interrupt()            (UDIEN   |=  (1<<WAKEUPE))
00431 
00433 #define Usb_disable_wake_up_interrupt()           (UDIEN   &= ~(1<<WAKEUPE))
00434 #define Is_swake_up_interrupt_enabled()           ((UDIEN &  (1<<WAKEUPE))   ? true : false)
00435 
00437 #define Usb_ack_wake_up()                         (UDINT   = ~(1<<WAKEUPI))
00438 
00440 #define Is_usb_wake_up()                          ((UDINT &   (1<<WAKEUPI)) ? true : false)
00441 
00443 #define Usb_enable_reset_interrupt()              (UDIEN   |=  (1<<EORSTE))
00444 
00446 #define Usb_disable_reset_interrupt()             (UDIEN   &= ~(1<<EORSTE))
00447 #define Is_reset_interrupt_enabled()              ((UDIEN &  (1<<EORSTE))   ? true : false)
00448 
00450 #define Usb_ack_reset()                           (UDINT   = ~(1<<EORSTI))
00451 
00453 #define Is_usb_reset()                            ((UDINT &   (1<<EORSTI))  ? true : false)
00454 
00456 #define Usb_enable_sof_interrupt()                (UDIEN   |=  (1<<SOFE))
00457 
00459 #define Usb_disable_sof_interrupt()               (UDIEN   &= ~(1<<SOFE))
00460 #define Is_sof_interrupt_enabled()                ((UDIEN &  (1<<SOFE))   ? true : false)
00461 
00463 #define Usb_ack_sof()                             (UDINT   = ~(1<<SOFI))
00464 
00466 #define Is_usb_sof()                              ((UDINT &   (1<<SOFI))    ? true : false)
00467 
00468 
00470 #define Usb_enable_suspend_interrupt()            (UDIEN   |=  (1<<SUSPE))
00471 
00473 #define Usb_disable_suspend_interrupt()           (UDIEN   &= ~(1<<SUSPE))
00474 #define Is_suspend_interrupt_enabled()            ((UDIEN &  (1<<SUSPE))   ? true : false)
00475 
00477 #define Usb_ack_suspend()                         (UDINT   = ~(1<<SUSPI))
00478 
00480 #define Is_usb_suspend()                          ((UDINT &   (1<<SUSPI))   ? true : false)
00481 
00483 #define Usb_enable_address()                      (UDADDR  |=  (1<<ADDEN))
00484 
00486 #define Usb_disable_address()                     (UDADDR  &= ~(1<<ADDEN))
00487 
00489 #define Usb_configure_address(addr)               (UDADDR  =   (UDADDR & (1<<ADDEN)) | ((uint8_t)addr & MSK_UADD))
00490 
00492 #define Usb_frame_number()                        ((uint16_t)((((uint16_t)UDFNUMH) << 8) | ((uint16_t)UDFNUML)))
00493 
00495 #define Is_usb_frame_number_crc_error()           ((UDMFN & (1<<FNCERR)) ? true : false)
00496 
00498 #define Usb_select_endpoint(ep)                   (UENUM = (uint8_t)ep )
00499 
00501 #define Usb_reset_endpoint(ep)                    (UERST   =   1 << (uint8_t)ep, UERST  =  0)
00502 
00504 #define Usb_enable_endpoint()                     (UECONX  |=  (1<<EPEN))
00505 
00507 #define Usb_enable_stall_handshake()              (UECONX  |=  (1<<STALLRQ))
00508 
00510 #define Usb_reset_data_toggle()                   (UECONX  |=  (1<<RSTDT))
00511 
00513 #define Usb_disable_endpoint()                    (UECONX  &= ~(1<<EPEN))
00514 
00516 #define Usb_disable_stall_handshake()             (UECONX  |=  (1<<STALLRQC))
00517 
00519 #define Usb_select_epnum_for_cpu()                (UECONX  &= ~(1<<EPNUMS))
00520 
00521 #define Is_usb_endpoint_enabled()                 ((UECONX & (1<<EPEN))    ? true : false)
00522 
00524 #define Is_usb_endpoint_stall_requested()         ((UECONX & (1<<STALLRQ)) ? true : false)
00525 
00526 
00528 #define Usb_configure_endpoint_type(type)         (UECFG0X =   (UECFG0X & ~(MSK_EPTYPE)) | ((uint8_t)type << 6))
00529 
00531 #define Usb_configure_endpoint_direction(dir)     (UECFG0X =   (UECFG0X & ~(1<<EPDIR))  | ((uint8_t)dir))
00532 
00533 
00535 #define Usb_configure_endpoint_size(size)         (UECFG1X =   (UECFG1X & ~MSK_EPSIZE) | ((uint8_t)size << 4))
00536 
00538 #define Usb_configure_endpoint_bank(bank)         (UECFG1X =   (UECFG1X & ~MSK_EPBK)   | ((uint8_t)bank << 2))
00539 
00541 #define Usb_allocate_memory()                     (UECFG1X |=  (1<<ALLOC))
00542 
00544 #define Usb_unallocate_memory()                   (UECFG1X &= ~(1<<ALLOC))
00545 
00547 #define Usb_ack_overflow_interrupt()              (UESTA0X &= ~(1<<OVERFI))
00548 
00550 #define Usb_ack_underflow_interrupt()             (UESTA0X &= ~(1<<UNDERFI))
00551 
00553 #define Usb_ack_zlp()                             (UESTA0X &= ~(1<<ZLPSEEN))
00554 
00556 #define Usb_data_toggle()                         ((UESTA0X&MSK_DTSEQ) >> 2)
00557 
00559 #define Usb_nb_busy_bank()                        (UESTA0X &   MSK_NBUSYBK)
00560 
00562 #define Is_usb_one_bank_busy()                    ((UESTA0X &  MSK_NBUSYBK) == 0 ? false : true)
00563 
00565 #define Is_endpoint_configured()                  ((UESTA0X &  (1<<CFGOK))   ? true : false)
00566 
00568 #define Is_usb_overflow()                         ((UESTA0X &  (1<<OVERFI))  ? true : false)
00569 
00571 #define Is_usb_underflow()                        ((UESTA0X &  (1<<UNDERFI)) ? true : false)
00572 
00574 #define Is_usb_zlp()                              ((UESTA0X &  (1<<ZLPSEEN)) ? true : false)
00575 
00577 #define Usb_control_direction()                   ((UESTA1X &  (1<<CTRLDIR)) >> 2)
00578 
00579 #define Usb_current_bank()                        ( UESTA1X & MSK_CURRBK)
00580 
00582 #define Usb_ack_fifocon()                         (UEINTX &= ~(1<<FIFOCON))
00583 
00585 #define Usb_ack_nak_in()                          (UEINTX &= ~(1<<NAKINI))
00586 
00588 #define Usb_ack_nak_out()                         (UEINTX &= ~(1<<NAKOUTI))
00589 
00591 #define Usb_ack_receive_setup()                   (UEINTX &= ~(1<<RXSTPI))
00592 
00594 #define Usb_ack_receive_out()                     (UEINTX &= ~(1<<RXOUTI), Usb_ack_fifocon())
00595 
00597 #define Usb_ack_stalled()                         (MSK_STALLEDI=   0)
00598 
00600 #define Usb_ack_in_ready()                        (UEINTX &= ~(1<<TXINI), Usb_ack_fifocon())
00601 
00603 #define Usb_kill_last_in_bank()                   (UENTTX |= (1<<RXOUTI))
00604 
00606 #define Is_usb_read_enabled()                     (UEINTX&(1<<RWAL))
00607 
00609 #define Is_usb_write_enabled()                    (UEINTX&(1<<RWAL))
00610 
00612 #define Is_usb_read_control_enabled()             (UEINTX&(1<<TXINI))
00613 
00615 #define Is_usb_receive_setup()                    (UEINTX&(1<<RXSTPI))
00616 
00618 #define Is_usb_receive_out()                      (UEINTX&(1<<RXOUTI))
00619 
00621 #define Is_usb_in_ready()                         (UEINTX&(1<<TXINI))
00622 
00624 #define Usb_send_in()                             (UEINTX &= ~(1<<FIFOCON))
00625 
00627 #define Usb_send_control_in()                     (UEINTX &= ~(1<<TXINI))
00628 
00630 #define Usb_free_out_bank()                       (UEINTX &= ~(1<<FIFOCON))
00631 
00633 #define Usb_ack_control_out()                     (UEINTX &= ~(1<<RXOUTI))
00634 
00636 #define Usb_enable_flow_error_interrupt()         (UEIENX  |=  (1<<FLERRE))
00637 
00639 #define Usb_enable_nak_in_interrupt()             (UEIENX  |=  (1<<NAKINE))
00640 
00642 #define Usb_enable_nak_out_interrupt()            (UEIENX  |=  (1<<NAKOUTE))
00643 
00645 #define Usb_enable_receive_setup_interrupt()      (UEIENX  |=  (1<<RXSTPE))
00646 
00648 #define Usb_enable_receive_out_interrupt()        (UEIENX  |=  (1<<RXOUTE))
00649 
00651 #define Usb_enable_stalled_interrupt()            (UEIENX  |=  (1<<STALLEDE))
00652 
00654 #define Usb_enable_in_ready_interrupt()           (UEIENX  |=  (1<<TXIN))
00655 
00657 #define Usb_disable_flow_error_interrupt()        (UEIENX  &= ~(1<<FLERRE))
00658 
00660 #define Usb_disable_nak_in_interrupt()            (UEIENX  &= ~(1<<NAKINE))
00661 
00663 #define Usb_disable_nak_out_interrupt()           (UEIENX  &= ~(1<<NAKOUTE))
00664 
00666 #define Usb_disable_receive_setup_interrupt()     (UEIENX  &= ~(1<<RXSTPE))
00667 
00669 #define Usb_disable_receive_out_interrupt()       (UEIENX  &= ~(1<<RXOUTE))
00670 
00672 #define Usb_disable_stalled_interrupt()           (UEIENX  &= ~(1<<STALLEDE))
00673 
00675 #define Usb_disable_in_ready_interrupt()          (UEIENX  &= ~(1<<TXIN))
00676 
00678 #define Usb_read_byte()                           (UEDATX)
00679 
00681 #define Usb_write_byte(byte)                      (UEDATX  =   (uint8_t)byte)
00682 
00684 #define Usb_byte_counter()                        ((((uint16_t)UEBCHX) << 8) | (UEBCLX))
00685 
00687 #define Usb_byte_counter_8()                      ((uint8_t)UEBCLX)
00688 
00690 #define Usb_interrupt_flags()                     (UEINT != 0x00)
00691 
00693 #define Is_usb_endpoint_event()                   (Usb_interrupt_flags())
00694 
00695 /* ADVANCED MACROS */
00696 #define Usb_select_ep_for_cpu(ep)                 (Usb_select_epnum_for_cpu(), Usb_select_endpoint(ep))
00697 #define Get_pipe_token(x)                         ((x & (0x80)) ? TOKEN_IN : TOKEN_OUT)
00698 
00700 #define Usb_write_word_enum_struc(x)    (x)
00701 
00702 
00703 /************************* PROTOTYPES (GLOBAL) ********************************/
00704 
00705 uint8_t  usb_config_ep(uint8_t, uint8_t);
00706 uint8_t  usb_select_enpoint_interrupt(void);
00707 uint16_t usb_get_nb_byte_epw(void);
00708 uint8_t  usb_send_packet(uint8_t , uint8_t*, uint8_t);
00709 uint8_t  usb_read_packet(uint8_t , uint8_t*, uint8_t);
00710 void     usb_halt_endpoint(uint8_t);
00711 void     usb_reset_endpoint(uint8_t);
00712 uint8_t  usb_init_device(void);
00713 
00714 #endif  /* _USB_DRV_H_ */
00715 
@DOC_TITLE@
Generated on Mon Jan 18 09:26:08 2010 for AVR1907 Xplain USB Gateway by doxygen 1.5.5