Skip to content

Commit

Permalink
cgo: add FreeRTOS compatibility headers
Browse files Browse the repository at this point in the history
This is especially useful if we ever want to support the ESP-IDF.

Currently implemented:

  - xSemaphoreCreateRecursiveMutex
  - xSemaphoreDelete
  - xSemaphoreTakeRecursive
  - xSemaphoreGiveRecursive
  • Loading branch information
aykevl committed Sep 27, 2021
1 parent 21a2d5a commit d4d5083
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions compileopts/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ func (c *Config) RP2040BootPatch() bool {
// preprocessing.
func (c *Config) CFlags() []string {
var cflags []string
// Compatibility CFlags.
cflags = append(cflags, "-I"+filepath.Join(goenv.Get("TINYGOROOT"), "src/compat/freertos/include"))
// CFlags for the target.
for _, flag := range c.Target.CFlags {
cflags = append(cflags, strings.ReplaceAll(flag, "{root}", goenv.Get("TINYGOROOT")))
}
Expand Down
1 change: 1 addition & 0 deletions loader/goroot.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ func needsSyscallPackage(buildTags []string) bool {
func pathsToOverride(needsSyscallPackage bool) map[string]bool {
paths := map[string]bool{
"/": true,
"compat/": false,
"crypto/": true,
"crypto/rand/": false,
"device/": false,
Expand Down
9 changes: 9 additions & 0 deletions src/compat/freertos/include/freertos/FreeRTOS.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include <stdint.h>

typedef uint32_t TickType_t;
typedef int BaseType_t;
typedef unsigned int UBaseType_t;

#define portMAX_DELAY (TickType_t)0xffffffffUL
3 changes: 3 additions & 0 deletions src/compat/freertos/include/freertos/queue.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

typedef struct QueueDefinition * QueueHandle_t;
12 changes: 12 additions & 0 deletions src/compat/freertos/include/freertos/semphr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

// Note: in FreeRTOS, SemaphoreHandle_t is an alias for QueueHandle_t.
typedef struct SemaphoreDefinition * SemaphoreHandle_t;

SemaphoreHandle_t xSemaphoreCreateRecursiveMutex(void);

void vSemaphoreDelete(SemaphoreHandle_t xSemaphore);

// Note: these two functions are macros in FreeRTOS.
BaseType_t xSemaphoreTakeRecursive(SemaphoreHandle_t xMutex, TickType_t xTicksToWait);
BaseType_t xSemaphoreGiveRecursive(SemaphoreHandle_t xMutex);
Empty file.

0 comments on commit d4d5083

Please sign in to comment.