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 <stddef.h> 21 #include "mxc_device.h" 22 #include "mxc_errors.h" 23 #include "mxc_assert.h" 24 #include "mxc_sys.h" 25 #include "sfcc.h" 26 #include "sfcc_reva.h" 27 #include "sfcc_reva_regs.h" 28 29 /* **** Definitions **** */ 30 31 /* **** Globals **** */ 32 33 /* **** Functions **** */ MXC_SFCC_Ready(mxc_sfcc_reva_regs_t * sfcc)34static int MXC_SFCC_Ready(mxc_sfcc_reva_regs_t *sfcc) 35 { 36 return (sfcc->ctrl & MXC_F_SFCC_REVA_CTRL_RDY); 37 } 38 MXC_SFCC_RevA_ID(mxc_sfcc_reva_regs_t * sfcc,mxc_sfcc_info_t cid)39int MXC_SFCC_RevA_ID(mxc_sfcc_reva_regs_t *sfcc, mxc_sfcc_info_t cid) 40 { 41 if (sfcc == NULL) { 42 return E_NULL_PTR; 43 } 44 45 switch (cid) { 46 case SFCC_INFO_RELNUM: 47 return ((sfcc->info & MXC_F_SFCC_REVA_INFO_RELNUM) >> MXC_F_SFCC_REVA_INFO_RELNUM_POS); 48 49 case SFCC_INFO_PARTNUM: 50 return ((sfcc->info & MXC_F_SFCC_REVA_INFO_PARTNUM) >> MXC_F_SFCC_REVA_INFO_PARTNUM_POS); 51 52 case SFCC_INFO_ID: 53 return ((sfcc->info & MXC_F_SFCC_REVA_INFO_ID) >> MXC_F_SFCC_REVA_INFO_ID_POS); 54 55 default: 56 return E_BAD_PARAM; 57 } 58 } 59 MXC_SFCC_RevA_Enable(mxc_sfcc_reva_regs_t * sfcc)60void MXC_SFCC_RevA_Enable(mxc_sfcc_reva_regs_t *sfcc) 61 { 62 // Invalidate cache and wait until ready 63 sfcc->ctrl &= ~MXC_F_SFCC_REVA_CTRL_EN; 64 sfcc->invalidate = 1; 65 66 while (!(MXC_SFCC_Ready(sfcc))) {} 67 68 // Enable Cache 69 sfcc->ctrl |= MXC_F_SFCC_REVA_CTRL_EN; 70 while (!(MXC_SFCC_Ready(sfcc))) {} 71 } 72 MXC_SFCC_RevA_Disable(mxc_sfcc_reva_regs_t * sfcc)73void MXC_SFCC_RevA_Disable(mxc_sfcc_reva_regs_t *sfcc) 74 { 75 // Disable Cache 76 sfcc->ctrl &= ~MXC_F_SFCC_REVA_CTRL_EN; 77 } 78