Contiki 2.6

usb_drv.h File Reference

This file contains the USB driver routines. More...

#include "compiler.h"

Go to the source code of this file.

Defines

#define Usb_enable_regulator()   (UHWCON |= (1<<UVREGE))
 Enable internal USB pads regulator.
#define Usb_disable_regulator()   (UHWCON &= ~(1<<UVREGE))
 Disable internal USB pads regulator.
#define Is_usb_regulator_enabled()   ((UHWCON & (1<<UVREGE)) ? TRUE : FALSE)
 Check regulator enable bit.
#define Usb_enable_uid_pin()   (UHWCON |= (1<<UIDE))
 Enable external UID pin.
#define Usb_disable_uid_pin()   (UHWCON &= ~(1<<UIDE))
 Disable external UID pin.
#define Usb_force_device_mode()   (Usb_disable_uid_pin(), UHWCON |= (1<<UIMOD))
 Disable external UID pin and force device mode.
#define Usb_force_host_mode()   (Usb_disable_uid_pin(), UHWCON &= ~(1<<UIMOD))
 Disable external UID pin and force host mode.
#define Usb_enable_uvcon_pin()   (UHWCON |= (1<<UVCONE))
 Enable external UVCON pin.
#define Usb_disable_uvcon_pin()   (UHWCON &= ~(1<<UVCONE))
 Enable external UVCON pin.
#define Usb_full_speed_mode()   (UDCON &= ~(1<<LSM))
 Use device full speed mode (default mode)
#define Usb_low_speed_mode()   (UDCON |= (1<<LSM))
 For device mode, force low speed mode.
#define Usb_enable()   (USBCON |= ((1<<USBE) | (1<<OTGPADE)))
 Enable both USB interface and Vbus pad.
#define Usb_disable()   (USBCON &= ~((1<<USBE) | (1<<OTGPADE)))
 Disable both USB interface and Vbus pad.
#define Usb_enable_vbus_pad()   (USBCON |= (1<<OTGPADE))
 Enable VBUS pad.
#define Usb_disable_vbus_pad()   (USBCON &= ~(1<<OTGPADE))
 Disable VBUS pad.
#define Usb_freeze_clock()   (USBCON |= (1<<FRZCLK))
 Stop internal USB clock in interface (freeze the interface register)
#define Usb_get_general_interrupt()   (USBINT & (USBCON & MSK_IDTE_VBUSTE))
 returns the USB general interrupts (interrupt enabled)
#define Usb_ack_all_general_interrupt()   (USBINT = ~(USBCON & MSK_IDTE_VBUSTE))
 acks the general interrupts (interrupt enabled)
#define Usb_get_otg_interrupt()   (OTGINT & OTGIEN)
 returns the USB Pad interrupts (interrupt enabled)
#define Usb_ack_all_otg_interrupt()   (OTGINT = ~OTGIEN)
 acks the USB Pad interrupts (interrupt enabled)
#define Usb_enable_vbus()   (OTGCON |= (1<<VBUSREQ))
 requests for VBus activation
#define Usb_disable_vbus()   (OTGCON |= (1<<VBUSRQC))
 requests for VBus desactivation
#define Usb_enable_manual_vbus()   (PORTE|=0x80,DDRE|=0x80,Usb_disable_uvcon_pin())
 Manually request VBUS without UVCON signal from USB interface.
#define Usb_device_initiate_hnp()   (OTGCON |= (1<<HNPREQ))
 initiates a Host Negociation Protocol
#define Usb_host_accept_hnp()   (OTGCON |= (1<<HNPREQ))
 accepts a Host Negociation Protocol
#define Usb_host_reject_hnp()   (OTGCON &= ~(1<<HNPREQ))
 rejects a Host Negociation Protocol
#define Usb_device_initiate_srp()   (OTGCON |= (1<<SRPREQ))
 initiates a Session Request Protocol
#define Usb_select_vbus_srp_method()   (OTGCON |= (1<<SRPSEL))
 selects VBus as SRP method
#define Usb_select_data_srp_method()   (OTGCON &= ~(1<<SRPSEL))
 selects data line as SRP method
#define Usb_enable_vbus_hw_control()   (OTGCON &= ~(1<<VBUSHWC))
 enables hardware control on VBus
#define Usb_disable_vbus_hw_control()   (OTGCON |= (1<<VBUSHWC))
 disables hardware control on VBus
#define Is_usb_vbus_enabled()   ((OTGCON & (1<<VBUSREQ)) ? TRUE : FALSE)
 tests if VBus has been requested
#define Is_usb_hnp()   ((OTGCON & (1<<HNPREQ)) ? TRUE : FALSE)
 tests if a HNP occurs
#define Is_usb_device_srp()   ((OTGCON & (1<<SRPREQ)) ? TRUE : FALSE)
 tests if a SRP from device occurs
#define Usb_enable_suspend_time_out_interrupt()   (OTGIEN |= (1<<STOE))
 enables suspend time out interrupt
#define Usb_disable_suspend_time_out_interrupt()   (OTGIEN &= ~(1<<STOE))
 disables suspend time out interrupt
#define Usb_ack_suspend_time_out_interrupt()   (OTGINT &= ~(1<<STOI))
 acks suspend time out interrupt
#define Is_usb_suspend_time_out_interrupt()   ((OTGINT & (1<<STOI)) ? TRUE : FALSE)
 tests if a suspend time out occurs
#define Usb_enable_hnp_error_interrupt()   (OTGIEN |= (1<<HNPERRE))
 enables HNP error interrupt
#define Usb_disable_hnp_error_interrupt()   (OTGIEN &= ~(1<<HNPERRE))
 disables HNP error interrupt
#define Usb_ack_hnp_error_interrupt()   (OTGINT &= ~(1<<HNPERRI))
 acks HNP error interrupt
#define Is_usb_hnp_error_interrupt()   ((OTGINT & (1<<HNPERRI)) ? TRUE : FALSE)
 tests if a HNP error occurs
#define Usb_enable_role_exchange_interrupt()   (OTGIEN |= (1<<ROLEEXE))
 enables role exchange interrupt
#define Usb_disable_role_exchange_interrupt()   (OTGIEN &= ~(1<<ROLEEXE))
 disables role exchange interrupt
#define Usb_ack_role_exchange_interrupt()   (OTGINT &= ~(1<<ROLEEXI))
 acks role exchange interrupt
#define Is_usb_role_exchange_interrupt()   ((OTGINT & (1<<ROLEEXI)) ? TRUE : FALSE)
 tests if a role exchange occurs
#define Usb_enable_bconnection_error_interrupt()   (OTGIEN |= (1<<BCERRE))
 enables B device connection error interrupt
#define Usb_disable_bconnection_error_interrupt()   (OTGIEN &= ~(1<<BCERRE))
 disables B device connection error interrupt
#define Usb_ack_bconnection_error_interrupt()   (OTGINT &= ~(1<<BCERRI))
 acks B device connection error interrupt
#define Is_usb_bconnection_error_interrupt()   ((OTGINT & (1<<BCERRI)) ? TRUE : FALSE)
 tests if a B device connection error occurs
#define Usb_enable_vbus_error_interrupt()   (OTGIEN |= (1<<VBERRE))
 enables VBus error interrupt
#define Usb_disable_vbus_error_interrupt()   (OTGIEN &= ~(1<<VBERRE))
 disables VBus error interrupt
#define Usb_ack_vbus_error_interrupt()   (OTGINT &= ~(1<<VBERRI))
 acks VBus error interrupt
#define Is_usb_vbus_error_interrupt()   ((OTGINT & (1<<VBERRI)) ? TRUE : FALSE)
 tests if a VBus error occurs
#define Usb_enable_srp_interrupt()   (OTGIEN |= (1<<SRPE))
 enables SRP interrupt
#define Usb_disable_srp_interrupt()   (OTGIEN &= ~(1<<SRPE))
 disables SRP interrupt
#define Usb_ack_srp_interrupt()   (OTGINT &= ~(1<<SRPI))
 acks SRP interrupt
#define Is_usb_srp_interrupt()   ((OTGINT & (1<<SRPI)) ? TRUE : FALSE)
 tests if a SRP occurs
#define Usb_initiate_remote_wake_up()   (UDCON |= (1<<RMWKUP))
 initiates a remote wake-up
#define Usb_detach()   (UDCON |= (1<<DETACH))
 detaches from USB bus
#define Usb_attach()   (UDCON &= ~(1<<DETACH))
 attaches to USB bus
#define Is_usb_pending_remote_wake_up()   ((UDCON & (1<<RMWKUP)) ? TRUE : FALSE)
 test if remote wake-up still running
#define Is_usb_detached()   ((UDCON & (1<<DETACH)) ? TRUE : FALSE)
 test if the device is detached
#define Usb_get_device_interrupt()   (UDINT & (1<<UDIEN))
 returns the USB device interrupts (interrupt enabled)
#define Usb_ack_all_device_interrupt()   (UDINT = ~(1<<UDIEN))
 acks the USB device interrupts (interrupt enabled)
#define Usb_enable_remote_wake_up_interrupt()   (UDIEN |= (1<<UPRSME))
 enables remote wake-up interrupt
#define Usb_disable_remote_wake_up_interrupt()   (UDIEN &= ~(1<<UPRSME))
 disables remote wake-up interrupt
#define Usb_ack_remote_wake_up_start()   (UDINT = ~(1<<UPRSMI))
 acks remote wake-up
#define Is_usb_remote_wake_up_start()   ((UDINT & (1<<UPRSMI)) ? TRUE : FALSE)
 tests if remote wake-up still running
#define Usb_enable_resume_interrupt()   (UDIEN |= (1<<EORSME))
 enables resume interrupt
#define Usb_disable_resume_interrupt()   (UDIEN &= ~(1<<EORSME))
 disables resume interrupt
#define Usb_ack_resume()   (UDINT = ~(1<<EORSMI))
 acks resume
#define Is_usb_resume()   ((UDINT & (1<<EORSMI)) ? TRUE : FALSE)
 tests if resume occurs
#define Usb_enable_wake_up_interrupt()   (UDIEN |= (1<<WAKEUPE))
 enables wake-up interrupt
#define Usb_disable_wake_up_interrupt()   (UDIEN &= ~(1<<WAKEUPE))
 disables wake-up interrupt
#define Usb_ack_wake_up()   (UDINT = ~(1<<WAKEUPI))
 acks wake-up
#define Is_usb_wake_up()   ((UDINT & (1<<WAKEUPI)) ? TRUE : FALSE)
 tests if wake-up occurs
#define Usb_enable_reset_interrupt()   (UDIEN |= (1<<EORSTE))
 enables USB reset interrupt
#define Usb_disable_reset_interrupt()   (UDIEN &= ~(1<<EORSTE))
 disables USB reset interrupt
#define Usb_ack_reset()   (UDINT = ~(1<<EORSTI))
 acks USB reset
#define Is_usb_reset()   ((UDINT & (1<<EORSTI)) ? TRUE : FALSE)
 tests if USB reset occurs
#define Usb_enable_sof_interrupt()   (UDIEN |= (1<<SOFE))
 enables Start Of Frame Interrupt
#define Usb_disable_sof_interrupt()   (UDIEN &= ~(1<<SOFE))
 disables Start Of Frame Interrupt
#define Usb_ack_sof()   (UDINT = ~(1<<SOFI))
 acks Start Of Frame
#define Is_usb_sof()   ((UDINT & (1<<SOFI)) ? TRUE : FALSE)
 tests if Start Of Frame occurs
#define Usb_enable_suspend_interrupt()   (UDIEN |= (1<<SUSPE))
 enables suspend state interrupt
#define Usb_disable_suspend_interrupt()   (UDIEN &= ~(1<<SUSPE))
 disables suspend state interrupt
#define Usb_ack_suspend()   (UDINT = ~(1<<SUSPI))
 acks Suspend
#define Is_usb_suspend()   ((UDINT & (1<<SUSPI)) ? TRUE : FALSE)
 tests if Suspend state detected
#define Usb_enable_address()   (UDADDR |= (1<<ADDEN))
 enables USB device address
#define Usb_disable_address()   (UDADDR &= ~(1<<ADDEN))
 disables USB device address
#define Usb_configure_address(addr)   (UDADDR = (UDADDR & (1<<ADDEN)) | ((U8)addr & MSK_UADD))
 sets the USB device address
#define Usb_frame_number()   ((U16)((((U16)UDFNUMH) << 8) | ((U16)UDFNUML)))
 returns the last frame number
#define Is_usb_frame_number_crc_error()   ((UDMFN & (1<<FNCERR)) ? TRUE : FALSE)
 tests if a crc error occurs in frame number
#define Usb_select_endpoint(ep)   (UENUM = (U8)ep )
 selects the endpoint number to interface with the CPU
#define Usb_get_selected_endpoint()   (UENUM )
 get the currently selected endpoint number
#define Usb_reset_endpoint(ep)   (UERST = 1 << (U8)ep, UERST = 0)
 resets the selected endpoint
#define Usb_enable_endpoint()   (UECONX |= (1<<EPEN))
 enables the current endpoint
#define Usb_enable_stall_handshake()   (UECONX |= (1<<STALLRQ))
 enables the STALL handshake for the next transaction
#define Usb_reset_data_toggle()   (UECONX |= (1<<RSTDT))
 resets the data toggle sequence
#define Usb_disable_endpoint()   (UECONX &= ~(1<<EPEN))
 disables the current endpoint
#define Usb_disable_stall_handshake()   (UECONX |= (1<<STALLRQC))
 disables the STALL handshake
#define Usb_select_epnum_for_cpu()   (UECONX &= ~(1<<EPNUMS))
 selects endpoint interface on CPU
#define Is_usb_endpoint_enabled()   ((UECONX & (1<<EPEN)) ? TRUE : FALSE)
 tests if the current endpoint is enabled
#define Is_usb_endpoint_stall_requested()   ((UECONX & (1<<STALLRQ)) ? TRUE : FALSE)
 tests if STALL handshake request is running
#define Usb_configure_endpoint_type(type)   (UECFG0X = (UECFG0X & ~(MSK_EPTYPE)) | ((U8)type << 6))
 configures the current endpoint
#define Usb_configure_endpoint_direction(dir)   (UECFG0X = (UECFG0X & ~(1<<EPDIR)) | ((U8)dir))
 configures the current endpoint direction
#define Usb_configure_endpoint_size(size)   (UECFG1X = (UECFG1X & ~MSK_EPSIZE) | ((U8)size << 4))
 configures the current endpoint size
#define Usb_configure_endpoint_bank(bank)   (UECFG1X = (UECFG1X & ~MSK_EPBK) | ((U8)bank << 2))
 configures the current endpoint number of banks
#define Usb_allocate_memory()   (UECFG1X |= (1<<ALLOC))
 allocates the current configuration in DPRAM memory
#define Usb_unallocate_memory()   (UECFG1X &= ~(1<<ALLOC))
 un-allocates the current configuration in DPRAM memory
#define Usb_ack_overflow_interrupt()   (UESTA0X &= ~(1<<OVERFI))
 acks endpoint overflow interrupt
#define Usb_ack_underflow_interrupt()   (UESTA0X &= ~(1<<UNDERFI))
 acks endpoint underflow memory
#define Usb_ack_zlp()   (UESTA0X &= ~(1<<ZLPSEEN))
 acks Zero Length Packet received
#define Usb_data_toggle()   ((UESTA0X&MSK_DTSEQ) >> 2)
 returns data toggle
#define Usb_nb_busy_bank()   (UESTA0X & MSK_NBUSYBK)
 returns the number of busy banks
#define Is_usb_one_bank_busy()   ((UESTA0X & MSK_NBUSYBK) == 0 ? FALSE : TRUE)
 tests if at least one bank is busy
#define Is_endpoint_configured()   ((UESTA0X & (1<<CFGOK)) ? TRUE : FALSE)
 tests if current endpoint is configured
#define Is_usb_overflow()   ((UESTA0X & (1<<OVERFI)) ? TRUE : FALSE)
 tests if an overflows occurs
#define Is_usb_underflow()   ((UESTA0X & (1<<UNDERFI)) ? TRUE : FALSE)
 tests if an underflow occurs
#define Is_usb_zlp()   ((UESTA0X & (1<<ZLPSEEN)) ? TRUE : FALSE)
 tests if a ZLP has been detected
#define Usb_control_direction()   ((UESTA1X & (1<<CTRLDIR)) >> 2)
 returns the control direction
#define Usb_current_bank()   ( UESTA1X & MSK_CURRBK)
 returns the number of the current bank
#define Usb_ack_fifocon()   (UEINTX &= ~(1<<FIFOCON))
 clears FIFOCON bit
#define Usb_ack_nak_in()   (UEINTX &= ~(1<<NAKINI))
 acks NAK IN received
#define Usb_ack_nak_out()   (UEINTX &= ~(1<<NAKOUTI))
 acks NAK OUT received
#define Usb_ack_receive_setup()   (UEINTX &= ~(1<<RXSTPI))
 acks receive SETUP
#define Is_usb_receive_nak_in()   (UEINTX &(1<<NAKINI))
 tests if NAK IN received
#define Is_usb_receive_nak_out()   (UEINTX &(1<<NAKOUTI))
 tests if NAK OUT received
#define Usb_ack_receive_out()   (UEINTX &= ~(1<<RXOUTI), Usb_ack_fifocon())
 acks reveive OUT
#define Usb_ack_stalled()   (MSK_STALLEDI= 0)
 acks STALL sent
#define Usb_ack_in_ready()   (UEINTX &= ~(1<<TXINI), Usb_ack_fifocon())
 acks IN ready
#define Usb_kill_last_in_bank()   (UENTTX |= (1<<RXOUTI))
 Kills last bank.
#define Is_usb_read_enabled()   (UEINTX&(1<<RWAL))
 tests if endpoint read allowed
#define Is_usb_write_enabled()   (UEINTX&(1<<RWAL))
 tests if endpoint write allowed
#define Is_usb_read_control_enabled()   (UEINTX&(1<<TXINI))
 tests if read allowed on control endpoint
#define Is_usb_receive_setup()   (UEINTX&(1<<RXSTPI))
 tests if SETUP received
#define Is_usb_receive_out()   (UEINTX&(1<<RXOUTI))
 tests if OUT received
#define Is_usb_in_ready()   (UEINTX&(1<<TXINI))
 tests if IN ready
#define Usb_send_in()   (UEINTX &= ~(1<<FIFOCON))
 sends IN
#define Usb_send_control_in()   (UEINTX &= ~(1<<TXINI))
 sends IN on control endpoint
#define Usb_free_out_bank()   (UEINTX &= ~(1<<FIFOCON))
 frees OUT bank
#define Usb_ack_control_out()   (UEINTX &= ~(1<<RXOUTI))
 acks OUT on control endpoint
#define Usb_enable_flow_error_interrupt()   (UEIENX |= (1<<FLERRE))
 enables flow error interrupt
#define Usb_enable_nak_in_interrupt()   (UEIENX |= (1<<NAKINE))
 enables NAK IN interrupt
#define Usb_enable_nak_out_interrupt()   (UEIENX |= (1<<NAKOUTE))
 enables NAK OUT interrupt
#define Usb_enable_receive_setup_interrupt()   (UEIENX |= (1<<RXSTPE))
 enables receive SETUP interrupt
#define Usb_enable_receive_out_interrupt()   (UEIENX |= (1<<RXOUTE))
 enables receive OUT interrupt
#define Usb_enable_stalled_interrupt()   (UEIENX |= (1<<STALLEDE))
 enables STALL sent interrupt
#define Usb_enable_in_ready_interrupt()   (UEIENX |= (1<<TXINE))
 enables IN ready interrupt
#define Usb_disable_flow_error_interrupt()   (UEIENX &= ~(1<<FLERRE))
 disables flow error interrupt
#define Usb_disable_nak_in_interrupt()   (UEIENX &= ~(1<<NAKINE))
 disables NAK IN interrupt
#define Usb_disable_nak_out_interrupt()   (UEIENX &= ~(1<<NAKOUTE))
 disables NAK OUT interrupt
#define Usb_disable_receive_setup_interrupt()   (UEIENX &= ~(1<<RXSTPE))
 disables receive SETUP interrupt
#define Usb_disable_receive_out_interrupt()   (UEIENX &= ~(1<<RXOUTE))
 disables receive OUT interrupt
#define Usb_disable_stalled_interrupt()   (UEIENX &= ~(1<<STALLEDE))
 disables STALL sent interrupt
#define Usb_disable_in_ready_interrupt()   (UEIENX &= ~(1<<TXIN))
 disables IN ready interrupt
#define Usb_read_byte()   (UEDATX)
 returns FIFO byte for current endpoint
#define Usb_write_byte(byte)   (UEDATX = (U8)byte)
 writes byte in FIFO for current endpoint
#define Usb_byte_counter()   ((((U16)UEBCHX) << 8) | (UEBCLX))
 returns number of bytes in FIFO current endpoint (16 bits)
#define Usb_byte_counter_8()   ((U8)UEBCLX)
 returns number of bytes in FIFO current endpoint (8 bits)
#define Usb_interrupt_flags()   (UEINT)
 tests the general endpoint interrupt flags
#define Is_usb_endpoint_event()   (Usb_interrupt_flags() != 0x00)
 tests the general endpoint interrupt flags
#define Host_allocate_memory()   (UPCFG1X |= (1<<ALLOC))
 allocates the current configuration in DPRAM memory
#define Host_unallocate_memory()   (UPCFG1X &= ~(1<<ALLOC))
 un-allocates the current configuration in DPRAM memory
#define Host_enable()   (USBCON |= (1<<HOST))
 enables USB Host function
#define Host_enable_sof()   (UHCON |= (1<<SOFEN))
 enables SOF generation
#define Host_disable_sof()   (UHCON &= ~(1<<SOFEN))
 disables SOF generation
#define Host_send_reset()   (UHCON |= (1<<RESET))
 sends a USB Reset to the device
#define Host_is_reset()   ((UHCON & (1<<RESET)) ? TRUE : FALSE)
 tests if USB Reset running
#define Host_send_resume()   (UHCON |= (1<<RESUME))
 sends a USB Resume to the device
#define Host_is_resume()   ((UHCON & (1<<RESUME)) ? TRUE : FALSE)
 tests if USB Resume running
#define Host_enable_sof_interrupt()   (UHIEN |= (1<<HSOFE))
 enables host start of frame interrupt
#define Host_disable_sof_interrupt()   (UHIEN &= ~(1<<HSOFE))
 enables host start of frame interrupt
#define Host_is_sof()   ((UHINT & (1<<HSOFI)) ? TRUE : FALSE)
 tests if SOF detected
#define Host_enable_hwup_interrupt()   (UHIEN |= (1<<HWUPE))
 enables host wake up interrupt detection
#define Host_disable_hwup_interrupt()   (UHIEN &= ~(1<<HWUPE))
 disables host wake up interrupt detection
#define Host_is_hwup()   ((UHINT & (1<<HWUPI)) ? TRUE : FALSE)
 tests if host wake up detected
#define Is_host_hwup()   ((UHINT & (1<<HWUPI)) ? TRUE : FALSE)
 Ack host wake up detection.
#define Host_enable_down_stream_resume_interrupt()   (UHIEN |= (1<<RSMEDE))
 enables host down stream rsm sent interrupt detection
#define Host_disable_down_stream_resume_interrupt()   (UHIEN &= ~(1<<RSMEDE))
 disables host down stream rsm sent interrupt detection
#define Is_host_down_stream_resume()   ((UHINT & (1<<RSMEDI)) ? TRUE : FALSE)
 Ack host down stream resume sent.
#define Host_enable_remote_wakeup_interrupt()   (UHIEN |= (1<<RXRSME))
 enables host remote wake up interrupt detection
#define Host_disable_remote_wakeup_interrupt()   (UHIEN &= ~(1<<RXRSME))
 disables host remote wake up interrupt detection
#define Host_is_remote_wakeup()   ((UHINT & (1<<RXRSMI)) ? TRUE : FALSE)
 tests if host wake up detected
#define Is_host_remote_wakeup()   ((UHINT & (1<<RXRSMI)) ? TRUE : FALSE)
 Ack host wake up detection.
#define Host_enable_device_connection_interrupt()   (UHIEN |= (1<<DCONNE))
 enables host device connection interrupt
#define Host_disable_device_connection_interrupt()   (UHIEN &= ~(1<<DCONNE))
 disables USB device connection interrupt
#define Is_device_connection()   (UHINT & (1<<DCONNI))
 tests if a USB device has been detected
#define Host_ack_device_connection()   (UHINT = ~(1<<DCONNI))
 acks device connection
#define Host_enable_device_disconnection_interrupt()   (UHIEN |= (1<<DDISCE))
 enables host device disconnection interrupt
#define Host_disable_device_disconnection_interrupt()   (UHIEN &= ~(1<<DDISCE))
 disables USB device connection interrupt
#define Is_device_disconnection()   (UHINT & (1<<DDISCI) ? TRUE : FALSE)
 tests if a USB device has been removed
#define Host_ack_device_disconnection()   (UHINT = ~(1<<DDISCI))
 acks device disconnection
#define Host_enable_reset_interrupt()   (UHIEN |= (1<<RSTE))
 enables host USB reset interrupt
#define Host_disable_reset_interrupt()   (UHIEN &= ~(1<<RSTE))
 disables host USB reset interrupt
#define Host_ack_reset()   (UHINT = ~(1<<RSTI))
 acks host USB reset sent
#define Is_host_reset()   Host_is_reset()
 tests if USB reset has been sent
#define Host_vbus_request()   (OTGCON |= (1<<VBUSREQ))
 switches on VBus
#define Host_clear_vbus_request()   (OTGCON |= (1<<VBUSRQC))
 switches off VBus
#define Host_configure_address(addr)   (UHADDR = addr & MSK_HADDR)
 configures the address to use for the device
#define Is_host_full_speed()   ((USBSTA & (1<<SPEED)) ? TRUE : FALSE)
 Get connected device speed, returns TRUE when in full speed mode.
#define Host_select_pipe(p)   (UPNUM = (U8)p)
 selects pipe for CPU interface
#define Host_get_selected_pipe()   (UPNUM )
 get the currently selected pipe number
#define Host_enable_pipe()   (UPCONX |= (1<<PEN))
 enables pipe
#define Host_disable_pipe()   (UPCONX &= ~(1<<PEN))
 disables pipe
#define Host_set_token_setup()   (UPCFG0X = UPCFG0X & ~MSK_TOKEN_SETUP)
 sets SETUP token
#define Host_set_token_in()   (UPCFG0X = (UPCFG0X & ~MSK_TOKEN_SETUP) | MSK_TOKEN_IN)
 sets IN token
#define Host_set_token_out()   (UPCFG0X = (UPCFG0X & ~MSK_TOKEN_SETUP) | MSK_TOKEN_OUT)
 sets OUT token
#define Host_get_endpoint_number()   (UPCFG0X & (MSK_PEPNUM))
 returns the number of the endpoint associated to the current pipe
#define Host_get_pipe_interrupt()   (UPINT)
 returns pipe interrupt register
#define Host_set_interrupt_frequency(frq)   (UPCFG2X = (U8)frq)
 sets the interrupt frequency
#define Is_pipe_configured()   (UPSTAX & (1<<CFGOK))
 tests if current pipe is configured
#define Is_host_one_bank_busy()   ((UPSTAX & (1<<MSK_NBUSYBK)) != 0)
 tests if at least one bank is busy
#define Host_number_of_busy_bank()   (UPSTAX & (1<<MSK_NBUSYBK))
 returns the number of busy banks
#define Host_reset_pipe(p)   (UPRST = 1<<p , UPRST = 0)
 resets the pipe
#define Host_write_byte(dat)   (UPDATX = dat)
 writes a byte into the pipe FIFO
#define Host_read_byte()   (UPDATX)
 reads a byte from the pipe FIFO
#define Host_freeze_pipe()   (UPCONX |= (1<<PFREEZE))
 freezes the pipe
#define Host_unfreeze_pipe()   (UPCONX &= ~(1<<PFREEZE))
 un-freezees the pipe
#define Is_host_pipe_freeze()   (UPCONX & (1<<PFREEZE))
 tests if the current pipe is frozen
#define Host_reset_pipe_data_toggle()   (UPCONX |= (1<<RSTDT) )
 resets data toggle
#define Is_host_setup_sent()   ((UPINTX & (1<<TXSTPI)) ? TRUE : FALSE)
 tests if SETUP has been sent
#define Is_host_control_in_received()   ((UPINTX & (1<<RXINI)) ? TRUE : FALSE)
 tests if control IN has been received
#define Is_host_control_out_sent()   ((UPINTX & (1<<TXOUTI)) ? TRUE : FALSE)
 tests if control OUT has been sent
#define Is_host_stall()   ((UPINTX & (1<<RXSTALLI)) ? TRUE : FALSE)
 tests if a STALL has been received
#define Is_host_pipe_error()   ((UPINTX & (1<<PERRI)) ? TRUE : FALSE)
 tests if an error occurs on current pipe
#define Host_send_setup()   (UPINTX &= ~(1<<FIFOCON))
 sends a setup
#define Host_send_control_in()   (UPINTX &= ~(1<<FIFOCON))
 sends a control IN
#define Host_send_control_out()   (UPINTX &= ~(1<<FIFOCON))
 sends a control OUT
#define Host_ack_control_out()   (UPINTX &= ~(1<<TXOUTI))
 acks control OUT
#define Host_ack_control_in()   (UPINTX &= ~(1<<RXINI))
 acks control IN
#define Host_ack_setup()   (UPINTX &= ~(1<<TXSTPI))
 acks setup
#define Host_ack_stall()   (UPINTX &= ~(1<<RXSTALLI))
 acks STALL reception
#define Host_send_out()   (UPINTX &= ~(1<<FIFOCON))
 sends a OUT
#define Is_host_out_sent()   ((UPINTX & (1<<TXOUTI)) ? TRUE : FALSE)
 tests if OUT has been sent
#define Host_ack_out_sent()   (UPINTX &= ~(1<<TXOUTI))
 acks OUT sent
#define Is_host_in_received()   ((UPINTX & (1<<RXINI)) ? TRUE : FALSE)
 tests if IN received
#define Host_ack_in_received()   (UPINTX &= ~(1<<RXINI))
 acks IN reception
#define Host_send_in()   (UPINTX &= ~(1<<FIFOCON))
 sends a IN
#define Is_host_nak_received()   ((UPINTX & (1<<NAKEDI)) ? TRUE : FALSE)
 tests if nak handshake has been received
#define Host_ack_nak_received()   (UPINTX &= ~(1<<NAKEDI))
 acks NAk received sent
#define Is_host_read_enabled()   (UPINTX&(1<<RWAL))
 tests if endpoint read allowed
#define Is_host_write_enabled()   (UPINTX&(1<<RWAL))
 tests if endpoint read allowed
#define Host_standard_in_mode()   (UPCONX &= ~(1<<INMODE))
 sets IN in standard mode
#define Host_continuous_in_mode()   (UPCONX |= (1<<INMODE))
 sets IN in continuous mode
#define Host_in_request_number(in_num)   (UPINRQX = (U8)in_num)
 sets number of IN requests to perform before freeze
#define Host_get_in_request_number()   (UPINRQX)
 returns number of remaining IN requests
#define Host_data_length_U8()   (UPBCLX)
 returns number of bytes (8 bits)
#define Host_data_length_U16()   ((((U16)UPBCHX)<<8) | UPBCLX)
 returns number of bytes (16 bits)
#define Host_byte_counter()   Host_data_length_U16()
 for device compatibility
#define Host_byte_counter_8()   Host_data_length_U8()
 for device compatibility
#define Host_get_pipe_length()   ((U16)0x08 << ((UPCFG1X & MSK_PSIZE)>>4))
 returns the size of the current pipe
#define Host_get_pipe_type()   (UPCFG0X>>6)
 returns the type of the current pipe
#define Host_error_status()   (UPERRX & MSK_ERROR)
 tests if error occurs on pipe
#define Host_ack_all_errors()   (UPERRX = 0x00)
 acks all pipe error
#define Host_enable_transmit_interrupt()   (UPIENX |= (1<<TXOUTE))
 Enable pipe end transmission interrupt.
#define Host_disable_transmit_interrupt()   (UPIENX &= ~(1<<TXOUTE))
 Disable pipe end transmission interrupt.
#define Host_enable_receive_interrupt()   (UPIENX |= (1<<RXINE))
 Enable pipe reception interrupt.
#define Host_disable_receive_interrupt()   (UPIENX &= ~(1<<RXINE))
 Disable pipe recption interrupt.
#define Host_enable_stall_interrupt()   (UPIENX |= (1<<RXSTALLE))
 Enable pipe stall interrupt.
#define Host_disable_stall_interrupt()   (UPIENX &= ~(1<<RXSTALLE))
 Disable pipe stall interrupt.
#define Host_enable_error_interrupt()   (UPIENX |= (1<<PERRE))
 Enable pipe error interrupt.
#define Host_disable_error_interrupt()   (UPIENX &= ~(1<<PERRE))
 Disable pipe error interrupt.
#define Host_enable_nak_interrupt()   (UPIENX |= (1<<NAKEDE))
 Enable pipe NAK interrupt.
#define Host_disable_nak_interrupt()   (UPIENX &= ~(1<<NAKEDE))
 Disable pipe NAK interrupt.
#define wSWAP(x)
 wSWAP This macro swaps the U8 order in words.
#define Usb_write_word_enum_struc(x)   (wSWAP(x))
 Usb_write_word_enum_struc This macro help to fill the U16 fill in USB enumeration struct.

Functions

U8 usb_config_ep (U8 config0, U8 config1)
 usb_configure_endpoint.
U8 usb_select_enpoint_interrupt (void)
 usb_select_endpoint_interrupt.
U8 usb_send_packet (U8 ep_num, U8 *tbuf, U8 data_length)
 usb_send_packet.
U8 usb_read_packet (U8 ep_num, U8 *rbuf, U8 data_length)
 usb_read_packet.
void usb_halt_endpoint (U8 ep_num)
 usb_halt_endpoint.
U8 usb_init_device (void)
 usb_init_device.

Detailed Description

This file contains the USB driver routines.

Definition in file usb_drv.h.