pic_usb.c File Reference

#include "pic_usb.h"
#include "memory.h"
#include "config.h"
#include "pic_usb_buffer_mgt.h"
#include "pic_serial.h"
Include dependency graph for pic_usb.c:

Go to the source code of this file.

Functions

void turn_usb_ints_on ()
 Turn on USB interrupts.
void usb_configure_endpoints ()
void usb_enable_module ()
 Enables the USB hardware and starts USB negotiations.
usb_state_type usb_get_state ()
 Query the current state of the USB connection.
void usb_handle_isr ()
 Handle USB interrupts.
void usb_handle_reset ()
void usb_handle_stall ()
void usb_handle_standard_request (setup_data_packet sdp)
void usb_handle_transaction (uns8 stat)
void usb_prime_ep0_out_e ()
void usb_prime_ep0_out_o ()
void usb_send_data (uns8 ep, uns8 *data, uns8 send_count, bit first)
 Send data over an endpoint pipe.
void usb_send_data_chunk ()
void usb_send_empty_data_pkt ()
 Send an empty data packet.
void usb_send_one_byte (uns8 data)
void usb_setup ()
 Setup USB hardware ready for use.
void usb_stall_ep0 ()
 Send a stall on control transfer endpoint.
void usb_stall_on_in ()

Variables

uns8 buffer_byte
control_mode_type control_mode
buffer_descriptordelivery_bd
uns8 * delivery_buffer
uns8 delivery_buffer_size
uns16 delivery_bytes_max_send
uns16 delivery_bytes_sent
uns16 delivery_bytes_to_send
uns8 * delivery_ptr
uns8 usb_address
setup_data_packet usb_sdp
usb_state_type usb_state = st_POWERED
usb_status_type usb_status

Function Documentation

void turn_usb_ints_on (  ) 

If you are using interrupt-driven code (generally the best way of doing things) you can turn on USB interrupts using turn_usb_ints_on(). Don't forget that you will also need to call turn_global_ints_on() as well. Typically this is called in your system setup routine.

Definition at line 962 of file pic_usb.c.

void usb_configure_endpoints (  ) 

Definition at line 66 of file pic_usb.c.

References buffer_descriptor::addr, BC8, BC9, bd1in, bd1out, bd2in, bd2out, bd3in, bd3out, BSTALL, buffer_descriptor::count, DTS, DTSEN, INCDIS, KEN, serial_print_str(), buffer_descriptor::stat, and UOWN.

Referenced by usb_handle_standard_request().

Here is the call graph for this function:

Here is the caller graph for this function:

void usb_enable_module (  ) 

After you've called usb_setup(), you can call usb_enable_module() whenever you're ready for USB negotiations to occur. Normally, this would need to occur relatively quickly after power-up if your PIC is powered by USB and it's purpose is to talk over USB. This is normally called from your main() routine once all other configuration is done.

Once the USB module has successfully negotiated a connection with the host, usb_device_configured_callback() will be called if you have requested this in your config.h file. This will indicate a successful connection. Because of the way USB works, there is no way to tell that it *hasn't* worked, except via a timer - if you haven't had a good connection in several seconds, you can assume it has failed (although this may just mean the user is hunting for a driver disk etc).

Definition at line 1033 of file pic_usb.c.

References st_DEFAULT, and usb_state.

usb_state_type usb_get_state (  ) 

Returns the USB state, either powered, default, address or connect. This is updated as the negotiation progresses. It may be useful to query this if, after a suitable time-out, the connection has not been made.

Definition at line 1039 of file pic_usb.c.

References usb_state.

void usb_handle_isr (  ) 

usb_handle_isr() should be inserted in your interrupt service routine. Alternatively, if you have reason not to want to do interrupt-driven USB, for example, a bootloader, you can poll this routine.

Make sure you call turn_usb_ints() and turn_global_ints_on() to ensure interrupts occur.

It will check for any of the USB interrupt flags and handle: USB transactions, USB reset, USB stall, USB Start Of Frame (including calling usb_SOF_callback() if configured in your config.h and most importantly USB transaction, which is where all the hard work is done.

Definition at line 928 of file pic_usb.c.

References uns8, usb_handle_reset(), usb_handle_stall(), usb_handle_transaction(), and usb_SOF_callback().

Here is the call graph for this function:

void usb_handle_reset (  ) 

Definition at line 853 of file pic_usb.c.

References buffer_descriptor::addr, BC8, BC9, bd0in, bd0out_e, bd0out_o, BSTALL, cm_IDLE, control_mode, buffer_descriptor::count, DTS, DTSEN, INCDIS, KEN, serial_print_int_hex(), serial_print_str(), buffer_descriptor::stat, UOWN, us_IDLE, usb_address, USB_EP0_IN_ADDR, USB_EP0_OUT_E_ADDR, USB_EP0_OUT_O_ADDR, and usb_status.

Referenced by usb_handle_isr().

Here is the call graph for this function:

Here is the caller graph for this function:

void usb_handle_stall (  ) 

Definition at line 918 of file pic_usb.c.

References bd0in, BSTALL, serial_print_str(), buffer_descriptor::stat, and UOWN.

Referenced by usb_handle_isr().

Here is the call graph for this function:

Here is the caller graph for this function:

void usb_handle_standard_request ( setup_data_packet  sdp  ) 
void usb_handle_transaction ( uns8  stat  ) 
void usb_prime_ep0_out_e (  ) 

! clear

Definition at line 384 of file pic_usb.c.

References buffer_descriptor::addr, BC8, BC9, bd0out_e, BSTALL, buffer_descriptor::count, DTS, DTSEN, INCDIS, KEN, serial_putc(), buffer_descriptor::stat, UOWN, and USB_EP0_OUT_E_ADDR.

Referenced by usb_handle_transaction().

Here is the call graph for this function:

Here is the caller graph for this function:

void usb_prime_ep0_out_o (  ) 

! clear

Definition at line 406 of file pic_usb.c.

References buffer_descriptor::addr, BC8, BC9, bd0out_o, BSTALL, buffer_descriptor::count, DTS, DTSEN, INCDIS, KEN, serial_putc(), buffer_descriptor::stat, UOWN, and USB_EP0_OUT_O_ADDR.

Referenced by usb_handle_transaction().

Here is the call graph for this function:

Here is the caller graph for this function:

void usb_send_data ( uns8  ep,
uns8 *  data,
uns8  send_count,
bit  first 
)

Use this routine to send data across the USB pipe.

Parameters:
ep Endpoint that the data should be sent from
data pointer to the data
send_count the number of bytes to send
first True if this is the first in a series of sends. Generally, this can be set to False, since it will automatically be set to the right value on endpoint creation. However, in the case of control transfers, the data stage needs to have the first parameter set to True to ensure the DTS bit is set correctly.

Definition at line 211 of file pic_usb.c.

References buffer_descriptor::addr, BC8, BC9, BSTALL, buffer_descriptor::count, DTS, DTSEN, ep_in_bd_location, ep_in_buffer_location, INCDIS, KEN, serial_print_int(), serial_print_str(), serial_putc(), buffer_descriptor::stat, uns16, uns8, and UOWN.

Referenced by usb_handle_class_request_callback().

Here is the call graph for this function:

Here is the caller graph for this function:

void usb_send_data_chunk (  ) 
void usb_send_empty_data_pkt (  ) 

Use this routine to send an data across the USB pipe on endpoint 0. This is the equivalent of sending a status acknowledge.

Definition at line 341 of file pic_usb.c.

References bd0in, buffer_0_in, delivery_buffer, delivery_buffer_size, delivery_bytes_max_send, delivery_bytes_sent, delivery_bytes_to_send, delivery_ptr, DTS, buffer_descriptor::stat, uns8, and usb_send_data_chunk().

Here is the call graph for this function:

void usb_send_one_byte ( uns8  data  ) 

Definition at line 370 of file pic_usb.c.

References bd0in, buffer_0_in, buffer_byte, delivery_buffer, delivery_buffer_size, delivery_bytes_max_send, delivery_bytes_sent, delivery_bytes_to_send, delivery_ptr, DTS, buffer_descriptor::stat, uns8, and usb_send_data_chunk().

Referenced by usb_handle_standard_request().

Here is the call graph for this function:

Here is the caller graph for this function:

void usb_setup (  ) 

usb_setup() configures the PIC USB hardware ready for use and prepares the internal data structures used to keep track of where the endpoint buffers are.

After calling usb_setup(), you are ready to call usb_enable_module() to actually start USB negotiations. Ensure that you have usb_handle_isr() in your interrupt service routine.

Definition at line 973 of file pic_usb.c.

References bd0in, bd0out_e, bd1in, bd1out, bd2in, bd2out, bd3in, bd3out, bd4in, bd4out, ep_in_bd_location, ep_out_bd_location, st_POWERED, and usb_state.

void usb_stall_ep0 (  ) 

Use this routine to send a stall on the control transfer endpoint - usually used to indicate that the requested function is not available.

Definition at line 203 of file pic_usb.c.

References bd0in, BSTALL, buffer_descriptor::stat, and UOWN.

Referenced by usb_handle_class_request_callback(), and usb_handle_standard_request().

Here is the caller graph for this function:

void usb_stall_on_in (  ) 

Definition at line 353 of file pic_usb.c.

References BC8, BC9, bd0in, BSTALL, DTS, DTSEN, INCDIS, KEN, buffer_descriptor::stat, and UOWN.


Variable Documentation

Definition at line 368 of file pic_usb.c.

Referenced by usb_send_one_byte().

Definition at line 62 of file pic_usb.c.

uns8* delivery_ptr

Store the usb address

Definition at line 54 of file pic_usb.c.

Referenced by usb_handle_reset(), usb_handle_standard_request(), and usb_handle_transaction().

Store the last setup data packet

Definition at line 52 of file pic_usb.c.

Referenced by usb_handle_class_ctrl_read_callback(), and usb_handle_class_ctrl_write_callback().

usb_state_type usb_state = st_POWERED

Store the current USB device state

Definition at line 50 of file pic_usb.c.

Referenced by usb_enable_module(), usb_get_state(), usb_handle_standard_request(), usb_handle_transaction(), and usb_setup().

Definition at line 64 of file pic_usb.c.

Referenced by usb_handle_reset(), usb_handle_standard_request(), and usb_handle_transaction().


Generated on Wed Dec 8 13:47:44 2010 for Pic Pack by  doxygen 1.6.1