jasonful / lcc Goto Github PK
View Code? Open in Web Editor NEWThis project forked from drh/lcc
The lcc retargetable ANSI C compiler
Home Page: http://sites.google.com/site/lccretargetablecompiler
This project forked from drh/lcc
The lcc retargetable ANSI C compiler
Home Page: http://sites.google.com/site/lccretargetablecompiler
I thought I installed everything according to your instructions on a Windows 10 machine. Unfortunately, I get this error message when I try to compile primes.c
D:\Dropbox\Arduino\lcc\ulpcc\examples>ulpcc primes.c
D:\Dropbox\Arduino\lcc\ulpcc\examples>lcc -I\components\soc\esp32\include -I\components\soc\esp32\include\soc -I\inc -Wf-target=ulp -S primes.c -o primes.S
cpp: primes.c:2 Could not find include file <ulp_c.h>
ulp_c.h is in the \inc directory
First I want to thank Jason for sharing his work !
I'm working on Windows10 and I eventually could get the ulpcc compiler working, but I had to reduce the length of many #defines in the file rtc_cntl_reg.h
exemple:
#define RTC_CNTL_BROWN_OUT_CLOSE_FLASH_ENA_M (BIT(14))
#define RTC_CNTL_BROWN_OUT_CLOSE_FLASH_ENA_V 0x1
#define RTC_CNTL_BROWN_OUT_CLOSE_FLASH_ENA_S 14
changed to the following :
#define RTCCNTLBROWNOUTCLOSEFLASH_ENA_M (BIT(14)) // to make labels shorters
#define RTCCNTLBROWNOUTCLOSEFLASH_ENA_V 0x1
#define RTCCNTLBROWNOUTCLOSEFLASH_ENA_S 14
because otherwise,the compiler appeared to ignore (trim out) the last character(s) and issued a multiple definition error as the beginning of the label was the same for the 3 above defines.
has those defines changed ? have you found a way to have the compiler/preprocessor accept longer labels ? did I missed something ?
best regards,
Jean-Marc.
Hi @jasonful, I've been able to build lcc for Mac OS (10.13.6) and tested it with few very simple examples and it looks pretty good to me. I want to integrate this into my ulptool repository for building ulp assembly files with Arduino, I can issue a pull also if you would like? I can look at linux (ubuntu) also if you want.
Pouring over the source code you did to make this work, my hats off to you!
It looks like a header got moved in newer versions of the ESP-IDF.
If you add the common includes directory as a flag, i.e.:
-I%IDF_PATH%\components\esp_common\include
It appears to resolve this. I'd make a pull request, but I just edited this locally and don't actually know where these flags are in source ๐
Multiplication is repeated addition, DIV is repeated substraction, MOD is DIV with outputting the remainder. I have little experience with building compilers, but those things are manageable in assembler.
I was also thinking about function calls. We could emulate the stack handling and use RTC slow memory (a few dedicated bytes at the end) to allow simple function calls.
Has anyone played with this?
Nice to see a C compiler for the ULP! I've seen you've added I2C peripheral support, but do you have any examples or suggestions how to use SPI? I wanted to use the ULP to push data to a SPI DAC.
Hi Jason,
So I've been looking over this for a few days and see a couple of issues that I would like to bring to the table while working on the the Mac build as of late and somewhat the linux build.
Hi,
I am trying to interface HX711 with ESP32 ULP Processor. I need to read data and shift. I have implemented the logic but it seems data is not correct. Would like to confirm if these functions are supported by library?
Kind Regards
Hi,
It might be me, but element offsets in structs seem to be four times bigger than I would expect e.g. the following extract -
typedef struct {
unsigned value;
unsigned time_high;
unsigned time_middle;
unsigned time_low;
} SAMPLE;
#define SAMPLES_TO_COLLECT 10
SAMPLE sample_list[SAMPLES_TO_COLLECT];
unsigned sample_idx;
sample_list[sample_idx].value = acc;
sample_list[sample_idx].time_high = time_high;
Produces -
move r2,sample_idx
ld r2,r2,0
lsh r2,r2,2
move r1,sample_list
add r2,r2,r1
move r1,entry.acc
ld r1,r1,0
st r1,r2,0
move r2,sample_idx
ld r2,r2,0
lsh r2,r2,2
//move r1,sample_list+16
move r1,sample_list+4
add r2,r2,r1
move r1,time_high
ld r1,r1,0
st r1,r2,0
i.e. an offset of 16 for the second element, when 4 seems to be what's needed.
Incidentally, this is a very useful tool. I didn't bother with the ULP until I found it.
Many thanks
Bob
I've implemented a timer for measuring distances using an HC-04:
while (READ_RTC_REG(RTC_GPIO_IN_REG, RTC_GPIO_IN_NEXT_S + 15, 1) != 0) {
i++;
}
This compiles into (56 Cylces):
L.9:
move r2,entry.raw #Cycles 2+4 = 6
ld r2,r2,0 #Cycles 4+4 = 8
move r3,entry.raw #Cycles 2+4 = 6
st r2,r3,0 #Cycles 4+4 = 8
reg_rd 265,29,29 #Cycles 8+4 = 8
move r0,r0 #Cycles 2+4 = 6
jump L.10, eq #Cycles 2+2 = 4
add r2,r2,1 #Cycles 2+4 = 6
jump L.9 #Cycles 2+2 = 4
L.10:
The above assembly can measure (assuming the speed of sound at 343m/s and the ULP Clock at 8MHz) with a precision of ~1mm.
I've optimized the code to
move r2,entry.raw #Cycles 2+4 = 6
ld r2,r2,0 #Cycles 4+4 = 8
L.9:
reg_rd 265,29,29 #Cycles 8+4 = 8
move r0,r0 #Cycles 2+4 = 6
jump L.10, eq #Cycles 2+2 = 4
add r2,r2,1 #Cycles 2+4 = 6
jump L.9 #Cycles 2+2 = 4
L.10:
move r3,entry.raw #Cycles 2+4 = 6
st r2,r3,0 #Cycles 4+4 = 8
Almost doubling the precision. Is there any way to use inline assembly or "functions" so I don't have to write the entire code in assembly?
Hi
I have tried the test examples in /tst/
and most of them gives all the getrule: Assertion '0' failed
error.
Only tst/incr.c
and tst/init.c
will compile.
I then made a simple example to pin point one kind of error:
$ cat -n foo.c
1 void main(void) {
2 unsigned int i = 3;
3 unsigned int a = sizeof(i);
4 while (i++ < 5) {
5 a = a + bar(a);
6 }
7 }
8 bar(x)
9 unsigned int x;
10 {
11 return 7+x;
12 }
The full command line output:
ff@ubuntu22lts:~/lcc$ ulpcc foo.c
<command-line>: warning: "__STDC__" redefined
<built-in>: note: this is the location of the previous definition
(414b4c0->op=ARGU4 at foo.c:5 is corrupt.)
rcc: src/gen.c:181: getrule: Assertion `0' failed.
/home/ff/lcc/build/lcc: fatal error in /home/ff/lcc/build/rcc
Another strange thing is that when it does compile, the function bar()
without argument a
it does not get called in the foo.S
file.
In line 12 move r2,r0
it is supposed to load the output from bar()
into i
but register r0
never gets loaded with a value (or I missed it).
1 void main(void) {
2 unsigned int i = 3;
3 unsigned int a = sizeof(i);
4 while (i++ < 5) {
5 a = a + bar(); // arg from bar() removed should give error
6 }
7 }
8 bar(x)
9 unsigned int x;
10 {
11 return 7 /*+x*/;
12 }
The foo.S:
1 .global main
2 .text
3 .bss
4 main.a:
5 .space 4
6 .text
7 .bss
8 main.i:
9 .space 4
10 .text
11 main:
12 move r2,3
13 move r3,main.i
14 st r2,r3,0
15 move r2,4
16 move r3,main.a
17 st r2,r3,0
18 jump L.3
19 L.2:
20 move r1,main.a
21 ld r1,r1,0
22 move r2,r0
23 add r2,r1,r2
24 move r3,main.a
25 st r2,r3,0
26 L.3:
27 move r2,main.i
28 ld r2,r2,0
29 add r1,r2,1
30 move r3,main.i
31 st r1,r3,0
32 move r1,5
33 sub r2,r2,r1 #{ if r2 < r1 goto L.2
34 add r2,r2,r1
35 jump L.2, ov #}
36 L.1:
37
38 .global bar
39 bar:
40 move r0,7
41 L.5:
42
43 halt
I'm running on Ubuntu VERSION="22.04.2 LTS (Jammy Jellyfish)"
.
After reading all the assembler output I kind of learned it but I would prefer to use ulpcc instead. It is a great and promising tool.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.