The SDK is designed for portability across embedded platforms and operating systems. To port the SDK to a new platform, follow these steps.
Use the Linux reference implementation in platform/linux/ as a working starting point. For RTOS-based platforms, map mutexes and events to your RTOS primitives (e.g., FreeRTOS SemaphoreHandle_t, Zephyr k_mutex).
Implement the platform layer
Create the platform directory
Create a new directory under platform/ (e.g., platform/my_platform/) with two files:
Platform types (ecod_platform_types.h)
Define the platform-specific types used by the SDK:
The Linux reference uses pthread_mutex_t for mutexes and a struct wrapping pthread_mutex_t + pthread_cond_t + bool flag for events. Adapt these to your platform’s RTOS or OS primitives.
Platform implementation (ecod_platform_<name>.c)
Implement all functions declared in ecod_sdk_platform.h. They are grouped into these categories:
Initialization
Implement the startup function to allocate platform resources:
// Called once at startup. Initialize platform resources (e.g., signal handling, log files).EC_SDK_STATUS ecod_platform_init(void);
Clock & timing
Implement these functions to provide the SDK with a monotonic clock and blocking delay:
// Return current time in milliseconds (must be monotonic / always increasing)u32 ecod_platform_get_tick_ms(void);// Blocking delay for the given number of millisecondsvoid ecod_platform_delay(u32 delay_ms);
Logging
Implement these functions to route SDK log output to your platform’s logging system:
// printf-style log output, filtered by level and tagged with module namevoid ecod_log(EC_LOG_LEVEL level, const char* module, const char* format, ...);// Set the maximum log level that will be outputvoid ecod_set_log_level(EC_LOG_LEVEL max_level);// Log a data buffer as hex (useful for protocol debugging)void ecod_log_buf(EC_LOG_LEVEL level, const char* module, const char* msg, u8* data, u32 data_len);
Memory (only when EC_USE_HEAP is enabled)
Implement malloc and free wrappers when heap allocation is enabled:
Implement these functions to handle raw serial or USB HID I/O:
// Open and configure the serial port (UART or HID). Called once.bool ecod_serial_init(void);// Synchronous send. Returns number of bytes actually sent.u32 ecod_serial_send(u8* data, u32 length);// Receive up to max_length bytes, waiting up to timeout_ms. Returns bytes received.u32 ecod_serial_receive(u8* data, u32 max_length, u32 timeout_ms);
Network (only if using the network bridge)
Implement these functions to give the SDK access to TCP sockets: