diff --git a/hw-tests/api-demo/api.h b/hw-tests/api-demo/api.h index 7283a779edf9a1d2325cab3c937b74e0330ba53e..797a3a33ec6732a1d558385e176584a136c91523 100644 --- a/hw-tests/api-demo/api.h +++ b/hw-tests/api-demo/api.h @@ -1,23 +1,21 @@ #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 */ diff --git a/hw-tests/api-demo/genapi.py b/hw-tests/api-demo/genapi.py index 3316875efbb86241ed2ee2884518bd196ebbc2a5..3aacbdc02aa37bb7801d21c73ba45278bb1f36b7 100644 --- a/hw-tests/api-demo/genapi.py +++ b/hw-tests/api-demo/genapi.py @@ -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, ) diff --git a/hw-tests/api-demo/main.c b/hw-tests/api-demo/main.c index a78e9ea666c583c858c6d2d9c8a880e37ace5f0b..d3e4fe6b314ceabef6d9938f4f9850b890592f64 100644 --- a/hw-tests/api-demo/main.c +++ b/hw-tests/api-demo/main.c @@ -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); diff --git a/hw-tests/api-demo/meson.build b/hw-tests/api-demo/meson.build index a86ba8c8fb254fd45a111e191862c1f842ece711..2440a8ad3ca7ebf91652fdf93b0d5140675d2c7a 100644 --- a/hw-tests/api-demo/meson.build +++ b/hw-tests/api-demo/meson.build @@ -1,8 +1,23 @@ +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: [ diff --git a/hw-tests/api-demo/test-payload.c b/hw-tests/api-demo/test-payload.c index 989c611a026d2241fcda709854fe1abe7e23ca7e..f0aa0fe095d07541bd4d88bfba7744606f7ab40a 100644 --- a/hw-tests/api-demo/test-payload.c +++ b/hw-tests/api-demo/test-payload.c @@ -1,9 +1,27 @@ #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 } } diff --git a/meson.build b/meson.build index e01f491ce24c50d83d478eacf28cde0f3dc18daa..0cb5a984fa08e582ef5ae817d5bac343a04e7213 100644 --- a/meson.build +++ b/meson.build @@ -27,5 +27,7 @@ add_global_link_arguments( language: 'c', ) +python3 = import('python').find_installation('python3') + subdir('lib/') subdir('hw-tests/')