1 /** 2 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 * 15 * Description: Provides sfc port template \n 16 * 17 * History: \n 18 * 2022-11-30, Create file. \n 19 */ 20 #ifndef SFC_PROTECT_H 21 #define SFC_PROTECT_H 22 23 #ifdef __cplusplus 24 #if __cplusplus 25 extern "C" { 26 #endif 27 #endif 28 29 30 #define SPI_CMD_RDSR_1 0x05 31 #define SPI_CMD_RDSR_2 0x35 32 #define SPI_CMD_RDSR_3 0x15 33 34 /** 35 * @brief 读取状态寄存器的值。 36 * @param [in] cmd 命令字可以是:05H/35H/15H。 37 * 05H: 读 SR1 38 * 35H: 读 SR2 39 * 15H: 读 SR3 40 * @retval 读取到的SR中的值。 41 * @endif 42 */ 43 uint32_t sfc_port_read_sr(uint32_t cmd); 44 45 #define SPI_CMD_WRSR_1 0x01 46 #define SPI_CMD_WRSR_2 0x31 47 #define SPI_CMD_WRSR_3 0x11 48 49 /** 50 * @brief 写状态寄存器。 51 * @param [in] is_volatile 是否是易失性写入。 52 * True: 易失性写入, 掉电后配置丢失。 53 * False: 非易失性写入, 掉电后配置不丢失。 54 * @param [in] cmd 命令字可以是:01H/31H/11H。 55 * 01H: 写 SR1 56 * 31H: 写 SR2 57 * 11H: 写 SR3 58 * @param [in] data 待写入的SR寄存器的数据。 59 * @endif 60 */ 61 void sfc_port_write_sr(bool is_volatile, uint8_t cmd, uint8_t data); 62 63 /** 64 * @brief 修复状态寄存器。 65 * @retval ERRCODE_SUCC 成功。 66 * @retval Other 失败,参考 @ref errcode_t 。 67 * @endif 68 */ 69 errcode_t sfc_port_fix_sr(void); 70 71 /** 72 * @if Eng 73 * @brief sfc lock with addr. 74 * @retval lock status. 75 * @else 76 * @brief SFC上锁,同时根据地址信息,放开对应区域的擦、写权限。 77 * @retval 锁状态。 78 * @endif 79 */ 80 uint32_t sfc_port_write_lock(uint32_t start_addr, uint32_t end_addr); 81 82 /** 83 * @if Eng 84 * @brief sfc unlock. 85 * @param [in] lock_sts lock status. 86 * @else 87 * @brief SFC解锁。 88 * @param [in] lock_sts 锁状态,传入的为由sfc_port_write_lock接口返回的值 89 * @endif 90 */ 91 void sfc_port_write_unlock(uint32_t lock_sts); 92 93 #ifdef __cplusplus 94 #if __cplusplus 95 } 96 #endif /* __cplusplus */ 97 #endif /* __cplusplus */ 98 #endif 99