mirror of https://github.com/m-labs/artiq.git
Variadic function demo
This commit is contained in:
parent
5a3fa5dbff
commit
a03a60b90e
|
@ -16,7 +16,7 @@ class CompilerTest(Experiment):
|
||||||
prime = 0
|
prime = 0
|
||||||
d = d + 1
|
d = d + 1
|
||||||
if prime == 1:
|
if prime == 1:
|
||||||
syscall("print_int", x)
|
syscall("rpc", 42, x)
|
||||||
x = x + 1
|
x = x + 1
|
||||||
self.led.set(0)
|
self.led.set(0)
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
#include <irq.h>
|
#include <irq.h>
|
||||||
#include <uart.h>
|
#include <uart.h>
|
||||||
|
@ -55,9 +56,17 @@ static int download_kernel(void *buffer, int maxlength)
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_int(int x)
|
static int rpc(int rpc_num, int n_args, ...)
|
||||||
{
|
{
|
||||||
printf("%d\n", x);
|
printf("rpc_num=%d n_args=%d\n", rpc_num, n_args);
|
||||||
|
|
||||||
|
va_list args;
|
||||||
|
va_start(args, n_args);
|
||||||
|
while(n_args--)
|
||||||
|
printf("%d\n", va_arg(args, int));
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gpio_set(int channel, int level)
|
static void gpio_set(int channel, int level)
|
||||||
|
@ -66,7 +75,7 @@ static void gpio_set(int channel, int level)
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct symbol syscalls[] = {
|
static const struct symbol syscalls[] = {
|
||||||
{"__syscall_print_int", print_int},
|
{"__syscall_rpc", rpc},
|
||||||
{"__syscall_gpio_set", gpio_set},
|
{"__syscall_gpio_set", gpio_set},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
@ -78,7 +87,6 @@ int main(void)
|
||||||
unsigned char kbuf[256*1024];
|
unsigned char kbuf[256*1024];
|
||||||
unsigned char kcode[256*1024];
|
unsigned char kcode[256*1024];
|
||||||
kernel_function k = (kernel_function)kcode;
|
kernel_function k = (kernel_function)kcode;
|
||||||
int i;
|
|
||||||
int length;
|
int length;
|
||||||
|
|
||||||
irq_setmask(0);
|
irq_setmask(0);
|
||||||
|
|
Loading…
Reference in New Issue