Skip to content

S29.03: Extract shared FreeRTOS BDD-target pipeline; main.c keeps only network wiring #520

Description

@DavidCozens

Parent epic: #512 (E29) · Depends on: S29.01 (done). Independent of S29.04.

Motivation

S29.01 deliberately duplicated the store/security-policy/lifecycle machinery into Bdd/Targets/FreeRtosLwip/main.c rather than DRY it then. The two FreeRTOS target main.c files (1258 + 1111 lines) now share ~600 lines near-verbatim — every store/policy function, the whole OnSet body, the Service task, the SD setup, ErrorHandlerEx, and the message-state globals. The only genuine divergence is the network backend (PlusTcp vs LwipRaw adapter wiring + platform bring-up) and GetHostname (different IP-stack read). Extract the shared surface so a future change (e.g. S29.05's Plus-FAT swap, a new store policy) is made once, not twice-in-sync.

Approach (agreed): one focused refactor

New Bdd/Targets/Common/BddTargetFreeRtosPipeline.{c,h} owning everything platform-independent:

  • State: message globals (appName/msgid/msg/port/…), SD handles + sdList + atomicCounter, CircularBuffer + mutex + ring, lifecycle mutex, solidSyslog + config + ready/teardown flags, all store/policy state.
  • Functions: the helpers, all store/policy lifecycle (RebuildWithFileStore, EnsureFatFsMounted, Create/DestroySecurityPolicy, DestroyCurrentStore, callbacks), the full OnSet, ServiceTask, ErrorHandlerEx, GetAppName/TimeQuality/Endpoint/EndpointVersion, SemihostingExit, the SD/config assembly, and the InteractiveTask body.

Each main.c shrinks to the platform seam — it injects the built switchingSender (its PlusTcp / LwipRaw adapters), a GetHostname callback (reads its IP stack), and a sender-teardown callback, then runs the shared pipeline. main(), IP/tcpip bring-up, hooks, and adapter construction stay in main.c.

Acceptance criteria

  • Shared pipeline TU in Bdd/Targets/Common/; both targets link it; the ~600 duplicated lines exist once.
  • Each main.c retains only network wiring + the injected seam (GetHostname, sender build, sender teardown).
  • Both FreeRTOS targets cross-build clean; no Platform/PlusTcp symbols in the lwIP ELF.
  • Full BDD suite green on both targets (the Tier-3 safety net), incl. the @store suite from S29.01.
  • No behaviour change — pure refactor.

Out of scope

  • The Plus-FAT swap (S29.05); Platform/PlusFat/ (S29.04); any library/Tier-1/2 code.

Environments

freertos-cross (both targets) + docker-compose BDD oracle run for validation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    storyStory issue

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions