- Main Page
- Modules
- Data Structures
- Files
- Related Pages

- File List
- Globals

# usb_drv.h File Reference

,vThis file contains the USB low level driver definition More...

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

Go to the source code of this file.

## Defines
#define | MAX_EP_NB 7
#define | EP_CONTROL 0
#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 | PIPE_CONTROL 0
#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 | MSK_EP_DIR 0x7F
#define | MSK_UADD 0x7F
#define | MSK_EPTYPE 0xC0
#define | MSK_EPSIZE 0x70
#define | MSK_EPBK 0x0C
#define | MSK_DTSEQ 0x0C
#define | MSK_NBUSYBK 0x03
#define | MSK_CURRBK 0x03
#define | MSK_DAT 0xFF
#define | MSK_BYCTH 0x07
#define | MSK_BYCTL 0xFF
#define | MSK_EPINT 0x7F
#define | MSK_HADDR 0xFF
#define | MSK_PNUM 0x07
#define | MSK_PRST 0x7F
#define | MSK_PTYPE 0xC0
#define | MSK_PTOKEN 0x30
#define | MSK_PEPNUM 0x0F
#define | MSK_PSIZE 0x70
#define | MSK_PBK 0x0C
#define | MSK_NBUSYBK 0x03
#define | MSK_ERROR 0x1F
#define | MSK_PTYPE 0xC0
#define | MSK_PTOKEN 0x30
#define | MSK_TOKEN_SETUP 0x30
#define | MSK_TOKEN_IN 0x10
#define | MSK_TOKEN_OUT 0x20
#define | MSK_PEPNUM 0x0F
#define | MSK_PSIZE 0x70
#define | MSK_PBK 0x0C
#define | TYPE_CONTROL 0
#define | TYPE_ISOCHRONOUS 1
#define | TYPE_BULK 2
#define | TYPE_INTERRUPT 3
#define | DIRECTION_OUT 0
#define | DIRECTION_IN 1
#define | SIZE_8 0
#define | SIZE_16 1
#define | SIZE_32 2
#define | SIZE_64 3
#define | SIZE_128 4
#define | SIZE_256 5
#define | SIZE_512 6
#define | SIZE_1024 7
#define | ONE_BANK 0
#define | TWO_BANKS 1
#define | NYET_ENABLED 0
#define | NYET_DISABLED 1
#define | TOKEN_SETUP 0
#define | TOKEN_IN 1
#define | TOKEN_OUT 2
#define | Is_ep_addr_in(x) ( (x&0x80)? TRUE : FALSE)
#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_configure_endpoint(num, type, dir, size, bank, nyet)
#define | Host_build_pipe_config0(type, token, ep_num) ((type<<6) | (token<<4) | (ep_num))
#define | Host_build_pipe_config1(size, bank) ((size<<4) | (bank<<2) )
#define | host_configure_pipe(num, type, token, ep_num, size, bank, freq)
#define | Usb_enable_regulator() (REGCR &= ~(1<<REGDIS))
| Enable internal USB pads regulator.
#define | Usb_disable_regulator() (REGCR |= (1<<REGDIS))
| Disable internal USB pads regulator.
#define | Is_usb_regulator_enabled() ((REGCR & (1<<REGDIS)) ? FALSE : TRUE)
| Check regulator enable bit.
#define | Usb_enable() (USBCON |= ((1<<USBE) ))
| Enable both USB interface.
#define | Usb_disable() (USBCON &= ~((1<<USBE)))
| Disable both USB interface.
#define | Is_usb_enabled() ((USBCON & (1<<USBE)) ? TRUE : FALSE)
#define | Usb_enable_device() (USBCON |= (1<<USBE))
#define | Usb_disable_device() (USBCON &= ~(1<<USBE))
#define | Usb_reset_macro_only() (UDCON &= ~(1<<RSTCPU))
#define | Usb_reset_all_system() (UDCON |= (1<<RSTCPU))
#define | Usb_vbus_sense_init()
| Init vbus sensing i/o.
#define | Is_usb_vbus_on() (((VBUS_SENSE_PIN&(1<<VBUS_SENSE_IO)) != 0) ? TRUE : FALSE)
| test if vbus is present
#define | Is_usb_vbus_off() (((VBUS_SENSE_PIN&(1<<VBUS_SENSE_IO)) == 0) ? TRUE : FALSE)
| test if vbus is not present
#define | Usb_freeze_clock() (USBCON |= (1<<FRZCLK))
| Stop internal USB clock in interface (freeze the interface register).
#define | Usb_unfreeze_clock() (USBCON &= ~(1<<FRZCLK))
#define | Is_usb_clock_freezed() ((USBCON & (1<<FRZCLK)) ? TRUE : FALSE)
#define | Ps2_enable_device() (PS2CON |= (1<<PS2EN))
#define | Ps2_disable_device() (PS2CON &= ~(1<<PS2EN))
#define | Usb_direct_drive_usb_enable() (UPOE |= (1<<UPWE1), UPOE &= ~(1<<UPWE0))
#define | Usb_direct_drive_ps2_enable() (UPOE |= ((1<<UPWE1) | (1<<UPWE0)))
#define | Usb_direct_drive_disable() (UPOE &= ~((1<<UPWE1) | (1<<UPWE0)))
#define | Usb_drive_dp_high() (UPOE |= (1<<UPDRV1))
#define | Usb_drive_dp_low() (UPOE &= ~(1<<UPDRV1))
#define | Usb_drive_dm_high() (UPOE |= (1<<UPDRV0))
#define | Usb_drive_dm_low() (UPOE &= ~(1<<UPDRV0))
#define | Ps2_drive_sck_high() (UPOE |= (1<<UPDRV1))
#define | Ps2_drive_sck_low() (UPOE &= ~(1<<UPDRV1))
#define | Ps2_drive_data_high() (UPOE |= (1<<UPDRV0))
#define | Ps2_drive_data_low() (UPOE &= ~(1<<UPDRV0))
#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_ack_cache_id_transition(x) ((x) &= ~(1<<IDTI))
#define | Usb_ack_cache_vbus_transition(x) ((x) &= ~(1<<VBUSTI))
#define | Is_usb_cache_id_transition(x) (((x) & (1<<IDTI)) )
#define | Is_usb_cache_vbus_transition(x) (((x) & (1<<VBUSTI)))
#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 | Is_remote_wake_up_interrupt_enabled() ((UDIEN & (1<<UPRSME)) ? TRUE : FALSE)
#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 | Is_resume_interrupt_enabled() ((UDIEN & (1<<EORSME)) ? TRUE : FALSE)
#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 | Is_swake_up_interrupt_enabled() ((UDIEN & (1<<WAKEUPE)) ? TRUE : FALSE)
#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 | Is_reset_interrupt_enabled() ((UDIEN & (1<<EORSTE)) ? TRUE : FALSE)
#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 | Is_sof_interrupt_enabled() ((UDIEN & (1<<SOFE)) ? TRUE : FALSE)
#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 | Is_suspend_interrupt_enabled() ((UDIEN & (1<<SUSPE)) ? TRUE : FALSE)
| test if suspend interrupt is enabled
#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 | Is_usb_addressed() ((UDADDR & (1<<ADDEN)) ? TRUE : FALSE)
| test if device is adressed
#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 | 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_nak_out_sent() (UEINTX&(1<<NAKOUTI))
| tests if a NAK has been sent
#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<<TXIN))
| 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() ((U8)(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 | 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.
## Typedefs
typedef enum endpoint_parameter | t_endpoint_parameter
## Enumerations
enum | endpoint_parameter { ep_num, ep_type, ep_direction, ep_size, ep_bank, nyet_status }
## Functions
U8 | usb_config_ep (U8, U8)
| usb_configure_endpoint.
U8 | usb_select_enpoint_interrupt (void)
| usb_select_endpoint_interrupt.
U16 | usb_get_nb_byte_epw (void)
U8 | usb_send_packet (U8, U8 *, U8)
| usb_send_packet.
U8 | usb_read_packet (U8, U8 *, U8)
| usb_read_packet.
void | usb_halt_endpoint (U8)
| usb_halt_endpoint.
void | usb_reset_endpoint (U8)
U8 | usb_init_device (void)
| usb_init_device.

## Detailed Description

,vThis file contains the USB low level driver definition

Copyright (c) 2006 Atmel.

Use of this program is subject to Atmel's End User License Agreement. Please read file license.txt for copyright notice.

Version:
  1.8 at90usb162-2enum-mouse_ms-1_0_1
  Id
    usb_drv.h,v 1.8 2006/11/30 14:08:28 rletendu Exp

Todo:

Bug:

Definition in file usb_drv.h.

## Typedef Documentation

typedef enum endpoint_parameter t_endpoint_parameter

## Enumeration Type Documentation

enum endpoint_parameter

Enumerator:

  ep_num |
  ep_type |
  ep_direction |
  ep_size |
  ep_bank |
  nyet_status |

Definition at line 22 of file usb_drv.h.

    00022 {ep_num, ep_type, ep_direction, ep_size, ep_bank, nyet_status} t_endpoint_parameter;

## Function Documentation

U8 usb_config_ep | ( | U8 | config0,
|  | U8 | config1 |
| ) |  |  |

usb_configure_endpoint.

This function configures an endpoint with the selected type.

Parameters:

  | config0 |
  | config1 |

Returns:
  Is_endpoint_configured.

Definition at line 39 of file usb_drv.c.

References ALLOC, Is_endpoint_configured, Usb_allocate_memory, and Usb_enable_endpoint.

    00040 {
    00041     Usb_enable_endpoint();
    00042     UECFG0X = config0;
    00043     UECFG1X = (UECFG1X & (1<<ALLOC)) | config1;
    00044     Usb_allocate_memory();
    00045     return (Is_endpoint_configured());
    00046 }

U8 usb_select_enpoint_interrupt | ( | void |  | ) |

usb_select_endpoint_interrupt.

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.

Parameters:

  | none |

Returns:
  endpoint number.

Definition at line 59 of file usb_drv.c.

References ep_num, MAX_EP_NB, and Usb_interrupt_flags.

    00060 {
    00061 U8 interrupt_flags;
    00062 U8 ep_num;
    00063
    00064    ep_num = 0;
    00065    interrupt_flags = Usb_interrupt_flags();
    00066
    00067    while(ep_num < MAX_EP_NB)
    00068    {
    00069       if (interrupt_flags & 1)
    00070       {
    00071          return (ep_num);
    00072       }
    00073       else
    00074       {
    00075          ep_num++;
    00076          interrupt_flags = interrupt_flags >> 1;
    00077       }
    00078    }
    00079    return 0;
    00080 }

U16 usb_get_nb_byte_epw | ( | void |  | ) |

U8 usb_send_packet | ( | U8 | ep_num,
|  | U8 * | tbuf,
|  | U8 | data_length |
| ) |  |  |

usb_send_packet.

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

Parameters:

  | ep_num | number of the addressed endpoint
  | *tbuf | address of the first data to send
  | data_length | number of bytes to send

Returns:
  address of the next U8 to send.

Example: usb_send_packet(3,&first_data,0x20); // send packet on the endpoint #3 while(!(Usb_tx_complete)); // wait packet ACK'ed by the Host Usb_clear_tx_complete(); // acknowledge the transmit

Note: tbuf is incremented of 'data_length'.

Definition at line 102 of file usb_drv.c.

References Is_usb_write_enabled, Usb_select_endpoint, and Usb_write_byte.

    00103 {
    00104 U8 remaining_length;
    00105
    00106    remaining_length = data_length;
    00107    Usb_select_endpoint(ep_num);
    00108    while(Is_usb_write_enabled() && (0 != remaining_length))
    00109    {
    00110       Usb_write_byte(*tbuf);
    00111       remaining_length--;
    00112       tbuf++;
    00113    }
    00114    return remaining_length;
    00115 }

U8 usb_read_packet | ( | U8 | ep_num,
|  | U8 * | rbuf,
|  | U8 | data_length |
| ) |  |  |

usb_read_packet.

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

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

Returns:
  address of the next U8 to send.

Example: while(!(Usb_rx_complete)); // wait new packet received usb_read_packet(4,&first_data,usb_get_nb_byte); // read packet from ep 4 Usb_clear_rx(); // acknowledge the transmit

Note: rbuf is incremented of 'data_length'.

Definition at line 137 of file usb_drv.c.

References Is_usb_read_enabled, Usb_read_byte, and Usb_select_endpoint.

    00138 {
    00139 U8 remaining_length;
    00140
    00141    remaining_length = data_length;
    00142    Usb_select_endpoint(ep_num);
    00143
    00144    while(Is_usb_read_enabled() && (0 != remaining_length))
    00145    {
    00146       *rbuf = Usb_read_byte();
    00147       remaining_length--;
    00148       rbuf++;
    00149    }
    00150    return remaining_length;
    00151 }

void usb_halt_endpoint | ( | U8 | ep_num | ) |

usb_halt_endpoint.

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

Returns:
  none

Definition at line 163 of file usb_drv.c.

References Usb_enable_stall_handshake, and Usb_select_endpoint.

    00164 {
    00165    Usb_select_endpoint(ep_num);
    00166    Usb_enable_stall_handshake();
    00167 }

void usb_reset_endpoint | ( | U8 |  | ) |

U8 usb_init_device | ( | void |  | ) |

usb_init_device.

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

Parameters:

  | none |

Returns:
  status

Definition at line 179 of file usb_drv.c.

References DIRECTION_OUT, EP_CONTROL, FALSE, Is_usb_endpoint_enabled, NYET_DISABLED, ONE_BANK, SIZE_32, TYPE_CONTROL, usb_configure_endpoint, and Usb_select_endpoint.

Referenced by usb_general_interrupt(), and usb_start_device().

    00180 {
    00181       Usb_select_endpoint(EP_CONTROL);
    00182       if(!Is_usb_endpoint_enabled())
    00183       {
    00184          return usb_configure_endpoint(EP_CONTROL,    \
    00185                                 TYPE_CONTROL,  \
    00186                                 DIRECTION_OUT, \
    00187                                 SIZE_32,       \
    00188                                 ONE_BANK,      \
    00189                                 NYET_DISABLED);
    00190       }
    00191    return FALSE;
    00192 }