acassis commented on code in PR #18785:
URL: https://github.com/apache/nuttx/pull/18785#discussion_r3130847376


##########
drivers/timers/dshot.c:
##########
@@ -0,0 +1,461 @@
+/****************************************************************************
+ * drivers/timers/dshot.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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 <sys/types.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/fs/fs.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/mutex.h>
+#include <nuttx/timers/dshot.h>
+
+#ifdef CONFIG_DSHOT
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define DSHOT_GCR_MASK       0x000fffffu
+#define DSHOT_ERPMSCALE_NUM  600000u
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct dshot_upperhalf_s
+{
+  uint8_t crefs;
+  mutex_t lock;
+  FAR struct dshot_lowerhalf_s *dev;
+  struct dshot_ch_telemetry_s telemetry[_DSHOT_NCHANNELS];
+  bool bidir;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int dshot_open(FAR struct file *filep);
+static int dshot_close(FAR struct file *filep);
+static ssize_t dshot_read(FAR struct file *filep, FAR char *buffer,
+                          size_t buflen);
+static ssize_t dshot_write(FAR struct file *filep, FAR const char *buffer,
+                           size_t buflen);
+static int dshot_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations g_dshotops =
+{
+  dshot_open,  /* open */
+  dshot_close, /* close */
+  dshot_read,  /* read */
+  dshot_write, /* write */
+  NULL,        /* seek */
+  dshot_ioctl, /* ioctl */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static uint16_t dshot_crc(uint16_t packet, bool bidir)
+{
+  uint16_t crc;
+
+  crc = packet >> 4;
+  crc = crc ^ (crc >> 4) ^ (crc >> 8);
+
+  if (bidir)
+    {
+      crc = ~crc;
+    }
+
+  return crc & 0xf;
+}
+
+static uint16_t dshot_build_packet(uint16_t throttle, bool telemetry,
+                                   bool bidir)
+{
+  uint16_t packet = 0;
+  packet |= throttle << 5;
+  packet |= (telemetry ? 1 << 4 : 0);
+  packet |= dshot_crc(packet, bidir);
+
+  return packet;
+}
+
+/* Parse raw pattern from the line into a 16-bit packet, and verify crc:
+ * 1. extract gcr20 value from the raw value
+ * 2. extract the 16-bit packet from the gcr20
+ * 3. check the packet crc
+ *
+ * In case of error, return negative error code.
+ * Otherwise return the 12-bit payload as a positive integer.
+ */

Review Comment:
   Please use the right Description format with its parameters and return type



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to