gr55xx_fpb.h
Go to the documentation of this file.
1 /**
2 ******************************************************************************
3 *
4 * @file gr55xx_fpb.h
5 *
6 ******************************************************************************
7 * @attention
8 #####Copyright (c) 2019 GOODIX
9 All rights reserved.
10
11 Redistribution and use in source and binary forms, with or without
12 modification, are permitted provided that the following conditions are met:
13 * Redistributions of source code must retain the above copyright
14 notice, this list of conditions and the following disclaimer.
15 * Redistributions in binary form must reproduce the above copyright
16 notice, this list of conditions and the following disclaimer in the
17 documentation and/or other materials provided with the distribution.
18 * Neither the name of GOODIX nor the names of its contributors may be used
19 to endorse or promote products derived from this software without
20 specific prior written permission.
21
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
26 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 POSSIBILITY OF SUCH DAMAGE.
33 *****************************************************************************************
34 */
35
36 /**
37 * @addtogroup SYSTEM
38 * @{
39 */
40
41 /**
42 * @addtogroup FPB
43 * @{
44 * @brief Definitions and prototypes for FPB interface.
45 */
46
47 #ifndef __GR55XX_FPB_H_
48 #define __GR55XX_FPB_H_
49
50 #include <stdint.h>
51 #include <stdio.h>
52 #include <stdbool.h>
53
54 /**
55 *@addtogroup GR55XX_FPB_ENUMERATIONS Enumerations
56 * @{
57 */
58 /**@brief FPB mode. */
59 typedef enum
60 {
61 FPB_MODE_PATCH_ONLY = 0, /**< FPB MODE ENABLE FOR PATCH ONLY*/
62 FPB_MODE_DEBUG_ONLY, /**< FPB MODE ENABLE FOR DEBUG ONLY*/
63 FPB_MODE_PATCH_AND_DEBUG, /**< FPB MODE ENABLE FOR PATCH AND DEBUG*/
64 } fpb_mode_t ;
65
66 /**@brief FPB state. */
67 typedef enum
68 {
69 FPB_PATCH_OFF = 0, /**< FPB patch disable */
70 FPB_PATCH_ON, /**< FPB patch enable */
71 } fpb_state_t;
72
73 /**@brief FPB register. */
74 typedef struct
75 {
76 volatile uint32_t CTRL; /**< Offset: 0x000 (R/W) Data */
77 volatile uint32_t REMAP; /**< Offset: 0x004 (R/W) Data */
78 volatile uint32_t COMP[8]; /**< Offset: 0x008 (R) Data */
79 } FPB_REG_TypeDef;
80 /** @} */
81
82 /** @addtogroup GR55XX_FPB_DEFINES Defines
83 * @{
84 */
85 #define FPB ((FPB_REG_TypeDef *) 0xE0002000UL) /**< FPB Register Address. */
86 /** @} */
87
88
89 /**
90 * @defgroup GR55XX_FPB_TYPEDEF Typedefs
91 * @{
92 */
93 /**@brief FPB function.*/
94 typedef void(*fun_t)(void);
95 /** @} */
96
97 /**
98 * @defgroup GR55XX_FPB_FUNCTION Functions
99 * @{
100 */
101 /**
102 ****************************************************************************************
103 * @brief Enabling patch function
104 * @param[in] index_start : Start Index Number
105 * @param[in] index_end : End Index Number
106 * @retval : void
107 ****************************************************************************************
108 */
109 void fpb_enable(uint8_t index_start ,uint8_t index_end);
110
111 /**
112 ****************************************************************************************
113 * @brief Replace old and new functions
114 * @param[in] ori_func : primitive function address
115 * @param[in] rep_func : replacement function address
116 * @param[in] patch_table_num : group number
117 * @retval : void
118 ****************************************************************************************
119 */
120 int fun_replace_by_svc(uint32_t ori_func, uint32_t rep_func, uint8_t patch_table_num);
121
122 /**
123 ****************************************************************************************
124 * @brief SVC handler process function
125 * @retval : void
126 ****************************************************************************************
127 */
128 uint32_t SVC_handler_proc(uint32_t *svc_args);
129
130 /**
131 ****************************************************************************************
132 * @brief Register FPB patch enable function
133 * @param[in] patch_enable_func : pointer of function
134 * @retval : void
135 ****************************************************************************************
136 */
137 void fpb_register_patch_init_func(fun_t patch_enable_func);
138
139 /**
140 ****************************************************************************************
141 * @brief FPB init function
142 * @param[in] fpb_mode : the mode of FPB
143 * @retval : void
144 ****************************************************************************************
145 */
146 void fpb_init(fpb_mode_t fpb_mode);
147
148 /**
149 ****************************************************************************************
150 * @brief svc sub-function register
151 * @param[in] svc_num : the number of svc
152 * @param[in] func : sub-function callback
153 * @retval : void
154 ****************************************************************************************
155 */
156 void svc_func_register(uint8_t svc_num, uint32_t func);
157
158 /**
159 ****************************************************************************************
160 * @brief register sve table function
161 * @param[in] p_svc_table : the pointer of sve table
162 * @retval : void
163 ****************************************************************************************
164 */
165 void svc_table_register(uint32_t *p_svc_table);
166
167 /**
168 ****************************************************************************************
169 * @brief register fpb space from user layer
170 * @param[in] user_fpb_space : the pointer of fpb user space
171 * @retval : void
172 ****************************************************************************************
173 */
174 void fpb_register_user_space(uint32_t *user_fpb_space);
175
176 /**
177 ****************************************************************************************
178 * @brief save the FPB state
179 *
180 * @retval : FPB state
181 ****************************************************************************************
182 */
183 fpb_state_t fpb_save_state(void);
184
185 /**
186 ****************************************************************************************
187 * @brief load the FPB state
188 * @param[in] state : the FPB state that needs to be loaded
189 * @retval : void
190 ****************************************************************************************
191 */
192 void fpb_load_state(fpb_state_t state);
193
194 /** @} */
195 #endif
196 /** @} */
197 /** @} */
198
fun_t
void(* fun_t)(void)
FPB function.
Definition: gr55xx_fpb.h:94
fpb_init
void fpb_init(fpb_mode_t fpb_mode)
FPB init function.
FPB_REG_TypeDef::REMAP
volatile uint32_t REMAP
Offset: 0x004 (R/W) Data.
Definition: gr55xx_fpb.h:77
fun_replace_by_svc
int fun_replace_by_svc(uint32_t ori_func, uint32_t rep_func, uint8_t patch_table_num)
Replace old and new functions.
FPB_PATCH_ON
@ FPB_PATCH_ON
FPB patch enable
Definition: gr55xx_fpb.h:70
FPB_PATCH_OFF
@ FPB_PATCH_OFF
FPB patch disable.
Definition: gr55xx_fpb.h:69
fpb_load_state
void fpb_load_state(fpb_state_t state)
load the FPB state
FPB_REG_TypeDef::CTRL
volatile uint32_t CTRL
Offset: 0x000 (R/W) Data.
Definition: gr55xx_fpb.h:76
FPB_REG_TypeDef
FPB register.
Definition: gr55xx_fpb.h:75
FPB_MODE_PATCH_ONLY
@ FPB_MODE_PATCH_ONLY
FPB MODE ENABLE FOR PATCH ONLY.
Definition: gr55xx_fpb.h:61
FPB_MODE_DEBUG_ONLY
@ FPB_MODE_DEBUG_ONLY
FPB MODE ENABLE FOR DEBUG ONLY.
Definition: gr55xx_fpb.h:62
FPB_MODE_PATCH_AND_DEBUG
@ FPB_MODE_PATCH_AND_DEBUG
FPB MODE ENABLE FOR PATCH AND DEBUG.
Definition: gr55xx_fpb.h:63
svc_table_register
void svc_table_register(uint32_t *p_svc_table)
register sve table function
fpb_enable
void fpb_enable(uint8_t index_start, uint8_t index_end)
Enabling patch function.
fpb_register_user_space
void fpb_register_user_space(uint32_t *user_fpb_space)
register fpb space from user layer
fpb_register_patch_init_func
void fpb_register_patch_init_func(fun_t patch_enable_func)
Register FPB patch enable function.
fpb_state_t
fpb_state_t
FPB state.
Definition: gr55xx_fpb.h:68
fpb_save_state
fpb_state_t fpb_save_state(void)
save the FPB state
svc_func_register
void svc_func_register(uint8_t svc_num, uint32_t func)
svc sub-function register
fpb_mode_t
fpb_mode_t
FPB mode.
Definition: gr55xx_fpb.h:60
SVC_handler_proc
uint32_t SVC_handler_proc(uint32_t *svc_args)
SVC handler process function.