1/*
2 * Copyright 2017, Data61
3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO)
4 * ABN 41 687 119 230.
5 *
6 * This software may be distributed and modified according to the terms of
7 * the BSD 2-Clause license. Note that NO WARRANTY is provided.
8 * See "LICENSE_BSD2.txt" for details.
9 *
10 * @TAG(DATA61_BSD)
11 */
12
13/*- from 'rpc-connector.c' import establish_from_rpc, begin_send, perform_call, release_recv with context -*/
14
15#include <camkes/dataport.h>
16
17/*? macros.show_includes(me.instance.type.includes) ?*/
18/*? macros.show_includes(me.interface.type.includes) ?*/
19
20/*- set connector = namespace() -*/
21
22/*- set buffer = configuration[me.parent.name].get('buffer') -*/
23/*- if buffer is none -*/
24  /*? establish_from_rpc(connector) ?*/
25/*- else -*/
26  /*- if not isinstance(buffer, six.string_types) -*/
27    /*? raise(TemplateError('invalid non-string setting for userspace buffer to back RPC connection', me.parent)) ?*/
28  /*- endif -*/
29  /*- if len(me.parent.from_ends) != 1 or len(me.parent.to_ends) != 1 -*/
30    /*? raise(TemplateError('invalid use of userspace buffer to back RPC connection that is not 1-to-1', me.parent)) ?*/
31  /*- endif -*/
32  /*- set c = list(filter(lambda('x: x.name == \'%s\'' % buffer), composition.connections)) -*/
33  /*- if len(c) == 0 -*/
34    /*? raise(TemplateError('invalid setting to non-existent connection for userspace buffer to back RPC connection', me.parent)) ?*/
35  /*- endif -*/
36  /*- if len(c[0].from_ends) != 1 or len(c[0].to_ends) != 1 -*/
37    /*? raise(TemplateError('invalid use of userspace buffer that is not 1-to-1 to back RPC connection', me.parent)) ?*/
38  /*- endif -*/
39  /*- if not isinstance(c[0].from_end.interface, camkes.ast.Dataport) -*/
40    /*? raise(TemplateError('invalid use of non-dataport to back RPC connection', me.parent)) ?*/
41  /*- endif -*/
42  extern /*? macros.dataport_type(c[0].from_end.interface.type) ?*/ * /*? c[0].from_end.interface.name ?*/;
43  /*# Conservatively count threads in this component to decide if we want lock access to the buffer #*/
44  /*- set thread_count = (1 if me.instance.type.control else 0) + len(me.instance.type.provides) + len(me.instance.type.uses) + len(me.instance.type.emits) + len(me.instance.type.consumes) -*/
45  /*- if thread_count > 1 -*/
46    /*- set lock = True -*/
47  /*- else -*/
48    /*- set lock = False -*/
49  /*- endif -*/
50  /*? establish_from_rpc(connector, buffer=('((void*)%s)' % c[0].from_end.interface.name, macros.dataport_size(c[0].from_end.interface.type), lock)) ?*/
51/*- endif -*/
52
53/*- include 'rpc-connector-common-from.c' -*/
54