1/*# 2 *#Copyright 2020, 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#include <sel4/sel4.h> 14#include <camkes.h> 15#include <utils/util.h> 16#include <platsupport/gpio.h> 17#include <platsupport/plat/gpio.h> 18 19/*- set client_ids = namespace() -*/ 20/*- if me.parent.type.to_threads == 0 -*/ 21 /*- include 'seL4RPCNoThreads-to.template.c' -*/ 22 /*- from 'global-endpoint.template.c' import allocate_rpc_endpoint_cap with context -*/ 23 /*- do allocate_rpc_endpoint_cap(me.parent.to_end, is_reader=True, other_end=me.parent.from_ends[0]) -*/ 24 /*- set client_ids.badges = pop('badges') -*/ 25/*- else -*/ 26 /*- include 'seL4RPCCall-to.template.c' -*/ 27 /*- from 'rpc-connector.c' import allocate_badges with context -*/ 28 /*- do allocate_badges(client_ids) -*/ 29/*- endif -*/ 30 31/*- set all_allocated_pins = [] -*/ 32/*- set client_allocated_pins = {} -*/ 33/*- for client_end in me.parent.from_ends -*/ 34 /*- set client_pin_configs = configuration[client_end.instance.name].get('%s_pins' % client_end.interface.name) -*/ 35 /*- if client_pin_configs is not none -*/ 36 /*- set client_pin_query = client_pin_configs.get('query') -*/ 37 /*- if client_pin_query is none -*/ 38 /*? raise(TemplateError('Missing GPIO allocation request, please assign GPIO IDs to the GPIO query instance')) ?*/ 39 /*- endif -*/ 40 /*- if client_pin_query[0] is none -*/ 41 /*? raise(TemplateError('Missing GPIO allocation request, please assign GPIO IDs to the GPIO query instance')) ?*/ 42 /*- endif -*/ 43 /*- set client_pins = client_pin_query[0]['desired_pins'] -*/ 44 /*- for pin in client_pins -*/ 45 /*- if pin in all_allocated_pins -*/ 46 /*? raise(TemplateError('Pin %s is being requested by two or more clients!' % pin)) ?*/ 47 /*- endif -*/ 48 /*- endfor -*/ 49 /*- do all_allocated_pins.extend(client_pins) -*/ 50 /*- set badge = client_ids.badges[loop.index0] -*/ 51 /*- do client_allocated_pins.setdefault(badge, []).extend(client_pins) -*/ 52 static gpio_id_t /*? me.interface.name ?*/_/*? badge ?*/_pins[] = { 53 /*- for pin in client_pins -*/ 54 /*? pin ?*/, 55 /*- endfor -*/ 56 -1 57 }; 58 /*- endif -*/ 59/*- endfor -*/ 60 61gpio_id_t */*? me.interface.name ?*/_get_client_pins(seL4_Word badge) 62{ 63 switch (badge) { 64 /*- for badge in client_allocated_pins.keys() -*/ 65 case /*? badge ?*/: 66 return /*? me.interface.name ?*/_/*? badge ?*/_pins; 67 /*- endfor -*/ 68 default: 69 return NULL; 70 } 71 72 assert(!"Should never get here!"); 73} 74 75unsigned int /*? me.interface.name ?*/_num_client_pins(seL4_Word badge) 76{ 77 switch (badge) { 78 /*- for badge in client_allocated_pins.keys() -*/ 79 case /*? badge ?*/: 80 return /*? len(client_allocated_pins[badge]) ?*/; 81 /*- endfor -*/ 82 default: 83 return 0; 84 } 85 86 assert(!"Should never get here!"); 87} 88 89seL4_Word /*? me.interface.name ?*/_get_pin_assignee(gpio_id_t pin_id) 90{ 91 switch (pin_id) { 92 /*- for badge in client_allocated_pins.keys() -*/ 93 /*- for pin in client_allocated_pins[badge] -*/ 94 case /*? pin ?*/: 95 return /*? badge ?*/; 96 /*- endfor -*/ 97 /*- endfor -*/ 98 default: 99 return 0; 100 } 101 102 assert(!"Should never get here!"); 103} 104