1 // Copyright 2020 The Pigweed Authors
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
7 // https://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
15 // Configuration macros for the pw_rpc module.
20 // The Nanopb-based pw_rpc implementation allocates memory to use for Nanopb
21 // structs for the request and response protobufs. The template function that
22 // allocates these structs rounds struct sizes up to this value so that
23 // different structs can be allocated with the same function. Structs with sizes
24 // larger than this value cause an extra function to be created, which slightly
25 // increases code size.
27 // Ideally, this value will be set to the size of the largest Nanopb struct used
28 // as an RPC request or response. The buffer can be stack or globally allocated
29 // (see PW_RPC_NANOPB_STRUCT_BUFFER_STACK_ALLOCATE).
30 #ifndef PW_RPC_NANOPB_STRUCT_MIN_BUFFER_SIZE
31 #define PW_RPC_NANOPB_STRUCT_MIN_BUFFER_SIZE 64
32 #endif // PW_RPC_NANOPB_STRUCT_MIN_BUFFER_SIZE
34 namespace pw::rpc::cfg {
36 inline constexpr size_t kNanopbStructMinBufferSize =
37 PW_RPC_NANOPB_STRUCT_MIN_BUFFER_SIZE;
39 } // namespace pw::rpc::cfg
41 #undef PW_RPC_NANOPB_STRUCT_MIN_BUFFER_SIZE
43 // This option determines whether to allocate the Nanopb structs on the stack or
44 // in a global variable. Globally allocated structs are NOT thread safe, but
45 // work fine when the RPC server's ProcessPacket function is only called from
47 #ifndef PW_RPC_NANOPB_STRUCT_BUFFER_STACK_ALLOCATE
48 #define PW_RPC_NANOPB_STRUCT_BUFFER_STACK_ALLOCATE 1
49 #endif // PW_RPC_NANOPB_STRUCT_BUFFER_STACK_ALLOCATE
51 #if PW_RPC_NANOPB_STRUCT_BUFFER_STACK_ALLOCATE
52 #define _PW_RPC_NANOPB_STRUCT_STORAGE_CLASS
54 #define _PW_RPC_NANOPB_STRUCT_STORAGE_CLASS static
55 #endif // PW_RPC_NANOPB_STRUCT_BUFFER_STACK_ALLOCATE
57 #undef PW_RPC_NANOPB_STRUCT_BUFFER_STACK_ALLOCATE