#ifndef __FAL_H__
#define __FAL_H__

#include "sr_stddef.h"
#include "sr_list.h"
#include <stdlib.h>


#ifndef FAL_DEV_NAME_MAX
#define FAL_DEV_NAME_MAX 16
#endif

typedef struct fal_flash fal_flash_t;

struct fal_flash_ops
{
    int (*read)(fal_flash_t *flash, uint32_t offset, uint8_t *buf, uint32_t size);
    int (*write)(fal_flash_t *flash, uint32_t offset, uint8_t *buf, uint32_t size);
    int (*erase_block)(fal_flash_t *flash, uint32_t offset, uint32_t num);
};

struct fal_flash
{
    //char name[FAL_DEV_NAME_MAX];
  	char *name;

    /* flash device start address and len  */
    uint32_t addr;   //物理基地址
    size_t len;
    /* the block size in the flash for erase minimum granularity */
    size_t blk_size;

    //uint32_t page_size;  /* flash memory page (without spare area) size measured in bytes */
    //uint32_t block_size; /* flash memory block size measured in number of pages */
    //uint32_t capacity;   /* flash capacity measured in bytes */

    struct fal_flash_ops ops;

    os_list_node_t list;

    //void *priv;
};

struct onchip_flash_info
{
    uint32_t start_addr;
    uint32_t capacity;
    uint32_t block_size;
    uint32_t page_size;
};

int              fal_flash_register(fal_flash_t *flash);
fal_flash_t     *fal_flash_find(const char *name);
//os_mtd_device_t *fal_mtd_device_create(const char *parition_name);
//os_blk_device_t *fal_blk_device_create(const char *parition_name);

//#define fal_block_shift(flash_dev) (os_ffs(flash_dev->block_size) - 1)
//#define fal_page_shift(flash_dev)  (os_ffs(flash_dev->page_size) - 1)

//#include <fal/fal_part.h>

#endif /* __FAL_H__ */
