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

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.