1 /******************************************************************************
2  *
3  * Copyright (C) 2024 Analog Devices, Inc.
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 
19 /* **** Includes **** */
20 #include "mxc_device.h"
21 #include "mxc_errors.h"
22 #include "mxc_assert.h"
23 #include "mxc_sys.h"
24 #include "sfcc.h"
25 #include "sfcc_reva.h"
26 
MXC_SFCC_ID(mxc_sfcc_info_t cid)27 int MXC_SFCC_ID(mxc_sfcc_info_t cid)
28 {
29     return MXC_SFCC_RevA_ID((mxc_sfcc_reva_regs_t *)MXC_SFCC, cid);
30 }
31 
MXC_SFCC_Enable(void)32 void MXC_SFCC_Enable(void)
33 {
34     MXC_SFCC_RevA_Enable((mxc_sfcc_reva_regs_t *)MXC_SFCC);
35 }
36 
MXC_SFCC_Disable(void)37 void MXC_SFCC_Disable(void)
38 {
39     MXC_SFCC_RevA_Disable((mxc_sfcc_reva_regs_t *)MXC_SFCC);
40 }
41 
MXC_SFCC_Flush(void)42 void MXC_SFCC_Flush(void)
43 {
44     /* NOTE: MEMPROT authentication bytes are not flushed with the SFCC invalidate bits,
45      * the GCR SFCC flush is required.
46      */
47     /* Flush all instruction caches */
48     MXC_GCR->sysctrl |= MXC_F_GCR_SYSCTRL_SFCC_FLUSH;
49 
50     /* Wait for flush to complete */
51     while (MXC_GCR->sysctrl & MXC_F_GCR_SYSCTRL_SFCC_FLUSH) {}
52 
53     MXC_SFCC_Disable();
54     MXC_SFCC_Enable();
55 }
56