• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2022 Beken Corporation
2 //
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 #include "flash_hal.h"
16 #include "flash_ll.h"
17 #include <driver/hal/hal_flash_types.h>
18 
flash_hal_init(flash_hal_t * hal)19 bk_err_t flash_hal_init(flash_hal_t *hal)
20 {
21 	hal->hw = (flash_hw_t *)FLASH_LL_REG_BASE(hal->id);
22 	flash_ll_init(hal->hw);
23 	return BK_OK;
24 }
25 
flash_hal_get_protect_value(flash_hal_t * hal,uint8_t status_reg_size,uint8_t protect_post,uint8_t protect_mask,uint8_t cmp_post)26 uint16_t flash_hal_get_protect_value(flash_hal_t *hal, uint8_t status_reg_size, uint8_t protect_post, uint8_t protect_mask, uint8_t cmp_post)
27 {
28 	uint16_t sr_value = flash_ll_read_status_reg(hal->hw, status_reg_size);
29 	uint16_t param = (sr_value >> protect_post) & protect_mask;
30 	uint16_t cmp = (sr_value >> cmp_post) & 0x01;
31 	uint16_t protect_value = (cmp << 8) | param;
32 
33 	return protect_value;
34 }
35 
36 
37