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 /* IRQ/Exception compatible thunk entry function */
22 typedef void (*CThunkEntry)(void);
23 
24 class CThunkBase {
25 protected:
26  typedef void (*Trampoline)(CThunkBase *);
27 
28  Trampoline _trampoline;
29 
30  /*
31  * Allocate a CThunkEntry which can be called without arguments
32  *
33  * Calling the CThunkEntry invokes the _trampoline of the
34  * given cthunk. This function traps if there are no more
35  * free thunks.
36  */
37  static CThunkEntry cthunk_alloc(CThunkBase *cthunk);
38 
39  /*
40  * Free a cthunk_entry so it can be reused
41  */
42  static void cthunk_free(CThunkEntry cthunk_entry);
43 
44 private:
45  typedef void (*CthunkFree)(CThunkEntry cthunk_entry);
46 
47  /*
48  * Table of thunk functions
49  */
50  static const CThunkEntry _thunk_table[MBED_CONF_PLATFORM_CTHUNK_COUNT_MAX];
51 
52  /*
53  * Table of active CThunk classes
54  */
55  static CThunkBase *_thunk_storage[MBED_CONF_PLATFORM_CTHUNK_COUNT_MAX];
56 
57  /*
58  * Lazily initialized free function pointer
59  */
60  static CthunkFree _cthunk_free_real;
61 
62  /*
63  * Actual free function
64  */
65  static void cthunk_free_real(CThunkEntry cthunk_entry);
66 
67  /*
68  * Template function which stored in the _thunk_table
69  */
70  template<int N>
71  static void thunk_entry()
72  {
73  _thunk_storage[N]->_trampoline(_thunk_storage[N]);
74  }
75 };
76 
77 #endif/*__CTHUNK_BASE_H__*/
78 
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.