Skip to content
Snippets Groups Projects
Verified Commit 1f41b761 authored by rahix's avatar rahix
Browse files

feat(api-demo): More code

parent 4c04057e
No related branches found
No related tags found
No related merge requests found
#ifndef _API_H
#define _API_H
#include <stdint.h>
#ifndef API
# define API(id, def) def
#endif
#define API_FOO 0x35c3
API(API_FOO, void foo(short x, int y, char z, int w));
#define API_BAR 0xc0ffee
API(API_BAR, void bar(char*astr));
#define API_BUZZER 0x35c3
API(API_BUZZER, void api_set_buzzer(uint8_t state));
typedef struct {
int foo;
int bar;
int baz;
} qux_t;
uint8_t red;
uint8_t green;
uint8_t blue;
} led_color_t;
#define API_QUX 0xCCC
API(API_QUX, void qux(qux_t q));
#define API_LED 0xc0ffee
API(API_LED, void api_set_led(uint8_t led, led_color_t color));
#endif /* _API_H */
......@@ -50,7 +50,12 @@ def main():
f_client = cx.enter_context(open(args.client, "w"))
f_server = cx.enter_context(open(args.server, "w"))
print('#include "{}"\n'.format(args.header))
print('#include "{}"\n'.format(
os.path.basename(args.header)
), file=f_client)
print('#include "{}"\n'.format(
os.path.basename(args.header)
), file=f_server)
for match in matcher.finditer(source):
api_id = match.group("id")
......@@ -81,7 +86,8 @@ def main():
cdecl=api_decl,
cargs=api_args,
total_size=" + ".join(api_args_sizes),
)
),
file=f_client,
)
for i, (arg, ty) in enumerate(zip(api_args_names, api_args_types)):
......@@ -90,7 +96,8 @@ def main():
type=ty,
offset=" + ".join(api_args_sizes[:i]) if i > 0 else "0",
arg=arg,
)
),
file=f_client,
)
print(
......@@ -103,7 +110,8 @@ def main():
}}
""".format(
id=api_id
)
),
file=f_client,
)
......
......@@ -4,6 +4,7 @@
#include "card10.h"
#include "tmr_utils.h"
#include "api.h"
void Core1_Start(void) {
//MXC_GCR->gp0 = (uint32_t)(&__isr_vector_core1);
......
api_stubs = custom_target(
'api_*.c',
input: 'api.h',
output: ['api_client.c', 'api_server.c'],
command: [
python3,
meson.current_source_dir() + '/genapi.py',
'-H', '@INPUT0@',
'-c', '@OUTPUT0@', '-s', '@OUTPUT1@',
],
depend_files: 'genapi.py',
)
name = 'api-demo-core0'
executable(
name + '.elf',
'main.c',
api_stubs[0],
dependencies: [libcard10, max32665_startup_core0],
link_whole: [max32665_startup_core0_lib, board_card10_lib],
link_args: [
......@@ -15,6 +30,7 @@ name = 'api-demo-core1'
executable(
name + '.elf',
'test-payload.c',
api_stubs[1],
dependencies: [libcard10, max32665_startup_core1],
link_whole: [max32665_startup_core1_lib, board_card10_lib],
link_args: [
......
#include "board.h"
#include "gpio.h"
#include "mxc_delay.h"
#include "api.h"
static const gpio_cfg_t motor_pin = {PORT_0, PIN_8, GPIO_FUNC_OUT, GPIO_PAD_NONE};
void api_set_buzzer(uint8_t state)
{
if (state) {
printf("API: Turning motor ON!\n");
GPIO_OutSet(&motor_pin);
} else {
printf("API: Turning motor OFF!\n");
GPIO_OutClr(&motor_pin);
}
}
void api_set_led(uint8_t led, led_color_t color)
{
printf("API: Changing color of led %d.\n", led);
leds_set(led, color.red, color.green, color.blue);
}
int main(void)
{
// Enable rxev on core1
......@@ -11,11 +29,5 @@ int main(void)
for (int i = 0; 1; i++) {
__asm volatile("wfe");
printf("core1: Hello! %d\n", i);
#if 0
GPIO_OutSet(&motor_pin);
mxc_delay(30000);
GPIO_OutClr(&motor_pin);
#endif
}
}
......@@ -27,5 +27,7 @@ add_global_link_arguments(
language: 'c',
)
python3 = import('python').find_installation('python3')
subdir('lib/')
subdir('hw-tests/')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment