Chapter 4.USB Stack (Target)
The USB software is implemented in the form of a USB stack comprising of three layers.
At the top of the stack are the USB Device Classes consisting of HID, CDC and MSC which are all described later.
In the middle is a core layer (USBCore) that handles standard device requests. At the bottom is a hardware abstraction layer (HAL) that
provides a hardware independent API for the upper layers.
This modular design means this software can be still be used even if developing a proprietary USB interface. For example a proprietary
module could be implemented by calling functions directly exposed by both the USBHAL API and USBCore API.
4.1.Hardware Abstraction Layer
The HAL is a hardware specific layer that provides a non-hardware specific API. The HAL supports the following transfer modes:
Control (Setup, Data IN/OUT, Status)
Bulk (IN and OUT)
Interrupt (IN)
Some HAL implementations may not be able to support all these modes but the H8SX1664 implementation does.
Here is a list of the functions that make up the USBHAL API.
Name Description
USBHAL_Init
Initialise the HAL. Register callback functions. If using the USB Core layer then this is done
automatically.
USBHAL_Config_Get
Get the current HAL configuration.
USBHAL_Config_Set
Set the current HAL configuration.
USBHAL_Control_ACK
Generate an ACK on the Control IN pipe. (Used following a setup packet)
USBHAL_Control_IN
Send data on the Control IN pipe. (Used following a setup packet)
USBHAL_Control_OUT
Receive data on the Control OUT pipe. (Used following a setup packet)
USBHAL_Bulk_IN
Send data on the Bulk IN pipe.
USBHAL_Bulk_OUT
Receive data on the Control OUT pipe.
USBHAL_Interrupt_IN
Send data on the Control IN pipe.
USBHAL_Reset
Reset this module. (Following an error).
USBHAL_Control_Stall
Stall the control pipe. (Used following a setup packet)
USBHAL_Bulk_IN_Stall
Stall the Bulk IN pipe.
USBHAL_Bulk_OUT_Stall
Stall the Bulk OUT pipe.
USBHAL_Interrupt_IN_Stall
Stall the Interrupt IN pipe.
USBHALInterruptHandler
The system must be setup so that this gets called when any USB Interrupt occurs.
The HAL module consists of the following files:-
usb_hal.c
usb_hal.h.
usb_common.h
6