Getting Started

Getting Started with LightOS

This guide will help you get LightOS running on your development machine and create your first application.


Prerequisites


Installation

1. Clone the Repository

git clone https://github.com/jiangintel-ux/lightOS.git
cd lightOS

2. Build for Host Testing

# Configure
cmake -B build -DCMAKE_BUILD_TYPE=Debug

# Build
cmake --build build -j

# Run tests
./build/lightos_unit_tests

You should see all 1122 tests pass.

3. Build for ARM Target

# Configure for ARM Cortex-R52
cmake -B build-arm \
    -DCMAKE_TOOLCHAIN_FILE=cmake/arm-none-eabi-gcc.cmake \
    -DLIGHTOS_TARGET_ARCH=cortex-r52

# Build
cmake --build build-arm -j

4. Build for RISC-V Target

# Configure for RISC-V RV64
cmake -B build-rv64 \
    -DCMAKE_TOOLCHAIN_FILE=cmake/riscv64-unknown-elf-gcc.cmake \
    -DLIGHTOS_TARGET_ARCH=rv64gc

# Build
cmake --build build-rv64 -j

Your First Application

Create a simple multi-threaded application:

// main.cpp
#include <lightos/kernel.hpp>
#include <lightos/thread.hpp>
#include <lightos/mutex.hpp>

using namespace lightos;

// Shared resource
mutex print_lock;
int counter = 0;

// Worker thread function
void worker(void* arg) {
    int id = reinterpret_cast<intptr_t>(arg);

    for (int i = 0; i < 5; i++) {
        {
            scoped_lock lock(print_lock);
            counter++;
            // In production: use proper logging
        }
        thread::sleep(milliseconds(100));
    }
}

int main() {
    // Initialize kernel
    kernel::init();

    // Create worker threads
    thread worker1("Worker1", priority::normal, worker, (void*)1);
    thread worker2("Worker2", priority::normal, worker, (void*)2);

    // Start threads
    worker1.start();
    worker2.start();

    // Wait for completion
    worker1.join();
    worker2.join();

    // counter should be 10
    return 0;
}

Build and run:

cmake --build build --target my_app
./build/my_app

Project Structure

lightOS/
├── include/
   └── lightos/           # Public headers
       ├── kernel.hpp     # Kernel initialization
       ├── thread.hpp     # Thread management
       ├── mutex.hpp      # Mutex primitives
       ├── semaphore.hpp  # Semaphore primitives
       ├── queue.hpp      # Message queues
       └── timer.hpp      # Timer services
├── src/
   ├── kernel/            # Kernel implementation
   └── arch/              # Architecture-specific code
├── tests/
   └── unit/              # Unit tests
├── examples/              # Example applications
└── cmake/                 # CMake toolchain files

Configuration Options

LightOS can be configured via CMake options:

OptionDefaultDescription
LIGHTOS_TARGET_ARCHhostTarget architecture
LIGHTOS_MAX_THREADS32Maximum thread count
LIGHTOS_MAX_PRIORITY32Priority levels
LIGHTOS_TICK_RATE_HZ1000System tick rate
LIGHTOS_HEAP_SIZE65536Heap size (bytes)
LIGHTOS_AUTOSAR_ENABLEDOFFEnable AUTOSAR features

Example:

cmake -B build \
    -DLIGHTOS_MAX_THREADS=16 \
    -DLIGHTOS_TICK_RATE_HZ=10000

Next Steps


Need Help?