DMOSI (DMOD Operating System Interface) is an abstraction layer for Real-Time Operating Systems (RTOS) and embedded operating systems. It provides a unified API that allows libraries and modules to interact with operating system primitives independently of the underlying RTOS implementation.
This repository serves as:
- An abstraction layer for other libraries implementing specific RTOS functionality
- A common interface for modules that need OS services without being tied to a specific RTOS
- A standardized API for embedded systems targeting various RTOS platforms (FreeRTOS, ThreadX, Zephyr, etc.)
DMOSI provides weak implementations (stubs) for the following operating system primitives:
Thread synchronization through mutual exclusion locks:
dmosi_mutex_create()- Create a mutex (recursive or non-recursive)dmosi_mutex_destroy()- Destroy a mutexdmosi_mutex_lock()- Lock a mutexdmosi_mutex_unlock()- Unlock a mutex
Counting semaphores for resource management:
dmosi_semaphore_create()- Create a semaphore with initial and max countsdmosi_semaphore_destroy()- Destroy a semaphoredmosi_semaphore_wait()- Wait on a semaphore (with timeout)dmosi_semaphore_post()- Post to a semaphore
Thread creation and management:
dmosi_thread_create()- Create a new threaddmosi_thread_destroy()- Destroy a threaddmosi_thread_join()- Wait for thread completiondmosi_thread_current()- Get current thread handledmosi_thread_sleep()- Sleep for specified milliseconds
Process-level operations (for RTOS that support processes):
dmosi_process_create()- Create a new processdmosi_process_destroy()- Destroy a processdmosi_process_current()- Get current process handle
Inter-task message queues:
dmosi_queue_create()- Create a queue with specified item size and lengthdmosi_queue_destroy()- Destroy a queuedmosi_queue_send()- Send data to queue (with timeout)dmosi_queue_receive()- Receive data from queue (with timeout)
Software timers for periodic or one-shot callbacks:
dmosi_timer_create()- Create a timer with callbackdmosi_timer_destroy()- Destroy a timerdmosi_timer_start()- Start a timerdmosi_timer_stop()- Stop a timerdmosi_timer_reset()- Reset a timer
Add DMOSI to your CMake project using FetchContent:
include(FetchContent)
FetchContent_Declare(
dmosi
GIT_REPOSITORY https://github.com/choco-technologies/dmosi.git
GIT_TAG main
)
FetchContent_MakeAvailable(dmosi)
target_link_libraries(your_target PRIVATE dmosi)To implement DMOSI for your specific RTOS, override the weak implementations by providing strong implementations in your library. Create a separate library or repository that links against DMOSI and provides the actual implementations for your target RTOS.
#include "dmosi.h"
void my_task(void)
{
// Create a mutex
dmosi_mutex_t mutex = dmosi_mutex_create(false);
// Lock the mutex
dmosi_mutex_lock(mutex);
// Critical section
// ...
// Unlock the mutex
dmosi_mutex_unlock(mutex);
// Create a thread (associated with current process)
dmosi_thread_t thread = dmosi_thread_create(
my_thread_function,
NULL, // argument
5, // priority
2048, // stack size
"my_thread", // thread name
"my_module", // module name
NULL // process (NULL = current process)
);
// Clean up
dmosi_mutex_destroy(mutex);
}By default, DMOSI provides implementations of several DMOD SAL API functions that call the corresponding dmosi_* functions. If you want to provide your own implementation or don't need this bridge, set this option:
set(DMOSI_DONT_IMPLEMENT_DMOD_API ON CACHE BOOL "Don't implement DMOD API" FORCE)This option provides more granular control over the DMOD API implementation. By default, DMOSI implements DMOD mutex API functions (Dmod_Mutex_New, Dmod_Mutex_Delete, Dmod_Mutex_Lock, Dmod_Mutex_Unlock) using DMOSI mutex functions. If you want to provide your own mutex implementation while still using other DMOD API implementations, set this option:
set(DMOSI_DONT_IMPLEMENT_DMOD_API_MUTEX ON CACHE BOOL "Don't implement DMOD Mutex API" FORCE)By default, DMOSI implements the DMOD environment API function Dmod_GetCurrentModuleNameEx using DMOSI thread functions (dmosi_thread_current and dmosi_thread_get_module_name). If you want to provide your own implementation, set this option:
set(DMOSI_DONT_IMPLEMENT_DMOD_API_ENV ON CACHE BOOL "Don't implement DMOD Environment API" FORCE)By default, DMOSI implements the DMOD process API function Dmod_Exit using DMOSI process functions (dmosi_process_current and dmosi_process_kill), with a fallback to the standard C library exit(). If you want to provide your own implementation, set this option:
set(DMOSI_DONT_IMPLEMENT_DMOD_API_PROC ON CACHE BOOL "Don't implement DMOD Process API" FORCE)Note: The global DMOSI_DONT_IMPLEMENT_DMOD_API option takes precedence. If it's set to ON, all DMOD API implementations (including mutex, environment, and process) will be disabled regardless of the granular settings.
mkdir build
cd build
cmake ..
makemkdir build
cd build
cmake -DDMOSI_DONT_IMPLEMENT_DMOD_API=ON ..
makemkdir build
cd build
cmake -DDMOSI_DONT_IMPLEMENT_DMOD_API_MUTEX=ON ..
makemkdir build
cd build
cmake -DDMOSI_BUILD_TESTS=ON ..
make
ctest┌─────────────────────────────────────────┐
│ Application / DMOD Modules │
└─────────────────┬───────────────────────┘
│
│ Uses DMOSI API
│
┌─────────────────▼───────────────────────┐
│ DMOSI Library │
│ (Weak implementations/stubs by default)│
└─────────────────┬───────────────────────┘
│
│ Overridden by
│
┌─────────────────▼───────────────────────┐
│ RTOS-Specific Implementation │
│ (FreeRTOS, ThreadX, Zephyr, etc.) │
└─────────────────┬───────────────────────┘
│
│
┌─────────────────▼───────────────────────┐
│ Hardware / RTOS Kernel │
└─────────────────────────────────────────┘
All functions have weak implementations that return error codes or NULL. This allows:
- Compilation without errors even when no RTOS is linked
- Gradual implementation - implement only what you need
- Testing - stub behavior for unit tests
- Flexibility - choose which functions to implement
Functions that can fail return:
0on success- Negative error codes on failure (typically
-ENOSYSfor unimplemented functions) NULLfor handle creation failures
When implementing DMOSI for a new RTOS:
- Create a new repository or library (e.g.,
dmosi-freertos) - Link against DMOSI
- Provide strong implementations for the functions your RTOS supports
- Document any RTOS-specific limitations or behaviors
See LICENSE file for details.
- DMOD - Dynamic Module System
- DMOSI implementations for specific RTOS (to be added)
For issues, questions, or contributions, please visit: https://github.com/choco-technologies/dmosi/issues