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/10/29 10:33:29 UTC

[GitHub] [incubator-nuttx] Donny9 commented on a change in pull request #2158: Linux I2C bus support in sim

Donny9 commented on a change in pull request #2158:
URL: https://github.com/apache/incubator-nuttx/pull/2158#discussion_r514156997



##########
File path: arch/sim/src/sim/up_linuxi2c.c
##########
@@ -0,0 +1,145 @@
+/****************************************************************************
+ * arch/sim/src/sim/up_linuxi2c.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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/kmalloc.h>
+
+#include <sys/types.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include <nuttx/i2c/i2c_master.h>
+
+#include "up_linuxi2c_host.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int linuxi2c_transfer(FAR struct i2c_master_s *dev,
+                             FAR struct i2c_msg_s *msgs, int count);
+#ifdef CONFIG_I2C_RESET
+int linuxi2c_reset(FAR struct i2c_master_s *dev);
+#endif
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+struct i2c_ops_s g_linuxi2c_ops =
+{
+  .transfer = linuxi2c_transfer,
+#ifdef CONFIG_I2C_RESET
+  .reset = linuxi2c_reset,
+#endif
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static int linuxi2c_transfer(FAR struct i2c_master_s *dev,
+                             FAR struct i2c_msg_s *msgs, int count)
+{
+  int ret;
+  uint16_t msg_idx;
+  struct linuxi2c_master_s *priv = (struct linuxi2c_master_s *)dev;
+  struct linux_i2c_rdwr_ioctl_data ioctl_data;
+  struct linux_i2c_msg *l_msgs =
+    kmm_malloc(sizeof(struct linux_i2c_msg) * count);
+
+  if (l_msgs == NULL)
+    {
+      return -1;
+    }
+
+  ioctl_data.msgs = l_msgs;
+  ioctl_data.nmsgs = count;
+
+  for (msg_idx = 0; msg_idx < count; msg_idx++)
+    {
+      /* TODO: Translate flags */

Review comment:
       Yes ,we should map nuttx flags to linux flags, otherwise, we can't access physical device by host i2c interface.




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