mscd_init:
  338|      1|void mscd_init(void) {
  339|      1|  TU_LOG_INT(CFG_TUD_MSC_LOG_LEVEL, sizeof(mscd_interface_t));
  340|      1|  tu_memclr(&_mscd_itf, sizeof(mscd_interface_t));
  ------------------
  |  |   95|      1|#define tu_memclr(buffer, size)  (void) memset((buffer), 0, (size))
  ------------------
  341|      1|}
mscd_reset:
  347|  16.1k|void mscd_reset(uint8_t rhport) {
  348|  16.1k|  (void) rhport;
  349|  16.1k|  tu_memclr(&_mscd_itf, sizeof(mscd_interface_t));
  ------------------
  |  |   95|  16.1k|#define tu_memclr(buffer, size)  (void) memset((buffer), 0, (size))
  ------------------
  350|  16.1k|}
mscd_open:
  352|    212|uint16_t mscd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len) {
  353|       |  // only support SCSI's BOT protocol
  354|    212|  TU_VERIFY(TUSB_CLASS_MSC    == itf_desc->bInterfaceClass &&
  ------------------
  |  |   95|    212|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  112|    212|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |   95|    212|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   93|    212|#define TU_VERIFY_2ARGS(_cond, _ret)   TU_VERIFY_DEFINE(_cond, _ret)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   86|    212|  do {                                \
  |  |  |  |  |  |  |  |  |  |   87|    848|    if (!(_cond)) {                   \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (87:11): [True: 212, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  Branch (87:11): [True: 212, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  Branch (87:11): [True: 212, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   88|      0|      return _ret;                    \
  |  |  |  |  |  |  |  |  |  |   89|      0|    }                                 \
  |  |  |  |  |  |  |  |  |  |   90|    212|  } while (0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (90:12): [Folded, False: 212]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  355|    212|            MSC_SUBCLASS_SCSI == itf_desc->bInterfaceSubClass &&
  356|    212|            MSC_PROTOCOL_BOT  == itf_desc->bInterfaceProtocol, 0);
  357|    212|  uint16_t const drv_len = sizeof(tusb_desc_interface_t) + 2*sizeof(tusb_desc_endpoint_t);
  358|    212|  TU_ASSERT(max_len >= drv_len, 0); // Max length must be at least 1 interface + 2 endpoints
  ------------------
  |  |  112|    212|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  112|    212|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  112|    212|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  109|    212|#define TU_ASSERT_2ARGS(_cond, _ret)   TU_ASSERT_DEFINE(_cond, _ret)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  104|    212|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  105|    212|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   54|      0|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (54:41): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   77|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (77:40): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (105:10): [True: 0, False: 212]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  106|    212|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:11): [Folded, False: 212]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  359|       |
  360|    212|  mscd_interface_t * p_msc = &_mscd_itf;
  361|    212|  p_msc->itf_num = itf_desc->bInterfaceNumber;
  362|    212|  p_msc->rhport = rhport;
  363|       |
  364|       |  // Open endpoint pair
  365|    212|  TU_ASSERT(usbd_open_edpt_pair(rhport, tu_desc_next(itf_desc), 2, TUSB_XFER_BULK, &p_msc->ep_out, &p_msc->ep_in), 0);
  ------------------
  |  |  112|    212|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  112|    212|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  112|    212|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  109|    212|#define TU_ASSERT_2ARGS(_cond, _ret)   TU_ASSERT_DEFINE(_cond, _ret)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  104|    212|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  105|    212|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   54|    212|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (54:41): [Folded, False: 212]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   77|    212|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (77:40): [Folded, False: 212]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (105:10): [True: 212, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  106|    212|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:11): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  366|       |
  367|       |  // Prepare for Command Block Wrapper
  368|      0|  TU_ASSERT(prepare_cbw(p_msc), drv_len);
  ------------------
  |  |  112|      0|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  112|      0|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  112|      0|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  109|      0|#define TU_ASSERT_2ARGS(_cond, _ret)   TU_ASSERT_DEFINE(_cond, _ret)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  104|      0|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  105|      0|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   54|      0|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (54:41): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   77|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (77:40): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (105:10): [True: 0, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  106|      0|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:11): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  369|       |
  370|      0|  return drv_len;
  371|      0|}

tusb_fifo.c:tu_min16:
  187|  36.9k|TU_ATTR_ALWAYS_INLINE static inline uint16_t tu_min16 (uint16_t x, uint16_t y) { return (x < y) ? x : y; }
  ------------------
  |  Branch (187:89): [True: 36.9k, False: 0]
  ------------------
usbd.c:tu_min16:
  187|  5.90k|TU_ATTR_ALWAYS_INLINE static inline uint16_t tu_min16 (uint16_t x, uint16_t y) { return (x < y) ? x : y; }
  ------------------
  |  Branch (187:89): [True: 4.49k, False: 1.40k]
  ------------------
usbd.c:tu_memcpy_s:
  118|    441|TU_ATTR_ALWAYS_INLINE static inline int tu_memcpy_s(void *dest, size_t destsz, const void *src, size_t count) {
  119|    441|  if (dest == NULL) {
  ------------------
  |  Branch (119:7): [True: 0, False: 441]
  ------------------
  120|      0|    return -1;
  121|      0|  }
  122|       |
  123|    441|  if (count == 0u) {
  ------------------
  |  Branch (123:7): [True: 0, False: 441]
  ------------------
  124|      0|    return 0;
  125|      0|  }
  126|       |
  127|    441|  if (src == NULL) {
  ------------------
  |  Branch (127:7): [True: 0, False: 441]
  ------------------
  128|      0|    return -1;
  129|      0|  }
  130|       |
  131|    441|  if (count > destsz) {
  ------------------
  |  Branch (131:7): [True: 0, False: 441]
  ------------------
  132|      0|    return -1;
  133|      0|  }
  134|       |
  135|    441|  (void) memcpy(dest, src, count);
  136|    441|  return 0;
  137|    441|}
usbd.c:tu_u16_low:
  178|  5.44k|TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_u16_low (uint16_t ui16) { return TU_U16_LOW(ui16); }
  ------------------
  |  |   27|  5.44k|#define TU_U16_LOW(_u16)              ((uint8_t) ((uint16_t) (_u16) & 0x00ffu))
  ------------------
usbd.c:tu_desc_in_bounds:
  371|    212|TU_ATTR_ALWAYS_INLINE static inline bool tu_desc_in_bounds(const uint8_t *p_desc, const uint8_t *desc_end) {
  372|    212|  return p_desc < desc_end && tu_desc_next(p_desc) <= desc_end;
  ------------------
  |  Branch (372:10): [True: 212, False: 0]
  |  Branch (372:31): [True: 212, False: 0]
  ------------------
  373|    212|}
usbd.c:tu_desc_type:
  362|    424|TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_desc_type(void const* desc) {
  363|    424|  return ((uint8_t const*) desc)[DESC_OFFSET_TYPE];
  364|    424|}
usbd.c:tu_u16_high:
  177|  2.13k|TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_u16_high(uint16_t ui16) { return TU_U16_HIGH(ui16); }
  ------------------
  |  |   26|  2.13k|#define TU_U16_HIGH(_u16)             ((uint8_t) (((uint16_t) (_u16) >> 8) & 0x00ffu))
  ------------------
usbd.c:tu_unaligned_read16:
  252|    271|TU_ATTR_ALWAYS_INLINE static inline uint16_t tu_unaligned_read16(const void *mem) {
  253|    271|  tu_unaligned_uint16_t const *ua16 = (tu_unaligned_uint16_t const *) mem;
  254|    271|  return ua16->val;
  255|    271|}
usbd.c:tu_desc_len:
  357|    588|TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_desc_len(void const* desc) {
  358|    588|  return ((uint8_t const*) desc)[DESC_OFFSET_LEN];
  359|    588|}
usbd.c:tu_desc_next:
  351|    212|TU_ATTR_ALWAYS_INLINE static inline uint8_t const * tu_desc_next(void const* desc) {
  352|    212|  uint8_t const* desc8 = (uint8_t const*) desc;
  353|    212|  return desc8 + desc8[DESC_OFFSET_LEN];
  354|    212|}
msc_device.c:tu_desc_next:
  351|    212|TU_ATTR_ALWAYS_INLINE static inline uint8_t const * tu_desc_next(void const* desc) {
  352|    212|  uint8_t const* desc8 = (uint8_t const*) desc;
  353|    212|  return desc8 + desc8[DESC_OFFSET_LEN];
  354|    212|}

tu_fifo_clear:
   62|      1|void tu_fifo_clear(tu_fifo_t *f) {
   63|      1|  ff_lock(f->mutex_wr);
   64|      1|  ff_lock(f->mutex_rd);
   65|       |
   66|      1|  f->rd_idx = 0;
   67|      1|  f->wr_idx = 0;
   68|       |
   69|      1|  ff_unlock(f->mutex_wr);
   70|      1|  ff_unlock(f->mutex_rd);
   71|      1|}
tu_fifo_peek_n_access_mode:
  444|  79.6k|                                    const tu_hwfifo_access_t *access_mode) {
  445|  79.6k|  uint16_t count = tu_ff_overflow_count(f->depth, wr_idx, rd_idx);
  446|  79.6k|  if (count == 0) {
  ------------------
  |  Branch (446:7): [True: 42.6k, False: 36.9k]
  ------------------
  447|  42.6k|    return 0; // nothing to peek
  448|  42.6k|  }
  449|       |
  450|       |  // Check overflow and correct if required
  451|  36.9k|  if (count > f->depth) {
  ------------------
  |  Branch (451:7): [True: 0, False: 36.9k]
  ------------------
  452|      0|    rd_idx = correct_read_index(f, wr_idx);
  453|      0|    count  = f->depth;
  454|      0|  }
  455|       |
  456|  36.9k|  if (count < n) {
  ------------------
  |  Branch (456:7): [True: 0, False: 36.9k]
  ------------------
  457|      0|    n = count; // limit to available count
  458|      0|  }
  459|       |
  460|  36.9k|  const uint16_t rd_ptr = idx2ptr(f->depth, rd_idx);
  461|       |
  462|       |#if CFG_TUSB_FIFO_HWFIFO_API
  463|       |  if (access_mode != NULL) {
  464|       |    hwff_pull_n(f, p_buffer, n, rd_ptr, access_mode);
  465|       |  } else
  466|       |#endif
  467|  36.9k|  {
  468|  36.9k|    (void)access_mode;
  469|  36.9k|    ff_pull_n(f, p_buffer, n, rd_ptr);
  470|  36.9k|  }
  471|       |
  472|  36.9k|  return n;
  473|  79.6k|}
tu_fifo_read_n_access_mode:
  486|  79.6k|uint16_t tu_fifo_read_n_access_mode(tu_fifo_t *f, void *buffer, uint16_t n, const tu_hwfifo_access_t *access_mode) {
  487|  79.6k|  ff_lock(f->mutex_rd);
  488|       |
  489|       |  // Peek the data: f->rd_idx might get modified in case of an overflow so we can not use a local variable
  490|  79.6k|  const uint16_t wr_idx = f->wr_idx;
  491|  79.6k|  n         = tu_fifo_peek_n_access_mode(f, buffer, n, wr_idx, f->rd_idx, access_mode);
  492|  79.6k|  f->rd_idx = advance_index(f->depth, f->rd_idx, n);
  493|       |
  494|  79.6k|  ff_unlock(f->mutex_rd);
  495|  79.6k|  return n;
  496|  79.6k|}
tu_fifo_write_n_access_mode:
  500|  36.9k|                                     const tu_hwfifo_access_t *access_mode) {
  501|  36.9k|  if (n == 0) {
  ------------------
  |  Branch (501:7): [True: 0, False: 36.9k]
  ------------------
  502|      0|    return 0;
  503|      0|  }
  504|       |
  505|  36.9k|  ff_lock(f->mutex_wr);
  506|       |
  507|  36.9k|  uint16_t wr_idx = f->wr_idx;
  508|  36.9k|  uint16_t rd_idx = f->rd_idx;
  509|       |
  510|  36.9k|  const uint8_t *buf8 = (const uint8_t *)data;
  511|       |
  512|  36.9k|  TU_LOG(TU_FIFO_DBG, "rd = %3u, wr = %3u, count = %3u, remain = %3u, n = %3u:  ", rd_idx, wr_idx,
  513|  36.9k|         tu_ff_overflow_count(f->depth, wr_idx, rd_idx), tu_ff_remaining_local(f->depth, wr_idx, rd_idx), n);
  514|       |
  515|  36.9k|  if (!f->overwritable) {
  ------------------
  |  Branch (515:7): [True: 36.9k, False: 0]
  ------------------
  516|       |    // limit up to full
  517|  36.9k|    const uint16_t remain = tu_ff_remaining_local(f->depth, wr_idx, rd_idx);
  518|  36.9k|    n                     = tu_min16(n, remain);
  519|  36.9k|  } else {
  520|       |    // In over-writable mode, fifo_write() is allowed even when fifo is full. In such case,
  521|       |    // oldest data in fifo i.e. at read pointer data will be overwritten
  522|       |    // Note: we can modify read buffer contents however we must not modify the read index itself within a write
  523|       |    // function! Since it would end up in a race condition with read functions!
  524|      0|    if (n >= f->depth) {
  ------------------
  |  Branch (524:9): [True: 0, False: 0]
  ------------------
  525|       |      // Only copy last part
  526|      0|      if (access_mode == NULL) {
  ------------------
  |  Branch (526:11): [True: 0, False: 0]
  ------------------
  527|      0|        buf8 += (n - f->depth);
  528|      0|      } else {
  529|       |        // TODO should read from hw fifo to discard data, however reading an odd number could
  530|       |        // accidentally discard data.
  531|      0|      }
  532|       |
  533|      0|      n = f->depth;
  534|       |
  535|       |      // We start writing at the read pointer's position since we fill the whole buffer
  536|      0|      wr_idx = rd_idx;
  537|      0|    } else {
  538|      0|      const uint16_t overflowable_count = tu_ff_overflow_count(f->depth, wr_idx, rd_idx);
  539|      0|      if (overflowable_count + n >= 2 * f->depth) {
  ------------------
  |  Branch (539:11): [True: 0, False: 0]
  ------------------
  540|       |        // Double overflowed
  541|       |        // Index is bigger than the allowed range [0,2*depth)
  542|       |        // re-position write index to have a full fifo after pushed
  543|      0|        wr_idx = advance_index(f->depth, rd_idx, f->depth - n);
  544|       |
  545|       |        // TODO we should also shift out n bytes from read index since we avoid changing rd index !!
  546|       |        // However memmove() is expensive due to actual copying + wrapping consideration.
  547|       |        // Also race condition could happen anyway if read() is invoke while moving result in corrupted memory
  548|       |        // currently deliberately not implemented --> result in incorrect data read back
  549|      0|      } else {
  550|       |        // normal + single overflowed:
  551|       |        // Index is in the range of [0,2*depth) and thus detect and recoverable. Recovering is handled in read()
  552|       |        // Therefore we just increase write index
  553|       |        // we will correct (re-position) read index later on in fifo_read() function
  554|      0|      }
  555|      0|    }
  556|      0|  }
  557|       |
  558|  36.9k|  if (n) {
  ------------------
  |  Branch (558:7): [True: 36.9k, False: 0]
  ------------------
  559|  36.9k|    const uint16_t wr_ptr = idx2ptr(f->depth, wr_idx);
  560|  36.9k|    TU_LOG(TU_FIFO_DBG, "actual_n = %u, wr_ptr = %u", n, wr_ptr);
  561|       |
  562|       |#if CFG_TUSB_FIFO_HWFIFO_API
  563|       |    if (access_mode != NULL) {
  564|       |      hwff_push_n(f, buf8, n, wr_ptr, access_mode);
  565|       |    } else
  566|       |#endif
  567|  36.9k|    {
  568|  36.9k|      ff_push_n(f, buf8, n, wr_ptr);
  569|  36.9k|    }
  570|  36.9k|    f->wr_idx = advance_index(f->depth, wr_idx, n);
  571|       |
  572|  36.9k|    TU_LOG(TU_FIFO_DBG, "\tnew_wr = %u\r\n", f->wr_idx);
  573|  36.9k|  }
  574|       |
  575|  36.9k|  ff_unlock(f->mutex_wr);
  576|       |
  577|  36.9k|  return n;
  578|  36.9k|}
tusb_fifo.c:idx2ptr:
  415|  73.9k|TU_ATTR_ALWAYS_INLINE static inline uint16_t idx2ptr(uint16_t depth, uint16_t idx) {
  416|       |  // Only run at most 3 times since index is limit in the range of [0..2*depth)
  417|   110k|  while (idx >= depth) {
  ------------------
  |  Branch (417:10): [True: 36.9k, False: 73.9k]
  ------------------
  418|  36.9k|    idx -= depth;
  419|  36.9k|  }
  420|  73.9k|  return idx;
  421|  73.9k|}
tusb_fifo.c:ff_pull_n:
  379|  36.9k|static void ff_pull_n(const tu_fifo_t *f, void *app_buf, uint16_t n, uint16_t rd_ptr) {
  380|  36.9k|  uint16_t       lin_bytes  = f->depth - rd_ptr;
  381|  36.9k|  uint16_t       wrap_bytes = n - lin_bytes; // only used if wrapped
  382|  36.9k|  const uint8_t *ff_buf     = f->buffer + rd_ptr;
  383|       |
  384|       |  // single byte access
  385|  36.9k|  if (n <= lin_bytes) {
  ------------------
  |  Branch (385:7): [True: 36.9k, False: 0]
  ------------------
  386|       |    // Linear only
  387|  36.9k|    memcpy(app_buf, ff_buf, n);
  388|  36.9k|  } else {
  389|       |    // Wrap around
  390|      0|    memcpy(app_buf, ff_buf, lin_bytes);                            // linear part
  391|      0|    memcpy((uint8_t *)app_buf + lin_bytes, f->buffer, wrap_bytes); // wrapped part
  392|      0|  }
  393|  36.9k|}
tusb_fifo.c:advance_index:
  401|   116k|static uint16_t advance_index(uint16_t depth, uint16_t idx, uint16_t offset) {
  402|       |  // We limit the index space of p such that a correct wrap around happens
  403|       |  // Check for a wrap around or if we are in unused index space - This has to be checked first!!
  404|       |  // We are exploiting the wrap around to the correct index
  405|   116k|  uint16_t new_idx = (uint16_t)(idx + offset);
  406|   116k|  if ((idx > new_idx) || (new_idx >= 2 * depth)) {
  ------------------
  |  Branch (406:7): [True: 0, False: 116k]
  |  Branch (406:26): [True: 2.31k, False: 114k]
  ------------------
  407|  2.31k|    const uint16_t non_used_index_space = (uint16_t)(UINT16_MAX - (2 * depth - 1));
  408|  2.31k|    new_idx                             = (uint16_t)(new_idx + non_used_index_space);
  409|  2.31k|  }
  410|       |
  411|   116k|  return new_idx;
  412|   116k|}
tusb_fifo.c:ff_push_n:
  363|  36.9k|static void ff_push_n(const tu_fifo_t *f, const void *app_buf, uint16_t n, uint16_t wr_ptr) {
  364|  36.9k|  uint16_t lin_bytes  = f->depth - wr_ptr;
  365|  36.9k|  uint16_t wrap_bytes = n - lin_bytes;
  366|  36.9k|  uint8_t *ff_buf     = f->buffer + wr_ptr;
  367|       |
  368|  36.9k|  if (n <= lin_bytes) {
  ------------------
  |  Branch (368:7): [True: 36.9k, False: 0]
  ------------------
  369|       |    // Linear only case
  370|  36.9k|    memcpy(ff_buf, app_buf, n);
  371|  36.9k|  } else {
  372|       |    // Wrap around case
  373|      0|    memcpy(ff_buf, app_buf, lin_bytes);                                    // linear part
  374|      0|    memcpy(f->buffer, ((const uint8_t *)app_buf) + lin_bytes, wrap_bytes); // wrapped part
  375|      0|  }
  376|  36.9k|}

tusb_fifo.c:tu_ff_overflow_count:
  243|   116k|TU_ATTR_ALWAYS_INLINE static inline uint16_t tu_ff_overflow_count(uint16_t depth, uint16_t wr_idx, uint16_t rd_idx) {
  244|   116k|  const int32_t diff = (int32_t)wr_idx - (int32_t)rd_idx;
  245|   116k|  if (diff >= 0) {
  ------------------
  |  Branch (245:7): [True: 114k, False: 2.54k]
  ------------------
  246|   114k|    return (uint16_t)diff;
  247|   114k|  } else {
  248|  2.54k|    return (uint16_t)(2 * depth + diff);
  249|  2.54k|  }
  250|   116k|}
tusb_fifo.c:tu_ff_remaining_local:
  253|  36.9k|TU_ATTR_ALWAYS_INLINE static inline uint16_t tu_ff_remaining_local(uint16_t depth, uint16_t wr_idx, uint16_t rd_idx) {
  254|  36.9k|  const uint16_t ovf_count = tu_ff_overflow_count(depth, wr_idx, rd_idx);
  255|  36.9k|  return (depth > ovf_count) ? (depth - ovf_count) : 0;
  ------------------
  |  Branch (255:10): [True: 36.9k, False: 0]
  ------------------
  256|  36.9k|}
usbd.c:tu_fifo_read_n:
  192|  79.6k|TU_ATTR_ALWAYS_INLINE static inline uint16_t tu_fifo_read_n(tu_fifo_t *f, void *buffer, uint16_t n) {
  193|       |  return tu_fifo_read_n_access_mode(f, buffer, n, NULL);
  194|  79.6k|}
usbd.c:tu_fifo_write_n:
  205|  36.9k|TU_ATTR_ALWAYS_INLINE static inline uint16_t tu_fifo_write_n(tu_fifo_t *f, const void *data, uint16_t n) {
  206|       |  return tu_fifo_write_n_access_mode(f, data, n, NULL);
  207|  36.9k|}

usbd.c:tu_edpt_number:
  561|  9.08k|TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_edpt_number(uint8_t addr) {
  562|  9.08k|  return (uint8_t) (addr & TUSB_EPNUM_MASK);
  563|  9.08k|}
usbd.c:tu_edpt_dir:
  556|  8.86k|TU_ATTR_ALWAYS_INLINE static inline tusb_dir_t tu_edpt_dir(uint8_t addr) {
  557|  8.86k|  return (addr & TUSB_DIR_IN_MASK) ? TUSB_DIR_IN : TUSB_DIR_OUT;
  ------------------
  |  Branch (557:10): [True: 4.72k, False: 4.14k]
  ------------------
  558|  8.86k|}
dcd_fuzz.cc:_ZL12tu_edpt_addrhh:
  565|    211|TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_edpt_addr(uint8_t num, uint8_t dir) {
  566|    211|  return (uint8_t) (num | (dir == (uint8_t)TUSB_DIR_IN ? (uint8_t)TUSB_DIR_IN_MASK : 0u));
  ------------------
  |  Branch (566:28): [True: 211, False: 0]
  ------------------
  567|    211|}
dcd_fuzz.cc:_ZL11tu_edpt_dirh:
  556|  6.45k|TU_ATTR_ALWAYS_INLINE static inline tusb_dir_t tu_edpt_dir(uint8_t addr) {
  557|  6.45k|  return (addr & TUSB_DIR_IN_MASK) ? TUSB_DIR_IN : TUSB_DIR_OUT;
  ------------------
  |  Branch (557:10): [True: 4.60k, False: 1.85k]
  ------------------
  558|  6.45k|}

dcd_fuzz.cc:_ZL20dcd_event_bus_signalh13dcd_eventid_tb:
  181|  11.1k|TU_ATTR_ALWAYS_INLINE static inline void dcd_event_bus_signal (uint8_t rhport, dcd_eventid_t eid, bool in_isr) {
  182|  11.1k|  dcd_event_t event;
  183|  11.1k|  event.rhport = rhport;
  184|  11.1k|  event.event_id = eid;
  185|  11.1k|  dcd_event_handler(&event, in_isr);
  186|  11.1k|}
dcd_fuzz.cc:_ZL19dcd_event_bus_reseth12tusb_speed_tb:
  189|  10.3k|TU_ATTR_ALWAYS_INLINE static inline  void dcd_event_bus_reset (uint8_t rhport, tusb_speed_t speed, bool in_isr) {
  190|  10.3k|  dcd_event_t event;
  191|  10.3k|  event.rhport = rhport;
  192|  10.3k|  event.event_id = DCD_EVENT_BUS_RESET;
  193|  10.3k|  event.bus_reset.speed = speed;
  194|  10.3k|  dcd_event_handler(&event, in_isr);
  195|  10.3k|}
dcd_fuzz.cc:_ZL24dcd_event_setup_receivedhPKhb:
  198|  16.5k|TU_ATTR_ALWAYS_INLINE static inline void dcd_event_setup_received(uint8_t rhport, uint8_t const * setup, bool in_isr) {
  199|  16.5k|  dcd_event_t event;
  200|  16.5k|  event.rhport = rhport;
  201|  16.5k|  event.event_id = DCD_EVENT_SETUP_RECEIVED;
  202|  16.5k|  (void) memcpy(&event.setup_received, setup, sizeof(tusb_control_request_t));
  203|       |  // USB wire format is little-endian. Convert multi-byte fields to host byte order
  204|       |  // so the stack always sees correct values regardless of CPU endianness.
  205|  16.5k|  event.setup_received.wValue  = tu_le16toh(event.setup_received.wValue);
  ------------------
  |  |  253|  16.5k|  #define tu_le16toh(u16) (u16)
  ------------------
  206|  16.5k|  event.setup_received.wIndex  = tu_le16toh(event.setup_received.wIndex);
  ------------------
  |  |  253|  16.5k|  #define tu_le16toh(u16) (u16)
  ------------------
  207|  16.5k|  event.setup_received.wLength = tu_le16toh(event.setup_received.wLength);
  ------------------
  |  |  253|  16.5k|  #define tu_le16toh(u16) (u16)
  ------------------
  208|  16.5k|  dcd_event_handler(&event, in_isr);
  209|  16.5k|}

tud_event_hook_cb:
   29|  36.9k|TU_ATTR_WEAK void tud_event_hook_cb(uint8_t rhport, uint32_t eventid, bool in_isr) {
   30|  36.9k|  (void) rhport; (void) eventid; (void) in_isr;
   31|  36.9k|}
tud_descriptor_bos_cb:
   37|    201|TU_ATTR_WEAK uint8_t const* tud_descriptor_bos_cb(void) {
   38|       |  return NULL;
   39|    201|}
tud_descriptor_device_qualifier_cb:
   41|    198|TU_ATTR_WEAK uint8_t const* tud_descriptor_device_qualifier_cb(void) {
   42|       |  return NULL;
   43|    198|}
tud_descriptor_other_speed_configuration_cb:
   45|    197|TU_ATTR_WEAK uint8_t const* tud_descriptor_other_speed_configuration_cb(uint8_t index) {
   46|    197|  (void) index;
   47|       |  return NULL;
   48|    197|}
tud_umount_cb:
   53|  5.76k|TU_ATTR_WEAK void tud_umount_cb(void) {
   54|  5.76k|}
tud_suspend_cb:
   56|  3.28k|TU_ATTR_WEAK void tud_suspend_cb(bool remote_wakeup_en) {
   57|  3.28k|  (void) remote_wakeup_en;
   58|  3.28k|}
tud_resume_cb:
   60|  1.05k|TU_ATTR_WEAK void tud_resume_cb(void) {
   61|  1.05k|}
tud_vendor_control_xfer_cb:
   63|  1.76k|TU_ATTR_WEAK bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const* request) {
   64|  1.76k|  (void) rhport; (void) stage; (void) request;
   65|       |  return false;
   66|  1.76k|}
usbd_app_driver_get_cb:
  437|      1|TU_ATTR_WEAK usbd_class_driver_t const* usbd_app_driver_get_cb(uint8_t* driver_count) {
  438|      1|  *driver_count = 0;
  439|       |  return NULL;
  440|      1|}
tud_inited:
  510|  43.6k|bool tud_inited(void) {
  511|  43.6k|  return _usbd_rhport != RHPORT_INVALID;
  512|  43.6k|}
tud_rhport_init:
  518|  1.00k|bool tud_rhport_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
  519|  1.00k|  if (tud_inited()) {
  ------------------
  |  Branch (519:7): [True: 1.00k, False: 1]
  ------------------
  520|  1.00k|    return true; // skip if already initialized
  521|  1.00k|  }
  522|      1|  TU_ASSERT(rh_init);
  ------------------
  |  |  112|      1|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  112|      1|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  112|      1|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  108|      1|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  104|      1|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  105|      1|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   54|      0|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (54:41): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   77|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (77:40): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (105:10): [True: 0, False: 1]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  106|      1|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:11): [Folded, False: 1]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  523|       | #if CFG_TUSB_DEBUG >= CFG_TUD_LOG_LEVEL
  524|       |  char const* speed_str = 0;
  525|       |  switch (rh_init->speed) {
  526|       |    case TUSB_SPEED_HIGH:
  527|       |      speed_str = "High";
  528|       |    break;
  529|       |    case TUSB_SPEED_FULL:
  530|       |      speed_str = "Full";
  531|       |    break;
  532|       |    case TUSB_SPEED_LOW:
  533|       |      speed_str = "Low";
  534|       |    break;
  535|       |    case TUSB_SPEED_AUTO:
  536|       |      speed_str = "Auto";
  537|       |    break;
  538|       |  default:
  539|       |    break;
  540|       |  }
  541|       |  TU_LOG_USBD("USBD init on controller %u, speed = %s\r\n", rhport, speed_str);
  542|       |  TU_LOG_INT(CFG_TUD_LOG_LEVEL, sizeof(usbd_device_t));
  543|       |  TU_LOG_INT(CFG_TUD_LOG_LEVEL, sizeof(dcd_event_t));
  544|       |  TU_LOG_INT(CFG_TUD_LOG_LEVEL, sizeof(tu_fifo_t));
  545|       |  TU_LOG_INT(CFG_TUD_LOG_LEVEL, sizeof(tu_edpt_stream_t));
  546|       |#endif
  547|       |
  548|      1|  tu_varclr(&_usbd_dev);
  ------------------
  |  |   96|      1|#define tu_varclr(_var)          tu_memclr(_var, sizeof(*(_var)))
  |  |  ------------------
  |  |  |  |   95|      1|#define tu_memclr(buffer, size)  (void) memset((buffer), 0, (size))
  |  |  ------------------
  ------------------
  549|      1|  _usbd_queued_setup = 0;
  550|       |
  551|      1|  osal_spin_init(&_usbd_spin);
  552|       |
  553|       |#if OSAL_MUTEX_REQUIRED
  554|       |  // Init device mutex
  555|       |  _usbd_mutex = osal_mutex_create(&_ubsd_mutexdef);
  556|       |  TU_ASSERT(_usbd_mutex);
  557|       |#endif
  558|       |
  559|       |  // Init device queue & task
  560|      1|  _usbd_q = osal_queue_create(&_usbd_qdef);
  561|      1|  TU_ASSERT(_usbd_q);
  ------------------
  |  |  112|      1|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  112|      1|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  112|      1|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  108|      1|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  104|      1|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  105|      1|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   54|      0|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (54:41): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   77|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (77:40): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (105:10): [True: 0, False: 1]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  106|      1|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:11): [Folded, False: 1]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  562|       |
  563|       |  // Get application driver if available
  564|      1|  _app_driver = usbd_app_driver_get_cb(&_app_driver_count);
  565|      1|  TU_ASSERT(_app_driver_count + _builtin_driver_count <= UINT8_MAX);
  ------------------
  |  |  112|      1|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  112|      1|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  112|      1|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  108|      1|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  104|      1|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  105|      1|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   54|      0|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (54:41): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   77|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (77:40): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (105:10): [True: 0, False: 1]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  106|      1|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:11): [Folded, False: 1]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  566|       |
  567|       |  // Init class drivers
  568|      2|  for (uint8_t i = 0; i < TOTAL_DRIVER_COUNT; i++) {
  ------------------
  |  |  369|      2|#define TOTAL_DRIVER_COUNT    ((uint8_t) (_app_driver_count + _builtin_driver_count))
  ------------------
  |  Branch (568:23): [True: 1, False: 1]
  ------------------
  569|      1|    usbd_class_driver_t const* driver = get_driver(i);
  570|      1|    TU_ASSERT(driver && driver->init);
  ------------------
  |  |  112|      1|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  112|      1|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  112|      1|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  108|      1|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  104|      1|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  105|      2|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   54|      0|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (54:41): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   77|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (77:40): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (105:12): [True: 1, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  Branch (105:12): [True: 1, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  106|      1|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:11): [Folded, False: 1]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  571|      1|    TU_LOG_USBD("%s init\r\n", driver->name);
  572|      1|    driver->init();
  573|      1|  }
  574|       |
  575|      1|  _usbd_rhport = rhport;
  576|       |
  577|       |  // Init device controller driver
  578|      1|  TU_ASSERT(dcd_init(rhport, rh_init));
  ------------------
  |  |  112|      1|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  112|      1|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  112|      1|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  108|      1|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  104|      1|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  105|      1|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   54|      0|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (54:41): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   77|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (77:40): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (105:10): [True: 0, False: 1]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  106|      1|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:11): [Folded, False: 1]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  579|      1|  dcd_int_enable(rhport);
  580|       |
  581|       |  return true;
  582|      1|}
tud_task_ext:
  668|  42.6k|void tud_task_ext(uint32_t timeout_ms, bool in_isr) {
  669|  42.6k|  (void) in_isr; // not implemented yet
  670|       |
  671|       |  // Skip if stack is not initialized
  672|  42.6k|  if (!tud_inited()) {
  ------------------
  |  Branch (672:7): [True: 0, False: 42.6k]
  ------------------
  673|      0|    return;
  674|      0|  }
  675|       |
  676|       |  // Loop until there are no more events in the queue or CFG_TUD_TASK_EVENTS_PER_RUN is reached
  677|  79.6k|  for (unsigned epr = 0;; epr++) {
  678|  79.6k|#if CFG_TUD_TASK_EVENTS_PER_RUN > 0
  679|  79.6k|    if (epr >= CFG_TUD_TASK_EVENTS_PER_RUN) {
  ------------------
  |  |  582|  79.6k|  #define CFG_TUD_TASK_EVENTS_PER_RUN  16
  ------------------
  |  Branch (679:9): [True: 0, False: 79.6k]
  ------------------
  680|      0|      TU_LOG_USBD("USBD event limit (" TU_XSTRING(CFG_TUD_TASK_EVENTS_PER_RUN) ") reached\r\n");
  681|      0|      break;
  682|      0|    }
  683|  79.6k|#endif
  684|  79.6k|    dcd_event_t event;
  685|  79.6k|    if (!osal_queue_receive(_usbd_q, &event, timeout_ms)) {
  ------------------
  |  Branch (685:9): [True: 42.6k, False: 36.9k]
  ------------------
  686|  42.6k|      return;
  687|  42.6k|    }
  688|       |
  689|       |#if CFG_TUSB_DEBUG >= CFG_TUD_LOG_LEVEL
  690|       |    if (event.event_id == DCD_EVENT_SETUP_RECEIVED) {
  691|       |      TU_LOG_USBD("\r\n"); // extra line for setup
  692|       |    }
  693|       |    TU_LOG_USBD("USBD %s ", event.event_id < DCD_EVENT_COUNT ? _usbd_event_str[event.event_id] : "CORRUPTED");
  694|       |#endif
  695|       |
  696|  36.9k|    switch (event.event_id) {
  697|  10.3k|      case DCD_EVENT_BUS_RESET:
  ------------------
  |  Branch (697:7): [True: 10.3k, False: 26.6k]
  ------------------
  698|  10.3k|        TU_LOG_USBD(": %s Speed\r\n", tu_str_speed[event.bus_reset.speed]);
  699|  10.3k|        usbd_reset(event.rhport);
  700|  10.3k|        _usbd_dev.speed = event.bus_reset.speed;
  701|  10.3k|        break;
  702|       |
  703|  5.76k|      case DCD_EVENT_UNPLUGGED:
  ------------------
  |  Branch (703:7): [True: 5.76k, False: 31.2k]
  ------------------
  704|  5.76k|        TU_LOG_USBD("\r\n");
  705|  5.76k|        usbd_reset(event.rhport);
  706|  5.76k|        tud_umount_cb();
  707|  5.76k|        break;
  708|       |
  709|  16.5k|      case DCD_EVENT_SETUP_RECEIVED:
  ------------------
  |  Branch (709:7): [True: 16.5k, False: 20.4k]
  ------------------
  710|  16.5k|        if (_usbd_queued_setup == 0) {
  ------------------
  |  Branch (710:13): [True: 0, False: 16.5k]
  ------------------
  711|      0|          break;
  712|      0|        }
  713|  16.5k|        _usbd_queued_setup--;
  714|  16.5k|        TU_LOG_BUF(CFG_TUD_LOG_LEVEL, &event.setup_received, 8);
  715|  16.5k|        if (_usbd_queued_setup != 0) {
  ------------------
  |  Branch (715:13): [True: 0, False: 16.5k]
  ------------------
  716|      0|          TU_LOG_USBD("  Skipped since there is other SETUP in queue\r\n");
  717|      0|          break;
  718|      0|        }
  719|       |
  720|       |        // Mark as connected after receiving 1st setup packet.
  721|       |        // But it is easier to set it every time instead of wasting time to check then set
  722|  16.5k|        _usbd_dev.connected = 1;
  723|       |
  724|       |        // reset ep state
  725|  16.5k|        _usbd_dev.ep_status[0][TUSB_DIR_OUT] = 0;
  726|  16.5k|        _usbd_dev.ep_status[0][TUSB_DIR_IN] = 0;
  727|       |
  728|       |        // Process control request
  729|  16.5k|        if (!process_setup_received(event.rhport, &event.setup_received)) {
  ------------------
  |  Branch (729:13): [True: 9.92k, False: 6.60k]
  ------------------
  730|  9.92k|          TU_LOG_USBD("  Stall EP0\r\n");
  731|       |          // Failed -> stall both control endpoint IN and OUT
  732|  9.92k|          dcd_edpt_stall(event.rhport, TU_EP0_OUT);
  733|  9.92k|          dcd_edpt_stall(event.rhport, TU_EP0_IN);
  734|  9.92k|        }
  735|  16.5k|        break;
  736|       |
  737|      0|      case DCD_EVENT_XFER_COMPLETE: {
  ------------------
  |  Branch (737:7): [True: 0, False: 36.9k]
  ------------------
  738|       |        // Invoke the class callback associated with the endpoint address
  739|      0|        uint8_t const ep_addr = event.xfer_complete.ep_addr;
  740|      0|        uint8_t const epnum = tu_edpt_number(ep_addr);
  741|      0|        uint8_t const ep_dir = tu_edpt_dir(ep_addr);
  742|       |
  743|      0|        TU_LOG_USBD("on EP %02X with %u bytes\r\n", ep_addr, (unsigned int) event.xfer_complete.len);
  744|       |
  745|       |        // Clear busy + claimed
  746|      0|        _usbd_dev.ep_status[epnum][ep_dir] &= (uint8_t) ~(TU_EDPT_STATE_BUSY | TU_EDPT_STATE_CLAIMED);
  ------------------
  |  |   31|      0|#define TU_EDPT_STATE_BUSY    0x01u
  ------------------
                      _usbd_dev.ep_status[epnum][ep_dir] &= (uint8_t) ~(TU_EDPT_STATE_BUSY | TU_EDPT_STATE_CLAIMED);
  ------------------
  |  |   33|      0|#define TU_EDPT_STATE_CLAIMED 0x04u
  ------------------
  747|       |
  748|      0|        if (0 == epnum) {
  ------------------
  |  Branch (748:13): [True: 0, False: 0]
  ------------------
  749|      0|          usbd_control_xfer_cb(event.rhport, ep_addr, (xfer_result_t) event.xfer_complete.result, event.xfer_complete.len);
  750|      0|        } else {
  751|      0|          usbd_class_driver_t const* driver = get_driver(_usbd_dev.ep2drv[epnum][ep_dir]);
  752|      0|          TU_ASSERT(driver,);
  ------------------
  |  |  112|      0|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  112|      0|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  112|      0|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  109|      0|#define TU_ASSERT_2ARGS(_cond, _ret)   TU_ASSERT_DEFINE(_cond, _ret)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  104|      0|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  105|      0|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   54|      0|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (54:41): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   77|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (77:40): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (105:10): [True: 0, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  106|      0|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:11): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  753|       |
  754|      0|          TU_LOG_USBD("  %s xfer callback\r\n", driver->name);
  755|      0|          driver->xfer_cb(event.rhport, ep_addr, (xfer_result_t) event.xfer_complete.result, event.xfer_complete.len);
  756|      0|        }
  757|      0|        break;
  758|      0|      }
  759|       |
  760|  3.28k|      case DCD_EVENT_SUSPEND:
  ------------------
  |  Branch (760:7): [True: 3.28k, False: 33.7k]
  ------------------
  761|       |        // NOTE: When plugging/unplugging device, the D+/D- state are unstable and
  762|       |        // can accidentally meet the SUSPEND condition ( Bus Idle for 3ms ), which result in a series of event
  763|       |        // e.g suspend -> resume -> unplug/plug. Skip suspend/resume if not connected
  764|  3.28k|        if (_usbd_dev.connected) {
  ------------------
  |  Branch (764:13): [True: 3.28k, False: 0]
  ------------------
  765|  3.28k|          TU_LOG_USBD(": Remote Wakeup = %u\r\n", _usbd_dev.remote_wakeup_en);
  766|  3.28k|          tud_suspend_cb(_usbd_dev.remote_wakeup_en);
  767|  3.28k|        } else {
  768|      0|          TU_LOG_USBD(" Skipped\r\n");
  769|      0|        }
  770|  3.28k|        break;
  771|       |
  772|  1.05k|      case DCD_EVENT_RESUME:
  ------------------
  |  Branch (772:7): [True: 1.05k, False: 35.9k]
  ------------------
  773|  1.05k|        if (_usbd_dev.connected) {
  ------------------
  |  Branch (773:13): [True: 1.05k, False: 0]
  ------------------
  774|  1.05k|          TU_LOG_USBD("\r\n");
  775|  1.05k|          tud_resume_cb();
  776|  1.05k|        } else {
  777|      0|          TU_LOG_USBD(" Skipped\r\n");
  778|      0|        }
  779|  1.05k|        break;
  780|       |
  781|      0|      case USBD_EVENT_FUNC_CALL:
  ------------------
  |  Branch (781:7): [True: 0, False: 36.9k]
  ------------------
  782|      0|        TU_LOG_USBD("\r\n");
  783|      0|        if (event.func_call.func != NULL) {
  ------------------
  |  Branch (783:13): [True: 0, False: 0]
  ------------------
  784|      0|          event.func_call.func(event.func_call.param);
  785|      0|        }
  786|      0|        break;
  787|       |
  788|      0|      case DCD_EVENT_SOF:
  ------------------
  |  Branch (788:7): [True: 0, False: 36.9k]
  ------------------
  789|      0|        if (tu_bit_test(_usbd_dev.sof_consumer, SOF_CONSUMER_USER)) {
  ------------------
  |  Branch (789:13): [True: 0, False: 0]
  ------------------
  790|      0|          TU_LOG_USBD("\r\n");
  791|      0|          tud_sof_cb(event.sof.frame_count);
  792|      0|        }
  793|      0|      break;
  794|       |
  795|      0|      default:
  ------------------
  |  Branch (795:7): [True: 0, False: 36.9k]
  ------------------
  796|      0|        TU_BREAKPOINT();
  ------------------
  |  |   77|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  ------------------
  |  |  |  Branch (77:40): [Folded, False: 0]
  |  |  ------------------
  ------------------
  797|      0|        break;
  798|  36.9k|    }
  799|       |
  800|       |    // allow to exit tud_task() if there is no event in the next run
  801|  36.9k|    timeout_ms = 0;
  802|  36.9k|  }
  803|  42.6k|}
tud_control_status:
  849|  2.60k|bool tud_control_status(uint8_t rhport, const tusb_control_request_t* request) {
  850|       |  // _usbd_dev.ctrl_xfer fields are pre-initialized at process_setup_received entry
  851|  2.60k|  (void) request;
  852|  2.60k|  return status_stage_xact(rhport, status_stage_ep(&_usbd_dev.ctrl_xfer.request));
  853|  2.60k|}
tud_control_xfer:
  856|  3.63k|bool tud_control_xfer(uint8_t rhport, const tusb_control_request_t* request, void* buffer, uint16_t len) {
  857|       |  // _usbd_dev.ctrl_xfer.request and reset fields are pre-initialized at process_setup_received entry
  858|  3.63k|  (void) request;
  859|  3.63k|  usbd_control_xfer_t* const ctrl_xfer = &_usbd_dev.ctrl_xfer;
  860|  3.63k|  ctrl_xfer->buffer = (uint8_t*) buffer;
  861|  3.63k|  ctrl_xfer->data_len = tu_min16(len, ctrl_xfer->request.wLength);
  862|       |
  863|  3.63k|  if (ctrl_xfer->request.wLength > 0U) {
  ------------------
  |  Branch (863:7): [True: 2.26k, False: 1.37k]
  ------------------
  864|  2.26k|    if (ctrl_xfer->data_len > 0U) {
  ------------------
  |  Branch (864:9): [True: 2.26k, False: 0]
  ------------------
  865|  2.26k|      TU_ASSERT(buffer);
  ------------------
  |  |  112|  2.26k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  112|  2.26k|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  112|  2.26k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  108|  2.26k|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  104|  2.26k|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  105|  2.26k|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   54|      0|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (54:41): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   77|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (77:40): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (105:10): [True: 0, False: 2.26k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  106|  2.26k|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:11): [Folded, False: 2.26k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  866|  2.26k|    }
  867|  2.26k|    TU_ASSERT(data_stage_xact(rhport));
  ------------------
  |  |  112|  2.26k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  112|  2.26k|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  112|  2.26k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  108|  2.26k|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  104|  2.26k|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  105|  2.26k|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   54|  1.31k|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (54:41): [Folded, False: 1.31k]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   77|  1.31k|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (77:40): [Folded, False: 1.31k]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (105:10): [True: 1.31k, False: 947]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  106|  2.26k|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:11): [Folded, False: 947]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  868|  2.26k|  } else {
  869|       |    // wLength == 0: Status stage is always IN per USB 2.0 §9.3.1
  870|  1.37k|    TU_ASSERT(status_stage_xact(rhport, TU_EP0_IN));
  ------------------
  |  |  112|  1.37k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  112|  1.37k|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  112|  1.37k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  108|  1.37k|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  104|  1.37k|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  105|  1.37k|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   54|    512|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (54:41): [Folded, False: 512]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   77|    512|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (77:40): [Folded, False: 512]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (105:10): [True: 512, False: 863]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  106|  1.37k|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:11): [Folded, False: 863]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  871|  1.37k|  }
  872|       |
  873|  1.81k|  return true;
  874|  3.63k|}
dcd_event_handler:
 1371|  37.9k|TU_ATTR_FAST_FUNC void dcd_event_handler(dcd_event_t const* event, bool in_isr) {
 1372|  37.9k|  bool send = false;
 1373|  37.9k|  switch (event->event_id) {
 1374|  5.76k|    case DCD_EVENT_UNPLUGGED:
  ------------------
  |  Branch (1374:5): [True: 5.76k, False: 32.2k]
  ------------------
 1375|  5.76k|      _usbd_dev.connected = 0;
 1376|  5.76k|      _usbd_dev.addressed = 0;
 1377|  5.76k|      _usbd_dev.cfg_num = 0;
 1378|  5.76k|      _usbd_dev.suspended = 0;
 1379|  5.76k|      send = true;
 1380|  5.76k|      break;
 1381|       |
 1382|  3.70k|    case DCD_EVENT_SUSPEND:
  ------------------
  |  Branch (1382:5): [True: 3.70k, False: 34.2k]
  ------------------
 1383|       |      // NOTE: When plugging/unplugging device, the D+/D- state are unstable and
 1384|       |      // can accidentally meet the SUSPEND condition ( Bus Idle for 3ms ).
 1385|       |      // In addition, some MCUs such as SAMD or boards that haven no VBUS detection cannot distinguish
 1386|       |      // suspended vs disconnected. We will skip handling SUSPEND/RESUME event if not currently connected
 1387|  3.70k|      if (_usbd_dev.connected) {
  ------------------
  |  Branch (1387:11): [True: 3.28k, False: 420]
  ------------------
 1388|  3.28k|        _usbd_dev.suspended = 1;
 1389|  3.28k|        send = true;
 1390|  3.28k|      }
 1391|  3.70k|      break;
 1392|       |
 1393|  1.64k|    case DCD_EVENT_RESUME:
  ------------------
  |  Branch (1393:5): [True: 1.64k, False: 36.3k]
  ------------------
 1394|       |      // skip event if not connected (especially required for SAMD)
 1395|  1.64k|      if (_usbd_dev.connected) {
  ------------------
  |  Branch (1395:11): [True: 1.05k, False: 588]
  ------------------
 1396|  1.05k|        _usbd_dev.suspended = 0;
 1397|  1.05k|        send = true;
 1398|  1.05k|      }
 1399|  1.64k|      break;
 1400|       |
 1401|      0|    case DCD_EVENT_SOF:
  ------------------
  |  Branch (1401:5): [True: 0, False: 37.9k]
  ------------------
 1402|       |      // SOF driver handler in ISR context
 1403|      0|      for (uint8_t i = 0; i < TOTAL_DRIVER_COUNT; i++) {
  ------------------
  |  |  369|      0|#define TOTAL_DRIVER_COUNT    ((uint8_t) (_app_driver_count + _builtin_driver_count))
  ------------------
  |  Branch (1403:27): [True: 0, False: 0]
  ------------------
 1404|      0|        usbd_class_driver_t const* driver = get_driver(i);
 1405|      0|        if (driver && driver->sof) {
  ------------------
  |  Branch (1405:13): [True: 0, False: 0]
  |  Branch (1405:23): [True: 0, False: 0]
  ------------------
 1406|      0|          driver->sof(event->rhport, event->sof.frame_count);
 1407|      0|        }
 1408|      0|      }
 1409|       |
 1410|       |      // Some MCUs after running dcd_remote_wakeup() does not have way to detect the end of remote wakeup
 1411|       |      // which last 1-15 ms. DCD can use SOF as a clear indicator that bus is back to operational
 1412|      0|      if (_usbd_dev.suspended) {
  ------------------
  |  Branch (1412:11): [True: 0, False: 0]
  ------------------
 1413|      0|        _usbd_dev.suspended = 0;
 1414|       |
 1415|      0|        dcd_event_t const event_resume = {.rhport = event->rhport, .event_id = DCD_EVENT_RESUME};
 1416|      0|        queue_event(&event_resume, in_isr);
 1417|      0|      }
 1418|       |
 1419|      0|      if (tu_bit_test(_usbd_dev.sof_consumer, SOF_CONSUMER_USER)) {
  ------------------
  |  Branch (1419:11): [True: 0, False: 0]
  ------------------
 1420|      0|        dcd_event_t const event_sof = {.rhport = event->rhport, .event_id = DCD_EVENT_SOF, .sof.frame_count = event->sof.frame_count};
 1421|      0|        queue_event(&event_sof, in_isr);
 1422|      0|      }
 1423|      0|      break;
 1424|       |
 1425|  16.5k|    case DCD_EVENT_SETUP_RECEIVED:
  ------------------
  |  Branch (1425:5): [True: 16.5k, False: 21.4k]
  ------------------
 1426|  16.5k|      _usbd_queued_setup++;
 1427|  16.5k|      send = true;
 1428|  16.5k|      break;
 1429|       |
 1430|      0|    case DCD_EVENT_XFER_COMPLETE: {
  ------------------
  |  Branch (1430:5): [True: 0, False: 37.9k]
  ------------------
 1431|       |      // Invoke the class callback associated with the endpoint address
 1432|      0|      uint8_t const ep_addr = event->xfer_complete.ep_addr;
 1433|      0|      uint8_t const epnum = tu_edpt_number(ep_addr);
 1434|      0|      uint8_t const ep_dir = tu_edpt_dir(ep_addr);
 1435|       |
 1436|      0|      send = true;
 1437|      0|      if(epnum > 0) {
  ------------------
  |  Branch (1437:10): [True: 0, False: 0]
  ------------------
 1438|      0|        usbd_class_driver_t const* driver = get_driver(_usbd_dev.ep2drv[epnum][ep_dir]);
 1439|       |
 1440|      0|        if (driver && driver->xfer_isr) {
  ------------------
  |  Branch (1440:13): [True: 0, False: 0]
  |  Branch (1440:23): [True: 0, False: 0]
  ------------------
 1441|       |          // Clear busy + claimed
 1442|      0|          _usbd_dev.ep_status[epnum][ep_dir] &= (uint8_t) ~(TU_EDPT_STATE_BUSY | TU_EDPT_STATE_CLAIMED);
  ------------------
  |  |   31|      0|#define TU_EDPT_STATE_BUSY    0x01u
  ------------------
                        _usbd_dev.ep_status[epnum][ep_dir] &= (uint8_t) ~(TU_EDPT_STATE_BUSY | TU_EDPT_STATE_CLAIMED);
  ------------------
  |  |   33|      0|#define TU_EDPT_STATE_CLAIMED 0x04u
  ------------------
 1443|       |
 1444|      0|          send = !driver->xfer_isr(event->rhport, ep_addr, (xfer_result_t) event->xfer_complete.result, event->xfer_complete.len);
 1445|       |
 1446|       |          // xfer_isr() is deferred to xfer_cb(), revert busy/claimed status
 1447|      0|          if (send) {
  ------------------
  |  Branch (1447:15): [True: 0, False: 0]
  ------------------
 1448|       |            // set busy + claimed
 1449|      0|            _usbd_dev.ep_status[epnum][ep_dir] |= (TU_EDPT_STATE_BUSY | TU_EDPT_STATE_CLAIMED);
  ------------------
  |  |   31|      0|#define TU_EDPT_STATE_BUSY    0x01u
  ------------------
                          _usbd_dev.ep_status[epnum][ep_dir] |= (TU_EDPT_STATE_BUSY | TU_EDPT_STATE_CLAIMED);
  ------------------
  |  |   33|      0|#define TU_EDPT_STATE_CLAIMED 0x04u
  ------------------
 1450|      0|          }
 1451|      0|        }
 1452|      0|      }
 1453|      0|      break;
 1454|      0|    }
 1455|       |
 1456|  10.3k|    default:
  ------------------
  |  Branch (1456:5): [True: 10.3k, False: 27.6k]
  ------------------
 1457|  10.3k|      send = true;
 1458|  10.3k|      break;
 1459|  37.9k|  }
 1460|       |
 1461|  37.9k|  if (send) {
  ------------------
  |  Branch (1461:7): [True: 36.9k, False: 1.00k]
  ------------------
 1462|  36.9k|    queue_event(event, in_isr);
 1463|  36.9k|  }
 1464|  37.9k|}
usbd_int_set:
 1470|   186k|void usbd_int_set(bool enabled) {
 1471|   186k|  if (enabled) {
  ------------------
  |  Branch (1471:7): [True: 93.2k, False: 93.2k]
  ------------------
 1472|  93.2k|    dcd_int_enable(_usbd_rhport);
 1473|  93.2k|  } else {
 1474|  93.2k|    dcd_int_disable(_usbd_rhport);
 1475|  93.2k|  }
 1476|   186k|}
usbd_open_edpt_pair:
 1487|    212|                         uint8_t *ep_in) {
 1488|    212|  for (int i = 0; i < ep_count; i++) {
  ------------------
  |  Branch (1488:19): [True: 212, False: 0]
  ------------------
 1489|    212|    const tusb_desc_endpoint_t *desc_ep = (const tusb_desc_endpoint_t *)p_desc;
 1490|       |
 1491|    212|    TU_ASSERT(TUSB_DESC_ENDPOINT == desc_ep->bDescriptorType && xfer_type == desc_ep->bmAttributes.xfer);
  ------------------
  |  |  112|    212|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  112|    212|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  112|    212|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  108|    212|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  104|    212|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  105|    424|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   54|      0|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (54:41): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   77|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (77:40): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (105:12): [True: 212, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  Branch (105:12): [True: 212, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  106|    212|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:11): [Folded, False: 212]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1492|    212|    TU_ASSERT(usbd_edpt_open(rhport, desc_ep));
  ------------------
  |  |  112|    212|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  112|    212|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  112|    212|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  108|    212|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  104|    212|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  105|    212|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   54|    212|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (54:41): [Folded, False: 212]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   77|    212|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (77:40): [Folded, False: 212]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (105:10): [True: 212, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  106|    212|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:11): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1493|       |
 1494|      0|    if (tu_edpt_dir(desc_ep->bEndpointAddress) == TUSB_DIR_IN) {
  ------------------
  |  Branch (1494:9): [True: 0, False: 0]
  ------------------
 1495|      0|      (*ep_in) = desc_ep->bEndpointAddress;
 1496|      0|    } else {
 1497|      0|      (*ep_out) = desc_ep->bEndpointAddress;
 1498|      0|    }
 1499|       |
 1500|      0|    p_desc = tu_desc_next(p_desc);
 1501|      0|  }
 1502|       |
 1503|      0|  return true;
 1504|    212|}
usbd_edpt_open:
 1522|    212|bool usbd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const* desc_ep) {
 1523|    212|  rhport = _usbd_rhport;
 1524|       |
 1525|    212|  TU_ASSERT(tu_edpt_number(desc_ep->bEndpointAddress) < CFG_TUD_ENDPPOINT_MAX);
  ------------------
  |  |  112|    212|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  112|    212|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  112|    212|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  108|    212|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  104|    212|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  105|    212|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   54|    212|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (54:41): [Folded, False: 212]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   77|    212|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (77:40): [Folded, False: 212]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (105:10): [True: 212, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  106|    212|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:11): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1526|      0|  TU_ASSERT(tu_edpt_validate(desc_ep, (tusb_speed_t)_usbd_dev.speed));
  ------------------
  |  |  112|      0|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  112|      0|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  112|      0|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  108|      0|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  104|      0|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  105|      0|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   54|      0|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (54:41): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   77|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (77:40): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (105:10): [True: 0, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  106|      0|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:11): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1527|       |
 1528|      0|  return dcd_edpt_open(rhport, desc_ep);
 1529|      0|}
usbd_edpt_xfer:
 1550|  6.24k|bool usbd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t* buffer, uint16_t total_bytes, bool is_isr) {
 1551|  6.24k|  rhport = _usbd_rhport;
 1552|       |
 1553|  6.24k|  uint8_t const epnum = tu_edpt_number(ep_addr);
 1554|  6.24k|  uint8_t const dir = tu_edpt_dir(ep_addr);
 1555|       |
 1556|       |  // TODO skip ready() check for now since enumeration also use this API
 1557|       |  // TU_VERIFY(tud_ready());
 1558|       |
 1559|  6.24k|  TU_LOG_USBD("  Queue EP %02X with %u bytes ...\r\n", ep_addr, total_bytes);
 1560|       |#if CFG_TUD_LOG_LEVEL >= 3
 1561|       |  if(dir == TUSB_DIR_IN) {
 1562|       |    TU_LOG_MEM(CFG_TUD_LOG_LEVEL, buffer, total_bytes, 2);
 1563|       |  }
 1564|       |#endif
 1565|       |
 1566|       |  // Attempt to transfer on a busy endpoint, sound like an race condition !
 1567|  6.24k|  TU_ASSERT((_usbd_dev.ep_status[epnum][dir] & TU_EDPT_STATE_BUSY) == 0);
  ------------------
  |  |  112|  6.24k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  112|  6.24k|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  112|  6.24k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  108|  6.24k|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  104|  6.24k|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  105|  6.24k|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   54|      0|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (54:41): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   77|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (77:40): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (105:10): [True: 0, False: 6.24k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  106|  6.24k|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:11): [Folded, False: 6.24k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1568|       |
 1569|       |  // Set busy first since the actual transfer can be complete before dcd_edpt_xfer()
 1570|       |  // could return and USBD task can preempt and clear the busy
 1571|  6.24k|  _usbd_dev.ep_status[epnum][dir] |= TU_EDPT_STATE_BUSY;
  ------------------
  |  |   31|  6.24k|#define TU_EDPT_STATE_BUSY    0x01u
  ------------------
 1572|       |
 1573|  6.24k|  if (dcd_edpt_xfer(rhport, ep_addr, buffer, total_bytes, is_isr)) {
  ------------------
  |  Branch (1573:7): [True: 3.11k, False: 3.12k]
  ------------------
 1574|  3.11k|    return true;
 1575|  3.12k|  } else {
 1576|       |    // DCD error, mark endpoint as ready to allow next transfer
 1577|  3.12k|    _usbd_dev.ep_status[epnum][dir] &= (uint8_t) ~(TU_EDPT_STATE_BUSY | TU_EDPT_STATE_CLAIMED);
  ------------------
  |  |   31|  3.12k|#define TU_EDPT_STATE_BUSY    0x01u
  ------------------
                  _usbd_dev.ep_status[epnum][dir] &= (uint8_t) ~(TU_EDPT_STATE_BUSY | TU_EDPT_STATE_CLAIMED);
  ------------------
  |  |   33|  3.12k|#define TU_EDPT_STATE_CLAIMED 0x04u
  ------------------
 1578|  3.12k|    TU_LOG_USBD("FAILED\r\n");
 1579|  3.12k|    TU_BREAKPOINT();
  ------------------
  |  |   77|  3.12k|  #define TU_BREAKPOINT() do {} while (0)
  |  |  ------------------
  |  |  |  Branch (77:40): [Folded, False: 3.12k]
  |  |  ------------------
  ------------------
 1580|       |    return false;
 1581|  3.12k|  }
 1582|  6.24k|}
usbd_edpt_stall:
 1633|    216|void usbd_edpt_stall(uint8_t rhport, uint8_t ep_addr) {
 1634|    216|  rhport = _usbd_rhport;
 1635|       |
 1636|    216|  uint8_t const epnum = tu_edpt_number(ep_addr);
 1637|    216|  uint8_t const dir = tu_edpt_dir(ep_addr);
 1638|       |
 1639|       |  // only stalled if currently cleared
 1640|    216|  TU_LOG_USBD("    Stall EP %02X\r\n", ep_addr);
 1641|    216|  dcd_edpt_stall(rhport, ep_addr);
 1642|    216|  _usbd_dev.ep_status[epnum][dir] |= (TU_EDPT_STATE_STALLED | TU_EDPT_STATE_BUSY);
  ------------------
  |  |   32|    216|#define TU_EDPT_STATE_STALLED 0x02u
  ------------------
                _usbd_dev.ep_status[epnum][dir] |= (TU_EDPT_STATE_STALLED | TU_EDPT_STATE_BUSY);
  ------------------
  |  |   31|    216|#define TU_EDPT_STATE_BUSY    0x01u
  ------------------
 1643|    216|}
usbd_edpt_clear_stall:
 1645|    219|void usbd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr) {
 1646|    219|  rhport = _usbd_rhport;
 1647|       |
 1648|    219|  uint8_t const epnum = tu_edpt_number(ep_addr);
 1649|    219|  uint8_t const dir = tu_edpt_dir(ep_addr);
 1650|       |
 1651|       |  // only clear if currently stalled
 1652|    219|  TU_LOG_USBD("    Clear Stall EP %02X\r\n", ep_addr);
 1653|    219|  dcd_edpt_clear_stall(rhport, ep_addr);
 1654|    219|  _usbd_dev.ep_status[epnum][dir] &= (uint8_t) ~(TU_EDPT_STATE_STALLED | TU_EDPT_STATE_BUSY);
  ------------------
  |  |   32|    219|#define TU_EDPT_STATE_STALLED 0x02u
  ------------------
                _usbd_dev.ep_status[epnum][dir] &= (uint8_t) ~(TU_EDPT_STATE_STALLED | TU_EDPT_STATE_BUSY);
  ------------------
  |  |   31|    219|#define TU_EDPT_STATE_BUSY    0x01u
  ------------------
 1655|    219|}
usbd_edpt_stalled:
 1657|    263|bool usbd_edpt_stalled(uint8_t rhport, uint8_t ep_addr) {
 1658|    263|  (void) rhport;
 1659|       |
 1660|    263|  uint8_t const epnum = tu_edpt_number(ep_addr);
 1661|    263|  uint8_t const dir = tu_edpt_dir(ep_addr);
 1662|       |
 1663|    263|  return (_usbd_dev.ep_status[epnum][dir] & TU_EDPT_STATE_STALLED) != 0;
  ------------------
  |  |   32|    263|#define TU_EDPT_STATE_STALLED 0x02u
  ------------------
 1664|    263|}
usbd.c:get_driver:
  373|  18.8k|TU_ATTR_ALWAYS_INLINE static inline usbd_class_driver_t const * get_driver(uint8_t drvid) {
  374|  18.8k|  usbd_class_driver_t const *driver = NULL;
  375|  18.8k|  if (drvid < _app_driver_count) {
  ------------------
  |  Branch (375:7): [True: 0, False: 18.8k]
  ------------------
  376|       |    // Application drivers
  377|      0|    driver = &_app_driver[drvid];
  378|  18.8k|  } else{
  379|  18.8k|    drvid -= _app_driver_count;
  380|  18.8k|    if (_builtin_driver_count > 0 && drvid < _builtin_driver_count) {
  ------------------
  |  Branch (380:9): [True: 18.8k, Folded]
  |  Branch (380:38): [True: 16.3k, False: 2.46k]
  ------------------
  381|  16.3k|      driver = &_usbd_driver[drvid];
  382|  16.3k|    }
  383|  18.8k|  }
  384|       |
  385|  18.8k|  return driver;
  386|  18.8k|}
usbd.c:usbd_reset:
  642|  16.1k|static void usbd_reset(uint8_t rhport) {
  643|  16.1k|  configuration_reset(rhport);
  644|  16.1k|}
usbd.c:configuration_reset:
  630|  16.1k|static void configuration_reset(uint8_t rhport) {
  631|  32.2k|  for (uint8_t i = 0; i < TOTAL_DRIVER_COUNT; i++) {
  ------------------
  |  |  369|  32.2k|#define TOTAL_DRIVER_COUNT    ((uint8_t) (_app_driver_count + _builtin_driver_count))
  ------------------
  |  Branch (631:23): [True: 16.1k, False: 16.1k]
  ------------------
  632|  16.1k|    usbd_class_driver_t const* driver = get_driver(i);
  633|  16.1k|    TU_ASSERT(driver,);
  ------------------
  |  |  112|  16.1k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  112|  16.1k|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  112|  16.1k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  109|  16.1k|#define TU_ASSERT_2ARGS(_cond, _ret)   TU_ASSERT_DEFINE(_cond, _ret)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  104|  16.1k|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  105|  16.1k|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   54|      0|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (54:41): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   77|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (77:40): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (105:10): [True: 0, False: 16.1k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  106|  16.1k|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:11): [Folded, False: 16.1k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  634|  16.1k|    driver->reset(rhport);
  635|  16.1k|  }
  636|       |
  637|  16.1k|  tu_varclr(&_usbd_dev);
  ------------------
  |  |   96|  16.1k|#define tu_varclr(_var)          tu_memclr(_var, sizeof(*(_var)))
  |  |  ------------------
  |  |  |  |   95|  16.1k|#define tu_memclr(buffer, size)  (void) memset((buffer), 0, (size))
  |  |  ------------------
  ------------------
  638|  16.1k|  (void)memset(_usbd_dev.itf2drv, TUSB_INDEX_INVALID_8, sizeof(_usbd_dev.itf2drv)); // invalid mapping
  639|  16.1k|  (void)memset(_usbd_dev.ep2drv, TUSB_INDEX_INVALID_8, sizeof(_usbd_dev.ep2drv));   // invalid mapping
  640|  16.1k|}
usbd.c:status_stage_xact:
  827|  3.98k|TU_ATTR_ALWAYS_INLINE static inline bool status_stage_xact(uint8_t rhport, uint8_t ep_status) {
  828|  3.98k|  return usbd_edpt_xfer(rhport, ep_status, NULL, 0, false);
  829|  3.98k|}
usbd.c:status_stage_ep:
  822|  2.60k|TU_ATTR_ALWAYS_INLINE static inline uint8_t status_stage_ep(const tusb_control_request_t* request) {
  823|  2.60k|  return (request->wLength != 0 && request->bmRequestType_bit.direction) ? TU_EP0_OUT : TU_EP0_IN;
  ------------------
  |  Branch (823:11): [True: 1.43k, False: 1.17k]
  |  Branch (823:36): [True: 34, False: 1.39k]
  ------------------
  824|  2.60k|}
usbd.c:data_stage_xact:
  833|  2.26k|static bool data_stage_xact(uint8_t rhport) {
  834|  2.26k|  usbd_control_xfer_t* const ctrl_xfer = &_usbd_dev.ctrl_xfer;
  835|  2.26k|  const uint16_t xact_len = tu_min16(ctrl_xfer->data_len - ctrl_xfer->total_xferred, CFG_TUD_ENDPOINT0_BUFSIZE);
  ------------------
  |  |  573|  2.26k|  #define CFG_TUD_ENDPOINT0_BUFSIZE  CFG_TUD_ENDPOINT0_SIZE
  |  |  ------------------
  |  |  |  |   90|  2.26k|#define CFG_TUD_ENDPOINT0_SIZE    64
  |  |  ------------------
  ------------------
  836|  2.26k|  uint8_t ep_addr = TU_EP0_OUT;
  837|       |
  838|  2.26k|  if (ctrl_xfer->request.bmRequestType_bit.direction == TUSB_DIR_IN) {
  ------------------
  |  Branch (838:7): [True: 441, False: 1.82k]
  ------------------
  839|    441|    ep_addr = TU_EP0_IN;
  840|    441|    if (0u != xact_len && ctrl_xfer->buffer != _ctrl_epbuf.buf) {
  ------------------
  |  Branch (840:9): [True: 441, False: 0]
  |  Branch (840:27): [True: 441, False: 0]
  ------------------
  841|    441|      TU_VERIFY(0 == tu_memcpy_s(_ctrl_epbuf.buf, CFG_TUD_ENDPOINT0_BUFSIZE, ctrl_xfer->buffer, xact_len));
  ------------------
  |  |   95|    441|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  112|    441|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |   95|    441|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   92|    441|#define TU_VERIFY_1ARGS(_cond)         TU_VERIFY_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   86|    441|  do {                                \
  |  |  |  |  |  |  |  |  |  |   87|    441|    if (!(_cond)) {                   \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (87:9): [True: 0, False: 441]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   88|      0|      return _ret;                    \
  |  |  |  |  |  |  |  |  |  |   89|      0|    }                                 \
  |  |  |  |  |  |  |  |  |  |   90|    441|  } while (0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (90:12): [Folded, False: 441]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  842|    441|    }
  843|    441|  }
  844|       |
  845|  2.26k|  return usbd_edpt_xfer(rhport, ep_addr, xact_len ? _ctrl_epbuf.buf : NULL, xact_len, false);
  ------------------
  |  Branch (845:42): [True: 2.26k, False: 0]
  ------------------
  846|  2.26k|}
usbd.c:process_setup_received:
 1058|  16.5k|static bool process_setup_received(uint8_t rhport, tusb_control_request_t const * p_request) {
 1059|       |  // Initialize control transfer state for this request. The request copy must be
 1060|       |  // visible to usbd_control_xfer_cb when the (asynchronous) status ZLP completes,
 1061|       |  // since the SETUP packet event has already gone out of scope by then.
 1062|  16.5k|  usbd_control_xfer_t* const ctrl_xfer = &_usbd_dev.ctrl_xfer;
 1063|  16.5k|  ctrl_xfer->request = *p_request;
 1064|  16.5k|  ctrl_xfer->buffer = NULL;
 1065|  16.5k|  ctrl_xfer->total_xferred = 0;
 1066|  16.5k|  ctrl_xfer->data_len = 0;
 1067|  16.5k|  ctrl_xfer->complete_cb = NULL;
 1068|       |
 1069|  16.5k|  p_request = &ctrl_xfer->request; // re-direct request pointer to internal copy (modifiable for hacking)
 1070|  16.5k|  TU_ASSERT(p_request->bmRequestType_bit.type < TUSB_REQ_TYPE_INVALID);
  ------------------
  |  |  112|  16.5k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  112|  16.5k|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  112|  16.5k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  108|  16.5k|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  104|  16.5k|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  105|  16.5k|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   54|  1.21k|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (54:41): [Folded, False: 1.21k]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   77|  1.21k|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (77:40): [Folded, False: 1.21k]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (105:10): [True: 1.21k, False: 15.3k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  106|  16.5k|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:11): [Folded, False: 15.3k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1071|       |
 1072|       |  // Vendor request
 1073|  15.3k|  if ( p_request->bmRequestType_bit.type == TUSB_REQ_TYPE_VENDOR ) {
  ------------------
  |  Branch (1073:8): [True: 1.76k, False: 13.5k]
  ------------------
 1074|  1.76k|    ctrl_xfer->complete_cb = tud_vendor_control_xfer_cb;
 1075|  1.76k|    return tud_vendor_control_xfer_cb(rhport, CONTROL_STAGE_SETUP, p_request);
 1076|  1.76k|  }
 1077|       |
 1078|       |#if CFG_TUSB_DEBUG >= CFG_TUD_LOG_LEVEL
 1079|       |  if (TUSB_REQ_TYPE_STANDARD == p_request->bmRequestType_bit.type && p_request->bRequest <= TUSB_REQ_SYNCH_FRAME) {
 1080|       |    TU_LOG_USBD("  %s", tu_str_std_request[p_request->bRequest]);
 1081|       |    if (TUSB_REQ_GET_DESCRIPTOR != p_request->bRequest) {
 1082|       |      TU_LOG_USBD("\r\n");
 1083|       |    }
 1084|       |  }
 1085|       |#endif
 1086|       |
 1087|  13.5k|  switch (p_request->bmRequestType_bit.recipient) { //-V2520
 1088|       |    //------------- Device Requests e.g in enumeration -------------//
 1089|  9.19k|    case TUSB_REQ_RCPT_DEVICE:
  ------------------
  |  Branch (1089:5): [True: 9.19k, False: 4.35k]
  ------------------
 1090|  9.19k|      if ( TUSB_REQ_TYPE_CLASS == p_request->bmRequestType_bit.type ) {
  ------------------
  |  Branch (1090:12): [True: 476, False: 8.71k]
  ------------------
 1091|    476|        uint8_t const itf = tu_u16_low(p_request->wIndex);
 1092|    476|        TU_VERIFY(itf < TU_ARRAY_SIZE(_usbd_dev.itf2drv));
  ------------------
  |  |   95|    476|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  112|    476|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |   95|    476|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   92|    476|#define TU_VERIFY_1ARGS(_cond)         TU_VERIFY_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   86|    476|  do {                                \
  |  |  |  |  |  |  |  |  |  |   87|    476|    if (!(_cond)) {                   \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (87:9): [True: 246, False: 230]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   88|    246|      return _ret;                    \
  |  |  |  |  |  |  |  |  |  |   89|    246|    }                                 \
  |  |  |  |  |  |  |  |  |  |   90|    476|  } while (0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (90:12): [Folded, False: 230]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1093|       |
 1094|    230|        usbd_class_driver_t const * driver = get_driver(_usbd_dev.itf2drv[itf]);
 1095|    230|        TU_VERIFY(driver);
  ------------------
  |  |   95|    230|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  112|    230|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |   95|    230|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   92|    230|#define TU_VERIFY_1ARGS(_cond)         TU_VERIFY_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   86|    230|  do {                                \
  |  |  |  |  |  |  |  |  |  |   87|    230|    if (!(_cond)) {                   \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (87:9): [True: 230, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   88|    230|      return _ret;                    \
  |  |  |  |  |  |  |  |  |  |   89|    230|    }                                 \
  |  |  |  |  |  |  |  |  |  |   90|    230|  } while (0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (90:12): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1096|       |
 1097|       |        // forward to class driver: "non-STD request to Interface"
 1098|      0|        return invoke_class_control(rhport, driver, p_request);
 1099|    230|      }
 1100|       |
 1101|  8.71k|      if (TUSB_REQ_TYPE_STANDARD != p_request->bmRequestType_bit.type) {
  ------------------
  |  Branch (1101:11): [True: 0, False: 8.71k]
  ------------------
 1102|       |        // Non-standard request is not supported
 1103|      0|        TU_BREAKPOINT();
  ------------------
  |  |   77|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  ------------------
  |  |  |  Branch (77:40): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1104|      0|        return false;
 1105|      0|      }
 1106|       |
 1107|  8.71k|      return process_std_device_request(rhport, p_request);
 1108|       |
 1109|       |    //------------- Class/Interface Specific Request -------------//
 1110|    912|    case TUSB_REQ_RCPT_INTERFACE: {
  ------------------
  |  Branch (1110:5): [True: 912, False: 12.6k]
  ------------------
 1111|    912|      uint8_t itf;
 1112|       |      #if CFG_TUD_PRINTER
 1113|       |      // Printer GET_DEVICE_ID has a weird wIndex = interface (high) | alt (low)
 1114|       |      // attempt to interpret this as a printer request if matched
 1115|       |      if (TUSB_REQ_TYPE_CLASS == p_request->bmRequestType_bit.type &&
 1116|       |          TUSB_DIR_IN == p_request->bmRequestType_bit.direction &&
 1117|       |          TUSB_PRINTER_REQUEST_GET_DEVICE_ID == p_request->bRequest) {
 1118|       |        itf = tu_u16_high(p_request->wIndex);
 1119|       |        if (itf < TU_ARRAY_SIZE(_usbd_dev.itf2drv)) {
 1120|       |          const usbd_class_driver_t * driver = get_driver(_usbd_dev.itf2drv[itf]);
 1121|       |          if (driver != NULL && driver->control_xfer_cb == printerd_control_xfer_cb) {
 1122|       |            if (invoke_class_control(rhport, driver, p_request)) {
 1123|       |              return true;
 1124|       |            }
 1125|       |          }
 1126|       |        }
 1127|       |      }
 1128|       |      #endif
 1129|    912|      itf = tu_u16_low(p_request->wIndex);
 1130|    912|      TU_VERIFY(itf < TU_ARRAY_SIZE(_usbd_dev.itf2drv));
  ------------------
  |  |   95|    912|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  112|    912|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |   95|    912|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   92|    912|#define TU_VERIFY_1ARGS(_cond)         TU_VERIFY_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   86|    912|  do {                                \
  |  |  |  |  |  |  |  |  |  |   87|    912|    if (!(_cond)) {                   \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (87:9): [True: 365, False: 547]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   88|    365|      return _ret;                    \
  |  |  |  |  |  |  |  |  |  |   89|    365|    }                                 \
  |  |  |  |  |  |  |  |  |  |   90|    912|  } while (0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (90:12): [Folded, False: 547]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1131|       |
 1132|    547|      usbd_class_driver_t const * driver = get_driver(_usbd_dev.itf2drv[itf]);
 1133|    547|      TU_VERIFY(driver);
  ------------------
  |  |   95|    547|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  112|    547|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |   95|    547|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   92|    547|#define TU_VERIFY_1ARGS(_cond)         TU_VERIFY_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   86|    547|  do {                                \
  |  |  |  |  |  |  |  |  |  |   87|    547|    if (!(_cond)) {                   \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (87:9): [True: 547, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   88|    547|      return _ret;                    \
  |  |  |  |  |  |  |  |  |  |   89|    547|    }                                 \
  |  |  |  |  |  |  |  |  |  |   90|    547|  } while (0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (90:12): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1134|       |
 1135|       |      // all requests to Interface (STD or Class) is forwarded to class driver.
 1136|       |      // notable requests are: GET HID REPORT DESCRIPTOR, SET_INTERFACE, GET_INTERFACE
 1137|      0|      if (!invoke_class_control(rhport, driver, p_request)) {
  ------------------
  |  Branch (1137:11): [True: 0, False: 0]
  ------------------
 1138|       |        // For GET_INTERFACE and SET_INTERFACE, it is mandatory to respond even if the class
 1139|       |        // driver doesn't use alternate settings or implement this
 1140|      0|        TU_VERIFY(TUSB_REQ_TYPE_STANDARD == p_request->bmRequestType_bit.type);
  ------------------
  |  |   95|      0|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  112|      0|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |   95|      0|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   92|      0|#define TU_VERIFY_1ARGS(_cond)         TU_VERIFY_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   86|      0|  do {                                \
  |  |  |  |  |  |  |  |  |  |   87|      0|    if (!(_cond)) {                   \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (87:9): [True: 0, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   88|      0|      return _ret;                    \
  |  |  |  |  |  |  |  |  |  |   89|      0|    }                                 \
  |  |  |  |  |  |  |  |  |  |   90|      0|  } while (0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (90:12): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1141|       |
 1142|       |        // Clear complete callback if driver set since it can also stall the request.
 1143|      0|        ctrl_xfer->complete_cb = NULL;
 1144|       |
 1145|      0|        switch (p_request->bRequest) { //-V2520
 1146|      0|          case TUSB_REQ_GET_INTERFACE: {
  ------------------
  |  Branch (1146:11): [True: 0, False: 0]
  ------------------
 1147|      0|            uint8_t alternate = 0;
 1148|      0|            tud_control_xfer(rhport, p_request, &alternate, 1);
 1149|      0|            break;
 1150|      0|          }
 1151|       |
 1152|      0|          case TUSB_REQ_SET_INTERFACE:
  ------------------
  |  Branch (1152:11): [True: 0, False: 0]
  ------------------
 1153|      0|            tud_control_status(rhport, p_request);
 1154|      0|            break;
 1155|       |
 1156|      0|          default: return false;
  ------------------
  |  Branch (1156:11): [True: 0, False: 0]
  ------------------
 1157|      0|        }
 1158|      0|      }
 1159|      0|      break;
 1160|      0|    }
 1161|       |
 1162|       |    //------------- Endpoint Request -------------//
 1163|  1.92k|    case TUSB_REQ_RCPT_ENDPOINT: {
  ------------------
  |  Branch (1163:5): [True: 1.92k, False: 11.6k]
  ------------------
 1164|  1.92k|      uint8_t const ep_addr = tu_u16_low(p_request->wIndex);
 1165|  1.92k|      uint8_t const ep_num  = tu_edpt_number(ep_addr);
 1166|  1.92k|      uint8_t const ep_dir  = tu_edpt_dir(ep_addr);
 1167|       |
 1168|  1.92k|      TU_ASSERT(ep_num < TU_ARRAY_SIZE(_usbd_dev.ep2drv) );
  ------------------
  |  |  112|  1.92k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  112|  1.92k|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  112|  1.92k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  108|  1.92k|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  104|  1.92k|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  105|  1.92k|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   54|    241|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (54:41): [Folded, False: 241]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   77|    241|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (77:40): [Folded, False: 241]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (105:10): [True: 241, False: 1.68k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  106|  1.92k|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:11): [Folded, False: 1.68k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1169|  1.68k|      usbd_class_driver_t const * driver = get_driver(_usbd_dev.ep2drv[ep_num][ep_dir]);
 1170|       |
 1171|  1.68k|      if (TUSB_REQ_TYPE_STANDARD != p_request->bmRequestType_bit.type) {
  ------------------
  |  Branch (1171:11): [True: 207, False: 1.47k]
  ------------------
 1172|       |        // Forward class request to its driver
 1173|    207|        TU_VERIFY(driver);
  ------------------
  |  |   95|    207|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  112|    207|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |   95|    207|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   92|    207|#define TU_VERIFY_1ARGS(_cond)         TU_VERIFY_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   86|    207|  do {                                \
  |  |  |  |  |  |  |  |  |  |   87|    207|    if (!(_cond)) {                   \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (87:9): [True: 207, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   88|    207|      return _ret;                    \
  |  |  |  |  |  |  |  |  |  |   89|    207|    }                                 \
  |  |  |  |  |  |  |  |  |  |   90|    207|  } while (0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (90:12): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1174|      0|        return invoke_class_control(rhport, driver, p_request);
 1175|  1.47k|      } else {
 1176|       |        // Handle STD request to endpoint
 1177|  1.47k|        switch (p_request->bRequest) { //-V2520
 1178|    263|          case TUSB_REQ_GET_STATUS: {
  ------------------
  |  Branch (1178:11): [True: 263, False: 1.21k]
  ------------------
 1179|    263|            uint16_t status = usbd_edpt_stalled(rhport, ep_addr) ? 0x0001u : 0x0000u;
  ------------------
  |  Branch (1179:31): [True: 0, False: 263]
  ------------------
 1180|    263|            tud_control_xfer(rhport, p_request, &status, 2);
 1181|    263|          }
 1182|    263|          break;
 1183|       |
 1184|    439|          case TUSB_REQ_CLEAR_FEATURE:
  ------------------
  |  Branch (1184:11): [True: 439, False: 1.03k]
  ------------------
 1185|    860|          case TUSB_REQ_SET_FEATURE: {
  ------------------
  |  Branch (1185:11): [True: 421, False: 1.05k]
  ------------------
 1186|    860|            if ( TUSB_REQ_FEATURE_EDPT_HALT == p_request->wValue ) {
  ------------------
  |  Branch (1186:18): [True: 435, False: 425]
  ------------------
 1187|    435|              if ( TUSB_REQ_CLEAR_FEATURE ==  p_request->bRequest ) {
  ------------------
  |  Branch (1187:20): [True: 219, False: 216]
  ------------------
 1188|    219|                usbd_edpt_clear_stall(rhport, ep_addr);
 1189|    219|              }else {
 1190|    216|                usbd_edpt_stall(rhport, ep_addr);
 1191|    216|              }
 1192|    435|            }
 1193|       |
 1194|    860|            if (driver != NULL) {
  ------------------
  |  Branch (1194:17): [True: 0, False: 860]
  ------------------
 1195|       |              // Some classes such as USBTMC needs to clear/re-init its buffer when receiving CLEAR_FEATURE request
 1196|       |              // We will also forward std request targeted endpoint to class drivers as well
 1197|       |
 1198|       |              // STD request must always be ACKed regardless of driver returned value
 1199|       |              // Also clear complete callback if driver set since it can also stall the request.
 1200|      0|              (void) invoke_class_control(rhport, driver, p_request);
 1201|      0|              ctrl_xfer->complete_cb = NULL;
 1202|       |
 1203|       |              // skip ZLP status if driver already did that
 1204|      0|              if (!(_usbd_dev.ep_status[0][TUSB_DIR_IN] & TU_EDPT_STATE_BUSY)) {
  ------------------
  |  |   31|      0|#define TU_EDPT_STATE_BUSY    0x01u
  ------------------
  |  Branch (1204:19): [True: 0, False: 0]
  ------------------
 1205|      0|                tud_control_status(rhport, p_request);
 1206|      0|              }
 1207|      0|            }
 1208|    860|          }
 1209|    860|          break;
 1210|       |
 1211|       |          // Unknown/Unsupported request
 1212|    354|          default:
  ------------------
  |  Branch (1212:11): [True: 354, False: 1.12k]
  ------------------
 1213|    354|            TU_BREAKPOINT();
  ------------------
  |  |   77|    354|  #define TU_BREAKPOINT() do {} while (0)
  |  |  ------------------
  |  |  |  Branch (77:40): [Folded, False: 354]
  |  |  ------------------
  ------------------
 1214|    354|            return false;
 1215|  1.47k|        }
 1216|  1.47k|      }
 1217|  1.12k|      break;
 1218|  1.68k|    }
 1219|       |
 1220|       |    // Unknown recipient
 1221|  1.51k|    default:
  ------------------
  |  Branch (1221:5): [True: 1.51k, False: 12.0k]
  ------------------
 1222|  1.51k|      TU_BREAKPOINT();
  ------------------
  |  |   77|  1.51k|  #define TU_BREAKPOINT() do {} while (0)
  |  |  ------------------
  |  |  |  Branch (77:40): [Folded, False: 1.51k]
  |  |  ------------------
  ------------------
 1223|  1.51k|      return false;
 1224|  13.5k|  }
 1225|       |
 1226|  1.12k|  return true;
 1227|  13.5k|}
usbd.c:process_std_device_request:
  947|  8.71k|static bool process_std_device_request(uint8_t rhport, tusb_control_request_t const * p_request) {
  948|  8.71k|  switch (p_request->bRequest) { //-V2520
  949|    211|    case TUSB_REQ_SET_ADDRESS:
  ------------------
  |  Branch (949:5): [True: 211, False: 8.50k]
  ------------------
  950|       |      // Depending on mcu, status phase could be sent either before or after changing device address,
  951|       |      // or even require stack to not response with status at all
  952|       |      // Therefore DCD must take full responsibility to response and include zlp status packet if needed.
  953|    211|      dcd_set_address(rhport, (uint8_t) p_request->wValue);
  954|    211|      _usbd_dev.addressed = 1;
  955|    211|      return true;
  956|       |
  957|    349|    case TUSB_REQ_GET_CONFIGURATION: {
  ------------------
  |  Branch (957:5): [True: 349, False: 8.36k]
  ------------------
  958|    349|      uint8_t cfg_num = _usbd_dev.cfg_num;
  959|    349|      tud_control_xfer(rhport, p_request, &cfg_num, 1);
  960|    349|      return true;
  961|      0|    }
  962|       |
  963|  1.08k|    case TUSB_REQ_SET_CONFIGURATION: {
  ------------------
  |  Branch (963:5): [True: 1.08k, False: 7.62k]
  ------------------
  964|  1.08k|      uint8_t const cfg_num = (uint8_t) p_request->wValue;
  965|       |
  966|       |      // Only process if new configure is different
  967|  1.08k|      if (_usbd_dev.cfg_num != cfg_num) {
  ------------------
  |  Branch (967:11): [True: 212, False: 873]
  ------------------
  968|    212|        if (_usbd_dev.cfg_num != 0) {
  ------------------
  |  Branch (968:13): [True: 0, False: 212]
  ------------------
  969|       |          // already configured: need to clear all endpoints and driver first
  970|      0|          TU_LOG_USBD("  Clear current Configuration (%u) before switching\r\n", _usbd_dev.cfg_num);
  971|       |
  972|      0|          dcd_sof_enable(rhport, false);
  973|      0|          dcd_edpt_close_all(rhport);
  974|       |
  975|       |          // close all drivers and current configured state except bus speed
  976|      0|          const uint8_t speed = _usbd_dev.speed;
  977|      0|          configuration_reset(rhport);
  978|       |
  979|      0|          _usbd_dev.speed = speed; // restore speed
  980|      0|        }
  981|       |
  982|    212|        _usbd_dev.cfg_num = cfg_num;
  983|       |
  984|       |        // Handle the new configuration
  985|    212|        if (cfg_num == 0) {
  ------------------
  |  Branch (985:13): [True: 0, False: 212]
  ------------------
  986|      0|          tud_umount_cb();
  987|    212|        } else {
  988|    212|          if (!process_set_config(rhport, cfg_num)) {
  ------------------
  |  Branch (988:15): [True: 212, False: 0]
  ------------------
  989|    212|            _usbd_dev.cfg_num = 0;
  990|    212|            TU_ASSERT(false);
  ------------------
  |  |  112|    212|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  112|    212|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  112|    212|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  108|    212|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  104|    212|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  105|    212|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   54|    212|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (54:41): [Folded, False: 212]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   77|    212|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (77:40): [Folded, False: 212]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (105:10): [True: 212, Folded]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  106|    212|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:11): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  991|    212|          }
  992|      0|          tud_mount_cb();
  993|      0|        }
  994|    212|      }
  995|       |
  996|    873|      tud_control_status(rhport, p_request);
  997|    873|      return true;
  998|  1.08k|    }
  999|       |
 1000|  2.13k|    case TUSB_REQ_GET_DESCRIPTOR:
  ------------------
  |  Branch (1000:5): [True: 2.13k, False: 6.58k]
  ------------------
 1001|  2.13k|      return process_get_descriptor(rhport, p_request);
 1002|       |
 1003|  1.14k|    case TUSB_REQ_SET_FEATURE:
  ------------------
  |  Branch (1003:5): [True: 1.14k, False: 7.57k]
  ------------------
 1004|  1.14k|      switch (p_request->wValue) { //-V2520
 1005|    886|        case TUSB_REQ_FEATURE_REMOTE_WAKEUP:
  ------------------
  |  Branch (1005:9): [True: 886, False: 257]
  ------------------
 1006|    886|          TU_LOG_USBD("    Enable Remote Wakeup\r\n");
 1007|       |          // Host may enable remote wake up before suspending especially HID device
 1008|    886|          _usbd_dev.remote_wakeup_en = 1;
 1009|    886|          tud_control_status(rhport, p_request);
 1010|    886|          return true;
 1011|       |
 1012|       |        #if CFG_TUD_TEST_MODE
 1013|       |        case TUSB_REQ_FEATURE_TEST_MODE: {
 1014|       |          // Only handle the test mode if supported and valid
 1015|       |          TU_VERIFY(0 == tu_u16_low(p_request->wIndex));
 1016|       |
 1017|       |          uint8_t const selector = tu_u16_high(p_request->wIndex);
 1018|       |          TU_VERIFY(TUSB_FEATURE_TEST_J <= selector && selector <= TUSB_FEATURE_TEST_FORCE_ENABLE);
 1019|       |
 1020|       |          _usbd_dev.ctrl_xfer.complete_cb = process_test_mode_cb;
 1021|       |          tud_control_status(rhport, p_request);
 1022|       |          return true;
 1023|       |        }
 1024|       |        #endif
 1025|       |
 1026|       |        // Stall unsupported feature selector
 1027|    257|        default: return false;
  ------------------
  |  Branch (1027:9): [True: 257, False: 886]
  ------------------
 1028|  1.14k|      }
 1029|       |
 1030|  1.18k|    case TUSB_REQ_CLEAR_FEATURE:
  ------------------
  |  Branch (1030:5): [True: 1.18k, False: 7.52k]
  ------------------
 1031|       |      // Only support remote wakeup for device feature
 1032|  1.18k|      TU_VERIFY(TUSB_REQ_FEATURE_REMOTE_WAKEUP == p_request->wValue);
  ------------------
  |  |   95|  1.18k|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  112|  1.18k|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |   95|  1.18k|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   92|  1.18k|#define TU_VERIFY_1ARGS(_cond)         TU_VERIFY_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   86|  1.18k|  do {                                \
  |  |  |  |  |  |  |  |  |  |   87|  1.18k|    if (!(_cond)) {                   \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (87:9): [True: 338, False: 849]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   88|    338|      return _ret;                    \
  |  |  |  |  |  |  |  |  |  |   89|    338|    }                                 \
  |  |  |  |  |  |  |  |  |  |   90|  1.18k|  } while (0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (90:12): [Folded, False: 849]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1033|    849|      TU_LOG_USBD("    Disable Remote Wakeup\r\n");
 1034|       |
 1035|       |      // Host may disable remote wake up after resuming
 1036|    849|      _usbd_dev.remote_wakeup_en = 0;
 1037|    849|      tud_control_status(rhport, p_request);
 1038|    849|      return true;
 1039|       |
 1040|  1.95k|    case TUSB_REQ_GET_STATUS: {
  ------------------
  |  Branch (1040:5): [True: 1.95k, False: 6.75k]
  ------------------
 1041|       |      // Device status bit mask
 1042|       |      // - Bit 0: Self Powered TODO must invoke callback to get actual status
 1043|       |      // - Bit 1: Remote Wakeup enabled
 1044|  1.95k|      uint16_t status = (uint16_t) _usbd_dev.dev_state_bm;
 1045|  1.95k|      tud_control_xfer(rhport, p_request, &status, 2);
 1046|  1.95k|      return true;
 1047|  1.18k|    }
 1048|       |
 1049|    648|    default:
  ------------------
  |  Branch (1049:5): [True: 648, False: 8.06k]
  ------------------
 1050|    648|      TU_BREAKPOINT();
  ------------------
  |  |   77|    648|  #define TU_BREAKPOINT() do {} while (0)
  |  |  ------------------
  |  |  |  Branch (77:40): [Folded, False: 648]
  |  |  ------------------
  ------------------
 1051|       |      return false;
 1052|  8.71k|  }
 1053|  8.71k|}
usbd.c:process_set_config:
 1231|    212|static bool process_set_config(uint8_t rhport, uint8_t cfg_num) {
 1232|       |  // index is cfg_num-1
 1233|    212|  const tusb_desc_configuration_t *desc_cfg =
 1234|    212|    (const tusb_desc_configuration_t *)tud_descriptor_configuration_cb(cfg_num - 1);
 1235|    212|  TU_ASSERT(desc_cfg != NULL && desc_cfg->bDescriptorType == TUSB_DESC_CONFIGURATION);
  ------------------
  |  |  112|    212|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  112|    212|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  112|    212|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  108|    212|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  104|    212|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  105|    424|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   54|      0|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (54:41): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   77|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (77:40): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (105:12): [True: 212, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  Branch (105:12): [True: 212, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  106|    212|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:11): [Folded, False: 212]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1236|       |
 1237|       |  // Parse configuration descriptor
 1238|    212|  _usbd_dev.self_powered = (desc_cfg->bmAttributes & TUSB_DESC_CONFIG_ATT_SELF_POWERED) ? 1u : 0u;
  ------------------
  |  Branch (1238:28): [True: 0, False: 212]
  ------------------
 1239|       |
 1240|       |  // Parse interface descriptor
 1241|    212|  const uint8_t *p_desc   = ((const uint8_t *)desc_cfg) + sizeof(tusb_desc_configuration_t);
 1242|    212|  const uint8_t *desc_end = ((const uint8_t *)desc_cfg) + tu_le16toh(desc_cfg->wTotalLength);
  ------------------
  |  |  253|    212|  #define tu_le16toh(u16) (u16)
  ------------------
 1243|       |
 1244|    212|  while (tu_desc_in_bounds(p_desc, desc_end)) {
  ------------------
  |  Branch (1244:10): [True: 212, False: 0]
  ------------------
 1245|       |    // Class will always start with Interface Association (if any) and then Interface descriptor
 1246|    212|    if (TUSB_DESC_INTERFACE_ASSOCIATION == tu_desc_type(p_desc)) {
  ------------------
  |  Branch (1246:9): [True: 0, False: 212]
  ------------------
 1247|      0|      p_desc = tu_desc_next(p_desc); // next to Interface
 1248|      0|      continue;
 1249|      0|    }
 1250|       |
 1251|    212|    TU_ASSERT(TUSB_DESC_INTERFACE == tu_desc_type(p_desc));
  ------------------
  |  |  112|    212|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  112|    212|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  112|    212|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  108|    212|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  104|    212|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  105|    212|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   54|      0|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (54:41): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   77|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (77:40): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (105:10): [True: 0, False: 212]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  106|    212|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:11): [Folded, False: 212]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1252|    212|    const tusb_desc_interface_t *desc_itf = (const tusb_desc_interface_t *)p_desc;
 1253|       |
 1254|       |    // Find driver for this interface
 1255|    212|    const uint16_t remaining_len = (uint16_t)(desc_end - p_desc);
 1256|    212|    uint8_t        drv_id;
 1257|    424|    for (drv_id = 0; drv_id < TOTAL_DRIVER_COUNT; drv_id++) {
  ------------------
  |  |  369|    424|#define TOTAL_DRIVER_COUNT    ((uint8_t) (_app_driver_count + _builtin_driver_count))
  ------------------
  |  Branch (1257:22): [True: 212, False: 212]
  ------------------
 1258|    212|      const usbd_class_driver_t *driver = get_driver(drv_id);
 1259|    212|      TU_ASSERT(driver);
  ------------------
  |  |  112|    212|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  112|    212|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  112|    212|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  108|    212|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  104|    212|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  105|    212|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   54|      0|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (54:41): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   77|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (77:40): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (105:10): [True: 0, False: 212]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  106|    212|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:11): [Folded, False: 212]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1260|    212|      const uint16_t drv_len = driver->open(rhport, desc_itf, remaining_len);
 1261|       |
 1262|    212|      if ((sizeof(tusb_desc_interface_t) <= drv_len) && (drv_len <= remaining_len)) {
  ------------------
  |  Branch (1262:11): [True: 0, False: 212]
  |  Branch (1262:57): [True: 0, False: 0]
  ------------------
 1263|       |        // Open successfully
 1264|      0|        TU_LOG_USBD("  %s opened\r\n", driver->name);
 1265|       |
 1266|       |        // bind found driver to all interfaces and endpoint within drv_len
 1267|      0|        TU_ASSERT(tu_bind_driver_to_ep_itf(drv_id, _usbd_dev.ep2drv, _usbd_dev.itf2drv, CFG_TUD_INTERFACE_MAX, p_desc,
  ------------------
  |  |  112|      0|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  112|      0|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  112|      0|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  108|      0|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  104|      0|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  105|      0|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   54|      0|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (54:41): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   77|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (77:40): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (105:10): [True: 0, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  106|      0|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:11): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1268|      0|                                           drv_len));
 1269|       |
 1270|      0|        p_desc += drv_len; // next Interface
 1271|      0|        break; // exit driver find loop
 1272|      0|      }
 1273|    212|    }
 1274|       |
 1275|       |    // Failed if there is no supported drivers
 1276|    212|    TU_ASSERT(drv_id < TOTAL_DRIVER_COUNT);
  ------------------
  |  |  112|    212|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  112|    212|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  112|    212|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  108|    212|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  104|    212|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  105|    212|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   54|    212|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (54:41): [Folded, False: 212]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   77|    212|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (77:40): [Folded, False: 212]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (105:10): [True: 212, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  106|    212|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:11): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1277|    212|  }
 1278|       |
 1279|      0|  return true;
 1280|    212|}
usbd.c:process_get_descriptor:
 1283|  2.13k|static bool process_get_descriptor(uint8_t rhport, tusb_control_request_t const * p_request) {
 1284|  2.13k|  tusb_desc_type_t const desc_type = (tusb_desc_type_t) tu_u16_high(p_request->wValue);
 1285|  2.13k|  uint8_t const desc_index = tu_u16_low( p_request->wValue );
 1286|       |
 1287|  2.13k|  switch(desc_type) { //-V2520
 1288|    210|    case TUSB_DESC_DEVICE: {
  ------------------
  |  Branch (1288:5): [True: 210, False: 1.92k]
  ------------------
 1289|    210|      TU_LOG_USBD(" Device\r\n");
 1290|       |
 1291|    210|      void *desc_device = (void *)(uintptr_t)tud_descriptor_device_cb();
 1292|    210|      TU_ASSERT(desc_device);
  ------------------
  |  |  112|    210|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  112|    210|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  112|    210|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  108|    210|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  104|    210|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  105|    210|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   54|      0|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (54:41): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   77|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (77:40): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (105:10): [True: 0, False: 210]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  106|    210|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:11): [Folded, False: 210]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1293|       |
 1294|       |      // Only response with exactly 1 Packet if: not addressed and host requested more data than device descriptor has.
 1295|       |      // This only happens with the very first get device descriptor and EP0 size = 8 or 16.
 1296|    210|      if ((CFG_TUD_ENDPOINT0_SIZE < sizeof(tusb_desc_device_t)) && !_usbd_dev.addressed &&
  ------------------
  |  |   90|    210|#define CFG_TUD_ENDPOINT0_SIZE    64
  ------------------
  |  Branch (1296:11): [Folded, False: 210]
  |  Branch (1296:68): [True: 0, False: 0]
  ------------------
 1297|      0|          p_request->wLength > sizeof(tusb_desc_device_t)) {
  ------------------
  |  Branch (1297:11): [True: 0, False: 0]
  ------------------
 1298|       |        // Hack here: we modify the request length to prevent usbd_control response with zlp
 1299|       |        // since we are responding with 1 packet & less data than wLength.
 1300|      0|        ((tusb_control_request_t *)(uintptr_t)p_request)->wLength = CFG_TUD_ENDPOINT0_SIZE;
  ------------------
  |  |   90|      0|#define CFG_TUD_ENDPOINT0_SIZE    64
  ------------------
 1301|      0|        return tud_control_xfer(rhport, p_request, desc_device, CFG_TUD_ENDPOINT0_SIZE);
  ------------------
  |  |   90|      0|#define CFG_TUD_ENDPOINT0_SIZE    64
  ------------------
 1302|    210|      } else {
 1303|    210|        return tud_control_xfer(rhport, p_request, desc_device, sizeof(tusb_desc_device_t));
 1304|    210|      }
 1305|    210|    }
 1306|       |    // break; // unreachable
 1307|       |
 1308|    201|    case TUSB_DESC_BOS: {
  ------------------
  |  Branch (1308:5): [True: 201, False: 1.93k]
  ------------------
 1309|    201|      TU_LOG_USBD(" BOS\r\n");
 1310|       |
 1311|       |      // requested by host if USB > 2.0 ( i.e 2.1 or 3.x )
 1312|    201|      uintptr_t desc_bos = (uintptr_t) tud_descriptor_bos_cb();
 1313|    201|      TU_VERIFY(desc_bos != 0);
  ------------------
  |  |   95|    201|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  112|    201|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |   95|    201|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   92|    201|#define TU_VERIFY_1ARGS(_cond)         TU_VERIFY_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   86|    201|  do {                                \
  |  |  |  |  |  |  |  |  |  |   87|    201|    if (!(_cond)) {                   \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (87:9): [True: 201, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   88|    201|      return _ret;                    \
  |  |  |  |  |  |  |  |  |  |   89|    201|    }                                 \
  |  |  |  |  |  |  |  |  |  |   90|    201|  } while (0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (90:12): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1314|       |
 1315|       |      // Use offsetof to avoid pointer to the odd/misaligned address
 1316|      0|      uint16_t const total_len = tu_le16toh( tu_unaligned_read16((const void*) (desc_bos + offsetof(tusb_desc_bos_t, wTotalLength))) );
  ------------------
  |  |  253|      0|  #define tu_le16toh(u16) (u16)
  ------------------
 1317|       |
 1318|      0|      return tud_control_xfer(rhport, p_request, (void*) desc_bos, total_len);
 1319|    201|    }
 1320|       |    // break; // unreachable
 1321|       |
 1322|    271|    case TUSB_DESC_CONFIGURATION:
  ------------------
  |  Branch (1322:5): [True: 271, False: 1.86k]
  ------------------
 1323|    468|    case TUSB_DESC_OTHER_SPEED_CONFIG: {
  ------------------
  |  Branch (1323:5): [True: 197, False: 1.93k]
  ------------------
 1324|    468|      uintptr_t desc_config;
 1325|       |
 1326|    468|      if ( desc_type == TUSB_DESC_CONFIGURATION ) {
  ------------------
  |  Branch (1326:12): [True: 271, False: 197]
  ------------------
 1327|    271|        TU_LOG_USBD(" Configuration[%u]\r\n", desc_index);
 1328|    271|        desc_config = (uintptr_t) tud_descriptor_configuration_cb(desc_index);
 1329|    271|        TU_ASSERT(desc_config != 0);
  ------------------
  |  |  112|    271|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  112|    271|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  112|    271|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  108|    271|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  104|    271|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  105|    271|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   54|      0|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (54:41): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   77|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (77:40): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (105:10): [True: 0, False: 271]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  106|    271|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:11): [Folded, False: 271]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1330|    271|      }else {
 1331|       |        // Host only request this after getting Device Qualifier descriptor
 1332|    197|        TU_LOG_USBD(" Other Speed Configuration\r\n");
 1333|    197|        desc_config = (uintptr_t) tud_descriptor_other_speed_configuration_cb(desc_index);
 1334|    197|        TU_VERIFY(desc_config != 0);
  ------------------
  |  |   95|    197|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  112|    197|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |   95|    197|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   92|    197|#define TU_VERIFY_1ARGS(_cond)         TU_VERIFY_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   86|    197|  do {                                \
  |  |  |  |  |  |  |  |  |  |   87|    197|    if (!(_cond)) {                   \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (87:9): [True: 197, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   88|    197|      return _ret;                    \
  |  |  |  |  |  |  |  |  |  |   89|    197|    }                                 \
  |  |  |  |  |  |  |  |  |  |   90|    197|  } while (0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (90:12): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1335|    197|      }
 1336|       |
 1337|       |      // Use offsetof to avoid pointer to the odd/misaligned address
 1338|    271|      uint16_t const total_len = tu_le16toh( tu_unaligned_read16((const void*) (desc_config + offsetof(tusb_desc_configuration_t, wTotalLength))) );
  ------------------
  |  |  253|    271|  #define tu_le16toh(u16) (u16)
  ------------------
 1339|       |
 1340|    271|      return tud_control_xfer(rhport, p_request, (void*) desc_config, total_len);
 1341|    468|    }
 1342|       |    // break; // unreachable
 1343|       |
 1344|    795|    case TUSB_DESC_STRING: {
  ------------------
  |  Branch (1344:5): [True: 795, False: 1.33k]
  ------------------
 1345|    795|      TU_LOG_USBD(" String[%u]\r\n", desc_index);
 1346|       |
 1347|       |      // String Descriptor always uses the desc set from user
 1348|    795|      uint8_t const* desc_str = (uint8_t const*) tud_descriptor_string_cb(desc_index, p_request->wIndex);
 1349|    795|      TU_VERIFY(desc_str);
  ------------------
  |  |   95|    795|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  112|    795|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |   95|    795|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   92|    795|#define TU_VERIFY_1ARGS(_cond)         TU_VERIFY_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   86|    795|  do {                                \
  |  |  |  |  |  |  |  |  |  |   87|    795|    if (!(_cond)) {                   \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (87:9): [True: 207, False: 588]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   88|    207|      return _ret;                    \
  |  |  |  |  |  |  |  |  |  |   89|    207|    }                                 \
  |  |  |  |  |  |  |  |  |  |   90|    795|  } while (0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (90:12): [Folded, False: 588]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1350|       |
 1351|       |      // first byte of descriptor is its size
 1352|    588|      return tud_control_xfer(rhport, p_request, (void*) (uintptr_t) desc_str, tu_desc_len(desc_str));
 1353|    795|    }
 1354|       |    // break; // unreachable
 1355|       |
 1356|    198|    case TUSB_DESC_DEVICE_QUALIFIER: {
  ------------------
  |  Branch (1356:5): [True: 198, False: 1.93k]
  ------------------
 1357|    198|      TU_LOG_USBD(" Device Qualifier\r\n");
 1358|    198|      uint8_t const* desc_qualifier = tud_descriptor_device_qualifier_cb();
 1359|    198|      TU_VERIFY(desc_qualifier);
  ------------------
  |  |   95|    198|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  112|    198|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |   95|    198|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   92|    198|#define TU_VERIFY_1ARGS(_cond)         TU_VERIFY_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   86|    198|  do {                                \
  |  |  |  |  |  |  |  |  |  |   87|    198|    if (!(_cond)) {                   \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (87:9): [True: 198, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   88|    198|      return _ret;                    \
  |  |  |  |  |  |  |  |  |  |   89|    198|    }                                 \
  |  |  |  |  |  |  |  |  |  |   90|    198|  } while (0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (90:12): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1360|      0|      return tud_control_xfer(rhport, p_request, (void*) (uintptr_t) desc_qualifier, tu_desc_len(desc_qualifier));
 1361|    198|    }
 1362|       |    // break; // unreachable
 1363|       |
 1364|    262|    default: return false;
  ------------------
  |  Branch (1364:5): [True: 262, False: 1.87k]
  ------------------
 1365|  2.13k|  }
 1366|  2.13k|}
usbd.c:queue_event:
  410|  36.9k|TU_ATTR_ALWAYS_INLINE static inline bool queue_event(dcd_event_t const * event, bool in_isr) {
  411|  36.9k|  TU_ASSERT(osal_queue_send(_usbd_q, event, in_isr));
  ------------------
  |  |  112|  36.9k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  112|  36.9k|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  112|  36.9k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  108|  36.9k|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  104|  36.9k|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  105|  36.9k|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   54|      0|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (54:41): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   77|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (77:40): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (105:10): [True: 0, False: 36.9k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  106|  36.9k|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:11): [Folded, False: 36.9k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  412|  36.9k|  tud_event_hook_cb(event->rhport, event->event_id, in_isr);
  413|       |  return true;
  414|  36.9k|}

fuzz.cc:_ZL8tud_taskv:
   76|  42.6k|void tud_task (void) {
   77|       |  tud_task_ext(UINT32_MAX, false);
   78|  42.6k|}

usbd.c:osal_spin_init:
   50|      1|TU_ATTR_ALWAYS_INLINE static inline void osal_spin_init(osal_spinlock_t *ctx) {
   51|      1|  (void) ctx;
   52|      1|}
usbd.c:osal_queue_create:
  176|      1|TU_ATTR_ALWAYS_INLINE static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef) {
  177|      1|  tu_fifo_clear(&qdef->ff);
  178|      1|  return (osal_queue_t) qdef;
  179|      1|}
usbd.c:osal_queue_receive:
  186|  79.6k|TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_receive(osal_queue_t qhdl, void* data, uint32_t msec) {
  187|  79.6k|  (void) msec; // not used, always behave as msec = 0
  188|       |
  189|  79.6k|  qhdl->interrupt_set(false);
  190|  79.6k|  const bool success = (tu_fifo_read_n(&qhdl->ff, data, qhdl->item_size) > 0);
  191|  79.6k|  qhdl->interrupt_set(true);
  192|       |
  193|  79.6k|  return success;
  194|  79.6k|}
usbd.c:osal_queue_send:
  196|  36.9k|TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_send(osal_queue_t qhdl, void const* data, bool in_isr) {
  197|  36.9k|  if (!in_isr) {
  ------------------
  |  Branch (197:7): [True: 13.5k, False: 23.4k]
  ------------------
  198|  13.5k|    qhdl->interrupt_set(false);
  199|  13.5k|  }
  200|       |
  201|  36.9k|  const bool success = (tu_fifo_write_n(&qhdl->ff, data, qhdl->item_size) > 0);
  202|       |
  203|  36.9k|  if (!in_isr) {
  ------------------
  |  Branch (203:7): [True: 13.5k, False: 23.4k]
  ------------------
  204|  13.5k|    qhdl->interrupt_set(true);
  205|  13.5k|  }
  206|       |
  207|  36.9k|  return success;
  208|  36.9k|}

tusb_rhport_init:
   65|  1.00k|bool tusb_rhport_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
   66|       |  //  backward compatible called with tusb_init(void)
   67|       |  #if defined(TUD_OPT_RHPORT) || defined(TUH_OPT_RHPORT)
   68|       |  if (rh_init == NULL) {
   69|       |    #if CFG_TUD_ENABLED && defined(TUD_OPT_RHPORT)
   70|       |    // init device stack CFG_TUSB_RHPORTx_MODE must be defined
   71|       |    const tusb_rhport_init_t dev_init = {
   72|       |      .role = TUSB_ROLE_DEVICE,
   73|       |      .speed = TUD_OPT_HIGH_SPEED ? TUSB_SPEED_HIGH : TUSB_SPEED_FULL
   74|       |    };
   75|       |    TU_ASSERT ( tud_rhport_init(TUD_OPT_RHPORT, &dev_init) );
   76|       |    _tusb_rhport_role[TUD_OPT_RHPORT] = TUSB_ROLE_DEVICE;
   77|       |    #endif
   78|       |
   79|       |    #if CFG_TUH_ENABLED && defined(TUH_OPT_RHPORT)
   80|       |    // init host stack CFG_TUSB_RHPORTx_MODE must be defined
   81|       |    const tusb_rhport_init_t host_init = {
   82|       |      .role = TUSB_ROLE_HOST,
   83|       |      .speed = TUH_OPT_HIGH_SPEED ? TUSB_SPEED_HIGH : TUSB_SPEED_FULL
   84|       |    };
   85|       |    TU_ASSERT( tuh_rhport_init(TUH_OPT_RHPORT, &host_init) );
   86|       |    _tusb_rhport_role[TUH_OPT_RHPORT] = TUSB_ROLE_HOST;
   87|       |    #endif
   88|       |
   89|       |    return true;
   90|       |  }
   91|       |  #endif
   92|       |
   93|       |  // new API with explicit rhport and role
   94|  1.00k|  TU_ASSERT(rhport < TUP_USBIP_CONTROLLER_NUM && rh_init->role != TUSB_ROLE_INVALID);
  ------------------
  |  |  112|  1.00k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  112|  1.00k|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  112|  1.00k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  108|  1.00k|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  104|  1.00k|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  105|  2.01k|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   54|      0|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (54:41): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   77|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (77:40): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (105:12): [True: 1.00k, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  Branch (105:12): [True: 1.00k, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  106|  1.00k|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:11): [Folded, False: 1.00k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   95|  1.00k|  _tusb_rhport_role[rhport] = rh_init->role;
   96|       |
   97|  1.00k|  #if CFG_TUD_ENABLED
   98|  1.00k|  if (rh_init->role == TUSB_ROLE_DEVICE) {
  ------------------
  |  Branch (98:7): [True: 1.00k, False: 0]
  ------------------
   99|  1.00k|    TU_ASSERT(tud_rhport_init(rhport, rh_init));
  ------------------
  |  |  112|  1.00k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  112|  1.00k|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  112|  1.00k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  108|  1.00k|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  104|  1.00k|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  105|  1.00k|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   54|      0|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (54:41): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   77|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (77:40): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (105:10): [True: 0, False: 1.00k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  106|  1.00k|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:11): [Folded, False: 1.00k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  100|  1.00k|  }
  101|  1.00k|  #endif
  102|       |
  103|       |  #if CFG_TUH_ENABLED
  104|       |  if (rh_init->role == TUSB_ROLE_HOST) {
  105|       |    TU_ASSERT(tuh_rhport_init(rhport, rh_init));
  106|       |  }
  107|       |  #endif
  108|       |
  109|  1.00k|  return true;
  110|  1.00k|}

dcd_init:
   49|      1|bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
   50|      1|  UNUSED(rhport);
  ------------------
  |  |   31|      1|#define UNUSED(x) (void)(x)
  ------------------
   51|      1|  UNUSED(rh_init);
  ------------------
  |  |   31|      1|#define UNUSED(x) (void)(x)
  ------------------
   52|      1|  return true;
   53|      1|}
dcd_int_handler:
   55|  42.6k|void dcd_int_handler(uint8_t rhport) {
   56|  42.6k|  assert(_fuzz_data_provider.has_value());
  ------------------
  |  Branch (56:3): [True: 42.6k, False: 0]
  ------------------
   57|       |
   58|  42.6k|  if (!state.interrupts_enabled) {
  ------------------
  |  Branch (58:7): [True: 0, False: 42.6k]
  ------------------
   59|      0|    return;
   60|      0|  }
   61|       |
   62|       |  // Choose if we want to generate a signal based on the fuzzed data.
   63|  42.6k|  if (_fuzz_data_provider->ConsumeBool()) {
  ------------------
  |  Branch (63:7): [True: 11.1k, False: 31.5k]
  ------------------
   64|       |    // Only generate bus signal events that don't carry additional union data.
   65|       |    // DCD_EVENT_XFER_COMPLETE, DCD_EVENT_SOF, and DCD_EVENT_BUS_RESET need
   66|       |    // properly initialized union fields; USBD_EVENT_FUNC_CALL is internal only.
   67|       |    // Valid bus-signal-only events: UNPLUGGED(2), SUSPEND(4), RESUME(5).
   68|  11.1k|    static const dcd_eventid_t bus_signal_events[] = {
   69|  11.1k|        DCD_EVENT_UNPLUGGED, DCD_EVENT_SUSPEND, DCD_EVENT_RESUME};
   70|  11.1k|    uint8_t idx = _fuzz_data_provider->ConsumeIntegralInRange<uint8_t>(0, 2);
   71|  11.1k|    dcd_event_bus_signal(rhport, bus_signal_events[idx],
   72|  11.1k|                         _fuzz_data_provider->ConsumeBool());
   73|  11.1k|  }
   74|       |
   75|       |  // Optionally generate a BUS_RESET event with a valid speed value.
   76|  42.6k|  if (_fuzz_data_provider->ConsumeBool()) {
  ------------------
  |  Branch (76:7): [True: 10.3k, False: 32.3k]
  ------------------
   77|  10.3k|    tusb_speed_t speed = (tusb_speed_t)_fuzz_data_provider->ConsumeIntegralInRange<uint8_t>(
   78|  10.3k|        TUSB_SPEED_FULL, TUSB_SPEED_HIGH);
   79|  10.3k|    dcd_event_bus_reset(rhport, speed, _fuzz_data_provider->ConsumeBool());
   80|  10.3k|  }
   81|       |
   82|  42.6k|  if (_fuzz_data_provider->ConsumeBool()) {
  ------------------
  |  Branch (82:7): [True: 16.5k, False: 26.1k]
  ------------------
   83|  16.5k|    constexpr size_t kSetupFrameLength = 8;
   84|  16.5k|    std::vector<uint8_t> setup =
   85|  16.5k|        _fuzz_data_provider->ConsumeBytes<uint8_t>(kSetupFrameLength);
   86|       |    // Fuzz consumer may return less than requested. If this is the case
   87|       |    // we want to make sure that at least that length is allocated and available
   88|       |    // to the signal handler.
   89|  16.5k|    if (setup.size() != kSetupFrameLength) {
  ------------------
  |  Branch (89:9): [True: 425, False: 16.0k]
  ------------------
   90|    425|      setup.resize(kSetupFrameLength);
   91|    425|    }
   92|  16.5k|    dcd_event_setup_received(rhport, setup.data(),
   93|       |                             // Identify trigger as either an interrupt or a
   94|       |                             // syncrhonous call depending on fuzz data.
   95|  16.5k|                             _fuzz_data_provider->ConsumeBool());
   96|  16.5k|  }
   97|  42.6k|}
dcd_int_enable:
   99|  93.2k|void dcd_int_enable(uint8_t rhport) {
  100|  93.2k|  state.interrupts_enabled = true;
  101|  93.2k|  UNUSED(rhport);
  ------------------
  |  |   31|  93.2k|#define UNUSED(x) (void)(x)
  ------------------
  102|  93.2k|  return;
  103|  93.2k|}
dcd_int_disable:
  105|  93.2k|void dcd_int_disable(uint8_t rhport) {
  106|  93.2k|  state.interrupts_enabled = false;
  107|  93.2k|  UNUSED(rhport);
  ------------------
  |  |   31|  93.2k|#define UNUSED(x) (void)(x)
  ------------------
  108|  93.2k|  return;
  109|  93.2k|}
dcd_set_address:
  111|    211|void dcd_set_address(uint8_t rhport, uint8_t dev_addr) {
  112|    211|  UNUSED(rhport);
  ------------------
  |  |   31|    211|#define UNUSED(x) (void)(x)
  ------------------
  113|    211|  state.address = dev_addr;
  114|       |  // Respond with status.
  115|       |  dcd_edpt_xfer(rhport, tu_edpt_addr(0, TUSB_DIR_IN), NULL, 0, false);
  116|    211|  return;
  117|    211|}
dcd_edpt_xfer:
  171|  6.45k|                   uint16_t total_bytes, bool is_isr) {
  172|  6.45k|  UNUSED(rhport);
  ------------------
  |  |   31|  6.45k|#define UNUSED(x) (void)(x)
  ------------------
  173|  6.45k|  UNUSED(buffer);
  ------------------
  |  |   31|  6.45k|#define UNUSED(x) (void)(x)
  ------------------
  174|  6.45k|  UNUSED(total_bytes);
  ------------------
  |  |   31|  6.45k|#define UNUSED(x) (void)(x)
  ------------------
  175|  6.45k|  UNUSED(is_isr);
  ------------------
  |  |   31|  6.45k|#define UNUSED(x) (void)(x)
  ------------------
  176|       |
  177|  6.45k|  uint8_t const dir = tu_edpt_dir(ep_addr);
  178|       |
  179|  6.45k|  if (dir == TUSB_DIR_IN) {
  ------------------
  |  Branch (179:7): [True: 4.60k, False: 1.85k]
  ------------------
  180|  4.60k|    std::vector<uint8_t> temp =
  181|  4.60k|        _fuzz_data_provider->ConsumeBytes<uint8_t>(total_bytes);
  182|  4.60k|    std::copy(temp.begin(), temp.end(), buffer);
  183|  4.60k|  }
  184|       |  // Ignore output data as it's not useful for fuzzing without a more
  185|       |  // complex fuzzed backend. But we need to make sure it's not
  186|       |  // optimised out.
  187|  6.45k|  volatile uint8_t *dont_optimise0 = buffer;
  188|  6.45k|  volatile uint16_t dont_optimise1 = total_bytes;
  189|  6.45k|  UNUSED(dont_optimise0);
  ------------------
  |  |   31|  6.45k|#define UNUSED(x) (void)(x)
  ------------------
  190|  6.45k|  UNUSED(dont_optimise1);
  ------------------
  |  |   31|  6.45k|#define UNUSED(x) (void)(x)
  ------------------
  191|       |
  192|       |
  193|  6.45k|  return _fuzz_data_provider->ConsumeBool();
  194|  6.45k|}
dcd_edpt_stall:
  202|  20.0k|void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr) {
  203|       |
  204|  20.0k|  UNUSED(rhport);
  ------------------
  |  |   31|  20.0k|#define UNUSED(x) (void)(x)
  ------------------
  205|  20.0k|  UNUSED(ep_addr);
  ------------------
  |  |   31|  20.0k|#define UNUSED(x) (void)(x)
  ------------------
  206|  20.0k|  return;
  207|  20.0k|}
dcd_edpt_clear_stall:
  212|    219|void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr) {
  213|       |
  214|    219|  UNUSED(rhport);
  ------------------
  |  |   31|    219|#define UNUSED(x) (void)(x)
  ------------------
  215|    219|  UNUSED(ep_addr);
  ------------------
  |  |   31|    219|#define UNUSED(x) (void)(x)
  ------------------
  216|    219|  return;
  217|    219|}

LLVMFuzzerTestOneInput:
   44|  1.00k|extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
   45|  1.00k|  FuzzedDataProvider provider(Data, Size);
   46|  1.00k|  std::vector<uint8_t> callback_data = provider.ConsumeBytes<uint8_t>(
   47|  1.00k|      provider.ConsumeIntegralInRange<size_t>(0, Size));
   48|  1.00k|  fuzz_init(callback_data.data(), callback_data.size());
   49|  1.00k|  tusb_rhport_init_t dev_init = {
   50|  1.00k|    .role = TUSB_ROLE_DEVICE,
   51|  1.00k|    .speed = TUSB_SPEED_AUTO
   52|  1.00k|  };
   53|  1.00k|  tusb_init(BOARD_TUD_RHPORT, &dev_init);
  ------------------
  |  |  150|  1.00k|#define tusb_init(...)                       TU_FUNC_OPTIONAL_ARG(_tusb_init, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  115|  1.00k|#define TU_FUNC_OPTIONAL_ARG(func, ...)   TU_XSTRCAT(func##_arg, TU_ARGS_NUM(__VA_ARGS__))(__VA_ARGS__)
  |  |  |  |  ------------------
  |  |  |  |  |  |   15|  1.00k|#define TU_XSTRCAT(a, b)      TU_STRCAT(a, b)     ///< expand then concat
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   13|  1.00k|#define TU_STRCAT(a, b)       a##b                ///< concat without expand
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  149|  1.00k|#define _tusb_init_arg2(_rhport, _rh_init)   tusb_rhport_init(_rhport, _rh_init)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   54|       |
   55|  43.6k|  for (int i = 0; i < FUZZ_ITERATIONS; i++) {
  ------------------
  |  |   42|  43.6k|#define FUZZ_ITERATIONS 500
  ------------------
  |  Branch (55:19): [True: 43.6k, False: 50]
  ------------------
   56|  43.6k|    if (provider.remaining_bytes() == 0) {
  ------------------
  |  Branch (56:9): [True: 956, False: 42.6k]
  ------------------
   57|    956|      return 0;
   58|    956|    }
   59|  42.6k|    tud_int_handler(provider.ConsumeIntegral<uint8_t>());
  ------------------
  |  |   88|  42.6k|#define tud_int_handler   dcd_int_handler
  ------------------
   60|  42.6k|    tud_task(); // tinyusb device task
   61|  42.6k|  }
   62|       |
   63|     50|  return 0;
   64|  1.00k|}

tud_descriptor_device_cb:
   46|    210|uint8_t const *tud_descriptor_device_cb(void) {
   47|    210|  tu_static tusb_desc_device_t const desc_device = {
  ------------------
  |  |   39|    210|  #define tu_static static __thread
  ------------------
   48|    210|      .bLength = sizeof(tusb_desc_device_t),
   49|    210|      .bDescriptorType = TUSB_DESC_DEVICE,
   50|    210|      .bcdUSB = USB_BCD,
  ------------------
  |  |   38|    210|#define USB_BCD 0x0200
  ------------------
   51|       |
   52|       |      // Use Interface Association Descriptor (IAD) for CDC
   53|       |      // As required by USB Specs IAD's subclass must be common class (2) and
   54|       |      // protocol must be IAD (1)
   55|    210|      .bDeviceClass = TUSB_CLASS_MISC,
   56|    210|      .bDeviceSubClass = MISC_SUBCLASS_COMMON,
   57|    210|      .bDeviceProtocol = MISC_PROTOCOL_IAD,
   58|       |
   59|    210|      .bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
  ------------------
  |  |   90|    210|#define CFG_TUD_ENDPOINT0_SIZE    64
  ------------------
   60|       |
   61|    210|      .idVendor = USB_VID,
  ------------------
  |  |   37|    210|#define USB_VID 0xCafe
  ------------------
   62|    210|      .idProduct = USB_PID,
  ------------------
  |  |   35|    210|  (0x4000 | PID_MAP(MSC, 0) | PID_MAP(HID, 1) | PID_MAP(MIDI, 2) |          \
  |  |  ------------------
  |  |  |  |   33|    210|#define PID_MAP(itf, n) ((CFG_TUD_##itf) << (n))
  |  |  |  |  ------------------
  |  |  |  |  |  |   95|    210|#define CFG_TUD_MSC              1
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                 (0x4000 | PID_MAP(MSC, 0) | PID_MAP(HID, 1) | PID_MAP(MIDI, 2) |          \
  |  |  ------------------
  |  |  |  |   33|    210|#define PID_MAP(itf, n) ((CFG_TUD_##itf) << (n))
  |  |  |  |  ------------------
  |  |  |  |  |  |   96|    210|#define CFG_TUD_HID              0
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                 (0x4000 | PID_MAP(MSC, 0) | PID_MAP(HID, 1) | PID_MAP(MIDI, 2) |          \
  |  |  ------------------
  |  |  |  |   33|    210|#define PID_MAP(itf, n) ((CFG_TUD_##itf) << (n))
  |  |  |  |  ------------------
  |  |  |  |  |  |   97|    210|#define CFG_TUD_MIDI             0
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   36|    210|   PID_MAP(VENDOR, 3))
  |  |  ------------------
  |  |  |  |   33|    210|#define PID_MAP(itf, n) ((CFG_TUD_##itf) << (n))
  |  |  |  |  ------------------
  |  |  |  |  |  |   98|    210|#define CFG_TUD_VENDOR           0
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   63|    210|      .bcdDevice = 0x0100,
   64|       |
   65|    210|      .iManufacturer = 0x01,
   66|    210|      .iProduct = 0x02,
   67|    210|      .iSerialNumber = 0x03,
   68|       |
   69|    210|      .bNumConfigurations = 0x01};
   70|       |
   71|    210|  return (uint8_t const *)&desc_device;
   72|    210|}
tud_descriptor_configuration_cb:
  161|    483|uint8_t const *tud_descriptor_configuration_cb(uint8_t index) {
  162|    483|  (void)index; // for multiple configurations
  163|       |
  164|       |#if TUD_OPT_HIGH_SPEED
  165|       |  // Although we are highspeed, host may be fullspeed.
  166|       |  return (tud_speed_get() == TUSB_SPEED_HIGH) ? desc_hs_configuration
  167|       |                                              : desc_fs_configuration;
  168|       |#else
  169|    483|  return desc_fs_configuration;
  170|    483|#endif
  171|    483|}
tud_descriptor_string_cb:
  192|    795|uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
  193|    795|  (void)langid;
  194|       |
  195|    795|  uint8_t chr_count;
  196|       |
  197|    795|  if (index == 0) {
  ------------------
  |  Branch (197:7): [True: 221, False: 574]
  ------------------
  198|    221|    memcpy(&_desc_str[1], string_desc_arr[0], 2);
  199|    221|    chr_count = 1;
  200|    574|  } else {
  201|       |    // Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
  202|       |    // https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
  203|       |
  204|    574|    if (!(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])))
  ------------------
  |  Branch (204:9): [True: 207, False: 367]
  ------------------
  205|    207|      return NULL;
  206|       |
  207|    367|    const char *str = string_desc_arr[index];
  208|       |
  209|       |    // Cap at max char
  210|    367|    chr_count = (uint8_t)strlen(str);
  211|    367|    if (chr_count > 31)
  ------------------
  |  Branch (211:9): [True: 0, False: 367]
  ------------------
  212|      0|      chr_count = 31;
  213|       |
  214|       |    // Convert ASCII string into UTF-16
  215|  5.35k|    for (uint8_t i = 0; i < chr_count; i++) {
  ------------------
  |  Branch (215:25): [True: 4.99k, False: 367]
  ------------------
  216|  4.99k|      _desc_str[1 + i] = str[i];
  217|  4.99k|    }
  218|    367|  }
  219|       |
  220|       |  // first byte is length (including header), second byte is string type
  221|    588|  _desc_str[0] = (uint16_t)((TUSB_DESC_STRING << 8) | (2 * chr_count + 2));
  222|       |
  223|    588|  return _desc_str;
  224|    795|}

fuzz_init:
   31|  1.00k|extern "C" int fuzz_init(const uint8_t *data, size_t size) {
   32|  1.00k|  _fuzz_data_provider.emplace(data, size);
   33|  1.00k|  return 0;
   34|  1.00k|}

