79 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			79 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
/****************************************************************************
 | 
						|
 | 
						|
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
 | 
						|
 | 
						|
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
 | 
						|
be copied by any method or incorporated into another program without
 | 
						|
the express written consent of Aerospace C.Power. This Information or any portion
 | 
						|
thereof remains the property of Aerospace C.Power. The Information contained herein
 | 
						|
is believed to be accurate and Aerospace C.Power assumes no responsibility or
 | 
						|
liability for its use in any way and conveys no license or title under
 | 
						|
any patent or copyright and makes no representation or warranty that this
 | 
						|
Information is free from patent or copyright infringement.
 | 
						|
 | 
						|
****************************************************************************/
 | 
						|
#include "os_types_api.h"
 | 
						|
#include "os_utils_api.h"
 | 
						|
#include "iot_io_api.h"
 | 
						|
#include "iot_flash_api.h"
 | 
						|
#include "iot_app_cus_flash.h"
 | 
						|
 | 
						|
uint16_t cus_app_flash_read(uint32_t offset, uint8_t * buffer, uint32_t size)
 | 
						|
{
 | 
						|
    int32_t fd;
 | 
						|
    uint8_t ret = 0;
 | 
						|
 | 
						|
    if (-1 == (fd = custom_dev_open())) {
 | 
						|
        ret = 1;
 | 
						|
        goto out;
 | 
						|
    }
 | 
						|
 | 
						|
    if (-1 == custom_dev_seek(fd, offset, DEV_SEEK_SET)) {
 | 
						|
        ret = 2;
 | 
						|
        goto err;
 | 
						|
    }
 | 
						|
 | 
						|
    if (-1 == custom_dev_read(fd, (void *)buffer, size)) {
 | 
						|
        ret = 3;
 | 
						|
        goto err;
 | 
						|
    }
 | 
						|
 | 
						|
err:
 | 
						|
    custom_dev_close(fd);
 | 
						|
out:
 | 
						|
    if (ret) {
 | 
						|
        iot_cus_printf("[ERR]read flash %lu Failed\n", ret);
 | 
						|
    }
 | 
						|
    return ret;
 | 
						|
}
 | 
						|
 | 
						|
uint16_t cus_app_flash_write(uint32_t offset, uint8_t * buffer, uint32_t size)
 | 
						|
{
 | 
						|
    int32_t fd;
 | 
						|
    uint8_t ret = 0;
 | 
						|
 | 
						|
    if (-1 == (fd = custom_dev_open())) {
 | 
						|
        ret = 1;
 | 
						|
        goto out;
 | 
						|
    }
 | 
						|
 | 
						|
    if (-1 == custom_dev_seek(fd, offset, DEV_SEEK_SET)) {
 | 
						|
        ret = 2;
 | 
						|
        goto err;
 | 
						|
    }
 | 
						|
 | 
						|
    if (-1 == custom_dev_write(fd, (void *)buffer, size)) {
 | 
						|
        ret = 3;
 | 
						|
        goto err;
 | 
						|
    }
 | 
						|
 | 
						|
err:
 | 
						|
    custom_dev_close(fd);
 | 
						|
out:
 | 
						|
    if (ret) {
 | 
						|
         iot_cus_printf("[ERR]write flash %lu Failed\n", ret);
 | 
						|
    }
 | 
						|
    return ret;
 | 
						|
}
 | 
						|
 |