mirror of
https://github.com/ringtailsoftware/uvm32.git
synced 2026-06-05 22:43:39 +00:00
50 lines
1.2 KiB
C
50 lines
1.2 KiB
C
// Common to all target code
|
|
|
|
#include "uvm32_sys.h"
|
|
|
|
// Basic types
|
|
typedef long uint32_t;
|
|
typedef char uint8_t;
|
|
typedef int bool;
|
|
#define true 1
|
|
#define false 0
|
|
|
|
static uint32_t syscall(uint32_t id, uint32_t param) {
|
|
register uint32_t a0 asm("a0") = (uint32_t)(param);
|
|
register uint32_t a1 asm("a1");
|
|
register uint32_t a7 asm("a7") = (uint32_t)(id);
|
|
|
|
asm volatile (
|
|
"ecall"
|
|
: "=r"(a1) // output
|
|
: "r"(a0), "r"(a7) // input
|
|
: "memory"
|
|
);
|
|
return a1;
|
|
}
|
|
|
|
#define syscall_cast(id, x) syscall((uint32_t)id, (uint32_t)x)
|
|
#define println(x) syscall_cast(UVM32_SYSCALL_PRINTLN, x)
|
|
#define print(x) syscall_cast(UVM32_SYSCALL_PRINT, x)
|
|
#define printd(x) syscall_cast(UVM32_SYSCALL_PRINTD, x)
|
|
#define printx(x) syscall_cast(UVM32_SYSCALL_PRINTX, x)
|
|
#define millis() syscall_cast(UVM32_SYSCALL_MILLIS, 0)
|
|
#define printc() syscall_cast(UVM32_SYSCALL_PRINTC, 0)
|
|
#define getc() syscall_cast(UVM32_SYSCALL_GETC, 0)
|
|
#define yield() syscall_cast(UVM32_SYSCALL_YIELD, 0)
|
|
|
|
#include "uvm32_common_custom.h"
|
|
|
|
// provide main, with setup()/loop() flow
|
|
void setup(void);
|
|
bool loop(void);
|
|
|
|
#ifndef USE_MAIN
|
|
void main(void) {
|
|
setup();
|
|
while(loop()) {
|
|
yield();
|
|
}
|
|
}
|
|
#endif
|
|
|