Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents
maxLevel3
minLevel2
indent20px

...

Excerpt

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.

Anchor
Table - Configuration Constants Summary
Table - Configuration Constants Summary

Panel
borderWidth0
titleTable - Configuration Constants Summary


ConstantDescriptionPossible Values
USBD_PHDC_CFG_MAX_NBR_DEVConfigures 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_CFGConfigures 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_LENMaximum 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 DEF_DISABLED if the device only uses one QoS level to send data, for instance. (See the PHDC RTOS QoS-based scheduler page). 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.

Warning
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.

Anchor
Table - Application-Specific Configuration Constants
Table - Application-Specific Configuration Constants

Panel
borderWidth0
titleTable - Application-Specific Configuration Constants


ConstantDescriptionPossible Values
USBD_PHDC_OS_CFG_SCHED_TASK_PRIO

QoS based scheduler’s task priority.

Warning

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_SIZEQoS 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.

Anchor
Table - PHDC Initialization API Summary
Table - PHDC Initialization API Summary

Panel
borderWidth0
titleTable - PHDC Initialization API Summary


Function nameOperation
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:

  1. 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.
  2. 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.
  3. Call USBD_PHDC_RdCfg() and USBD_PHDC_WrCfg()
    The next step is to call USBD_PHDC_RdCfg() and USBD_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).

  4. 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).
  5. Call USBD_PHDC_CfgAdd()

Anchor
Table - Listing of QoS Bins
Table - Listing of QoS Bins

Panel
borderWidth0
titleTable - Listing of QoS Bins


NameDescription
USBD_PHDC_LATENCY_VERYHIGH_RELY_BESTVery-high latency, best reliability.
USBD_PHDC_LATENCY_HIGH_RELY_BESTHigh latency, best reliability.
USBD_PHDC_LATENCY_MEDIUM_RELY_BESTMedium latency, best reliability.
USBD_PHDC_LATENCY_MEDIUM_RELY_BETTERMedium latency, better reliability.
USBD_PHDC_LATENCY_MEDIUM_RELY_GOODMedium latency, good reliability.
USBD_PHDC_LATENCY_LOW_RELY_GOODLow 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().


shows 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.

Anchor
Listing - PHDC Instance Initialization and Configuration Example
Listing - PHDC Instance Initialization and Configuration Example

Code Block
languagecpp
titleListing - PHDC Instance Initialization and Configuration Example
linenumberstrue
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)
}


Panel
bgColor#f0f0f0

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