Implement locking using FreeRTOS compatibility layer from TinyGo

This commit is contained in:
Ayke van Laethem
2021-09-27 16:23:52 +02:00
parent 0f0fdf894c
commit 1a32b5be12
2 changed files with 8 additions and 14 deletions
+2
View File
@@ -17,6 +17,8 @@ package espnet
*/ */
import "C" import "C"
import _ "compat/freertos"
type ESPWiFi struct { type ESPWiFi struct {
} }
+6 -14
View File
@@ -2,6 +2,8 @@
#include <stddef.h> #include <stddef.h>
#include <stdio.h> #include <stdio.h>
#include "espnet.h" #include "espnet.h"
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
// Stub functions, to know which functions need to be implemented for OS // Stub functions, to know which functions need to be implemented for OS
// functionality. // functionality.
@@ -70,27 +72,17 @@ static void *_mutex_create(void) {
return NULL; return NULL;
} }
// simplified mutex to continue with call stack
unsigned int mutx = 0;
static void *_recursive_mutex_create(void) { static void *_recursive_mutex_create(void) {
printf("called: _recursive_mutex_create. ret=%p\n", &mutx); return xSemaphoreCreateRecursiveMutex();
return &mutx;
} }
static void _mutex_delete(void *mutex) { static void _mutex_delete(void *mutex) {
printf("called: _mutex_delete: %p\n", mutex); return vSemaphoreDelete(mutex);
} }
static int32_t _mutex_lock(void *mutex) { static int32_t _mutex_lock(void *mutex) {
printf("called: _mutex_lock: %p (%d)\n", mutex, *(unsigned int*)mutex); return (int32_t)xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
// simplified mutex to continue with call stack
*(unsigned int*)mutex = 1;
return 0;
} }
static int32_t _mutex_unlock(void *mutex) { static int32_t _mutex_unlock(void *mutex) {
printf("called: _mutex_unlock: %p (%d)\n", mutex, *(unsigned int*)mutex); return (int32_t)xSemaphoreGiveRecursive(mutex);
// simplified mutex to continue with call stack
*(unsigned int*)mutex = 0;
return 0;
} }
static void * _queue_create(uint32_t queue_len, uint32_t item_size) { static void * _queue_create(uint32_t queue_len, uint32_t item_size) {
printf("called: _queue_create\n"); printf("called: _queue_create\n");