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 register. */
67 typedef struct
68 {
69  volatile uint32_t CTRL; /**< Offset: 0x000 (R/W) Data */
70  volatile uint32_t REMAP; /**< Offset: 0x004 (R/W) Data */
71  volatile uint32_t COMP[16]; /**< Offset: 0x008 (R) Data */
73 /** @} */
74 
75 /** @addtogroup GR55XX_FPB_DEFINES Defines
76  * @{
77  */
78 #define FPB ((FPB_REG_TypeDef *) 0xE0002000UL) /**< FPB Register Address. */
79 /** @} */
80 
81 
82 /**
83  * @defgroup GR55XX_FPB_TYPEDEF Typedefs
84  * @{
85  */
86 /**@brief FPB function.*/
87 typedef void(*fun_t)(void);
88 /** @} */
89 
90 /**
91  * @defgroup GR55XX_FPB_FUNCTION Functions
92  * @{
93  */
94  /**
95  ****************************************************************************************
96  * @brief Enabling patch function
97  * @param[in] index_start : Start Index Number
98  * @param[in] index_end : End Index Number
99  * @retval 0 Success
100  * @retval -1 on failure
101  ****************************************************************************************
102  */
103 int8_t fpb_enable(uint8_t index_start, uint8_t index_end);
104 
105 /**
106  ****************************************************************************************
107  * @brief Replace old and new functions
108  * @param[in] ori_func : primitive function address
109  * @param[in] rep_func : replacement function address
110  * @param[in] patch_table_num : group number
111  * @retval 0 Success
112  * @retval -1 on failure
113  ****************************************************************************************
114  */
115 int8_t fun_replace_by_svc(uint32_t ori_func, uint32_t rep_func, uint8_t patch_table_num);
116 
117  /**
118  ****************************************************************************************
119  * @brief SVC handler process function
120  * @param[in] svc_args SVC arguments
121  ****************************************************************************************
122  */
123 uint32_t SVC_handler_proc(uint32_t *svc_args);
124 
125  /**
126  ****************************************************************************************
127  * @brief Register FPB patch enable function
128  * @param[in] patch_enable_func : pointer of function
129  ****************************************************************************************
130  */
131 void fpb_register_patch_init_func(fun_t patch_enable_func);
132 
133  /**
134  ****************************************************************************************
135  * @brief FPB init function
136  * @param[in] fpb_mode : the mode of FPB
137  ****************************************************************************************
138  */
139 void fpb_init(fpb_mode_t fpb_mode);
140 
141  /**
142  ****************************************************************************************
143  * @brief svc sub-function register
144  * @param[in] svc_num : the number of svc
145  * @param[in] func : sub-function callback
146  ****************************************************************************************
147  */
148 void svc_func_register(uint8_t svc_num, uint32_t func);
149 
150  /**
151  ****************************************************************************************
152  * @brief register svc table function
153  * @param[in] p_svc_table : the pointer of svc table
154  ****************************************************************************************
155  */
156 void svc_table_register(uint32_t *p_svc_table);
157 
158  /**
159  ****************************************************************************************
160  * @brief register svc table function
161  * @param[in] p_svc_table : the pointer of svc table
162  * @param[in] size : the size of svc table
163  ****************************************************************************************
164  */
165 void svc_table_register_with_size(uint32_t *p_svc_table, uint16_t size);
166 
167  /**
168  ****************************************************************************************
169  * @brief register fpb space from user layer
170  * @param[in] user_fpb_space : the pointer of fpb user space
171  ****************************************************************************************
172  */
173 void fpb_register_user_space(uint32_t *user_fpb_space);
174 
175  /**
176  ****************************************************************************************
177  * @brief Replace the old variable
178  * @param[in] var_addr : the address of old variable
179  * @param[in] value : the new value
180  * @param[in] patch_table_num : 0 or 1
181  * @retval 0 Success
182  * @retval -1 Failure
183  ****************************************************************************************
184  */
185 int8_t fpb_var_replace(uint32_t var_addr, uint32_t value, uint8_t patch_table_num);
186 
187 /** @} */
188 #endif
189 /** @} */
190 /** @} */
191 
fun_t
void(* fun_t)(void)
FPB function.
Definition: gr55xx_fpb.h:87
svc_table_register_with_size
void svc_table_register_with_size(uint32_t *p_svc_table, uint16_t size)
register svc table function
fpb_enable
int8_t fpb_enable(uint8_t index_start, uint8_t index_end)
Enabling patch function.
fpb_init
void fpb_init(fpb_mode_t fpb_mode)
FPB init function.
fpb_var_replace
int8_t fpb_var_replace(uint32_t var_addr, uint32_t value, uint8_t patch_table_num)
Replace the old variable.
FPB_REG_TypeDef::REMAP
volatile uint32_t REMAP
Definition: gr55xx_fpb.h:70
FPB_REG_TypeDef::CTRL
volatile uint32_t CTRL
Definition: gr55xx_fpb.h:69
FPB_REG_TypeDef
FPB register.
Definition: gr55xx_fpb.h:68
FPB_MODE_PATCH_ONLY
@ FPB_MODE_PATCH_ONLY
Definition: gr55xx_fpb.h:61
FPB_MODE_DEBUG_ONLY
@ FPB_MODE_DEBUG_ONLY
Definition: gr55xx_fpb.h:62
FPB_MODE_PATCH_AND_DEBUG
@ FPB_MODE_PATCH_AND_DEBUG
Definition: gr55xx_fpb.h:63
fun_replace_by_svc
int8_t fun_replace_by_svc(uint32_t ori_func, uint32_t rep_func, uint8_t patch_table_num)
Replace old and new functions.
svc_table_register
void svc_table_register(uint32_t *p_svc_table)
register svc table 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.
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.