FreeRTOS: Common I/O
AWS IoT Common I/O library
Return to main page ↑
iot_flash.h
Go to the documentation of this file.
1 /*
2  * FreeRTOS Common IO V1.0.0
3  * Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of
6  * this software and associated documentation files (the "Software"), to deal in
7  * the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9  * the Software, and to permit persons to whom the Software is furnished to do so,
10  * subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * http://aws.amazon.com/freertos
23  * http://www.FreeRTOS.org
24  */
25 
31 #ifndef _IOT_FLASH_H_
32 #define _IOT_FLASH_H_
33 
42 #define IOT_FLASH_SUCCESS ( 0 )
43 #define IOT_FLASH_INVALID_VALUE ( 1 )
44 #define IOT_FLASH_WRITE_FAILED ( 2 )
45 #define IOT_FLASH_READ_FAILED ( 3 )
46 #define IOT_FLASH_ERASE_FAILED ( 4 )
47 #define IOT_FLASH_DEVICE_BUSY ( 5 )
48 #define IOT_FLASH_CTRL_OP_FAILED ( 6 )
49 #define IOT_FLASH_FUNCTION_NOT_SUPPORTED ( 7 )
54 typedef enum
55 {
60  eFlashEraseSuspended /*<! Flash erase operation suspended. */
62 
66 typedef enum
67 {
73 
77 typedef enum
78 {
82 
86 typedef struct IotFlashInfo
87 {
88  uint32_t ulFlashSize;
89  uint32_t ulBlockSize;
90  uint32_t ulSectorSize;
91  uint32_t ulPageSize;
92  uint32_t ulLockSupportSize;
95  uint8_t ucAsyncSupported;
98 
102 typedef struct IotFlashWriteProtectConfig
103 {
104  uint32_t ulAddress;
105  uint32_t ulSize;
108 
112 typedef enum IotFlashIoctlRequest
113 {
126 
130 struct IotFlashDescriptor;
131 
137 typedef struct IotFlashDescriptor * IotFlashHandle_t;
138 
151 typedef void ( * IotFlashCallback_t)( IotFlashOperationStatus_t xStatus, void * pvUserContext );
152 
168 IotFlashHandle_t iot_flash_open( int32_t lFlashInstance );
169 
181 IotFlashInfo_t * iot_flash_getinfo( IotFlashHandle_t const pxFlashHandle );
182 
206 void iot_flash_set_callback( IotFlashHandle_t const pxFlashHandle,
207  IotFlashCallback_t xCallback,
208  void * pvUserContext );
209 
228 int32_t iot_flash_ioctl( IotFlashHandle_t const pxFlashHandle,
229  IotFlashIoctlRequest_t xRequest,
230  void * const pvBuffer );
231 
293 int32_t iot_flash_erase_sectors( IotFlashHandle_t const pxFlashHandle,
294  uint32_t ulStartAddress,
295  size_t xSize );
296 
310 int32_t iot_flash_erase_chip( IotFlashHandle_t const pxFlashHandle );
311 
333 int32_t iot_flash_write_sync( IotFlashHandle_t const pxFlashHandle,
334  uint32_t ulAddress,
335  uint8_t * const pvBuffer,
336  size_t xBytes );
337 
355 int32_t iot_flash_read_sync( IotFlashHandle_t const pxFlashHandle,
356  uint32_t ulAddress,
357  uint8_t * const pvBuffer,
358  size_t xBytes );
359 
384 int32_t iot_flash_write_async( IotFlashHandle_t const pxFlashHandle,
385  uint32_t ulAddress,
386  uint8_t * const pvBuffer,
387  size_t xBytes );
388 
412 int32_t iot_flash_read_async( IotFlashHandle_t const pxFlashHandle,
413  uint32_t ulAddress,
414  uint8_t * const pvBuffer,
415  size_t xBytes );
416 
429 int32_t iot_flash_close( IotFlashHandle_t const pxFlashHandle );
430 
435 #endif /* ifndef _IOT_FLASH_H_ */
Definition: iot_flash.h:79
uint32_t ulLockSupportSize
Definition: iot_flash.h:92
uint32_t ulBlockSize
Definition: iot_flash.h:89
Definition: iot_flash.h:59
Definition: iot_flash.h:120
Definition: iot_flash.h:80
uint32_t ulPageSize
Definition: iot_flash.h:91
uint32_t ulSectorSize
Definition: iot_flash.h:90
IotFlashHandle_t iot_flash_open(int32_t lFlashInstance)
iot_flash_open is used to initialize the flash device. This must be called before using any other fla...
IotFlashStatus_t
Flash current status.
Definition: iot_flash.h:54
IotFlashInfo_t * iot_flash_getinfo(IotFlashHandle_t const pxFlashHandle)
iot_flash_getinfo is used to get the information about the physical flash device. ...
IotFlashWriteProtect_t
Flash sector protection type.
Definition: iot_flash.h:77
Definition: iot_flash.h:70
IotFlashOperationStatus_t
Flash driver last operation status.
Definition: iot_flash.h:66
Definition: iot_flash.h:123
int32_t iot_flash_write_async(IotFlashHandle_t const pxFlashHandle, uint32_t ulAddress, uint8_t *const pvBuffer, size_t xBytes)
iot_flash_write_async is used to write data to flash starting at the address provided. The sector(s) being written to, must be erased first before any write can take place. This is an asynchronous (non-blocking) operation and returns as soon as the write operation is started. When the write is completed, user callback is called to notify that the write is complete. The caller can check the status of the operation by using eGetStatus IOCTL. User must register for a callback when using the non-blocking operations to know when they are complete. If there is another flash operation is in progress, write will return an error.
Definition: iot_flash.h:56
Definition: iot_flash.h:115
uint8_t ucAsyncSupported
Definition: iot_flash.h:95
void iot_flash_set_callback(IotFlashHandle_t const pxFlashHandle, IotFlashCallback_t xCallback, void *pvUserContext)
iot_flash_set_callback is used to set the callback to be called upon completion of erase/program/read...
Definition: iot_flash.h:69
int32_t iot_flash_write_sync(IotFlashHandle_t const pxFlashHandle, uint32_t ulAddress, uint8_t *const pvBuffer, size_t xBytes)
iot_flash_write_sync is used to write data to flash starting at the address provided. The sector(s) being written to, must be erased first before any write can take place. This is a blocking operation and waits until the number of bytes are written before returning. If there is another flash operation is in progress, write will return an error.
Definition: iot_flash.h:71
flash information
Definition: iot_flash.h:86
uint32_t ulFlashSize
Definition: iot_flash.h:88
int32_t iot_flash_close(IotFlashHandle_t const pxFlashHandle)
iot_flash_close is used to close the flash device. If any operations are in progress when close is ca...
int32_t iot_flash_ioctl(IotFlashHandle_t const pxFlashHandle, IotFlashIoctlRequest_t xRequest, void *const pvBuffer)
iot_flash_ioctl is used to configure the flash parameters and setup certain flash operations and also...
IotFlashIoctlRequest_t
Ioctl request types.
Definition: iot_flash.h:112
#define IOT_FLASH_ERASE_FAILED
Definition: iot_flash.h:46
#define IOT_FLASH_SUCCESS
Return values used by this driver.
Definition: iot_flash.h:42
int32_t iot_flash_erase_sectors(IotFlashHandle_t const pxFlashHandle, uint32_t ulStartAddress, size_t xSize)
iot_flash_erase_sectors is used to erase data in flash from the start of the address specified until ...
uint32_t ulSize
Definition: iot_flash.h:105
struct IotFlashDescriptor * IotFlashHandle_t
IotFlashHandle_t type is the flash handle returned by calling iot_flash_open() this is initialized in...
Definition: iot_flash.h:137
#define IOT_FLASH_READ_FAILED
Definition: iot_flash.h:45
#define IOT_FLASH_WRITE_FAILED
Definition: iot_flash.h:44
int32_t iot_flash_erase_chip(IotFlashHandle_t const pxFlashHandle)
iot_erase_chip is used to erase the entire flash chip. If there is another flash operation is in prog...
Definition: iot_flash.h:57
Definition: iot_flash.h:124
Definition: iot_flash.h:58
Definition: iot_flash.h:117
int32_t iot_flash_read_sync(IotFlashHandle_t const pxFlashHandle, uint32_t ulAddress, uint8_t *const pvBuffer, size_t xBytes)
iot_flash_read_sync is used to read data from flash. This is a blocking operation and waits until the...
Flash protection configuration.
Definition: iot_flash.h:102
uint32_t ulAddress
Definition: iot_flash.h:104
void(* IotFlashCallback_t)(IotFlashOperationStatus_t xStatus, void *pvUserContext)
Flash notification callback type. This callback can be passed to the driver by using iot_flash_set_ca...
Definition: iot_flash.h:151
IotFlashWriteProtect_t xProtectionLevel
Definition: iot_flash.h:106
Definition: iot_flash.h:122
Definition: iot_flash.h:114
Definition: iot_flash.h:68
int32_t iot_flash_read_async(IotFlashHandle_t const pxFlashHandle, uint32_t ulAddress, uint8_t *const pvBuffer, size_t xBytes)
iot_flash_read_async is used to read data from flash. This is an asynchronous (non-blocking) operatio...