pic_usb.h File Reference

Pic USB routines. More...

#include "pic_utils.h"
Include dependency graph for pic_usb.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  buffer_descriptor
struct  CDC_ACM_functional_descriptor
struct  CDC_call_mgt_functional_descriptor
struct  CDC_header_functional_descriptor
struct  CDC_union_functional_descriptor
struct  configuration_descriptor
struct  device_descriptor
struct  endpoint_descriptor
struct  hid_descriptor
struct  interface_descriptor
struct  setup_data_packet

Defines

#define BC8   0
#define BC9   1
#define BSTALL   2
#define DATA_STAGE_DIR   7
#define dt_CONFIGURATION   0x02
#define dt_CS_INTERFACE   0x24
#define dt_DEBUG   0x0a
#define dt_DEVICE   0x01
#define dt_DEVICE_QUALIFIER   0x06
#define dt_ENDPOINT   0x05
#define dt_HID   0x21
#define dt_HID_REPORT   0x22
#define dt_INTERFACE   0x04
#define dt_INTERFACE_ASSOC   0x0b
#define dt_INTERFACE_POWER   0x08
#define dt_OTG   0x09
#define dt_OTHER_SPEED_CONFIG   0x07
#define dt_STRING   0x03
#define DTS   6
#define DTSEN   3
#define INCDIS   4
#define KEN   5
#define PID0   2
#define PID1   3
#define PID2   4
#define PID3   5
#define pid_ACK   0b00000010
#define pid_DATA0   0b00000011
#define pid_DATA1   0b00001011
#define pid_DATA2   0b00000111
#define pid_IN   0b00001001
#define pid_MDATA   0b00001111
#define pid_NAK   0b00001010
#define pid_NYET   0b00000110
#define pid_OUT   0b00000001
#define pid_SETUP   0b00001101
#define pid_SOF   0b00000101
#define pid_STALL   0b00001110
#define req_Clear_Feature   0x01
#define req_Get_Configuration   0x08
#define req_Get_Descriptor   0x06
#define req_Get_Interface   0x0a
#define req_Get_Status   0x00
#define req_Set_Address   0x05
#define req_Set_Configuration   0x09
#define req_Set_Descriptor   0x07
#define req_Set_Feature   0x03
#define req_Set_Interface   0x0b
#define req_Synch_Frame   0x0c
#define REQUEST_TYPE0   5
#define REQUEST_TYPE1   6
#define UOWN   7
#define usb_send_status_ack()   usb_send_empty_data_pkt()

Enumerations

enum  control_mode_type {
  cm_IDLE, cm_CTRL_WRITE_DATA_STAGE, cm_CTRL_WRITE_DATA_STAGE_CLASS, cm_CTRL_READ_DATA_STAGE,
  cm_CTRL_READ_DATA_STAGE_CLASS, cm_CTRL_READ_AWAITING_STATUS, cm_CTRL_WRITE_SENDING_STATUS
}
enum  usb_state_type { st_POWERED, st_DEFAULT, st_ADDRESS, st_CONFIGURED }
enum  usb_status_type { us_IDLE, us_SET_ADDRESS }

Functions

void turn_usb_ints_on ()
 Turn on USB interrupts.
void usb_device_configured_callback ()
 Callback routine triggered when a successful intial USB negotiation has completed.
void usb_enable_module ()
 Enables the USB hardware and starts USB negotiations.
void usb_ep_data_in_callback (uns8 end_point, uns16 byte_count)
 Callback routine triggered when data has been sent to the host.
void usb_ep_data_out_callback (uns8 end_point, uns8 *buffer_location, uns16 byte_count)
 Callback routine triggered when data has been sent to the device.
void usb_get_descriptor_callback (uns8 descriptor_type, uns8 descriptor_num, uns8 **rtn_descriptor_ptr, uns16 *rtn_descriptor_size)
 Callback routine triggered when the descriptor is requested by the host.
usb_state_type usb_get_state ()
 Query the current state of the USB connection.
void usb_handle_class_ctrl_read_callback ()
 Callback routine for a class control read.
void usb_handle_class_ctrl_write_callback (uns8 *data, uns16 count)
 Callback routine for a class control write.
void usb_handle_class_request_callback (setup_data_packet sdp)
 Callback routine for a control transfer request that is placed on the class.
void usb_handle_isr ()
 Handle USB interrupts.
void usb_send_data (uns8 ep, uns8 *data, uns8 send_count, bit first)
 Send data over an endpoint pipe.
void usb_send_empty_data_pkt ()
 Send an empty data packet.
void usb_setup ()
 Setup USB hardware ready for use.
void usb_SOF_callback (uns16 frame)
 Callback routine triggered each time a start of frame (SOF) has been received.
void usb_stall_ep0 ()
 Send a stall on control transfer endpoint.

Variables

control_mode_type control_mode
uns8 usb_address
setup_data_packet usb_sdp
usb_state_type usb_state

Detailed Description

Put the following in your config.h

Use this define if you would like to get USB negotiation and data transfer information out the serial (UART) port. You'll also need to include pic_serial.c in your project. define USB_DEBUG

Use this define if you would like a high level (ie, lots) of USB debug information printed out the serial (UART) port. define USB_DEBUG_HIGH

Define the highest numbered endpoint you will use (in this case, we choose 3). define USB_HIGHEST_EP 3

Define either USB_SELF_POWERED or USB_BUS_POWERED define USB_SELF_POWERED define USB_BUS_POWERED

Define your endpoint buffers. These start at 0x500 for a 18f4550. You'll always need endpoint 0, which is the control transfer endpoint, and others as well depending on your use. You don't have to declare the endpoints you don't use, even if they're not sequential.

define USB_EP0_OUT_SIZE 8 define USB_EP0_OUT_ADDR 0x0200

define USB_EP0_IN_SIZE 8 define USB_EP0_IN_ADDR 0x0208

EP1 not used

define USB_EP2_IN_SIZE 8 define USB_EP2_IN_ADDR 0x0210

define USB_EP3_OUT_SIZE 8 define USB_EP3_OUT_ADDR 0x0218 define USB_EP3_IN_SIZE 8 define USB_EP3_IN_ADDR 0x0220

Use this define if you want to get a callback each SOF (Start Of Frame), generally every 1ms define USB_CALLBACK_ON_SOF if you define it, you'll need to include this routine in your code: void usb_SOF_callback(uns16 frame) { }

Use this define if you would like to know when your device has been configured and is ready for use define USB_CALLBACK_ON_DEVICE_CONFIGURED if you define it, you'll need to include this routine in your code: void usb_device_configured_callback() { }

Use this define if your device uses class control transfers, eg, CDC (virtual serial port) is one that does define USB_CALLBACK_ON_CTRL_CLASS if you define it, you'll need to include these routines in your code: void usb_handle_class_ctrl_read_callback(); void usb_handle_class_ctrl_write_callback(uns8 *data, uns16 count); void usb_handle_class_request_callback(setup_data_packet sdp);

Use this define if you would like to get notified when data has arrived or been succesfully sent define USB_EP_DATA_CALLBACK if you define it, you'll need to include these routines in your code: void usb_ep_data_out_callback(uns8 end_point, uns8 *buffer_location, uns16 byte_count); void usb_ep_data_in_callback(uns8 end_point, uns16 byte_count);

Put the following in your ISR

usb_handle_isr();

Put the following in your system setup routine

Setup USB usb_setup();

Turn on USB interrupts void turn_usb_ints_on();

Turn on global interrupts turn_global_ints_on();

When you're ready to start the USB subsystem and negotiate address, send descriptors etc, call

usb_enable_module();

Definition in file pic_usb.h.


Define Documentation

#define BC8   0
#define BC9   1
#define BSTALL   2
#define DATA_STAGE_DIR   7

Definition at line 178 of file pic_usb.h.

Referenced by usb_handle_transaction().

#define dt_CONFIGURATION   0x02

Definition at line 278 of file pic_usb.h.

#define dt_CS_INTERFACE   0x24

Definition at line 291 of file pic_usb.h.

#define dt_DEBUG   0x0a

Definition at line 286 of file pic_usb.h.

#define dt_DEVICE   0x01

Definition at line 277 of file pic_usb.h.

#define dt_DEVICE_QUALIFIER   0x06

Definition at line 282 of file pic_usb.h.

#define dt_ENDPOINT   0x05

Definition at line 281 of file pic_usb.h.

#define dt_HID   0x21

Definition at line 288 of file pic_usb.h.

#define dt_HID_REPORT   0x22

Definition at line 289 of file pic_usb.h.

#define dt_INTERFACE   0x04

Definition at line 280 of file pic_usb.h.

#define dt_INTERFACE_ASSOC   0x0b

Definition at line 287 of file pic_usb.h.

#define dt_INTERFACE_POWER   0x08

Definition at line 284 of file pic_usb.h.

#define dt_OTG   0x09

Definition at line 285 of file pic_usb.h.

#define dt_OTHER_SPEED_CONFIG   0x07

Definition at line 283 of file pic_usb.h.

#define dt_STRING   0x03

Definition at line 279 of file pic_usb.h.

#define DTS   6
#define DTSEN   3
#define INCDIS   4
#define KEN   5
#define PID0   2

Definition at line 206 of file pic_usb.h.

#define PID1   3

Definition at line 205 of file pic_usb.h.

#define PID2   4

Definition at line 204 of file pic_usb.h.

#define PID3   5

Definition at line 203 of file pic_usb.h.

#define pid_ACK   0b00000010

Definition at line 255 of file pic_usb.h.

Referenced by usb_handle_transaction().

#define pid_DATA0   0b00000011

Definition at line 248 of file pic_usb.h.

#define pid_DATA1   0b00001011

Definition at line 249 of file pic_usb.h.

#define pid_DATA2   0b00000111

Definition at line 250 of file pic_usb.h.

#define pid_IN   0b00001001

Definition at line 242 of file pic_usb.h.

Referenced by usb_handle_transaction().

#define pid_MDATA   0b00001111

Definition at line 251 of file pic_usb.h.

#define pid_NAK   0b00001010

Definition at line 256 of file pic_usb.h.

#define pid_NYET   0b00000110

Definition at line 258 of file pic_usb.h.

#define pid_OUT   0b00000001

Definition at line 241 of file pic_usb.h.

Referenced by usb_handle_transaction().

#define pid_SETUP   0b00001101

Definition at line 244 of file pic_usb.h.

Referenced by usb_handle_transaction().

#define pid_SOF   0b00000101

Definition at line 243 of file pic_usb.h.

#define pid_STALL   0b00001110

Definition at line 257 of file pic_usb.h.

#define req_Clear_Feature   0x01

Definition at line 264 of file pic_usb.h.

#define req_Get_Configuration   0x08

Definition at line 269 of file pic_usb.h.

#define req_Get_Descriptor   0x06

Definition at line 267 of file pic_usb.h.

Referenced by usb_handle_standard_request().

#define req_Get_Interface   0x0a

Definition at line 271 of file pic_usb.h.

Referenced by usb_handle_standard_request().

#define req_Get_Status   0x00

Definition at line 263 of file pic_usb.h.

Referenced by usb_handle_standard_request().

#define req_Set_Address   0x05

Definition at line 266 of file pic_usb.h.

Referenced by usb_handle_standard_request().

#define req_Set_Configuration   0x09

Definition at line 270 of file pic_usb.h.

Referenced by usb_handle_standard_request().

#define req_Set_Descriptor   0x07

Definition at line 268 of file pic_usb.h.

#define req_Set_Feature   0x03

Definition at line 265 of file pic_usb.h.

#define req_Set_Interface   0x0b

Definition at line 272 of file pic_usb.h.

#define req_Synch_Frame   0x0c

Definition at line 273 of file pic_usb.h.

#define REQUEST_TYPE0   5

Definition at line 181 of file pic_usb.h.

Referenced by usb_handle_transaction().

#define REQUEST_TYPE1   6

Definition at line 180 of file pic_usb.h.

Referenced by usb_handle_transaction().

#define UOWN   7
 
#define usb_send_status_ack (  )     usb_send_empty_data_pkt()

Send a status acknowledge by sending an empty data packet

Definition at line 397 of file pic_usb.h.

Referenced by usb_handle_class_ctrl_write_callback(), usb_handle_class_request_callback(), and usb_handle_standard_request().


Enumeration Type Documentation

Describe the state of the control transfer

Enumerator:
cm_IDLE 

No control transfer taking place

cm_CTRL_WRITE_DATA_STAGE 

Device receiving data during the data stage

cm_CTRL_WRITE_DATA_STAGE_CLASS 

Device receiving data during the data stage destined for the class

cm_CTRL_READ_DATA_STAGE 

Device sending data during the data stage

cm_CTRL_READ_DATA_STAGE_CLASS 

Device class is sending data during the data stage

cm_CTRL_READ_AWAITING_STATUS 

Device is awaiting reception of status after sending data

cm_CTRL_WRITE_SENDING_STATUS 

Device is sending status after receiving data

Definition at line 211 of file pic_usb.h.

Handle the different states that USB device can be in

Enumerator:
st_POWERED 

USB device is powered up, ready to start negotiating

st_DEFAULT 

USB device is now negotiating

st_ADDRESS 

USB device now has an address

st_CONFIGURED 

USB device is completely configured and ready to rock and roll

Definition at line 140 of file pic_usb.h.

Handle the special case of when we send a status ack and THEN change the address. So we need to know that the USB device is in that micro state (ie, received the new address but not yet sent the status

Enumerator:
us_IDLE 
us_SET_ADDRESS 

Definition at line 232 of file pic_usb.h.


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_device_configured_callback (  ) 

Once descriptors have been received by the host and the host has selected a configuration to use, this routine is triggered. Typically this means that negotiations have completed successfully and an appropriate driver has been loaded.

In order for this callback to be triggered, you must define USB_CALLBACK_ON_DEVICE_CONFIGURED in your config.h

Referenced by usb_handle_standard_request().

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.

void usb_ep_data_in_callback ( uns8  end_point,
uns16  byte_count 
)

If you have called usb_send_data to transfer data to the host, this routine will be fired once this data has been transferred. You may send more data by using usb_send_data(). Since the current PicPack USB library supports only single buffering, transfer speed is limited by how quickly you can refill the buffer again. In the future, we may support double buffering (ping poing buffering) which will most likely improve transfer speeds (to be fair, transfer performance has not been a limiting factor in tests so far).

In order for this callback to be triggered, you must define USB_EP_DATA_CALLBACK in your config.h

Parameters:
end_point The endpoint on which the data was transferred
byte_count The number of bytes that were actually transferred

Definition at line 323 of file usb_cdc_class.c.

References serial_print_int(), serial_print_str(), and usb_cdc_handle_tx().

Referenced by usb_handle_transaction().

Here is the call graph for this function:

Here is the caller graph for this function:

void usb_ep_data_out_callback ( uns8  end_point,
uns8 *  buffer_location,
uns16  byte_count 
)

If data is sent to the device and the endpoint is not endpoint 0 (the control transfer endpoint) then this routine is called. Since the routine is passed the actual hardware buffer location, it is important to pull data out of the buffer as soon as possible in order to free up the buffer to receive more data. The buffer is re-primed only once this routine completes since PicPack only supports single-buffered mode. In the future, we may look at supporting double buffering (ping-pong buffering) in order to be able to receive more data even while this routine is being called.

In order for this callback to be triggered, you must define USB_EP_DATA_CALLBACK in your config.h

Parameters:
end_point The endpoint the data was sent do
buffer_lcoation The memory location of the USB buffer where the data was received into
byte_count The number of bytes received

Definition at line 283 of file usb_cdc_class.c.

References cdc_rx_buffer, cdc_rx_end, cdc_rx_start, platform_leds_flash(), serial_print_int(), serial_print_str(), and uns8.

Referenced by usb_handle_transaction().

Here is the call graph for this function:

Here is the caller graph for this function:

void usb_get_descriptor_callback ( uns8  descriptor_type,
uns8  descriptor_num,
uns8 **  rtn_descriptor_ptr,
uns16 *  rtn_descriptor_size 
)

Once negotiations start, descriptors are quested by the host. The device must be able to respond to these requests. Typically, this routine consists of a switch statement depending on the descriptor_type parameter. The descriptor_num is used to specify which of the descriptor_type descriptors are required, since they may be several (for example, string descriptors).

Since descriptors are specific to a particular device (and project), this callback routine and the associated descriptors are put in a file called usb_config_xxxx.c and placed in the project workspace. This is because while the descriptors could have been provided as part of the PicPack library, you will almost always want to change them to suit your application, even if only for changing the vendor and device IDs and serial numbers.

At present, descriptors are required to be in RAM.

Since descriptor requests are an essential part of the USB protocol, this callback routine is mandatory.

Referenced by usb_handle_standard_request().

Here is the caller graph for this function:

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_class_ctrl_read_callback (  ) 

When a control transfer is taking place, this routine is called to indicate that a control read for the class has taken place. Since everything in USB land is all about what has just happened, this callback will occur after data has been transferred to the host. If you wish to send more data to the host, use usb_send_data(), or if your control read has sent all the data required, you will need to indicate that the state has changed by setting the control_mode variable to cm_CTRL_READ_AWAITING_STATUS. This will indicate to the stack that it should now wait for the status packet before completing the control transfer.

To allow this callback to trigger, ensure you define USB_CALLBACK_ON_CLASS_CTRL in your config.h

Definition at line 268 of file usb_cdc_class.c.

References setup_data_packet::bRequest, cm_CTRL_READ_AWAITING_STATUS, control_mode, req_GET_LINE_CODING, serial_print_int(), serial_print_str(), and usb_sdp.

Referenced by usb_handle_transaction().

Here is the call graph for this function:

Here is the caller graph for this function:

void usb_handle_class_ctrl_write_callback ( uns8 *  data,
uns16  count 
)

When a control transfer is taking place, this routine is called to indicate that a control write for the class has taken place. Since everything in USB land is all about what has just happened, this callback will occur after data has been received by the device. If you expect more data from the host, it will arrive in due course since endpoint 0 will be primed for more data automatically. If you have received all the data from the host, you will need to set the control_mode state variable to cm_CTRL_WRITE_SENDING_STATUS and then actually send the status by calling usb_send_status_ack(). Once the status has actually been sent, the control_mode state will automatically change to cm_IDLE to indicate the transfer has completed.

To allow this callback to trigger, ensure you define USB_CALLBACK_ON_CLASS_CTRL in your config.h

Definition at line 168 of file usb_cdc_class.c.

References long_union::as_byte_array, long_union::as_long, setup_data_packet::bRequest, class_data, cm_CTRL_WRITE_SENDING_STATUS, control_mode, current_bit_rate, line_coding::data_bits, line_coding::dte_rate, line_coding::parity, platform_leds_flash(), req_SET_LINE_CODING, serial_print_int(), serial_print_int_hex(), serial_print_str(), serial_putc(), serial_setup(), serial_tx_empty(), serial_tx_isr(), line_coding::stop_bits, usb_sdp, and usb_send_status_ack.

Referenced by usb_handle_transaction().

Here is the call graph for this function:

Here is the caller graph for this function:

void usb_handle_class_request_callback ( setup_data_packet  sdp  ) 

After receiving a setup packet, where the request is placed on the class, this routine is called. In usb_handle_class_request_callback, you can set up ready for the data stage of the control transfer. The direction of the data stage can be determined by examining test_bit(sdp.bRequest, DATA_STAGE_DIR) although generally it appears to be obvious from the request. The request is stored in sdp.bRequest.

Typically, if it is a control read transfer (that is, it is a request by the host for data), then you will need to move the control_mode state variable to cm_CTRL_READ_DATA_STAGE_CLASS and send data using usb_send_data(). If you only intend to send one packet, you can immediately move the control_mode state variable to cm_CTRL_READ_AWAITING_STATUS to indicate you are waiting for the status to arrive. You could wait for the usb_handle_class_ctrl_read callback and do it (move to cm_CTROL_READ_AWAITING_STATUS) but the PicPack USB stack can handle the control read event for you if you've already switched states.

If it is a control write transfer (that is, it is a request by the host to send data to the device), then you will need to move the control_mode state variable to cm_CTRL_WRITE_DATA_STAGE_CLASS. Then, the usb_handle_class_ctrl_write will be fired when data is received by the device in the data stage.

To allow this callback to trigger, ensure you define USB_CALLBACK_ON_CLASS_CTRL in your config.h

Definition at line 112 of file usb_cdc_class.c.

References long_union::as_byte_array, setup_data_packet::bRequest, cm_CTRL_READ_AWAITING_STATUS, cm_CTRL_READ_DATA_STAGE_CLASS, cm_CTRL_WRITE_DATA_STAGE_CLASS, cm_CTRL_WRITE_SENDING_STATUS, control_mode, line_coding::data_bits, line_coding::dte_rate, line_coding::parity, req_GET_IDLE, req_GET_LINE_CODING, req_GET_PROTOCOL, req_GET_REPORT, req_SET_CONTROL_LINE_STATE, req_SET_IDLE, req_SET_LINE_CODING, req_SET_PROTOCOL, req_SET_REPORT, serial_print_int(), serial_print_int_hex(), serial_print_str(), serial_putc(), line_coding::stop_bits, uns8, usb_send_data(), usb_send_status_ack, usb_stall_ep0(), setup_data_packet::wLength, and setup_data_packet::wValue.

Referenced by usb_handle_transaction().

Here is the call graph for this function:

Here is the caller graph for this function:

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_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_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_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_SOF_callback ( uns16  frame  ) 

Frames in USB occur each 1ms. A SOF packet is sent to each device at the start of each frame. This is a really neat way of getting a 1ms timer without any further work.

Parameters:
frame The frame number. Frames will wrap at 65535.

Definition at line 478 of file usb_cdc_class.c.

References usb_cdc_handle_tx().

Referenced by usb_handle_isr().

Here is the call graph for this function:

Here is the caller graph for this function:

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:


Variable Documentation

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().

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().


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