Adding pthreads + arudino threads.

This commit is contained in:
Brad Nelson
2021-02-21 14:16:17 -08:00
parent a8ed647a81
commit 98047c626d
3 changed files with 35 additions and 0 deletions

View File

@ -14,6 +14,7 @@
#define ENABLE_SDCARD_SUPPORT
#define ENABLE_I2C_SUPPORT
#define ENABLE_SOCKETS_SUPPORT
#define ENABLE_FREERTOS_SUPPORT
// For now assume only boards with PSRAM (ESP32-CAM)
// will want SerialBluetooth (very large) and camera support.
@ -117,6 +118,7 @@
OPTIONAL_SERIAL_BLUETOOTH_SUPPORT \
OPTIONAL_CAMERA_SUPPORT \
OPTIONAL_SOCKETS_SUPPORT \
OPTIONAL_FREERTOS_SUPPORT \
#ifndef ENABLE_SPIFFS_SUPPORT
// Provide a default failing SPIFFS.begin
@ -133,6 +135,15 @@
X("SPIFFS.usedBytes", SPIFFS_USED_BYTES, PUSH SPIFFS.usedBytes())
#endif
#ifndef ENABLE_FREERTOS_SUPPORT
# define OPTIONAL_FREERTOS_SUPPORT
#else
# define OPTIONAL_FREERTOS_SUPPORT \
Y(vTaskDelete, vTaskDelete((TaskHandle_t) n0); DROP) \
Y(xTaskCreatePinnedToCore, n0 = xTaskCreatePinnedToCore((TaskFunction_t) a6, c5, n4, a3, (UBaseType_t) n2, (TaskHandler_t *) a1, (BaseType_t) n0); NIPn(6)) \
Y(xPortGetCoreID, PUSH xPortGetCoreID())
#endif
#ifndef ENABLE_CAMERA_SUPPORT
# define OPTIONAL_CAMERA_SUPPORT
#else

View File

@ -17,6 +17,7 @@ static struct {
cell_t *heap, **current, ***context, notfound;
int argc;
char **argv;
cell_t *(*runner)(cell_t *rp); // pointer to forth_run
cell_t *rp; // spot to park main thread
cell_t DOLIT_XT, DOEXIT_XT, YIELD_XT;
} g_sys;
@ -160,4 +161,5 @@ static void forth_init(int argc, char *argv[], void *heap,
*++rp = (cell_t) sp;
*++rp = (cell_t) start;
g_sys.rp = rp;
g_sys.runner = forth_run;
}

22
ueforth/posix/pthreads.fs Normal file
View File

@ -0,0 +1,22 @@
( pthreads )
posix definitions also internals
z" libpthread.so" shared-library pthread
z" pthread_create" 4 pthread pthread_create
z" pthread_join" 2 pthread pthread_join
z" pthread_exit" 1 pthread pthread_exit
'sys 11 cells + @ constant forth_run
: ++! ( n a ) cell+ dup >r ! r> ;
: >entry ( xt sp rp -- rp ) here >r rot , ['] yield , ++! r> swap ++! ;
: thread ( xt dstack rstack -- tid )
here >r cells allot here cell+ >r cells allot r> r> >entry ( rinit )
0 >r rp@ ( rinit tid )
0 rot forth_run swap ( tid attr forth_run rinit )
pthread_create throw r> ;
: join ( tid -- ) 0 pthread_join throw ;
only forth definitions