Adding start of interrupts and moving rtos words to vocab.

This commit is contained in:
Brad Nelson
2021-03-28 23:49:49 -07:00
parent 9af4861de4
commit 9f62c3b99e
2 changed files with 67 additions and 0 deletions

View File

@ -15,6 +15,7 @@
#define ENABLE_I2C_SUPPORT
#define ENABLE_SOCKETS_SUPPORT
#define ENABLE_FREERTOS_SUPPORT
#define ENABLE_INTERRUPTS_SUPPORT
// Uncomment this #define for OLED Support.
// You will need to install these libraries from the Library Manager:
@ -128,6 +129,7 @@
OPTIONAL_CAMERA_SUPPORT \
OPTIONAL_SOCKETS_SUPPORT \
OPTIONAL_FREERTOS_SUPPORT \
OPTIONAL_INTERRUPTS_SUPPORT \
OPTIONAL_OLED_SUPPORT \
#ifndef ENABLE_SPIFFS_SUPPORT
@ -156,6 +158,19 @@
Y(xPortGetCoreID, PUSH xPortGetCoreID())
#endif
#ifndef ENABLE_INTERRUPTS_SUPPORT
# define OPTIONAL_INTERRUPTS_SUPPORT
#else
# include "esp_intr_alloc.h"
# include "driver/gpio.h"
# define OPTIONAL_INTERRUPTS_SUPPORT \
Y(gpio_isr_handler_add, n0 = GpioIsrHandlerAdd((gpio_num_t) n2, n1, n0); NIPn(2)) \
Y(gpio_isr_handler_remove, n0 = gpio_isr_handler_remove((gpio_num_t) n0)) \
Y(gpio_install_isr_service, n0 = gpio_install_isr_service(n0)) \
Y(esp_intr_alloc, n0 = EspIntrAlloc(n4, n3, n2, n1, a0); NIPn(4)) \
Y(esp_intr_free, n0 = esp_intr_free((intr_handle_t) n0))
#endif
#ifndef ENABLE_CAMERA_SUPPORT
# define OPTIONAL_CAMERA_SUPPORT
#else
@ -368,6 +383,9 @@ static Adafruit_SSD1306 *oled_display = 0;
static char filename[PATH_MAX];
static String string_value;
static cell_t EspIntrAlloc(cell_t source, cell_t flags, cell_t xt, cell_t arg, cell_t *ret);
static cell_t GpioIsrHandlerAdd(cell_t pin, cell_t xt, cell_t arg);
{{core}}
{{interp}}
{{boot}}
@ -419,6 +437,41 @@ static void InvokeWebServerOn(WebServer *ws, const char *url, cell_t xt) {
}
#endif
struct handle_interrupt_args {
cell_t xt;
cell_t arg;
};
static void IRAM_ATTR HandleInterrupt(void *arg) {
struct handle_interrupt_args *args = (struct handle_interrupt_args *) arg;
cell_t code[2];
code[0] = args->xt;
code[1] = g_sys.YIELD_XT;
cell_t stack[16];
cell_t rstack[16];
stack[0] = args->arg;
cell_t *rp = rstack;
*++rp = (cell_t) (stack + 1);
*++rp = (cell_t) code;
forth_run(rp);
}
static cell_t EspIntrAlloc(cell_t source, cell_t flags, cell_t xt, cell_t arg, void *ret) {
// NOTE: Leaks memory.
struct handle_interrupt_args *args = (struct handle_interrupt_args *) malloc(sizeof(struct handle_interrupt_args));
args->xt = xt;
args->arg = arg;
return esp_intr_alloc(source, flags, HandleInterrupt, args, (intr_handle_t *) ret);
}
static cell_t GpioIsrHandlerAdd(cell_t pin, cell_t xt, cell_t arg) {
// NOTE: Leaks memory.
struct handle_interrupt_args *args = (struct handle_interrupt_args *) malloc(sizeof(struct handle_interrupt_args));
args->xt = xt;
args->arg = arg;
return gpio_isr_handler_add((gpio_num_t) pin, HandleInterrupt, args);
}
void setup() {
cell_t *heap = (cell_t *) malloc(HEAP_SIZE);
forth_init(0, 0, heap, boot, sizeof(boot));

View File

@ -86,6 +86,20 @@ transfer{
16 constant sizeof(sockaddr_in)
forth definitions
vocabulary interrupts interrupts definitions
transfer{
gpio_isr_handler_add gpio_isr_handler_remove gpio_install_isr_service
esp_intr_alloc esp_intr_free
}transfer
0 constant ESP_INTR_FLAG_DEFAULT
forth definitions
vocabulary rtos rtos definitions
transfer{
xPortGetCoreID xTaskCreatePinnedToCore vTaskDelete
}transfer
forth definitions
DEFINED? SerialBT.new [IF]
vocabulary bluetooth bluetooth definitions
transfer{