Skip to content

Commit af31c04

Browse files
committed
Merge branch 'master' of https://github.com/yesco/esp-lisp
2 parents d0939a9 + 4efd483 commit af31c04

File tree

6 files changed

+256
-71
lines changed

6 files changed

+256
-71
lines changed

README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,33 @@ Lot's of stuff is missing...
3737

3838
## performace
3939

40-
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).
40+
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).
4141

4242
## how to build
4343

44+
### I want to run it on my linux/cygwin, I have GCC
45+
46+
- Get https://github.com/yesco/esp-lisp
47+
- esp-lisp> ./run
48+
49+
It'll compile and run it for you, you'll have a lisp prompt.
50+
51+
lisp> help
52+
...
53+
54+
try out the commands, it also shows what functions/symbols there are
55+
56+
lisp> (+ 3 4)
57+
7
58+
59+
lisp> (setq fac (lambda (n) (if (= n 0) 1 (* n (fac (- n 1))))))
60+
#func[]
61+
62+
lisp> (fac 6)
63+
720
64+
65+
### build embeddable image and flash it to a nodemcu/EPS8266 device
66+
4467
In a directory:
4568

4669
- Get https://github.com/SuperHouse/esp-open-rtos (and all it wants)

esplisp.c

Lines changed: 65 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,31 @@
33
/* https://www.mozilla.org/en-US/MPL/2.0/ */
44
/* "driver" for esp-open-rtos put in examples/lisp */
55

6+
#include <string.h>
7+
8+
#include "FreeRTOS.h"
9+
#include "task.h"
10+
611
#include "espressif/esp_common.h"
712
#include "espressif/sdk_private.h"
813
#include "FreeRTOS.h"
914
#include "task.h"
1015
#include "queue.h"
1116

12-
#include <string.h>
17+
#include "ssid_config.h"
18+
19+
#include "lwip/err.h"
20+
#include "lwip/sockets.h"
21+
#include "lwip/sys.h"
22+
#include "lwip/netdb.h"
23+
#include "lwip/dns.h"
1324

1425
#include "lisp.h"
1526

1627
void lispTask(void *pvParameters)
1728
{
18-
lisp env = lispinit();
19-
lisprun(&env);
29+
lisp env = lisp_init();
30+
lisp_run(&env);
2031
return;
2132

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

30-
unsigned int mem = xPortGetFreeHeapSize();
31-
printf("free=%u\r\n", mem);
32-
int start = xTaskGetTickCount();
33-
34-
lisprun(&env);
35-
36-
int tm = (xTaskGetTickCount() - start) * portTICK_RATE_MS;
37-
printf("free=%u USED=%u TIME=%d\r\n", xPortGetFreeHeapSize(), (unsigned int)(mem-xPortGetFreeHeapSize()), tm);
38-
printf("======================================================================\n");
39-
reportAllocs();
40-
41-
start = xTaskGetTickCount();
42-
int i, s = 0;
43-
for(i=0; i<1000000; i++) { s = s + 1; }
44-
tm = (xTaskGetTickCount() - start) * portTICK_RATE_MS;
45-
46-
printf("10,000,000 LOOP (100x lua) TIME=%d\r\n", tm);
47-
printf("======================================================================\n");
41+
lisp_run(&env);
4842

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

6963
static xQueueHandle mainqueue;
7064

71-
void user_init(void)
72-
{
65+
unsigned int lastTick = 0;
66+
int lastMem = 0;
67+
68+
void print_memory_info(int verbose) {
69+
report_allocs(verbose);
70+
71+
int tick = xTaskGetTickCount();
72+
int ms = (tick - lastTick) / portTICK_RATE_MS;
73+
int mem = xPortGetFreeHeapSize();
74+
if (verbose)
75+
printf("=== free=%u USED=%u bytes TIME=%d ms ===\n", mem, lastMem-mem, ms);
76+
else {
77+
if (mem) printf("free=%u ", mem);
78+
if (lastMem-mem) printf("USED=%u bytes ", lastMem-mem);
79+
if (ms) printf("TIME=%d ms ", ms);
80+
}
81+
lastTick = tick;
82+
lastMem = mem;
83+
}
84+
85+
#define max(a,b) \
86+
({ __typeof__ (a) _a = (a); \
87+
__typeof__ (b) _b = (b); \
88+
_a > _b ? _a : _b; })
89+
90+
// can call with NULLs get the default config
91+
void connect_wifi(char* ssid, char* password) {
92+
ssid = ssid ? ssid : WIFI_SSID;
93+
password = password ? password : WIFI_PASS;
94+
95+
struct sdk_station_config config;
96+
memset(config.ssid, 0, sizeof(config.ssid));
97+
memset(config.password, 0, sizeof(config.password));
98+
memcpy(config.ssid, ssid, max(strlen(ssid), sizeof(config.ssid)));
99+
memcpy(config.password, password, sizeof(config.password));
100+
101+
sdk_wifi_set_opmode(STATION_MODE);
102+
sdk_wifi_station_set_config(&config);
103+
}
104+
105+
// want callback for tasks
106+
// However, how to handle multiple gets at same time?
107+
// TODO: keep as task as maybe it's blocking?
108+
//void http_get_task(void *pvParameters) {
109+
// vTaskDelay(1000 / portTICK_RATE_MS);
110+
111+
void user_init(void) {
112+
lastTick = xTaskGetTickCount();
113+
lastMem = xPortGetFreeHeapSize();
114+
73115
sdk_uart_div_modify(0, UART_CLK_FREQ / 115200);
74116

75117
mainqueue = xQueueCreate(10, sizeof(uint32_t));

0 commit comments

Comments
 (0)