Microchip® Advanced Software Framework

usb_drv.c File Reference
#include "usb_drv.h"
#include "usb_descriptors.h"

Functions

void host_disable_all_pipes (void)
 

------------—— HOST ---------------------------——

More...
 
U32 host_read_p_rxpacket (U8 p, void *rxbuf, U32 data_length, void **prxbuf)
 host_read_p_rxpacket More...
 
U32 host_set_p_txpacket (U8 p, U8 txbyte, U32 data_length)
 host_set_p_txpacket More...
 
U32 host_write_p_txpacket (U8 p, const void *txbuf, U32 data_length, const void **ptxbuf)
 host_write_p_txpacket More...
 
Status_bool_t usb_init_device (void)
 

------------—— DEVICE -------------------------——

More...
 
U32 usb_read_ep_rxpacket (U8 ep, void *rxbuf, U32 data_length, void **prxbuf)
 usb_read_ep_rxpacket More...
 
U32 usb_set_ep_txpacket (U8 ep, U8 txbyte, U32 data_length)
 usb_set_ep_txpacket More...
 
U32 usb_write_ep_txpacket (U8 ep, const void *txbuf, U32 data_length, const void **ptxbuf)
 usb_write_ep_txpacket More...
 

Variables

UnionVPtr pep_fifo [MAX_PEP_NB]
 Pointers to the FIFO data registers of pipes/endpoints Use aggregated pointers to have several alignments available for a same address. More...
 

void host_disable_all_pipes ( void  )


------------—— HOST ---------------------------——

host_disable_all_pipes

This function disables all pipes for the host controller. Useful to execute upon disconnection.

Returns
Void

References cpu_irq_disable, cpu_irq_enable, cpu_irq_is_enabled, Host_disable_pipe, Host_disable_pipe_interrupt, Host_reset_pipe, Host_unallocate_memory, Is_host_pipe_enabled, and MAX_PEP_NB.

Referenced by usb_general_interrupt_non_naked(), and usb_host_task().

U32 host_read_p_rxpacket ( U8  p,
void *  rxbuf,
U32  data_length,
void **  prxbuf 
)

host_read_p_rxpacket

This function reads the selected pipe FIFO to the buffer pointed to by rxbuf, using as few accesses as possible.

Parameters
pNumber of the addressed pipe
rxbufAddress of buffer to write
data_lengthNumber of bytes to read
prxbufNULL or pointer to the buffer address to update
Returns
Number of non-read bytes
Note
The selected pipe FIFO may be read in several steps by calling host_read_p_rxpacket several times.
Warning
Invoke Host_reset_pipe_fifo_access before this function when at FIFO beginning whether or not the FIFO is to be read in several steps.
Do not mix calls to this function with calls to indexed macros.

References Align_down, Get_align, Host_byte_count, min, Test_align, UnionPtr::u16ptr, UnionCPtr::u16ptr, UnionCVPtr::u16ptr, UnionPtr::u32ptr, UnionCPtr::u32ptr, UnionCVPtr::u32ptr, UnionPtr::u64ptr, UnionCPtr::u64ptr, UnionCVPtr::u64ptr, UnionPtr::u8ptr, UnionVPtr::u8ptr, UnionCPtr::u8ptr, and UnionCVPtr::u8ptr.

Referenced by host_get_data(), host_mouse_hid_task(), and host_transfer_control().

U32 host_set_p_txpacket ( U8  p,
U8  txbyte,
U32  data_length 
)

host_set_p_txpacket

This function fills the selected pipe FIFO with a constant byte, using as few accesses as possible.

Parameters
pNumber of the addressed pipe
txbyteByte to fill the pipe with
data_lengthNumber of bytes to write
Returns
Number of non-written bytes
Note
The selected pipe FIFO may be filled in several steps by calling host_set_p_txpacket several times.
Warning
Invoke Host_reset_pipe_fifo_access before this function when at FIFO beginning whether or not the FIFO is to be filled in several steps.
Do not mix calls to this function with calls to indexed macros.

References Align_down, Host_byte_count, Host_get_pipe_size, min, Test_align, Union64::u16, UnionVPtr::u16ptr, UnionCVPtr::u16ptr, Union64::u32, UnionVPtr::u32ptr, UnionCVPtr::u32ptr, Union64::u64, UnionVPtr::u64ptr, UnionCVPtr::u64ptr, u8, Union64::u8, UnionVPtr::u8ptr, and UnionCVPtr::u8ptr.

U32 host_write_p_txpacket ( U8  p,
const void *  txbuf,
U32  data_length,
const void **  ptxbuf 
)

host_write_p_txpacket

This function writes the buffer pointed to by txbuf to the selected pipe FIFO, using as few accesses as possible.

Parameters
pNumber of the addressed pipe
txbufAddress of buffer to read
data_lengthNumber of bytes to write
ptxbufNULL or pointer to the buffer address to update
Returns
Number of non-written bytes
Note
The selected pipe FIFO may be written in several steps by calling host_write_p_txpacket several times.
Warning
Invoke Host_reset_pipe_fifo_access before this function when at FIFO beginning whether or not the FIFO is to be written in several steps.
Do not mix calls to this function with calls to indexed macros.

References Align_down, Get_align, Host_byte_count, Host_get_pipe_size, min, Test_align, UnionVPtr::u16ptr, UnionCPtr::u16ptr, UnionVPtr::u32ptr, UnionCPtr::u32ptr, UnionVPtr::u64ptr, UnionCPtr::u64ptr, UnionVPtr::u8ptr, and UnionCPtr::u8ptr.

Referenced by host_send_data(), and host_transfer_control().

Status_bool_t usb_init_device ( void  )


------------—— DEVICE -------------------------——

usb_init_device

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

Returns
Status

References DIRECTION_OUT, EP_CONTROL, EP_CONTROL_LENGTH, Is_usb_endpoint_enabled, Is_usb_id_device, SINGLE_BANK, TYPE_CONTROL, and Usb_configure_endpoint.

Referenced by usb_general_interrupt_non_naked(), and usb_start_device().

U32 usb_read_ep_rxpacket ( U8  ep,
void *  rxbuf,
U32  data_length,
void **  prxbuf 
)

usb_read_ep_rxpacket

This function reads the selected endpoint FIFO to the buffer pointed to by rxbuf, using as few accesses as possible.

Parameters
epNumber of the addressed endpoint
rxbufAddress of buffer to write
data_lengthNumber of bytes to read
prxbufNULL or pointer to the buffer address to update
Returns
Number of non-read bytes
Note
The selected endpoint FIFO may be read in several steps by calling usb_read_ep_rxpacket several times.
Warning
Invoke Usb_reset_endpoint_fifo_access before this function when at FIFO beginning whether or not the FIFO is to be read in several steps.
Do not mix calls to this function with calls to indexed macros.

References Align_down, Get_align, min, Test_align, UnionPtr::u16ptr, UnionCVPtr::u16ptr, StructCPtr::u16ptr, UnionPtr::u32ptr, UnionCVPtr::u32ptr, StructCPtr::u32ptr, UnionPtr::u64ptr, UnionCVPtr::u64ptr, StructCPtr::u64ptr, UnionPtr::u8ptr, UnionVPtr::u8ptr, UnionCVPtr::u8ptr, StructCPtr::u8ptr, and Usb_byte_count.

U32 usb_set_ep_txpacket ( U8  ep,
U8  txbyte,
U32  data_length 
)

usb_set_ep_txpacket

This function fills the selected endpoint FIFO with a constant byte, using as few accesses as possible.

Parameters
epNumber of the addressed endpoint
txbyteByte to fill the endpoint with
data_lengthNumber of bytes to write
Returns
Number of non-written bytes
Note
The selected endpoint FIFO may be filled in several steps by calling usb_set_ep_txpacket several times.
Warning
Invoke Usb_reset_endpoint_fifo_access before this function when at FIFO beginning whether or not the FIFO is to be filled in several steps.
Do not mix calls to this function with calls to indexed macros.

References Align_down, min, Test_align, Union64::u16, UnionVPtr::u16ptr, UnionCVPtr::u16ptr, Union64::u32, UnionVPtr::u32ptr, UnionCVPtr::u32ptr, Union64::u64, UnionVPtr::u64ptr, UnionCVPtr::u64ptr, u8, Union64::u8, UnionVPtr::u8ptr, UnionCVPtr::u8ptr, Usb_byte_count, and Usb_get_endpoint_size.

U32 usb_write_ep_txpacket ( U8  ep,
const void *  txbuf,
U32  data_length,
const void **  ptxbuf 
)

usb_write_ep_txpacket

This function writes the buffer pointed to by txbuf to the selected endpoint FIFO, using as few accesses as possible.

Parameters
epNumber of the addressed endpoint
txbufAddress of buffer to read
data_lengthNumber of bytes to write
ptxbufNULL or pointer to the buffer address to update
Returns
Number of non-written bytes
Note
The selected endpoint FIFO may be written in several steps by calling usb_write_ep_txpacket several times.
Warning
Invoke Usb_reset_endpoint_fifo_access before this function when at FIFO beginning whether or not the FIFO is to be written in several steps.
Do not mix calls to this function with calls to indexed macros.

References Align_down, Get_align, min, Test_align, UnionVPtr::u16ptr, UnionCPtr::u16ptr, UnionVPtr::u32ptr, UnionCPtr::u32ptr, UnionVPtr::u64ptr, UnionCPtr::u64ptr, UnionVPtr::u8ptr, UnionCPtr::u8ptr, Usb_byte_count, and Usb_get_endpoint_size.

Referenced by hid_get_descriptor(), usb_get_descriptor(), and usb_set_feature().

UnionVPtr pep_fifo[MAX_PEP_NB]

Pointers to the FIFO data registers of pipes/endpoints Use aggregated pointers to have several alignments available for a same address.