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 2020/10/26 00:36:17 UTC

[GitHub] [mynewt-nimble] v01d opened a new pull request #878: Add support for NuttX

v01d opened a new pull request #878:
URL: https://github.com/apache/mynewt-nimble/pull/878


   This PR adds support for Apache NuttX RTOS. As NuttX is POSIX compatible, I mostly used the Linux porting layer unchanged and only introduce some differences (I also wrote the event queue using POSIX message queues, which removed the need for the C++ file). Support for the required interface in NuttX has just been merged so this depends on master version of NuttX at the moment. nimBLE is used on NuttX just for its host layer.
   
   I'm marking this as draft because I would like to get some feedback in order to check that I'm in the right direction and then clean it up a bit (there are some changes that you may want to be merged separately). Also, I needed to distinguish Linux from NuttX case in the HCI socket interface file but I don't know how to create a new variable to do so, so I would need to fix that as well.
   
   I've been using nimBLE extensively on NuttX, both in the "sim" build (where NuttX uses the PC's bluetooth stack and simply passes the HCI messages around) and on nRF52832 chip (I wrote a link-layer for NuttX which is not yet merged).
   
   Integration will be completed in NuttX by having an extra "nimble" application which downloads this repo and builds the required userspace component (the host-layer).


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



[GitHub] [mynewt-nimble] v01d commented on pull request #878: Add support for NuttX

Posted by GitBox <gi...@apache.org>.
v01d commented on pull request #878:
URL: https://github.com/apache/mynewt-nimble/pull/878#issuecomment-740067070


   I just force pushed the changes. I still don't know what to do about the coding style error reported by CI.


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



[GitHub] [mynewt-nimble] apache-mynewt-bot commented on pull request #878: Add support for NuttX

Posted by GitBox <gi...@apache.org>.
apache-mynewt-bot commented on pull request #878:
URL: https://github.com/apache/mynewt-nimble/pull/878#issuecomment-745404670


   
   <!-- style-bot -->
   
   ## Style check summary
   
   ### Our coding style is [here!](https://github.com/apache/mynewt-core/blob/master/CODING_STANDARDS.md)
   
   
   #### nimble/transport/socket/src/ble_hci_socket.c
   <details>
   
   ```diff
   @@ -54,7 +54,7 @@
    #if MYNEWT_VAL(BLE_SOCK_USE_LINUX_BLUE)
    #include <sys/errno.h>
    #define BTPROTO_HCI       1
   -#define HCI_CHANNEL_RAW	  0
   +#define HCI_CHANNEL_RAW   0
    #define HCI_CHANNEL_USER  1
    #define HCIDEVUP          _IOW('H', 201, int)
    #define HCIDEVDOWN        _IOW('H', 202, int)
   ```
   
   </details>
   
   #### porting/nimble/include/log_common/log_common.h
   <details>
   
   ```diff
   @@ -44,12 +44,12 @@
    #define LOG_LEVEL_MAX      (15)
    
    #define LOG_LEVEL_STR(level) \
   -    (LOG_LEVEL_DEBUG    == level ? "DEBUG"    :\
   -    (LOG_LEVEL_INFO     == level ? "INFO"     :\
   -    (LOG_LEVEL_WARN     == level ? "WARN"     :\
   -    (LOG_LEVEL_ERROR    == level ? "ERROR"    :\
   -    (LOG_LEVEL_CRITICAL == level ? "CRITICAL" :\
   -     "UNKNOWN")))))
   +    (LOG_LEVEL_DEBUG == level ? "DEBUG"    : \
   +     (LOG_LEVEL_INFO == level ? "INFO"     : \
   +      (LOG_LEVEL_WARN == level ? "WARN"     : \
   +       (LOG_LEVEL_ERROR == level ? "ERROR"    : \
   +        (LOG_LEVEL_CRITICAL == level ? "CRITICAL" : \
   +         "UNKNOWN")))))
    
    /* XXX: These module IDs are defined for backwards compatibility.  Application
     * code should use the syscfg settings directly.  These defines will be removed
   ```
   
   </details>


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



[GitHub] [mynewt-nimble] sjanc commented on a change in pull request #878: Add support for NuttX

Posted by GitBox <gi...@apache.org>.
sjanc commented on a change in pull request #878:
URL: https://github.com/apache/mynewt-nimble/pull/878#discussion_r542349982



##########
File path: porting/nimble/include/log_common/log_common.h
##########
@@ -26,14 +26,116 @@
 extern "C" {
 #endif
 
+struct log;
+
+#define LOG_VERSION_V3  3
+
+#define LOG_TYPE_STREAM  (0)
+#define LOG_TYPE_MEMORY  (1)
+#define LOG_TYPE_STORAGE (2)
+
 #define LOG_LEVEL_DEBUG    (0)
 #define LOG_LEVEL_INFO     (1)
 #define LOG_LEVEL_WARN     (2)
 #define LOG_LEVEL_ERROR    (3)
 #define LOG_LEVEL_CRITICAL (4)
-/* Up to 7 custom log levels. */
+/* Up to 10 custom log levels. */
 #define LOG_LEVEL_MAX      (15)
 
+#define LOG_LEVEL_STR(level) \
+    (LOG_LEVEL_DEBUG    == level ? "DEBUG"    :\
+    (LOG_LEVEL_INFO     == level ? "INFO"     :\
+    (LOG_LEVEL_WARN     == level ? "WARN"     :\
+    (LOG_LEVEL_ERROR    == level ? "ERROR"    :\
+    (LOG_LEVEL_CRITICAL == level ? "CRITICAL" :\
+     "UNKNOWN")))))
+
+/* XXX: These module IDs are defined for backwards compatibility.  Application
+ * code should use the syscfg settings directly.  These defines will be removed
+ * in a future release.
+ */
+#define LOG_MODULE_DEFAULT          0
+#define LOG_MODULE_OS               1
+#define LOG_MODULE_NEWTMGR          2
+#define LOG_MODULE_NIMBLE_CTLR      3
+#define LOG_MODULE_NIMBLE_HOST      4
+#define LOG_MODULE_NFFS             5
+#define LOG_MODULE_REBOOT           6
+#define LOG_MODULE_IOTIVITY         7
+#define LOG_MODULE_TEST             8
+
+#define LOG_MODULE_PERUSER          64
+#define LOG_MODULE_MAX              (255)
+
+#define LOG_ETYPE_STRING         (0)
+#define LOG_ETYPE_CBOR           (1)
+#define LOG_ETYPE_BINARY         (2)
+
+/* UTC Timestamp for Jan 2016 00:00:00 */
+#define UTC01_01_2016    1451606400
+
+#define LOG_NAME_MAX_LEN    (64)
+
+#ifndef MYNEWT_VAL_LOG_LEVEL
+#define LOG_SYSLEVEL    ((uint8_t)LOG_LEVEL_MAX)
+#else
+#define LOG_SYSLEVEL    ((uint8_t)MYNEWT_VAL_LOG_LEVEL)
+#endif
+
+/**
+ * @brief Determines if a log module will accept an entry with a given level.
+ *
+ * A log entry is only accepted if its level is less than or equal to both:
+ *    o Global log level setting (LOG_LEVEL), and
+ *    o The specified module log level
+ *
+ * @param mod_level             The module's minimum log level.
+ * @param entry_level           The level of the entry to be logged.
+ *
+ * @return                      true if the entry would be logged;
+ *                              false otherwise.
+ */
+#define LOG_MOD_LEVEL_IS_ACTIVE(mod_level, entry_level) \
+    (LOG_LEVEL <= (entry_level) && (mod_level) <= (entry_level))
+
+/* Newtmgr Log opcodes */
+#define LOGS_NMGR_OP_READ               (0)
+#define LOGS_NMGR_OP_CLEAR              (1)
+#define LOGS_NMGR_OP_APPEND             (2)
+#define LOGS_NMGR_OP_MODULE_LIST        (3)
+#define LOGS_NMGR_OP_LEVEL_LIST         (4)
+#define LOGS_NMGR_OP_LOGS_LIST          (5)
+#define LOGS_NMGR_OP_SET_WATERMARK      (6)
+#define LOGS_NMGR_OP_MODLEVEL           (8)
+
+#define LOG_PRINTF_MAX_ENTRY_LEN (128)
+
+/* Global log info */
+struct log_info {
+#if MYNEWT_VAL(LOG_GLOBAL_IDX)
+    uint32_t li_next_index;
+#endif
+    uint8_t li_version;
+};
+
+extern struct log_info g_log_info;
+
+/** @typedef log_append_cb
+ * @brief Callback that is executed each time the corresponding log is appended
+ * to.
+ *
+ * @param log                   The log that was just appended to.
+ * @param idx                   The index of newly appended log entry.
+ */
+typedef void log_append_cb(struct log *log, uint32_t idx);

Review comment:
       I think we need to #include <stdint.h>  in this file, this should fix CI error for mesh sample




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



[GitHub] [mynewt-nimble] v01d commented on a change in pull request #878: Add support for NuttX

Posted by GitBox <gi...@apache.org>.
v01d commented on a change in pull request #878:
URL: https://github.com/apache/mynewt-nimble/pull/878#discussion_r537683161



##########
File path: nimble/transport/socket/src/ble_hci_socket.c
##########
@@ -205,6 +208,8 @@ static struct ble_hci_sock_state {
 static int s_ble_hci_device = MYNEWT_VAL(BLE_SOCK_TCP_PORT);
 #elif MYNEWT_VAL(BLE_SOCK_USE_LINUX_BLUE)
 static int s_ble_hci_device = MYNEWT_VAL(BLE_SOCK_LINUX_DEV);
+#elif MYNEWT_VAL(BLE_SOCK_USE_LINUX_BLUE) || MYNEWT_VAL(BLE_SOCK_USE_NUTTX)

Review comment:
       Right, fixed.




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



[GitHub] [mynewt-nimble] v01d commented on a change in pull request #878: Add support for NuttX

Posted by GitBox <gi...@apache.org>.
v01d commented on a change in pull request #878:
URL: https://github.com/apache/mynewt-nimble/pull/878#discussion_r543490513



##########
File path: porting/nimble/include/log/log.h
##########
@@ -30,11 +30,13 @@ log_dummy(void *log, ...)
     (void)log;
 }
 
+#if 0

Review comment:
       I think that would require an include to be present before defining LOG_DEBUG which may not always be the case. What about `#if MYNEWT`?




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



[GitHub] [mynewt-nimble] sjanc commented on a change in pull request #878: Add support for NuttX

Posted by GitBox <gi...@apache.org>.
sjanc commented on a change in pull request #878:
URL: https://github.com/apache/mynewt-nimble/pull/878#discussion_r537313324



##########
File path: porting/examples/nuttx/README.md
##########
@@ -0,0 +1,73 @@
+<!--
+#
+# 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.
+#
+-->
+
+# Apache Mynewt NimBLE
+
+## Overview
+
+See (https://mynewt.apache.org/network/ble/ble_intro/).
+
+## Building
+
+NimBLE is usually built as a part of Apache Mynewt OS, but ports for
+other RTOS-es are also available.
+
+### Linux

Review comment:
       this readme should be either updated to reflect nuttx env or removed

##########
File path: porting/examples/nuttx/include/syscfg.h
##########
@@ -0,0 +1,941 @@
+/**

Review comment:
       is this file needed? 

##########
File path: porting/nimble/include/log/log.h
##########
@@ -30,11 +30,13 @@ log_dummy(void *log, ...)
     (void)log;
 }
 
+#if 0

Review comment:
       why is this needed?

##########
File path: nimble/host/src/ble_hs_hci.c
##########
@@ -339,11 +339,13 @@ ble_hs_hci_cmd_tx(uint16_t opcode, const void *cmd, uint8_t cmd_len,
 static void
 ble_hs_hci_rx_ack(uint8_t *ack_ev)
 {
+#if 0
     if (ble_npl_sem_get_count(&ble_hs_hci_sem) > 0) {
         /* This ack is unexpected; ignore it. */
         ble_hci_trans_buf_free(ack_ev);
         return;
     }
+#endif

Review comment:
       could you comment on this a bit? it looks like this code was here since day 1

##########
File path: porting/targets/nuttx/pkg.yml
##########
@@ -0,0 +1,40 @@
+# 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.
+#
+
+pkg.name: "porting/targets/nuttx"
+pkg.type: "target"
+pkg.description: This target is used to generate syscfg.h file and other artifacts for linux example app.

Review comment:
       "for nuttx example app"




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



[GitHub] [mynewt-nimble] v01d commented on a change in pull request #878: Add support for NuttX

Posted by GitBox <gi...@apache.org>.
v01d commented on a change in pull request #878:
URL: https://github.com/apache/mynewt-nimble/pull/878#discussion_r537684217



##########
File path: nimble/transport/socket/src/ble_hci_socket.c
##########
@@ -281,6 +343,9 @@ ble_hci_sock_cmdevt_tx(uint8_t *hci_ev, uint8_t h4_type)
     memset(&msg, 0, sizeof(msg));
     memset(iov, 0, sizeof(iov));
 
+    msg.msg_name = (void *)btaddr;
+    msg.msg_namelen = 6;
+

Review comment:
       Right. I initially tried to use sendmsg() for NuttX but that is not implemented yet for Bluetooth sockets, this was leftover code. I just removed it.




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



[GitHub] [mynewt-nimble] v01d commented on a change in pull request #878: Add support for NuttX

Posted by GitBox <gi...@apache.org>.
v01d commented on a change in pull request #878:
URL: https://github.com/apache/mynewt-nimble/pull/878#discussion_r514496987



##########
File path: nimble/host/src/ble_hs_hci.c
##########
@@ -339,11 +339,13 @@ ble_hs_hci_cmd_tx(uint16_t opcode, const void *cmd, uint8_t cmd_len,
 static void
 ble_hs_hci_rx_ack(uint8_t *ack_ev)
 {
+#if 0
     if (ble_npl_sem_get_count(&ble_hs_hci_sem) > 0) {
         /* This ack is unexpected; ignore it. */
         ble_hci_trans_buf_free(ack_ev);
         return;
     }
+#endif

Review comment:
       This is ifdefed since it is a race condition




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



[GitHub] [mynewt-nimble] apache-mynewt-bot removed a comment on pull request #878: Add support for NuttX

Posted by GitBox <gi...@apache.org>.
apache-mynewt-bot removed a comment on pull request #878:
URL: https://github.com/apache/mynewt-nimble/pull/878#issuecomment-716242792


   
   <!-- style-bot -->
   
   ## Style check summary
   
   ### Our coding style is [here!](https://github.com/apache/mynewt-core/blob/master/CODING_STANDARDS.md)
   
   
   #### nimble/transport/socket/src/ble_hci_socket.c
   <details>
   
   ```diff
   @@ -54,17 +54,17 @@
    #if 0/*MYNEWT_VAL(BLE_SOCK_USE_LINUX_BLUE)*/
    #include <sys/errno.h>
    #define BTPROTO_HCI 1
   -#define HCI_CHANNEL_RAW		0
   -#define HCI_CHANNEL_USER	1
   -#define HCIDEVUP	_IOW('H', 201, int)
   -#define HCIDEVDOWN	_IOW('H', 202, int)
   -#define HCIDEVRESET	_IOW('H', 203, int)
   -#define HCIGETDEVLIST	_IOR('H', 210, int)
   +#define HCI_CHANNEL_RAW     0
   +#define HCI_CHANNEL_USER    1
   +#define HCIDEVUP    _IOW('H', 201, int)
   +#define HCIDEVDOWN  _IOW('H', 202, int)
   +#define HCIDEVRESET _IOW('H', 203, int)
   +#define HCIGETDEVLIST   _IOR('H', 210, int)
    
    struct sockaddr_hci {
   -        sa_family_t    hci_family;
   -        unsigned short hci_dev;
   -        unsigned short hci_channel;
   +    sa_family_t hci_family;
   +    unsigned short hci_dev;
   +    unsigned short hci_channel;
    };
    #endif
    
   @@ -276,54 +276,54 @@
        }
        return 0;
    #else
   -  size_t len;
   -  uint8_t* buf;
   -  int i;
   -  struct os_mbuf *m;
   -  struct sockaddr_hci addr;
   -
   -  addr.hci_family = AF_BLUETOOTH;
   -  addr.hci_channel = HCI_CHANNEL_RAW;
   -  addr.hci_dev = 0;
   -
   -  memcpy(&addr, &addr, sizeof(struct sockaddr_hci));
   -
   -  len = 1;
   -
   -  for (m = om; m; m = SLIST_NEXT(m, om_next)) {
   -      len += m->om_len;
   -  }
   -
   -  buf = (uint8_t*)malloc(len);
   -
   -  buf[0] = BLE_HCI_UART_H4_ACL;
   -
   -  i = 1;
   -  for (m = om; m; m = SLIST_NEXT(m, om_next)) {
   -      memcpy(&buf[i], m->om_data, m->om_len);
   -      i += m->om_len;
   -  }
   -
   -  STATS_INC(hci_sock_stats, omsg);
   -  STATS_INC(hci_sock_stats, oacl);
   -  STATS_INCN(hci_sock_stats, obytes, OS_MBUF_PKTLEN(om) + 1);
   -
   -  i = sendto(ble_hci_sock_state.sock, buf, len, 0,
   -             (struct sockaddr *)&addr, sizeof(struct sockaddr_hci));
   -
   -  free(buf);
   -
   -  os_mbuf_free_chain(om);
   -  if (i != OS_MBUF_PKTLEN(om) + 1) {
   -      if (i < 0) {
   -          dprintf(1, "sendto() failed : %d\n", errno);
   -      } else {
   -          dprintf(1, "sendto() partial write: %d\n", i);
   -      }
   -      STATS_INC(hci_sock_stats, oerr);
   -      return BLE_ERR_MEM_CAPACITY;
   -  }
   -  return 0;
   +    size_t len;
   +    uint8_t * buf;
   +    int i;
   +    struct os_mbuf *m;
   +    struct sockaddr_hci addr;
   +
   +    addr.hci_family = AF_BLUETOOTH;
   +    addr.hci_channel = HCI_CHANNEL_RAW;
   +    addr.hci_dev = 0;
   +
   +    memcpy(&addr, &addr, sizeof(struct sockaddr_hci));
   +
   +    len = 1;
   +
   +    for (m = om; m; m = SLIST_NEXT(m, om_next)) {
   +        len += m->om_len;
   +    }
   +
   +    buf = (uint8_t *)malloc(len);
   +
   +    buf[0] = BLE_HCI_UART_H4_ACL;
   +
   +    i = 1;
   +    for (m = om; m; m = SLIST_NEXT(m, om_next)) {
   +        memcpy(&buf[i], m->om_data, m->om_len);
   +        i += m->om_len;
   +    }
   +
   +    STATS_INC(hci_sock_stats, omsg);
   +    STATS_INC(hci_sock_stats, oacl);
   +    STATS_INCN(hci_sock_stats, obytes, OS_MBUF_PKTLEN(om) + 1);
   +
   +    i = sendto(ble_hci_sock_state.sock, buf, len, 0,
   +               (struct sockaddr *)&addr, sizeof(struct sockaddr_hci));
   +
   +    free(buf);
   +
   +    os_mbuf_free_chain(om);
   +    if (i != OS_MBUF_PKTLEN(om) + 1) {
   +        if (i < 0) {
   +            dprintf(1, "sendto() failed : %d\n", errno);
   +        } else {
   +            dprintf(1, "sendto() partial write: %d\n", i);
   +        }
   +        STATS_INC(hci_sock_stats, oerr);
   +        return BLE_ERR_MEM_CAPACITY;
   +    }
   +    return 0;
    #endif
    }
    
   @@ -341,7 +341,7 @@
        memset(&msg, 0, sizeof(msg));
        memset(iov, 0, sizeof(iov));
    
   -    msg.msg_name = (void*)btaddr;
   +    msg.msg_name = (void *)btaddr;
        msg.msg_namelen = 6;
    
        msg.msg_iov = iov;
   @@ -377,49 +377,49 @@
            return BLE_ERR_MEM_CAPACITY;
        }
    #else
   -  uint8_t* buf;
   -  size_t len;
   -  struct sockaddr_hci addr;
   -  int i;
   -
   -  addr.hci_family = AF_BLUETOOTH;
   -  addr.hci_channel = HCI_CHANNEL_RAW;
   -  addr.hci_dev = 0;
   -
   -  memcpy(&addr, &addr, sizeof(struct sockaddr_hci));
   -
   -  if (h4_type == BLE_HCI_UART_H4_CMD) {
   -      len = sizeof(struct ble_hci_cmd) + hci_ev[2];
   -      STATS_INC(hci_sock_stats, ocmd);
   -  } else if (h4_type == BLE_HCI_UART_H4_EVT) {
   -      len = sizeof(struct ble_hci_ev) + hci_ev[1];
   -      STATS_INC(hci_sock_stats, oevt);
   -  } else {
   -      assert(0);
   -  }
   -
   -  STATS_INC(hci_sock_stats, omsg);
   -  STATS_INCN(hci_sock_stats, obytes, len + 1);
   -
   -  buf = (uint8_t*)malloc(len + 1);
   -
   -  buf[0] = h4_type;
   -  memcpy(&buf[1], hci_ev, len);
   -
   -  i = sendto(ble_hci_sock_state.sock, buf, len + 1, 0,
   -             (struct sockaddr *)&addr, sizeof(struct sockaddr_hci));
   -
   -  free(buf);
   -  ble_hci_trans_buf_free(hci_ev);
   -  if (i != len + 1) {
   -      if (i < 0) {
   -          dprintf(1, "sendto() failed : %d\n", errno);
   -      } else {
   -          dprintf(1, "sendto() partial write: %d\n", i);
   -      }
   -      STATS_INC(hci_sock_stats, oerr);
   -      return BLE_ERR_MEM_CAPACITY;
   -  }
   +    uint8_t * buf;
   +    size_t len;
   +    struct sockaddr_hci addr;
   +    int i;
   +
   +    addr.hci_family = AF_BLUETOOTH;
   +    addr.hci_channel = HCI_CHANNEL_RAW;
   +    addr.hci_dev = 0;
   +
   +    memcpy(&addr, &addr, sizeof(struct sockaddr_hci));
   +
   +    if (h4_type == BLE_HCI_UART_H4_CMD) {
   +        len = sizeof(struct ble_hci_cmd) + hci_ev[2];
   +        STATS_INC(hci_sock_stats, ocmd);
   +    } else if (h4_type == BLE_HCI_UART_H4_EVT) {
   +        len = sizeof(struct ble_hci_ev) + hci_ev[1];
   +        STATS_INC(hci_sock_stats, oevt);
   +    } else {
   +        assert(0);
   +    }
   +
   +    STATS_INC(hci_sock_stats, omsg);
   +    STATS_INCN(hci_sock_stats, obytes, len + 1);
   +
   +    buf = (uint8_t *)malloc(len + 1);
   +
   +    buf[0] = h4_type;
   +    memcpy(&buf[1], hci_ev, len);
   +
   +    i = sendto(ble_hci_sock_state.sock, buf, len + 1, 0,
   +               (struct sockaddr *)&addr, sizeof(struct sockaddr_hci));
   +
   +    free(buf);
   +    ble_hci_trans_buf_free(hci_ev);
   +    if (i != len + 1) {
   +        if (i < 0) {
   +            dprintf(1, "sendto() failed : %d\n", errno);
   +        } else {
   +            dprintf(1, "sendto() partial write: %d\n", i);
   +        }
   +        STATS_INC(hci_sock_stats, oerr);
   +        return BLE_ERR_MEM_CAPACITY;
   +    }
    #endif
    
        return 0;
   @@ -441,7 +441,7 @@
        }
        len = read(bhss->sock, bhss->rx_data + bhss->rx_off,
                   sizeof(bhss->rx_data) - bhss->rx_off);
   -    //printf("off: %i read len: %i\n", bhss->rx_off, len);
   +    /*printf("off: %i read len: %i\n", bhss->rx_off, len); */
        if (len < 0) {
            return -2;
        }
   @@ -487,14 +487,14 @@
                }
                len = 1 + sizeof(struct ble_hci_ev) + bhss->rx_data[2];
                if (bhss->rx_off < len) {
   -                //printf("expected len %i, got only %i\n", len, bhss->rx_off);
   +                /*printf("expected len %i, got only %i\n", len, bhss->rx_off); */
                    return -1;
                }
                STATS_INC(hci_sock_stats, imsg);
                STATS_INC(hci_sock_stats, ievt);
                data = ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
                if (!data) {
   -                //printf("failed EVT\n");
   +                /*printf("failed EVT\n"); */
                    STATS_INC(hci_sock_stats, ierr);
                    break;
                }
   @@ -514,16 +514,16 @@
                    return -1;
                }
                len = 1 + BLE_HCI_DATA_HDR_SZ + (bhss->rx_data[4] << 8) +
   -              bhss->rx_data[3];
   +                  bhss->rx_data[3];
                if (bhss->rx_off < len) {
   -                //printf("expected len %i, got only %i\n", len, bhss->rx_off);
   +                /*printf("expected len %i, got only %i\n", len, bhss->rx_off); */
                    return -1;
                }
                STATS_INC(hci_sock_stats, imsg);
                STATS_INC(hci_sock_stats, iacl);
                m = ble_hci_trans_acl_buf_alloc();
                if (!m) {
   -                //printf("failed ACL\n");
   +                /*printf("failed ACL\n"); */
                    STATS_INC(hci_sock_stats, imem);
                    break;
                }
   ```
   
   </details>
   
   #### porting/nimble/include/log_common/log_common.h
   <details>
   
   ```diff
   @@ -43,12 +43,12 @@
    #define LOG_LEVEL_MAX      (15)
    
    #define LOG_LEVEL_STR(level) \
   -    (LOG_LEVEL_DEBUG    == level ? "DEBUG"    :\
   -    (LOG_LEVEL_INFO     == level ? "INFO"     :\
   -    (LOG_LEVEL_WARN     == level ? "WARN"     :\
   -    (LOG_LEVEL_ERROR    == level ? "ERROR"    :\
   -    (LOG_LEVEL_CRITICAL == level ? "CRITICAL" :\
   -     "UNKNOWN")))))
   +    (LOG_LEVEL_DEBUG == level ? "DEBUG"    : \
   +     (LOG_LEVEL_INFO == level ? "INFO"     : \
   +      (LOG_LEVEL_WARN == level ? "WARN"     : \
   +       (LOG_LEVEL_ERROR == level ? "ERROR"    : \
   +        (LOG_LEVEL_CRITICAL == level ? "CRITICAL" : \
   +         "UNKNOWN")))))
    
    /* XXX: These module IDs are defined for backwards compatibility.  Application
     * code should use the syscfg settings directly.  These defines will be removed
   @@ -131,8 +131,8 @@
    
    /** @typdef log_notify_rotate_cb
     * @brief Callback that is executed each time we are about to rotate a log.
   - * 
   - * @param log                   The log that is about to rotate 
   + *
   + * @param log                   The log that is about to rotate
     */
    typedef void log_notify_rotate_cb(const struct log *log);
    
   ```
   
   </details>


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



[GitHub] [mynewt-nimble] v01d commented on pull request #878: Add support for NuttX

Posted by GitBox <gi...@apache.org>.
v01d commented on pull request #878:
URL: https://github.com/apache/mynewt-nimble/pull/878#issuecomment-735470984


   Hi, sorry for insisting but is there a chance for this to be reviewed? I don't think it is really that different than the Linux case.
   I also would like to continue BLE work on NuttX using nimBLE and having this integrated upstream would really help.


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



[GitHub] [mynewt-nimble] v01d commented on pull request #878: Add support for NuttX

Posted by GitBox <gi...@apache.org>.
v01d commented on pull request #878:
URL: https://github.com/apache/mynewt-nimble/pull/878#issuecomment-728386430


   Hi @ccollins476ad @andrzej-kaczmarek any chance you could take a look at the PR and offer some feedback?


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



[GitHub] [mynewt-nimble] apache-mynewt-bot removed a comment on pull request #878: Add support for NuttX

Posted by GitBox <gi...@apache.org>.
apache-mynewt-bot removed a comment on pull request #878:
URL: https://github.com/apache/mynewt-nimble/pull/878#issuecomment-740097423


   
   <!-- style-bot -->
   
   ## Style check summary
   
   ### Our coding style is [here!](https://github.com/apache/mynewt-core/blob/master/CODING_STANDARDS.md)
   
   
   #### nimble/transport/socket/src/ble_hci_socket.c
   <details>
   
   ```diff
   @@ -54,7 +54,7 @@
    #if MYNEWT_VAL(BLE_SOCK_USE_LINUX_BLUE)
    #include <sys/errno.h>
    #define BTPROTO_HCI       1
   -#define HCI_CHANNEL_RAW	  0
   +#define HCI_CHANNEL_RAW   0
    #define HCI_CHANNEL_USER  1
    #define HCIDEVUP          _IOW('H', 201, int)
    #define HCIDEVDOWN        _IOW('H', 202, int)
   ```
   
   </details>
   
   #### porting/nimble/include/log_common/log_common.h
   <details>
   
   ```diff
   @@ -43,12 +43,12 @@
    #define LOG_LEVEL_MAX      (15)
    
    #define LOG_LEVEL_STR(level) \
   -    (LOG_LEVEL_DEBUG    == level ? "DEBUG"    :\
   -    (LOG_LEVEL_INFO     == level ? "INFO"     :\
   -    (LOG_LEVEL_WARN     == level ? "WARN"     :\
   -    (LOG_LEVEL_ERROR    == level ? "ERROR"    :\
   -    (LOG_LEVEL_CRITICAL == level ? "CRITICAL" :\
   -     "UNKNOWN")))))
   +    (LOG_LEVEL_DEBUG == level ? "DEBUG"    : \
   +     (LOG_LEVEL_INFO == level ? "INFO"     : \
   +      (LOG_LEVEL_WARN == level ? "WARN"     : \
   +       (LOG_LEVEL_ERROR == level ? "ERROR"    : \
   +        (LOG_LEVEL_CRITICAL == level ? "CRITICAL" : \
   +         "UNKNOWN")))))
    
    /* XXX: These module IDs are defined for backwards compatibility.  Application
     * code should use the syscfg settings directly.  These defines will be removed
   ```
   
   </details>


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



[GitHub] [mynewt-nimble] apache-mynewt-bot commented on pull request #878: Add support for NuttX

Posted by GitBox <gi...@apache.org>.
apache-mynewt-bot commented on pull request #878:
URL: https://github.com/apache/mynewt-nimble/pull/878#issuecomment-719001812


   
   <!-- style-bot -->
   
   ## Style check summary
   
   ### Our coding style is [here!](https://github.com/apache/mynewt-core/blob/master/CODING_STANDARDS.md)
   
   
   #### nimble/transport/socket/src/ble_hci_socket.c
   <details>
   
   ```diff
   @@ -54,15 +54,15 @@
    #if MYNEWT_VAL(BLE_SOCK_USE_LINUX_BLUE)
    #include <sys/errno.h>
    #define BTPROTO_HCI       1
   -#define HCI_CHANNEL_RAW		0
   -#define HCI_CHANNEL_USER	1
   +#define HCI_CHANNEL_RAW     0
   +#define HCI_CHANNEL_USER    1
    #define HCIDEVUP          _IOW('H', 201, int)
    #define HCIDEVDOWN        _IOW('H', 202, int)
    #define HCIDEVRESET       _IOW('H', 203, int)
    #define HCIGETDEVLIST     _IOR('H', 210, int)
    
    struct sockaddr_hci {
   -    sa_family_t    hci_family;
   +    sa_family_t hci_family;
        unsigned short hci_dev;
        unsigned short hci_channel;
    };
   @@ -279,7 +279,7 @@
    ble_hci_sock_acl_tx(struct os_mbuf *om)
    {
        size_t len;
   -    uint8_t* buf;
   +    uint8_t * buf;
        int i;
        struct os_mbuf *m;
        struct sockaddr_hci addr;
   @@ -296,7 +296,7 @@
            len += m->om_len;
        }
    
   -    buf = (uint8_t*)malloc(len);
   +    buf = (uint8_t *)malloc(len);
    
        buf[0] = BLE_HCI_UART_H4_ACL;
    
   @@ -385,7 +385,7 @@
    static int
    ble_hci_sock_cmdevt_tx(uint8_t *hci_ev, uint8_t h4_type)
    {
   -    uint8_t* buf;
   +    uint8_t * buf;
        size_t len;
        struct sockaddr_hci addr;
        int i;
   @@ -409,7 +409,7 @@
        STATS_INC(hci_sock_stats, omsg);
        STATS_INCN(hci_sock_stats, obytes, len + 1);
    
   -    buf = (uint8_t*)malloc(len + 1);
   +    buf = (uint8_t *)malloc(len + 1);
    
        buf[0] = h4_type;
        memcpy(&buf[1], hci_ev, len);
   ```
   
   </details>
   
   #### porting/nimble/include/log_common/log_common.h
   <details>
   
   ```diff
   @@ -43,12 +43,12 @@
    #define LOG_LEVEL_MAX      (15)
    
    #define LOG_LEVEL_STR(level) \
   -    (LOG_LEVEL_DEBUG    == level ? "DEBUG"    :\
   -    (LOG_LEVEL_INFO     == level ? "INFO"     :\
   -    (LOG_LEVEL_WARN     == level ? "WARN"     :\
   -    (LOG_LEVEL_ERROR    == level ? "ERROR"    :\
   -    (LOG_LEVEL_CRITICAL == level ? "CRITICAL" :\
   -     "UNKNOWN")))))
   +    (LOG_LEVEL_DEBUG == level ? "DEBUG"    : \
   +     (LOG_LEVEL_INFO == level ? "INFO"     : \
   +      (LOG_LEVEL_WARN == level ? "WARN"     : \
   +       (LOG_LEVEL_ERROR == level ? "ERROR"    : \
   +        (LOG_LEVEL_CRITICAL == level ? "CRITICAL" : \
   +         "UNKNOWN")))))
    
    /* XXX: These module IDs are defined for backwards compatibility.  Application
     * code should use the syscfg settings directly.  These defines will be removed
   @@ -131,8 +131,8 @@
    
    /** @typdef log_notify_rotate_cb
     * @brief Callback that is executed each time we are about to rotate a log.
   - * 
   - * @param log                   The log that is about to rotate 
   + *
   + * @param log                   The log that is about to rotate
     */
    typedef void log_notify_rotate_cb(const struct log *log);
    
   ```
   
   </details>


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



[GitHub] [mynewt-nimble] v01d commented on a change in pull request #878: Add support for NuttX

Posted by GitBox <gi...@apache.org>.
v01d commented on a change in pull request #878:
URL: https://github.com/apache/mynewt-nimble/pull/878#discussion_r537691245



##########
File path: porting/npl/nuttx/src/os_callout.c
##########
@@ -0,0 +1,159 @@
+/*
+ * 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.
+ */
+
+#include <nuttx/config.h>
+#include <assert.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
+
+#include <time.h>
+#include <signal.h>
+
+#include "nimble/nimble_npl.h"
+
+static void
+ble_npl_callout_timer_cb(union sigval sv)
+{
+    struct ble_npl_callout *c = (struct ble_npl_callout *)sv.sival_ptr;
+    assert(c);
+
+    if (c->c_evq) {
+        ble_npl_eventq_put(c->c_evq, &c->c_ev);
+    } else {
+        c->c_ev.ev_cb(&c->c_ev);
+    }
+}
+
+void ble_npl_callout_init(struct ble_npl_callout *c, 
+                          struct ble_npl_eventq *evq,
+                          ble_npl_event_fn *ev_cb, 
+                          void *ev_arg)
+{
+    struct sigevent         event;
+
+    /* Initialize the callout. */
+    memset(c, 0, sizeof(*c));
+    c->c_ev.ev_cb = ev_cb;
+    c->c_ev.ev_arg = ev_arg;
+    c->c_evq = evq;
+    c->c_active = false;
+
+    event.sigev_notify = SIGEV_THREAD;
+    event.sigev_value.sival_ptr = c;     // put callout obj in signal args
+    event.sigev_notify_function = ble_npl_callout_timer_cb;
+    event.sigev_notify_attributes = NULL;
+
+    timer_create(CLOCK_REALTIME, &event, &c->c_timer);
+}
+
+bool ble_npl_callout_is_active(struct ble_npl_callout *c)
+{
+    // TODO: seek native posix method to determine whether timer_t is active.
+    // TODO: fix bug where one-shot timer is still active after fired.
+    return c->c_active;
+}
+
+int ble_npl_callout_inited(struct ble_npl_callout *c)
+{
+    return (c->c_timer != NULL);
+}
+
+ble_npl_error_t ble_npl_callout_reset(struct ble_npl_callout *c,
+				      ble_npl_time_t ticks)

Review comment:
       ok, I fixed coding style, let me know if you find other issues




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



[GitHub] [mynewt-nimble] v01d commented on a change in pull request #878: Add support for NuttX

Posted by GitBox <gi...@apache.org>.
v01d commented on a change in pull request #878:
URL: https://github.com/apache/mynewt-nimble/pull/878#discussion_r541045887



##########
File path: porting/nimble/include/log/log.h
##########
@@ -30,11 +30,13 @@ log_dummy(void *log, ...)
     (void)log;
 }
 
+#if 0

Review comment:
       Any suggestion on what to do about it? I think it is the only remaining issue in the PR




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



[GitHub] [mynewt-nimble] v01d commented on a change in pull request #878: Add support for NuttX

Posted by GitBox <gi...@apache.org>.
v01d commented on a change in pull request #878:
URL: https://github.com/apache/mynewt-nimble/pull/878#discussion_r537682494



##########
File path: nimble/host/src/ble_hs_hci.c
##########
@@ -339,11 +339,13 @@ ble_hs_hci_cmd_tx(uint16_t opcode, const void *cmd, uint8_t cmd_len,
 static void
 ble_hs_hci_rx_ack(uint8_t *ack_ev)
 {
+#if 0
     if (ble_npl_sem_get_count(&ble_hs_hci_sem) > 0) {
         /* This ack is unexpected; ignore it. */
         ble_hci_trans_buf_free(ack_ev);
         return;
     }
+#endif

Review comment:
       I found that this check would return true unexpectedly and it would not get to the release. It seemed to be a race condition due to the fact that the this function would get called too fast under certain conditions. I think the sequence was that the lock was actually set after the if check.




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



[GitHub] [mynewt-nimble] andrzej-kaczmarek commented on a change in pull request #878: Add support for NuttX

Posted by GitBox <gi...@apache.org>.
andrzej-kaczmarek commented on a change in pull request #878:
URL: https://github.com/apache/mynewt-nimble/pull/878#discussion_r544543001



##########
File path: porting/nimble/include/log/log.h
##########
@@ -30,11 +30,13 @@ log_dummy(void *log, ...)
     (void)log;
 }
 
+#if 0

Review comment:
       I think `#if MYNEWT` is ok for now, we'll need to resolve this anyway in some other way as @sjanc proposed




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



[GitHub] [mynewt-nimble] v01d commented on a change in pull request #878: Add support for NuttX

Posted by GitBox <gi...@apache.org>.
v01d commented on a change in pull request #878:
URL: https://github.com/apache/mynewt-nimble/pull/878#discussion_r543491224



##########
File path: porting/nimble/include/log_common/log_common.h
##########
@@ -26,14 +26,116 @@
 extern "C" {
 #endif
 
+struct log;
+
+#define LOG_VERSION_V3  3
+
+#define LOG_TYPE_STREAM  (0)
+#define LOG_TYPE_MEMORY  (1)
+#define LOG_TYPE_STORAGE (2)
+
 #define LOG_LEVEL_DEBUG    (0)
 #define LOG_LEVEL_INFO     (1)
 #define LOG_LEVEL_WARN     (2)
 #define LOG_LEVEL_ERROR    (3)
 #define LOG_LEVEL_CRITICAL (4)
-/* Up to 7 custom log levels. */
+/* Up to 10 custom log levels. */
 #define LOG_LEVEL_MAX      (15)
 
+#define LOG_LEVEL_STR(level) \
+    (LOG_LEVEL_DEBUG    == level ? "DEBUG"    :\
+    (LOG_LEVEL_INFO     == level ? "INFO"     :\
+    (LOG_LEVEL_WARN     == level ? "WARN"     :\
+    (LOG_LEVEL_ERROR    == level ? "ERROR"    :\
+    (LOG_LEVEL_CRITICAL == level ? "CRITICAL" :\
+     "UNKNOWN")))))
+
+/* XXX: These module IDs are defined for backwards compatibility.  Application
+ * code should use the syscfg settings directly.  These defines will be removed
+ * in a future release.
+ */
+#define LOG_MODULE_DEFAULT          0
+#define LOG_MODULE_OS               1
+#define LOG_MODULE_NEWTMGR          2
+#define LOG_MODULE_NIMBLE_CTLR      3
+#define LOG_MODULE_NIMBLE_HOST      4
+#define LOG_MODULE_NFFS             5
+#define LOG_MODULE_REBOOT           6
+#define LOG_MODULE_IOTIVITY         7
+#define LOG_MODULE_TEST             8
+
+#define LOG_MODULE_PERUSER          64
+#define LOG_MODULE_MAX              (255)
+
+#define LOG_ETYPE_STRING         (0)
+#define LOG_ETYPE_CBOR           (1)
+#define LOG_ETYPE_BINARY         (2)
+
+/* UTC Timestamp for Jan 2016 00:00:00 */
+#define UTC01_01_2016    1451606400
+
+#define LOG_NAME_MAX_LEN    (64)
+
+#ifndef MYNEWT_VAL_LOG_LEVEL
+#define LOG_SYSLEVEL    ((uint8_t)LOG_LEVEL_MAX)
+#else
+#define LOG_SYSLEVEL    ((uint8_t)MYNEWT_VAL_LOG_LEVEL)
+#endif
+
+/**
+ * @brief Determines if a log module will accept an entry with a given level.
+ *
+ * A log entry is only accepted if its level is less than or equal to both:
+ *    o Global log level setting (LOG_LEVEL), and
+ *    o The specified module log level
+ *
+ * @param mod_level             The module's minimum log level.
+ * @param entry_level           The level of the entry to be logged.
+ *
+ * @return                      true if the entry would be logged;
+ *                              false otherwise.
+ */
+#define LOG_MOD_LEVEL_IS_ACTIVE(mod_level, entry_level) \
+    (LOG_LEVEL <= (entry_level) && (mod_level) <= (entry_level))
+
+/* Newtmgr Log opcodes */
+#define LOGS_NMGR_OP_READ               (0)
+#define LOGS_NMGR_OP_CLEAR              (1)
+#define LOGS_NMGR_OP_APPEND             (2)
+#define LOGS_NMGR_OP_MODULE_LIST        (3)
+#define LOGS_NMGR_OP_LEVEL_LIST         (4)
+#define LOGS_NMGR_OP_LOGS_LIST          (5)
+#define LOGS_NMGR_OP_SET_WATERMARK      (6)
+#define LOGS_NMGR_OP_MODLEVEL           (8)
+
+#define LOG_PRINTF_MAX_ENTRY_LEN (128)
+
+/* Global log info */
+struct log_info {
+#if MYNEWT_VAL(LOG_GLOBAL_IDX)
+    uint32_t li_next_index;
+#endif
+    uint8_t li_version;
+};
+
+extern struct log_info g_log_info;
+
+/** @typedef log_append_cb
+ * @brief Callback that is executed each time the corresponding log is appended
+ * to.
+ *
+ * @param log                   The log that was just appended to.
+ * @param idx                   The index of newly appended log entry.
+ */
+typedef void log_append_cb(struct log *log, uint32_t idx);

Review comment:
       Ok, I'll add the include




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



[GitHub] [mynewt-nimble] v01d commented on a change in pull request #878: Add support for NuttX

Posted by GitBox <gi...@apache.org>.
v01d commented on a change in pull request #878:
URL: https://github.com/apache/mynewt-nimble/pull/878#discussion_r514504977



##########
File path: nimble/host/services/bas/include/services/bas/ble_svc_bas.h
##########
@@ -28,4 +28,6 @@
 
 int ble_svc_bas_battery_level_set(uint8_t level);
 
+void ble_svc_bas_init(void);

Review comment:
       This declaration was missing




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



[GitHub] [mynewt-nimble] apache-mynewt-bot removed a comment on pull request #878: Add support for NuttX

Posted by GitBox <gi...@apache.org>.
apache-mynewt-bot removed a comment on pull request #878:
URL: https://github.com/apache/mynewt-nimble/pull/878#issuecomment-719946791


   
   <!-- style-bot -->
   
   ## Style check summary
   
   ### Our coding style is [here!](https://github.com/apache/mynewt-core/blob/master/CODING_STANDARDS.md)
   
   
   #### nimble/transport/socket/src/ble_hci_socket.c
   <details>
   
   ```diff
   @@ -54,7 +54,7 @@
    #if MYNEWT_VAL(BLE_SOCK_USE_LINUX_BLUE)
    #include <sys/errno.h>
    #define BTPROTO_HCI       1
   -#define HCI_CHANNEL_RAW	  0
   +#define HCI_CHANNEL_RAW   0
    #define HCI_CHANNEL_USER  1
    #define HCIDEVUP          _IOW('H', 201, int)
    #define HCIDEVDOWN        _IOW('H', 202, int)
   ```
   
   </details>
   
   #### porting/nimble/include/log_common/log_common.h
   <details>
   
   ```diff
   @@ -43,12 +43,12 @@
    #define LOG_LEVEL_MAX      (15)
    
    #define LOG_LEVEL_STR(level) \
   -    (LOG_LEVEL_DEBUG    == level ? "DEBUG"    :\
   -    (LOG_LEVEL_INFO     == level ? "INFO"     :\
   -    (LOG_LEVEL_WARN     == level ? "WARN"     :\
   -    (LOG_LEVEL_ERROR    == level ? "ERROR"    :\
   -    (LOG_LEVEL_CRITICAL == level ? "CRITICAL" :\
   -     "UNKNOWN")))))
   +    (LOG_LEVEL_DEBUG == level ? "DEBUG"    : \
   +     (LOG_LEVEL_INFO == level ? "INFO"     : \
   +      (LOG_LEVEL_WARN == level ? "WARN"     : \
   +       (LOG_LEVEL_ERROR == level ? "ERROR"    : \
   +        (LOG_LEVEL_CRITICAL == level ? "CRITICAL" : \
   +         "UNKNOWN")))))
    
    /* XXX: These module IDs are defined for backwards compatibility.  Application
     * code should use the syscfg settings directly.  These defines will be removed
   ```
   
   </details>


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



[GitHub] [mynewt-nimble] v01d commented on a change in pull request #878: Add support for NuttX

Posted by GitBox <gi...@apache.org>.
v01d commented on a change in pull request #878:
URL: https://github.com/apache/mynewt-nimble/pull/878#discussion_r537691929



##########
File path: porting/npl/nuttx/src/os_callout.c
##########
@@ -0,0 +1,159 @@
+/*
+ * 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.
+ */
+
+#include <nuttx/config.h>
+#include <assert.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
+
+#include <time.h>
+#include <signal.h>
+
+#include "nimble/nimble_npl.h"
+
+static void
+ble_npl_callout_timer_cb(union sigval sv)
+{
+    struct ble_npl_callout *c = (struct ble_npl_callout *)sv.sival_ptr;
+    assert(c);
+
+    if (c->c_evq) {
+        ble_npl_eventq_put(c->c_evq, &c->c_ev);
+    } else {
+        c->c_ev.ev_cb(&c->c_ev);
+    }
+}
+
+void ble_npl_callout_init(struct ble_npl_callout *c, 
+                          struct ble_npl_eventq *evq,
+                          ble_npl_event_fn *ev_cb, 
+                          void *ev_arg)
+{
+    struct sigevent         event;
+
+    /* Initialize the callout. */
+    memset(c, 0, sizeof(*c));
+    c->c_ev.ev_cb = ev_cb;
+    c->c_ev.ev_arg = ev_arg;
+    c->c_evq = evq;
+    c->c_active = false;
+
+    event.sigev_notify = SIGEV_THREAD;
+    event.sigev_value.sival_ptr = c;     // put callout obj in signal args
+    event.sigev_notify_function = ble_npl_callout_timer_cb;
+    event.sigev_notify_attributes = NULL;
+
+    timer_create(CLOCK_REALTIME, &event, &c->c_timer);
+}
+
+bool ble_npl_callout_is_active(struct ble_npl_callout *c)
+{
+    // TODO: seek native posix method to determine whether timer_t is active.
+    // TODO: fix bug where one-shot timer is still active after fired.
+    return c->c_active;
+}
+
+int ble_npl_callout_inited(struct ble_npl_callout *c)
+{
+    return (c->c_timer != NULL);
+}
+
+ble_npl_error_t ble_npl_callout_reset(struct ble_npl_callout *c,
+				      ble_npl_time_t ticks)
+{
+    struct itimerspec       its;
+
+    if (ticks < 0) {
+        return BLE_NPL_EINVAL;
+    }
+
+    if (ticks == 0) {
+        ticks = 1;
+    }
+
+    c->c_ticks = ble_npl_time_get() + ticks;
+
+    its.it_interval.tv_sec = 0;
+    its.it_interval.tv_nsec = 0;                     // one shot

Review comment:
       done




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



[GitHub] [mynewt-nimble] v01d commented on a change in pull request #878: Add support for NuttX

Posted by GitBox <gi...@apache.org>.
v01d commented on a change in pull request #878:
URL: https://github.com/apache/mynewt-nimble/pull/878#discussion_r537686505



##########
File path: porting/targets/nuttx/pkg.yml
##########
@@ -0,0 +1,40 @@
+# 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.
+#
+
+pkg.name: "porting/targets/nuttx"
+pkg.type: "target"
+pkg.description: This target is used to generate syscfg.h file and other artifacts for linux example app.

Review comment:
       Fixed




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



[GitHub] [mynewt-nimble] andrzej-kaczmarek merged pull request #878: Add support for NuttX

Posted by GitBox <gi...@apache.org>.
andrzej-kaczmarek merged pull request #878:
URL: https://github.com/apache/mynewt-nimble/pull/878


   


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



[GitHub] [mynewt-nimble] v01d commented on pull request #878: Add support for NuttX

Posted by GitBox <gi...@apache.org>.
v01d commented on pull request #878:
URL: https://github.com/apache/mynewt-nimble/pull/878#issuecomment-746968583


   It seems last few changes made CI happy. I think those were all requested changes. Do you think it is OK to merge?


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



[GitHub] [mynewt-nimble] apache-mynewt-bot commented on pull request #878: Add support for NuttX

Posted by GitBox <gi...@apache.org>.
apache-mynewt-bot commented on pull request #878:
URL: https://github.com/apache/mynewt-nimble/pull/878#issuecomment-716242792


   
   <!-- style-bot -->
   
   ## Style check summary
   
   ### Our coding style is [here!](https://github.com/apache/mynewt-core/blob/master/CODING_STANDARDS.md)
   
   
   #### nimble/transport/socket/src/ble_hci_socket.c
   <details>
   
   ```diff
   @@ -54,17 +54,17 @@
    #if 0/*MYNEWT_VAL(BLE_SOCK_USE_LINUX_BLUE)*/
    #include <sys/errno.h>
    #define BTPROTO_HCI 1
   -#define HCI_CHANNEL_RAW		0
   -#define HCI_CHANNEL_USER	1
   -#define HCIDEVUP	_IOW('H', 201, int)
   -#define HCIDEVDOWN	_IOW('H', 202, int)
   -#define HCIDEVRESET	_IOW('H', 203, int)
   -#define HCIGETDEVLIST	_IOR('H', 210, int)
   +#define HCI_CHANNEL_RAW     0
   +#define HCI_CHANNEL_USER    1
   +#define HCIDEVUP    _IOW('H', 201, int)
   +#define HCIDEVDOWN  _IOW('H', 202, int)
   +#define HCIDEVRESET _IOW('H', 203, int)
   +#define HCIGETDEVLIST   _IOR('H', 210, int)
    
    struct sockaddr_hci {
   -        sa_family_t    hci_family;
   -        unsigned short hci_dev;
   -        unsigned short hci_channel;
   +    sa_family_t hci_family;
   +    unsigned short hci_dev;
   +    unsigned short hci_channel;
    };
    #endif
    
   @@ -276,54 +276,54 @@
        }
        return 0;
    #else
   -  size_t len;
   -  uint8_t* buf;
   -  int i;
   -  struct os_mbuf *m;
   -  struct sockaddr_hci addr;
   -
   -  addr.hci_family = AF_BLUETOOTH;
   -  addr.hci_channel = HCI_CHANNEL_RAW;
   -  addr.hci_dev = 0;
   -
   -  memcpy(&addr, &addr, sizeof(struct sockaddr_hci));
   -
   -  len = 1;
   -
   -  for (m = om; m; m = SLIST_NEXT(m, om_next)) {
   -      len += m->om_len;
   -  }
   -
   -  buf = (uint8_t*)malloc(len);
   -
   -  buf[0] = BLE_HCI_UART_H4_ACL;
   -
   -  i = 1;
   -  for (m = om; m; m = SLIST_NEXT(m, om_next)) {
   -      memcpy(&buf[i], m->om_data, m->om_len);
   -      i += m->om_len;
   -  }
   -
   -  STATS_INC(hci_sock_stats, omsg);
   -  STATS_INC(hci_sock_stats, oacl);
   -  STATS_INCN(hci_sock_stats, obytes, OS_MBUF_PKTLEN(om) + 1);
   -
   -  i = sendto(ble_hci_sock_state.sock, buf, len, 0,
   -             (struct sockaddr *)&addr, sizeof(struct sockaddr_hci));
   -
   -  free(buf);
   -
   -  os_mbuf_free_chain(om);
   -  if (i != OS_MBUF_PKTLEN(om) + 1) {
   -      if (i < 0) {
   -          dprintf(1, "sendto() failed : %d\n", errno);
   -      } else {
   -          dprintf(1, "sendto() partial write: %d\n", i);
   -      }
   -      STATS_INC(hci_sock_stats, oerr);
   -      return BLE_ERR_MEM_CAPACITY;
   -  }
   -  return 0;
   +    size_t len;
   +    uint8_t * buf;
   +    int i;
   +    struct os_mbuf *m;
   +    struct sockaddr_hci addr;
   +
   +    addr.hci_family = AF_BLUETOOTH;
   +    addr.hci_channel = HCI_CHANNEL_RAW;
   +    addr.hci_dev = 0;
   +
   +    memcpy(&addr, &addr, sizeof(struct sockaddr_hci));
   +
   +    len = 1;
   +
   +    for (m = om; m; m = SLIST_NEXT(m, om_next)) {
   +        len += m->om_len;
   +    }
   +
   +    buf = (uint8_t *)malloc(len);
   +
   +    buf[0] = BLE_HCI_UART_H4_ACL;
   +
   +    i = 1;
   +    for (m = om; m; m = SLIST_NEXT(m, om_next)) {
   +        memcpy(&buf[i], m->om_data, m->om_len);
   +        i += m->om_len;
   +    }
   +
   +    STATS_INC(hci_sock_stats, omsg);
   +    STATS_INC(hci_sock_stats, oacl);
   +    STATS_INCN(hci_sock_stats, obytes, OS_MBUF_PKTLEN(om) + 1);
   +
   +    i = sendto(ble_hci_sock_state.sock, buf, len, 0,
   +               (struct sockaddr *)&addr, sizeof(struct sockaddr_hci));
   +
   +    free(buf);
   +
   +    os_mbuf_free_chain(om);
   +    if (i != OS_MBUF_PKTLEN(om) + 1) {
   +        if (i < 0) {
   +            dprintf(1, "sendto() failed : %d\n", errno);
   +        } else {
   +            dprintf(1, "sendto() partial write: %d\n", i);
   +        }
   +        STATS_INC(hci_sock_stats, oerr);
   +        return BLE_ERR_MEM_CAPACITY;
   +    }
   +    return 0;
    #endif
    }
    
   @@ -341,7 +341,7 @@
        memset(&msg, 0, sizeof(msg));
        memset(iov, 0, sizeof(iov));
    
   -    msg.msg_name = (void*)btaddr;
   +    msg.msg_name = (void *)btaddr;
        msg.msg_namelen = 6;
    
        msg.msg_iov = iov;
   @@ -377,49 +377,49 @@
            return BLE_ERR_MEM_CAPACITY;
        }
    #else
   -  uint8_t* buf;
   -  size_t len;
   -  struct sockaddr_hci addr;
   -  int i;
   -
   -  addr.hci_family = AF_BLUETOOTH;
   -  addr.hci_channel = HCI_CHANNEL_RAW;
   -  addr.hci_dev = 0;
   -
   -  memcpy(&addr, &addr, sizeof(struct sockaddr_hci));
   -
   -  if (h4_type == BLE_HCI_UART_H4_CMD) {
   -      len = sizeof(struct ble_hci_cmd) + hci_ev[2];
   -      STATS_INC(hci_sock_stats, ocmd);
   -  } else if (h4_type == BLE_HCI_UART_H4_EVT) {
   -      len = sizeof(struct ble_hci_ev) + hci_ev[1];
   -      STATS_INC(hci_sock_stats, oevt);
   -  } else {
   -      assert(0);
   -  }
   -
   -  STATS_INC(hci_sock_stats, omsg);
   -  STATS_INCN(hci_sock_stats, obytes, len + 1);
   -
   -  buf = (uint8_t*)malloc(len + 1);
   -
   -  buf[0] = h4_type;
   -  memcpy(&buf[1], hci_ev, len);
   -
   -  i = sendto(ble_hci_sock_state.sock, buf, len + 1, 0,
   -             (struct sockaddr *)&addr, sizeof(struct sockaddr_hci));
   -
   -  free(buf);
   -  ble_hci_trans_buf_free(hci_ev);
   -  if (i != len + 1) {
   -      if (i < 0) {
   -          dprintf(1, "sendto() failed : %d\n", errno);
   -      } else {
   -          dprintf(1, "sendto() partial write: %d\n", i);
   -      }
   -      STATS_INC(hci_sock_stats, oerr);
   -      return BLE_ERR_MEM_CAPACITY;
   -  }
   +    uint8_t * buf;
   +    size_t len;
   +    struct sockaddr_hci addr;
   +    int i;
   +
   +    addr.hci_family = AF_BLUETOOTH;
   +    addr.hci_channel = HCI_CHANNEL_RAW;
   +    addr.hci_dev = 0;
   +
   +    memcpy(&addr, &addr, sizeof(struct sockaddr_hci));
   +
   +    if (h4_type == BLE_HCI_UART_H4_CMD) {
   +        len = sizeof(struct ble_hci_cmd) + hci_ev[2];
   +        STATS_INC(hci_sock_stats, ocmd);
   +    } else if (h4_type == BLE_HCI_UART_H4_EVT) {
   +        len = sizeof(struct ble_hci_ev) + hci_ev[1];
   +        STATS_INC(hci_sock_stats, oevt);
   +    } else {
   +        assert(0);
   +    }
   +
   +    STATS_INC(hci_sock_stats, omsg);
   +    STATS_INCN(hci_sock_stats, obytes, len + 1);
   +
   +    buf = (uint8_t *)malloc(len + 1);
   +
   +    buf[0] = h4_type;
   +    memcpy(&buf[1], hci_ev, len);
   +
   +    i = sendto(ble_hci_sock_state.sock, buf, len + 1, 0,
   +               (struct sockaddr *)&addr, sizeof(struct sockaddr_hci));
   +
   +    free(buf);
   +    ble_hci_trans_buf_free(hci_ev);
   +    if (i != len + 1) {
   +        if (i < 0) {
   +            dprintf(1, "sendto() failed : %d\n", errno);
   +        } else {
   +            dprintf(1, "sendto() partial write: %d\n", i);
   +        }
   +        STATS_INC(hci_sock_stats, oerr);
   +        return BLE_ERR_MEM_CAPACITY;
   +    }
    #endif
    
        return 0;
   @@ -441,7 +441,7 @@
        }
        len = read(bhss->sock, bhss->rx_data + bhss->rx_off,
                   sizeof(bhss->rx_data) - bhss->rx_off);
   -    //printf("off: %i read len: %i\n", bhss->rx_off, len);
   +    /*printf("off: %i read len: %i\n", bhss->rx_off, len); */
        if (len < 0) {
            return -2;
        }
   @@ -487,14 +487,14 @@
                }
                len = 1 + sizeof(struct ble_hci_ev) + bhss->rx_data[2];
                if (bhss->rx_off < len) {
   -                //printf("expected len %i, got only %i\n", len, bhss->rx_off);
   +                /*printf("expected len %i, got only %i\n", len, bhss->rx_off); */
                    return -1;
                }
                STATS_INC(hci_sock_stats, imsg);
                STATS_INC(hci_sock_stats, ievt);
                data = ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
                if (!data) {
   -                //printf("failed EVT\n");
   +                /*printf("failed EVT\n"); */
                    STATS_INC(hci_sock_stats, ierr);
                    break;
                }
   @@ -514,16 +514,16 @@
                    return -1;
                }
                len = 1 + BLE_HCI_DATA_HDR_SZ + (bhss->rx_data[4] << 8) +
   -              bhss->rx_data[3];
   +                  bhss->rx_data[3];
                if (bhss->rx_off < len) {
   -                //printf("expected len %i, got only %i\n", len, bhss->rx_off);
   +                /*printf("expected len %i, got only %i\n", len, bhss->rx_off); */
                    return -1;
                }
                STATS_INC(hci_sock_stats, imsg);
                STATS_INC(hci_sock_stats, iacl);
                m = ble_hci_trans_acl_buf_alloc();
                if (!m) {
   -                //printf("failed ACL\n");
   +                /*printf("failed ACL\n"); */
                    STATS_INC(hci_sock_stats, imem);
                    break;
                }
   ```
   
   </details>
   
   #### porting/nimble/include/log_common/log_common.h
   <details>
   
   ```diff
   @@ -43,12 +43,12 @@
    #define LOG_LEVEL_MAX      (15)
    
    #define LOG_LEVEL_STR(level) \
   -    (LOG_LEVEL_DEBUG    == level ? "DEBUG"    :\
   -    (LOG_LEVEL_INFO     == level ? "INFO"     :\
   -    (LOG_LEVEL_WARN     == level ? "WARN"     :\
   -    (LOG_LEVEL_ERROR    == level ? "ERROR"    :\
   -    (LOG_LEVEL_CRITICAL == level ? "CRITICAL" :\
   -     "UNKNOWN")))))
   +    (LOG_LEVEL_DEBUG == level ? "DEBUG"    : \
   +     (LOG_LEVEL_INFO == level ? "INFO"     : \
   +      (LOG_LEVEL_WARN == level ? "WARN"     : \
   +       (LOG_LEVEL_ERROR == level ? "ERROR"    : \
   +        (LOG_LEVEL_CRITICAL == level ? "CRITICAL" : \
   +         "UNKNOWN")))))
    
    /* XXX: These module IDs are defined for backwards compatibility.  Application
     * code should use the syscfg settings directly.  These defines will be removed
   @@ -131,8 +131,8 @@
    
    /** @typdef log_notify_rotate_cb
     * @brief Callback that is executed each time we are about to rotate a log.
   - * 
   - * @param log                   The log that is about to rotate 
   + *
   + * @param log                   The log that is about to rotate
     */
    typedef void log_notify_rotate_cb(const struct log *log);
    
   ```
   
   </details>


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



[GitHub] [mynewt-nimble] sjanc commented on a change in pull request #878: Add support for NuttX

Posted by GitBox <gi...@apache.org>.
sjanc commented on a change in pull request #878:
URL: https://github.com/apache/mynewt-nimble/pull/878#discussion_r542217425



##########
File path: porting/nimble/include/log/log.h
##########
@@ -30,11 +30,13 @@ log_dummy(void *log, ...)
     (void)log;
 }
 
+#if 0

Review comment:
       Hmm I think for now we could just put all this under #ifndef LOG_DEBUG
   
   in long term I think we should add own NPL_LOG_* and use those instead of relying on modlog module defining those




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



[GitHub] [mynewt-nimble] andrzej-kaczmarek commented on pull request #878: Add support for NuttX

Posted by GitBox <gi...@apache.org>.
andrzej-kaczmarek commented on pull request #878:
URL: https://github.com/apache/mynewt-nimble/pull/878#issuecomment-736861388


   @v01d sorry it takes so long, I was quite busy recently but I should find some time to check it this week


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



[GitHub] [mynewt-nimble] apache-mynewt-bot removed a comment on pull request #878: Add support for NuttX

Posted by GitBox <gi...@apache.org>.
apache-mynewt-bot removed a comment on pull request #878:
URL: https://github.com/apache/mynewt-nimble/pull/878#issuecomment-719001812


   
   <!-- style-bot -->
   
   ## Style check summary
   
   ### Our coding style is [here!](https://github.com/apache/mynewt-core/blob/master/CODING_STANDARDS.md)
   
   
   #### nimble/transport/socket/src/ble_hci_socket.c
   <details>
   
   ```diff
   @@ -54,15 +54,15 @@
    #if MYNEWT_VAL(BLE_SOCK_USE_LINUX_BLUE)
    #include <sys/errno.h>
    #define BTPROTO_HCI       1
   -#define HCI_CHANNEL_RAW		0
   -#define HCI_CHANNEL_USER	1
   +#define HCI_CHANNEL_RAW     0
   +#define HCI_CHANNEL_USER    1
    #define HCIDEVUP          _IOW('H', 201, int)
    #define HCIDEVDOWN        _IOW('H', 202, int)
    #define HCIDEVRESET       _IOW('H', 203, int)
    #define HCIGETDEVLIST     _IOR('H', 210, int)
    
    struct sockaddr_hci {
   -    sa_family_t    hci_family;
   +    sa_family_t hci_family;
        unsigned short hci_dev;
        unsigned short hci_channel;
    };
   @@ -279,7 +279,7 @@
    ble_hci_sock_acl_tx(struct os_mbuf *om)
    {
        size_t len;
   -    uint8_t* buf;
   +    uint8_t * buf;
        int i;
        struct os_mbuf *m;
        struct sockaddr_hci addr;
   @@ -296,7 +296,7 @@
            len += m->om_len;
        }
    
   -    buf = (uint8_t*)malloc(len);
   +    buf = (uint8_t *)malloc(len);
    
        buf[0] = BLE_HCI_UART_H4_ACL;
    
   @@ -385,7 +385,7 @@
    static int
    ble_hci_sock_cmdevt_tx(uint8_t *hci_ev, uint8_t h4_type)
    {
   -    uint8_t* buf;
   +    uint8_t * buf;
        size_t len;
        struct sockaddr_hci addr;
        int i;
   @@ -409,7 +409,7 @@
        STATS_INC(hci_sock_stats, omsg);
        STATS_INCN(hci_sock_stats, obytes, len + 1);
    
   -    buf = (uint8_t*)malloc(len + 1);
   +    buf = (uint8_t *)malloc(len + 1);
    
        buf[0] = h4_type;
        memcpy(&buf[1], hci_ev, len);
   ```
   
   </details>
   
   #### porting/nimble/include/log_common/log_common.h
   <details>
   
   ```diff
   @@ -43,12 +43,12 @@
    #define LOG_LEVEL_MAX      (15)
    
    #define LOG_LEVEL_STR(level) \
   -    (LOG_LEVEL_DEBUG    == level ? "DEBUG"    :\
   -    (LOG_LEVEL_INFO     == level ? "INFO"     :\
   -    (LOG_LEVEL_WARN     == level ? "WARN"     :\
   -    (LOG_LEVEL_ERROR    == level ? "ERROR"    :\
   -    (LOG_LEVEL_CRITICAL == level ? "CRITICAL" :\
   -     "UNKNOWN")))))
   +    (LOG_LEVEL_DEBUG == level ? "DEBUG"    : \
   +     (LOG_LEVEL_INFO == level ? "INFO"     : \
   +      (LOG_LEVEL_WARN == level ? "WARN"     : \
   +       (LOG_LEVEL_ERROR == level ? "ERROR"    : \
   +        (LOG_LEVEL_CRITICAL == level ? "CRITICAL" : \
   +         "UNKNOWN")))))
    
    /* XXX: These module IDs are defined for backwards compatibility.  Application
     * code should use the syscfg settings directly.  These defines will be removed
   @@ -131,8 +131,8 @@
    
    /** @typdef log_notify_rotate_cb
     * @brief Callback that is executed each time we are about to rotate a log.
   - * 
   - * @param log                   The log that is about to rotate 
   + *
   + * @param log                   The log that is about to rotate
     */
    typedef void log_notify_rotate_cb(const struct log *log);
    
   ```
   
   </details>


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



[GitHub] [mynewt-nimble] v01d commented on a change in pull request #878: Add support for NuttX

Posted by GitBox <gi...@apache.org>.
v01d commented on a change in pull request #878:
URL: https://github.com/apache/mynewt-nimble/pull/878#discussion_r537685455



##########
File path: porting/examples/nuttx/README.md
##########
@@ -0,0 +1,73 @@
+<!--
+#
+# 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.
+#
+-->
+
+# Apache Mynewt NimBLE
+
+## Overview
+
+See (https://mynewt.apache.org/network/ble/ble_intro/).
+
+## Building
+
+NimBLE is usually built as a part of Apache Mynewt OS, but ports for
+other RTOS-es are also available.
+
+### Linux

Review comment:
       I'll remove it since the build starts on NuttX side and the documentation should be there.




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



[GitHub] [mynewt-nimble] apache-mynewt-bot removed a comment on pull request #878: Add support for NuttX

Posted by GitBox <gi...@apache.org>.
apache-mynewt-bot removed a comment on pull request #878:
URL: https://github.com/apache/mynewt-nimble/pull/878#issuecomment-740067692


   
   <!-- style-bot -->
   
   ## Style check summary
   
   ### Our coding style is [here!](https://github.com/apache/mynewt-core/blob/master/CODING_STANDARDS.md)
   
   
   #### nimble/transport/socket/src/ble_hci_socket.c
   <details>
   
   ```diff
   @@ -54,7 +54,7 @@
    #if MYNEWT_VAL(BLE_SOCK_USE_LINUX_BLUE)
    #include <sys/errno.h>
    #define BTPROTO_HCI       1
   -#define HCI_CHANNEL_RAW	  0
   +#define HCI_CHANNEL_RAW   0
    #define HCI_CHANNEL_USER  1
    #define HCIDEVUP          _IOW('H', 201, int)
    #define HCIDEVDOWN        _IOW('H', 202, int)
   ```
   
   </details>
   
   #### porting/nimble/include/log_common/log_common.h
   <details>
   
   ```diff
   @@ -43,12 +43,12 @@
    #define LOG_LEVEL_MAX      (15)
    
    #define LOG_LEVEL_STR(level) \
   -    (LOG_LEVEL_DEBUG    == level ? "DEBUG"    :\
   -    (LOG_LEVEL_INFO     == level ? "INFO"     :\
   -    (LOG_LEVEL_WARN     == level ? "WARN"     :\
   -    (LOG_LEVEL_ERROR    == level ? "ERROR"    :\
   -    (LOG_LEVEL_CRITICAL == level ? "CRITICAL" :\
   -     "UNKNOWN")))))
   +    (LOG_LEVEL_DEBUG == level ? "DEBUG"    : \
   +     (LOG_LEVEL_INFO == level ? "INFO"     : \
   +      (LOG_LEVEL_WARN == level ? "WARN"     : \
   +       (LOG_LEVEL_ERROR == level ? "ERROR"    : \
   +        (LOG_LEVEL_CRITICAL == level ? "CRITICAL" : \
   +         "UNKNOWN")))))
    
    /* XXX: These module IDs are defined for backwards compatibility.  Application
     * code should use the syscfg settings directly.  These defines will be removed
   ```
   
   </details>


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



[GitHub] [mynewt-nimble] apache-mynewt-bot commented on pull request #878: Add support for NuttX

Posted by GitBox <gi...@apache.org>.
apache-mynewt-bot commented on pull request #878:
URL: https://github.com/apache/mynewt-nimble/pull/878#issuecomment-740097423


   
   <!-- style-bot -->
   
   ## Style check summary
   
   ### Our coding style is [here!](https://github.com/apache/mynewt-core/blob/master/CODING_STANDARDS.md)
   
   
   #### nimble/transport/socket/src/ble_hci_socket.c
   <details>
   
   ```diff
   @@ -54,7 +54,7 @@
    #if MYNEWT_VAL(BLE_SOCK_USE_LINUX_BLUE)
    #include <sys/errno.h>
    #define BTPROTO_HCI       1
   -#define HCI_CHANNEL_RAW	  0
   +#define HCI_CHANNEL_RAW   0
    #define HCI_CHANNEL_USER  1
    #define HCIDEVUP          _IOW('H', 201, int)
    #define HCIDEVDOWN        _IOW('H', 202, int)
   ```
   
   </details>
   
   #### porting/nimble/include/log_common/log_common.h
   <details>
   
   ```diff
   @@ -43,12 +43,12 @@
    #define LOG_LEVEL_MAX      (15)
    
    #define LOG_LEVEL_STR(level) \
   -    (LOG_LEVEL_DEBUG    == level ? "DEBUG"    :\
   -    (LOG_LEVEL_INFO     == level ? "INFO"     :\
   -    (LOG_LEVEL_WARN     == level ? "WARN"     :\
   -    (LOG_LEVEL_ERROR    == level ? "ERROR"    :\
   -    (LOG_LEVEL_CRITICAL == level ? "CRITICAL" :\
   -     "UNKNOWN")))))
   +    (LOG_LEVEL_DEBUG == level ? "DEBUG"    : \
   +     (LOG_LEVEL_INFO == level ? "INFO"     : \
   +      (LOG_LEVEL_WARN == level ? "WARN"     : \
   +       (LOG_LEVEL_ERROR == level ? "ERROR"    : \
   +        (LOG_LEVEL_CRITICAL == level ? "CRITICAL" : \
   +         "UNKNOWN")))))
    
    /* XXX: These module IDs are defined for backwards compatibility.  Application
     * code should use the syscfg settings directly.  These defines will be removed
   ```
   
   </details>


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



[GitHub] [mynewt-nimble] v01d commented on a change in pull request #878: Add support for NuttX

Posted by GitBox <gi...@apache.org>.
v01d commented on a change in pull request #878:
URL: https://github.com/apache/mynewt-nimble/pull/878#discussion_r537686188



##########
File path: porting/nimble/include/log/log.h
##########
@@ -30,11 +30,13 @@ log_dummy(void *log, ...)
     (void)log;
 }
 
+#if 0

Review comment:
       Please see previous comment: https://github.com/apache/mynewt-nimble/pull/878#issuecomment-718964467




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



[GitHub] [mynewt-nimble] v01d commented on pull request #878: Add support for NuttX

Posted by GitBox <gi...@apache.org>.
v01d commented on pull request #878:
URL: https://github.com/apache/mynewt-nimble/pull/878#issuecomment-736862868


   great, thanks @andrzej-kaczmarek 


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



[GitHub] [mynewt-nimble] v01d commented on pull request #878: Add support for NuttX

Posted by GitBox <gi...@apache.org>.
v01d commented on pull request #878:
URL: https://github.com/apache/mynewt-nimble/pull/878#issuecomment-718964467


   Ok, I just addressed the style issues and also found how to define a variable to distinguish NuttX from Linux. There are just two things worth mentioning:
   - a check on a semaphore which is actually a race condition (see annotation above) since it checks the semaphore at a time which may be incorrect (in NuttX this was triggered incorrectly, possibly on Linux it was slower and it wasn't triggered)
   - I had to disable LOG_* defines in log.h, due to conflicts of syslog() defines which NuttX has. It was suggested in #864 that I could redefine include path to my own log.h, and to do this I would have to change all includes of `log.h` from using `"` to `<`/`>` for that to work. But I feel hesitant to do so since it sounds a bit hack to do that only for that include. If you confirm it is OK to do so, I will add that as well. Otherwise, I think the simpler change is to remove those LOG_* macros which are not used in nimBLE (or maybe conditionally define them based on MYNEWT?)
   
   


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



[GitHub] [mynewt-nimble] apache-mynewt-bot commented on pull request #878: Add support for NuttX

Posted by GitBox <gi...@apache.org>.
apache-mynewt-bot commented on pull request #878:
URL: https://github.com/apache/mynewt-nimble/pull/878#issuecomment-740067692


   
   <!-- style-bot -->
   
   ## Style check summary
   
   ### Our coding style is [here!](https://github.com/apache/mynewt-core/blob/master/CODING_STANDARDS.md)
   
   
   #### nimble/transport/socket/src/ble_hci_socket.c
   <details>
   
   ```diff
   @@ -54,7 +54,7 @@
    #if MYNEWT_VAL(BLE_SOCK_USE_LINUX_BLUE)
    #include <sys/errno.h>
    #define BTPROTO_HCI       1
   -#define HCI_CHANNEL_RAW	  0
   +#define HCI_CHANNEL_RAW   0
    #define HCI_CHANNEL_USER  1
    #define HCIDEVUP          _IOW('H', 201, int)
    #define HCIDEVDOWN        _IOW('H', 202, int)
   ```
   
   </details>
   
   #### porting/nimble/include/log_common/log_common.h
   <details>
   
   ```diff
   @@ -43,12 +43,12 @@
    #define LOG_LEVEL_MAX      (15)
    
    #define LOG_LEVEL_STR(level) \
   -    (LOG_LEVEL_DEBUG    == level ? "DEBUG"    :\
   -    (LOG_LEVEL_INFO     == level ? "INFO"     :\
   -    (LOG_LEVEL_WARN     == level ? "WARN"     :\
   -    (LOG_LEVEL_ERROR    == level ? "ERROR"    :\
   -    (LOG_LEVEL_CRITICAL == level ? "CRITICAL" :\
   -     "UNKNOWN")))))
   +    (LOG_LEVEL_DEBUG == level ? "DEBUG"    : \
   +     (LOG_LEVEL_INFO == level ? "INFO"     : \
   +      (LOG_LEVEL_WARN == level ? "WARN"     : \
   +       (LOG_LEVEL_ERROR == level ? "ERROR"    : \
   +        (LOG_LEVEL_CRITICAL == level ? "CRITICAL" : \
   +         "UNKNOWN")))))
    
    /* XXX: These module IDs are defined for backwards compatibility.  Application
     * code should use the syscfg settings directly.  These defines will be removed
   ```
   
   </details>


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



[GitHub] [mynewt-nimble] v01d commented on a change in pull request #878: Add support for NuttX

Posted by GitBox <gi...@apache.org>.
v01d commented on a change in pull request #878:
URL: https://github.com/apache/mynewt-nimble/pull/878#discussion_r537692798



##########
File path: porting/examples/nuttx/include/syscfg.h
##########
@@ -0,0 +1,941 @@
+/**

Review comment:
       No, I just removed it.




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



[GitHub] [mynewt-nimble] apache-mynewt-bot commented on pull request #878: Add support for NuttX

Posted by GitBox <gi...@apache.org>.
apache-mynewt-bot commented on pull request #878:
URL: https://github.com/apache/mynewt-nimble/pull/878#issuecomment-740096778


   
   <!-- style-bot -->
   
   ## Style check summary
   
   ### Our coding style is [here!](https://github.com/apache/mynewt-core/blob/master/CODING_STANDARDS.md)
   
   
   #### nimble/transport/socket/src/ble_hci_socket.c
   <details>
   
   ```diff
   @@ -54,7 +54,7 @@
    #if MYNEWT_VAL(BLE_SOCK_USE_LINUX_BLUE)
    #include <sys/errno.h>
    #define BTPROTO_HCI       1
   -#define HCI_CHANNEL_RAW	  0
   +#define HCI_CHANNEL_RAW   0
    #define HCI_CHANNEL_USER  1
    #define HCIDEVUP          _IOW('H', 201, int)
    #define HCIDEVDOWN        _IOW('H', 202, int)
   ```
   
   </details>
   
   #### porting/nimble/include/log_common/log_common.h
   <details>
   
   ```diff
   @@ -43,12 +43,12 @@
    #define LOG_LEVEL_MAX      (15)
    
    #define LOG_LEVEL_STR(level) \
   -    (LOG_LEVEL_DEBUG    == level ? "DEBUG"    :\
   -    (LOG_LEVEL_INFO     == level ? "INFO"     :\
   -    (LOG_LEVEL_WARN     == level ? "WARN"     :\
   -    (LOG_LEVEL_ERROR    == level ? "ERROR"    :\
   -    (LOG_LEVEL_CRITICAL == level ? "CRITICAL" :\
   -     "UNKNOWN")))))
   +    (LOG_LEVEL_DEBUG == level ? "DEBUG"    : \
   +     (LOG_LEVEL_INFO == level ? "INFO"     : \
   +      (LOG_LEVEL_WARN == level ? "WARN"     : \
   +       (LOG_LEVEL_ERROR == level ? "ERROR"    : \
   +        (LOG_LEVEL_CRITICAL == level ? "CRITICAL" : \
   +         "UNKNOWN")))))
    
    /* XXX: These module IDs are defined for backwards compatibility.  Application
     * code should use the syscfg settings directly.  These defines will be removed
   ```
   
   </details>


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



[GitHub] [mynewt-nimble] apache-mynewt-bot removed a comment on pull request #878: Add support for NuttX

Posted by GitBox <gi...@apache.org>.
apache-mynewt-bot removed a comment on pull request #878:
URL: https://github.com/apache/mynewt-nimble/pull/878#issuecomment-740096778


   
   <!-- style-bot -->
   
   ## Style check summary
   
   ### Our coding style is [here!](https://github.com/apache/mynewt-core/blob/master/CODING_STANDARDS.md)
   
   
   #### nimble/transport/socket/src/ble_hci_socket.c
   <details>
   
   ```diff
   @@ -54,7 +54,7 @@
    #if MYNEWT_VAL(BLE_SOCK_USE_LINUX_BLUE)
    #include <sys/errno.h>
    #define BTPROTO_HCI       1
   -#define HCI_CHANNEL_RAW	  0
   +#define HCI_CHANNEL_RAW   0
    #define HCI_CHANNEL_USER  1
    #define HCIDEVUP          _IOW('H', 201, int)
    #define HCIDEVDOWN        _IOW('H', 202, int)
   ```
   
   </details>
   
   #### porting/nimble/include/log_common/log_common.h
   <details>
   
   ```diff
   @@ -43,12 +43,12 @@
    #define LOG_LEVEL_MAX      (15)
    
    #define LOG_LEVEL_STR(level) \
   -    (LOG_LEVEL_DEBUG    == level ? "DEBUG"    :\
   -    (LOG_LEVEL_INFO     == level ? "INFO"     :\
   -    (LOG_LEVEL_WARN     == level ? "WARN"     :\
   -    (LOG_LEVEL_ERROR    == level ? "ERROR"    :\
   -    (LOG_LEVEL_CRITICAL == level ? "CRITICAL" :\
   -     "UNKNOWN")))))
   +    (LOG_LEVEL_DEBUG == level ? "DEBUG"    : \
   +     (LOG_LEVEL_INFO == level ? "INFO"     : \
   +      (LOG_LEVEL_WARN == level ? "WARN"     : \
   +       (LOG_LEVEL_ERROR == level ? "ERROR"    : \
   +        (LOG_LEVEL_CRITICAL == level ? "CRITICAL" : \
   +         "UNKNOWN")))))
    
    /* XXX: These module IDs are defined for backwards compatibility.  Application
     * code should use the syscfg settings directly.  These defines will be removed
   ```
   
   </details>


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



[GitHub] [mynewt-nimble] v01d commented on a change in pull request #878: Add support for NuttX

Posted by GitBox <gi...@apache.org>.
v01d commented on a change in pull request #878:
URL: https://github.com/apache/mynewt-nimble/pull/878#discussion_r537731511



##########
File path: nimble/host/src/ble_hs_hci.c
##########
@@ -339,11 +339,13 @@ ble_hs_hci_cmd_tx(uint16_t opcode, const void *cmd, uint8_t cmd_len,
 static void
 ble_hs_hci_rx_ack(uint8_t *ack_ev)
 {
+#if 0
     if (ble_npl_sem_get_count(&ble_hs_hci_sem) > 0) {
         /* This ack is unexpected; ignore it. */
         ble_hci_trans_buf_free(ack_ev);
         return;
     }
+#endif

Review comment:
       Ok, I looked further into the issue and it was not a race condition after all. The problem is that ble_npl_sem_get_count() returns unsigned integer and NuttX returns negative numbers in sem_getvalue() to indicate number of lock count (this is a valid option as per the man page). So this would generate 65536 as the sem value and the if would get triggered.
   It now works as expected.




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



[GitHub] [mynewt-nimble] andrzej-kaczmarek commented on a change in pull request #878: Add support for NuttX

Posted by GitBox <gi...@apache.org>.
andrzej-kaczmarek commented on a change in pull request #878:
URL: https://github.com/apache/mynewt-nimble/pull/878#discussion_r537348035



##########
File path: nimble/transport/socket/src/ble_hci_socket.c
##########
@@ -205,6 +208,8 @@ static struct ble_hci_sock_state {
 static int s_ble_hci_device = MYNEWT_VAL(BLE_SOCK_TCP_PORT);
 #elif MYNEWT_VAL(BLE_SOCK_USE_LINUX_BLUE)
 static int s_ble_hci_device = MYNEWT_VAL(BLE_SOCK_LINUX_DEV);
+#elif MYNEWT_VAL(BLE_SOCK_USE_LINUX_BLUE) || MYNEWT_VAL(BLE_SOCK_USE_NUTTX)

Review comment:
       `MYNEWT_VAL(BLE_SOCK_USE_LINUX_BLUE)` is always false here since it's already checked earlier

##########
File path: porting/npl/nuttx/src/os_callout.c
##########
@@ -0,0 +1,159 @@
+/*
+ * 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.
+ */
+
+#include <nuttx/config.h>
+#include <assert.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
+
+#include <time.h>
+#include <signal.h>
+
+#include "nimble/nimble_npl.h"
+
+static void
+ble_npl_callout_timer_cb(union sigval sv)
+{
+    struct ble_npl_callout *c = (struct ble_npl_callout *)sv.sival_ptr;
+    assert(c);
+
+    if (c->c_evq) {
+        ble_npl_eventq_put(c->c_evq, &c->c_ev);
+    } else {
+        c->c_ev.ev_cb(&c->c_ev);
+    }
+}
+
+void ble_npl_callout_init(struct ble_npl_callout *c, 
+                          struct ble_npl_eventq *evq,
+                          ble_npl_event_fn *ev_cb, 
+                          void *ev_arg)
+{
+    struct sigevent         event;
+
+    /* Initialize the callout. */
+    memset(c, 0, sizeof(*c));
+    c->c_ev.ev_cb = ev_cb;
+    c->c_ev.ev_arg = ev_arg;
+    c->c_evq = evq;
+    c->c_active = false;
+
+    event.sigev_notify = SIGEV_THREAD;
+    event.sigev_value.sival_ptr = c;     // put callout obj in signal args
+    event.sigev_notify_function = ble_npl_callout_timer_cb;
+    event.sigev_notify_attributes = NULL;
+
+    timer_create(CLOCK_REALTIME, &event, &c->c_timer);
+}
+
+bool ble_npl_callout_is_active(struct ble_npl_callout *c)
+{
+    // TODO: seek native posix method to determine whether timer_t is active.
+    // TODO: fix bug where one-shot timer is still active after fired.
+    return c->c_active;
+}
+
+int ble_npl_callout_inited(struct ble_npl_callout *c)
+{
+    return (c->c_timer != NULL);
+}
+
+ble_npl_error_t ble_npl_callout_reset(struct ble_npl_callout *c,
+				      ble_npl_time_t ticks)

Review comment:
       use spaces for indentation, return type should be in separate line. the same for other functions in NPL
   

##########
File path: nimble/transport/socket/src/ble_hci_socket.c
##########
@@ -281,6 +343,9 @@ ble_hci_sock_cmdevt_tx(uint8_t *hci_ev, uint8_t h4_type)
     memset(&msg, 0, sizeof(msg));
     memset(iov, 0, sizeof(iov));
 
+    msg.msg_name = (void *)btaddr;
+    msg.msg_namelen = 6;
+

Review comment:
       why do we need this here? there's separate code for nuttx below. if this fixes something else than nuttx, please create separate PR.

##########
File path: porting/npl/nuttx/src/os_callout.c
##########
@@ -0,0 +1,159 @@
+/*
+ * 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.
+ */
+
+#include <nuttx/config.h>
+#include <assert.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
+
+#include <time.h>
+#include <signal.h>
+
+#include "nimble/nimble_npl.h"
+
+static void
+ble_npl_callout_timer_cb(union sigval sv)
+{
+    struct ble_npl_callout *c = (struct ble_npl_callout *)sv.sival_ptr;
+    assert(c);
+
+    if (c->c_evq) {
+        ble_npl_eventq_put(c->c_evq, &c->c_ev);
+    } else {
+        c->c_ev.ev_cb(&c->c_ev);
+    }
+}
+
+void ble_npl_callout_init(struct ble_npl_callout *c, 
+                          struct ble_npl_eventq *evq,
+                          ble_npl_event_fn *ev_cb, 
+                          void *ev_arg)
+{
+    struct sigevent         event;
+
+    /* Initialize the callout. */
+    memset(c, 0, sizeof(*c));
+    c->c_ev.ev_cb = ev_cb;
+    c->c_ev.ev_arg = ev_arg;
+    c->c_evq = evq;
+    c->c_active = false;
+
+    event.sigev_notify = SIGEV_THREAD;
+    event.sigev_value.sival_ptr = c;     // put callout obj in signal args
+    event.sigev_notify_function = ble_npl_callout_timer_cb;
+    event.sigev_notify_attributes = NULL;
+
+    timer_create(CLOCK_REALTIME, &event, &c->c_timer);
+}
+
+bool ble_npl_callout_is_active(struct ble_npl_callout *c)
+{
+    // TODO: seek native posix method to determine whether timer_t is active.
+    // TODO: fix bug where one-shot timer is still active after fired.
+    return c->c_active;
+}
+
+int ble_npl_callout_inited(struct ble_npl_callout *c)
+{
+    return (c->c_timer != NULL);
+}
+
+ble_npl_error_t ble_npl_callout_reset(struct ble_npl_callout *c,
+				      ble_npl_time_t ticks)
+{
+    struct itimerspec       its;
+
+    if (ticks < 0) {
+        return BLE_NPL_EINVAL;
+    }
+
+    if (ticks == 0) {
+        ticks = 1;
+    }
+
+    c->c_ticks = ble_npl_time_get() + ticks;
+
+    its.it_interval.tv_sec = 0;
+    its.it_interval.tv_nsec = 0;                     // one shot

Review comment:
       do not use C++ style comments




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



[GitHub] [mynewt-nimble] apache-mynewt-bot commented on pull request #878: Add support for NuttX

Posted by GitBox <gi...@apache.org>.
apache-mynewt-bot commented on pull request #878:
URL: https://github.com/apache/mynewt-nimble/pull/878#issuecomment-719059851


   
   <!-- style-bot -->
   
   ## Style check summary
   
   ### Our coding style is [here!](https://github.com/apache/mynewt-core/blob/master/CODING_STANDARDS.md)
   
   
   #### nimble/transport/socket/src/ble_hci_socket.c
   <details>
   
   ```diff
   @@ -54,7 +54,7 @@
    #if MYNEWT_VAL(BLE_SOCK_USE_LINUX_BLUE)
    #include <sys/errno.h>
    #define BTPROTO_HCI       1
   -#define HCI_CHANNEL_RAW	  0
   +#define HCI_CHANNEL_RAW   0
    #define HCI_CHANNEL_USER  1
    #define HCIDEVUP          _IOW('H', 201, int)
    #define HCIDEVDOWN        _IOW('H', 202, int)
   @@ -279,7 +279,7 @@
    ble_hci_sock_acl_tx(struct os_mbuf *om)
    {
        size_t len;
   -    uint8_t* buf;
   +    uint8_t * buf;
        int i;
        struct os_mbuf *m;
        struct sockaddr_hci addr;
   @@ -296,7 +296,7 @@
            len += m->om_len;
        }
    
   -    buf = (uint8_t*)malloc(len);
   +    buf = (uint8_t *)malloc(len);
    
        buf[0] = BLE_HCI_UART_H4_ACL;
    
   ```
   
   </details>
   
   #### porting/nimble/include/log_common/log_common.h
   <details>
   
   ```diff
   @@ -43,12 +43,12 @@
    #define LOG_LEVEL_MAX      (15)
    
    #define LOG_LEVEL_STR(level) \
   -    (LOG_LEVEL_DEBUG    == level ? "DEBUG"    :\
   -    (LOG_LEVEL_INFO     == level ? "INFO"     :\
   -    (LOG_LEVEL_WARN     == level ? "WARN"     :\
   -    (LOG_LEVEL_ERROR    == level ? "ERROR"    :\
   -    (LOG_LEVEL_CRITICAL == level ? "CRITICAL" :\
   -     "UNKNOWN")))))
   +    (LOG_LEVEL_DEBUG == level ? "DEBUG"    : \
   +     (LOG_LEVEL_INFO == level ? "INFO"     : \
   +      (LOG_LEVEL_WARN == level ? "WARN"     : \
   +       (LOG_LEVEL_ERROR == level ? "ERROR"    : \
   +        (LOG_LEVEL_CRITICAL == level ? "CRITICAL" : \
   +         "UNKNOWN")))))
    
    /* XXX: These module IDs are defined for backwards compatibility.  Application
     * code should use the syscfg settings directly.  These defines will be removed
   @@ -131,8 +131,8 @@
    
    /** @typdef log_notify_rotate_cb
     * @brief Callback that is executed each time we are about to rotate a log.
   - * 
   - * @param log                   The log that is about to rotate 
   + *
   + * @param log                   The log that is about to rotate
     */
    typedef void log_notify_rotate_cb(const struct log *log);
    
   ```
   
   </details>


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