Xmega Application Note


usb_drv.h File Reference


Detailed Description

This file contains the USB low level driver definition.

Application note:
AVR1907: Xplain Evaluation Board
Documentation
For comprehensive code documentation, supported compilers, compiler settings and supported devices see readme.html
Author:
Atmel Corporation: http://www.atmel.com
Support email: avr@atmel.com
Revision
3122
Date
2010-01-13 13:26:22 +0100 (on, 13 jan 2010)

Copyright (c) 2010, Atmel Corporation All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. The name of ATMEL may not be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Definition in file usb_drv.h.

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define EP_1   1
#define EP_2   2
#define EP_3   3
#define EP_4   4
#define EP_5   5
#define EP_6   6
#define EP_7   7
#define EP_CONTROL   0
#define Get_pipe_token(x)   ((x & (0x80)) ? TOKEN_IN : TOKEN_OUT)
#define Is_bconnection_error_interrupt_enabled()   ((OTGIEN & (1<<BCERRE)) ? true : false)
#define Is_endpoint_configured()   ((UESTA0X & (1<<CFGOK)) ? true : false)
#define Is_hnp_error_interrupt_enabled()   ((OTGIEN & (1<<HNPERRE)) ? true : false)
#define Is_otg_cache_bconnection_error(x)   (((x) & MSK_BCERRI))
#define Is_remote_wake_up_interrupt_enabled()   ((UDIEN & (1<<UPRSME)) ? true : false)
#define Is_reset_interrupt_enabled()   ((UDIEN & (1<<EORSTE)) ? true : false)
#define Is_resume_interrupt_enabled()   ((UDIEN & (1<<EORSME)) ? true : false)
#define Is_role_exchange_interrupt_enabled()   ((OTGIEN & (1<<ROLEEXE)) ? true : false)
#define Is_sof_interrupt_enabled()   ((UDIEN & (1<<SOFE)) ? true : false)
#define Is_srp_interrupt_enabled()   ((OTGIEN & (1<<SRPE)) ? true : false)
#define Is_suspend_interrupt_enabled()   ((UDIEN & (1<<SUSPE)) ? true : false)
#define Is_suspend_time_out_interrupt_enabled()   ((OTGIEN & (1<<STOE)) ? true : false)
#define Is_swake_up_interrupt_enabled()   ((UDIEN & (1<<WAKEUPE)) ? true : false)
#define Is_usb_bconnection_error_interrupt()   ((OTGINT & (1<<BCERRI)) ? true : false)
#define Is_usb_cache_id_transition(x)   (((x) & (1<<IDTI)) )
#define Is_usb_cache_vbus_transition(x)   (((x) & (1<<VBUSTI)))
#define Is_usb_clock_freezed()   ((USBCON & (1<<FRZCLK)) ? true : false)
#define Is_usb_detached()   ((UDCON & (1<<DETACH)) ? true : false)
#define Is_usb_device_srp()   ((OTGCON & (1<<SRPREQ)) ? true : false)
#define Is_usb_enabled()   ((USBCON & (1<<USBE)) ? true : false)
#define Is_usb_endpoint_enabled()   ((UECONX & (1<<EPEN)) ? true : false)
#define Is_usb_endpoint_event()   (Usb_interrupt_flags())
#define Is_usb_endpoint_stall_requested()   ((UECONX & (1<<STALLRQ)) ? true : false)
#define Is_usb_frame_number_crc_error()   ((UDMFN & (1<<FNCERR)) ? true : false)
#define Is_usb_hnp()   ((OTGCON & (1<<HNPREQ)) ? true : false)
#define Is_usb_hnp_error_interrupt()   ((OTGINT & (1<<HNPERRI)) ? true : false)
#define Is_usb_host_enabled()   ((USBCON & (1<<HOST)) ? true : false)
#define Is_usb_id_device()   ((USBSTA & (1<<ID)) ? true : false)
#define Is_usb_id_interrupt_enabled()   ((USBCON & (1<<IDTE)) ? true : false)
#define Is_usb_id_transition()   ((USBINT & (1<<IDTI)) ? true : false)
#define Is_usb_in_ready()   (UEINTX&(1<<TXINI))
#define Is_usb_one_bank_busy()   ((UESTA0X & MSK_NBUSYBK) == 0 ? false : true)
#define Is_usb_overflow()   ((UESTA0X & (1<<OVERFI)) ? true : false)
#define Is_usb_pending_remote_wake_up()   ((UDCON & (1<<RMWKUP)) ? true : false)
#define Is_usb_read_control_enabled()   (UEINTX&(1<<TXINI))
#define Is_usb_read_enabled()   (UEINTX&(1<<RWAL))
#define Is_usb_receive_out()   (UEINTX&(1<<RXOUTI))
#define Is_usb_receive_setup()   (UEINTX&(1<<RXSTPI))
#define Is_usb_regulator_enabled()   ((UHWCON & (1<<UVREGE)) ? true : false)
#define Is_usb_remote_wake_up_start()   ((UDINT & (1<<UPRSMI)) ? true : false)
#define Is_usb_reset()   ((UDINT & (1<<EORSTI)) ? true : false)
#define Is_usb_resume()   ((UDINT & (1<<EORSMI)) ? true : false)
#define Is_usb_role_exchange_interrupt()   ((OTGINT & (1<<ROLEEXI)) ? true : false)
#define Is_usb_sof()   ((UDINT & (1<<SOFI)) ? true : false)
#define Is_usb_srp_interrupt()   ((OTGINT & (1<<SRPI)) ? true : false)
#define Is_usb_suspend()   ((UDINT & (1<<SUSPI)) ? true : false)
#define Is_usb_suspend_time_out_interrupt()   ((OTGINT & (1<<STOI)) ? true : false)
#define Is_usb_underflow()   ((UESTA0X & (1<<UNDERFI)) ? true : false)
#define Is_usb_vbus_enabled()   ((OTGCON & (1<<VBUSREQ)) ? true : false)
#define Is_usb_vbus_error_interrupt()   ((OTGINT & (1<<VBERRI)) ? true : false)
#define Is_usb_vbus_high()   ((USBSTA & (1<<VBUS)) ? true : false)
#define Is_usb_vbus_interrupt_enabled()   ((USBCON & (1<<VBUSTE)) ? true : false)
#define Is_usb_vbus_low()   ((USBSTA & (1<<VBUS)) ? false : true)
#define Is_usb_vbus_transition()   ((USBINT & (1<<VBUSTI)) ? true : false)
#define Is_usb_wake_up()   ((UDINT & (1<<WAKEUPI)) ? true : false)
#define Is_usb_write_enabled()   (UEINTX&(1<<RWAL))
#define Is_usb_zlp()   ((UESTA0X & (1<<ZLPSEEN)) ? true : false)
#define Is_vbus_error_interrupt_enabled()   ((OTGIEN & (1<<VBERRE)) ? true : false)
#define MAX_EP_NB   7
#define MSK_BYCTH   0x07
#define MSK_BYCTL   0xFF
#define MSK_CURRBK   0x03
#define MSK_DAT   0xFF
#define MSK_DTSEQ   0x0C
#define MSK_EP_DIR   0x7F
#define MSK_EPBK   0x0C
#define MSK_EPINT   0x7F
#define MSK_EPSIZE   0x70
#define MSK_EPTYPE   0xC0
#define MSK_ERROR   0x1F
#define MSK_HADDR   0xFF
#define MSK_NBUSYBK   0x03
#define MSK_NBUSYBK   0x03
#define MSK_PBK   0x0C
#define MSK_PBK   0x0C
#define MSK_PEPNUM   0x0F
#define MSK_PEPNUM   0x0F
#define MSK_PNUM   0x07
#define MSK_PRST   0x7F
#define MSK_PSIZE   0x70
#define MSK_PSIZE   0x70
#define MSK_PTOKEN   0x30
#define MSK_PTOKEN   0x30
#define MSK_PTYPE   0xC0
#define MSK_PTYPE   0xC0
#define MSK_TOKEN_IN   0x10
#define MSK_TOKEN_OUT   0x20
#define MSK_TOKEN_SETUP   0x30
#define MSK_UADD   0x7F
#define PIPE_0   0
#define PIPE_1   1
#define PIPE_2   2
#define PIPE_3   3
#define PIPE_4   4
#define PIPE_5   5
#define PIPE_6   6
#define PIPE_7   7
#define PIPE_CONTROL   0
#define Usb_ack_all_device_interrupt()   (UDINT = ~(1<<UDIEN))
#define Usb_ack_all_general_interrupt()   (USBINT = ~(USBCON & MSK_IDTE_VBUSTE))
#define Usb_ack_all_otg_interrupt()   (OTGINT = ~OTGIEN)
#define Usb_ack_bconnection_error_interrupt()   (OTGINT &= ~(1<<BCERRI))
#define Usb_ack_cache_bconnection_error(x)   ((x) &= ~MSK_BCERRI)
#define Usb_ack_cache_id_transition(x)   ((x) &= ~(1<<IDTI))
#define Usb_ack_cache_vbus_transition(x)   ((x) &= ~(1<<VBUSTI))
#define Usb_ack_control_out()   (UEINTX &= ~(1<<RXOUTI))
#define Usb_ack_fifocon()   (UEINTX &= ~(1<<FIFOCON))
#define Usb_ack_hnp_error_interrupt()   (OTGINT &= ~(1<<HNPERRI))
#define Usb_ack_id_transition()   (USBINT = ~(1<<IDTI))
#define Usb_ack_in_ready()   (UEINTX &= ~(1<<TXINI), Usb_ack_fifocon())
#define Usb_ack_nak_in()   (UEINTX &= ~(1<<NAKINI))
#define Usb_ack_nak_out()   (UEINTX &= ~(1<<NAKOUTI))
#define Usb_ack_overflow_interrupt()   (UESTA0X &= ~(1<<OVERFI))
#define Usb_ack_receive_out()   (UEINTX &= ~(1<<RXOUTI), Usb_ack_fifocon())
#define Usb_ack_receive_setup()   (UEINTX &= ~(1<<RXSTPI))
#define Usb_ack_remote_wake_up_start()   (UDINT = ~(1<<UPRSMI))
#define Usb_ack_reset()   (UDINT = ~(1<<EORSTI))
#define Usb_ack_resume()   (UDINT = ~(1<<EORSMI))
#define Usb_ack_role_exchange_interrupt()   (OTGINT &= ~(1<<ROLEEXI))
#define Usb_ack_sof()   (UDINT = ~(1<<SOFI))
#define Usb_ack_srp_interrupt()   (OTGINT &= ~(1<<SRPI))
#define Usb_ack_stalled()   (MSK_STALLEDI= 0)
#define Usb_ack_suspend()   (UDINT = ~(1<<SUSPI))
#define Usb_ack_suspend_time_out_interrupt()   (OTGINT &= ~(1<<STOI))
#define Usb_ack_underflow_interrupt()   (UESTA0X &= ~(1<<UNDERFI))
#define Usb_ack_vbus_error_interrupt()   (OTGINT &= ~(1<<VBERRI))
#define Usb_ack_vbus_transition()   (USBINT = ~(1<<VBUSTI))
#define Usb_ack_wake_up()   (UDINT = ~(1<<WAKEUPI))
#define Usb_ack_zlp()   (UESTA0X &= ~(1<<ZLPSEEN))
#define Usb_allocate_memory()   (UECFG1X |= (1<<ALLOC))
#define Usb_attach()   (UDCON &= ~(1<<DETACH))
#define Usb_build_ep_config0(type, dir, nyet)   ((type<<6) | (nyet<<1) | (dir))
#define Usb_build_ep_config1(size, bank)   ((size<<4) | (bank<<2))
#define Usb_byte_counter()   ((((uint16_t)UEBCHX) << 8) | (UEBCLX))
#define Usb_byte_counter_8()   ((uint8_t)UEBCLX)
#define Usb_configure_address(addr)   (UDADDR = (UDADDR & (1<<ADDEN)) | ((uint8_t)addr & MSK_UADD))
#define usb_configure_endpoint(num, type, dir, size, bank, nyet)
#define Usb_configure_endpoint_bank(bank)   (UECFG1X = (UECFG1X & ~MSK_EPBK) | ((uint8_t)bank << 2))
#define Usb_configure_endpoint_direction(dir)   (UECFG0X = (UECFG0X & ~(1<<EPDIR)) | ((uint8_t)dir))
#define Usb_configure_endpoint_size(size)   (UECFG1X = (UECFG1X & ~MSK_EPSIZE) | ((uint8_t)size << 4))
#define Usb_configure_endpoint_type(type)   (UECFG0X = (UECFG0X & ~(MSK_EPTYPE)) | ((uint8_t)type << 6))
#define Usb_control_direction()   ((UESTA1X & (1<<CTRLDIR)) >> 2)
#define Usb_current_bank()   ( UESTA1X & MSK_CURRBK)
#define Usb_data_toggle()   ((UESTA0X&MSK_DTSEQ) >> 2)
#define Usb_detach()   (UDCON |= (1<<DETACH))
#define Usb_device_initiate_hnp()   (OTGCON |= (1<<HNPREQ))
#define Usb_device_initiate_srp()   (OTGCON |= (1<<SRPREQ))
#define Usb_disable()   (USBCON &= ~((1<<USBE) | (1<<OTGPADE)))
#define Usb_disable_address()   (UDADDR &= ~(1<<ADDEN))
#define Usb_disable_bconnection_error_interrupt()   (OTGIEN &= ~(1<<BCERRE))
#define Usb_disable_endpoint()   (UECONX &= ~(1<<EPEN))
#define Usb_disable_flow_error_interrupt()   (UEIENX &= ~(1<<FLERRE))
#define Usb_disable_hnp_error_interrupt()   (OTGIEN &= ~(1<<HNPERRE))
#define Usb_disable_id_interrupt()   (USBCON &= ~(1<<IDTE))
#define Usb_disable_in_ready_interrupt()   (UEIENX &= ~(1<<TXIN))
#define Usb_disable_nak_in_interrupt()   (UEIENX &= ~(1<<NAKINE))
#define Usb_disable_nak_out_interrupt()   (UEIENX &= ~(1<<NAKOUTE))
#define Usb_disable_receive_out_interrupt()   (UEIENX &= ~(1<<RXOUTE))
#define Usb_disable_receive_setup_interrupt()   (UEIENX &= ~(1<<RXSTPE))
#define Usb_disable_regulator()   (UHWCON &= ~(1<<UVREGE))
#define Usb_disable_remote_wake_up_interrupt()   (UDIEN &= ~(1<<UPRSME))
#define Usb_disable_reset_interrupt()   (UDIEN &= ~(1<<EORSTE))
#define Usb_disable_resume_interrupt()   (UDIEN &= ~(1<<EORSME))
#define Usb_disable_role_exchange_interrupt()   (OTGIEN &= ~(1<<ROLEEXE))
#define Usb_disable_sof_interrupt()   (UDIEN &= ~(1<<SOFE))
#define Usb_disable_srp_interrupt()   (OTGIEN &= ~(1<<SRPE))
#define Usb_disable_stall_handshake()   (UECONX |= (1<<STALLRQC))
#define Usb_disable_stalled_interrupt()   (UEIENX &= ~(1<<STALLEDE))
#define Usb_disable_suspend_interrupt()   (UDIEN &= ~(1<<SUSPE))
#define Usb_disable_suspend_time_out_interrupt()   (OTGIEN &= ~(1<<STOE))
#define Usb_disable_uid_pin()   (UHWCON &= ~(1<<UIDE))
#define Usb_disable_uvcon_pin()   (UHWCON &= ~(1<<UVCONE))
#define Usb_disable_vbus()   (OTGCON |= (1<<VBUSRQC))
#define Usb_disable_vbus_error_interrupt()   (OTGIEN &= ~(1<<VBERRE))
#define Usb_disable_vbus_hw_control()   (OTGCON |= (1<<VBUSHWC))
#define Usb_disable_vbus_interrupt()   (USBCON &= ~(1<<VBUSTE))
#define Usb_disable_vbus_pad()   (USBCON &= ~(1<<OTGPADE))
#define Usb_disable_wake_up_interrupt()   (UDIEN &= ~(1<<WAKEUPE))
#define Usb_enable()   (USBCON |= ((1<<USBE) | (1<<OTGPADE)))
#define Usb_enable_address()   (UDADDR |= (1<<ADDEN))
#define Usb_enable_bconnection_error_interrupt()   (OTGIEN |= (1<<BCERRE))
#define Usb_enable_endpoint()   (UECONX |= (1<<EPEN))
#define Usb_enable_flow_error_interrupt()   (UEIENX |= (1<<FLERRE))
#define Usb_enable_hnp_error_interrupt()   (OTGIEN |= (1<<HNPERRE))
#define Usb_enable_id_interrupt()   (USBCON |= (1<<IDTE))
#define Usb_enable_in_ready_interrupt()   (UEIENX |= (1<<TXIN))
#define Usb_enable_manual_vbus()   (PORTE|=0x80,DDRE|=0x80,Usb_disable_uvcon_pin())
#define Usb_enable_nak_in_interrupt()   (UEIENX |= (1<<NAKINE))
#define Usb_enable_nak_out_interrupt()   (UEIENX |= (1<<NAKOUTE))
#define Usb_enable_receive_out_interrupt()   (UEIENX |= (1<<RXOUTE))
#define Usb_enable_receive_setup_interrupt()   (UEIENX |= (1<<RXSTPE))
#define Usb_enable_regulator()   (UHWCON |= (1<<UVREGE))
#define Usb_enable_remote_wake_up_interrupt()   (UDIEN |= (1<<UPRSME))
#define Usb_enable_reset_interrupt()   (UDIEN |= (1<<EORSTE))
#define Usb_enable_resume_interrupt()   (UDIEN |= (1<<EORSME))
#define Usb_enable_role_exchange_interrupt()   (OTGIEN |= (1<<ROLEEXE))
#define Usb_enable_sof_interrupt()   (UDIEN |= (1<<SOFE))
#define Usb_enable_srp_interrupt()   (OTGIEN |= (1<<SRPE))
#define Usb_enable_stall_handshake()   (UECONX |= (1<<STALLRQ))
#define Usb_enable_stalled_interrupt()   (UEIENX |= (1<<STALLEDE))
#define Usb_enable_suspend_interrupt()   (UDIEN |= (1<<SUSPE))
#define Usb_enable_suspend_time_out_interrupt()   (OTGIEN |= (1<<STOE))
#define Usb_enable_uid_pin()   (UHWCON |= (1<<UIDE))
#define Usb_enable_uvcon_pin()   (UHWCON |= (1<<UVCONE))
#define Usb_enable_vbus()   (OTGCON |= (1<<VBUSREQ))
#define Usb_enable_vbus_error_interrupt()   (OTGIEN |= (1<<VBERRE))
#define Usb_enable_vbus_hw_control()   (OTGCON &= ~(1<<VBUSHWC))
#define Usb_enable_vbus_interrupt()   (USBCON |= (1<<VBUSTE))
#define Usb_enable_vbus_pad()   (USBCON |= (1<<OTGPADE))
#define Usb_enable_wake_up_interrupt()   (UDIEN |= (1<<WAKEUPE))
#define Usb_enter_dpram_mode()   (UDPADDH = (1<<DPACC))
#define Usb_exit_dpram_mode()   (UDPADDH = (uint8_t)~(1<<DPACC))
#define Usb_force_device_mode()   (Usb_disable_uid_pin(), UHWCON |= (1<<UIMOD))
#define Usb_force_host_mode()   (Usb_disable_uid_pin(), UHWCON &= ~(1<<UIMOD))
#define Usb_frame_number()   ((uint16_t)((((uint16_t)UDFNUMH) << 8) | ((uint16_t)UDFNUML)))
#define Usb_free_out_bank()   (UEINTX &= ~(1<<FIFOCON))
#define Usb_freeze_clock()   (USBCON |= (1<<FRZCLK))
#define Usb_full_speed_mode()   (UHWCON |= (1<<UDSS))
#define Usb_get_device_interrupt()   (UDINT & (1<<UDIEN))
#define Usb_get_general_interrupt()   (USBINT & (USBCON & MSK_IDTE_VBUSTE))
#define Usb_get_otg_interrupt()   (OTGINT & OTGIEN)
#define Usb_host_accept_hnp()   (OTGCON |= (1<<HNPREQ))
#define Usb_host_reject_hnp()   (OTGCON &= ~(1<<HNPREQ))
#define Usb_initiate_remote_wake_up()   (UDCON |= (1<<RMWKUP))
#define Usb_interrupt_flags()   (UEINT != 0x00)
#define Usb_kill_last_in_bank()   (UENTTX |= (1<<RXOUTI))
#define Usb_low_speed_mode()   (UHWCON &= ~(1<<UDSS))
#define Usb_nb_busy_bank()   (UESTA0X & MSK_NBUSYBK)
#define Usb_read_byte()   (UEDATX)
#define Usb_read_dpram_byte()   (UEDATX)
#define Usb_reset_data_toggle()   (UECONX |= (1<<RSTDT))
#define Usb_reset_endpoint(ep)   (UERST = 1 << (uint8_t)ep, UERST = 0)
#define Usb_select_data_srp_method()   (OTGCON &= ~(1<<SRPSEL))
#define Usb_select_device()   (USBCON &= ~(1<<HOST))
#define Usb_select_endpoint(ep)   (UENUM = (uint8_t)ep )
#define Usb_select_ep_for_cpu(ep)   (Usb_select_epnum_for_cpu(), Usb_select_endpoint(ep))
#define Usb_select_epnum_for_cpu()   (UECONX &= ~(1<<EPNUMS))
#define Usb_select_host()   (USBCON |= (1<<HOST))
#define Usb_select_vbus_srp_method()   (OTGCON |= (1<<SRPSEL))
#define Usb_send_control_in()   (UEINTX &= ~(1<<TXINI))
#define Usb_send_in()   (UEINTX &= ~(1<<FIFOCON))
#define Usb_set_dpram_address(addr)   (UDPADDH = (1<<DPACC) + ((Uint16)addr >> 8), UDPADDL = (uint8_t)addr)
#define Usb_unallocate_memory()   (UECFG1X &= ~(1<<ALLOC))
#define Usb_unfreeze_clock()   (USBCON &= ~(1<<FRZCLK))
#define Usb_write_byte(byte)   (UEDATX = (uint8_t)byte)
#define Usb_write_dpram_byte(val)   (UEDATX=val)
#define Usb_write_word_enum_struc(x)   (x)

Typedefs

typedef enum ep_bank e_ep_bank
typedef enum ep_dir e_ep_dir
typedef enum ep_nyet e_ep_nyet
typedef enum ep_size e_ep_size
typedef enum ep_token e_ep_token
typedef enum ep_type e_ep_type

Enumerations

enum  ep_bank { ONE_BANK = 0x00, TWO_BANKS = 0x01 }
enum  ep_dir { DIRECTION_OUT = 0x00, DIRECTION_IN = 0x01 }
enum  ep_nyet { NYET_DISABLED = 0x00, NYET_ENABLED = 0x01 }
enum  ep_size {
  SIZE_8 = 0x00, SIZE_16 = 0x01, SIZE_32 = 0x02, SIZE_64 = 0x03,
  SIZE_128 = 0x04, SIZE_256 = 0x05, SIZE_512 = 0x06, SIZE_1024 = 0x07
}
enum  ep_token { TOKEN_SETUP = 0x00, TOKEN_IN = 0x01, TOKEN_OUT = 0x02 }
enum  ep_type { TYPE_CONTROL = 0x00, TYPE_ISOCHRONOUS = 0x01, TYPE_BULK = 0x02, TYPE_INTERRUPT = 0x03 }

Functions

uint8_t usb_config_ep (uint8_t, uint8_t)
 This function configures an endpoint with the selected type.
uint16_t usb_get_nb_byte_epw (void)
void usb_halt_endpoint (uint8_t)
 This function sends a STALL handshake for the next Host request. A STALL handshake will be send for each next request untill a SETUP or a Clear Halt Feature occurs for this endpoint.
uint8_t usb_init_device (void)
 This function initializes the USB device controller and configures the Default Control Endpoint.
uint8_t usb_read_packet (uint8_t, uint8_t *, uint8_t)
 This function moves the data stored in the selected endpoint fifo to the address specified by *rbuf.
void usb_reset_endpoint (uint8_t)
uint8_t usb_select_enpoint_interrupt (void)
 This function select the endpoint where an event occurs and returns the number of this endpoint. If no event occurs on the endpoints, this function returns 0.
uint8_t usb_send_packet (uint8_t, uint8_t *, uint8_t)
 This function moves the data pointed by tbuf to the selected endpoint fifo and sends it through the USB.


Define Documentation

#define EP_1   1

Definition at line 56 of file usb_drv.h.

#define EP_2   2

Definition at line 57 of file usb_drv.h.

#define EP_3   3

Definition at line 58 of file usb_drv.h.

#define EP_4   4

Definition at line 59 of file usb_drv.h.

#define EP_5   5

Definition at line 60 of file usb_drv.h.

#define EP_6   6

Definition at line 61 of file usb_drv.h.

#define EP_7   7

Definition at line 62 of file usb_drv.h.

#define EP_CONTROL   0

Definition at line 55 of file usb_drv.h.

Referenced by usb_clear_feature(), usb_device_task(), usb_init_device(), and usb_set_feature().

#define Get_pipe_token (  )     ((x & (0x80)) ? TOKEN_IN : TOKEN_OUT)

Definition at line 697 of file usb_drv.h.

 
#define Is_bconnection_error_interrupt_enabled (  )     ((OTGIEN & (1<<BCERRE)) ? true : false)

Definition at line 346 of file usb_drv.h.

 
#define Is_endpoint_configured (  )     ((UESTA0X & (1<<CFGOK)) ? true : false)

tests if current endpoint is configured

Definition at line 565 of file usb_drv.h.

Referenced by usb_config_ep().

 
#define Is_hnp_error_interrupt_enabled (  )     ((OTGIEN & (1<<HNPERRE)) ? true : false)

Definition at line 320 of file usb_drv.h.

#define Is_otg_cache_bconnection_error (  )     (((x) & MSK_BCERRI))

Definition at line 250 of file usb_drv.h.

 
#define Is_remote_wake_up_interrupt_enabled (  )     ((UDIEN & (1<<UPRSME)) ? true : false)

Definition at line 408 of file usb_drv.h.

 
#define Is_reset_interrupt_enabled (  )     ((UDIEN & (1<<EORSTE)) ? true : false)

Definition at line 447 of file usb_drv.h.

Referenced by ISR().

 
#define Is_resume_interrupt_enabled (  )     ((UDIEN & (1<<EORSME)) ? true : false)

Definition at line 421 of file usb_drv.h.

Referenced by ISR().

 
#define Is_role_exchange_interrupt_enabled (  )     ((OTGIEN & (1<<ROLEEXE)) ? true : false)

Definition at line 333 of file usb_drv.h.

 
#define Is_sof_interrupt_enabled (  )     ((UDIEN & (1<<SOFE)) ? true : false)

Definition at line 460 of file usb_drv.h.

Referenced by ISR().

 
#define Is_srp_interrupt_enabled (  )     ((OTGIEN & (1<<SRPE)) ? true : false)

Definition at line 372 of file usb_drv.h.

 
#define Is_suspend_interrupt_enabled (  )     ((UDIEN & (1<<SUSPE)) ? true : false)

Definition at line 474 of file usb_drv.h.

Referenced by ISR().

 
#define Is_suspend_time_out_interrupt_enabled (  )     ((OTGIEN & (1<<STOE)) ? true : false)

Definition at line 306 of file usb_drv.h.

 
#define Is_swake_up_interrupt_enabled (  )     ((UDIEN & (1<<WAKEUPE)) ? true : false)

Definition at line 434 of file usb_drv.h.

Referenced by ISR().

 
#define Is_usb_bconnection_error_interrupt (  )     ((OTGINT & (1<<BCERRI)) ? true : false)

tests if a B device connection error occurs

Definition at line 352 of file usb_drv.h.

#define Is_usb_cache_id_transition (  )     (((x) & (1<<IDTI)) )

Definition at line 242 of file usb_drv.h.

#define Is_usb_cache_vbus_transition (  )     (((x) & (1<<VBUSTI)))

Definition at line 243 of file usb_drv.h.

 
#define Is_usb_clock_freezed (  )     ((USBCON & (1<<FRZCLK)) ? true : false)

Definition at line 218 of file usb_drv.h.

 
#define Is_usb_detached (  )     ((UDCON & (1<<DETACH)) ? true : false)

test if the device is detached

Definition at line 395 of file usb_drv.h.

 
#define Is_usb_device_srp (  )     ((OTGCON & (1<<SRPREQ)) ? true : false)

tests if a SRP from device occurs

Definition at line 299 of file usb_drv.h.

 
#define Is_usb_enabled (  )     ((USBCON & (1<<USBE)) ? true : false)

Definition at line 203 of file usb_drv.h.

 
#define Is_usb_endpoint_enabled (  )     ((UECONX & (1<<EPEN)) ? true : false)

tests if the current endpoint is enabled

Definition at line 521 of file usb_drv.h.

Referenced by usb_clear_feature(), usb_init_device(), and usb_set_feature().

 
#define Is_usb_endpoint_event (  )     (Usb_interrupt_flags())

tests the general endpoint interrupt flags

Definition at line 693 of file usb_drv.h.

 
#define Is_usb_endpoint_stall_requested (  )     ((UECONX & (1<<STALLRQ)) ? true : false)

tests if STALL handshake request is running

Definition at line 524 of file usb_drv.h.

 
#define Is_usb_frame_number_crc_error (  )     ((UDMFN & (1<<FNCERR)) ? true : false)

tests if a crc error occurs in frame number

Definition at line 495 of file usb_drv.h.

 
#define Is_usb_hnp (  )     ((OTGCON & (1<<HNPREQ)) ? true : false)

tests if a HNP occurs

Definition at line 296 of file usb_drv.h.

 
#define Is_usb_hnp_error_interrupt (  )     ((OTGINT & (1<<HNPERRI)) ? true : false)

tests if a HNP error occurs

Definition at line 326 of file usb_drv.h.

 
#define Is_usb_host_enabled (  )     ((USBCON & (1<<HOST)) ? true : false)

Definition at line 213 of file usb_drv.h.

 
#define Is_usb_id_device (  )     ((USBSTA & (1<<ID)) ? true : false)

Definition at line 223 of file usb_drv.h.

Referenced by usb_init_device().

 
#define Is_usb_id_interrupt_enabled (  )     ((USBCON & (1<<IDTE)) ? true : false)

Definition at line 222 of file usb_drv.h.

 
#define Is_usb_id_transition (  )     ((USBINT & (1<<IDTI)) ? true : false)

Definition at line 225 of file usb_drv.h.

 
#define Is_usb_in_ready (  )     (UEINTX&(1<<TXINI))

tests if IN ready

Definition at line 621 of file usb_drv.h.

Referenced by usb_set_address(), and usb_set_interface().

 
#define Is_usb_one_bank_busy (  )     ((UESTA0X & MSK_NBUSYBK) == 0 ? false : true)

tests if at least one bank is busy

Definition at line 562 of file usb_drv.h.

 
#define Is_usb_overflow (  )     ((UESTA0X & (1<<OVERFI)) ? true : false)

tests if an overflows occurs

Definition at line 568 of file usb_drv.h.

 
#define Is_usb_pending_remote_wake_up (  )     ((UDCON & (1<<RMWKUP)) ? true : false)

test if remote wake-up still running

Definition at line 392 of file usb_drv.h.

 
#define Is_usb_read_control_enabled (  )     (UEINTX&(1<<TXINI))

tests if read allowed on control endpoint

Definition at line 612 of file usb_drv.h.

Referenced by cdc_get_line_coding(), cdc_set_control_line_state(), cdc_set_line_coding(), and usb_get_descriptor().

 
#define Is_usb_read_enabled (  )     (UEINTX&(1<<RWAL))

tests if endpoint read allowed

Definition at line 606 of file usb_drv.h.

Referenced by usb_read_packet().

 
#define Is_usb_receive_out (  )     (UEINTX&(1<<RXOUTI))

 
#define Is_usb_receive_setup (  )     (UEINTX&(1<<RXSTPI))

tests if SETUP received

Definition at line 615 of file usb_drv.h.

Referenced by usb_device_task().

 
#define Is_usb_regulator_enabled (  )     ((UHWCON & (1<<UVREGE)) ? true : false)

Check regulator enable bit

Definition at line 171 of file usb_drv.h.

 
#define Is_usb_remote_wake_up_start (  )     ((UDINT & (1<<UPRSMI)) ? true : false)

tests if remote wake-up still running

Definition at line 414 of file usb_drv.h.

 
#define Is_usb_reset (  )     ((UDINT & (1<<EORSTI)) ? true : false)

tests if USB reset occurs

Definition at line 453 of file usb_drv.h.

Referenced by ISR().

 
#define Is_usb_resume (  )     ((UDINT & (1<<EORSMI)) ? true : false)

tests if resume occurs

Definition at line 427 of file usb_drv.h.

Referenced by ISR().

 
#define Is_usb_role_exchange_interrupt (  )     ((OTGINT & (1<<ROLEEXI)) ? true : false)

tests if a role exchange occurs

Definition at line 339 of file usb_drv.h.

 
#define Is_usb_sof (  )     ((UDINT & (1<<SOFI)) ? true : false)

tests if Start Of Frame occurs

Definition at line 466 of file usb_drv.h.

Referenced by ISR().

 
#define Is_usb_srp_interrupt (  )     ((OTGINT & (1<<SRPI)) ? true : false)

tests if a SRP occurs

Definition at line 378 of file usb_drv.h.

 
#define Is_usb_suspend (  )     ((UDINT & (1<<SUSPI)) ? true : false)

tests if Suspend state detected

Definition at line 480 of file usb_drv.h.

Referenced by ISR().

 
#define Is_usb_suspend_time_out_interrupt (  )     ((OTGINT & (1<<STOI)) ? true : false)

tests if a suspend time out occurs

Definition at line 312 of file usb_drv.h.

 
#define Is_usb_underflow (  )     ((UESTA0X & (1<<UNDERFI)) ? true : false)

tests if an underflow occurs

Definition at line 571 of file usb_drv.h.

 
#define Is_usb_vbus_enabled (  )     ((OTGCON & (1<<VBUSREQ)) ? true : false)

tests if VBus has been requested

Definition at line 293 of file usb_drv.h.

 
#define Is_usb_vbus_error_interrupt (  )     ((OTGINT & (1<<VBERRI)) ? true : false)

tests if a VBus error occurs

Definition at line 365 of file usb_drv.h.

 
#define Is_usb_vbus_high (  )     ((USBSTA & (1<<VBUS)) ? true : false)

Definition at line 230 of file usb_drv.h.

Referenced by ISR(), and usb_device_task().

 
#define Is_usb_vbus_interrupt_enabled (  )     ((USBCON & (1<<VBUSTE)) ? true : false)

Definition at line 229 of file usb_drv.h.

Referenced by ISR().

 
#define Is_usb_vbus_low (  )     ((USBSTA & (1<<VBUS)) ? false : true)

Definition at line 231 of file usb_drv.h.

 
#define Is_usb_vbus_transition (  )     ((USBINT & (1<<VBUSTI)) ? true : false)

Definition at line 233 of file usb_drv.h.

Referenced by ISR().

 
#define Is_usb_wake_up (  )     ((UDINT & (1<<WAKEUPI)) ? true : false)

tests if wake-up occurs

Definition at line 440 of file usb_drv.h.

Referenced by ISR().

 
#define Is_usb_write_enabled (  )     (UEINTX&(1<<RWAL))

tests if endpoint write allowed

Definition at line 609 of file usb_drv.h.

Referenced by uart_usb_putchar(), uart_usb_tx_ready(), and usb_send_packet().

 
#define Is_usb_zlp (  )     ((UESTA0X & (1<<ZLPSEEN)) ? true : false)

tests if a ZLP has been detected

Definition at line 574 of file usb_drv.h.

 
#define Is_vbus_error_interrupt_enabled (  )     ((OTGIEN & (1<<VBERRE)) ? true : false)

Definition at line 359 of file usb_drv.h.

#define MAX_EP_NB   7

Definition at line 53 of file usb_drv.h.

#define MSK_BYCTH   0x07

Definition at line 84 of file usb_drv.h.

#define MSK_BYCTL   0xFF

Definition at line 85 of file usb_drv.h.

#define MSK_CURRBK   0x03

Definition at line 82 of file usb_drv.h.

#define MSK_DAT   0xFF

Definition at line 83 of file usb_drv.h.

#define MSK_DTSEQ   0x0C

Definition at line 80 of file usb_drv.h.

#define MSK_EP_DIR   0x7F

Definition at line 75 of file usb_drv.h.

Referenced by usb_clear_feature(), usb_get_status(), and usb_set_feature().

#define MSK_EPBK   0x0C

Definition at line 79 of file usb_drv.h.

#define MSK_EPINT   0x7F

Definition at line 86 of file usb_drv.h.

#define MSK_EPSIZE   0x70

Definition at line 78 of file usb_drv.h.

#define MSK_EPTYPE   0xC0

Definition at line 77 of file usb_drv.h.

#define MSK_ERROR   0x1F

Definition at line 99 of file usb_drv.h.

#define MSK_HADDR   0xFF

Definition at line 87 of file usb_drv.h.

#define MSK_NBUSYBK   0x03

Definition at line 98 of file usb_drv.h.

#define MSK_NBUSYBK   0x03

Definition at line 98 of file usb_drv.h.

#define MSK_PBK   0x0C

Definition at line 109 of file usb_drv.h.

#define MSK_PBK   0x0C

Definition at line 109 of file usb_drv.h.

#define MSK_PEPNUM   0x0F

Definition at line 106 of file usb_drv.h.

#define MSK_PEPNUM   0x0F

Definition at line 106 of file usb_drv.h.

#define MSK_PNUM   0x07

Definition at line 90 of file usb_drv.h.

#define MSK_PRST   0x7F

Definition at line 91 of file usb_drv.h.

#define MSK_PSIZE   0x70

Definition at line 108 of file usb_drv.h.

#define MSK_PSIZE   0x70

Definition at line 108 of file usb_drv.h.

#define MSK_PTOKEN   0x30

Definition at line 102 of file usb_drv.h.

#define MSK_PTOKEN   0x30

Definition at line 102 of file usb_drv.h.

#define MSK_PTYPE   0xC0

Definition at line 101 of file usb_drv.h.

#define MSK_PTYPE   0xC0

Definition at line 101 of file usb_drv.h.

#define MSK_TOKEN_IN   0x10

Definition at line 104 of file usb_drv.h.

#define MSK_TOKEN_OUT   0x20

Definition at line 105 of file usb_drv.h.

#define MSK_TOKEN_SETUP   0x30

Definition at line 103 of file usb_drv.h.

#define MSK_UADD   0x7F

Definition at line 76 of file usb_drv.h.

#define PIPE_0   0

Definition at line 65 of file usb_drv.h.

#define PIPE_1   1

Definition at line 66 of file usb_drv.h.

#define PIPE_2   2

Definition at line 67 of file usb_drv.h.

#define PIPE_3   3

Definition at line 68 of file usb_drv.h.

#define PIPE_4   4

Definition at line 69 of file usb_drv.h.

#define PIPE_5   5

Definition at line 70 of file usb_drv.h.

#define PIPE_6   6

Definition at line 71 of file usb_drv.h.

#define PIPE_7   7

Definition at line 72 of file usb_drv.h.

#define PIPE_CONTROL   0

Definition at line 64 of file usb_drv.h.

 
#define Usb_ack_all_device_interrupt (  )     (UDINT = ~(1<<UDIEN))

acks the USB device interrupts (interrupt enabled)

Definition at line 401 of file usb_drv.h.

 
#define Usb_ack_all_general_interrupt (  )     (USBINT = ~(USBCON & MSK_IDTE_VBUSTE))

acks the general interrupts (interrupt enabled)

Definition at line 239 of file usb_drv.h.

 
#define Usb_ack_all_otg_interrupt (  )     (OTGINT = ~OTGIEN)

acks the USB Pad interrupts (interrupt enabled)

Definition at line 249 of file usb_drv.h.

 
#define Usb_ack_bconnection_error_interrupt (  )     (OTGINT &= ~(1<<BCERRI))

acks B device connection error interrupt

Definition at line 349 of file usb_drv.h.

#define Usb_ack_cache_bconnection_error (  )     ((x) &= ~MSK_BCERRI)

Definition at line 251 of file usb_drv.h.

#define Usb_ack_cache_id_transition (  )     ((x) &= ~(1<<IDTI))

Definition at line 240 of file usb_drv.h.

#define Usb_ack_cache_vbus_transition (  )     ((x) &= ~(1<<VBUSTI))

Definition at line 241 of file usb_drv.h.

 
#define Usb_ack_control_out (  )     (UEINTX &= ~(1<<RXOUTI))

acks OUT on control endpoint

Definition at line 633 of file usb_drv.h.

 
#define Usb_ack_fifocon (  )     (UEINTX &= ~(1<<FIFOCON))

clears FIFOCON bit

Definition at line 582 of file usb_drv.h.

 
#define Usb_ack_hnp_error_interrupt (  )     (OTGINT &= ~(1<<HNPERRI))

acks HNP error interrupt

Definition at line 323 of file usb_drv.h.

 
#define Usb_ack_id_transition (  )     (USBINT = ~(1<<IDTI))

Definition at line 224 of file usb_drv.h.

 
#define Usb_ack_in_ready (  )     (UEINTX &= ~(1<<TXINI), Usb_ack_fifocon())

acks IN ready

Definition at line 600 of file usb_drv.h.

Referenced by usb_get_configuration().

 
#define Usb_ack_nak_in (  )     (UEINTX &= ~(1<<NAKINI))

acks NAK IN received

Definition at line 585 of file usb_drv.h.

 
#define Usb_ack_nak_out (  )     (UEINTX &= ~(1<<NAKOUTI))

acks NAK OUT received

Definition at line 588 of file usb_drv.h.

 
#define Usb_ack_overflow_interrupt (  )     (UESTA0X &= ~(1<<OVERFI))

acks endpoint overflow interrupt

Definition at line 547 of file usb_drv.h.

 
#define Usb_ack_receive_out (  )     (UEINTX &= ~(1<<RXOUTI), Usb_ack_fifocon())

 
#define Usb_ack_receive_setup (  )     (UEINTX &= ~(1<<RXSTPI))

 
#define Usb_ack_remote_wake_up_start (  )     (UDINT = ~(1<<UPRSMI))

acks remote wake-up

Definition at line 411 of file usb_drv.h.

 
#define Usb_ack_reset (  )     (UDINT = ~(1<<EORSTI))

acks USB reset

Definition at line 450 of file usb_drv.h.

Referenced by ISR().

 
#define Usb_ack_resume (  )     (UDINT = ~(1<<EORSMI))

acks resume

Definition at line 424 of file usb_drv.h.

Referenced by ISR().

 
#define Usb_ack_role_exchange_interrupt (  )     (OTGINT &= ~(1<<ROLEEXI))

acks role exchange interrupt

Definition at line 336 of file usb_drv.h.

 
#define Usb_ack_sof (  )     (UDINT = ~(1<<SOFI))

acks Start Of Frame

Definition at line 463 of file usb_drv.h.

Referenced by ISR().

 
#define Usb_ack_srp_interrupt (  )     (OTGINT &= ~(1<<SRPI))

acks SRP interrupt

Definition at line 375 of file usb_drv.h.

 
#define Usb_ack_stalled (  )     (MSK_STALLEDI= 0)

acks STALL sent

Definition at line 597 of file usb_drv.h.

 
#define Usb_ack_suspend (  )     (UDINT = ~(1<<SUSPI))

acks Suspend

Definition at line 477 of file usb_drv.h.

Referenced by ISR().

 
#define Usb_ack_suspend_time_out_interrupt (  )     (OTGINT &= ~(1<<STOI))

acks suspend time out interrupt

Definition at line 309 of file usb_drv.h.

 
#define Usb_ack_underflow_interrupt (  )     (UESTA0X &= ~(1<<UNDERFI))

acks endpoint underflow memory

Definition at line 550 of file usb_drv.h.

 
#define Usb_ack_vbus_error_interrupt (  )     (OTGINT &= ~(1<<VBERRI))

acks VBus error interrupt

Definition at line 362 of file usb_drv.h.

 
#define Usb_ack_vbus_transition (  )     (USBINT = ~(1<<VBUSTI))

Definition at line 232 of file usb_drv.h.

Referenced by ISR().

 
#define Usb_ack_wake_up (  )     (UDINT = ~(1<<WAKEUPI))

acks wake-up

Definition at line 437 of file usb_drv.h.

Referenced by ISR().

 
#define Usb_ack_zlp (  )     (UESTA0X &= ~(1<<ZLPSEEN))

acks Zero Length Packet received

Definition at line 553 of file usb_drv.h.

 
#define Usb_allocate_memory (  )     (UECFG1X |= (1<<ALLOC))

allocates the current configuration in DPRAM memory

Definition at line 541 of file usb_drv.h.

Referenced by usb_config_ep().

 
#define Usb_attach (  )     (UDCON &= ~(1<<DETACH))

attaches to USB bus

Definition at line 389 of file usb_drv.h.

Referenced by ISR(), usb_device_task(), and usb_start_device().

#define Usb_build_ep_config0 ( type,
dir,
nyet   )     ((type<<6) | (nyet<<1) | (dir))

Definition at line 155 of file usb_drv.h.

#define Usb_build_ep_config1 ( size,
bank   )     ((size<<4) | (bank<<2))

Definition at line 156 of file usb_drv.h.

 
#define Usb_byte_counter (  )     ((((uint16_t)UEBCHX) << 8) | (UEBCLX))

returns number of bytes in FIFO current endpoint (16 bits)

Definition at line 684 of file usb_drv.h.

Referenced by uart_usb_test_hit().

 
#define Usb_byte_counter_8 (  )     ((uint8_t)UEBCLX)

returns number of bytes in FIFO current endpoint (8 bits)

Definition at line 687 of file usb_drv.h.

#define Usb_configure_address ( addr   )     (UDADDR = (UDADDR & (1<<ADDEN)) | ((uint8_t)addr & MSK_UADD))

sets the USB device address

Definition at line 489 of file usb_drv.h.

Referenced by usb_set_address().

#define usb_configure_endpoint ( num,
type,
dir,
size,
bank,
nyet   ) 

Value:

( Usb_select_endpoint(num),                                    \
                usb_config_ep(Usb_build_ep_config0(type, dir, nyet),         \
                Usb_build_ep_config1(size, bank)    ))

Definition at line 158 of file usb_drv.h.

Referenced by usb_init_device(), and usb_user_endpoint_init().

#define Usb_configure_endpoint_bank ( bank   )     (UECFG1X = (UECFG1X & ~MSK_EPBK) | ((uint8_t)bank << 2))

configures the current endpoint number of banks

Definition at line 538 of file usb_drv.h.

#define Usb_configure_endpoint_direction ( dir   )     (UECFG0X = (UECFG0X & ~(1<<EPDIR)) | ((uint8_t)dir))

configures the current endpoint direction

Definition at line 531 of file usb_drv.h.

#define Usb_configure_endpoint_size ( size   )     (UECFG1X = (UECFG1X & ~MSK_EPSIZE) | ((uint8_t)size << 4))

configures the current endpoint size

Definition at line 535 of file usb_drv.h.

#define Usb_configure_endpoint_type ( type   )     (UECFG0X = (UECFG0X & ~(MSK_EPTYPE)) | ((uint8_t)type << 6))

configures the current endpoint

Definition at line 528 of file usb_drv.h.

 
#define Usb_control_direction (  )     ((UESTA1X & (1<<CTRLDIR)) >> 2)

returns the control direction

Definition at line 577 of file usb_drv.h.

 
#define Usb_current_bank (  )     ( UESTA1X & MSK_CURRBK)

returns the number of the current bank

Definition at line 579 of file usb_drv.h.

 
#define Usb_data_toggle (  )     ((UESTA0X&MSK_DTSEQ) >> 2)

returns data toggle

Definition at line 556 of file usb_drv.h.

 
#define Usb_detach (  )     (UDCON |= (1<<DETACH))

detaches from USB bus

Definition at line 386 of file usb_drv.h.

 
#define Usb_device_initiate_hnp (  )     (OTGCON |= (1<<HNPREQ))

initiates a Host Negociation Protocol

Definition at line 269 of file usb_drv.h.

 
#define Usb_device_initiate_srp (  )     (OTGCON |= (1<<SRPREQ))

initiates a Session Request Protocol

Definition at line 278 of file usb_drv.h.

 
#define Usb_disable (  )     (USBCON &= ~((1<<USBE) | (1<<OTGPADE)))

Disable both USB interface and Vbus pad

Definition at line 202 of file usb_drv.h.

Referenced by usb_device_task_init().

 
#define Usb_disable_address (  )     (UDADDR &= ~(1<<ADDEN))

disables USB device address

Definition at line 486 of file usb_drv.h.

 
#define Usb_disable_bconnection_error_interrupt (  )     (OTGIEN &= ~(1<<BCERRE))

disables B device connection error interrupt

Definition at line 345 of file usb_drv.h.

 
#define Usb_disable_endpoint (  )     (UECONX &= ~(1<<EPEN))

disables the current endpoint

Definition at line 513 of file usb_drv.h.

 
#define Usb_disable_flow_error_interrupt (  )     (UEIENX &= ~(1<<FLERRE))

disables flow error interrupt

Definition at line 657 of file usb_drv.h.

 
#define Usb_disable_hnp_error_interrupt (  )     (OTGIEN &= ~(1<<HNPERRE))

disables HNP error interrupt

Definition at line 318 of file usb_drv.h.

 
#define Usb_disable_id_interrupt (  )     (USBCON &= ~(1<<IDTE))

Definition at line 221 of file usb_drv.h.

 
#define Usb_disable_in_ready_interrupt (  )     (UEIENX &= ~(1<<TXIN))

disables IN ready interrupt

Definition at line 675 of file usb_drv.h.

 
#define Usb_disable_nak_in_interrupt (  )     (UEIENX &= ~(1<<NAKINE))

disables NAK IN interrupt

Definition at line 660 of file usb_drv.h.

 
#define Usb_disable_nak_out_interrupt (  )     (UEIENX &= ~(1<<NAKOUTE))

disables NAK OUT interrupt

Definition at line 663 of file usb_drv.h.

 
#define Usb_disable_receive_out_interrupt (  )     (UEIENX &= ~(1<<RXOUTE))

disables receive OUT interrupt

Definition at line 669 of file usb_drv.h.

 
#define Usb_disable_receive_setup_interrupt (  )     (UEIENX &= ~(1<<RXSTPE))

disables receive SETUP interrupt

Definition at line 666 of file usb_drv.h.

 
#define Usb_disable_regulator (  )     (UHWCON &= ~(1<<UVREGE))

Disable internal USB pads regulator

Definition at line 168 of file usb_drv.h.

 
#define Usb_disable_remote_wake_up_interrupt (  )     (UDIEN &= ~(1<<UPRSME))

disables remote wake-up interrupt

Definition at line 407 of file usb_drv.h.

 
#define Usb_disable_reset_interrupt (  )     (UDIEN &= ~(1<<EORSTE))

disables USB reset interrupt

Definition at line 446 of file usb_drv.h.

 
#define Usb_disable_resume_interrupt (  )     (UDIEN &= ~(1<<EORSME))

disables resume interrupt

Definition at line 420 of file usb_drv.h.

Referenced by ISR().

 
#define Usb_disable_role_exchange_interrupt (  )     (OTGIEN &= ~(1<<ROLEEXE))

disables role exchange interrupt

Definition at line 332 of file usb_drv.h.

 
#define Usb_disable_sof_interrupt (  )     (UDIEN &= ~(1<<SOFE))

disables Start Of Frame Interrupt

Definition at line 459 of file usb_drv.h.

 
#define Usb_disable_srp_interrupt (  )     (OTGIEN &= ~(1<<SRPE))

disables SRP interrupt

Definition at line 371 of file usb_drv.h.

 
#define Usb_disable_stall_handshake (  )     (UECONX |= (1<<STALLRQC))

disables the STALL handshake

Definition at line 516 of file usb_drv.h.

Referenced by usb_clear_feature().

 
#define Usb_disable_stalled_interrupt (  )     (UEIENX &= ~(1<<STALLEDE))

disables STALL sent interrupt

Definition at line 672 of file usb_drv.h.

 
#define Usb_disable_suspend_interrupt (  )     (UDIEN &= ~(1<<SUSPE))

disables suspend state interrupt

Definition at line 473 of file usb_drv.h.

 
#define Usb_disable_suspend_time_out_interrupt (  )     (OTGIEN &= ~(1<<STOE))

disables suspend time out interrupt

Definition at line 305 of file usb_drv.h.

 
#define Usb_disable_uid_pin (  )     (UHWCON &= ~(1<<UIDE))

Disable external UID pin

Definition at line 178 of file usb_drv.h.

 
#define Usb_disable_uvcon_pin (  )     (UHWCON &= ~(1<<UVCONE))

Enable external UVCON pin

Definition at line 190 of file usb_drv.h.

 
#define Usb_disable_vbus (  )     (OTGCON |= (1<<VBUSRQC))

requests for VBus desactivation

Definition at line 263 of file usb_drv.h.

 
#define Usb_disable_vbus_error_interrupt (  )     (OTGIEN &= ~(1<<VBERRE))

disables VBus error interrupt

Definition at line 358 of file usb_drv.h.

 
#define Usb_disable_vbus_hw_control (  )     (OTGCON |= (1<<VBUSHWC))

disables hardware control on VBus

Definition at line 290 of file usb_drv.h.

 
#define Usb_disable_vbus_interrupt (  )     (USBCON &= ~(1<<VBUSTE))

Definition at line 228 of file usb_drv.h.

 
#define Usb_disable_vbus_pad (  )     (USBCON &= ~(1<<OTGPADE))

Disable VBUS pad

Definition at line 209 of file usb_drv.h.

 
#define Usb_disable_wake_up_interrupt (  )     (UDIEN &= ~(1<<WAKEUPE))

disables wake-up interrupt

Definition at line 433 of file usb_drv.h.

Referenced by ISR().

 
#define Usb_enable (  )     (USBCON |= ((1<<USBE) | (1<<OTGPADE)))

Enable both USB interface and Vbus pad

Definition at line 199 of file usb_drv.h.

Referenced by usb_device_task_init().

 
#define Usb_enable_address (  )     (UDADDR |= (1<<ADDEN))

enables USB device address

Definition at line 483 of file usb_drv.h.

Referenced by usb_set_address().

 
#define Usb_enable_bconnection_error_interrupt (  )     (OTGIEN |= (1<<BCERRE))

enables B device connection error interrupt

Definition at line 342 of file usb_drv.h.

 
#define Usb_enable_endpoint (  )     (UECONX |= (1<<EPEN))

enables the current endpoint

Definition at line 504 of file usb_drv.h.

Referenced by usb_config_ep().

 
#define Usb_enable_flow_error_interrupt (  )     (UEIENX |= (1<<FLERRE))

enables flow error interrupt

Definition at line 636 of file usb_drv.h.

 
#define Usb_enable_hnp_error_interrupt (  )     (OTGIEN |= (1<<HNPERRE))

enables HNP error interrupt

Definition at line 315 of file usb_drv.h.

 
#define Usb_enable_id_interrupt (  )     (USBCON |= (1<<IDTE))

Definition at line 220 of file usb_drv.h.

 
#define Usb_enable_in_ready_interrupt (  )     (UEIENX |= (1<<TXIN))

enables IN ready interrupt

Definition at line 654 of file usb_drv.h.

 
#define Usb_enable_manual_vbus (  )     (PORTE|=0x80,DDRE|=0x80,Usb_disable_uvcon_pin())

Manually request VBUS without UVCON signal from USB interface

Definition at line 266 of file usb_drv.h.

 
#define Usb_enable_nak_in_interrupt (  )     (UEIENX |= (1<<NAKINE))

enables NAK IN interrupt

Definition at line 639 of file usb_drv.h.

 
#define Usb_enable_nak_out_interrupt (  )     (UEIENX |= (1<<NAKOUTE))

enables NAK OUT interrupt

Definition at line 642 of file usb_drv.h.

 
#define Usb_enable_receive_out_interrupt (  )     (UEIENX |= (1<<RXOUTE))

enables receive OUT interrupt

Definition at line 648 of file usb_drv.h.

 
#define Usb_enable_receive_setup_interrupt (  )     (UEIENX |= (1<<RXSTPE))

enables receive SETUP interrupt

Definition at line 645 of file usb_drv.h.

 
#define Usb_enable_regulator (  )     (UHWCON |= (1<<UVREGE))

Enable internal USB pads regulator

Definition at line 165 of file usb_drv.h.

 
#define Usb_enable_remote_wake_up_interrupt (  )     (UDIEN |= (1<<UPRSME))

enables remote wake-up interrupt

Definition at line 404 of file usb_drv.h.

 
#define Usb_enable_reset_interrupt (  )     (UDIEN |= (1<<EORSTE))

enables USB reset interrupt

Definition at line 443 of file usb_drv.h.

Referenced by ISR(), usb_device_task(), and usb_start_device().

 
#define Usb_enable_resume_interrupt (  )     (UDIEN |= (1<<EORSME))

enables resume interrupt

Definition at line 417 of file usb_drv.h.

 
#define Usb_enable_role_exchange_interrupt (  )     (OTGIEN |= (1<<ROLEEXE))

enables role exchange interrupt

Definition at line 329 of file usb_drv.h.

 
#define Usb_enable_sof_interrupt (  )     (UDIEN |= (1<<SOFE))

enables Start Of Frame Interrupt

Definition at line 456 of file usb_drv.h.

Referenced by cdc_task_init().

 
#define Usb_enable_srp_interrupt (  )     (OTGIEN |= (1<<SRPE))

enables SRP interrupt

Definition at line 368 of file usb_drv.h.

 
#define Usb_enable_stall_handshake (  )     (UECONX |= (1<<STALLRQ))

enables the STALL handshake for the next transaction

Definition at line 507 of file usb_drv.h.

Referenced by usb_clear_feature(), usb_get_descriptor(), usb_get_interface(), usb_get_status(), usb_halt_endpoint(), usb_process_request(), usb_set_configuration(), and usb_set_feature().

 
#define Usb_enable_stalled_interrupt (  )     (UEIENX |= (1<<STALLEDE))

enables STALL sent interrupt

Definition at line 651 of file usb_drv.h.

 
#define Usb_enable_suspend_interrupt (  )     (UDIEN |= (1<<SUSPE))

enables suspend state interrupt

Definition at line 470 of file usb_drv.h.

Referenced by usb_start_device().

 
#define Usb_enable_suspend_time_out_interrupt (  )     (OTGIEN |= (1<<STOE))

enables suspend time out interrupt

Definition at line 302 of file usb_drv.h.

 
#define Usb_enable_uid_pin (  )     (UHWCON |= (1<<UIDE))

Enable external UID pin

Definition at line 175 of file usb_drv.h.

 
#define Usb_enable_uvcon_pin (  )     (UHWCON |= (1<<UVCONE))

Enable external UVCON pin

Definition at line 187 of file usb_drv.h.

 
#define Usb_enable_vbus (  )     (OTGCON |= (1<<VBUSREQ))

requests for VBus activation

Definition at line 260 of file usb_drv.h.

 
#define Usb_enable_vbus_error_interrupt (  )     (OTGIEN |= (1<<VBERRE))

enables VBus error interrupt

Definition at line 355 of file usb_drv.h.

 
#define Usb_enable_vbus_hw_control (  )     (OTGCON &= ~(1<<VBUSHWC))

enables hardware control on VBus

Definition at line 287 of file usb_drv.h.

 
#define Usb_enable_vbus_interrupt (  )     (USBCON |= (1<<VBUSTE))

Definition at line 227 of file usb_drv.h.

Referenced by usb_device_task_init().

 
#define Usb_enable_vbus_pad (  )     (USBCON |= (1<<OTGPADE))

Enable VBUS pad

Definition at line 206 of file usb_drv.h.

 
#define Usb_enable_wake_up_interrupt (  )     (UDIEN |= (1<<WAKEUPE))

enables wake-up interrupt

Definition at line 430 of file usb_drv.h.

Referenced by ISR().

 
#define Usb_enter_dpram_mode (  )     (UDPADDH = (1<<DPACC))

Definition at line 253 of file usb_drv.h.

 
#define Usb_exit_dpram_mode (  )     (UDPADDH = (uint8_t)~(1<<DPACC))

Definition at line 254 of file usb_drv.h.

 
#define Usb_force_device_mode (  )     (Usb_disable_uid_pin(), UHWCON |= (1<<UIMOD))

Disable external UID pin and force device mode

Definition at line 181 of file usb_drv.h.

Referenced by usb_task_init().

 
#define Usb_force_host_mode (  )     (Usb_disable_uid_pin(), UHWCON &= ~(1<<UIMOD))

Disable external UID pin and force host mode

Definition at line 184 of file usb_drv.h.

 
#define Usb_frame_number (  )     ((uint16_t)((((uint16_t)UDFNUMH) << 8) | ((uint16_t)UDFNUML)))

returns the last frame number

Definition at line 492 of file usb_drv.h.

 
#define Usb_free_out_bank (  )     (UEINTX &= ~(1<<FIFOCON))

frees OUT bank

Definition at line 630 of file usb_drv.h.

 
#define Usb_freeze_clock (  )     (USBCON |= (1<<FRZCLK))

Stop internal USB clock in interface (freeze the interface register)

Definition at line 216 of file usb_drv.h.

Referenced by ISR().

 
#define Usb_full_speed_mode (  )     (UHWCON |= (1<<UDSS))

Use device full speed mode (default mode)

Definition at line 193 of file usb_drv.h.

 
#define Usb_get_device_interrupt (  )     (UDINT & (1<<UDIEN))

returns the USB device interrupts (interrupt enabled)

Definition at line 398 of file usb_drv.h.

 
#define Usb_get_general_interrupt (  )     (USBINT & (USBCON & MSK_IDTE_VBUSTE))

returns the USB general interrupts (interrupt enabled)

Definition at line 236 of file usb_drv.h.

 
#define Usb_get_otg_interrupt (  )     (OTGINT & OTGIEN)

returns the USB Pad interrupts (interrupt enabled)

Definition at line 246 of file usb_drv.h.

 
#define Usb_host_accept_hnp (  )     (OTGCON |= (1<<HNPREQ))

accepts a Host Negociation Protocol

Definition at line 272 of file usb_drv.h.

 
#define Usb_host_reject_hnp (  )     (OTGCON &= ~(1<<HNPREQ))

rejects a Host Negociation Protocol

Definition at line 275 of file usb_drv.h.

 
#define Usb_initiate_remote_wake_up (  )     (UDCON |= (1<<RMWKUP))

initiates a remote wake-up

Definition at line 383 of file usb_drv.h.

 
#define Usb_interrupt_flags (  )     (UEINT != 0x00)

tests the general endpoint interrupt flags

Definition at line 690 of file usb_drv.h.

Referenced by usb_select_enpoint_interrupt().

 
#define Usb_kill_last_in_bank (  )     (UENTTX |= (1<<RXOUTI))

Kills last bank

Definition at line 603 of file usb_drv.h.

 
#define Usb_low_speed_mode (  )     (UHWCON &= ~(1<<UDSS))

For device mode, force low speed mode

Definition at line 196 of file usb_drv.h.

 
#define Usb_nb_busy_bank (  )     (UESTA0X & MSK_NBUSYBK)

returns the number of busy banks

Definition at line 559 of file usb_drv.h.

 
#define Usb_read_byte (  )     (UEDATX)

 
#define Usb_read_dpram_byte (  )     (UEDATX)

Definition at line 257 of file usb_drv.h.

 
#define Usb_reset_data_toggle (  )     (UECONX |= (1<<RSTDT))

resets the data toggle sequence

Definition at line 510 of file usb_drv.h.

Referenced by usb_clear_feature().

#define Usb_reset_endpoint ( ep   )     (UERST = 1 << (uint8_t)ep, UERST = 0)

resets the selected endpoint

Definition at line 501 of file usb_drv.h.

Referenced by usb_clear_feature(), usb_device_task(), and usb_user_endpoint_init().

 
#define Usb_select_data_srp_method (  )     (OTGCON &= ~(1<<SRPSEL))

selects data line as SRP method

Definition at line 284 of file usb_drv.h.

 
#define Usb_select_device (  )     (USBCON &= ~(1<<HOST))

Definition at line 211 of file usb_drv.h.

Referenced by usb_device_task_init(), and usb_init_device().

#define Usb_select_endpoint ( ep   )     (UENUM = (uint8_t)ep )

#define Usb_select_ep_for_cpu ( ep   )     (Usb_select_epnum_for_cpu(), Usb_select_endpoint(ep))

Definition at line 696 of file usb_drv.h.

 
#define Usb_select_epnum_for_cpu (  )     (UECONX &= ~(1<<EPNUMS))

selects endpoint interface on CPU

Definition at line 519 of file usb_drv.h.

 
#define Usb_select_host (  )     (USBCON |= (1<<HOST))

Definition at line 212 of file usb_drv.h.

 
#define Usb_select_vbus_srp_method (  )     (OTGCON |= (1<<SRPSEL))

selects VBus as SRP method

Definition at line 281 of file usb_drv.h.

 
#define Usb_send_control_in (  )     (UEINTX &= ~(1<<TXINI))

 
#define Usb_send_in (  )     (UEINTX &= ~(1<<FIFOCON))

sends IN

Definition at line 624 of file usb_drv.h.

Referenced by uart_usb_flush().

#define Usb_set_dpram_address ( addr   )     (UDPADDH = (1<<DPACC) + ((Uint16)addr >> 8), UDPADDL = (uint8_t)addr)

Definition at line 255 of file usb_drv.h.

 
#define Usb_unallocate_memory (  )     (UECFG1X &= ~(1<<ALLOC))

un-allocates the current configuration in DPRAM memory

Definition at line 544 of file usb_drv.h.

 
#define Usb_unfreeze_clock (  )     (USBCON &= ~(1<<FRZCLK))

Definition at line 217 of file usb_drv.h.

Referenced by ISR(), and usb_start_device().

#define Usb_write_byte ( byte   )     (UEDATX = (uint8_t)byte)

writes byte in FIFO for current endpoint

Definition at line 681 of file usb_drv.h.

Referenced by cdc_get_line_coding(), uart_usb_putchar(), usb_get_configuration(), usb_get_descriptor(), usb_get_status(), and usb_send_packet().

#define Usb_write_dpram_byte ( val   )     (UEDATX=val)

Definition at line 256 of file usb_drv.h.

#define Usb_write_word_enum_struc (  )     (x)

This macro help to fill the uint16_t fill in USB enumeration struct.

Definition at line 700 of file usb_drv.h.


Typedef Documentation

typedef enum ep_bank e_ep_bank

typedef enum ep_dir e_ep_dir

typedef enum ep_nyet e_ep_nyet

typedef enum ep_size e_ep_size

typedef enum ep_token e_ep_token

typedef enum ep_type e_ep_type


Enumeration Type Documentation

enum ep_bank

Enumerator:
ONE_BANK 
TWO_BANKS 

Definition at line 136 of file usb_drv.h.

00136                     {
00137         ONE_BANK            = 0x00,
00138         TWO_BANKS           = 0x01
00139 }e_ep_bank;

enum ep_dir

Enumerator:
DIRECTION_OUT 
DIRECTION_IN 

Definition at line 120 of file usb_drv.h.

00120                    {
00121         DIRECTION_OUT       = 0x00,
00122         DIRECTION_IN        = 0x01
00123 }e_ep_dir;

enum ep_nyet

Enumerator:
NYET_DISABLED 
NYET_ENABLED 

Definition at line 141 of file usb_drv.h.

00141                     {
00142         NYET_DISABLED       = 0x00,
00143         NYET_ENABLED        = 0x01
00144 }e_ep_nyet;

enum ep_size

Enumerator:
SIZE_8 
SIZE_16 
SIZE_32 
SIZE_64 
SIZE_128 
SIZE_256 
SIZE_512 
SIZE_1024 

Definition at line 125 of file usb_drv.h.

00125                     {
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;

enum ep_token

Enumerator:
TOKEN_SETUP 
TOKEN_IN 
TOKEN_OUT 

Definition at line 146 of file usb_drv.h.

00146                      {
00147         TOKEN_SETUP         = 0x00,
00148         TOKEN_IN            = 0x01,
00149         TOKEN_OUT           = 0x02
00150 }e_ep_token;

enum ep_type

Enumerator:
TYPE_CONTROL 
TYPE_ISOCHRONOUS 
TYPE_BULK 
TYPE_INTERRUPT 

Definition at line 113 of file usb_drv.h.

00113                     {
00114         TYPE_CONTROL        = 0x00,
00115         TYPE_ISOCHRONOUS    = 0x01,
00116         TYPE_BULK           = 0x02,
00117         TYPE_INTERRUPT      = 0x03
00118 }e_ep_type;


Function Documentation

uint8_t usb_config_ep ( uint8_t  config0,
uint8_t  config1 
)

This function configures an endpoint with the selected type.

Parameters:
config0 
config1 
Return values:
Is_endpoint_configured. 

Definition at line 59 of file usb_drv.c.

References Is_endpoint_configured, Usb_allocate_memory, and Usb_enable_endpoint.

00060 {
00061         Usb_enable_endpoint();
00062         UECFG0X = config0;
00063         UECFG1X = (UECFG1X & (1<<ALLOC)) | config1;
00064         Usb_allocate_memory();
00065         return (Is_endpoint_configured());
00066 }

uint16_t usb_get_nb_byte_epw ( void   ) 

void usb_halt_endpoint ( uint8_t  ep_num  ) 

This function sends a STALL handshake for the next Host request. A STALL handshake will be send for each next request untill a SETUP or a Clear Halt Feature occurs for this endpoint.

Parameters:
ep_num number of the addressed endpoint

Definition at line 153 of file usb_drv.c.

References Usb_enable_stall_handshake, and Usb_select_endpoint.

00154 {
00155         Usb_select_endpoint(ep_num);
00156         Usb_enable_stall_handshake();
00157 }

uint8_t usb_init_device ( void   ) 

This function initializes the USB device controller and configures the Default Control Endpoint.

Return values:
status 

Definition at line 165 of file usb_drv.c.

References DIRECTION_OUT, EP_CONTROL, Is_usb_endpoint_enabled, Is_usb_id_device, NYET_DISABLED, ONE_BANK, SIZE_64, TYPE_CONTROL, usb_configure_endpoint, Usb_select_device, and Usb_select_endpoint.

Referenced by ISR(), and usb_start_device().

00166 {
00167         Usb_select_device();
00168         if(Is_usb_id_device())
00169         {
00170                 Usb_select_endpoint(EP_CONTROL);
00171                 if(!Is_usb_endpoint_enabled())
00172                 {
00173                         return usb_configure_endpoint(EP_CONTROL,    \
00174                                                       TYPE_CONTROL,  \
00175                                                       DIRECTION_OUT, \
00176                                                       SIZE_64,       \
00177                                                       ONE_BANK,      \
00178                                                       NYET_DISABLED);
00179                 }
00180         }
00181         return false;
00182 }

uint8_t usb_read_packet ( uint8_t  ep_num,
uint8_t *  rbuf,
uint8_t  data_length 
)

This function moves the data stored in the selected endpoint fifo to the address specified by *rbuf.

Note:
rbuf is incremented of 'data_length'.
Parameters:
ep_num number of the addressed endpoint
rbuf aaddress of the first data to write with the USB data
data_length number of bytes to read
Return values:
address of the next uint8_t to send.

Definition at line 131 of file usb_drv.c.

References Is_usb_read_enabled, Usb_read_byte, and Usb_select_endpoint.

00132 {
00133         uint8_t remaining_length;
00134         
00135         remaining_length = data_length;
00136         Usb_select_endpoint(ep_num);
00137         
00138         while(Is_usb_read_enabled() && (0 != remaining_length)){
00139                 *rbuf = Usb_read_byte();
00140                 remaining_length--;
00141                 rbuf++;
00142         }
00143         return remaining_length;
00144 }

void usb_reset_endpoint ( uint8_t   ) 

uint8_t usb_select_enpoint_interrupt ( void   ) 

This function select the endpoint where an event occurs and returns the number of this endpoint. If no event occurs on the endpoints, this function returns 0.

Return values:
endpoint number.

Definition at line 75 of file usb_drv.c.

References Usb_interrupt_flags.

00076 {
00077         uint8_t interrupt_flags;
00078         uint8_t ep_num;
00079         
00080         ep_num = 0;
00081         interrupt_flags = Usb_interrupt_flags();
00082         
00083         while(ep_num < 9){
00084                 if (interrupt_flags & 1){
00085                         return (ep_num);
00086                 }else{
00087                         ep_num++;
00088                         interrupt_flags = interrupt_flags >> 1;
00089                 }
00090         }
00091         return 0;
00092 }

uint8_t usb_send_packet ( uint8_t  ep_num,
uint8_t *  tbuf,
uint8_t  data_length 
)

This function moves the data pointed by tbuf to the selected endpoint fifo and sends it through the USB.

Note:
tbuf is incremented of 'data_length'.
Parameters:
ep_num number of the addressed endpoint
*tbuf address of the first data to send
data_length number of bytes to send
Return values:
address of the next byte to send.

Definition at line 106 of file usb_drv.c.

References Is_usb_write_enabled, Usb_select_endpoint, and Usb_write_byte.

00107 {
00108         uint8_t remaining_length;
00109         
00110         remaining_length = data_length;
00111         Usb_select_endpoint(ep_num);
00112         while(Is_usb_write_enabled() && (0 != remaining_length)){
00113                 Usb_write_byte(*tbuf);
00114                 remaining_length--;
00115                 tbuf++;
00116         }
00117         return remaining_length;
00118 }

@DOC_TITLE@
Generated on Mon Jan 18 09:26:13 2010 for AVR1907 Xplain USB Gateway by doxygen 1.5.5