ICARUS OS (Intelligent Cooperative Architecture for Real-time Unified Systems) 0.1.0
Preemptive Real-Time Operating System for ARM Cortex-M7
Loading...
Searching...
No Matches
cdc.c File Reference

USB CDC raw write helper implementation. More...

#include "bsp/cdc.h"
#include <string.h>
#include "usbd_cdc_if.h"
#include "icarus/icarus.h"

Go to the source code of this file.

Functions

bool CDC_Write (const uint8_t *data, uint16_t len)
 Push len bytes to the USB CDC IN endpoint.
 
bool CDC_WriteString (const char *s)
 Convenience wrapper that pushes a NUL-terminated C string.
 

Detailed Description

USB CDC raw write helper implementation.

Calls the ST USB CDC class driver (CDC_Transmit_FS from usbd_cdc_if.h) and busy-retries on USBD_BUSY using task_active_sleep(1) between attempts. The retry budget is bounded by CDC_WRITE_MAX_RETRIES so a stuck endpoint cannot block the caller forever.

Under HOST_TEST the ST middleware is unavailable, so the implementation is replaced by a small in-memory sink that stores the most recent payload — exposed to the unit tests via __cdc_host_* hooks declared in tests/src/test_cdc.c.

Author
Souham Biswas
Date
2026

Definition in file cdc.c.

Function Documentation

◆ CDC_Write()

bool CDC_Write ( const uint8_t *  data,
uint16_t  len 
)

Push len bytes to the USB CDC IN endpoint.

Parameters
dataPointer to the bytes to send (must be non-NULL when len > 0).
lenNumber of bytes to send.
Returns
true if the bytes were accepted by the CDC stack within CDC_WRITE_MAX_RETRIES busy-retries; false otherwise (caller's bytes were not sent).
Note
Must be called from task context — the busy-retry path uses task_active_sleep(1) and would deadlock from an ISR.
The transmit buffer the ST middleware accepts is borrowed, not copied. The pointer data must remain valid until the function returns.

Definition at line 33 of file cdc.c.

References CDC_Transmit_FS(), CDC_WRITE_MAX_RETRIES, and task_active_sleep().

Referenced by CDC_WriteString().

◆ CDC_WriteString()

bool CDC_WriteString ( const char *  s)

Convenience wrapper that pushes a NUL-terminated C string.

Parameters
sNUL-terminated string. NULL is treated as a no-op success.
Returns
true on success, false if the underlying CDC_Write could not flush within the retry budget.

Definition at line 112 of file cdc.c.

References CDC_Write().