test

Dependencies:   mbed Watchdog

Dependents:   STM32-MC_node

Committer:
ommpy
Date:
Mon Jul 06 17:18:59 2020 +0530
Revision:
0:d383e2dee0f7
first commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ommpy 0:d383e2dee0f7 1 /* mbed Microcontroller Library
ommpy 0:d383e2dee0f7 2 * Copyright (c) 2018-2018 ARM Limited
ommpy 0:d383e2dee0f7 3 * SPDX-License-Identifier: Apache-2.0
ommpy 0:d383e2dee0f7 4 *
ommpy 0:d383e2dee0f7 5 * Licensed under the Apache License, Version 2.0 (the "License");
ommpy 0:d383e2dee0f7 6 * you may not use this file except in compliance with the License.
ommpy 0:d383e2dee0f7 7 * You may obtain a copy of the License at
ommpy 0:d383e2dee0f7 8 *
ommpy 0:d383e2dee0f7 9 * http://www.apache.org/licenses/LICENSE-2.0
ommpy 0:d383e2dee0f7 10 *
ommpy 0:d383e2dee0f7 11 * Unless required by applicable law or agreed to in writing, software
ommpy 0:d383e2dee0f7 12 * distributed under the License is distributed on an "AS IS" BASIS,
ommpy 0:d383e2dee0f7 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ommpy 0:d383e2dee0f7 14 * See the License for the specific language governing permissions and
ommpy 0:d383e2dee0f7 15 * limitations under the License.
ommpy 0:d383e2dee0f7 16 */
ommpy 0:d383e2dee0f7 17
ommpy 0:d383e2dee0f7 18 #ifndef __CTHUNK_BASE_H__
ommpy 0:d383e2dee0f7 19 #define __CTHUNK_BASE_H__
ommpy 0:d383e2dee0f7 20
ommpy 0:d383e2dee0f7 21 /* IRQ/Exception compatible thunk entry function */
ommpy 0:d383e2dee0f7 22 typedef void (*CThunkEntry)(void);
ommpy 0:d383e2dee0f7 23
ommpy 0:d383e2dee0f7 24 class CThunkBase {
ommpy 0:d383e2dee0f7 25 protected:
ommpy 0:d383e2dee0f7 26 typedef void (*Trampoline)(CThunkBase *);
ommpy 0:d383e2dee0f7 27
ommpy 0:d383e2dee0f7 28 Trampoline _trampoline;
ommpy 0:d383e2dee0f7 29
ommpy 0:d383e2dee0f7 30 /*
ommpy 0:d383e2dee0f7 31 * Allocate a CThunkEntry which can be called without arguments
ommpy 0:d383e2dee0f7 32 *
ommpy 0:d383e2dee0f7 33 * Calling the CThunkEntry invokes the _trampoline of the
ommpy 0:d383e2dee0f7 34 * given cthunk. This function traps if there are no more
ommpy 0:d383e2dee0f7 35 * free thunks.
ommpy 0:d383e2dee0f7 36 */
ommpy 0:d383e2dee0f7 37 static CThunkEntry cthunk_alloc(CThunkBase *cthunk);
ommpy 0:d383e2dee0f7 38
ommpy 0:d383e2dee0f7 39 /*
ommpy 0:d383e2dee0f7 40 * Free a cthunk_entry so it can be reused
ommpy 0:d383e2dee0f7 41 */
ommpy 0:d383e2dee0f7 42 static void cthunk_free(CThunkEntry cthunk_entry);
ommpy 0:d383e2dee0f7 43
ommpy 0:d383e2dee0f7 44 private:
ommpy 0:d383e2dee0f7 45 typedef void (*CthunkFree)(CThunkEntry cthunk_entry);
ommpy 0:d383e2dee0f7 46
ommpy 0:d383e2dee0f7 47 /*
ommpy 0:d383e2dee0f7 48 * Table of thunk functions
ommpy 0:d383e2dee0f7 49 */
ommpy 0:d383e2dee0f7 50 static const CThunkEntry _thunk_table[MBED_CONF_PLATFORM_CTHUNK_COUNT_MAX];
ommpy 0:d383e2dee0f7 51
ommpy 0:d383e2dee0f7 52 /*
ommpy 0:d383e2dee0f7 53 * Table of active CThunk classes
ommpy 0:d383e2dee0f7 54 */
ommpy 0:d383e2dee0f7 55 static CThunkBase *_thunk_storage[MBED_CONF_PLATFORM_CTHUNK_COUNT_MAX];
ommpy 0:d383e2dee0f7 56
ommpy 0:d383e2dee0f7 57 /*
ommpy 0:d383e2dee0f7 58 * Lazily initialized free function pointer
ommpy 0:d383e2dee0f7 59 */
ommpy 0:d383e2dee0f7 60 static CthunkFree _cthunk_free_real;
ommpy 0:d383e2dee0f7 61
ommpy 0:d383e2dee0f7 62 /*
ommpy 0:d383e2dee0f7 63 * Actual free function
ommpy 0:d383e2dee0f7 64 */
ommpy 0:d383e2dee0f7 65 static void cthunk_free_real(CThunkEntry cthunk_entry);
ommpy 0:d383e2dee0f7 66
ommpy 0:d383e2dee0f7 67 /*
ommpy 0:d383e2dee0f7 68 * Template function which stored in the _thunk_table
ommpy 0:d383e2dee0f7 69 */
ommpy 0:d383e2dee0f7 70 template<int N>
ommpy 0:d383e2dee0f7 71 static void thunk_entry()
ommpy 0:d383e2dee0f7 72 {
ommpy 0:d383e2dee0f7 73 _thunk_storage[N]->_trampoline(_thunk_storage[N]);
ommpy 0:d383e2dee0f7 74 }
ommpy 0:d383e2dee0f7 75 };
ommpy 0:d383e2dee0f7 76
ommpy 0:d383e2dee0f7 77 #endif/*__CTHUNK_BASE_H__*/
ommpy 0:d383e2dee0f7 78