pebble
  • Tutorials
  • Get the SDK
  • Guides
  • Documentation
  • PebbleOS
  • Mobile App
  • Examples
  • Index 01
  • Community
  • Blog
  • More
Privacy
Cookies
Publish

PebbleOS

  • Overview
  • Start here
    • Getting started guide
  • Pebble Firmware
    • Overview
    • Playground
    • Application SDK
  • Development
    • The pbl CLI
    • Build system
    • Samples
    • Emulator and simulator
    • Testing
    • Debugging
    • Conventions
  • System
    • Architecture overview
    • Kernel
      • Threads
      • Syscalls
      • Interrupts
      • Time and delays
      • Work queues
      • Boot
      • Idle
      • Memory
      • Fatal errors and assertions
      • Reboot and power-off
      • Print
      • Compiler abstraction
      • Kernel internals
    • Drivers
    • Subsystems
    • Libraries
    • Third-party
  • Hardware
    • Boards
    • Board Add-ons
    • Programmers
  • Community
    • Contribution Guidelines
  • Reference
    • Reference
    • Kconfig options

Kernel

kernel/ owns every RTOS primitive the firmware uses. The public API lives in include/pbl/kernel/ and is the only threading interface the rest of the tree may use. The implementation is PebbleOS’s own.

Topics

  • Threads
  • Syscalls
  • Interrupts
  • Time and delays
  • Work queues
  • Boot
  • Idle
  • Memory
  • Fatal errors and assertions
  • Reboot and power-off
  • Print
  • Compiler abstraction
  • Kernel internals

Layout

        block-beta
  columns 2
  api["Public API · include/pbl/kernel/<br/>threads, mutexes, semaphores, queues, poll, IRQs"]:2
  core["Kernel · kernel/<br/>scheduler, objects, ticks"]:2
  arm["Cortex-M port · kernel/arch/arm/<br/>context switch, SVC, MPU"] posix["Host port · kernel/arch/posix/<br/>native simulator, unit tests"]

  classDef app fill:#fa4a36,stroke:#fa4a36,color:#ffffff
  classDef system fill:#fd8a7c,stroke:#fd8a7c,color:#171717
  classDef base fill:#525252,stroke:#525252,color:#ffffff
  class api app
  class core system
  class arm,posix base
    

Next to the API, include/pbl/kernel/ holds:

  • backend.h: the private state each public object struct embeds;

  • compiler.h: the compiler abstraction;

  • section.h: the placement of code and data in special sections.

Objects

Object

Struct

Static define

Thread

struct pbl_thread

PBL_THREAD_STACK_DEFINE + pbl_thread_create

Mutex

struct pbl_mutex

PBL_MUTEX_DEFINE

Semaphore

struct pbl_sem

PBL_SEM_DEFINE

Message queue

struct pbl_msgq

PBL_MSGQ_DEFINE

Poll group

struct pbl_poll_group

PBL_POLL_GROUP_DEFINE

Work item

struct pbl_work

PBL_WORK_DEFINE

Delayed work item

struct pbl_delayed_work

PBL_DELAYED_WORK_DEFINE

Work queue

struct pbl_workq

PBL_WORKQ_DEFINE

Conventions:

  • Every object is a caller-owned struct; there is no create/destroy pair that hands out heap handles. A PBL_*_DEFINE is a complete static initialiser, so a defined object is usable before the scheduler starts and needs no init call. pbl_*_init() exists for objects that live in dynamically allocated memory.

  • Blocking calls take a pbl_timeout_t (PBL_NO_WAIT, PBL_FOREVER, PBL_MSEC(), PBL_TICKS()). The struct type stops ticks/ms mix-ups.

  • Return int: 0 on success, -EAGAIN on timeout, -EBUSY for PBL_NO_WAIT.

  • No _from_isr variants: pbl_in_isr() picks the path and any needed context switch is requested inside the call.

  • Mutexes are recursive with owner and lock-site tracking. Non-recursive intent is expressed with pbl_mutex_assert_held(m, false).

  • Priorities: higher is more urgent, PBL_PRIO_IDLE .. PBL_PRIO_MAX.

  • Returning from a thread entry function ends the thread.

Configuration

kernel/Kconfig holds the tick rate, the number of priorities, the NVIC priority levels the kernel uses, the thread limit, the TLS slot count and the stack alignment the MPU guard needs.

kernel/arch/arm/Kconfig describes the CPU: each SoC selects its core (CPU_CORTEX_M4, CPU_CORTEX_M7, CPU_CORTEX_M33, CPU_STAR_MC1) and features (CPU_HAS_FPU, CPU_HAS_FPU_DOUBLE), the core selects its architecture (ARMV7_M, ARMV8_M_MAINLINE) and the architecture its traits (CPU_CORTEX_M_HAS_SPLIM). The compiler flags and the MPU backend are derived from these symbols. Floating-point arguments go in FPU registers (-mfloat-abi=hard) unless FP_SOFTFP_ABI is selected, as the Pebble firmware does for its soft-float apps. QEMU boards pick the emulated core with SOC_QEMU_PEBBLE_CORTEX_M4 or SOC_QEMU_PEBBLE_CORTEX_M33.

Modules

The API reference documents every kernel module.

MCU and SoC

CPU core helpers (pbl/mcu/) wrap the architecture’s interrupt, cache, FPU and MPU control; pbl/soc/ holds what is specific to one SoC family.

The API reference documents both: MCU and SoC.

Generated from PebbleOS 7416f78a1. This page is maintained in the pebbleos repository: docs/kernel/index.md.

Overview

  • Topics
  • Layout
  • Objects
  • Configuration
  • Modules
  • MCU and SoC