Driver API for Virtual Streaming interface using fixed-size data blocks (cmsis_vstream.h) More...
Content | |
Return Codes | |
Return codes for driver functions. Negative values indicate errors. | |
Streaming Modes | |
Streaming modes used by the vStreamStart function. | |
Driver Event Flags | |
Events signaled by the driver via the vStreamEvent function. | |
Streaming Status | |
Structure indicating the status of the virtual stream. | |
Data Structures | |
struct | vStreamDriver_t |
Access structure of the Virtual Streaming interface Driver. More... | |
Typedefs | |
typedef void(* | vStreamEvent_t) (uint32_t event_flags) |
Pointer to vStreamEvent : Handling of Virtual Streaming Events. | |
Functions | |
int32_t | vStreamInitialize (vStreamEvent_t event_cb) |
Initialize Virtual Streaming interface. | |
int32_t | vStreamUninitialize (void) |
De-initialize Virtual Streaming interface. | |
int32_t | vStreamSetBuf (void *buf, uint32_t buf_size, uint32_t block_size) |
Set Virtual Streaming data buffer. | |
int32_t | vStreamStart (uint32_t mode) |
Start streaming. | |
int32_t | vStreamStop (void) |
Stop streaming. | |
void * | vStreamGetBlock (void) |
Get pointer to Virtual Streaming data block. | |
int32_t | vStreamReleaseBlock (void) |
Release Virtual Streaming data block. | |
vStreamStatus_t | vStreamGetStatus (void) |
Get Virtual Streaming status. | |
void | vStreamEvent (uint32_t event_flags) |
Callback function for handling Virtual Streaming events. | |
Driver API for Virtual Streaming interface using fixed-size data blocks (cmsis_vstream.h)
The vStream software component provides an abstraction layer for streaming data using fixed-size blocks. It offers a standardized interface to interact with various streaming devices such as sensors, cameras, microphones, speakers, or simulated devices. It allows seamless development on one platform and deployment on another.
vStream API
The following header file defines the Application Programming Interface (API) for Virtual Streaming interface:
The driver implementation is typically a part of the Board Support Pack (BSP) for a specific board with streaming devices.
Driver Functions
All driver functions are grouped within the vStreamDriver_t access structure.
User Code Template
The CMSIS Driver:vStream (API):Custom component provides a stub implementation of all vStream driver functions.
This template can be used to implement the vStream driver for your target hardware.
The default driver access structure is named Driver_vStreamDevice, but Device
should be replaced with a specific device name, such as Driver_vStreamAccelerometer
. See vStreamDriver_t for more details.
Code Example
The following example demonstrates how to use the vStream driver for an accelerometer:
struct vStreamDriver_t |
Access structure of the Virtual Streaming interface Driver.
This structure provides function pointers to access the vStream driver.
Recommended naming convention for access structures:
Data Fields | |
int32_t(* | Initialize )(vStreamEvent_t event_cb) |
Pointer to vStreamInitialize : Initialize Virtual Streaming interface. | |
int32_t(* | Uninitialize )(void) |
Pointer to vStreamUninitialize : De-initialize Virtual Streaming interface. | |
int32_t(* | SetBuf )(void *buf, uint32_t buf_size, uint32_t block_size) |
Pointer to vStreamSetBuf : Set Virtual Streaming data buffer. | |
int32_t(* | Start )(uint32_t mode) |
Pointer to vStreamStart : Start streaming. | |
int32_t(* | Stop )(void) |
Pointer to vStreamStop : Stop streaming. | |
void *(* | GetBlock )(void) |
Pointer to vStreamGetBlock : Get pointer to data block. | |
int32_t(* | ReleaseBlock )(void) |
Pointer to vStreamReleaseBlock : Release data block. | |
vStreamStatus_t(* | GetStatus )(void) |
Pointer to vStreamGetStatus : Get Virtual Streaming status. | |
int32_t(* Initialize) (vStreamEvent_t event_cb) |
Pointer to vStreamInitialize : Initialize Virtual Streaming interface.
int32_t(* Uninitialize) (void) |
Pointer to vStreamUninitialize : De-initialize Virtual Streaming interface.
int32_t(* SetBuf) (void *buf, uint32_t buf_size, uint32_t block_size) |
Pointer to vStreamSetBuf : Set Virtual Streaming data buffer.
int32_t(* Start) (uint32_t mode) |
Pointer to vStreamStart : Start streaming.
int32_t(* Stop) (void) |
Pointer to vStreamStop : Stop streaming.
void *(* GetBlock) (void) |
Pointer to vStreamGetBlock : Get pointer to data block.
int32_t(* ReleaseBlock) (void) |
Pointer to vStreamReleaseBlock : Release data block.
vStreamStatus_t(* GetStatus) (void) |
Pointer to vStreamGetStatus : Get Virtual Streaming status.
vStreamEvent_t |
Pointer to vStreamEvent : Handling of Virtual Streaming Events.
Provides the typedef for the callback function vStreamEvent.
Parameter for:
int32_t vStreamInitialize | ( | vStreamEvent_t | event_cb | ) |
Initialize Virtual Streaming interface.
This function prepares the Virtual Streaming interface for operation.
It performs the following tasks:
The event callback function must conform to the vStreamEvent_t type.
If event signaling is not required, pass a NULL pointer for event_cb.
This function must be called before any other vStream operations.
Code Example:
int32_t vStreamUninitialize | ( | void | ) |
De-initialize Virtual Streaming interface.
This function disables the Virtual Streaming interface and releases all associated resources that were allocated during vStreamInitialize.
Use this function to properly shut down the interface when streaming is no longer required.
After calling vStreamUninitialize, the interface is considered inactive, and re-initialization is required to resume streaming operations.
Code Example:
int32_t vStreamSetBuf | ( | void * | buf, |
uint32_t | buf_size, | ||
uint32_t | block_size | ||
) |
Set Virtual Streaming data buffer.
[in] | buf | pointer to memory buffer used for streaming data |
[in] | buf_size | total size of the streaming data buffer (in bytes) |
[in] | block_size | streaming data block size (in bytes) |
This function registers a memory buffer for use by the Virtual Streaming driver.
The buffer is used for reading or writing fixed-size data blocks, depending on the streaming direction.
Memory buffer recommendations:
If block_size is larger than buf_size, the function returns VSTREAM_ERROR_PARAMETER.
This function must be called after initialization and before starting the stream.
Code Example:
int32_t vStreamStart | ( | uint32_t | mode | ) |
Start streaming.
[in] | mode | streaming mode (see Streaming Modes) |
This function initiates the streaming operation based on the specified mode.
Before calling vStreamStart:
The mode parameter defines the streaming behavior:
Code Example:
int32_t vStreamStop | ( | void | ) |
Stop streaming.
This function stops the ongoing streaming process initiated by vStreamStart and resets the stream, by discarding any remaining or incomplete data blocks.
Calling this function halts data transfers and prepares the stream for either shutdown or restart. After stopping, the stream can be restarted using vStreamStart without requiring re-initialization or reconfiguration, provided the buffer settings remain valid.
Code Example:
void * vStreamGetBlock | ( | void | ) |
Get pointer to Virtual Streaming data block.
This function provides access to the data block used for input or output operations, depending on the streaming direction.
The returned block remains valid until it is released using vStreamReleaseBlock.
Code Example:
int32_t vStreamReleaseBlock | ( | void | ) |
Release Virtual Streaming data block.
This function finalizes the use of the data block returned by vStreamGetBlock.
This function must be called after processing or preparing the data block returned by vStreamGetBlock to maintain proper buffer flow and avoid data loss or stalling.
Code Example:
vStreamStatus_t vStreamGetStatus | ( | void | ) |
Get Virtual Streaming status.
This function returns the current operational status of the Virtual Streaming interface.
The returned structure includes the following information:
Use this function to monitor the health and state of the streaming process during runtime.
Code Example:
void vStreamEvent | ( | uint32_t | event_flags | ) |
Callback function for handling Virtual Streaming events.
[in] | event_flags | bitmask indicating one or more streaming events (see Driver Event Flags) |
This user-implemented callback function is invoked by the driver to signal runtime events during streaming.
It is registered by the vStreamInitialize function.
The event_flags parameter is a bitmask where each bit represents a specific event condition.
Multiple events may be reported simultaneously via combined bits. Use this function to respond to runtime conditions, such as processing data, handling errors, or updating application state.
The following events can be signaled:
Parameter event_flags | Bit | Description |
---|---|---|
VSTREAM_EVENT_DATA | 0 | Occurs when a new block of incoming data is available or when a block of outgoing data was streamed out. |
VSTREAM_EVENT_OVERFLOW | 1 | Occurs when a block of incoming data begins to be overwritten because it was not released in time using the vStreamReleaseBlock function. |
VSTREAM_EVENT_UNDERFLOW | 2 | Occurs when a block of outgoing data was not ready (committed with vStreamReleaseBlock function) before streaming out required it. |
VSTREAM_EVENT_EOS | 3 | Occurs when a streaming interface reached end of stream. |