Using Arduino functions in the avr-C

Hi guys!

I’m writing a toy compiler for the ATmega328p using LLVM.
I want to test some functions like millis or analogWrite.

The digitalWrite function I wrote in the avr-C and successfully linked with my code from the toy compiler. The compiler only set function declaration and then avr-gcc links all code together.

So, can I call Arduino functions in this way, and how to do that?

For example, I wrote the digitalWriteLed13High() function in the “avr_native.c”:

#include <avr/io.h>

void digitalWriteLed13High()
	PORTB |= _BV(PB5);

Also, I have digitalWriteLed13High() function declaration and function call in the code from the toy compiler.

I generate then the program.o file and link everything together:

avr-gcc -mmcu=atmega328p -O1 -DF_CPU=16000000 program.o avr_native.c -o program.elf

Can I do this with the Arduino functions and which headers to include in the “avr_native.c”?