Skip to content

Commit 1a32b5b

Browse files
committed
Implement locking using FreeRTOS compatibility layer from TinyGo
1 parent 0f0fdf8 commit 1a32b5b

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

espnet/ap.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ package espnet
1717
*/
1818
import "C"
1919

20+
import _ "compat/freertos"
21+
2022
type ESPWiFi struct {
2123
}
2224

espnet/espnet.c

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include <stddef.h>
33
#include <stdio.h>
44
#include "espnet.h"
5+
#include "freertos/FreeRTOS.h"
6+
#include "freertos/semphr.h"
57

68
// Stub functions, to know which functions need to be implemented for OS
79
// functionality.
@@ -70,27 +72,17 @@ static void *_mutex_create(void) {
7072
return NULL;
7173
}
7274

73-
// simplified mutex to continue with call stack
74-
unsigned int mutx = 0;
75-
7675
static void *_recursive_mutex_create(void) {
77-
printf("called: _recursive_mutex_create. ret=%p\n", &mutx);
78-
return &mutx;
76+
return xSemaphoreCreateRecursiveMutex();
7977
}
8078
static void _mutex_delete(void *mutex) {
81-
printf("called: _mutex_delete: %p\n", mutex);
79+
return vSemaphoreDelete(mutex);
8280
}
8381
static int32_t _mutex_lock(void *mutex) {
84-
printf("called: _mutex_lock: %p (%d)\n", mutex, *(unsigned int*)mutex);
85-
// simplified mutex to continue with call stack
86-
*(unsigned int*)mutex = 1;
87-
return 0;
82+
return (int32_t)xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
8883
}
8984
static int32_t _mutex_unlock(void *mutex) {
90-
printf("called: _mutex_unlock: %p (%d)\n", mutex, *(unsigned int*)mutex);
91-
// simplified mutex to continue with call stack
92-
*(unsigned int*)mutex = 0;
93-
return 0;
85+
return (int32_t)xSemaphoreGiveRecursive(mutex);
9486
}
9587
static void * _queue_create(uint32_t queue_len, uint32_t item_size) {
9688
printf("called: _queue_create\n");

0 commit comments

Comments
 (0)