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


##########
system/i3c/i3c_main.c:
##########
@@ -0,0 +1,416 @@
+/****************************************************************************
+ * apps/system/i3c/i3c_main.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 <ctype.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <getopt.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+
+#include <nuttx/i3c/i3c_driver.h>
+#include <nuttx/i3c/device.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Device naming */
+
+#define DEVNAME_FMT    "/dev/i3c%d"
+#define DEVNAME_FMTLEN (8 + 3 + 1)
+
+/****************************************************************************
+ * Private Type
+ ****************************************************************************/
+
+struct i3c_ioc_priv_xfer
+{
+  uint8_t rnw;       /* encodes the transfer direction. true for a read, false 
for a write */
+  uint16_t len;      /* Length of data buffer buffers, in bytes */
+  FAR uint8_t *data; /*  Holds pointer to userspace buffer with transmit data 
*/
+  uint8_t pad[5];
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static FAR const char *g_sopts = "b:m:p:r:w:h:g";
+static const struct option g_lopts[] =
+{
+  {"bus",     required_argument,  NULL, 'b' },
+  {"manufid", required_argument,  NULL, 'm' },
+  {"partid",  required_argument,  NULL, 'p' },
+  {"read",    required_argument,  NULL, 'r' },
+  {"write",   required_argument,  NULL, 'w' },
+  {"get",     required_argument,  NULL, 'g' },
+  {"command", required_argument,  NULL, 'c' },
+  {"help",    no_argument,        NULL, 'h' },
+  {0, 0, 0, 0}
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: print_usage
+ ****************************************************************************/
+
+static void print_usage(FAR const char *name)
+{
+  fprintf(stdout, "usage: %s options...\n", name);
+  fprintf(stdout, "  options:\n");
+  fprintf(stdout, "  -b --bus     <bus>          bus to use.\n");
+  fprintf(stdout, "  -m --manufid <manufid>      manufacturer ID "
+                  "(upper 16 bits of PID).\n");
+  fprintf(stdout, "  -p --partid  <partid>       part ID "
+                  "(lower 32 bits of PID).\n");
+  fprintf(stdout, "  -r --read    <data length>  read data.\n");
+  fprintf(stdout, "  -w --write   <data block>   Write data block.\n");
+  fprintf(stdout, "  -g --get     <data block>   get a dev info.\n");
+  fprintf(stdout, "  -h --help    Output usage message and exit.\n");
+}
+
+/****************************************************************************
+ * Name: rx_args_to_xfer
+ ****************************************************************************/
+
+static int rx_args_to_xfer(int length, int rnw, FAR uint8_t **data,
+                           FAR char *arg)
+{
+  int32_t len = strtol(arg, NULL, 0);
+  FAR uint8_t *tmp;
+
+  tmp = calloc(len, sizeof(uint8_t));
+  if (!tmp)
+    {
+      return -ENOMEM;
+    }
+
+  rnw = 1;
+  length = len;

Review Comment:
   nop



##########
system/i3c/i3c_main.c:
##########
@@ -0,0 +1,416 @@
+/****************************************************************************
+ * apps/system/i3c/i3c_main.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 <ctype.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <getopt.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+
+#include <nuttx/i3c/i3c_driver.h>
+#include <nuttx/i3c/device.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Device naming */
+
+#define DEVNAME_FMT    "/dev/i3c%d"
+#define DEVNAME_FMTLEN (8 + 3 + 1)
+
+/****************************************************************************
+ * Private Type
+ ****************************************************************************/
+
+struct i3c_ioc_priv_xfer
+{
+  uint8_t rnw;       /* encodes the transfer direction. true for a read, false 
for a write */
+  uint16_t len;      /* Length of data buffer buffers, in bytes */
+  FAR uint8_t *data; /*  Holds pointer to userspace buffer with transmit data 
*/
+  uint8_t pad[5];
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static FAR const char *g_sopts = "b:m:p:r:w:h:g";
+static const struct option g_lopts[] =
+{
+  {"bus",     required_argument,  NULL, 'b' },
+  {"manufid", required_argument,  NULL, 'm' },
+  {"partid",  required_argument,  NULL, 'p' },
+  {"read",    required_argument,  NULL, 'r' },
+  {"write",   required_argument,  NULL, 'w' },
+  {"get",     required_argument,  NULL, 'g' },
+  {"command", required_argument,  NULL, 'c' },
+  {"help",    no_argument,        NULL, 'h' },
+  {0, 0, 0, 0}
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: print_usage
+ ****************************************************************************/
+
+static void print_usage(FAR const char *name)
+{
+  fprintf(stdout, "usage: %s options...\n", name);
+  fprintf(stdout, "  options:\n");
+  fprintf(stdout, "  -b --bus     <bus>          bus to use.\n");
+  fprintf(stdout, "  -m --manufid <manufid>      manufacturer ID "
+                  "(upper 16 bits of PID).\n");
+  fprintf(stdout, "  -p --partid  <partid>       part ID "
+                  "(lower 32 bits of PID).\n");
+  fprintf(stdout, "  -r --read    <data length>  read data.\n");
+  fprintf(stdout, "  -w --write   <data block>   Write data block.\n");
+  fprintf(stdout, "  -g --get     <data block>   get a dev info.\n");
+  fprintf(stdout, "  -h --help    Output usage message and exit.\n");
+}
+
+/****************************************************************************
+ * Name: rx_args_to_xfer
+ ****************************************************************************/
+
+static int rx_args_to_xfer(int length, int rnw, FAR uint8_t **data,
+                           FAR char *arg)
+{
+  int32_t len = strtol(arg, NULL, 0);
+  FAR uint8_t *tmp;
+
+  tmp = calloc(len, sizeof(uint8_t));
+  if (!tmp)
+    {
+      return -ENOMEM;
+    }
+
+  rnw = 1;
+  length = len;
+  *data = tmp;
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: w_args_to_xfer
+ ****************************************************************************/
+
+static int w_args_to_xfer(uint8_t length, FAR uint8_t **data, FAR char *arg)
+{
+  FAR char *data_ptrs[256];
+  FAR uint8_t *tmp;
+  int i = 0;
+  int len;
+
+  data_ptrs[i] = strtok(arg, ",");
+  while (data_ptrs[i] && i < 255)
+    {
+      data_ptrs[++i] = strtok(NULL, ",");
+    }
+
+  tmp = calloc(i, sizeof(uint8_t));
+  if (!tmp)
+    {
+      return -ENOMEM;
+    }
+
+  for (len = 0; len < i; len++)
+    {
+      tmp[len] = (uint8_t)strtol(data_ptrs[len], NULL, 0);
+    }
+
+  length = len;
+  *data = tmp;
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: print_rx_data
+ ****************************************************************************/
+
+static void print_rx_data(FAR struct i3c_ioc_priv_xfer *xfer)
+{
+  FAR uint8_t *tmp;
+  uint32_t i;
+
+  tmp = calloc(xfer->len, sizeof(uint8_t));

Review Comment:
   remove the allocation



##########
system/i3c/i3c_main.c:
##########
@@ -0,0 +1,416 @@
+/****************************************************************************
+ * apps/system/i3c/i3c_main.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 <ctype.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <getopt.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+
+#include <nuttx/i3c/i3c_driver.h>
+#include <nuttx/i3c/device.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Device naming */
+
+#define DEVNAME_FMT    "/dev/i3c%d"
+#define DEVNAME_FMTLEN (8 + 3 + 1)
+
+/****************************************************************************
+ * Private Type
+ ****************************************************************************/
+
+struct i3c_ioc_priv_xfer

Review Comment:
   let's use i3c_priv_xfer directly



##########
system/i3c/i3c_main.c:
##########
@@ -0,0 +1,416 @@
+/****************************************************************************
+ * apps/system/i3c/i3c_main.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 <ctype.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <getopt.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+
+#include <nuttx/i3c/i3c_driver.h>
+#include <nuttx/i3c/device.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Device naming */
+
+#define DEVNAME_FMT    "/dev/i3c%d"
+#define DEVNAME_FMTLEN (8 + 3 + 1)
+
+/****************************************************************************
+ * Private Type
+ ****************************************************************************/
+
+struct i3c_ioc_priv_xfer
+{
+  uint8_t rnw;       /* encodes the transfer direction. true for a read, false 
for a write */
+  uint16_t len;      /* Length of data buffer buffers, in bytes */
+  FAR uint8_t *data; /*  Holds pointer to userspace buffer with transmit data 
*/
+  uint8_t pad[5];
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static FAR const char *g_sopts = "b:m:p:r:w:h:g";
+static const struct option g_lopts[] =
+{
+  {"bus",     required_argument,  NULL, 'b' },
+  {"manufid", required_argument,  NULL, 'm' },
+  {"partid",  required_argument,  NULL, 'p' },
+  {"read",    required_argument,  NULL, 'r' },
+  {"write",   required_argument,  NULL, 'w' },
+  {"get",     required_argument,  NULL, 'g' },
+  {"command", required_argument,  NULL, 'c' },
+  {"help",    no_argument,        NULL, 'h' },
+  {0, 0, 0, 0}
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: print_usage
+ ****************************************************************************/
+
+static void print_usage(FAR const char *name)
+{
+  fprintf(stdout, "usage: %s options...\n", name);
+  fprintf(stdout, "  options:\n");
+  fprintf(stdout, "  -b --bus     <bus>          bus to use.\n");
+  fprintf(stdout, "  -m --manufid <manufid>      manufacturer ID "
+                  "(upper 16 bits of PID).\n");
+  fprintf(stdout, "  -p --partid  <partid>       part ID "
+                  "(lower 32 bits of PID).\n");
+  fprintf(stdout, "  -r --read    <data length>  read data.\n");
+  fprintf(stdout, "  -w --write   <data block>   Write data block.\n");
+  fprintf(stdout, "  -g --get     <data block>   get a dev info.\n");
+  fprintf(stdout, "  -h --help    Output usage message and exit.\n");
+}
+
+/****************************************************************************
+ * Name: rx_args_to_xfer
+ ****************************************************************************/
+
+static int rx_args_to_xfer(int length, int rnw, FAR uint8_t **data,
+                           FAR char *arg)
+{
+  int32_t len = strtol(arg, NULL, 0);
+  FAR uint8_t *tmp;
+
+  tmp = calloc(len, sizeof(uint8_t));
+  if (!tmp)
+    {
+      return -ENOMEM;
+    }
+
+  rnw = 1;
+  length = len;
+  *data = tmp;
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: w_args_to_xfer
+ ****************************************************************************/
+
+static int w_args_to_xfer(uint8_t length, FAR uint8_t **data, FAR char *arg)
+{
+  FAR char *data_ptrs[256];
+  FAR uint8_t *tmp;
+  int i = 0;
+  int len;
+
+  data_ptrs[i] = strtok(arg, ",");
+  while (data_ptrs[i] && i < 255)
+    {
+      data_ptrs[++i] = strtok(NULL, ",");
+    }
+
+  tmp = calloc(i, sizeof(uint8_t));
+  if (!tmp)
+    {
+      return -ENOMEM;
+    }
+
+  for (len = 0; len < i; len++)
+    {
+      tmp[len] = (uint8_t)strtol(data_ptrs[len], NULL, 0);
+    }
+
+  length = len;

Review Comment:
   nop



##########
system/i3c/i3c_main.c:
##########
@@ -0,0 +1,416 @@
+/****************************************************************************
+ * apps/system/i3c/i3c_main.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 <ctype.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <getopt.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+
+#include <nuttx/i3c/i3c_driver.h>
+#include <nuttx/i3c/device.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Device naming */
+
+#define DEVNAME_FMT    "/dev/i3c%d"
+#define DEVNAME_FMTLEN (8 + 3 + 1)
+
+/****************************************************************************
+ * Private Type
+ ****************************************************************************/
+
+struct i3c_ioc_priv_xfer
+{
+  uint8_t rnw;       /* encodes the transfer direction. true for a read, false 
for a write */
+  uint16_t len;      /* Length of data buffer buffers, in bytes */
+  FAR uint8_t *data; /*  Holds pointer to userspace buffer with transmit data 
*/
+  uint8_t pad[5];
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static FAR const char *g_sopts = "b:m:p:r:w:h:g";
+static const struct option g_lopts[] =
+{
+  {"bus",     required_argument,  NULL, 'b' },
+  {"manufid", required_argument,  NULL, 'm' },
+  {"partid",  required_argument,  NULL, 'p' },
+  {"read",    required_argument,  NULL, 'r' },
+  {"write",   required_argument,  NULL, 'w' },
+  {"get",     required_argument,  NULL, 'g' },
+  {"command", required_argument,  NULL, 'c' },
+  {"help",    no_argument,        NULL, 'h' },
+  {0, 0, 0, 0}
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: print_usage
+ ****************************************************************************/
+
+static void print_usage(FAR const char *name)
+{
+  fprintf(stdout, "usage: %s options...\n", name);
+  fprintf(stdout, "  options:\n");
+  fprintf(stdout, "  -b --bus     <bus>          bus to use.\n");
+  fprintf(stdout, "  -m --manufid <manufid>      manufacturer ID "
+                  "(upper 16 bits of PID).\n");
+  fprintf(stdout, "  -p --partid  <partid>       part ID "
+                  "(lower 32 bits of PID).\n");
+  fprintf(stdout, "  -r --read    <data length>  read data.\n");
+  fprintf(stdout, "  -w --write   <data block>   Write data block.\n");
+  fprintf(stdout, "  -g --get     <data block>   get a dev info.\n");
+  fprintf(stdout, "  -h --help    Output usage message and exit.\n");
+}
+
+/****************************************************************************
+ * Name: rx_args_to_xfer
+ ****************************************************************************/
+
+static int rx_args_to_xfer(int length, int rnw, FAR uint8_t **data,
+                           FAR char *arg)

Review Comment:
   add const



##########
system/i3c/i3c_main.c:
##########
@@ -0,0 +1,416 @@
+/****************************************************************************
+ * apps/system/i3c/i3c_main.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 <ctype.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <getopt.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+
+#include <nuttx/i3c/i3c_driver.h>
+#include <nuttx/i3c/device.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Device naming */
+
+#define DEVNAME_FMT    "/dev/i3c%d"
+#define DEVNAME_FMTLEN (8 + 3 + 1)
+
+/****************************************************************************
+ * Private Type
+ ****************************************************************************/
+
+struct i3c_ioc_priv_xfer
+{
+  uint8_t rnw;       /* encodes the transfer direction. true for a read, false 
for a write */
+  uint16_t len;      /* Length of data buffer buffers, in bytes */
+  FAR uint8_t *data; /*  Holds pointer to userspace buffer with transmit data 
*/
+  uint8_t pad[5];

Review Comment:
   remove



##########
system/i3c/i3c_main.c:
##########
@@ -0,0 +1,416 @@
+/****************************************************************************
+ * apps/system/i3c/i3c_main.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 <ctype.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <getopt.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+
+#include <nuttx/i3c/i3c_driver.h>
+#include <nuttx/i3c/device.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Device naming */
+
+#define DEVNAME_FMT    "/dev/i3c%d"
+#define DEVNAME_FMTLEN (8 + 3 + 1)
+
+/****************************************************************************
+ * Private Type
+ ****************************************************************************/
+
+struct i3c_ioc_priv_xfer
+{
+  uint8_t rnw;       /* encodes the transfer direction. true for a read, false 
for a write */
+  uint16_t len;      /* Length of data buffer buffers, in bytes */
+  FAR uint8_t *data; /*  Holds pointer to userspace buffer with transmit data 
*/
+  uint8_t pad[5];
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static FAR const char *g_sopts = "b:m:p:r:w:h:g";
+static const struct option g_lopts[] =
+{
+  {"bus",     required_argument,  NULL, 'b' },
+  {"manufid", required_argument,  NULL, 'm' },
+  {"partid",  required_argument,  NULL, 'p' },
+  {"read",    required_argument,  NULL, 'r' },
+  {"write",   required_argument,  NULL, 'w' },
+  {"get",     required_argument,  NULL, 'g' },
+  {"command", required_argument,  NULL, 'c' },
+  {"help",    no_argument,        NULL, 'h' },
+  {0, 0, 0, 0}
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: print_usage
+ ****************************************************************************/
+
+static void print_usage(FAR const char *name)
+{
+  fprintf(stdout, "usage: %s options...\n", name);
+  fprintf(stdout, "  options:\n");
+  fprintf(stdout, "  -b --bus     <bus>          bus to use.\n");
+  fprintf(stdout, "  -m --manufid <manufid>      manufacturer ID "
+                  "(upper 16 bits of PID).\n");
+  fprintf(stdout, "  -p --partid  <partid>       part ID "
+                  "(lower 32 bits of PID).\n");
+  fprintf(stdout, "  -r --read    <data length>  read data.\n");
+  fprintf(stdout, "  -w --write   <data block>   Write data block.\n");
+  fprintf(stdout, "  -g --get     <data block>   get a dev info.\n");
+  fprintf(stdout, "  -h --help    Output usage message and exit.\n");
+}
+
+/****************************************************************************
+ * Name: rx_args_to_xfer
+ ****************************************************************************/
+
+static int rx_args_to_xfer(int length, int rnw, FAR uint8_t **data,
+                           FAR char *arg)
+{
+  int32_t len = strtol(arg, NULL, 0);
+  FAR uint8_t *tmp;
+
+  tmp = calloc(len, sizeof(uint8_t));
+  if (!tmp)
+    {
+      return -ENOMEM;
+    }
+
+  rnw = 1;
+  length = len;
+  *data = tmp;
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: w_args_to_xfer
+ ****************************************************************************/
+
+static int w_args_to_xfer(uint8_t length, FAR uint8_t **data, FAR char *arg)
+{
+  FAR char *data_ptrs[256];
+  FAR uint8_t *tmp;
+  int i = 0;
+  int len;
+
+  data_ptrs[i] = strtok(arg, ",");
+  while (data_ptrs[i] && i < 255)
+    {
+      data_ptrs[++i] = strtok(NULL, ",");
+    }
+
+  tmp = calloc(i, sizeof(uint8_t));
+  if (!tmp)
+    {
+      return -ENOMEM;
+    }
+
+  for (len = 0; len < i; len++)
+    {
+      tmp[len] = (uint8_t)strtol(data_ptrs[len], NULL, 0);
+    }
+
+  length = len;
+  *data = tmp;
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: print_rx_data
+ ****************************************************************************/
+
+static void print_rx_data(FAR struct i3c_ioc_priv_xfer *xfer)
+{
+  FAR uint8_t *tmp;
+  uint32_t i;
+
+  tmp = calloc(xfer->len, sizeof(uint8_t));
+  if (!tmp)
+    {
+      return;
+    }
+
+  memcpy(tmp, (FAR void *)(uintptr_t)xfer->data,
+         xfer->len * sizeof(uint8_t));
+
+  fprintf(stdout, "  received data:\n");
+  for (i = 0; i < xfer->len; i++)
+    {
+      fprintf(stdout, "    0x%02x\n", tmp[i]);
+    }
+
+  free(tmp);
+}
+
+/****************************************************************************
+ * Name: i3c_transfers
+ ****************************************************************************/
+
+static int i3c_transfers(int argc, FAR char *argv[], const int fd,
+                         uint16_t manufid, uint16_t partid, int nxfers)
+{
+  FAR struct i3c_ioc_priv_xfer *xfers;
+  struct i3c_transfer_s transfers;
+  int ret = 0;
+  int opt;
+  int i;
+
+  if (nxfers <= 0)
+    {
+      return EXIT_FAILURE;
+    }
+
+  transfers.manufid = manufid;
+  transfers.partid = partid;
+
+  /* init receive or send works */
+
+  xfers = calloc(nxfers, sizeof(*xfers));
+  if (!xfers)
+    {
+      return -ENOMEM;
+    }
+
+  optind = 1;
+  while ((opt = getopt_long(argc, argv, g_sopts, g_lopts, NULL)) != EOF)
+    {
+      switch (opt)
+        {
+          case 'h':
+          case 'm':
+          case 'p':
+          case 'b':
+            break;
+          case 'r':
+            if (rx_args_to_xfer(xfers->len, xfers->rnw, &xfers->data,
+                                optarg))
+              {
+                ret = EXIT_FAILURE;
+                goto err_free;
+              }
+
+            break;
+          case 'w':
+            if (w_args_to_xfer(xfers->len, &xfers->data, optarg))

Review Comment:
   ditto



##########
system/i3c/i3c_main.c:
##########
@@ -0,0 +1,416 @@
+/****************************************************************************
+ * apps/system/i3c/i3c_main.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 <ctype.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <getopt.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+
+#include <nuttx/i3c/i3c_driver.h>
+#include <nuttx/i3c/device.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Device naming */
+
+#define DEVNAME_FMT    "/dev/i3c%d"
+#define DEVNAME_FMTLEN (8 + 3 + 1)
+
+/****************************************************************************
+ * Private Type
+ ****************************************************************************/
+
+struct i3c_ioc_priv_xfer
+{
+  uint8_t rnw;       /* encodes the transfer direction. true for a read, false 
for a write */
+  uint16_t len;      /* Length of data buffer buffers, in bytes */
+  FAR uint8_t *data; /*  Holds pointer to userspace buffer with transmit data 
*/
+  uint8_t pad[5];
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static FAR const char *g_sopts = "b:m:p:r:w:h:g";
+static const struct option g_lopts[] =
+{
+  {"bus",     required_argument,  NULL, 'b' },
+  {"manufid", required_argument,  NULL, 'm' },
+  {"partid",  required_argument,  NULL, 'p' },
+  {"read",    required_argument,  NULL, 'r' },
+  {"write",   required_argument,  NULL, 'w' },
+  {"get",     required_argument,  NULL, 'g' },
+  {"command", required_argument,  NULL, 'c' },
+  {"help",    no_argument,        NULL, 'h' },
+  {0, 0, 0, 0}
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: print_usage
+ ****************************************************************************/
+
+static void print_usage(FAR const char *name)
+{
+  fprintf(stdout, "usage: %s options...\n", name);
+  fprintf(stdout, "  options:\n");
+  fprintf(stdout, "  -b --bus     <bus>          bus to use.\n");
+  fprintf(stdout, "  -m --manufid <manufid>      manufacturer ID "
+                  "(upper 16 bits of PID).\n");
+  fprintf(stdout, "  -p --partid  <partid>       part ID "
+                  "(lower 32 bits of PID).\n");
+  fprintf(stdout, "  -r --read    <data length>  read data.\n");
+  fprintf(stdout, "  -w --write   <data block>   Write data block.\n");
+  fprintf(stdout, "  -g --get     <data block>   get a dev info.\n");
+  fprintf(stdout, "  -h --help    Output usage message and exit.\n");
+}
+
+/****************************************************************************
+ * Name: rx_args_to_xfer
+ ****************************************************************************/
+
+static int rx_args_to_xfer(int length, int rnw, FAR uint8_t **data,
+                           FAR char *arg)
+{
+  int32_t len = strtol(arg, NULL, 0);
+  FAR uint8_t *tmp;
+
+  tmp = calloc(len, sizeof(uint8_t));
+  if (!tmp)
+    {
+      return -ENOMEM;
+    }
+
+  rnw = 1;
+  length = len;
+  *data = tmp;
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: w_args_to_xfer
+ ****************************************************************************/
+
+static int w_args_to_xfer(uint8_t length, FAR uint8_t **data, FAR char *arg)
+{
+  FAR char *data_ptrs[256];
+  FAR uint8_t *tmp;
+  int i = 0;
+  int len;
+
+  data_ptrs[i] = strtok(arg, ",");
+  while (data_ptrs[i] && i < 255)
+    {
+      data_ptrs[++i] = strtok(NULL, ",");
+    }
+
+  tmp = calloc(i, sizeof(uint8_t));
+  if (!tmp)
+    {
+      return -ENOMEM;
+    }
+
+  for (len = 0; len < i; len++)
+    {
+      tmp[len] = (uint8_t)strtol(data_ptrs[len], NULL, 0);
+    }
+
+  length = len;
+  *data = tmp;
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: print_rx_data
+ ****************************************************************************/
+
+static void print_rx_data(FAR struct i3c_ioc_priv_xfer *xfer)
+{
+  FAR uint8_t *tmp;
+  uint32_t i;
+
+  tmp = calloc(xfer->len, sizeof(uint8_t));
+  if (!tmp)
+    {
+      return;
+    }
+
+  memcpy(tmp, (FAR void *)(uintptr_t)xfer->data,
+         xfer->len * sizeof(uint8_t));
+
+  fprintf(stdout, "  received data:\n");
+  for (i = 0; i < xfer->len; i++)
+    {
+      fprintf(stdout, "    0x%02x\n", tmp[i]);
+    }
+
+  free(tmp);
+}
+
+/****************************************************************************
+ * Name: i3c_transfers
+ ****************************************************************************/
+
+static int i3c_transfers(int argc, FAR char *argv[], const int fd,
+                         uint16_t manufid, uint16_t partid, int nxfers)
+{
+  FAR struct i3c_ioc_priv_xfer *xfers;
+  struct i3c_transfer_s transfers;
+  int ret = 0;
+  int opt;
+  int i;
+
+  if (nxfers <= 0)
+    {
+      return EXIT_FAILURE;
+    }
+
+  transfers.manufid = manufid;
+  transfers.partid = partid;
+
+  /* init receive or send works */
+
+  xfers = calloc(nxfers, sizeof(*xfers));
+  if (!xfers)
+    {
+      return -ENOMEM;
+    }
+
+  optind = 1;
+  while ((opt = getopt_long(argc, argv, g_sopts, g_lopts, NULL)) != EOF)
+    {
+      switch (opt)
+        {
+          case 'h':
+          case 'm':
+          case 'p':
+          case 'b':
+            break;
+          case 'r':
+            if (rx_args_to_xfer(xfers->len, xfers->rnw, &xfers->data,
+                                optarg))
+              {
+                ret = EXIT_FAILURE;
+                goto err_free;
+              }
+
+            break;
+          case 'w':
+            if (w_args_to_xfer(xfers->len, &xfers->data, optarg))
+              {
+                ret = EXIT_FAILURE;
+                goto err_free;
+              }
+
+            break;
+        }
+    }
+
+  transfers.nxfers = nxfers;
+  transfers.xfers = (FAR struct i3c_priv_xfer *)xfers;

Review Comment:
   remove the casst



##########
system/i3c/i3c_main.c:
##########
@@ -0,0 +1,416 @@
+/****************************************************************************
+ * apps/system/i3c/i3c_main.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 <ctype.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <getopt.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+
+#include <nuttx/i3c/i3c_driver.h>
+#include <nuttx/i3c/device.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Device naming */
+
+#define DEVNAME_FMT    "/dev/i3c%d"
+#define DEVNAME_FMTLEN (8 + 3 + 1)
+
+/****************************************************************************
+ * Private Type
+ ****************************************************************************/
+
+struct i3c_ioc_priv_xfer
+{
+  uint8_t rnw;       /* encodes the transfer direction. true for a read, false 
for a write */
+  uint16_t len;      /* Length of data buffer buffers, in bytes */
+  FAR uint8_t *data; /*  Holds pointer to userspace buffer with transmit data 
*/
+  uint8_t pad[5];
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static FAR const char *g_sopts = "b:m:p:r:w:h:g";
+static const struct option g_lopts[] =
+{
+  {"bus",     required_argument,  NULL, 'b' },
+  {"manufid", required_argument,  NULL, 'm' },
+  {"partid",  required_argument,  NULL, 'p' },
+  {"read",    required_argument,  NULL, 'r' },
+  {"write",   required_argument,  NULL, 'w' },
+  {"get",     required_argument,  NULL, 'g' },
+  {"command", required_argument,  NULL, 'c' },
+  {"help",    no_argument,        NULL, 'h' },
+  {0, 0, 0, 0}
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: print_usage
+ ****************************************************************************/
+
+static void print_usage(FAR const char *name)
+{
+  fprintf(stdout, "usage: %s options...\n", name);
+  fprintf(stdout, "  options:\n");
+  fprintf(stdout, "  -b --bus     <bus>          bus to use.\n");
+  fprintf(stdout, "  -m --manufid <manufid>      manufacturer ID "
+                  "(upper 16 bits of PID).\n");
+  fprintf(stdout, "  -p --partid  <partid>       part ID "
+                  "(lower 32 bits of PID).\n");
+  fprintf(stdout, "  -r --read    <data length>  read data.\n");
+  fprintf(stdout, "  -w --write   <data block>   Write data block.\n");
+  fprintf(stdout, "  -g --get     <data block>   get a dev info.\n");
+  fprintf(stdout, "  -h --help    Output usage message and exit.\n");
+}
+
+/****************************************************************************
+ * Name: rx_args_to_xfer
+ ****************************************************************************/
+
+static int rx_args_to_xfer(int length, int rnw, FAR uint8_t **data,
+                           FAR char *arg)
+{
+  int32_t len = strtol(arg, NULL, 0);
+  FAR uint8_t *tmp;
+
+  tmp = calloc(len, sizeof(uint8_t));
+  if (!tmp)
+    {
+      return -ENOMEM;
+    }
+
+  rnw = 1;
+  length = len;
+  *data = tmp;
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: w_args_to_xfer
+ ****************************************************************************/
+
+static int w_args_to_xfer(uint8_t length, FAR uint8_t **data, FAR char *arg)
+{
+  FAR char *data_ptrs[256];
+  FAR uint8_t *tmp;
+  int i = 0;
+  int len;
+
+  data_ptrs[i] = strtok(arg, ",");
+  while (data_ptrs[i] && i < 255)
+    {
+      data_ptrs[++i] = strtok(NULL, ",");
+    }
+
+  tmp = calloc(i, sizeof(uint8_t));
+  if (!tmp)
+    {
+      return -ENOMEM;
+    }
+
+  for (len = 0; len < i; len++)
+    {
+      tmp[len] = (uint8_t)strtol(data_ptrs[len], NULL, 0);
+    }
+
+  length = len;
+  *data = tmp;
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: print_rx_data
+ ****************************************************************************/
+
+static void print_rx_data(FAR struct i3c_ioc_priv_xfer *xfer)
+{
+  FAR uint8_t *tmp;
+  uint32_t i;
+
+  tmp = calloc(xfer->len, sizeof(uint8_t));
+  if (!tmp)
+    {
+      return;
+    }
+
+  memcpy(tmp, (FAR void *)(uintptr_t)xfer->data,
+         xfer->len * sizeof(uint8_t));
+
+  fprintf(stdout, "  received data:\n");
+  for (i = 0; i < xfer->len; i++)
+    {
+      fprintf(stdout, "    0x%02x\n", tmp[i]);
+    }
+
+  free(tmp);
+}
+
+/****************************************************************************
+ * Name: i3c_transfers
+ ****************************************************************************/
+
+static int i3c_transfers(int argc, FAR char *argv[], const int fd,
+                         uint16_t manufid, uint16_t partid, int nxfers)
+{
+  FAR struct i3c_ioc_priv_xfer *xfers;
+  struct i3c_transfer_s transfers;
+  int ret = 0;
+  int opt;
+  int i;
+
+  if (nxfers <= 0)
+    {
+      return EXIT_FAILURE;
+    }
+
+  transfers.manufid = manufid;
+  transfers.partid = partid;
+
+  /* init receive or send works */
+
+  xfers = calloc(nxfers, sizeof(*xfers));
+  if (!xfers)
+    {
+      return -ENOMEM;
+    }
+
+  optind = 1;
+  while ((opt = getopt_long(argc, argv, g_sopts, g_lopts, NULL)) != EOF)
+    {
+      switch (opt)
+        {
+          case 'h':
+          case 'm':
+          case 'p':
+          case 'b':
+            break;
+          case 'r':
+            if (rx_args_to_xfer(xfers->len, xfers->rnw, &xfers->data,

Review Comment:
   need increase xfers



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