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
dmosi_thread_t thread = dmosi_thread_create(
my_thread_function,
NULL, // argument
5, // priority
2048 // stack size
);
// Clean up
dmosi_mutex_destroy(mutex);
}By default, DMOSI provides implementations of DMOD mutex API functions (Dmod_Mutex_*) that call the corresponding dmosi_mutex_* 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)mkdir build
cd build
cmake ..
makemkdir build
cd build
cmake -DDMOSI_DONT_IMPLEMENT_DMOD_API=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