2.5.4.4 USB_DEVICE_CDC_SerialStateNotificationSend Function

C

USB_DEVICE_CDC_RESULT USB_DEVICE_CDC_SerialStateNotificationSend(
    USB_DEVICE_CDC_INDEX iCDC, 
    USB_DEVICE_CDC_TRANSFER_HANDLE * transferHandle, 
    USB_CDC_SERIAL_STATE * notificationData
);

Summary

This function places a request to send serial state notification data to the host. The function will place the request with the driver, the request will get serviced when the data is requested by the USB host. A handle to the request is returned in the transferHandle parameter. The termination of the request is indicated by the USB_DEVICE_CDC_EVENT_SERIAL_STATE_NOTIFICATION_COMPLETE event. The amount of data transmitted and the transfer handle associated with the request is returned along with the event in the serialStateNotificationCompleteData member of pData parameter of the event handler. The transfer handle expires when the event handler for the USB_DEVICE_CDC_EVENT_SERIAL_STATE_NOTIFICATION_COMPLETE event exits. If the send request could not be accepted, the function returns an error code and transferHandle will contain the value USB_DEVICE_CDC_TRANSFER_HANDLE_INVALID.

Precondition

The function driver should have been configured.

Parameters

Parameters Description
iCDC USB Device CDC Function Driver instance.
transferHandle Pointer to a output only variable that will contain transfer handle.
notificationData USB_DEVICE_CDC_SERIAL_STATE_NOTIFICATION type of notification data to be sent to the host.

Returns

USB_DEVICE_CDC_RESULT_OK - The request was successful. transferHandle contains a valid transfer handle.

USB_DEVICE_CDC_RESULT_ERROR_TRANSFER_QUEUE_FULL - Internal request queue is full. The request could not be added.

USB_DEVICE_CDC_RESULT_ERROR_INSTANCE_NOT_CONFIGURED - The specified instance is not configured yet.

USB_DEVICE_CDC_RESULT_ERROR_INSTANCE_INVALID - The specified instance was not provisioned in the application and is invalid.

Example

USB_CDC_SERIAL_STATE notificationData;

// This application function could possibly update the notificationData
// data structure.

APP_UpdateNotificationData(&notificationData);

// Now send the updated notification data to the host.

result = USB_DEVICE_CDC_SerialStateNotificationSend
            (instanceIndex, &transferHandle, &notificationData);

if(USB_DEVICE_CDC_RESULT_OK != result)
{
    // Error handling here. The transferHandle will contain
    // USB_DEVICE_CDC_TRANSFER_HANDLE_INVALID in this case.
} 

Remarks

While the using the CDC Function Driver with the PIC32MZ USB module, the notification data buffer provided to the USB_DEVICE_CDC_SerialStateNotificationSend function should be placed in coherent memory and aligned at a 16 byte boundary. This can be done by declaring the buffer using the __attribute__((coherent, aligned(16))) attribute. An example is shown here:

uint8_t data[256] __attribute__((coherent, aligned(16)));