SAM3S8/SD8 Software Package: USB Device Hardware Access Layer

SAM3S8/SD8 Software Package 1.2
Modules | Defines | Functions

# USB Device Hardware Access Layer
[USB Device Framework]

Collaboration diagram for USB Device Hardware Access Layer:

## Modules

| USB Device LEDs

## Defines

#define | CHIP_USB_UDP
#define | CHIP_USB_PULLUP_INTERNAL
#define | CHIP_USB_NUMENDPOINTS 8
#define | CHIP_USB_ENDPOINTS_MAXPACKETSIZE(i)
#define | CHIP_USB_ENDPOINTS_BANKS(i)
#define | UDP_CSR_RXDATA_BK (UDP_CSR_RX_DATA_BK0 | UDP_CSR_RX_DATA_BK1)
#define | UDP_ENDPOINT_DISABLED 0
#define | UDP_ENDPOINT_HALTED 1
#define | UDP_ENDPOINT_IDLE 2
#define | UDP_ENDPOINT_SENDING 3
#define | UDP_ENDPOINT_RECEIVING 4
#define | UDP_ENDPOINT_SENDINGM 5
#define | UDP_ENDPOINT_RECEIVINGM 6
#define | REG_NO_EFFECT_1_ALL
#define | SET_CSR(endpoint, flags)
#define | CLEAR_CSR(endpoint, flags)
#define | MBL_NbBuffer(i, o, size) (((i)>(o))?((i)-(o)):((i)+(size)-(o)))
#define | MBL_FULL 1
#define | MBL_NULL 2
#define | bmEP(bEP) (1 << (bEP))

## Functions

void | USBD_IrqHandler (void)
| Default SUPC interrupt handler for USBD.
void | USBD_HAL_ResetEPs (uint32_t bmEPs, uint8_t bStatus, uint8_t bKeepCfg)

Reset endpoints and disable them.

1. Terminate transfer if there is any, with given status;
2. Reset the endpoint & disable it.

void | USBD_HAL_CancelIo (uint32_t bmEPs)
uint8_t | USBD_HAL_ConfigureEP (const USBEndpointDescriptor *pDescriptor)
uint8_t | USBD_HAL_SetTransferCallback (uint8_t bEP, TransferCallback fCallback, void *pCbData)
uint8_t | USBD_HAL_SetupMblTransfer (uint8_t bEndpoint, USBDTransferBuffer *pMbList, uint16_t mblSize, uint16_t startOffset)
uint8_t | USBD_HAL_Write (uint8_t bEndpoint, const void *pData, uint32_t dLength)
uint8_t | USBD_HAL_Read (uint8_t bEndpoint, void *pData, uint32_t dLength)
void | USBD_HAL_Connect (void)
| Enable Pull-up, connect.
void | USBD_HAL_Disconnect (void)
| Disable Pull-up, disconnect.
void | USBD_HAL_RemoteWakeUp (void)
void | USBD_HAL_SetAddress (uint8_t address)
void | USBD_HAL_SetConfiguration (uint8_t cfgnum)
void | USBD_HAL_Init (void)
uint8_t | USBD_HAL_Stall (uint8_t bEP)
uint8_t | USBD_HAL_Halt (uint8_t bEndpoint, uint8_t ctl)
uint8_t | USBD_HAL_IsHighSpeed (void)
void | USBD_HAL_Suspend (void)
void | USBD_HAL_Activate (void)

## Detailed Description

Defines all structures and symbols for USB device hardware interface.

## Define Documentation

#define bmEP | ( |  | bEP ) | (1 << (bEP))

Get bitmap for an endpoint

Definition at line 64 of file USBD_HAL.h.

#define CHIP_USB_ENDPOINTS_BANKS | ( |  | i ) |

Value:

    ((i == 0) ? 1 : \
       ((i == 1) ? 2 : \
       ((i == 2) ? 2 : \
       ((i == 3) ? 1 : \
       ((i == 4) ? 2 : \
       ((i == 5) ? 2 : \
       ((i == 6) ? 2 : \
       ((i == 7) ? 2 : 0 ))))))))

Endpoints Number of Bank

Definition at line 80 of file USBD_HAL.c.

#define CHIP_USB_ENDPOINTS_MAXPACKETSIZE | ( |  | i ) |

Value:

    ((i == 0) ? 64 : \
       ((i == 1) ? 64 : \
       ((i == 2) ? 64 : \
       ((i == 3) ? 64 : \
       ((i == 4) ? 512 : \
       ((i == 5) ? 512 : \
       ((i == 6) ? 64 : \
       ((i == 7) ? 64 : 0 ))))))))

Endpoints max paxcket size

Definition at line 69 of file USBD_HAL.c.

#define CHIP_USB_NUMENDPOINTS 8

Number of USB endpoints

Definition at line 66 of file USBD_HAL.c.

#define CHIP_USB_PULLUP_INTERNAL

Indicates chip has an internal pull-up.

Definition at line 63 of file USBD_HAL.c.

#define CHIP_USB_UDP

Indicates chip has an UDP Full Speed.

Definition at line 60 of file USBD_HAL.c.

#define CLEAR_CSR | ( |  | endpoint,
|  |  | flags
| ) |  |

Value:

    { \
        volatile uint32_t reg; \
        int32_t nop_count ; \
        reg = UDP->UDP_CSR[endpoint]; \
        reg |= REG_NO_EFFECT_1_ALL; \
        reg &= ~((uint32_t)(flags)); \
        UDP->UDP_CSR[endpoint] = reg; \
        for( nop_count=0; nop_count<15; nop_count++ ) {\
            nop();\
        }\
    }

Clears the specified bit(s) in the UDP_CSR register.

Parameters:

  endpoint | The endpoint number of the CSR to process.
  flags | The bitmap to clear to 0.

Definition at line 188 of file USBD_HAL.c.

#define MBL_FULL 1

Buffer list is full

Definition at line 210 of file USBD_HAL.c.

#define MBL_NbBuffer | ( |  | i,
|  |  | o,
|  |  | size
| ) |  | (((i)>(o))?((i)-(o)):((i)+(size)-(o)))

Get Number of buffer in Multi-Buffer-List

Parameters:

  i | input index
  o | output index
  size | list size

Definition at line 207 of file USBD_HAL.c.

#define MBL_NULL 2

Buffer list is null

Definition at line 212 of file USBD_HAL.c.

#define REG_NO_EFFECT_1_ALL

Value:

    UDP_CSR_RX_DATA_BK0 | UDP_CSR_RX_DATA_BK1 \
                                    |UDP_CSR_STALLSENT | UDP_CSR_RXSETUP \
                                    |UDP_CSR_TXCOMP

## "UDP CSR register access"

This page lists the macros to access UDP CSR register.

In a preemptive environment, set or clear the flag and wait for a time of 1 UDPCK clock cycle and 1 peripheral clock cycle. However, RX_DATA_BK0, TXPKTRDY, RX_DATA_BK1 require wait times of 3 UDPCK clock cycles and 5 peripheral clock cycles before accessing DPR. See datasheet

!Macros

- CLEAR_CSR
- SET_CSR Bitmap for all status bits in CSR.

Definition at line 159 of file USBD_HAL.c.

#define SET_CSR | ( |  | endpoint,
|  |  | flags
| ) |  |

Value:

    { \
            volatile uint32_t reg; \
            int32_t nop_count ; \
            reg = UDP->UDP_CSR[endpoint] ; \
            reg |= REG_NO_EFFECT_1_ALL; \
            reg |= (flags); \
            UDP->UDP_CSR[endpoint] = reg; \
            for( nop_count=0; nop_count<15; nop_count++ ) {\
                nop();\
            }\
        }

Sets the specified bit(s) in the UDP_CSR register.

Parameters:

  endpoint | The endpoint number of the CSR to process.
  flags | The bitmap to set to 1.

Definition at line 169 of file USBD_HAL.c.

#define UDP_CSR_RXDATA_BK (UDP_CSR_RX_DATA_BK0 | UDP_CSR_RX_DATA_BK1)

## "UDP Register field values"

This section lists the initialize values of UDP registers.

### Values

- UDP_RXDATA Bit mask for both banks of the UDP_CSR register.

Definition at line 99 of file USBD_HAL.c.

#define UDP_ENDPOINT_DISABLED 0

## "UDP Endpoint states"

This page lists the endpoint states.

### States

- UDP_ENDPOINT_DISABLED
- UDP_ENDPOINT_HALTED
- UDP_ENDPOINT_IDLE
- UDP_ENDPOINT_SENDING
- UDP_ENDPOINT_RECEIVING
- UDP_ENDPOINT_SENDINGM
- UDP_ENDPOINT_RECEIVINGM Endpoint states: Endpoint is disabled

Definition at line 117 of file USBD_HAL.c.

#define UDP_ENDPOINT_HALTED 1

Endpoint states: Endpoint is halted (i.e. STALLs every request)

Definition at line 119 of file USBD_HAL.c.

#define UDP_ENDPOINT_IDLE 2

Endpoint states: Endpoint is idle (i.e. ready for transmission)

Definition at line 121 of file USBD_HAL.c.

#define UDP_ENDPOINT_RECEIVING 4

Endpoint states: Endpoint is receiving data

Definition at line 125 of file USBD_HAL.c.

#define UDP_ENDPOINT_RECEIVINGM 6

Endpoint states: Endpoint is receiving MBL

Definition at line 129 of file USBD_HAL.c.

#define UDP_ENDPOINT_SENDING 3

Endpoint states: Endpoint is sending data

Definition at line 123 of file USBD_HAL.c.

#define UDP_ENDPOINT_SENDINGM 5

Endpoint states: Endpoint is sending MBL

Definition at line 127 of file USBD_HAL.c.

## Function Documentation

void USBD_HAL_Activate | ( | void | ) |

Activate USB Device HW Interface

1. Enable USB Peripheral
2. Enable USB Clock
3. Enable transceiver

Definition at line 1658 of file USBD_HAL.c.

void USBD_HAL_CancelIo | ( | uint32_t | bmEPs ) |

Cancel pending READ/WRITE

Parameters:

  bmEPs | Bitmap for endpoints to reset.

Note:
  EP callback is invoked with USBD_STATUS_CANCELED.

Definition at line 1236 of file USBD_HAL.c.

uint8_t USBD_HAL_ConfigureEP | ( | const USBEndpointDescriptor * | pDescriptor ) |

Configures an endpoint according to its endpoint Descriptor.

Parameters:

  pDescriptor | Pointer to an endpoint descriptor.

Definition at line 1260 of file USBD_HAL.c.

Here is the call graph for this function:

void USBD_HAL_Connect | ( | void | ) |

Enable Pull-up, connect.

1. Enable HW access if needed
2. Enable Pull-Up
3. Disable HW access if needed

Definition at line 1458 of file USBD_HAL.c.

void USBD_HAL_Disconnect | ( | void | ) |

Disable Pull-up, disconnect.

1. Enable HW access if needed
2. Disable PULL-Up
3. Disable HW access if needed

Definition at line 1472 of file USBD_HAL.c.

uint8_t USBD_HAL_Halt | ( | uint8_t | bEndpoint,
|  | uint8_t | ctl
| ) |  |

Sets/Clear/Get the HALT state on the endpoint. In HALT state, the endpoint should keep stalling any packet.

Parameters:

  bEndpoint | Endpoint number.
  ctl | Control code CLR/HALT/READ. 0: Clear HALT state; 1: Set HALT state; .: Return HALT status.

Returns:
  USBD_STATUS_INVALID_PARAMETER if endpoint not exist, otherwise endpoint halt status.

Definition at line 1577 of file USBD_HAL.c.

void USBD_HAL_Init | ( | void | ) |

Initializes the USB HW Access driver.

Definition at line 1528 of file USBD_HAL.c.

Here is the call graph for this function:

uint8_t USBD_HAL_IsHighSpeed | ( | void | ) |

Indicates if the device is running in high or full-speed. Always returns 0 since UDP does not support high-speed mode.

Definition at line 1632 of file USBD_HAL.c.

uint8_t USBD_HAL_Read | ( | uint8_t | bEndpoint,
|  | void * | pData,
|  | uint32_t | dLength
| ) |  |

Reads incoming data on an USB endpoint This methods sets the transfer descriptor and activate the endpoint interrupt. The actual transfer is then carried out by the endpoint interrupt handler. The Read operation finishes either when the buffer is full, or a short packet (inferior to endpoint maximum size) is received.

*The buffer must be kept allocated until the transfer is finished*.

Parameters:

  bEndpoint | Endpoint number.
  pData | Pointer to a data buffer.
  dLength | Size of the data buffer in bytes.

Returns:
  USBD_STATUS_SUCCESS if the read operation has been started; otherwise, the corresponding error code.

Definition at line 1441 of file USBD_HAL.c.

void USBD_HAL_RemoteWakeUp | ( | void | ) |

Starts a remote wake-up procedure.

Definition at line 1482 of file USBD_HAL.c.

void USBD_HAL_ResetEPs | ( | uint32_t | bmEPs,
|  | uint8_t | bStatus,
|  | uint8_t | bKeepCfg
| ) |  |

Reset endpoints and disable them.

1. Terminate transfer if there is any, with given status;
2. Reset the endpoint & disable it.

Parameters:

  bmEPs | Bitmap for endpoints to reset.
  bStatus | Status passed to terminate transfer on endpoint.
  bKeepCfg | 1 to keep old endpoint configuration.

Note:
  Use USBD_HAL_ConfigureEP() to configure and enable endpoint if not keeping old configuration.

See also:
  USBD_HAL_ConfigureEP().

Definition at line 1188 of file USBD_HAL.c.

void USBD_HAL_SetAddress | ( | uint8_t | address ) |

Sets the device address to the given value.

Parameters:

  address | New device address.

Definition at line 1499 of file USBD_HAL.c.

void USBD_HAL_SetConfiguration | ( | uint8_t | cfgnum ) |

Sets the current device configuration.

Parameters:

  cfgnum | - Configuration number to set.

Definition at line 1513 of file USBD_HAL.c.

uint8_t USBD_HAL_SetTransferCallback | ( | uint8_t | bEP,
|  | TransferCallback | fCallback,
|  | void * | pCbData
| ) |  |

Set callback for a USB endpoint for transfer (read/write).

Parameters:

  bEP | Endpoint number.
  fCallback | Optional callback function to invoke when the transfer is complete.
  pCbData | Optional pointer to data to the callback function.

Returns:
  USBD_STATUS_SUCCESS or USBD_STATUS_LOCKED if endpoint is busy.

Definition at line 1333 of file USBD_HAL.c.

uint8_t USBD_HAL_SetupMblTransfer | ( | uint8_t | bEndpoint,
|  | USBDTransferBuffer * | pMbList,
|  | uint16_t | mblSize,
|  | uint16_t | startOffset
| ) |  |

Configure an endpoint to use multi-buffer-list transfer mode. The buffers can be added by _Read/_Write function.

Parameters:

  pMbList | Pointer to a multi-buffer list used, NULL to disable MBL.
  mblSize | Multi-buffer list size (number of buffers can be queued)
  startOffset | When number of buffer achieve this offset transfer start

Definition at line 1357 of file USBD_HAL.c.

uint8_t USBD_HAL_Stall | ( | uint8_t | bEP ) |

Causes the given endpoint to acknowledge the next packet it receives with a STALL handshake except setup request.

Parameters:

  bEP | Endpoint number.

Returns:
  USBD_STATUS_SUCCESS or USBD_STATUS_LOCKED.

Definition at line 1551 of file USBD_HAL.c.

void USBD_HAL_Suspend | ( | void | ) |

Suspend USB Device HW Interface

1. Disable transceiver
2. Disable USB Clock
3. Disable USB Peripheral

Definition at line 1644 of file USBD_HAL.c.

uint8_t USBD_HAL_Write | ( | uint8_t | bEndpoint,
|  | const void * | pData,
|  | uint32_t | dLength
| ) |  |

Sends data through a USB endpoint. Sets up the transfer descriptor, writes one or two data payloads (depending on the number of FIFO bank for the endpoint) and then starts the actual transfer. The operation is complete when all the data has been sent.

*If the size of the buffer is greater than the size of the endpoint (or twice the size if the endpoint has two FIFO banks), then the buffer must be kept allocated until the transfer is finished*. This means that it is not possible to declare it on the stack (i.e. as a local variable of a function which returns after starting a transfer).

Parameters:

  bEndpoint | Endpoint number.
  pData | Pointer to a buffer with the data to send.
  dLength | Size of the data buffer.

Returns:
  USBD_STATUS_SUCCESS if the transfer has been started; otherwise, the corresponding error status code.

Definition at line 1417 of file USBD_HAL.c.

void USBD_IrqHandler | ( | void | ) |

Default SUPC interrupt handler for USBD.

USBD (UDP) interrupt handler Manages device resume, suspend, end of bus reset. Forwards endpoint events to the appropriate handler.

/ Start Of Frame (SOF)

Definition at line 1064 of file USBD_HAL.c.

Here is the call graph for this function:
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines