]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/T-HEAD_CB2201_CDK/csi/csi_driver/include/drv_flash.h
Introduce a port for T-HEAD CK802. A simple demo for T-HEAD CB2201 is also included.
[freertos] / FreeRTOS / Demo / T-HEAD_CB2201_CDK / csi / csi_driver / include / drv_flash.h
1 /*
2  * Copyright (C) 2017 C-SKY Microsystems Co., Ltd. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 /******************************************************************************
17  * @file     drv_flash.c
18  * @brief    header file for flash driver
19  * @version  V1.0
20  * @date     02. June 2017
21  ******************************************************************************/
22
23 #ifndef _CSI_FLASH_H_
24 #define _CSI_FLASH_H_
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 #include <stdint.h>
31 #include <drv_common.h>
32
33
34 typedef struct  {
35     uint32_t base;
36     void    *priv;
37 } csi_flash_t;
38
39 /**
40 \brief Flash Sector information
41 */
42 typedef struct {
43     uint32_t start;                       ///< Sector Start address
44     uint32_t end;                         ///< Sector End address (start+size-1)
45 } const flash_sector;
46
47 /**
48 \brief Flash information
49 */
50 typedef struct {
51     flash_sector     *sector_info;        ///< Sector layout information (NULL=Uniform sectors)
52     uint32_t          sector_count;       ///< Number of sectors
53     uint32_t          sector_size;        ///< Uniform sector size in bytes (0=sector_info used)
54     uint32_t          page_size;          ///< Optimal programming page size in bytes
55     uint32_t          program_unit;       ///< Smallest programmable unit in bytes
56     uint8_t           erased_value;       ///< Contents of erased memory (usually 0xFF)
57 } flash_info_t;
58
59 /**
60 \brief Flash Status
61 */
62 typedef struct {
63     uint32_t busy  : 1;                   ///< Flash busy flag
64     uint32_t error : 1;                   ///< Read/Program/Erase error flag (cleared on start of next operation)
65 } flash_status_t;
66
67 /****** FLASH Event *****/
68 typedef enum {
69     FLASH_EVENT_READY           = 0,  ///< Flash Ready
70     FLASH_EVENT_ERROR              ,  ///< Read/Program/Erase Error
71 } flash_event_e;
72
73 typedef void (*flash_event_cb_t)(flash_event_e event);   ///< Pointer to \ref flash_event_cb_t : FLASH Event call back.
74
75 /**
76 \brief Flash Driver Capabilities.
77 */
78 typedef struct {
79     uint32_t event_ready  : 1;            ///< Signal Flash Ready event
80     uint32_t data_width   : 2;            ///< Data width: 0=8-bit, 1=16-bit, 2=32-bit
81     uint32_t erase_chip   : 1;            ///< Supports EraseChip operation
82 } flash_capabilities_t;
83
84
85
86
87 /**
88   \brief       get flash instance count.
89   \return      flash instance count
90 */
91 int32_t drv_flash_get_instance_count(void);
92
93 /**
94   \brief       get flash instance .
95   \param[in]   idx   must not exceed return value of drv_flash_get_instance_count()
96   \return      pointer to flash instance
97 */
98 csi_flash_t *drv_flash_get_instance(int32_t idx);
99
100 /**
101   \brief       Get driver capabilities.
102   \param[in]   instance flash instance to operate.
103   \return      \ref flash_capabilities_t
104 */
105 flash_capabilities_t drv_flash_get_capabilities(const csi_flash_t *instance);
106
107 /**
108   \brief       Initialize FLASH Interface. 1. Initializes the resources needed for the FLASH interface 2.registers event callback function
109   \param[in]   instance  flash instance to operate.
110   \param[in]   cb_event  Pointer to \ref flash_event_cb_t
111   \return      error code
112 */
113 int32_t drv_flash_initialize(const csi_flash_t *instance, flash_event_cb_t cb_event);
114
115 /**
116   \brief       De-initialize FLASH Interface. stops operation and releases the software resources used by the interface
117   \param[in]   instance  flash instance to operate.
118   \return      error code
119 */
120 int32_t drv_flash_uninitialize(const csi_flash_t *instance);
121
122 /**
123   \brief       Get Flash information.
124   \param[in]   instance  flash instance to operate.
125   \return      Pointer to Flash information \ref flash_info_t
126 */
127 flash_info_t *drv_flash_get_info(const csi_flash_t *instance);
128
129 /**
130   \brief       Read data from Flash.
131   \param[in]   instance  flash instance to operate.
132   \param[in]   addr  Data address.
133   \param[in]   data  Pointer to a buffer storing the data read from Flash.
134   \param[in]   cnt   Number of data items to read.
135   \return      number of data items read or error code
136 */
137 int32_t drv_flash_read(const csi_flash_t *instance, uint32_t addr, void *data, uint32_t cnt);
138
139 /**
140   \brief       Program data to Flash.
141   \param[in]   instance  flash instance to operate.
142   \param[in]   addr  Data address.
143   \param[in]   data  Pointer to a buffer containing the data to be programmed to Flash..
144   \param[in]   cnt   Number of data items to program.
145   \return      number of data items programmed or error code
146 */
147 int32_t drv_flash_program(const csi_flash_t *instance, uint32_t addr, const void *data, uint32_t cnt);
148
149 /**
150   \brief       Erase Flash Sector.
151   \param[in]   instance  flash instance to operate.
152   \param[in]   addr  Sector address
153   \return      error code
154 */
155 int32_t drv_flash_erase_sector(const csi_flash_t *instance, uint32_t addr);
156
157 /**
158   \brief       Erase complete Flash.
159   \param[in]   instance  flash instance to operate.
160   \return      error code
161 */
162 int32_t drv_flash_erase_chip(const csi_flash_t *instance);
163
164 /**
165   \brief       Get FLASH status.
166   \param[in]   instance  flash instance to operate.
167   \return      FLASH status \ref flash_status_t
168 */
169 flash_status_t drv_flash_get_status(const csi_flash_t *instance);
170
171 #ifdef __cplusplus
172 }
173 #endif
174
175 #endif /* _CSI_FLASH_H_ */