You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "xiaoxiang781216 (via GitHub)" <gi...@apache.org> on 2024/03/01 01:16:00 UTC

Re: [PR] testing/nand_sim: Adds a virtual NAND Flash device [nuttx-apps]

xiaoxiang781216 commented on code in PR #2319:
URL: https://github.com/apache/nuttx-apps/pull/2319#discussion_r1508366914


##########
.gitignore:
##########
@@ -39,3 +39,6 @@ Make.dep
 .dirlinks
 .vscode
 .DS_Store
+build
+.ccls-cache
+compile_commands.json

Review Comment:
   why need add these file?



##########
system/vi/vi.c:
##########
@@ -4501,6 +4504,9 @@ static void vi_parsecolon(FAR struct vi_s *vi)
     {
       /* Yes... free resources and exit */
 
+      term.c_lflag |= ECHO;

Review Comment:
   let's move vi related change to new patch.



##########
system/vi/vi.c:
##########
@@ -1303,7 +1306,7 @@ static bool vi_savetext(FAR struct vi_s *vi, FAR const char *filename,
 
   fclose(stream);
 
-  len = snprintf(vi->scratch, sizeof(vi->scratch), "%dC written", nwritten);
+  len = snprintf(vi->scratch, sizeof(vi->scratch), "%ldC written", nwritten);

Review Comment:
   ```suggestion
     len = snprintf(vi->scratch, sizeof(vi->scratch), "%zC written", nwritten);
   ```



##########
system/vi/vi.c:
##########
@@ -475,6 +476,8 @@ static void     vi_appendrepeat(FAR struct vi_s *vi, uint16_t ch);
  * Private Data
  ****************************************************************************/
 
+struct termios term;

Review Comment:
   ```suggestion
   static struct termios g_termios;
   ```



##########
testing/nand_sim/nand_sim_wrapper.c:
##########
@@ -0,0 +1,303 @@
+/****************************************************************************
+ * apps/testing/nand_sim/nand_sim_wrapper.c

Review Comment:
   need move to nuttx/drivers/mtd, since it's a general log wrapper, not couple with nand_sim_raw directly, it's better to remove sim_ from the whole source file.



##########
testing/nand_sim/nand_sim_raw.c:
##########
@@ -0,0 +1,250 @@
+/****************************************************************************
+ * apps/testing/nand_sim/nand_sim_raw.c

Review Comment:
   nand_sim_raw is a nand raw lowhalf driver, so it should be moved to.nuttx/drivers/mtd



##########
testing/nand_sim/nand_sim.h:
##########
@@ -0,0 +1,177 @@
+/****************************************************************************
+ * apps/testing/nand_sim/nand_sim.h
+ *
+ * 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.
+ *
+ ****************************************************************************/
+#ifndef __TESTING_NAND_SIM_NAND_SIM_H
+#define __TESTING_NAND_SIM_NAND_SIM_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <debug.h>
+#include <stdio.h>
+
+#include <nuttx/drivers/drivers.h>
+#include <nuttx/mtd/nand.h>
+#include <nuttx/mtd/nand_scheme.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define NAND_SIM_DEBUG_NONE           0
+#define NAND_SIM_DEBUG_STDOUT         1
+#define NAND_SIM_DEBUG_FILE           2
+
+#define NAND_SIM_DEBUG                CONFIG_TESTING_NAND_SIM_DEBUG
+
+#define NAND_SIM_B(x)                 (x)
+#define NAND_SIM_KB(x)                (NAND_SIM_B(x) << 10)
+#define NAND_SIM_MB(x)                (NAND_SIM_KB(x) << 10)
+
+#define NAND_SIM_NAME                 "nand"
+#define NAND_SIM_PATH                 "/dev/" NAND_SIM_NAME
+
+#define NAND_SIM_SIZE                 NAND_SIM_MB(CONFIG_TESTING_NAND_SIM_SIZE)
+
+#define NAND_SIM_LOG_PAGES_PER_BLOCK  ((uint32_t) 7)
+#define NAND_SIM_PAGE_SIZE            ((uint32_t) (1 << 9)) /* 512 B */
+#define NAND_SIM_SPARE_SIZE           ((uint32_t) (1 << 4)) /* 16 B */
+#define NAND_SIM_N_PAGES              ((uint32_t) NAND_SIM_SIZE / NAND_SIM_PAGE_SIZE)
+#define NAND_SIM_TOTAL_PAGE_SIZE      ((uint32_t) (NAND_SIM_PAGE_SIZE + NAND_SIM_SPARE_SIZE))
+#define NAND_SIM_PAGES_PER_BLOCK      ((uint32_t) (NAND_SIM_BLOCK_SIZE / NAND_SIM_PAGE_SIZE))
+
+#define NAND_SIM_N_BLOCKS             ((uint32_t) (NAND_SIM_N_PAGES / NAND_SIM_PAGES_PER_BLOCK))
+#define NAND_SIM_BLOCK_SIZE           ((uint32_t) ((1 << NAND_SIM_LOG_PAGES_PER_BLOCK) * NAND_SIM_PAGE_SIZE))
+
+#define NAND_SIM_WRITE_STATUS_SIG     10
+#define NAND_SIM_WRITE_LOG_SIG        12
+
+#if NAND_SIM_DEBUG == NAND_SIM_DEBUG_FILE
+# define NAND_SIM_LOG(...)      nxmutex_lock(&nand_sim_file_mut); \
+                                fprintf(g_nand_sim_logs, __VA_ARGS__); \
+                                nxmutex_unlock(&nand_sim_file_mut); \
+                                fflush(g_nand_sim_logs)
+#elif NAND_SIM_DEBUG == NAND_SIM_DEBUG_STDOUT
+# define NAND_SIM_LOG(...)      nxmutex_lock(&nand_sim_file_mut); \
+                                fprintf(stdout, __VA_ARGS__); \
+                                nxmutex_unlock(&nand_sim_file_mut); \
+                                fflush(stdout)
+#else
+# define NAND_SIM_LOG(...)
+#endif
+
+#define NAND_SIM_PAGE_WRITTEN         0
+#define NAND_SIM_PAGE_FREE            1
+
+#define NAND_SIM_BLOCK_GOOD           0xff
+#define NAND_SIM_BLOCK_BAD            0xba
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+#ifndef __ASSEMBLY__

Review Comment:
   remove



-- 
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