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

feat(api-demo): Make API calls work!


Signed-off-by: default avatarRahix <rahix@rahix.de>
parent f9b2e27b
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......
......@@ -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();
......
......@@ -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()
......@@ -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++);
......
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