Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/yesco/esp-lisp
Browse files Browse the repository at this point in the history
  • Loading branch information
yesco committed Oct 5, 2015
2 parents d0939a9 + 4efd483 commit af31c04
Show file tree
Hide file tree
Showing 6 changed files with 256 additions and 71 deletions.
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,33 @@ Lot's of stuff is missing...

## performace

The esp-lisp is interpreted, too keep the code small and simple. Compared to lua from the NodeMcu it's about 2x slower, but lua is compiled and uses lots of memory for functions (about 600 bytes for a simple call).
The esp-lisp is interpreted, to keep the code small and simple. Compared to lua from the NodeMcu it's about 2x slower, but lua is compiled and uses lots of memory for functions (about 600 bytes for a simple call).

## how to build

### I want to run it on my linux/cygwin, I have GCC

- Get https://github.com/yesco/esp-lisp
- esp-lisp> ./run

It'll compile and run it for you, you'll have a lisp prompt.

lisp> help
...

try out the commands, it also shows what functions/symbols there are

lisp> (+ 3 4)
7

lisp> (setq fac (lambda (n) (if (= n 0) 1 (* n (fac (- n 1))))))
#func[]

lisp> (fac 6)
720

### build embeddable image and flash it to a nodemcu/EPS8266 device

In a directory:

- Get https://github.com/SuperHouse/esp-open-rtos (and all it wants)
Expand Down
88 changes: 65 additions & 23 deletions esplisp.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,31 @@
/* https://www.mozilla.org/en-US/MPL/2.0/ */
/* "driver" for esp-open-rtos put in examples/lisp */

#include <string.h>

#include "FreeRTOS.h"
#include "task.h"

#include "espressif/esp_common.h"
#include "espressif/sdk_private.h"
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"

#include <string.h>
#include "ssid_config.h"

#include "lwip/err.h"
#include "lwip/sockets.h"
#include "lwip/sys.h"
#include "lwip/netdb.h"
#include "lwip/dns.h"

#include "lisp.h"

void lispTask(void *pvParameters)
{
lisp env = lispinit();
lisprun(&env);
lisp env = lisp_init();
lisp_run(&env);
return;

// TODO: move into a mem info and profile function!
Expand All @@ -27,24 +38,7 @@ void lispTask(void *pvParameters)
while(1) {
//vTaskDelay(300); // 3s

unsigned int mem = xPortGetFreeHeapSize();
printf("free=%u\r\n", mem);
int start = xTaskGetTickCount();

lisprun(&env);

int tm = (xTaskGetTickCount() - start) * portTICK_RATE_MS;
printf("free=%u USED=%u TIME=%d\r\n", xPortGetFreeHeapSize(), (unsigned int)(mem-xPortGetFreeHeapSize()), tm);
printf("======================================================================\n");
reportAllocs();

start = xTaskGetTickCount();
int i, s = 0;
for(i=0; i<1000000; i++) { s = s + 1; }
tm = (xTaskGetTickCount() - start) * portTICK_RATE_MS;

printf("10,000,000 LOOP (100x lua) TIME=%d\r\n", tm);
printf("======================================================================\n");
lisp_run(&env);

xQueueSend(*queue, &count, 0);
count++;
Expand All @@ -68,8 +62,56 @@ void recvTask(void *pvParameters)

static xQueueHandle mainqueue;

void user_init(void)
{
unsigned int lastTick = 0;
int lastMem = 0;

void print_memory_info(int verbose) {
report_allocs(verbose);

int tick = xTaskGetTickCount();
int ms = (tick - lastTick) / portTICK_RATE_MS;
int mem = xPortGetFreeHeapSize();
if (verbose)
printf("=== free=%u USED=%u bytes TIME=%d ms ===\n", mem, lastMem-mem, ms);
else {
if (mem) printf("free=%u ", mem);
if (lastMem-mem) printf("USED=%u bytes ", lastMem-mem);
if (ms) printf("TIME=%d ms ", ms);
}
lastTick = tick;
lastMem = mem;
}

#define max(a,b) \
({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a > _b ? _a : _b; })

// can call with NULLs get the default config
void connect_wifi(char* ssid, char* password) {
ssid = ssid ? ssid : WIFI_SSID;
password = password ? password : WIFI_PASS;

struct sdk_station_config config;
memset(config.ssid, 0, sizeof(config.ssid));
memset(config.password, 0, sizeof(config.password));
memcpy(config.ssid, ssid, max(strlen(ssid), sizeof(config.ssid)));
memcpy(config.password, password, sizeof(config.password));

sdk_wifi_set_opmode(STATION_MODE);
sdk_wifi_station_set_config(&config);
}

// want callback for tasks
// However, how to handle multiple gets at same time?
// TODO: keep as task as maybe it's blocking?
//void http_get_task(void *pvParameters) {
// vTaskDelay(1000 / portTICK_RATE_MS);

void user_init(void) {
lastTick = xTaskGetTickCount();
lastMem = xPortGetFreeHeapSize();

sdk_uart_div_modify(0, UART_CLK_FREQ / 115200);

mainqueue = xQueueCreate(10, sizeof(uint32_t));
Expand Down
Loading

0 comments on commit af31c04

Please sign in to comment.