You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/09/01 02:11:04 UTC

[GitHub] [incubator-nuttx] XinStellaris commented on a diff in pull request #6829: drivers/mtd:init commit of power-loss resilient cfg

XinStellaris commented on code in PR #6829:
URL: https://github.com/apache/incubator-nuttx/pull/6829#discussion_r960159046


##########
drivers/mtd/mtd_config_fs.c:
##########
@@ -0,0 +1,2484 @@
+/****************************************************************************
+ * drivers/mtd/mtd_config_fs.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ * NVS: non volatile storage in flash
+ *
+ * Copyright (c) 2018 Laczen
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <sys/types.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <string.h>
+#include <debug.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <sys/poll.h>
+#include <nuttx/crc8.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/mtd/mtd.h>
+#include <nuttx/mtd/configdata.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define MIN(a, b)                       ((a) > (b) ? (b) : (a))
+
+/* MASKS AND SHIFT FOR ADDRESSES
+ * an address in nvs is an uint32_t where:
+ *   high 2 bytes represent the sector number
+ *   low 2 bytes represent the offset in a sector
+ */
+
+#define ADDR_SECT_MASK                  0xFFFF0000
+#define ADDR_SECT_SHIFT                 16
+#define ADDR_OFFS_MASK                  0x0000FFFF
+
+/* we don't want to store all the read content in stack or heap,
+ * so we make a buffer to do compare or move.
+ */
+
+#define NVS_BUFFER_SIZE                 32
+
+/* if data is written after last ate, and power loss happens,
+ * we need to find a clean offset by skipping dirty data.
+ * This macro defines how many bytes to skip when dirty data
+ * is spotted(may take several skips).
+ * Normally 1 byte is okay, such process only happens when
+ * nvs is started, and it is acceptable to take some time during
+ * starting.
+ */
+
+#define NVS_CORRUPT_DATA_SKIP_STEP      1
+
+#define NVS_LOOKUP_CACHE_NO_ADDR        0xffffffff
+
+/* gc done or close ate has the id of 0xffffffff.
+ * We can tell if the ate is special by looking at its id.
+ */
+
+#define NVS_SPECIAL_ATE_ID              0xffffffff

Review Comment:
   the special value doesn't need to be the same as erase value. Here it is defined as 0xffffffff for simplicity.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org