You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/11/22 11:33:42 UTC

[GitHub] rymanluk commented on a change in pull request #1507: Add generic serial bus driver

rymanluk commented on a change in pull request #1507: Add generic serial bus driver
URL: https://github.com/apache/mynewt-core/pull/1507#discussion_r235673135
 
 

 ##########
 File path: hw/bus/include/bus/bus.h
 ##########
 @@ -0,0 +1,212 @@
+/*
+ * 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 HW_BUS_H_
+#define HW_BUS_H_
+
+#include <stdint.h>
+#include "os/os_dev.h"
+#include "os/os_mutex.h"
+#include "os/os_time.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Flags used for bus operations
+ */
+#define BUS_F_NONE          0
+#define BUS_F_NOSTOP        0x0001
+
+/**
+ * Read data from node
+ *
+ * Reads data from node. Bus is locked automatically for the duration of
+ * operation.
+ *
+ * The timeout parameter applies to complete transaction time, including
+ * locking the bus.
+ *
+ * @param node     Node device object
+ * @param buf      Buffer to read data into
+ * @param length   Length of data to be read
+ * @param timeout  Operation timeout
+ * @param flags    Flags
+ *
+ * @return 0 on success, SYS_xxx on error
+ */
+int
+bus_node_read(struct os_dev *node, uint8_t *buf, uint16_t length,
+              os_time_t timeout, uint16_t flags);
+
+/**
+ * Write data to node
+ *
+ * Writes data to node. Bus is locked automatically for the duration of
+ * operation.
+ *
+ * The timeout parameter applies to complete transaction time, including
+ * locking the bus.
+ *
+ * @param node     Node device object
+ * @param buf      Buffer with data be written
+ * @param length   Length of data to be written
+ * @param timeout  Operation timeout
+ * @param flags    Flags
+ *
+ * @return 0 on success, SYS_xxx on error
+ */
+int
+bus_node_write(struct os_dev *node, uint8_t *buf, uint16_t length,
+               os_time_t timeout, uint16_t flags);
+
+/**
+ * Perform write and read transaction on node
+ *
+ * Writes data to node and automatically reads response afterwards. This is a
+ * convenient shortcut for a generic write-then-read operation used to read data
+ * from devices which is executed atomically (i.e. with bus lock held during
+ * entire transaction).
+ *
+ * The timeout parameter applies to complete transaction time.
+ *
+ * @param node     Node device object
+ * @param wbuf     Buffer with data be written
+ * @param wlength  Length of data to be written
+ * @param rbuf     Buffer to read data into
+ * @param rlength  Length of data to be read
+ * @param timeout  Operation timeout
+ * @param flags    Flags
+ *
+ * @return 0 on success, SYS_xxx on error
+ */
+int
+bus_node_write_read_transact(struct os_dev *node, uint8_t *wbuf,
+                             uint16_t wlength, uint8_t *rbuf, uint16_t rlength,
+                             os_time_t timeout, uint16_t flags);
+
+/**
+ * Read data from node
+ *
+ * This is simple version of bus_node_read() with default timeout and no flags.
+ *
+ * @param node     Node device object
+ * @param buf      Buffer to read data into
+ * @param length   Length of data to be read
+ *
+ * @return 0 on success, SYS_xxx on error
+ */
+static inline int
+bus_node_simple_read(struct os_dev *node, uint8_t *buf, uint16_t length)
+{
+    return bus_node_read(node, buf, length, OS_TIMEOUT_NEVER, BUS_F_NONE);
+}
+
+/**
+ * Read data from node
 
 Review comment:
   Should be write

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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


With regards,
Apache Git Services