• 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 #pragma once
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 #define FLASH_DEV_NAME                ("flash")
22 
23 #define FLASH_FAILURE                (1)
24 #define FLASH_SUCCESS                (0)
25 
26 #define FLASH_CMD_MAGIC              (0xe240000)
27 enum
28 {
29     CMD_FLASH_SET_CLK = FLASH_CMD_MAGIC + 1,
30     CMD_FLASH_SET_DCO,
31     CMD_FLASH_SET_DPLL,
32 
33     CMD_FLASH_WRITE_ENABLE,
34     CMD_FLASH_WRITE_DISABLE,
35 
36     CMD_FLASH_READ_SR,
37     CMD_FLASH_WRITE_SR,
38 
39     CMD_FLASH_READ_QE,
40     CMD_FLASH_SET_QE,
41 
42     CMD_FLASH_SET_QWFR,
43     CMD_FLASH_CLR_QWFR,
44 
45     CMD_FLASH_SET_WSR,
46     CMD_FLASH_GET_ID,
47     CMD_FLASH_READ_MID,
48     CMD_FLASH_ERASE_SECTOR,
49 	CMD_FLASH_SET_HPM,
50 	CMD_FLASH_GET_PROTECT,
51     CMD_FLASH_SET_PROTECT
52 };
53 
54 typedef enum
55 {
56     FLASH_PROTECT_NONE,
57     FLASH_PROTECT_ALL,
58     FLASH_PROTECT_HALF,
59     FLASH_UNPROTECT_LAST_BLOCK
60 } PROTECT_TYPE;
61 
62 typedef enum
63 {
64     FLASH_XTX_16M_SR_WRITE_DISABLE,
65     FLASH_XTX_16M_SR_WRITE_ENABLE
66 } XTX_FLASH_MODE;
67 
68 typedef struct
69 {
70     UINT8 byte;
71     UINT16 value;
72 } flash_sr_t;
73 
74 /*******************************************************************************
75 * Function Declarations
76 *******************************************************************************/
77 void flash_init(void);
78 void flash_exit(void);
79 UINT8 flash_get_line_mode(void);
80 void flash_set_line_mode(UINT8);
81 UINT32 flash_read(char *user_buf, UINT32 count, UINT32 address);
82 UINT32 flash_write(char *user_buf, UINT32 count, UINT32 address);
83 
84 #ifdef __cplusplus
85 }
86 #endif
87 
88