Blame view

RIOT/sys/include/fs/spiffs_fs.h 3.11 KB
a752c7ab   elopes   add first test an...
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
  /*
   * Copyright (C) 2016 OTA keys S.A.
   *
   * This file is subject to the terms and conditions of the GNU Lesser
   * General Public License v2.1. See the file LICENSE in the top level
   * directory for more details.
   */
  
  /**
   * @defgroup    sys_spiffs  SPIFFS integration
   * @ingroup     pkg_spiffs
   * @brief       RIOT integration of SPIFFS
   *
   * The RIOT integration of SPIFFS follows the SPIFFS wiki:
   * https://github.com/pellepl/spiffs/wiki/Integrate-spiffs#integrating-spiffs
   *
   * @{
   *
   * @file
   * @brief       SPIFFS integration with vfs
   *
   * @author      Vincent Dupont <vincent@otakeys.com>
   */
  
  #ifndef FS_SPIFFS_FS_H
  #define FS_SPIFFS_FS_H
  
  #ifdef __cplusplus
  extern "C" {
  #endif
  
  #include "spiffs.h"
  #include "spiffs_config.h"
  #include "vfs.h"
  #include "mtd.h"
  #include "mutex.h"
  
  /** Size of the buffer needed for directory */
  #define SPIFFS_DIR_SIZE (12)
  
  #if (VFS_DIR_BUFFER_SIZE < SPIFFS_DIR_SIZE)
  #error "VFS_DIR_BUFFER_SIZE too small"
  #endif
  
  /**
   * @name SPIFFS config constants
   * @{
   */
  #ifndef SPIFFS_FS_CACHE_SIZE
  #if SPIFFS_CACHE || defined(DOXYGEN)
  /**
   * @brief the size of the cache buffer
   *
   * Ignored if cache is disabled in build config. One cache page will be slightly
   * larger than the logical page size. The more ram, the more cache pages,
   * the quicker the system.
   */
  #define SPIFFS_FS_CACHE_SIZE (512)
  #else
  #define SPIFFS_FS_CACHE_SIZE (0)
  #endif /* SPIFFS_CACHE */
  #endif /* SPIFFS_FS_CACHE_SIZE */
  #ifndef SPIFFS_FS_WORK_SIZE
  /**
   * @brief The size of the work buffer
   *
   * A ram memory buffer being double the size of the logical page size
   * This buffer is used extensively by the spiffs stack.
   * If logical page size is 256, this buffer must be 512 bytes.
   */
  #define SPIFFS_FS_WORK_SIZE  (512)
  #endif
  #ifndef SPIFFS_FS_FD_SPACE_SIZE
  /**
   * @brief the size of the file descriptor buffer
   *
   * A file descriptor normally is around 32 bytes depending on the build config -
   * the bigger the buffer, the more file descriptors are available.
   */
  #define SPIFFS_FS_FD_SPACE_SIZE (4 * 32)
  #endif
  /** @} */
  
  /**
   * This contains everything needed to run an instance of SPIFFS
   */
  typedef struct spiffs_desc {
      spiffs fs;                                  /**< The SPIFFS struct */
      uint8_t work[SPIFFS_FS_WORK_SIZE];          /**< SPIFFS work buffer */
      uint8_t fd_space[SPIFFS_FS_FD_SPACE_SIZE];  /**< SPIFFS file descriptor cache */
  #if (SPIFFS_CACHE == 1) || defined(DOXYGEN)
      uint8_t cache[SPIFFS_FS_CACHE_SIZE];        /**< SPIFFS cache */
  #endif
      spiffs_config config;                       /**< SPIFFS config, filled at mount time depending
                                                   *  on the underlying mtdi_dev_t @p dev */
      mutex_t lock;                               /**< A lock for SPIFFS internal use */
  #if (SPIFFS_HAL_CALLBACK_EXTRA == 1) || defined(DOXYGEN)
      mtd_dev_t *dev;                             /**< The underlying mtd device, must be set by user */
  #endif
  } spiffs_desc_t;
  
  /** The SPIFFS vfs driver, a pointer to a spiffs_desc_t must be provided as vfs_mountp::private_data */
  extern const vfs_file_system_t spiffs_file_system;
  
  #ifdef __cplusplus
  }
  #endif
  
  #endif /* FS_SPIFFS_FS_H */
  
  /** @} */