PHDC Configuration
General Configuration
Some constants are available to customize the class. These constants are located in the usbd_cfg.h
file. Table - Configuration Constants Summary shows a description of each of them.
Constant | Description | Possible Values |
---|---|---|
USBD_PHDC_CFG_MAX_NBR_DEV | Configures the maximum number of class instances. Unless you plan on having multiple configuration or interfaces using different class instances, this can be set to 1. | From 1 to 254. Default value is 1. |
USBD_PHDC_CFG_MAX_NBR_CFG | Configures the maximum number of configuration in which PHDC is used. Keep in mind that if you use a high-speed device, two configurations will be built, one for full-speed and another for high-speed. Default value is 2. | From 1 (low- and full-speed) or 2 (high-speed) to 254. Default value is 2. |
USBD_PHDC_CFG_DATA_OPAQUE_MAX_LEN | Maximum length in octets that opaque data can be. | Equal or less than MaxPacketSize - 21. Default value is 43. |
USBD_PHDC_OS_CFG_SCHED_EN | If using µC/OS-II or µC/OS-III RTOS port, enable or disable the scheduler feature. You should set it to If you set this constant to DEF_ENABLED , you must ensure that the scheduler’s task has a lower priority (i.e., higher priority value) than any task that can write PHDC data. |
DEF_ENABLED
or DEF_DISABLED |
If you set USBD_PHDC_OS_CFG_SCHED_EN
to DEF_ENABLED
and you use a µC/OS-II or µC/OS-III RTOS port, PHDC will need an internal task for the scheduling operations. There are two application specific configurations that must be set in this case. They should be defined in the app_cfg.h
file. Table - Application-Specific Configuration Constants describes these configurations.
Constant | Description | Possible Values |
---|---|---|
USBD_PHDC_OS_CFG_SCHED_TASK_PRIO | QoS based scheduler’s task priority. You must ensure that the scheduler’s task has a lower priority (i.e. higher priority value) than any task writing PHDC data. | From the lowest to the highest priority supported by the OS used. |
USBD_PHDC_OS_CFG_SCHED_TASK_STK_SIZE | QoS based scheduler’s task stack size. The required size of the stack can greatly vary depending on the OS used, the CPU architecture, the type of application, etc. Refer to the documentation of the OS for more details about tasks and stack size calculation. | From the minimal to the maximal stack size supported by the OS used. Default value is 512. |
Class Instance Configuration
Before starting the communication phase, your application needs to initialize and configure the class to suit its needs. Table - PHDC Initialization API Summary summarizes the initialization functions provided by the PHDC implementation. For a complete API reference, see the PHDC Functions reference.
Function name | Operation |
---|---|
USBD_PHDC_Init() | Initializes PHDC internal structures and variables. |
USBD_PHDC_Add() | Adds a new instance of PHDC. |
USBD_PHDC_RdCfg() | Configures read communication pipe parameters. |
USBD_PHDC_WrCfg() | Configures write communication pipe parameters. |
USBD_PHDC_11073_ExtCfg() | Configures IEEE 11073 function extension(s). |
USBD_PHDC_CfgAdd() | Adds PHDC instance into USB device configuration. |
You need to follow these steps to successfully initialize PHDC:
- Call
USBD_PHDC_Init()
This is the first function you should call, and you should do it only once, even if you use multiple class instances. This function will initialize all internal structures and variables that the class will need. It will also initialize the real-time operating system (RTOS) layer. - Call
USBD_PHDC_Add()
This function will allocate a PHDC instance. This call will also let you determine if the PHDC instance is capable of sending / receiving the metadata message preamble and if it uses a vendor-defined or ISO/IEEE-11073 based data and messaging protocol.
Another parameter of this function lets you specify a callback function that the class will call when the host enables / disables metadata message preambles. This is useful for the application as the behavior in communication will differ depending on the metadata message preamble state.
If your application needs to send low latency / good reliability data, the class will need to allocate an interrupt endpoint. The endpoint’s interval will be specified in this call as well. Call
USBD_PHDC_RdCfg()
andUSBD_PHDC_WrCfg()
The next step is to callUSBD_PHDC_RdCfg()
andUSBD_PHDC_WrCfg()
. These functions will let you set the latency / reliability bins that the communication pipe will carry. Bins are listed in Table - Listing of QoS Bins. It will also be used to specify opaque data to send within extra endpoint metadata descriptors (see “USB Device Class Definition for Personal Healthcare Devices”, Release 1.0, Section 5 for more details on PHDC extra descriptors).- Call
USBD_PHDC_11073_ExtCfg()
(optional)
If the PHDC instance uses ISO/IEEE 11073-based data and messaging protocol, a call to this function will let you configure the device specialization code(s). - Call
USBD_PHDC_CfgAdd()
Name | Description |
---|---|
USBD_PHDC_LATENCY_VERYHIGH_RELY_BEST | Very-high latency, best reliability. |
USBD_PHDC_LATENCY_HIGH_RELY_BEST | High latency, best reliability. |
USBD_PHDC_LATENCY_MEDIUM_RELY_BEST | Medium latency, best reliability. |
USBD_PHDC_LATENCY_MEDIUM_RELY_BETTER | Medium latency, better reliability. |
USBD_PHDC_LATENCY_MEDIUM_RELY_GOOD | Medium latency, good reliability. |
USBD_PHDC_LATENCY_LOW_RELY_GOOD | Low latency, good reliability. |
Finally, once the class instance is correctly configured and initialized, you will need to add it to a USB configuration. This is done by calling USBD_PHDC_CfgAdd()
.
Listing - PHDC Instance Initialization and Configuration Example shows an example of initialization and configuration of a PHDC instance. If you need more than one class instance of PHDC for your application, refer to the Class Instance Concept page for generic examples of how to build your device.
CPU_BOOLEAN App_USBD_PHDC_Init(CPU_INT08U dev_nbr, CPU_INT08U cfg_hs, CPU_INT08U cfg_fs) { USBD_ERR err; CPU_INT08U class_nbr; USBD_PHDC_Init(&err); (1) class_nbr = USBD_PHDC_Add(DEF_YES, (2) DEF_YES, App_USBD_PHDC_SetPreambleEn, 10, &err); latency_rely_flags = USBD_PHDC_LATENCY_VERYHIGH_RELY_BEST | USBD_PHDC_LATENCY_HIGH_RELY_BEST | USBD_PHDC_LATENCY_MEDIUM_RELY_BEST; USBD_PHDC_RdCfg(class_nbr, (3) latency_rely_flags, opaque_data_rx, sizeof(opaque_data_rx), &err); USBD_PHDC_WrCfg(class_nbr, (3) USBD_PHDC_LATENCY_VERYHIGH_RELY_BEST, opaque_data_tx, sizeof(opaque_data_tx), &err); USBD_PHDC_11073_ExtCfg(class_nbr, dev_specialization, 1, &err); (4) valid_cfg_hs = USBD_PHDC_CfgAdd(class_nbr, dev_nbr, cfg_hs, &err); (5) valid_cfg_fs = USBD_PHDC_CfgAdd(class_nbr, dev_nbr, cfg_fs, &err); (6) }
(1) Initialize PHDC internal members and variables.
(2) Create a PHDC instance, this instance support preambles and ISO/IEEE 11073 based data and messaging protocol.
(3) Configure read and write pipes with correct QoS and opaque data.
(4) Add ISO/IEEE 11073 device specialization to PHDC instance.
(5) Add class instance to high-speed configuration.
(6) Add class instance to full-speed configuration.