summaryrefslogtreecommitdiff
path: root/bsp/xuantie/libraries/xuantie_libraries/csi/csi2/include/drv/eflash.h
blob: 8d6c41d0f650b43c3a43c8152222907d8ac3957d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
 /*
 * Copyright (C) 2017-2024 Alibaba Group Holding Limited
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/******************************************************************************
 * @file     eflash.h
 * @brief    header file for eflash driver
 * @version  V1.0
 * @date     02. June 2017
 * @model    eflash
 ******************************************************************************/
#ifndef _DRV_EFLASH_H_
#define _DRV_EFLASH_H_

#include <stdint.h>
#include <drv/common.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
\brief Flash information
*/
typedef struct {
    uint32_t          flash_size;         ///< Chip End address (start+size-1)
    uint32_t          sector_size;        ///< Uniform sector size in bytes
    uint32_t          erased_value;       ///< erased value
} csi_eflash_info_t;

/**
\brief Flash Status
*/
typedef struct {
    uint32_t busy  : 1;                   ///< Flash busy flag
    uint32_t error : 1;                   ///< Read/Program/Erase error flag (cleared on start of next operation)
} eflash_status_t;

/// definition for eflash handle.
typedef struct {
    csi_dev_t           dev;
    void                *arg;
    csi_eflash_info_t   eflashinfo;
    uint16_t            prog;
    uint16_t            erase;
    void                *priv;
} csi_eflash_t;

// Function documentation

/**
  \brief       Initialize EFLASH Interface. 1. Initializes the resources needed for the EFLASH interface 2.registers event callback function
  \param[in]   eflash  eflash handle to operate.
  \param[in]   idx  device id
  \param[in]   arg  User can define it by himself as callback's param
  \return      error code
*/
csi_error_t csi_eflash_init(csi_eflash_t *eflash, int32_t idx, void *arg);

/**
  \brief       De-initialize EFLASH Interface. stops operation and releases the software resources used by the interface
  \param[in]   eflash  eflash handle to operate.
  \return      error code
*/
csi_error_t csi_eflash_uninit(csi_eflash_t *eflash);

/**
  \brief       Read data from Flash.
  \param[in]   eflash  eflash handle to operate.
  \param[in]   offset  Data address.
  \param[out]  data  Pointer to a buffer storing the data read from Flash.
  \param[in]   size   Number of data items to read.
  \return      error code
*/
csi_error_t csi_eflash_read(csi_eflash_t *eflash, uint32_t offset, void *data, uint32_t size);

/**
  \brief       Program data to Flash.
  \param[in]   eflash  eflash handle to operate.
  \param[in]   offset  Data address.
  \param[in]   data  Pointer to a buffer containing the data to be programmed to Flash.
  \param[in]   size   Number of data items to program.
  \return      error code
*/
csi_error_t csi_eflash_program(csi_eflash_t *eflash, uint32_t offset, const void *data, uint32_t size);

/**
  \brief       Erase Flash Sector.
  \param[in]   eflash  eflash handle to operate.
  \param[in]   offset  flash address, flash address need sector size aligned
  \param[in]   size  erase size
  \return      error code
*/
csi_error_t csi_eflash_erase(csi_eflash_t *eflash, uint32_t offset,uint32_t size);

/**
  \brief       Erase whole flash
  \param[in]   eflash  eflash handle to operate.
  \return      error code
*/
csi_error_t csi_eflash_erase_chip(csi_eflash_t *eflash);

/**
  \brief       Get Flash information.
  \param[in]   eflash  eflash handle to operate.
*/
void csi_eflash_dev_info(csi_eflash_t *eflash,csi_eflash_info_t *eflash_info);

/**
  \brief       enable eflash power manage
  \param[in]   eflash  eflash handle to operate.
  \return      error code
*/
csi_error_t csi_eflash_enable_pm(csi_eflash_t *eflash);

/**
  \brief       disable eflash power manage
  \param[in]   eflash  eflash handle to operate.
*/
void csi_eflash_disable_pm(csi_eflash_t *eflash);

#ifdef __cplusplus
}
#endif

#endif /* _DRV_EFLASH_H_ */