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
Pipeline #342 passed
#ifndef _API_H #ifndef _API_H
#define _API_H #define _API_H
#include <stdint.h>
#ifndef API #ifndef API
# define API(id, def) def # define API(id, def) def
#endif #endif
#define API_FOO 0x35c3 #define API_BUZZER 0x35c3
API(API_FOO, void foo(short x, int y, char z, int w)); API(API_BUZZER, void api_set_buzzer(uint8_t state));
#define API_BAR 0xc0ffee
API(API_BAR, void bar(char*astr));
typedef struct { typedef struct {
int foo; uint8_t red;
int bar; uint8_t green;
int baz; uint8_t blue;
} qux_t; } led_color_t;
#define API_QUX 0xCCC #define API_LED 0xc0ffee
API(API_QUX, void qux(qux_t q)); API(API_LED, void api_set_led(uint8_t led, led_color_t color));
#endif /* _API_H */ #endif /* _API_H */
...@@ -50,7 +50,12 @@ def main(): ...@@ -50,7 +50,12 @@ def main():
f_client = cx.enter_context(open(args.client, "w")) f_client = cx.enter_context(open(args.client, "w"))
f_server = cx.enter_context(open(args.server, "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): for match in matcher.finditer(source):
api_id = match.group("id") api_id = match.group("id")
...@@ -81,7 +86,8 @@ def main(): ...@@ -81,7 +86,8 @@ def main():
cdecl=api_decl, cdecl=api_decl,
cargs=api_args, cargs=api_args,
total_size=" + ".join(api_args_sizes), total_size=" + ".join(api_args_sizes),
) ),
file=f_client,
) )
for i, (arg, ty) in enumerate(zip(api_args_names, api_args_types)): for i, (arg, ty) in enumerate(zip(api_args_names, api_args_types)):
...@@ -90,7 +96,8 @@ def main(): ...@@ -90,7 +96,8 @@ def main():
type=ty, type=ty,
offset=" + ".join(api_args_sizes[:i]) if i > 0 else "0", offset=" + ".join(api_args_sizes[:i]) if i > 0 else "0",
arg=arg, arg=arg,
) ),
file=f_client,
) )
print( print(
...@@ -103,7 +110,8 @@ def main(): ...@@ -103,7 +110,8 @@ def main():
}} }}
""".format( """.format(
id=api_id id=api_id
) ),
file=f_client,
) )
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "card10.h" #include "card10.h"
#include "tmr_utils.h" #include "tmr_utils.h"
#include "api.h"
void Core1_Start(void) { void Core1_Start(void) {
//MXC_GCR->gp0 = (uint32_t)(&__isr_vector_core1); //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' name = 'api-demo-core0'
executable( executable(
name + '.elf', name + '.elf',
'main.c', 'main.c',
api_stubs[0],
dependencies: [libcard10, max32665_startup_core0], dependencies: [libcard10, max32665_startup_core0],
link_whole: [max32665_startup_core0_lib, board_card10_lib], link_whole: [max32665_startup_core0_lib, board_card10_lib],
link_args: [ link_args: [
...@@ -15,6 +30,7 @@ name = 'api-demo-core1' ...@@ -15,6 +30,7 @@ name = 'api-demo-core1'
executable( executable(
name + '.elf', name + '.elf',
'test-payload.c', 'test-payload.c',
api_stubs[1],
dependencies: [libcard10, max32665_startup_core1], dependencies: [libcard10, max32665_startup_core1],
link_whole: [max32665_startup_core1_lib, board_card10_lib], link_whole: [max32665_startup_core1_lib, board_card10_lib],
link_args: [ link_args: [
......
#include "board.h" #include "board.h"
#include "gpio.h" #include "gpio.h"
#include "mxc_delay.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}; 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) int main(void)
{ {
// Enable rxev on core1 // Enable rxev on core1
...@@ -11,11 +29,5 @@ int main(void) ...@@ -11,11 +29,5 @@ int main(void)
for (int i = 0; 1; i++) { for (int i = 0; 1; i++) {
__asm volatile("wfe"); __asm volatile("wfe");
printf("core1: Hello! %d\n", i); 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( ...@@ -27,5 +27,7 @@ add_global_link_arguments(
language: 'c', language: 'c',
) )
python3 = import('python').find_installation('python3')
subdir('lib/') subdir('lib/')
subdir('hw-tests/') 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