# locden/template-lstk-armm3m4 architecture

> Architecture diagram of the GitHub repository locden/template-lstk-armm3m4, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/locden/template-lstk-armm3m4
- Repository: https://github.com/locden/template-lstk-armm3m4

## Overview

##### Project type and purpose
- This is an embedded event-driven kernel (“LSTK”) implementing an Active Object model with priority-based preemption.
- It provides per-task message queues, a non-blocking timer service, an Observer pattern, and basic memory-pool management.

##### Main components (focus on Application/lstk folder)
- Kernel Core
- fsm: Finite-State-Machine dispatching
- message: Message queue management
- observer: Subject/Observer notification
- task: Task control and scheduling
- timer: Time-event management
- tsm: Time-switch model (internal state transitions)
- Hardware Abstraction
- ports/ltk_port: Bridge to low-level HW or RTOS tick

##### Listing all public functions in each LSTK component

- LTK_Fsm_init(Fsm_t *me, ...)
- LTK_Fsm_dispatch(Fsm_t *me, const LTK_Evt_t *e)

- LTK_Message_init(MsgQ_t *q)
- LTK_Message_post(MsgQ_t *q, const LTK_Evt_t *e)
- LTK_Message_get(MsgQ_t *q)
- LTK_Message_remove(MsgQ_t *q, const LTK_Evt_t *e)

- LTK_observerInit(obs_sub_t *sub, LTK_Signal sig)
- LTK_observerAttach(obs_sub_t *sub, LTK_Task_t *node)
- LTK_observerDetach(obs_sub_t *sub, LTK_Task_t *node)
- LTK_observerNotify(obs_sub_t *sub, const LTK_Evt_t *e)

- LTK_Task_init(LTK_Task_t *me, uint8_t prio, MsgQ_t *q)
- LTK_Task_post(LTK_Task_t *me, const LTK_Evt_t *e)
- LTK_Task_run(LTK_Task_t *me)
- LTK_Task_dispatch(LTK_Task_t *me, const LTK_Evt_t *e)

- LTK_TimeEvt_arm(LTK_TimeEvt_t *me, uint32_t ctr, uint32_t interval)
- LTK_TimeEvt_disarm(LTK_TimeEvt_t *me)
- LTK_Timer_tickHandler(void)   // called from ports/interrupt

- LTK_TSM_init(LTK_Tsm_t *me)
- LTK_TSM_dispatch(LTK_Tsm_t *me, const LTK_Evt_t *e)

- LTK_Port_init(void)
- LTK_Port_tickISR(void)
- LTK_Port_enterCritical(void)
- LTK_Port_exitCritical(void)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External sources
    Tick["Hardware/RTOS Tick"]:::external
    App["Application Code"]:::external

    %% Kernel container
    subgraph "LSTK Kernel"
        direction TB
        ports["ports/ltk_port\n• LTK_Port_init()\n• LTK_Port_tickISR()\n• LTK_Port_enterCritical()\n• LTK_Port_exitCritical()"]:::port
        timer["timer\n• LTK_TimeEvt_arm()\n• LTK_TimeEvt_disarm()\n• LTK_Timer_tickHandler()"]:::timer
        message["message\n• LTK_Message_init()\n• LTK_Message_post()\n• LTK_Message_get()\n• LTK_Message_remove()"]:::message
        task["task\n• LTK_Task_init()\n• LTK_Task_post()\n• LTK_Task_run()\n• LTK_Task_dispatch()"]:::task
        fsm["fsm\n• LTK_Fsm_init()\n• LTK_Fsm_dispatch()"]:::fsm
        tsm["tsm\n• LTK_TSM_init()\n• LTK_TSM_dispatch()"]:::tsm
        observer["observer\n• LTK_observerInit()\n• LTK_observerAttach()\n• LTK_observerDetach()\n• LTK_observerNotify()"]:::observer
    end

    %% Data flows
    Tick -->|"LTK_Port_tickISR() →"| ports
    ports -->|"LTK_Timer_tickHandler() →"| timer
    timer -->|"LTK_Message_post() →"| message
    message -->|"deliver_event() →"| task
    App -->|"LTK_Task_post() →"| task
    task -->|"LTK_Task_dispatch() →"| fsm
    observer -.->|"LTK_observerNotify() →"| task

    %% Click Events
    click fsm "https://github.com/locden/template-lstk-armm3m4/blob/master/Application/lstk/fsm.h"
    click message "https://github.com/locden/template-lstk-armm3m4/blob/master/Application/lstk/message.h"
    click observer "https://github.com/locden/template-lstk-armm3m4/blob/master/Application/lstk/observer.h"
    click task "https://github.com/locden/template-lstk-armm3m4/blob/master/Application/lstk/task.h"
    click timer "https://github.com/locden/template-lstk-armm3m4/blob/master/Application/lstk/timer.h"
    click tsm "https://github.com/locden/template-lstk-armm3m4/blob/master/Application/lstk/tsm.h"
    click ports "https://github.com/locden/template-lstk-armm3m4/blob/master/Application/lstk/ports/ltk_port.h"

    %% Styles
    classDef external fill:#f9f,stroke:#333,stroke-width:1px;
    classDef fsm fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef message fill:#008080,stroke:#000,stroke-width:1px;
    classDef observer fill:#FFA500,stroke:#000,stroke-width:1px;
    classDef task fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef timer fill:#DDA0DD,stroke:#000,stroke-width:1px;
    classDef tsm fill:#FFC0CB,stroke:#000,stroke-width:1px;
    classDef port fill:#D3D3D3,stroke:#000,stroke-width:1px;
```
