Skip to content

Feasibility of linking tinygo with existing C project #2121

Open
@BenShen98

Description

@BenShen98

Background:
I am working on an IoT project involving ZigBee SDK (pre-compiled archive & C code) and FreeRTOS (C & ASM). Targeted for nrf52840 (1MB flash, 256KB RAM) and similar board.

I was writing code in pure C, mainly

  1. RTOS scheduling for running tasks
  2. Protothread-like scheduling for event-based "jobs" within a task (using full-blown RTOS task would create too much overhead)
  3. I am also thinking to add a consensus algorithm for job configurations

I am considering replacing 2) and 3) with golang, since the language got concurrency build in. And I might be able to use an existing consensus algorithm written in go (e.g. etcd/raft).

Question:

  1. I understand tinygo uses LLVM to produce an optimised objective file. The Call-Convention section in the docs mentioned the argument with only integer and pointers will be stable. Does it mean I can invoke functions written in go with a pointer to a C struct, and by using cgo, I can parse the C struct in go without any problem?
  2. On the tinygo documentation, I see more of how to use c code within go. Rather than how to link go code to existing C project. Is this intentional, what are the downsides of doing this?

PS: I know here is not the best place to ask newbie questions, but I can't find a forum online.
Hope it will be informative to other people as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionQuestion about usage of TinyGo

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions