joey shelton / LED_Demo

Dependencies:   MAX44000 PWM_Tone_Library nexpaq_mdk

Fork of LED_Demo by Maxim nexpaq

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers box_config.h Source File

box_config.h

00001 /*
00002  * Copyright (c) 2013-2016, ARM Limited, All Rights Reserved
00003  * SPDX-License-Identifier: Apache-2.0
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License"); you may
00006  * not use this file except in compliance with the License.
00007  * You may obtain a copy of the License at
00008  *
00009  * http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00013  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 #ifndef __UVISOR_API_BOX_CONFIG_H__
00018 #define __UVISOR_API_BOX_CONFIG_H__
00019 
00020 #include "api/inc/uvisor_exports.h"
00021 #include "api/inc/page_allocator_exports.h"
00022 #include <stddef.h>
00023 #include <stdint.h>
00024 
00025 UVISOR_EXTERN const uint32_t __uvisor_mode;
00026 
00027 #define UVISOR_DISABLED   0
00028 #define UVISOR_PERMISSIVE 1
00029 #define UVISOR_ENABLED    2
00030 
00031 #define UVISOR_SET_MODE(mode) \
00032     UVISOR_SET_MODE_ACL_COUNT(mode, NULL, 0)
00033 
00034 #define UVISOR_SET_MODE_ACL(mode, acl_list) \
00035     UVISOR_SET_MODE_ACL_COUNT(mode, acl_list, UVISOR_ARRAY_COUNT(acl_list))
00036 
00037 #define UVISOR_SET_MODE_ACL_COUNT(mode, acl_list, acl_list_count) \
00038     uint8_t __attribute__((section(".keep.uvisor.bss.boxes"), aligned(32))) __reserved_stack[UVISOR_STACK_BAND_SIZE]; \
00039     \
00040     UVISOR_EXTERN const uint32_t __uvisor_mode = (mode); \
00041     \
00042     static const __attribute__((section(".keep.uvisor.cfgtbl"), aligned(4))) UvisorBoxConfig main_cfg = { \
00043         UVISOR_BOX_MAGIC, \
00044         UVISOR_BOX_VERSION, \
00045         0, \
00046         sizeof(RtxBoxIndex), \
00047         0, \
00048         0, \
00049         0, \
00050         NULL, \
00051         acl_list, \
00052         acl_list_count \
00053     }; \
00054     \
00055     extern const __attribute__((section(".keep.uvisor.cfgtbl_ptr_first"), aligned(4))) void * const main_cfg_ptr = &main_cfg;
00056 
00057 /* Creates a global page heap with at least `minimum_number_of_pages` each of size `page_size` in bytes.
00058  * The total page heap size is at least `minimum_number_of_pages * page_size`. */
00059 #define UVISOR_SET_PAGE_HEAP(page_size, minimum_number_of_pages) \
00060     const uint32_t __uvisor_page_size = (page_size); \
00061     uint8_t __attribute__((section(".keep.uvisor.page_heap"))) \
00062         main_page_heap_reserved[ (page_size) * (minimum_number_of_pages) ]
00063 
00064 
00065 /* this macro selects an overloaded macro (variable number of arguments) */
00066 #define __UVISOR_BOX_MACRO(_1, _2, _3, _4, NAME, ...) NAME
00067 
00068 #define __UVISOR_BOX_CONFIG(box_name, acl_list, acl_list_count, stack_size, context_size) \
00069     \
00070     uint8_t __attribute__((section(".keep.uvisor.bss.boxes"), aligned(32))) \
00071         box_name ## _reserved[ \
00072             UVISOR_STACK_SIZE_ROUND( \
00073                 ( \
00074                     (UVISOR_MIN_STACK(stack_size) + \
00075                     (context_size) + \
00076                     (__uvisor_box_heapsize) + \
00077                     sizeof(RtxBoxIndex) \
00078                 ) \
00079             * 8) \
00080         / 6)]; \
00081     \
00082     static const __attribute__((section(".keep.uvisor.cfgtbl"), aligned(4))) UvisorBoxConfig box_name ## _cfg = { \
00083         UVISOR_BOX_MAGIC, \
00084         UVISOR_BOX_VERSION, \
00085         UVISOR_MIN_STACK(stack_size), \
00086         sizeof(RtxBoxIndex), \
00087         context_size, \
00088         __uvisor_box_heapsize, \
00089         __uvisor_box_lib_config, \
00090         __uvisor_box_namespace, \
00091         acl_list, \
00092         acl_list_count \
00093     }; \
00094     \
00095     extern const __attribute__((section(".keep.uvisor.cfgtbl_ptr"), aligned(4))) void * const box_name ## _cfg_ptr = &box_name ## _cfg;
00096 
00097 #define __UVISOR_BOX_CONFIG_NOCONTEXT(box_name, acl_list, stack_size) \
00098     __UVISOR_BOX_CONFIG(box_name, acl_list, UVISOR_ARRAY_COUNT(acl_list), stack_size, 0) \
00099 
00100 #define __UVISOR_BOX_CONFIG_CONTEXT(box_name, acl_list, stack_size, context_type) \
00101     __UVISOR_BOX_CONFIG(box_name, acl_list, UVISOR_ARRAY_COUNT(acl_list), stack_size, sizeof(context_type)) \
00102     UVISOR_EXTERN context_type *const *const __uvisor_ps;
00103 
00104 #define __UVISOR_BOX_CONFIG_NOACL(box_name, stack_size, context_type) \
00105     __UVISOR_BOX_CONFIG(box_name, NULL, 0, stack_size, sizeof(context_type)) \
00106     UVISOR_EXTERN context_type *const *const __uvisor_ps;
00107 
00108 #define __UVISOR_BOX_CONFIG_NOACL_NOCONTEXT(box_name, stack_size) \
00109     __UVISOR_BOX_CONFIG(box_name, NULL, 0, stack_size, 0)
00110 
00111 #define UVISOR_BOX_CONFIG_ACL(...) \
00112     __UVISOR_BOX_MACRO(__VA_ARGS__, __UVISOR_BOX_CONFIG_CONTEXT, \
00113                                     __UVISOR_BOX_CONFIG_NOCONTEXT, \
00114                                     __UVISOR_BOX_CONFIG_NOACL_NOCONTEXT)(__VA_ARGS__)
00115 
00116 #define UVISOR_BOX_CONFIG_CTX(...) \
00117     __UVISOR_BOX_MACRO(__VA_ARGS__, __UVISOR_BOX_CONFIG_CONTEXT, \
00118                                     __UVISOR_BOX_CONFIG_NOACL, \
00119                                     __UVISOR_BOX_CONFIG_NOACL_NOCONTEXT)(__VA_ARGS__)
00120 
00121 #define UVISOR_BOX_CONFIG(...) \
00122     UVISOR_BOX_CONFIG_ACL(__VA_ARGS__)
00123 
00124 /* Use this macro before box defintion (for example, UVISOR_BOX_CONFIG) to
00125  * define the name of your box. If you don't want a name, use this macro with
00126  * box_namespace as NULL. */
00127 #define UVISOR_BOX_NAMESPACE(box_namespace) \
00128     static const char *const __uvisor_box_namespace = box_namespace
00129 
00130 /* Use this macro before UVISOR_BOX_CONFIG to define the function the main
00131  * thread of your box will use for its body. If you don't want a main thread,
00132  * too bad: you have to have one. */
00133 #define UVISOR_BOX_MAIN(function, priority, stack_size) \
00134     static osThreadDef(function, priority, stack_size); \
00135     static const void * const __uvisor_box_lib_config = osThread(function);
00136 
00137 #define UVISOR_BOX_HEAPSIZE(heap_size) \
00138     static const uint32_t __uvisor_box_heapsize = heap_size;
00139 
00140 #define uvisor_ctx (*__uvisor_ps)
00141 
00142 /* Return the numeric box ID of the current box. */
00143 UVISOR_EXTERN int uvisor_box_id_self(void);
00144 
00145 /* Return the numeric box ID of the box that is calling through the most recent
00146  * secure gateway. Return -1 if there is no secure gateway calling box. */
00147 UVISOR_EXTERN int uvisor_box_id_caller(void);
00148 
00149 /* Copy the box namespace of the specified box ID to the memory provided by
00150  * box_namespace. The box_namespace's length must be at least
00151  * MAX_BOX_NAMESPACE_LENGTH bytes. Return how many bytes were copied into
00152  * box_namespace. Return UVISOR_ERROR_INVALID_BOX_ID if the provided box ID is
00153  * invalid. Return UVISOR_ERROR_BUFFER_TOO_SMALL if the provided box_namespace
00154  * is too small to hold MAX_BOX_NAMESPACE_LENGTH bytes. Return
00155  * UVISOR_ERROR_BOX_NAMESPACE_ANONYMOUS if the box is anonymous. */
00156 UVISOR_EXTERN int uvisor_box_namespace(int box_id, char *box_namespace, size_t length);
00157 
00158 #endif /* __UVISOR_API_BOX_CONFIG_H__ */