• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2022 Beken Corporation
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13 
14 #include "iot_errno.h"
15 #include "iot_flash.h"
16 #include "flash.h"
17 
18 //#include "bk_flash.h"
19 
20 static flash_protect_type_t  protect_flag;
IoTFlashRead(unsigned int flashOffset,unsigned int size,unsigned char * ramData)21 unsigned int IoTFlashRead(unsigned int flashOffset, unsigned int size, unsigned char *ramData)
22 {
23 	bk_flash_read_bytes(flashOffset,ramData,size);
24 	return IOT_SUCCESS;
25 }
26 
IoTFlashWrite(unsigned int flashOffset,unsigned int size,const unsigned char * ramData,unsigned char doErase)27 unsigned int IoTFlashWrite(unsigned int flashOffset, unsigned int size,
28                            const unsigned char *ramData, unsigned char doErase)
29 {
30 	bk_flash_write_bytes(flashOffset,ramData,size);
31 	return IOT_SUCCESS;
32 }
33 
IoTFlashErase(unsigned int flashOffset,unsigned int size)34 unsigned int IoTFlashErase(unsigned int flashOffset, unsigned int size)
35 {
36 	UINT32 i;
37 	UINT32 start_sector, end_sector, param;
38 	GLOBAL_INT_DECLARATION();
39 
40 	start_sector = flashOffset >> 12;
41 	end_sector = (flashOffset + size - 1) >> 12;
42 
43 	GLOBAL_INT_DISABLE();
44 	for (i = start_sector; i <= end_sector; i ++) {
45 		param = i << 12;
46 		bk_flash_erase_sector(param);
47 	}
48 	GLOBAL_INT_RESTORE();
49 
50 	return IOT_SUCCESS;
51 }
52 
IoTFlashInit(void)53 unsigned int IoTFlashInit(void)
54 {
55 	protect_flag = bk_flash_get_protect_type();
56 	return IOT_SUCCESS;
57 	bk_flash_set_protect_type(FLASH_PROTECT_NONE);
58 }
59 
IoTFlashDeinit(void)60 unsigned int IoTFlashDeinit(void)
61 {
62 	bk_flash_set_protect_type(protect_flag);
63 	return IOT_SUCCESS;
64 }
65