diff --git a/hw-tests/api-demo/api/api_dispatcher.c b/hw-tests/api-demo/api/api_dispatcher.c index be5db0967aa78dc0f74f13b9ffb73fd951579662..1c9c73dd8b259e20f2b15e7d7eedebd3b43242b4 100644 --- a/hw-tests/api-demo/api/api_dispatcher.c +++ b/hw-tests/api-demo/api/api_dispatcher.c @@ -12,6 +12,9 @@ int api_init (sys_cfg_sema_t *sys_cfg) return ret; } +/* Generated function */ +void __api_dispatch_call(uint32_t id, void*buffer); + void api_dispatcher() { while (SEMA_GetSema(API_CALL_SEMA) == E_BUSY) {} @@ -22,11 +25,7 @@ void api_dispatcher() } printf("core1: Catched API CALL!\n"); - printf("%d: ",ApiCallSpace->id); - for (int i = 0; i < 16; i++) { - printf("0x%02x ", ((char*)ApiCallSpace->buf)[i]); - } - printf("\n"); + __api_dispatch_call(ApiCallSpace->id, ApiCallSpace->buf); ApiCallSpace->returning = 1; diff --git a/hw-tests/api-demo/core1-dispatcher.c b/hw-tests/api-demo/core1-dispatcher.c index 570a3255577fdd116bfb601904d1e3246675d35b..b0ad77431b5d0531f537efd37e577309b97f385a 100644 --- a/hw-tests/api-demo/core1-dispatcher.c +++ b/hw-tests/api-demo/core1-dispatcher.c @@ -3,6 +3,7 @@ #include "mxc_delay.h" #include "api.h" #include "tmr_utils.h" +#include "leds.h" #include "api/api_dispatcher.h" @@ -22,18 +23,21 @@ void api_set_buzzer(uint8_t state) void api_set_led(uint8_t led, led_color_t color) { printf("API: Changing color of led %d.\n", led); + printf("Color { r: %3d, g: %3d, b: %3d }\n", color.red, color.green, color.blue); leds_set(led, color.red, color.green, color.blue); + leds_update(); } void api_test(char test0, short test1, int test2, long test3) { - printf ("test0: %x, test1: %x, test2: %x, test3: %x\n", - test0, test1, test2, test3); + printf ("test0: %x, test1: %d, test2: %x, test3: %lx\n", + test0, (int)test1, test2, test3); } int main(void) { api_init(NULL); + leds_init(); while (1) { api_dispatcher(); diff --git a/hw-tests/api-demo/genapi.py b/hw-tests/api-demo/genapi.py index 56782979ab07abba68cd84aec162577f41c3e94b..40cf1099e357ef1198d9ef3a732a7915ba074ac5 100644 --- a/hw-tests/api-demo/genapi.py +++ b/hw-tests/api-demo/genapi.py @@ -40,7 +40,7 @@ def main(): # Parse the header for API definitions matcher = re.compile( - r"__GENERATE_API \$ __GEN_ID_(?P<id>\w+) \$ (?P<decl>.+?)\((?P<args>.*?)\) \$", + r"__GENERATE_API \$ __GEN_ID_(?P<id>\w+) \$ void (?P<decl>.+?)\((?P<args>.*?)\) \$", re.DOTALL | re.MULTILINE, ) @@ -53,7 +53,13 @@ def main(): print('#include "{}"\n'.format( os.path.basename(args.header) ), file=f_client) - print('#include "{}"\n'.format( + + print("""\ +#include "{}" + +void __api_dispatch_call(uint32_t id, void*buffer) +{{ + switch (id) {{""".format( os.path.basename(args.header) ), file=f_server) @@ -78,7 +84,8 @@ def main(): print( """\ /* Autogenerated stub for {id} */ -{cdecl}({cargs}) {{ +void {cdecl}({cargs}) +{{ const int size = {total_size}; void*buffer; @@ -93,6 +100,12 @@ def main(): file=f_client, ) + print("""\ + case {id}: + {cdecl}(""".format(id=api_id, cdecl=api_decl), + file=f_server, + ) + for i, (arg, ty) in enumerate(zip(api_args_names, api_args_types)): print( """ *({type}*)(buffer + {offset}) = {arg};""".format( @@ -103,6 +116,28 @@ def main(): file=f_client, ) + if i != 0: + print(",", file=f_server) + + print( + """\ + *({type}*)(buffer + {offset})""".format( + type=ty, + offset=" + ".join(api_args_sizes[:i]) if i > 0 else "0", + ), + file=f_server, + end="", + ) + + print(""" + ); + break;""".format( + cdecl=api_decl, + args=", ".join(api_args_names), + ), + file=f_server, + ) + print( """ printf("Sending call {id}\\nBUF: "); @@ -119,6 +154,15 @@ def main(): file=f_client, ) + print("""\ + default: + printf("Error: API function %x is unknown!!\\n", {id}); + break; + }} +}}""".format( + id=api_id, + ), file=f_server) + if __name__ == "__main__": main() diff --git a/hw-tests/api-demo/main.c b/hw-tests/api-demo/main.c index bb49d153b2cab798ec6e76472b72f7de79439f72..ac615346537a6427e1e1a295347940bd807f8791 100644 --- a/hw-tests/api-demo/main.c +++ b/hw-tests/api-demo/main.c @@ -19,6 +19,7 @@ void Core1_Stop(void) { int main(void) { int count = 0; + led_color_t red = {0x10, 0, 0}; card10_init(); card10_diag(); @@ -31,6 +32,8 @@ int main(void) api_set_buzzer(1); TMR_Delay(MXC_TMR0, MSEC(300), 0); api_set_buzzer(0); + api_set_led(5, red); + api_test(0xAB, 0x7DEF, 0x01, 0x02); while(1) { printf("count = %d\n", count++);