• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
52 /**
53  * @addtogroup GR55XX_FPB_ENUMERATIONS Enumerations
54  * @{
55  */
56 /** @brief FPB mode. */
57 typedef enum {
58     FPB_MODE_PATCH_ONLY = 0,                /**< FPB MODE ENABLE FOR PATCH ONLY*/
59     FPB_MODE_DEBUG_ONLY,                    /**< FPB MODE ENABLE FOR DEBUG ONLY*/
60     FPB_MODE_PATCH_AND_DEBUG,               /**< FPB MODE ENABLE FOR PATCH AND DEBUG*/
61 } fpb_mode_t ;
62 
63 /** @brief FPB state. */
64 typedef enum {
65     FPB_PATCH_OFF = 0,                      /**< FPB patch disable */
66     FPB_PATCH_ON,                           /**< FPB patch enable  */
67 } fpb_state_t;
68 
69 /** @brief FPB register. */
70 typedef struct {
71     volatile uint32_t CTRL;                 /**< Offset: 0x000 (R/W)  Data */
72     volatile uint32_t REMAP;                /**< Offset: 0x004 (R/W)  Data */
73     volatile uint32_t COMP[8];              /**< Offset: 0x008  (R)   Data */
74 } FPB_REG_TypeDef;
75 /** @} */
76 
77 /** @addtogroup GR55XX_FPB_DEFINES Defines
78  * @{
79  */
80 #define FPB  ((FPB_REG_TypeDef *)  0xE0002000UL) /**< FPB Register Address. */
81 /** @} */
82 
83 
84 /**
85  * @defgroup GR55XX_FPB_TYPEDEF Typedefs
86  * @{
87  */
88 /** @brief FPB function.*/
89 typedef void(*fun_t)(void);
90 /** @} */
91 
92 /**
93  * @defgroup GR55XX_FPB_FUNCTION Functions
94  * @{
95  */
96 /**
97 ****************************************************************************************
98 * @brief  Enabling patch function
99 * @param[in] index_start :  Start Index Number
100 * @param[in] index_end   :  End Index Number
101 * @retval :  void
102 ****************************************************************************************
103 */
104 void fpb_enable(uint8_t index_start, uint8_t index_end);
105 
106 /**
107  ****************************************************************************************
108  * @brief  Replace old and new functions
109  * @param[in] ori_func : primitive function address
110  * @param[in] rep_func : replacement function address
111  * @param[in] patch_table_num : group number
112  * @retval :  void
113  ****************************************************************************************
114  */
115 int 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 * @retval :  void
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 * @retval :  void
130 ****************************************************************************************
131 */
132 void fpb_register_patch_init_func(fun_t patch_enable_func);
133 
134 /**
135 ****************************************************************************************
136 * @brief  FPB init function
137 * @param[in] fpb_mode : the mode of FPB
138 * @retval :  void
139 ****************************************************************************************
140 */
141 void fpb_init(fpb_mode_t fpb_mode);
142 
143 /**
144 ****************************************************************************************
145 * @brief  svc sub-function register
146 * @param[in] svc_num : the number of svc
147 * @param[in] func : sub-function callback
148 * @retval :  void
149 ****************************************************************************************
150 */
151 void svc_func_register(uint8_t svc_num, uint32_t func);
152 
153 /**
154 ****************************************************************************************
155 * @brief  register sve table function
156 * @param[in] p_svc_table : the pointer of sve table
157 * @retval :  void
158 ****************************************************************************************
159 */
160 void svc_table_register(uint32_t *p_svc_table);
161 
162 /**
163  ****************************************************************************************
164  * @brief  register fpb space from user layer
165  * @param[in] user_fpb_space : the pointer of fpb user space
166  * @retval :  void
167  ****************************************************************************************
168  */
169 void fpb_register_user_space(uint32_t *user_fpb_space);
170 
171 /**
172 ****************************************************************************************
173 * @brief  save the FPB state
174 *
175 * @retval : FPB state
176 ****************************************************************************************
177 */
178 fpb_state_t fpb_save_state(void);
179 
180 /**
181 ****************************************************************************************
182 * @brief load the FPB state
183 * @param[in] state : the FPB state that needs to be loaded
184 * @retval :  void
185 ****************************************************************************************
186 */
187 void fpb_load_state(fpb_state_t state);
188 
189 /** @} */
190 #endif
191 /** @} */
192 /** @} */
193 
194