summaryrefslogtreecommitdiff
path: root/components/fal/inc/fal_def.h
blob: a2a4d07702eda5477fb42f3395aa7526b99cc230 (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
/*
 * Copyright (c) 2006-2018, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2018-05-17     armink       the first version
 */

#ifndef _FAL_DEF_H_
#define _FAL_DEF_H_

#include <rtthread.h>

/* FAL flash and partition device name max length */
#ifndef FAL_DEV_NAME_MAX
#define FAL_DEV_NAME_MAX 24
#endif

#ifndef FAL_DEV_BLK_MAX
#define FAL_DEV_BLK_MAX 6
#endif

struct flash_blk
{
    rt_size_t size;
    rt_size_t count;
};

struct fal_flash_dev
{
    char name[FAL_DEV_NAME_MAX];

    /* flash device start address and len  */
    rt_uint32_t addr;
    rt_size_t len;
    /* the block size in the flash for erase minimum granularity */
    rt_size_t blk_size;

    struct
    {
        int (*init)(void);
        int (*read)(long offset, rt_uint8_t *buf, rt_size_t size);
        int (*write)(long offset, const rt_uint8_t *buf, rt_size_t size);
        int (*erase)(long offset, rt_size_t size);
    } ops;

    /* write minimum granularity, unit: bit.
       1(nor flash)/ 8(stm32f2/f4)/ 32(stm32f1)/ 64(stm32l4)
       0 will not take effect. */
    rt_size_t write_gran;
    struct flash_blk blocks[FAL_DEV_BLK_MAX];
};
typedef struct fal_flash_dev *fal_flash_dev_t;

/**
 * FAL partition
 */
struct fal_partition
{
    rt_uint32_t magic_word;

    /* partition name */
    char name[FAL_DEV_NAME_MAX];
    /* flash device name for partition */
    char flash_name[FAL_DEV_NAME_MAX];

    /* partition offset address on flash device */
    long offset;
    rt_size_t len;

    rt_uint32_t reserved;
};
typedef struct fal_partition *fal_partition_t;

#endif /* _FAL_DEF_H_ */