ArchitectureΒΆ
This document provides a detailed overview of the Nexus platform architecture.
Design PrinciplesΒΆ
Nexus is built on the following design principles:
Separation of Concerns: Each layer has a specific responsibility
Abstraction: Hide implementation details behind clean interfaces
Portability: Minimize platform-specific code in applications
Testability: Design for unit testing and simulation
Resource Efficiency: Optimize for constrained embedded systems
Layer ArchitectureΒΆ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Applications β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Middleware β
β βββββββββββ βββββββββββ βββββββββββ βββββββββββ β
β β Shell β β Log β β Config β β Event β β
β βββββββββββ βββββββββββ βββββββββββ βββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β OSAL β
β βββββββββββ βββββββββββ βββββββββββ βββββββββββ β
β β Task β β Mutex β β Queue β β Timer β β
β βββββββββββ βββββββββββ βββββββββββ βββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β HAL β
β βββββββββββ βββββββββββ βββββββββββ βββββββββββ β
β β GPIO β β UART β β SPI β β I2C β β
β βββββββββββ βββββββββββ βββββββββββ βββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Platform / Hardware β
β βββββββββββ βββββββββββ βββββββββββ βββββββββββ β
β β STM32F4 β β STM32H7 β β ESP32 β β nRF52 β β
β βββββββββββ βββββββββββ βββββββββββ βββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Application LayerΒΆ
User applications built on top of Nexus platform. Applications should:
Use only public APIs from lower layers
Avoid direct hardware access
Be portable across supported platforms
Middleware LayerΒΆ
Common services that provide higher-level functionality:
Log Framework: Flexible logging with multiple backends
Shell: Command-line interface for debugging
Config: Configuration management and persistence
Event: Event-driven programming support
See Log Framework for detailed Log Framework documentation.
OSAL LayerΒΆ
OS Abstraction Layer provides portable RTOS primitives:
Task: Thread/task management
Mutex: Mutual exclusion locks
Semaphore: Binary and counting semaphores
Queue: Message queues for inter-task communication
Timer: Software timers
Supported backends:
FreeRTOS
Native (pthreads for PC simulation)
Bare-metal (cooperative scheduling)
See OS Abstraction Layer (OSAL) for detailed OSAL documentation.
HAL LayerΒΆ
Hardware Abstraction Layer provides unified peripheral APIs:
GPIO: General-purpose I/O
UART: Serial communication
SPI: SPI bus master/slave
I2C: I2C bus master/slave
Timer: Hardware timers and PWM
ADC: Analog-to-digital conversion
See Hardware Abstraction Layer (HAL) for detailed HAL documentation.
Platform LayerΒΆ
MCU-specific implementations including:
Startup code and system initialization
Linker scripts
Vendor SDK integration
Clock and power management
Data FlowΒΆ
Application
β
βΌ
βββββββββββββββββββ
β Middleware β β Uses OSAL for threading, HAL for I/O
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β OSAL β β Uses HAL for timing
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β HAL β β Uses Platform for hardware access
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β Platform β β Direct hardware access
βββββββββββββββββββ
Dependency RulesΒΆ
Strict dependency rules ensure clean architecture:
Upper layers depend on lower layers (never reverse)
Same-layer components are independent (no horizontal dependencies)
Platform layer is the only layer with hardware access
β
Application β Middleware β OSAL β HAL β Platform
β HAL β Middleware (reverse dependency)
β GPIO β UART (horizontal dependency within HAL)
Memory ManagementΒΆ
Nexus supports multiple memory management strategies:
- Static Allocation
All memory allocated at compile time. Suitable for safety-critical systems.
- Dynamic Allocation
Runtime memory allocation using malloc/free. More flexible but requires careful management.
- Pool Allocation
Fixed-size memory pools for predictable allocation patterns.
Configuration example:
/* Static allocation mode */
#define NEXUS_USE_STATIC_ALLOC 1
#define NEXUS_MAX_TASKS 8
#define NEXUS_MAX_MUTEXES 16
Error HandlingΒΆ
All Nexus APIs follow consistent error handling:
/* All functions return status codes */
hal_status_t status = hal_gpio_init(port, pin, &config);
if (status != HAL_OK) {
/* Handle error */
LOG_ERROR("GPIO init failed: %d", status);
}
Common status codes:
Status |
Description |
|---|---|
|
Operation successful |
|
General error |
|
Invalid parameter |
|
Invalid state |
|
Operation timed out |
|
Memory allocation failed |
Build SystemΒΆ
Nexus uses CMake for cross-platform build configuration:
# Select platform
cmake -B build -DNEXUS_PLATFORM=stm32f4
# Enable features
cmake -B build \
-DNEXUS_PLATFORM=stm32f4 \
-DNEXUS_BUILD_TESTS=ON \
-DNEXUS_ENABLE_LOG=ON
Key CMake options:
Option |
Description |
|---|---|
|
Target platform (stm32f4, native) |
|
Build unit tests |
|
Enable log framework |
|
Enable code coverage |
Next StepsΒΆ
Hardware Abstraction Layer (HAL) - Learn about the Hardware Abstraction Layer
OS Abstraction Layer (OSAL) - Learn about the OS Abstraction Layer
Log Framework - Learn about the Log Framework
Porting Guide - Port Nexus to a new platform