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 2020/08/26 15:40:10 UTC

[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a change in pull request #1618: Samd5e5 progmem

xiaoxiang781216 commented on a change in pull request #1618:
URL: https://github.com/apache/incubator-nuttx/pull/1618#discussion_r477397380



##########
File path: boards/arm/samd5e5/metro-m4/src/sam_bq27426.c
##########
@@ -0,0 +1,77 @@
+/****************************************************************************
+ * boards/arm/samd5e5/metro-m4/src/sam_bq27426.c
+ *
+ *   Author: Leomar Mateus Radke <le...@falker.com.br>
+ *   Author: Ricardo Wartchow <wa...@gmail.com>
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <debug.h>
+#include <errno.h>
+
+#include <nuttx/i2c/i2c_master.h>
+#include <nuttx/power/battery_gauge.h>
+
+#include <nuttx/power/bq27426.h>
+#include <nuttx/power/battery_ioctl.h>
+
+#include "arm_arch.h"
+#include "chip.h"
+#include "hardware/sam_i2c_master.h"
+#include "metro-m4.h"
+
+#include <arch/board/board.h>
+#include "sam_config.h"
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+#ifdef CONFIG_BQ27426
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: sam_bq24298_initialize
+ *
+ * Description:
+ *   Called to configure bq24298
+ *
+ ****************************************************************************/
+
+int sam_bq27426_initialize(FAR const char *devname)
+{
+    FAR struct battery_gauge_dev_s *bq27426_m4;
+
+    bq27426_m4 = (FAR struct battery_gauge_dev_s *)bq27426_initialize(
+                                                   g_i2c5_dev,
+                                                   BQ27426_I2C_ADDRESS,
+                                                   100000);
+  return battery_gauge_register(devname, bq27426_m4);
+}
+#endif /* CONFIG_BQ27426 */

Review comment:
       add new line

##########
File path: arch/arm/src/samd5e5/sam_progmem.c
##########
@@ -0,0 +1,1015 @@
+/****************************************************************************
+ * arch/arm/src/samd5e5/sam_progmem.c
+ *
+ *   Copyright 2020 Falker Automacao Agricola LTDA.
+ *   Author: Leomar Mateus Radke <le...@falker.com.br>
+ *   Author: Ricardo Wartchow <wa...@gmail.com>

Review comment:
       The new apache copyright don't allow to add the contributor name.

##########
File path: arch/arm/src/samd5e5/Make.defs
##########
@@ -177,3 +177,7 @@ endif
 ifeq ($(CONFIG_SAMD5E5_RTC),y)
 CHIP_CSRCS += sam_rtc.c
 endif
+
+ifeq ($(CONFIG_SAMD5E5_PROGMEM),y)
+CHIP_CSRCS += sam_progmem.c
+endif

Review comment:
       add one newline

##########
File path: drivers/power/bq27426.c
##########
@@ -0,0 +1,460 @@
+/****************************************************************************
+ * drivers/power/bq27426.c
+ *
+ * Lower half driver for BQ27426 battery fuel gauge
+ *
+ *   Author: Leomar Mateus Radke <le...@falker.com.br>
+ *   Author: Ricardo Wartchow <wa...@gmail.com>

Review comment:
       remove

##########
File path: arch/arm/src/samd5e5/sam_progmem.h
##########
@@ -0,0 +1,59 @@
+/****************************************************************************
+ * arch/arm/src/samd5e5/sam_progmem.h
+ *
+ *   Copyright 2020 Falker Automacao Agricola LTDA.
+ *   Author: Leomar Mateus Radke <le...@falker.com.br>
+ *   Author: Ricardo Wartchow <wa...@gmail.com>

Review comment:
       remove author.

##########
File path: boards/arm/samd5e5/metro-m4/src/sam_at24.c
##########
@@ -0,0 +1,129 @@
+/****************************************************************************
+ * boards/arm/samd5e5/metro-m4/src/sam_at24.c
+ *
+ *   Author: Leomar Mateus Radke <le...@falker.com.br>
+ *   Author: Ricardo Wartchow <wa...@gmail.com>

Review comment:
       remove the author.

##########
File path: boards/arm/samd5e5/metro-m4/src/sam_smartfs.c
##########
@@ -0,0 +1,237 @@
+/****************************************************************************
+ * boards/arm/samd5e5/metro-m4/src/sam_smartfs.c
+ *
+ *   Author: Leomar Mateus Radke <le...@falker.com.br>
+ *   Author: Ricardo Wartchow <wa...@gmail.com>
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdbool.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#include <debug.h>
+
+#include "arm_arch.h"
+#include "chip.h"
+#include <arch/board/board.h>
+
+#include "metro-m4.h"
+
+#ifdef CONFIG_MTD
+#  include <nuttx/mtd/mtd.h>
+#  include <nuttx/mtd/configdata.h>
+#  include <nuttx/drivers/drivers.h>
+#  include "sam_progmem.h"
+#endif
+
+#ifdef CONFIG_FS_SMARTFS
+#  include <nuttx/fs/smart.h>
+#endif
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#ifdef CONFIG_FS_SMARTFS
+  int ret;
+  FAR struct mtd_dev_s *mtd;
+  FAR struct mtd_geometry_s geo;
+#endif
+
+#if defined(CONFIG_MTD_PARTITION_NAMES)
+  const char *partname = "mnta";
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+#ifdef CONFIG_FS_SMARTFS
+int sam_smartfs_initialize(void)
+{
+  /* Initialize the SAMD5E5 FLASH programming memory library */
+
+  sam_progmem_initialize();
+
+  /* Create an instance of the SAMD5E5 FLASH program memory device driver */
+
+  mtd = progmem_initialize();
+  if (!mtd)
+    {
+      syslog(LOG_ERR, "ERROR: progmem_initialize failed\n");
+    }
+
+  ret = mtd->ioctl(mtd, MTDIOC_GEOMETRY, (unsigned long)((uintptr_t)&geo));
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "ERROR: mtd->ioctl failed: %d\n", ret);
+      return ret;
+    }
+
+  #ifdef CONFIG_MTD_PARTITION
+    {
+      int partno;
+      int partsize;
+      int partoffset;
+      int partszbytes;
+      int erasesize;
+      const char *partstring = "256";
+      const char *ptr;
+      FAR struct mtd_dev_s *mtd_part;
+      char  partref[4];
+
+      /* Now create a partition on the FLASH device */
+
+      partno = 0;
+      ptr = partstring;
+      partoffset = 0;
+
+          /* Get the Flash erase size */
+
+          erasesize = geo.erasesize;
+
+          while (*ptr != '\0')
+            {
+              /* Get the partition size */
+
+              partsize = atoi(ptr);
+              partszbytes = (partsize << 10); /* partsize is defined in KB */
+              printf("partsize %d partszbytes %d\n", partsize, partszbytes);
+
+              /* Check if partition size is bigger then erase block */
+
+              if (partszbytes < erasesize)
+                {
+                  syslog(LOG_ERR,
+                    "ERROR: Partition size is lesser than erasesize!\n");
+                  return -1;
+                }
+
+              /* Check if partition size is multiple of erase block */
+
+              if ((partszbytes % erasesize) != 0)
+                {
+                  syslog(LOG_ERR,
+                    "ERROR: Partition size is not multiple of erasesize!\n");
+                  return -1;
+                }
+
+              mtd_part = mtd_partition(mtd, partoffset,
+                                       partszbytes / erasesize);
+              partoffset += partszbytes / erasesize;
+
+              /* Test if this is the config partition */
+
+            #if defined  CONFIG_MTD_CONFIG
+              if (partno == 0)
+                {
+                  /* Register the partition as the config device */
+
+                  mtdconfig_register(mtd_part);
+                }
+                else
+            #endif
+                {
+                  /* Now initialize a SMART Flash block device
+                   * and bind it to the MTD device.
+                   */
+
+            #if defined(CONFIG_MTD_SMART) && defined(CONFIG_FS_SMARTFS)
+                      sprintf(partref, "p%d", partno);
+                      smart_initialize(0, mtd_part, partref);
+            #endif
+                }
+
+                  /* Set the partition name */
+
+            #ifdef CONFIG_MTD_PARTITION_NAMES
+                  if (!mtd_part)
+                    {
+                      syslog(LOG_ERR,
+                            "Error: failed to create partition %s\n",
+                            partname);
+                      return -1;
+                    }
+
+                  mtd_setpartitionname(mtd_part, partname);
+
+                  /* Now skip to next name.
+                   * We don't need to split the string here
+                   * because the MTD partition logic will only
+                   * display names up to the comma,
+                   * thus allowing us to use a single static name
+                   * in the code.
+                   */
+
+                  while (*partname != ',' && *partname != '\0')
+                    {
+                      /* Skip to next ',' */
+
+                      partname++;
+                    }
+
+                  if (*partname == ',')
+                    {
+                      partname++;
+                    }
+            #endif
+
+          /* Update the pointer to point to the next size in the list */
+
+          while ((*ptr >= '0') && (*ptr <= '9'))
+            {
+              ptr++;
+            }
+
+          if (*ptr == ',')
+            {
+              ptr++;
+            }
+
+          /* Increment the part number */
+
+          partno++;
+        }
+    }
+  #else /* CONFIG_MTD_PARTITION */
+
+  /* Configure the device with no partition support */
+
+  smart_initialize(0, mtd, NULL);
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "ERROR: SmartFS initialization failed: %d\n", ret);
+      return ret;
+    }
+
+    #endif
+
+  return OK;
+}
+#endif /* CONFIG_FS_SMARTFS */

Review comment:
       add newline

##########
File path: include/nuttx/power/bq27426.h
##########
@@ -0,0 +1,213 @@
+/****************************************************************************
+ * include/nuttx/power/bq27426.h
+ * Lower half driver for bq27426 battery fuel gauge.
+ *
+ *   Author: Leomar Mateus Radke <le...@falker.com.br>
+ *   Author: Ricardo Wartchow <wa...@gmail.com>

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.

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