mscd_init:
  357|      1|void mscd_init(void) {
  358|      1|  TU_LOG_INT(CFG_TUD_MSC_LOG_LEVEL, sizeof(mscd_interface_t));
  359|      1|  tu_memclr(&_mscd_itf, sizeof(mscd_interface_t));
  ------------------
  |  |  114|      1|#define tu_memclr(buffer, size)  (void) memset((buffer), 0, (size))
  ------------------
  360|      1|}
mscd_reset:
  366|  15.7k|void mscd_reset(uint8_t rhport) {
  367|  15.7k|  (void) rhport;
  368|  15.7k|  tu_memclr(&_mscd_itf, sizeof(mscd_interface_t));
  ------------------
  |  |  114|  15.7k|#define tu_memclr(buffer, size)  (void) memset((buffer), 0, (size))
  ------------------
  369|  15.7k|}
mscd_open:
  371|    209|uint16_t mscd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len) {
  372|       |  // only support SCSI's BOT protocol
  373|    209|  TU_VERIFY(TUSB_CLASS_MSC    == itf_desc->bInterfaceClass &&
  ------------------
  |  |  114|    209|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    209|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  114|    209|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  112|    209|#define TU_VERIFY_2ARGS(_cond, _ret)   TU_VERIFY_DEFINE(_cond, _ret)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  105|    209|  do {                                \
  |  |  |  |  |  |  |  |  |  |  106|    836|    if (!(_cond)) {                   \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:11): [True: 209, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:11): [True: 209, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:11): [True: 209, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  107|      0|      return _ret;                    \
  |  |  |  |  |  |  |  |  |  |  108|      0|    }                                 \
  |  |  |  |  |  |  |  |  |  |  109|    209|  } while (0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (109:12): [Folded, False: 209]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  374|    209|            MSC_SUBCLASS_SCSI == itf_desc->bInterfaceSubClass &&
  375|    209|            MSC_PROTOCOL_BOT  == itf_desc->bInterfaceProtocol, 0);
  376|    209|  uint16_t const drv_len = sizeof(tusb_desc_interface_t) + 2*sizeof(tusb_desc_endpoint_t);
  377|    209|  TU_ASSERT(max_len >= drv_len, 0); // Max length must be at least 1 interface + 2 endpoints
  ------------------
  |  |  131|    209|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    209|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|    209|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  128|    209|#define TU_ASSERT_2ARGS(_cond, _ret)   TU_ASSERT_DEFINE(_cond, _ret)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|    209|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|    209|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   73|      0|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (73:41): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   96|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (96:40): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (124:10): [True: 0, False: 209]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|    209|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 209]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  378|       |
  379|    209|  mscd_interface_t * p_msc = &_mscd_itf;
  380|    209|  p_msc->itf_num = itf_desc->bInterfaceNumber;
  381|    209|  p_msc->rhport = rhport;
  382|       |
  383|       |  // Open endpoint pair
  384|    209|  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);
  ------------------
  |  |  131|    209|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    209|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|    209|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  128|    209|#define TU_ASSERT_2ARGS(_cond, _ret)   TU_ASSERT_DEFINE(_cond, _ret)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|    209|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|    209|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   73|    209|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (73:41): [Folded, False: 209]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   96|    209|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (96:40): [Folded, False: 209]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (124:10): [True: 209, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|    209|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  385|       |
  386|       |  // Prepare for Command Block Wrapper
  387|      0|  TU_ASSERT(prepare_cbw(p_msc), drv_len);
  ------------------
  |  |  131|      0|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|      0|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|      0|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  128|      0|#define TU_ASSERT_2ARGS(_cond, _ret)   TU_ASSERT_DEFINE(_cond, _ret)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|      0|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|      0|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   73|      0|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (73:41): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   96|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (96:40): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (124:10): [True: 0, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|      0|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  388|       |
  389|      0|  return drv_len;
  390|      0|}

tusb_fifo.c:tu_min16:
  206|  34.4k|TU_ATTR_ALWAYS_INLINE static inline uint16_t tu_min16 (uint16_t x, uint16_t y) { return (x < y) ? x : y; }
  ------------------
  |  Branch (206:89): [True: 34.4k, False: 0]
  ------------------
usbd.c:tu_min16:
  206|  5.36k|TU_ATTR_ALWAYS_INLINE static inline uint16_t tu_min16 (uint16_t x, uint16_t y) { return (x < y) ? x : y; }
  ------------------
  |  Branch (206:89): [True: 4.38k, False: 983]
  ------------------
usbd.c:tu_memcpy_s:
  137|    391|TU_ATTR_ALWAYS_INLINE static inline int tu_memcpy_s(void *dest, size_t destsz, const void *src, size_t count) {
  138|    391|  if (dest == NULL) {
  ------------------
  |  Branch (138:7): [True: 0, False: 391]
  ------------------
  139|      0|    return -1;
  140|      0|  }
  141|       |
  142|    391|  if (count == 0u) {
  ------------------
  |  Branch (142:7): [True: 0, False: 391]
  ------------------
  143|      0|    return 0;
  144|      0|  }
  145|       |
  146|    391|  if (src == NULL) {
  ------------------
  |  Branch (146:7): [True: 0, False: 391]
  ------------------
  147|      0|    return -1;
  148|      0|  }
  149|       |
  150|    391|  if (count > destsz) {
  ------------------
  |  Branch (150:7): [True: 0, False: 391]
  ------------------
  151|      0|    return -1;
  152|      0|  }
  153|       |
  154|    391|  (void) memcpy(dest, src, count);
  155|    391|  return 0;
  156|    391|}
usbd.c:tu_u16_low:
  197|  5.52k|TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_u16_low (uint16_t ui16) { return TU_U16_LOW(ui16); }
  ------------------
  |  |   46|  5.52k|#define TU_U16_LOW(_u16)              ((uint8_t) ((uint16_t) (_u16) & 0x00ffu))
  ------------------
usbd.c:tu_desc_in_bounds:
  390|    209|TU_ATTR_ALWAYS_INLINE static inline bool tu_desc_in_bounds(const uint8_t *p_desc, const uint8_t *desc_end) {
  391|    209|  return p_desc < desc_end && tu_desc_next(p_desc) <= desc_end;
  ------------------
  |  Branch (391:10): [True: 209, False: 0]
  |  Branch (391:31): [True: 209, False: 0]
  ------------------
  392|    209|}
usbd.c:tu_desc_type:
  381|    418|TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_desc_type(void const* desc) {
  382|    418|  return ((uint8_t const*) desc)[DESC_OFFSET_TYPE];
  383|    418|}
usbd.c:tu_u16_high:
  196|  2.45k|TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_u16_high(uint16_t ui16) { return TU_U16_HIGH(ui16); }
  ------------------
  |  |   45|  2.45k|#define TU_U16_HIGH(_u16)             ((uint8_t) (((uint16_t) (_u16) >> 8) & 0x00ffu))
  ------------------
usbd.c:tu_unaligned_read16:
  271|    390|TU_ATTR_ALWAYS_INLINE static inline uint16_t tu_unaligned_read16(const void *mem) {
  272|    390|  tu_unaligned_uint16_t const *ua16 = (tu_unaligned_uint16_t const *) mem;
  273|    390|  return ua16->val;
  274|    390|}
usbd.c:tu_desc_len:
  376|    772|TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_desc_len(void const* desc) {
  377|    772|  return ((uint8_t const*) desc)[DESC_OFFSET_LEN];
  378|    772|}
usbd.c:tu_desc_next:
  370|    209|TU_ATTR_ALWAYS_INLINE static inline uint8_t const * tu_desc_next(void const* desc) {
  371|    209|  uint8_t const* desc8 = (uint8_t const*) desc;
  372|    209|  return desc8 + desc8[DESC_OFFSET_LEN];
  373|    209|}
msc_device.c:tu_desc_next:
  370|    209|TU_ATTR_ALWAYS_INLINE static inline uint8_t const * tu_desc_next(void const* desc) {
  371|    209|  uint8_t const* desc8 = (uint8_t const*) desc;
  372|    209|  return desc8 + desc8[DESC_OFFSET_LEN];
  373|    209|}

tu_fifo_clear:
   81|      1|void tu_fifo_clear(tu_fifo_t *f) {
   82|      1|  ff_lock(f->mutex_wr);
   83|      1|  ff_lock(f->mutex_rd);
   84|       |
   85|      1|  f->rd_idx = 0;
   86|      1|  f->wr_idx = 0;
   87|       |
   88|      1|  ff_unlock(f->mutex_wr);
   89|      1|  ff_unlock(f->mutex_rd);
   90|      1|}
tu_fifo_peek_n_access_mode:
  463|  76.1k|                                    const tu_hwfifo_access_t *access_mode) {
  464|  76.1k|  uint16_t count = tu_ff_overflow_count(f->depth, wr_idx, rd_idx);
  465|  76.1k|  if (count == 0) {
  ------------------
  |  Branch (465:7): [True: 41.7k, False: 34.4k]
  ------------------
  466|  41.7k|    return 0; // nothing to peek
  467|  41.7k|  }
  468|       |
  469|       |  // Check overflow and correct if required
  470|  34.4k|  if (count > f->depth) {
  ------------------
  |  Branch (470:7): [True: 0, False: 34.4k]
  ------------------
  471|      0|    rd_idx = correct_read_index(f, wr_idx);
  472|      0|    count  = f->depth;
  473|      0|  }
  474|       |
  475|  34.4k|  if (count < n) {
  ------------------
  |  Branch (475:7): [True: 0, False: 34.4k]
  ------------------
  476|      0|    n = count; // limit to available count
  477|      0|  }
  478|       |
  479|  34.4k|  const uint16_t rd_ptr = idx2ptr(f->depth, rd_idx);
  480|       |
  481|       |#if CFG_TUSB_FIFO_HWFIFO_API
  482|       |  if (access_mode != NULL) {
  483|       |    hwff_pull_n(f, p_buffer, n, rd_ptr, access_mode);
  484|       |  } else
  485|       |#endif
  486|  34.4k|  {
  487|  34.4k|    (void)access_mode;
  488|  34.4k|    ff_pull_n(f, p_buffer, n, rd_ptr);
  489|  34.4k|  }
  490|       |
  491|  34.4k|  return n;
  492|  76.1k|}
tu_fifo_read_n_access_mode:
  505|  76.1k|uint16_t tu_fifo_read_n_access_mode(tu_fifo_t *f, void *buffer, uint16_t n, const tu_hwfifo_access_t *access_mode) {
  506|  76.1k|  ff_lock(f->mutex_rd);
  507|       |
  508|       |  // Peek the data: f->rd_idx might get modified in case of an overflow so we can not use a local variable
  509|  76.1k|  const uint16_t wr_idx = f->wr_idx;
  510|  76.1k|  n         = tu_fifo_peek_n_access_mode(f, buffer, n, wr_idx, f->rd_idx, access_mode);
  511|  76.1k|  f->rd_idx = advance_index(f->depth, f->rd_idx, n);
  512|       |
  513|  76.1k|  ff_unlock(f->mutex_rd);
  514|  76.1k|  return n;
  515|  76.1k|}
tu_fifo_write_n_access_mode:
  519|  34.4k|                                     const tu_hwfifo_access_t *access_mode) {
  520|  34.4k|  if (n == 0) {
  ------------------
  |  Branch (520:7): [True: 0, False: 34.4k]
  ------------------
  521|      0|    return 0;
  522|      0|  }
  523|       |
  524|  34.4k|  ff_lock(f->mutex_wr);
  525|       |
  526|  34.4k|  uint16_t wr_idx = f->wr_idx;
  527|  34.4k|  uint16_t rd_idx = f->rd_idx;
  528|       |
  529|  34.4k|  const uint8_t *buf8 = (const uint8_t *)data;
  530|       |
  531|  34.4k|  TU_LOG(TU_FIFO_DBG, "rd = %3u, wr = %3u, count = %3u, remain = %3u, n = %3u:  ", rd_idx, wr_idx,
  532|  34.4k|         tu_ff_overflow_count(f->depth, wr_idx, rd_idx), tu_ff_remaining_local(f->depth, wr_idx, rd_idx), n);
  533|       |
  534|  34.4k|  if (!f->overwritable) {
  ------------------
  |  Branch (534:7): [True: 34.4k, False: 0]
  ------------------
  535|       |    // limit up to full
  536|  34.4k|    const uint16_t remain = tu_ff_remaining_local(f->depth, wr_idx, rd_idx);
  537|  34.4k|    n                     = tu_min16(n, remain);
  538|  34.4k|  } else {
  539|       |    // In over-writable mode, fifo_write() is allowed even when fifo is full. In such case,
  540|       |    // oldest data in fifo i.e. at read pointer data will be overwritten
  541|       |    // Note: we can modify read buffer contents however we must not modify the read index itself within a write
  542|       |    // function! Since it would end up in a race condition with read functions!
  543|      0|    if (n >= f->depth) {
  ------------------
  |  Branch (543:9): [True: 0, False: 0]
  ------------------
  544|       |      // Only copy last part
  545|      0|      if (access_mode == NULL) {
  ------------------
  |  Branch (545:11): [True: 0, False: 0]
  ------------------
  546|      0|        buf8 += (n - f->depth);
  547|      0|      } else {
  548|       |        // TODO should read from hw fifo to discard data, however reading an odd number could
  549|       |        // accidentally discard data.
  550|      0|      }
  551|       |
  552|      0|      n = f->depth;
  553|       |
  554|       |      // We start writing at the read pointer's position since we fill the whole buffer
  555|      0|      wr_idx = rd_idx;
  556|      0|    } else {
  557|      0|      const uint16_t overflowable_count = tu_ff_overflow_count(f->depth, wr_idx, rd_idx);
  558|      0|      if (overflowable_count + n >= 2 * f->depth) {
  ------------------
  |  Branch (558:11): [True: 0, False: 0]
  ------------------
  559|       |        // Double overflowed
  560|       |        // Index is bigger than the allowed range [0,2*depth)
  561|       |        // re-position write index to have a full fifo after pushed
  562|      0|        wr_idx = advance_index(f->depth, rd_idx, f->depth - n);
  563|       |
  564|       |        // TODO we should also shift out n bytes from read index since we avoid changing rd index !!
  565|       |        // However memmove() is expensive due to actual copying + wrapping consideration.
  566|       |        // Also race condition could happen anyway if read() is invoke while moving result in corrupted memory
  567|       |        // currently deliberately not implemented --> result in incorrect data read back
  568|      0|      } else {
  569|       |        // normal + single overflowed:
  570|       |        // Index is in the range of [0,2*depth) and thus detect and recoverable. Recovering is handled in read()
  571|       |        // Therefore we just increase write index
  572|       |        // we will correct (re-position) read index later on in fifo_read() function
  573|      0|      }
  574|      0|    }
  575|      0|  }
  576|       |
  577|  34.4k|  if (n) {
  ------------------
  |  Branch (577:7): [True: 34.4k, False: 0]
  ------------------
  578|  34.4k|    const uint16_t wr_ptr = idx2ptr(f->depth, wr_idx);
  579|  34.4k|    TU_LOG(TU_FIFO_DBG, "actual_n = %u, wr_ptr = %u", n, wr_ptr);
  580|       |
  581|       |#if CFG_TUSB_FIFO_HWFIFO_API
  582|       |    if (access_mode != NULL) {
  583|       |      hwff_push_n(f, buf8, n, wr_ptr, access_mode);
  584|       |    } else
  585|       |#endif
  586|  34.4k|    {
  587|  34.4k|      ff_push_n(f, buf8, n, wr_ptr);
  588|  34.4k|    }
  589|  34.4k|    f->wr_idx = advance_index(f->depth, wr_idx, n);
  590|       |
  591|  34.4k|    TU_LOG(TU_FIFO_DBG, "\tnew_wr = %u\r\n", f->wr_idx);
  592|  34.4k|  }
  593|       |
  594|  34.4k|  ff_unlock(f->mutex_wr);
  595|       |
  596|  34.4k|  return n;
  597|  34.4k|}
tusb_fifo.c:idx2ptr:
  434|  68.8k|TU_ATTR_ALWAYS_INLINE static inline uint16_t idx2ptr(uint16_t depth, uint16_t idx) {
  435|       |  // Only run at most 3 times since index is limit in the range of [0..2*depth)
  436|   103k|  while (idx >= depth) {
  ------------------
  |  Branch (436:10): [True: 34.4k, False: 68.8k]
  ------------------
  437|  34.4k|    idx -= depth;
  438|  34.4k|  }
  439|  68.8k|  return idx;
  440|  68.8k|}
tusb_fifo.c:ff_pull_n:
  398|  34.4k|static void ff_pull_n(const tu_fifo_t *f, void *app_buf, uint16_t n, uint16_t rd_ptr) {
  399|  34.4k|  uint16_t       lin_bytes  = f->depth - rd_ptr;
  400|  34.4k|  uint16_t       wrap_bytes = n - lin_bytes; // only used if wrapped
  401|  34.4k|  const uint8_t *ff_buf     = f->buffer + rd_ptr;
  402|       |
  403|       |  // single byte access
  404|  34.4k|  if (n <= lin_bytes) {
  ------------------
  |  Branch (404:7): [True: 34.4k, False: 0]
  ------------------
  405|       |    // Linear only
  406|  34.4k|    memcpy(app_buf, ff_buf, n);
  407|  34.4k|  } else {
  408|       |    // Wrap around
  409|      0|    memcpy(app_buf, ff_buf, lin_bytes);                            // linear part
  410|      0|    memcpy((uint8_t *)app_buf + lin_bytes, f->buffer, wrap_bytes); // wrapped part
  411|      0|  }
  412|  34.4k|}
tusb_fifo.c:advance_index:
  420|   110k|static uint16_t advance_index(uint16_t depth, uint16_t idx, uint16_t offset) {
  421|       |  // We limit the index space of p such that a correct wrap around happens
  422|       |  // Check for a wrap around or if we are in unused index space - This has to be checked first!!
  423|       |  // We are exploiting the wrap around to the correct index
  424|   110k|  uint16_t new_idx = (uint16_t)(idx + offset);
  425|   110k|  if ((idx > new_idx) || (new_idx >= 2 * depth)) {
  ------------------
  |  Branch (425:7): [True: 0, False: 110k]
  |  Branch (425:26): [True: 2.15k, False: 108k]
  ------------------
  426|  2.15k|    const uint16_t non_used_index_space = (uint16_t)(UINT16_MAX - (2 * depth - 1));
  427|  2.15k|    new_idx                             = (uint16_t)(new_idx + non_used_index_space);
  428|  2.15k|  }
  429|       |
  430|   110k|  return new_idx;
  431|   110k|}
tusb_fifo.c:ff_push_n:
  382|  34.4k|static void ff_push_n(const tu_fifo_t *f, const void *app_buf, uint16_t n, uint16_t wr_ptr) {
  383|  34.4k|  uint16_t lin_bytes  = f->depth - wr_ptr;
  384|  34.4k|  uint16_t wrap_bytes = n - lin_bytes;
  385|  34.4k|  uint8_t *ff_buf     = f->buffer + wr_ptr;
  386|       |
  387|  34.4k|  if (n <= lin_bytes) {
  ------------------
  |  Branch (387:7): [True: 34.4k, False: 0]
  ------------------
  388|       |    // Linear only case
  389|  34.4k|    memcpy(ff_buf, app_buf, n);
  390|  34.4k|  } else {
  391|       |    // Wrap around case
  392|      0|    memcpy(ff_buf, app_buf, lin_bytes);                                    // linear part
  393|      0|    memcpy(f->buffer, ((const uint8_t *)app_buf) + lin_bytes, wrap_bytes); // wrapped part
  394|      0|  }
  395|  34.4k|}

tusb_fifo.c:tu_ff_overflow_count:
  262|   110k|TU_ATTR_ALWAYS_INLINE static inline uint16_t tu_ff_overflow_count(uint16_t depth, uint16_t wr_idx, uint16_t rd_idx) {
  263|   110k|  const int32_t diff = (int32_t)wr_idx - (int32_t)rd_idx;
  264|   110k|  if (diff >= 0) {
  ------------------
  |  Branch (264:7): [True: 108k, False: 2.37k]
  ------------------
  265|   108k|    return (uint16_t)diff;
  266|   108k|  } else {
  267|  2.37k|    return (uint16_t)(2 * depth + diff);
  268|  2.37k|  }
  269|   110k|}
tusb_fifo.c:tu_ff_remaining_local:
  272|  34.4k|TU_ATTR_ALWAYS_INLINE static inline uint16_t tu_ff_remaining_local(uint16_t depth, uint16_t wr_idx, uint16_t rd_idx) {
  273|  34.4k|  const uint16_t ovf_count = tu_ff_overflow_count(depth, wr_idx, rd_idx);
  274|  34.4k|  return (depth > ovf_count) ? (depth - ovf_count) : 0;
  ------------------
  |  Branch (274:10): [True: 34.4k, False: 0]
  ------------------
  275|  34.4k|}
usbd.c:tu_fifo_read_n:
  211|  76.1k|TU_ATTR_ALWAYS_INLINE static inline uint16_t tu_fifo_read_n(tu_fifo_t *f, void *buffer, uint16_t n) {
  212|       |  return tu_fifo_read_n_access_mode(f, buffer, n, NULL);
  213|  76.1k|}
usbd.c:tu_fifo_write_n:
  224|  34.4k|TU_ATTR_ALWAYS_INLINE static inline uint16_t tu_fifo_write_n(tu_fifo_t *f, const void *data, uint16_t n) {
  225|       |  return tu_fifo_write_n_access_mode(f, data, n, NULL);
  226|  34.4k|}

usbd.c:tu_edpt_number:
  579|  8.52k|TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_edpt_number(uint8_t addr) {
  580|  8.52k|  return (uint8_t) (addr & TUSB_EPNUM_MASK);
  581|  8.52k|}
usbd.c:tu_edpt_dir:
  574|  8.31k|TU_ATTR_ALWAYS_INLINE static inline tusb_dir_t tu_edpt_dir(uint8_t addr) {
  575|  8.31k|  return (addr & TUSB_DIR_IN_MASK) ? TUSB_DIR_IN : TUSB_DIR_OUT;
  ------------------
  |  Branch (575:10): [True: 4.26k, False: 4.04k]
  ------------------
  576|  8.31k|}
dcd_fuzz.cc:_ZL12tu_edpt_addrhh:
  583|    218|TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_edpt_addr(uint8_t num, uint8_t dir) {
  584|    218|  return (uint8_t) (num | (dir == (uint8_t)TUSB_DIR_IN ? (uint8_t)TUSB_DIR_IN_MASK : 0u));
  ------------------
  |  Branch (584:28): [True: 218, False: 0]
  ------------------
  585|    218|}
dcd_fuzz.cc:_ZL11tu_edpt_dirh:
  574|  6.00k|TU_ATTR_ALWAYS_INLINE static inline tusb_dir_t tu_edpt_dir(uint8_t addr) {
  575|  6.00k|  return (addr & TUSB_DIR_IN_MASK) ? TUSB_DIR_IN : TUSB_DIR_OUT;
  ------------------
  |  Branch (575:10): [True: 4.15k, False: 1.85k]
  ------------------
  576|  6.00k|}

dcd_fuzz.cc:_ZL20dcd_event_bus_signalh13dcd_eventid_tb:
  200|  10.2k|TU_ATTR_ALWAYS_INLINE static inline void dcd_event_bus_signal (uint8_t rhport, dcd_eventid_t eid, bool in_isr) {
  201|  10.2k|  dcd_event_t event;
  202|  10.2k|  event.rhport = rhport;
  203|  10.2k|  event.event_id = eid;
  204|  10.2k|  dcd_event_handler(&event, in_isr);
  205|  10.2k|}
dcd_fuzz.cc:_ZL19dcd_event_bus_reseth12tusb_speed_tb:
  208|  9.59k|TU_ATTR_ALWAYS_INLINE static inline  void dcd_event_bus_reset (uint8_t rhport, tusb_speed_t speed, bool in_isr) {
  209|  9.59k|  dcd_event_t event;
  210|  9.59k|  event.rhport = rhport;
  211|  9.59k|  event.event_id = DCD_EVENT_BUS_RESET;
  212|  9.59k|  event.bus_reset.speed = speed;
  213|  9.59k|  dcd_event_handler(&event, in_isr);
  214|  9.59k|}
dcd_fuzz.cc:_ZL24dcd_event_setup_receivedhPKhb:
  217|  15.4k|TU_ATTR_ALWAYS_INLINE static inline void dcd_event_setup_received(uint8_t rhport, uint8_t const * setup, bool in_isr) {
  218|  15.4k|  dcd_event_t event;
  219|  15.4k|  event.rhport = rhport;
  220|  15.4k|  event.event_id = DCD_EVENT_SETUP_RECEIVED;
  221|  15.4k|  (void) memcpy(&event.setup_received, setup, sizeof(tusb_control_request_t));
  222|       |  // USB wire format is little-endian. Convert multi-byte fields to host byte order
  223|       |  // so the stack always sees correct values regardless of CPU endianness.
  224|  15.4k|  event.setup_received.wValue  = tu_le16toh(event.setup_received.wValue);
  ------------------
  |  |  272|  15.4k|  #define tu_le16toh(u16) (u16)
  ------------------
  225|  15.4k|  event.setup_received.wIndex  = tu_le16toh(event.setup_received.wIndex);
  ------------------
  |  |  272|  15.4k|  #define tu_le16toh(u16) (u16)
  ------------------
  226|  15.4k|  event.setup_received.wLength = tu_le16toh(event.setup_received.wLength);
  ------------------
  |  |  272|  15.4k|  #define tu_le16toh(u16) (u16)
  ------------------
  227|  15.4k|  dcd_event_handler(&event, in_isr);
  228|  15.4k|}

tud_event_hook_cb:
   48|  34.4k|TU_ATTR_WEAK void tud_event_hook_cb(uint8_t rhport, uint32_t eventid, bool in_isr) {
   49|  34.4k|  (void) rhport; (void) eventid; (void) in_isr;
   50|  34.4k|}
tud_descriptor_bos_cb:
   56|    202|TU_ATTR_WEAK uint8_t const* tud_descriptor_bos_cb(void) {
   57|       |  return NULL;
   58|    202|}
tud_descriptor_device_qualifier_cb:
   60|    209|TU_ATTR_WEAK uint8_t const* tud_descriptor_device_qualifier_cb(void) {
   61|       |  return NULL;
   62|    209|}
tud_descriptor_other_speed_configuration_cb:
   64|    198|TU_ATTR_WEAK uint8_t const* tud_descriptor_other_speed_configuration_cb(uint8_t index) {
   65|    198|  (void) index;
   66|       |  return NULL;
   67|    198|}
tud_umount_cb:
   72|  6.12k|TU_ATTR_WEAK void tud_umount_cb(void) {
   73|  6.12k|}
tud_suspend_cb:
   75|  2.05k|TU_ATTR_WEAK void tud_suspend_cb(bool remote_wakeup_en) {
   76|  2.05k|  (void) remote_wakeup_en;
   77|  2.05k|}
tud_resume_cb:
   79|  1.23k|TU_ATTR_WEAK void tud_resume_cb(void) {
   80|  1.23k|}
tud_vendor_control_xfer_cb:
   82|  1.75k|TU_ATTR_WEAK bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const* request) {
   83|  1.75k|  (void) rhport; (void) stage; (void) request;
   84|       |  return false;
   85|  1.75k|}
usbd_app_driver_get_cb:
  457|      1|TU_ATTR_WEAK usbd_class_driver_t const* usbd_app_driver_get_cb(uint8_t* driver_count) {
  458|      1|  *driver_count = 0;
  459|       |  return NULL;
  460|      1|}
tud_inited:
  530|  42.7k|bool tud_inited(void) {
  531|  42.7k|  return _usbd_rhport != RHPORT_INVALID;
  532|  42.7k|}
tud_rhport_init:
  538|  1.02k|bool tud_rhport_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
  539|  1.02k|  if (tud_inited()) {
  ------------------
  |  Branch (539:7): [True: 1.01k, False: 1]
  ------------------
  540|  1.01k|    return true; // skip if already initialized
  541|  1.01k|  }
  542|      1|  TU_ASSERT(rh_init);
  ------------------
  |  |  131|      1|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|      1|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|      1|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  127|      1|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|      1|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|      1|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   73|      0|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (73:41): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   96|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (96:40): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (124:10): [True: 0, False: 1]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|      1|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 1]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  543|       | #if CFG_TUSB_DEBUG >= CFG_TUD_LOG_LEVEL
  544|       |  char const* speed_str = 0;
  545|       |  switch (rh_init->speed) {
  546|       |    case TUSB_SPEED_HIGH:
  547|       |      speed_str = "High";
  548|       |    break;
  549|       |    case TUSB_SPEED_FULL:
  550|       |      speed_str = "Full";
  551|       |    break;
  552|       |    case TUSB_SPEED_LOW:
  553|       |      speed_str = "Low";
  554|       |    break;
  555|       |    case TUSB_SPEED_AUTO:
  556|       |      speed_str = "Auto";
  557|       |    break;
  558|       |  default:
  559|       |    break;
  560|       |  }
  561|       |  TU_LOG_USBD("USBD init on controller %u, speed = %s\r\n", rhport, speed_str);
  562|       |  TU_LOG_INT(CFG_TUD_LOG_LEVEL, sizeof(usbd_device_t));
  563|       |  TU_LOG_INT(CFG_TUD_LOG_LEVEL, sizeof(dcd_event_t));
  564|       |  TU_LOG_INT(CFG_TUD_LOG_LEVEL, sizeof(tu_fifo_t));
  565|       |  TU_LOG_INT(CFG_TUD_LOG_LEVEL, sizeof(tu_edpt_stream_t));
  566|       |#endif
  567|       |
  568|      1|  tu_varclr(&_usbd_dev);
  ------------------
  |  |  115|      1|#define tu_varclr(_var)          tu_memclr(_var, sizeof(*(_var)))
  |  |  ------------------
  |  |  |  |  114|      1|#define tu_memclr(buffer, size)  (void) memset((buffer), 0, (size))
  |  |  ------------------
  ------------------
  569|      1|  _usbd_queued_setup = 0;
  570|       |
  571|      1|  osal_spin_init(&_usbd_spin);
  572|       |
  573|       |#if OSAL_MUTEX_REQUIRED
  574|       |  // Init device mutex
  575|       |  _usbd_mutex = osal_mutex_create(&_ubsd_mutexdef);
  576|       |  TU_ASSERT(_usbd_mutex);
  577|       |#endif
  578|       |
  579|       |  // Init device queue & task
  580|      1|  _usbd_q = osal_queue_create(&_usbd_qdef);
  581|      1|  TU_ASSERT(_usbd_q);
  ------------------
  |  |  131|      1|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|      1|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|      1|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  127|      1|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|      1|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|      1|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   73|      0|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (73:41): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   96|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (96:40): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (124:10): [True: 0, False: 1]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|      1|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 1]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  582|       |
  583|       |  // Get application driver if available
  584|      1|  _app_driver = usbd_app_driver_get_cb(&_app_driver_count);
  585|      1|  TU_ASSERT(_app_driver_count + BUILTIN_DRIVER_COUNT <= UINT8_MAX);
  ------------------
  |  |  131|      1|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|      1|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|      1|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  127|      1|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|      1|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|      1|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   73|      0|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (73:41): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   96|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (96:40): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (124:10): [True: 0, False: 1]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|      1|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 1]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  586|       |
  587|       |  // Init class drivers
  588|      2|  for (uint8_t i = 0; i < TOTAL_DRIVER_COUNT; i++) {
  ------------------
  |  |  389|      2|#define TOTAL_DRIVER_COUNT    ((uint8_t) (_app_driver_count + BUILTIN_DRIVER_COUNT))
  ------------------
  |  Branch (588:23): [True: 1, False: 1]
  ------------------
  589|      1|    usbd_class_driver_t const* driver = get_driver(i);
  590|      1|    TU_ASSERT(driver && driver->init);
  ------------------
  |  |  131|      1|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|      1|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|      1|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  127|      1|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|      1|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|      2|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   73|      0|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (73:41): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   96|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (96:40): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (124:12): [True: 1, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  Branch (124:12): [True: 1, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|      1|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 1]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  591|      1|    TU_LOG_USBD("%s init\r\n", driver->name);
  592|      1|    driver->init();
  593|      1|  }
  594|       |
  595|      1|  _usbd_rhport = rhport;
  596|       |
  597|       |  // Init device controller driver
  598|      1|  TU_ASSERT(dcd_init(rhport, rh_init));
  ------------------
  |  |  131|      1|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|      1|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|      1|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  127|      1|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|      1|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|      1|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   73|      0|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (73:41): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   96|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (96:40): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (124:10): [True: 0, False: 1]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|      1|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 1]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  599|      1|  dcd_int_enable(rhport);
  600|       |
  601|       |  return true;
  602|      1|}
tud_task_ext:
  686|  41.7k|void tud_task_ext(uint32_t timeout_ms, bool in_isr) {
  687|  41.7k|  (void) in_isr; // not implemented yet
  688|       |
  689|       |  // Skip if stack is not initialized
  690|  41.7k|  if (!tud_inited()) {
  ------------------
  |  Branch (690:7): [True: 0, False: 41.7k]
  ------------------
  691|      0|    return;
  692|      0|  }
  693|       |
  694|       |  // Loop until there are no more events in the queue or CFG_TUD_TASK_EVENTS_PER_RUN is reached
  695|  76.1k|  for (unsigned epr = 0;; epr++) {
  696|  76.1k|#if CFG_TUD_TASK_EVENTS_PER_RUN > 0
  697|  76.1k|    if (epr >= CFG_TUD_TASK_EVENTS_PER_RUN) {
  ------------------
  |  |  586|  76.1k|  #define CFG_TUD_TASK_EVENTS_PER_RUN  16
  ------------------
  |  Branch (697:9): [True: 0, False: 76.1k]
  ------------------
  698|      0|      TU_LOG_USBD("USBD event limit (" TU_XSTRING(CFG_TUD_TASK_EVENTS_PER_RUN) ") reached\r\n");
  699|      0|      break;
  700|      0|    }
  701|  76.1k|#endif
  702|  76.1k|    dcd_event_t event;
  703|  76.1k|    if (!osal_queue_receive(_usbd_q, &event, timeout_ms)) {
  ------------------
  |  Branch (703:9): [True: 41.7k, False: 34.4k]
  ------------------
  704|  41.7k|      return;
  705|  41.7k|    }
  706|       |
  707|       |#if CFG_TUSB_DEBUG >= CFG_TUD_LOG_LEVEL
  708|       |    if (event.event_id == DCD_EVENT_SETUP_RECEIVED) {
  709|       |      TU_LOG_USBD("\r\n"); // extra line for setup
  710|       |    }
  711|       |    TU_LOG_USBD("USBD %s ", event.event_id < DCD_EVENT_COUNT ? _usbd_event_str[event.event_id] : "CORRUPTED");
  712|       |#endif
  713|       |
  714|  34.4k|    switch (event.event_id) {
  715|  9.59k|      case DCD_EVENT_BUS_RESET:
  ------------------
  |  Branch (715:7): [True: 9.59k, False: 24.8k]
  ------------------
  716|  9.59k|        TU_LOG_USBD(": %s Speed\r\n", tu_str_speed[event.bus_reset.speed]);
  717|  9.59k|        usbd_reset(event.rhport);
  718|  9.59k|        _usbd_dev.speed = event.bus_reset.speed;
  719|  9.59k|        break;
  720|       |
  721|  6.12k|      case DCD_EVENT_UNPLUGGED:
  ------------------
  |  Branch (721:7): [True: 6.12k, False: 28.3k]
  ------------------
  722|  6.12k|        TU_LOG_USBD("\r\n");
  723|  6.12k|        usbd_reset(event.rhport);
  724|  6.12k|        tud_umount_cb();
  725|  6.12k|        break;
  726|       |
  727|  15.4k|      case DCD_EVENT_SETUP_RECEIVED:
  ------------------
  |  Branch (727:7): [True: 15.4k, False: 19.0k]
  ------------------
  728|  15.4k|        if (_usbd_queued_setup == 0) {
  ------------------
  |  Branch (728:13): [True: 0, False: 15.4k]
  ------------------
  729|      0|          break;
  730|      0|        }
  731|  15.4k|        _usbd_queued_setup--;
  732|  15.4k|        TU_LOG_BUF(CFG_TUD_LOG_LEVEL, &event.setup_received, 8);
  733|  15.4k|        if (_usbd_queued_setup != 0) {
  ------------------
  |  Branch (733:13): [True: 0, False: 15.4k]
  ------------------
  734|      0|          TU_LOG_USBD("  Skipped since there is other SETUP in queue\r\n");
  735|      0|          break;
  736|      0|        }
  737|       |
  738|       |        // Mark as connected after receiving 1st setup packet.
  739|       |        // But it is easier to set it every time instead of wasting time to check then set
  740|  15.4k|        _usbd_dev.connected = 1;
  741|       |
  742|       |        // reset ep state
  743|  15.4k|        _usbd_dev.ep_status[0][TUSB_DIR_OUT] = 0;
  744|  15.4k|        _usbd_dev.ep_status[0][TUSB_DIR_IN] = 0;
  745|       |
  746|       |        // Process control request
  747|  15.4k|        if (!process_setup_received(event.rhport, &event.setup_received)) {
  ------------------
  |  Branch (747:13): [True: 9.22k, False: 6.20k]
  ------------------
  748|  9.22k|          TU_LOG_USBD("  Stall EP0\r\n");
  749|       |          // Failed -> stall both control endpoint IN and OUT
  750|  9.22k|          dcd_edpt_stall(event.rhport, TU_EP0_OUT);
  751|  9.22k|          dcd_edpt_stall(event.rhport, TU_EP0_IN);
  752|  9.22k|        }
  753|  15.4k|        break;
  754|       |
  755|      0|      case DCD_EVENT_XFER_COMPLETE: {
  ------------------
  |  Branch (755:7): [True: 0, False: 34.4k]
  ------------------
  756|       |        // Invoke the class callback associated with the endpoint address
  757|      0|        uint8_t const ep_addr = event.xfer_complete.ep_addr;
  758|      0|        uint8_t const epnum = tu_edpt_number(ep_addr);
  759|      0|        uint8_t const ep_dir = tu_edpt_dir(ep_addr);
  760|       |
  761|      0|        TU_LOG_USBD("on EP %02X with %u bytes\r\n", ep_addr, (unsigned int) event.xfer_complete.len);
  762|       |
  763|       |        // Clear busy + claimed
  764|      0|        _usbd_dev.ep_status[epnum][ep_dir] &= (uint8_t) ~(TU_EDPT_STATE_BUSY | TU_EDPT_STATE_CLAIMED);
  ------------------
  |  |   50|      0|#define TU_EDPT_STATE_BUSY    0x01u
  ------------------
                      _usbd_dev.ep_status[epnum][ep_dir] &= (uint8_t) ~(TU_EDPT_STATE_BUSY | TU_EDPT_STATE_CLAIMED);
  ------------------
  |  |   52|      0|#define TU_EDPT_STATE_CLAIMED 0x04u
  ------------------
  765|       |
  766|      0|        if (0 == epnum) {
  ------------------
  |  Branch (766:13): [True: 0, False: 0]
  ------------------
  767|      0|          usbd_control_xfer_cb(event.rhport, ep_addr, (xfer_result_t) event.xfer_complete.result, event.xfer_complete.len);
  768|      0|        } else {
  769|      0|          usbd_class_driver_t const* driver = get_driver(_usbd_dev.ep2drv[epnum][ep_dir]);
  770|      0|          TU_ASSERT(driver,);
  ------------------
  |  |  131|      0|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|      0|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|      0|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  128|      0|#define TU_ASSERT_2ARGS(_cond, _ret)   TU_ASSERT_DEFINE(_cond, _ret)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|      0|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|      0|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   73|      0|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (73:41): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   96|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (96:40): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (124:10): [True: 0, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|      0|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  771|       |
  772|      0|          TU_LOG_USBD("  %s xfer callback\r\n", driver->name);
  773|      0|          driver->xfer_cb(event.rhport, ep_addr, (xfer_result_t) event.xfer_complete.result, event.xfer_complete.len);
  774|      0|        }
  775|      0|        break;
  776|      0|      }
  777|       |
  778|  2.05k|      case DCD_EVENT_SUSPEND:
  ------------------
  |  Branch (778:7): [True: 2.05k, False: 32.3k]
  ------------------
  779|       |        // NOTE: When plugging/unplugging device, the D+/D- state are unstable and
  780|       |        // can accidentally meet the SUSPEND condition ( Bus Idle for 3ms ), which result in a series of event
  781|       |        // e.g suspend -> resume -> unplug/plug. Skip suspend/resume if not connected
  782|  2.05k|        if (_usbd_dev.connected) {
  ------------------
  |  Branch (782:13): [True: 2.05k, False: 0]
  ------------------
  783|  2.05k|          TU_LOG_USBD(": Remote Wakeup = %u\r\n", _usbd_dev.remote_wakeup_en);
  784|  2.05k|          tud_suspend_cb(_usbd_dev.remote_wakeup_en);
  785|  2.05k|        } else {
  786|      0|          TU_LOG_USBD(" Skipped\r\n");
  787|      0|        }
  788|  2.05k|        break;
  789|       |
  790|  1.23k|      case DCD_EVENT_RESUME:
  ------------------
  |  Branch (790:7): [True: 1.23k, False: 33.2k]
  ------------------
  791|  1.23k|        if (_usbd_dev.connected) {
  ------------------
  |  Branch (791:13): [True: 1.23k, False: 0]
  ------------------
  792|  1.23k|          TU_LOG_USBD("\r\n");
  793|  1.23k|          tud_resume_cb();
  794|  1.23k|        } else {
  795|      0|          TU_LOG_USBD(" Skipped\r\n");
  796|      0|        }
  797|  1.23k|        break;
  798|       |
  799|      0|      case USBD_EVENT_FUNC_CALL:
  ------------------
  |  Branch (799:7): [True: 0, False: 34.4k]
  ------------------
  800|      0|        TU_LOG_USBD("\r\n");
  801|      0|        if (event.func_call.func != NULL) {
  ------------------
  |  Branch (801:13): [True: 0, False: 0]
  ------------------
  802|      0|          event.func_call.func(event.func_call.param);
  803|      0|        }
  804|      0|        break;
  805|       |
  806|      0|      case DCD_EVENT_SOF:
  ------------------
  |  Branch (806:7): [True: 0, False: 34.4k]
  ------------------
  807|      0|        if (tu_bit_test(_usbd_dev.sof_consumer, SOF_CONSUMER_USER)) {
  ------------------
  |  Branch (807:13): [True: 0, False: 0]
  ------------------
  808|      0|          TU_LOG_USBD("\r\n");
  809|      0|          tud_sof_cb(event.sof.frame_count);
  810|      0|        }
  811|      0|      break;
  812|       |
  813|      0|      default:
  ------------------
  |  Branch (813:7): [True: 0, False: 34.4k]
  ------------------
  814|      0|        TU_BREAKPOINT();
  ------------------
  |  |   96|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  ------------------
  |  |  |  Branch (96:40): [Folded, False: 0]
  |  |  ------------------
  ------------------
  815|      0|        break;
  816|  34.4k|    }
  817|       |
  818|       |    // allow to exit tud_task() if there is no event in the next run
  819|  34.4k|    timeout_ms = 0;
  820|  34.4k|  }
  821|  41.7k|}
tud_control_status:
  867|  2.63k|bool tud_control_status(uint8_t rhport, const tusb_control_request_t* request) {
  868|       |  // _usbd_dev.ctrl_xfer fields are pre-initialized at process_setup_received entry
  869|  2.63k|  (void) request;
  870|  2.63k|  return status_stage_xact(rhport, status_stage_ep(&_usbd_dev.ctrl_xfer.request));
  871|  2.63k|}
tud_control_xfer:
  874|  3.15k|bool tud_control_xfer(uint8_t rhport, const tusb_control_request_t* request, void* buffer, uint16_t len) {
  875|       |  // _usbd_dev.ctrl_xfer.request and reset fields are pre-initialized at process_setup_received entry
  876|  3.15k|  (void) request;
  877|  3.15k|  usbd_control_xfer_t* const ctrl_xfer = &_usbd_dev.ctrl_xfer;
  878|  3.15k|  ctrl_xfer->buffer = (uint8_t*) buffer;
  879|  3.15k|  ctrl_xfer->data_len = tu_min16(len, ctrl_xfer->request.wLength);
  880|       |
  881|  3.15k|  if (ctrl_xfer->request.wLength > 0U) {
  ------------------
  |  Branch (881:7): [True: 2.20k, False: 949]
  ------------------
  882|  2.20k|    if (ctrl_xfer->data_len > 0U) {
  ------------------
  |  Branch (882:9): [True: 2.20k, False: 0]
  ------------------
  883|  2.20k|      TU_ASSERT(buffer);
  ------------------
  |  |  131|  2.20k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|  2.20k|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|  2.20k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  127|  2.20k|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|  2.20k|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|  2.20k|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   73|      0|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (73:41): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   96|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (96:40): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (124:10): [True: 0, False: 2.20k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|  2.20k|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 2.20k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  884|  2.20k|    }
  885|  2.20k|    TU_ASSERT(data_stage_xact(rhport));
  ------------------
  |  |  131|  2.20k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|  2.20k|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|  2.20k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  127|  2.20k|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|  2.20k|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|  2.20k|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   73|  1.14k|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (73:41): [Folded, False: 1.14k]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   96|  1.14k|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (96:40): [Folded, False: 1.14k]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (124:10): [True: 1.14k, False: 1.06k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|  2.20k|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 1.06k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  886|  2.20k|  } else {
  887|       |    // wLength == 0: Status stage is always IN per USB 2.0 §9.3.1
  888|    949|    TU_ASSERT(status_stage_xact(rhport, TU_EP0_IN));
  ------------------
  |  |  131|    949|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    949|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|    949|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  127|    949|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|    949|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|    949|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   73|    636|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (73:41): [Folded, False: 636]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   96|    636|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (96:40): [Folded, False: 636]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (124:10): [True: 636, False: 313]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|    949|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 313]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  889|    949|  }
  890|       |
  891|  1.37k|  return true;
  892|  3.15k|}
dcd_event_handler:
 1387|  35.2k|TU_ATTR_FAST_FUNC void dcd_event_handler(dcd_event_t const* event, bool in_isr) {
 1388|  35.2k|  bool send = false;
 1389|  35.2k|  switch (event->event_id) {
 1390|  6.12k|    case DCD_EVENT_UNPLUGGED:
  ------------------
  |  Branch (1390:5): [True: 6.12k, False: 29.1k]
  ------------------
 1391|  6.12k|      _usbd_dev.connected = 0;
 1392|  6.12k|      _usbd_dev.addressed = 0;
 1393|  6.12k|      _usbd_dev.cfg_num = 0;
 1394|  6.12k|      _usbd_dev.suspended = 0;
 1395|  6.12k|      send = true;
 1396|  6.12k|      break;
 1397|       |
 1398|  2.46k|    case DCD_EVENT_SUSPEND:
  ------------------
  |  Branch (1398:5): [True: 2.46k, False: 32.8k]
  ------------------
 1399|       |      // NOTE: When plugging/unplugging device, the D+/D- state are unstable and
 1400|       |      // can accidentally meet the SUSPEND condition ( Bus Idle for 3ms ).
 1401|       |      // In addition, some MCUs such as SAMD or boards that haven no VBUS detection cannot distinguish
 1402|       |      // suspended vs disconnected. We will skip handling SUSPEND/RESUME event if not currently connected
 1403|  2.46k|      if (_usbd_dev.connected) {
  ------------------
  |  Branch (1403:11): [True: 2.05k, False: 411]
  ------------------
 1404|  2.05k|        _usbd_dev.suspended = 1;
 1405|  2.05k|        send = true;
 1406|  2.05k|      }
 1407|  2.46k|      break;
 1408|       |
 1409|  1.66k|    case DCD_EVENT_RESUME:
  ------------------
  |  Branch (1409:5): [True: 1.66k, False: 33.6k]
  ------------------
 1410|       |      // skip event if not connected (especially required for SAMD)
 1411|  1.66k|      if (_usbd_dev.connected) {
  ------------------
  |  Branch (1411:11): [True: 1.23k, False: 436]
  ------------------
 1412|  1.23k|        _usbd_dev.suspended = 0;
 1413|  1.23k|        send = true;
 1414|  1.23k|      }
 1415|  1.66k|      break;
 1416|       |
 1417|      0|    case DCD_EVENT_SOF:
  ------------------
  |  Branch (1417:5): [True: 0, False: 35.2k]
  ------------------
 1418|       |      // SOF driver handler in ISR context
 1419|      0|      for (uint8_t i = 0; i < TOTAL_DRIVER_COUNT; i++) {
  ------------------
  |  |  389|      0|#define TOTAL_DRIVER_COUNT    ((uint8_t) (_app_driver_count + BUILTIN_DRIVER_COUNT))
  ------------------
  |  Branch (1419:27): [True: 0, False: 0]
  ------------------
 1420|      0|        usbd_class_driver_t const* driver = get_driver(i);
 1421|      0|        if (driver && driver->sof) {
  ------------------
  |  Branch (1421:13): [True: 0, False: 0]
  |  Branch (1421:23): [True: 0, False: 0]
  ------------------
 1422|      0|          driver->sof(event->rhport, event->sof.frame_count);
 1423|      0|        }
 1424|      0|      }
 1425|       |
 1426|       |      // Some MCUs after running dcd_remote_wakeup() does not have way to detect the end of remote wakeup
 1427|       |      // which last 1-15 ms. DCD can use SOF as a clear indicator that bus is back to operational
 1428|      0|      if (_usbd_dev.suspended) {
  ------------------
  |  Branch (1428:11): [True: 0, False: 0]
  ------------------
 1429|      0|        _usbd_dev.suspended = 0;
 1430|       |
 1431|      0|        dcd_event_t const event_resume = {.rhport = event->rhport, .event_id = DCD_EVENT_RESUME};
 1432|      0|        queue_event(&event_resume, in_isr);
 1433|      0|      }
 1434|       |
 1435|      0|      if (tu_bit_test(_usbd_dev.sof_consumer, SOF_CONSUMER_USER)) {
  ------------------
  |  Branch (1435:11): [True: 0, False: 0]
  ------------------
 1436|      0|        dcd_event_t const event_sof = {.rhport = event->rhport, .event_id = DCD_EVENT_SOF, .sof.frame_count = event->sof.frame_count};
 1437|      0|        queue_event(&event_sof, in_isr);
 1438|      0|      }
 1439|      0|      break;
 1440|       |
 1441|  15.4k|    case DCD_EVENT_SETUP_RECEIVED:
  ------------------
  |  Branch (1441:5): [True: 15.4k, False: 19.8k]
  ------------------
 1442|  15.4k|      _usbd_queued_setup++;
 1443|  15.4k|      send = true;
 1444|  15.4k|      break;
 1445|       |
 1446|      0|    case DCD_EVENT_XFER_COMPLETE: {
  ------------------
  |  Branch (1446:5): [True: 0, False: 35.2k]
  ------------------
 1447|       |      // Invoke the class callback associated with the endpoint address
 1448|      0|      uint8_t const ep_addr = event->xfer_complete.ep_addr;
 1449|      0|      uint8_t const epnum = tu_edpt_number(ep_addr);
 1450|      0|      uint8_t const ep_dir = tu_edpt_dir(ep_addr);
 1451|       |
 1452|      0|      send = true;
 1453|      0|      if(epnum > 0) {
  ------------------
  |  Branch (1453:10): [True: 0, False: 0]
  ------------------
 1454|      0|        usbd_class_driver_t const* driver = get_driver(_usbd_dev.ep2drv[epnum][ep_dir]);
 1455|       |
 1456|      0|        if (driver && driver->xfer_isr) {
  ------------------
  |  Branch (1456:13): [True: 0, False: 0]
  |  Branch (1456:23): [True: 0, False: 0]
  ------------------
 1457|       |          // Clear busy + claimed
 1458|      0|          _usbd_dev.ep_status[epnum][ep_dir] &= (uint8_t) ~(TU_EDPT_STATE_BUSY | TU_EDPT_STATE_CLAIMED);
  ------------------
  |  |   50|      0|#define TU_EDPT_STATE_BUSY    0x01u
  ------------------
                        _usbd_dev.ep_status[epnum][ep_dir] &= (uint8_t) ~(TU_EDPT_STATE_BUSY | TU_EDPT_STATE_CLAIMED);
  ------------------
  |  |   52|      0|#define TU_EDPT_STATE_CLAIMED 0x04u
  ------------------
 1459|       |
 1460|      0|          send = !driver->xfer_isr(event->rhport, ep_addr, (xfer_result_t) event->xfer_complete.result, event->xfer_complete.len);
 1461|       |
 1462|       |          // xfer_isr() is deferred to xfer_cb(), revert busy/claimed status
 1463|      0|          if (send) {
  ------------------
  |  Branch (1463:15): [True: 0, False: 0]
  ------------------
 1464|       |            // set busy + claimed
 1465|      0|            _usbd_dev.ep_status[epnum][ep_dir] |= (TU_EDPT_STATE_BUSY | TU_EDPT_STATE_CLAIMED);
  ------------------
  |  |   50|      0|#define TU_EDPT_STATE_BUSY    0x01u
  ------------------
                          _usbd_dev.ep_status[epnum][ep_dir] |= (TU_EDPT_STATE_BUSY | TU_EDPT_STATE_CLAIMED);
  ------------------
  |  |   52|      0|#define TU_EDPT_STATE_CLAIMED 0x04u
  ------------------
 1466|      0|          }
 1467|      0|        }
 1468|      0|      }
 1469|      0|      break;
 1470|      0|    }
 1471|       |
 1472|  9.59k|    default:
  ------------------
  |  Branch (1472:5): [True: 9.59k, False: 25.6k]
  ------------------
 1473|  9.59k|      send = true;
 1474|  9.59k|      break;
 1475|  35.2k|  }
 1476|       |
 1477|  35.2k|  if (send) {
  ------------------
  |  Branch (1477:7): [True: 34.4k, False: 847]
  ------------------
 1478|  34.4k|    queue_event(event, in_isr);
 1479|  34.4k|  }
 1480|  35.2k|}
usbd_int_set:
 1486|   179k|void usbd_int_set(bool enabled) {
 1487|   179k|  if (enabled) {
  ------------------
  |  Branch (1487:7): [True: 89.7k, False: 89.7k]
  ------------------
 1488|  89.7k|    dcd_int_enable(_usbd_rhport);
 1489|  89.7k|  } else {
 1490|  89.7k|    dcd_int_disable(_usbd_rhport);
 1491|  89.7k|  }
 1492|   179k|}
usbd_open_edpt_pair:
 1503|    209|                         uint8_t *ep_in) {
 1504|    209|  for (int i = 0; i < ep_count; i++) {
  ------------------
  |  Branch (1504:19): [True: 209, False: 0]
  ------------------
 1505|    209|    const tusb_desc_endpoint_t *desc_ep = (const tusb_desc_endpoint_t *)p_desc;
 1506|       |
 1507|    209|    TU_ASSERT(TUSB_DESC_ENDPOINT == desc_ep->bDescriptorType && xfer_type == desc_ep->bmAttributes.xfer);
  ------------------
  |  |  131|    209|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    209|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|    209|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  127|    209|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|    209|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|    418|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   73|      0|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (73:41): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   96|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (96:40): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (124:12): [True: 209, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  Branch (124:12): [True: 209, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|    209|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 209]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1508|    209|    TU_ASSERT(usbd_edpt_open(rhport, desc_ep));
  ------------------
  |  |  131|    209|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    209|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|    209|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  127|    209|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|    209|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|    209|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   73|    209|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (73:41): [Folded, False: 209]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   96|    209|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (96:40): [Folded, False: 209]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (124:10): [True: 209, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|    209|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1509|       |
 1510|      0|    if (tu_edpt_dir(desc_ep->bEndpointAddress) == TUSB_DIR_IN) {
  ------------------
  |  Branch (1510:9): [True: 0, False: 0]
  ------------------
 1511|      0|      (*ep_in) = desc_ep->bEndpointAddress;
 1512|      0|    } else {
 1513|      0|      (*ep_out) = desc_ep->bEndpointAddress;
 1514|      0|    }
 1515|       |
 1516|      0|    p_desc = tu_desc_next(p_desc);
 1517|      0|  }
 1518|       |
 1519|      0|  return true;
 1520|    209|}
usbd_edpt_open:
 1538|    209|bool usbd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const* desc_ep) {
 1539|    209|  rhport = _usbd_rhport;
 1540|       |
 1541|    209|  TU_ASSERT(tu_edpt_number(desc_ep->bEndpointAddress) < CFG_TUD_ENDPPOINT_MAX);
  ------------------
  |  |  131|    209|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    209|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|    209|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  127|    209|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|    209|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|    209|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   73|    209|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (73:41): [Folded, False: 209]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   96|    209|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (96:40): [Folded, False: 209]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (124:10): [True: 209, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|    209|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1542|      0|  TU_ASSERT(tu_edpt_validate(desc_ep, (tusb_speed_t)_usbd_dev.speed));
  ------------------
  |  |  131|      0|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|      0|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|      0|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  127|      0|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|      0|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|      0|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   73|      0|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (73:41): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   96|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (96:40): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (124:10): [True: 0, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|      0|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1543|       |
 1544|      0|  return dcd_edpt_open(rhport, desc_ep);
 1545|      0|}
usbd_edpt_xfer:
 1566|  5.79k|bool usbd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t* buffer, uint16_t total_bytes, bool is_isr) {
 1567|  5.79k|  rhport = _usbd_rhport;
 1568|       |
 1569|  5.79k|  uint8_t const epnum = tu_edpt_number(ep_addr);
 1570|  5.79k|  uint8_t const dir = tu_edpt_dir(ep_addr);
 1571|       |
 1572|       |  // TODO skip ready() check for now since enumeration also use this API
 1573|       |  // TU_VERIFY(tud_ready());
 1574|       |
 1575|  5.79k|  TU_LOG_USBD("  Queue EP %02X with %u bytes ...\r\n", ep_addr, total_bytes);
 1576|       |#if CFG_TUD_LOG_LEVEL >= 3
 1577|       |  if(dir == TUSB_DIR_IN) {
 1578|       |    TU_LOG_MEM(CFG_TUD_LOG_LEVEL, buffer, total_bytes, 2);
 1579|       |  }
 1580|       |#endif
 1581|       |
 1582|       |  // Attempt to transfer on a busy endpoint, sound like an race condition !
 1583|  5.79k|  TU_ASSERT((_usbd_dev.ep_status[epnum][dir] & TU_EDPT_STATE_BUSY) == 0);
  ------------------
  |  |  131|  5.79k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|  5.79k|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|  5.79k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  127|  5.79k|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|  5.79k|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|  5.79k|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   73|      0|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (73:41): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   96|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (96:40): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (124:10): [True: 0, False: 5.79k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|  5.79k|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 5.79k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1584|       |
 1585|       |  // Set busy first since the actual transfer can be complete before dcd_edpt_xfer()
 1586|       |  // could return and USBD task can preempt and clear the busy
 1587|  5.79k|  _usbd_dev.ep_status[epnum][dir] |= TU_EDPT_STATE_BUSY;
  ------------------
  |  |   50|  5.79k|#define TU_EDPT_STATE_BUSY    0x01u
  ------------------
 1588|       |
 1589|  5.79k|  if (dcd_edpt_xfer(rhport, ep_addr, buffer, total_bytes, is_isr)) {
  ------------------
  |  Branch (1589:7): [True: 2.45k, False: 3.33k]
  ------------------
 1590|  2.45k|    return true;
 1591|  3.33k|  } else {
 1592|       |    // DCD error, mark endpoint as ready to allow next transfer
 1593|  3.33k|    _usbd_dev.ep_status[epnum][dir] &= (uint8_t) ~(TU_EDPT_STATE_BUSY | TU_EDPT_STATE_CLAIMED);
  ------------------
  |  |   50|  3.33k|#define TU_EDPT_STATE_BUSY    0x01u
  ------------------
                  _usbd_dev.ep_status[epnum][dir] &= (uint8_t) ~(TU_EDPT_STATE_BUSY | TU_EDPT_STATE_CLAIMED);
  ------------------
  |  |   52|  3.33k|#define TU_EDPT_STATE_CLAIMED 0x04u
  ------------------
 1594|  3.33k|    TU_LOG_USBD("FAILED\r\n");
 1595|  3.33k|    TU_BREAKPOINT();
  ------------------
  |  |   96|  3.33k|  #define TU_BREAKPOINT() do {} while (0)
  |  |  ------------------
  |  |  |  Branch (96:40): [Folded, False: 3.33k]
  |  |  ------------------
  ------------------
 1596|       |    return false;
 1597|  3.33k|  }
 1598|  5.79k|}
usbd_edpt_stall:
 1649|    227|void usbd_edpt_stall(uint8_t rhport, uint8_t ep_addr) {
 1650|    227|  rhport = _usbd_rhport;
 1651|       |
 1652|    227|  uint8_t const epnum = tu_edpt_number(ep_addr);
 1653|    227|  uint8_t const dir = tu_edpt_dir(ep_addr);
 1654|       |
 1655|       |  // only stalled if currently cleared
 1656|    227|  TU_LOG_USBD("    Stall EP %02X\r\n", ep_addr);
 1657|    227|  dcd_edpt_stall(rhport, ep_addr);
 1658|    227|  _usbd_dev.ep_status[epnum][dir] |= (TU_EDPT_STATE_STALLED | TU_EDPT_STATE_BUSY);
  ------------------
  |  |   51|    227|#define TU_EDPT_STATE_STALLED 0x02u
  ------------------
                _usbd_dev.ep_status[epnum][dir] |= (TU_EDPT_STATE_STALLED | TU_EDPT_STATE_BUSY);
  ------------------
  |  |   50|    227|#define TU_EDPT_STATE_BUSY    0x01u
  ------------------
 1659|    227|}
usbd_edpt_clear_stall:
 1661|    201|void usbd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr) {
 1662|    201|  rhport = _usbd_rhport;
 1663|       |
 1664|    201|  uint8_t const epnum = tu_edpt_number(ep_addr);
 1665|    201|  uint8_t const dir = tu_edpt_dir(ep_addr);
 1666|       |
 1667|       |  // only clear if currently stalled
 1668|    201|  TU_LOG_USBD("    Clear Stall EP %02X\r\n", ep_addr);
 1669|    201|  dcd_edpt_clear_stall(rhport, ep_addr);
 1670|    201|  _usbd_dev.ep_status[epnum][dir] &= (uint8_t) ~(TU_EDPT_STATE_STALLED | TU_EDPT_STATE_BUSY);
  ------------------
  |  |   51|    201|#define TU_EDPT_STATE_STALLED 0x02u
  ------------------
                _usbd_dev.ep_status[epnum][dir] &= (uint8_t) ~(TU_EDPT_STATE_STALLED | TU_EDPT_STATE_BUSY);
  ------------------
  |  |   50|    201|#define TU_EDPT_STATE_BUSY    0x01u
  ------------------
 1671|    201|}
usbd_edpt_stalled:
 1673|    221|bool usbd_edpt_stalled(uint8_t rhport, uint8_t ep_addr) {
 1674|    221|  (void) rhport;
 1675|       |
 1676|    221|  uint8_t const epnum = tu_edpt_number(ep_addr);
 1677|    221|  uint8_t const dir = tu_edpt_dir(ep_addr);
 1678|       |
 1679|    221|  return (_usbd_dev.ep_status[epnum][dir] & TU_EDPT_STATE_STALLED) != 0;
  ------------------
  |  |   51|    221|#define TU_EDPT_STATE_STALLED 0x02u
  ------------------
 1680|    221|}
usbd.c:get_driver:
  393|  18.2k|TU_ATTR_ALWAYS_INLINE static inline usbd_class_driver_t const * get_driver(uint8_t drvid) {
  394|  18.2k|  usbd_class_driver_t const *driver = NULL;
  395|  18.2k|  if (drvid < _app_driver_count) {
  ------------------
  |  Branch (395:7): [True: 0, False: 18.2k]
  ------------------
  396|       |    // Application drivers
  397|      0|    driver = &_app_driver[drvid];
  398|  18.2k|  } else{
  399|  18.2k|    drvid -= _app_driver_count;
  400|  18.2k|    if (drvid < BUILTIN_DRIVER_COUNT) {
  ------------------
  |  Branch (400:9): [True: 15.9k, False: 2.29k]
  ------------------
  401|  15.9k|      driver = &_usbd_driver[drvid];
  402|  15.9k|    }
  403|  18.2k|  }
  404|       |
  405|  18.2k|  return driver;
  406|  18.2k|}
usbd.c:usbd_reset:
  660|  15.7k|static void usbd_reset(uint8_t rhport) {
  661|  15.7k|  configuration_reset(rhport);
  662|  15.7k|}
usbd.c:configuration_reset:
  648|  15.7k|static void configuration_reset(uint8_t rhport) {
  649|  31.4k|  for (uint8_t i = 0; i < TOTAL_DRIVER_COUNT; i++) {
  ------------------
  |  |  389|  31.4k|#define TOTAL_DRIVER_COUNT    ((uint8_t) (_app_driver_count + BUILTIN_DRIVER_COUNT))
  ------------------
  |  Branch (649:23): [True: 15.7k, False: 15.7k]
  ------------------
  650|  15.7k|    usbd_class_driver_t const* driver = get_driver(i);
  651|  15.7k|    TU_ASSERT(driver,);
  ------------------
  |  |  131|  15.7k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|  15.7k|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|  15.7k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  128|  15.7k|#define TU_ASSERT_2ARGS(_cond, _ret)   TU_ASSERT_DEFINE(_cond, _ret)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|  15.7k|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|  15.7k|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   73|      0|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (73:41): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   96|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (96:40): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (124:10): [True: 0, False: 15.7k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|  15.7k|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 15.7k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  652|  15.7k|    driver->reset(rhport);
  653|  15.7k|  }
  654|       |
  655|  15.7k|  tu_varclr(&_usbd_dev);
  ------------------
  |  |  115|  15.7k|#define tu_varclr(_var)          tu_memclr(_var, sizeof(*(_var)))
  |  |  ------------------
  |  |  |  |  114|  15.7k|#define tu_memclr(buffer, size)  (void) memset((buffer), 0, (size))
  |  |  ------------------
  ------------------
  656|  15.7k|  (void)memset(_usbd_dev.itf2drv, TUSB_INDEX_INVALID_8, sizeof(_usbd_dev.itf2drv)); // invalid mapping
  657|  15.7k|  (void)memset(_usbd_dev.ep2drv, TUSB_INDEX_INVALID_8, sizeof(_usbd_dev.ep2drv));   // invalid mapping
  658|  15.7k|}
usbd.c:status_stage_xact:
  845|  3.58k|TU_ATTR_ALWAYS_INLINE static inline bool status_stage_xact(uint8_t rhport, uint8_t ep_status) {
  846|  3.58k|  return usbd_edpt_xfer(rhport, ep_status, NULL, 0, false);
  847|  3.58k|}
usbd.c:status_stage_ep:
  840|  2.63k|TU_ATTR_ALWAYS_INLINE static inline uint8_t status_stage_ep(const tusb_control_request_t* request) {
  841|  2.63k|  return (request->wLength != 0 && request->bmRequestType_bit.direction) ? TU_EP0_OUT : TU_EP0_IN;
  ------------------
  |  Branch (841:11): [True: 1.60k, False: 1.02k]
  |  Branch (841:36): [True: 32, False: 1.57k]
  ------------------
  842|  2.63k|}
usbd.c:data_stage_xact:
  851|  2.20k|static bool data_stage_xact(uint8_t rhport) {
  852|  2.20k|  usbd_control_xfer_t* const ctrl_xfer = &_usbd_dev.ctrl_xfer;
  853|  2.20k|  const uint16_t xact_len = tu_min16(ctrl_xfer->data_len - ctrl_xfer->total_xferred, CFG_TUD_ENDPOINT0_BUFSIZE);
  ------------------
  |  |  577|  2.20k|  #define CFG_TUD_ENDPOINT0_BUFSIZE  CFG_TUD_ENDPOINT0_SIZE
  |  |  ------------------
  |  |  |  |   90|  2.20k|#define CFG_TUD_ENDPOINT0_SIZE    64
  |  |  ------------------
  ------------------
  854|  2.20k|  uint8_t ep_addr = TU_EP0_OUT;
  855|       |
  856|  2.20k|  if (ctrl_xfer->request.bmRequestType_bit.direction == TUSB_DIR_IN) {
  ------------------
  |  Branch (856:7): [True: 391, False: 1.81k]
  ------------------
  857|    391|    ep_addr = TU_EP0_IN;
  858|    391|    if (0u != xact_len && ctrl_xfer->buffer != _ctrl_epbuf.buf) {
  ------------------
  |  Branch (858:9): [True: 391, False: 0]
  |  Branch (858:27): [True: 391, False: 0]
  ------------------
  859|    391|      TU_VERIFY(0 == tu_memcpy_s(_ctrl_epbuf.buf, CFG_TUD_ENDPOINT0_BUFSIZE, ctrl_xfer->buffer, xact_len));
  ------------------
  |  |  114|    391|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    391|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  114|    391|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  111|    391|#define TU_VERIFY_1ARGS(_cond)         TU_VERIFY_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  105|    391|  do {                                \
  |  |  |  |  |  |  |  |  |  |  106|    391|    if (!(_cond)) {                   \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:9): [True: 0, False: 391]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  107|      0|      return _ret;                    \
  |  |  |  |  |  |  |  |  |  |  108|      0|    }                                 \
  |  |  |  |  |  |  |  |  |  |  109|    391|  } while (0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (109:12): [Folded, False: 391]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  860|    391|    }
  861|    391|  }
  862|       |
  863|  2.20k|  return usbd_edpt_xfer(rhport, ep_addr, xact_len ? _ctrl_epbuf.buf : NULL, xact_len, false);
  ------------------
  |  Branch (863:42): [True: 2.20k, False: 0]
  ------------------
  864|  2.20k|}
usbd.c:process_setup_received:
 1074|  15.4k|static bool process_setup_received(uint8_t rhport, tusb_control_request_t const * p_request) {
 1075|       |  // Initialize control transfer state for this request. The request copy must be
 1076|       |  // visible to usbd_control_xfer_cb when the (asynchronous) status ZLP completes,
 1077|       |  // since the SETUP packet event has already gone out of scope by then.
 1078|  15.4k|  usbd_control_xfer_t* const ctrl_xfer = &_usbd_dev.ctrl_xfer;
 1079|  15.4k|  ctrl_xfer->request = *p_request;
 1080|  15.4k|  ctrl_xfer->buffer = NULL;
 1081|  15.4k|  ctrl_xfer->total_xferred = 0;
 1082|  15.4k|  ctrl_xfer->data_len = 0;
 1083|  15.4k|  ctrl_xfer->complete_cb = NULL;
 1084|       |
 1085|  15.4k|  p_request = &ctrl_xfer->request; // re-direct request pointer to internal copy (modifiable for hacking)
 1086|  15.4k|  TU_ASSERT(p_request->bmRequestType_bit.type < TUSB_REQ_TYPE_INVALID);
  ------------------
  |  |  131|  15.4k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|  15.4k|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|  15.4k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  127|  15.4k|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|  15.4k|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|  15.4k|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   73|  1.06k|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (73:41): [Folded, False: 1.06k]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   96|  1.06k|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (96:40): [Folded, False: 1.06k]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (124:10): [True: 1.06k, False: 14.3k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|  15.4k|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 14.3k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1087|       |
 1088|       |  // Vendor request
 1089|  14.3k|  if ( p_request->bmRequestType_bit.type == TUSB_REQ_TYPE_VENDOR ) {
  ------------------
  |  Branch (1089:8): [True: 1.75k, False: 12.6k]
  ------------------
 1090|  1.75k|    ctrl_xfer->complete_cb = tud_vendor_control_xfer_cb;
 1091|  1.75k|    return tud_vendor_control_xfer_cb(rhport, CONTROL_STAGE_SETUP, p_request);
 1092|  1.75k|  }
 1093|       |
 1094|       |#if CFG_TUSB_DEBUG >= CFG_TUD_LOG_LEVEL
 1095|       |  if (TUSB_REQ_TYPE_STANDARD == p_request->bmRequestType_bit.type && p_request->bRequest <= TUSB_REQ_SYNCH_FRAME) {
 1096|       |    TU_LOG_USBD("  %s", tu_str_std_request[p_request->bRequest]);
 1097|       |    if (TUSB_REQ_GET_DESCRIPTOR != p_request->bRequest) {
 1098|       |      TU_LOG_USBD("\r\n");
 1099|       |    }
 1100|       |  }
 1101|       |#endif
 1102|       |
 1103|  12.6k|  switch (p_request->bmRequestType_bit.recipient) { //-V2520
 1104|       |    //------------- Device Requests e.g in enumeration -------------//
 1105|  8.65k|    case TUSB_REQ_RCPT_DEVICE:
  ------------------
  |  Branch (1105:5): [True: 8.65k, False: 3.96k]
  ------------------
 1106|  8.65k|      if ( TUSB_REQ_TYPE_CLASS == p_request->bmRequestType_bit.type ) {
  ------------------
  |  Branch (1106:12): [True: 443, False: 8.20k]
  ------------------
 1107|    443|        uint8_t const itf = tu_u16_low(p_request->wIndex);
 1108|    443|        TU_VERIFY(itf < TU_ARRAY_SIZE(_usbd_dev.itf2drv));
  ------------------
  |  |  114|    443|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    443|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  114|    443|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  111|    443|#define TU_VERIFY_1ARGS(_cond)         TU_VERIFY_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  105|    443|  do {                                \
  |  |  |  |  |  |  |  |  |  |  106|    443|    if (!(_cond)) {                   \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:9): [True: 227, False: 216]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  107|    227|      return _ret;                    \
  |  |  |  |  |  |  |  |  |  |  108|    227|    }                                 \
  |  |  |  |  |  |  |  |  |  |  109|    443|  } while (0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (109:12): [Folded, False: 216]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1109|       |
 1110|    216|        usbd_class_driver_t const * driver = get_driver(_usbd_dev.itf2drv[itf]);
 1111|    216|        TU_VERIFY(driver);
  ------------------
  |  |  114|    216|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    216|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  114|    216|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  111|    216|#define TU_VERIFY_1ARGS(_cond)         TU_VERIFY_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  105|    216|  do {                                \
  |  |  |  |  |  |  |  |  |  |  106|    216|    if (!(_cond)) {                   \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:9): [True: 216, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  107|    216|      return _ret;                    \
  |  |  |  |  |  |  |  |  |  |  108|    216|    }                                 \
  |  |  |  |  |  |  |  |  |  |  109|    216|  } while (0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (109:12): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1112|       |
 1113|       |        // forward to class driver: "non-STD request to Interface"
 1114|      0|        return invoke_class_control(rhport, driver, p_request);
 1115|    216|      }
 1116|       |
 1117|  8.20k|      if (TUSB_REQ_TYPE_STANDARD != p_request->bmRequestType_bit.type) {
  ------------------
  |  Branch (1117:11): [True: 0, False: 8.20k]
  ------------------
 1118|       |        // Non-standard request is not supported
 1119|      0|        TU_BREAKPOINT();
  ------------------
  |  |   96|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  ------------------
  |  |  |  Branch (96:40): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1120|      0|        return false;
 1121|      0|      }
 1122|       |
 1123|  8.20k|      return process_std_device_request(rhport, p_request);
 1124|       |
 1125|       |    //------------- Class/Interface Specific Request -------------//
 1126|    751|    case TUSB_REQ_RCPT_INTERFACE: {
  ------------------
  |  Branch (1126:5): [True: 751, False: 11.8k]
  ------------------
 1127|    751|      uint8_t itf;
 1128|       |      #if CFG_TUD_PRINTER
 1129|       |      // Printer GET_DEVICE_ID has a weird wIndex = interface (high) | alt (low)
 1130|       |      // attempt to interpret this as a printer request if matched
 1131|       |      if (TUSB_REQ_TYPE_CLASS == p_request->bmRequestType_bit.type &&
 1132|       |          TUSB_DIR_IN == p_request->bmRequestType_bit.direction &&
 1133|       |          TUSB_PRINTER_REQUEST_GET_DEVICE_ID == p_request->bRequest) {
 1134|       |        itf = tu_u16_high(p_request->wIndex);
 1135|       |        if (itf < TU_ARRAY_SIZE(_usbd_dev.itf2drv)) {
 1136|       |          const usbd_class_driver_t * driver = get_driver(_usbd_dev.itf2drv[itf]);
 1137|       |          if (driver != NULL && driver->control_xfer_cb == printerd_control_xfer_cb) {
 1138|       |            if (invoke_class_control(rhport, driver, p_request)) {
 1139|       |              return true;
 1140|       |            }
 1141|       |          }
 1142|       |        }
 1143|       |      }
 1144|       |      #endif
 1145|    751|      itf = tu_u16_low(p_request->wIndex);
 1146|    751|      TU_VERIFY(itf < TU_ARRAY_SIZE(_usbd_dev.itf2drv));
  ------------------
  |  |  114|    751|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    751|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  114|    751|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  111|    751|#define TU_VERIFY_1ARGS(_cond)         TU_VERIFY_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  105|    751|  do {                                \
  |  |  |  |  |  |  |  |  |  |  106|    751|    if (!(_cond)) {                   \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:9): [True: 319, False: 432]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  107|    319|      return _ret;                    \
  |  |  |  |  |  |  |  |  |  |  108|    319|    }                                 \
  |  |  |  |  |  |  |  |  |  |  109|    751|  } while (0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (109:12): [Folded, False: 432]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1147|       |
 1148|    432|      usbd_class_driver_t const * driver = get_driver(_usbd_dev.itf2drv[itf]);
 1149|    432|      TU_VERIFY(driver);
  ------------------
  |  |  114|    432|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    432|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  114|    432|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  111|    432|#define TU_VERIFY_1ARGS(_cond)         TU_VERIFY_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  105|    432|  do {                                \
  |  |  |  |  |  |  |  |  |  |  106|    432|    if (!(_cond)) {                   \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:9): [True: 432, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  107|    432|      return _ret;                    \
  |  |  |  |  |  |  |  |  |  |  108|    432|    }                                 \
  |  |  |  |  |  |  |  |  |  |  109|    432|  } while (0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (109:12): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1150|       |
 1151|       |      // all requests to Interface (STD or Class) is forwarded to class driver.
 1152|       |      // notable requests are: GET HID REPORT DESCRIPTOR, SET_INTERFACE, GET_INTERFACE
 1153|      0|      if (!invoke_class_control(rhport, driver, p_request)) {
  ------------------
  |  Branch (1153:11): [True: 0, False: 0]
  ------------------
 1154|       |        // For GET_INTERFACE and SET_INTERFACE, it is mandatory to respond even if the class
 1155|       |        // driver doesn't use alternate settings or implement this
 1156|      0|        TU_VERIFY(TUSB_REQ_TYPE_STANDARD == p_request->bmRequestType_bit.type);
  ------------------
  |  |  114|      0|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|      0|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  114|      0|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  111|      0|#define TU_VERIFY_1ARGS(_cond)         TU_VERIFY_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  105|      0|  do {                                \
  |  |  |  |  |  |  |  |  |  |  106|      0|    if (!(_cond)) {                   \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:9): [True: 0, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  107|      0|      return _ret;                    \
  |  |  |  |  |  |  |  |  |  |  108|      0|    }                                 \
  |  |  |  |  |  |  |  |  |  |  109|      0|  } while (0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (109:12): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1157|       |
 1158|       |        // Clear complete callback if driver set since it can also stall the request.
 1159|      0|        ctrl_xfer->complete_cb = NULL;
 1160|       |
 1161|      0|        switch (p_request->bRequest) { //-V2520
 1162|      0|          case TUSB_REQ_GET_INTERFACE: {
  ------------------
  |  Branch (1162:11): [True: 0, False: 0]
  ------------------
 1163|      0|            uint8_t alternate = 0;
 1164|      0|            tud_control_xfer(rhport, p_request, &alternate, 1);
 1165|      0|            break;
 1166|      0|          }
 1167|       |
 1168|      0|          case TUSB_REQ_SET_INTERFACE:
  ------------------
  |  Branch (1168:11): [True: 0, False: 0]
  ------------------
 1169|      0|            tud_control_status(rhport, p_request);
 1170|      0|            break;
 1171|       |
 1172|      0|          default: return false;
  ------------------
  |  Branch (1172:11): [True: 0, False: 0]
  ------------------
 1173|      0|        }
 1174|      0|      }
 1175|      0|      break;
 1176|      0|    }
 1177|       |
 1178|       |    //------------- Endpoint Request -------------//
 1179|  1.87k|    case TUSB_REQ_RCPT_ENDPOINT: {
  ------------------
  |  Branch (1179:5): [True: 1.87k, False: 10.7k]
  ------------------
 1180|  1.87k|      uint8_t const ep_addr = tu_u16_low(p_request->wIndex);
 1181|  1.87k|      uint8_t const ep_num  = tu_edpt_number(ep_addr);
 1182|  1.87k|      uint8_t const ep_dir  = tu_edpt_dir(ep_addr);
 1183|       |
 1184|  1.87k|      TU_ASSERT(ep_num < TU_ARRAY_SIZE(_usbd_dev.ep2drv) );
  ------------------
  |  |  131|  1.87k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|  1.87k|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|  1.87k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  127|  1.87k|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|  1.87k|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|  1.87k|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   73|    225|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (73:41): [Folded, False: 225]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   96|    225|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (96:40): [Folded, False: 225]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (124:10): [True: 225, False: 1.64k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|  1.87k|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 1.64k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1185|  1.64k|      usbd_class_driver_t const * driver = get_driver(_usbd_dev.ep2drv[ep_num][ep_dir]);
 1186|       |
 1187|  1.64k|      if (TUSB_REQ_TYPE_STANDARD != p_request->bmRequestType_bit.type) {
  ------------------
  |  Branch (1187:11): [True: 204, False: 1.44k]
  ------------------
 1188|       |        // Forward class request to its driver
 1189|    204|        TU_VERIFY(driver);
  ------------------
  |  |  114|    204|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    204|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  114|    204|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  111|    204|#define TU_VERIFY_1ARGS(_cond)         TU_VERIFY_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  105|    204|  do {                                \
  |  |  |  |  |  |  |  |  |  |  106|    204|    if (!(_cond)) {                   \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:9): [True: 204, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  107|    204|      return _ret;                    \
  |  |  |  |  |  |  |  |  |  |  108|    204|    }                                 \
  |  |  |  |  |  |  |  |  |  |  109|    204|  } while (0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (109:12): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1190|      0|        return invoke_class_control(rhport, driver, p_request);
 1191|  1.44k|      } else {
 1192|       |        // Handle STD request to endpoint
 1193|  1.44k|        switch (p_request->bRequest) { //-V2520
 1194|    221|          case TUSB_REQ_GET_STATUS: {
  ------------------
  |  Branch (1194:11): [True: 221, False: 1.22k]
  ------------------
 1195|    221|            uint16_t status = usbd_edpt_stalled(rhport, ep_addr) ? 0x0001u : 0x0000u;
  ------------------
  |  Branch (1195:31): [True: 0, False: 221]
  ------------------
 1196|    221|            tud_control_xfer(rhport, p_request, &status, 2);
 1197|    221|          }
 1198|    221|          break;
 1199|       |
 1200|    407|          case TUSB_REQ_CLEAR_FEATURE:
  ------------------
  |  Branch (1200:11): [True: 407, False: 1.03k]
  ------------------
 1201|    848|          case TUSB_REQ_SET_FEATURE: {
  ------------------
  |  Branch (1201:11): [True: 441, False: 1.00k]
  ------------------
 1202|    848|            if ( TUSB_REQ_FEATURE_EDPT_HALT == p_request->wValue ) {
  ------------------
  |  Branch (1202:18): [True: 428, False: 420]
  ------------------
 1203|    428|              if ( TUSB_REQ_CLEAR_FEATURE ==  p_request->bRequest ) {
  ------------------
  |  Branch (1203:20): [True: 201, False: 227]
  ------------------
 1204|    201|                usbd_edpt_clear_stall(rhport, ep_addr);
 1205|    227|              }else {
 1206|    227|                usbd_edpt_stall(rhport, ep_addr);
 1207|    227|              }
 1208|    428|            }
 1209|       |
 1210|    848|            if (driver != NULL) {
  ------------------
  |  Branch (1210:17): [True: 0, False: 848]
  ------------------
 1211|       |              // Some classes such as USBTMC needs to clear/re-init its buffer when receiving CLEAR_FEATURE request
 1212|       |              // We will also forward std request targeted endpoint to class drivers as well
 1213|       |
 1214|       |              // STD request must always be ACKed regardless of driver returned value
 1215|       |              // Also clear complete callback if driver set since it can also stall the request.
 1216|      0|              (void) invoke_class_control(rhport, driver, p_request);
 1217|      0|              ctrl_xfer->complete_cb = NULL;
 1218|       |
 1219|       |              // skip ZLP status if driver already did that
 1220|      0|              if (!(_usbd_dev.ep_status[0][TUSB_DIR_IN] & TU_EDPT_STATE_BUSY)) {
  ------------------
  |  |   50|      0|#define TU_EDPT_STATE_BUSY    0x01u
  ------------------
  |  Branch (1220:19): [True: 0, False: 0]
  ------------------
 1221|      0|                tud_control_status(rhport, p_request);
 1222|      0|              }
 1223|      0|            }
 1224|    848|          }
 1225|    848|          break;
 1226|       |
 1227|       |          // Unknown/Unsupported request
 1228|    374|          default:
  ------------------
  |  Branch (1228:11): [True: 374, False: 1.06k]
  ------------------
 1229|    374|            TU_BREAKPOINT();
  ------------------
  |  |   96|    374|  #define TU_BREAKPOINT() do {} while (0)
  |  |  ------------------
  |  |  |  Branch (96:40): [Folded, False: 374]
  |  |  ------------------
  ------------------
 1230|    374|            return false;
 1231|  1.44k|        }
 1232|  1.44k|      }
 1233|  1.06k|      break;
 1234|  1.64k|    }
 1235|       |
 1236|       |    // Unknown recipient
 1237|  1.33k|    default:
  ------------------
  |  Branch (1237:5): [True: 1.33k, False: 11.2k]
  ------------------
 1238|  1.33k|      TU_BREAKPOINT();
  ------------------
  |  |   96|  1.33k|  #define TU_BREAKPOINT() do {} while (0)
  |  |  ------------------
  |  |  |  Branch (96:40): [Folded, False: 1.33k]
  |  |  ------------------
  ------------------
 1239|  1.33k|      return false;
 1240|  12.6k|  }
 1241|       |
 1242|  1.06k|  return true;
 1243|  12.6k|}
usbd.c:process_std_device_request:
  963|  8.20k|static bool process_std_device_request(uint8_t rhport, tusb_control_request_t const * p_request) {
  964|  8.20k|  switch (p_request->bRequest) { //-V2520
  965|    218|    case TUSB_REQ_SET_ADDRESS:
  ------------------
  |  Branch (965:5): [True: 218, False: 7.99k]
  ------------------
  966|       |      // Depending on mcu, status phase could be sent either before or after changing device address,
  967|       |      // or even require stack to not response with status at all
  968|       |      // Therefore DCD must take full responsibility to response and include zlp status packet if needed.
  969|    218|      dcd_set_address(rhport, (uint8_t) p_request->wValue);
  970|    218|      _usbd_dev.addressed = 1;
  971|    218|      return true;
  972|       |
  973|    288|    case TUSB_REQ_GET_CONFIGURATION: {
  ------------------
  |  Branch (973:5): [True: 288, False: 7.92k]
  ------------------
  974|    288|      uint8_t cfg_num = _usbd_dev.cfg_num;
  975|    288|      tud_control_xfer(rhport, p_request, &cfg_num, 1);
  976|    288|      return true;
  977|      0|    }
  978|       |
  979|    939|    case TUSB_REQ_SET_CONFIGURATION: {
  ------------------
  |  Branch (979:5): [True: 939, False: 7.26k]
  ------------------
  980|    939|      uint8_t const cfg_num = (uint8_t) p_request->wValue;
  981|       |
  982|       |      // Only process if new configure is different
  983|    939|      if (_usbd_dev.cfg_num != cfg_num) {
  ------------------
  |  Branch (983:11): [True: 209, False: 730]
  ------------------
  984|    209|        if (_usbd_dev.cfg_num != 0) {
  ------------------
  |  Branch (984:13): [True: 0, False: 209]
  ------------------
  985|       |          // already configured: need to clear all endpoints and driver first
  986|      0|          TU_LOG_USBD("  Clear current Configuration (%u) before switching\r\n", _usbd_dev.cfg_num);
  987|       |
  988|      0|          dcd_sof_enable(rhport, false);
  989|      0|          dcd_edpt_close_all(rhport);
  990|       |
  991|       |          // close all drivers and current configured state except bus speed
  992|      0|          const uint8_t speed = _usbd_dev.speed;
  993|      0|          configuration_reset(rhport);
  994|       |
  995|      0|          _usbd_dev.speed = speed; // restore speed
  996|      0|        }
  997|       |
  998|    209|        _usbd_dev.cfg_num = cfg_num;
  999|       |
 1000|       |        // Handle the new configuration
 1001|    209|        if (cfg_num == 0) {
  ------------------
  |  Branch (1001:13): [True: 0, False: 209]
  ------------------
 1002|      0|          tud_umount_cb();
 1003|    209|        } else {
 1004|    209|          if (!process_set_config(rhport, cfg_num)) {
  ------------------
  |  Branch (1004:15): [True: 209, False: 0]
  ------------------
 1005|    209|            _usbd_dev.cfg_num = 0;
 1006|    209|            TU_ASSERT(false);
  ------------------
  |  |  131|    209|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    209|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|    209|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  127|    209|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|    209|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|    209|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   73|    209|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (73:41): [Folded, False: 209]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   96|    209|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (96:40): [Folded, False: 209]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (124:10): [True: 209, Folded]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|    209|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1007|    209|          }
 1008|      0|          tud_mount_cb();
 1009|      0|        }
 1010|    209|      }
 1011|       |
 1012|    730|      tud_control_status(rhport, p_request);
 1013|    730|      return true;
 1014|    939|    }
 1015|       |
 1016|  2.45k|    case TUSB_REQ_GET_DESCRIPTOR:
  ------------------
  |  Branch (1016:5): [True: 2.45k, False: 5.75k]
  ------------------
 1017|  2.45k|      return process_get_descriptor(rhport, p_request);
 1018|       |
 1019|  1.10k|    case TUSB_REQ_SET_FEATURE:
  ------------------
  |  Branch (1019:5): [True: 1.10k, False: 7.10k]
  ------------------
 1020|  1.10k|      switch (p_request->wValue) { //-V2520
 1021|    863|        case TUSB_REQ_FEATURE_REMOTE_WAKEUP:
  ------------------
  |  Branch (1021:9): [True: 863, False: 242]
  ------------------
 1022|    863|          TU_LOG_USBD("    Enable Remote Wakeup\r\n");
 1023|       |          // Host may enable remote wake up before suspending especially HID device
 1024|    863|          _usbd_dev.remote_wakeup_en = 1;
 1025|    863|          tud_control_status(rhport, p_request);
 1026|    863|          return true;
 1027|       |
 1028|       |        #if CFG_TUD_TEST_MODE
 1029|       |        case TUSB_REQ_FEATURE_TEST_MODE: {
 1030|       |          // Only handle the test mode if supported and valid
 1031|       |          TU_VERIFY(0 == tu_u16_low(p_request->wIndex));
 1032|       |
 1033|       |          uint8_t const selector = tu_u16_high(p_request->wIndex);
 1034|       |          TU_VERIFY(TUSB_FEATURE_TEST_J <= selector && selector <= TUSB_FEATURE_TEST_FORCE_ENABLE);
 1035|       |
 1036|       |          _usbd_dev.ctrl_xfer.complete_cb = process_test_mode_cb;
 1037|       |          tud_control_status(rhport, p_request);
 1038|       |          return true;
 1039|       |        }
 1040|       |        #endif
 1041|       |
 1042|       |        // Stall unsupported feature selector
 1043|    242|        default: return false;
  ------------------
  |  Branch (1043:9): [True: 242, False: 863]
  ------------------
 1044|  1.10k|      }
 1045|       |
 1046|  1.36k|    case TUSB_REQ_CLEAR_FEATURE:
  ------------------
  |  Branch (1046:5): [True: 1.36k, False: 6.84k]
  ------------------
 1047|       |      // Only support remote wakeup for device feature
 1048|  1.36k|      TU_VERIFY(TUSB_REQ_FEATURE_REMOTE_WAKEUP == p_request->wValue);
  ------------------
  |  |  114|  1.36k|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|  1.36k|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  114|  1.36k|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  111|  1.36k|#define TU_VERIFY_1ARGS(_cond)         TU_VERIFY_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  105|  1.36k|  do {                                \
  |  |  |  |  |  |  |  |  |  |  106|  1.36k|    if (!(_cond)) {                   \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:9): [True: 326, False: 1.03k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  107|    326|      return _ret;                    \
  |  |  |  |  |  |  |  |  |  |  108|    326|    }                                 \
  |  |  |  |  |  |  |  |  |  |  109|  1.36k|  } while (0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (109:12): [Folded, False: 1.03k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1049|  1.03k|      TU_LOG_USBD("    Disable Remote Wakeup\r\n");
 1050|       |
 1051|       |      // Host may disable remote wake up after resuming
 1052|  1.03k|      _usbd_dev.remote_wakeup_en = 0;
 1053|  1.03k|      tud_control_status(rhport, p_request);
 1054|  1.03k|      return true;
 1055|       |
 1056|  1.27k|    case TUSB_REQ_GET_STATUS: {
  ------------------
  |  Branch (1056:5): [True: 1.27k, False: 6.93k]
  ------------------
 1057|       |      // Device status bit mask
 1058|       |      // - Bit 0: Self Powered TODO must invoke callback to get actual status
 1059|       |      // - Bit 1: Remote Wakeup enabled
 1060|  1.27k|      uint16_t status = (uint16_t) _usbd_dev.dev_state_bm;
 1061|  1.27k|      tud_control_xfer(rhport, p_request, &status, 2);
 1062|  1.27k|      return true;
 1063|  1.36k|    }
 1064|       |
 1065|    567|    default:
  ------------------
  |  Branch (1065:5): [True: 567, False: 7.64k]
  ------------------
 1066|    567|      TU_BREAKPOINT();
  ------------------
  |  |   96|    567|  #define TU_BREAKPOINT() do {} while (0)
  |  |  ------------------
  |  |  |  Branch (96:40): [Folded, False: 567]
  |  |  ------------------
  ------------------
 1067|       |      return false;
 1068|  8.20k|  }
 1069|  8.20k|}
usbd.c:process_set_config:
 1247|    209|static bool process_set_config(uint8_t rhport, uint8_t cfg_num) {
 1248|       |  // index is cfg_num-1
 1249|    209|  const tusb_desc_configuration_t *desc_cfg =
 1250|    209|    (const tusb_desc_configuration_t *)tud_descriptor_configuration_cb(cfg_num - 1);
 1251|    209|  TU_ASSERT(desc_cfg != NULL && desc_cfg->bDescriptorType == TUSB_DESC_CONFIGURATION);
  ------------------
  |  |  131|    209|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    209|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|    209|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  127|    209|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|    209|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|    418|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   73|      0|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (73:41): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   96|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (96:40): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (124:12): [True: 209, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  Branch (124:12): [True: 209, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|    209|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 209]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1252|       |
 1253|       |  // Parse configuration descriptor
 1254|    209|  _usbd_dev.self_powered = (desc_cfg->bmAttributes & TUSB_DESC_CONFIG_ATT_SELF_POWERED) ? 1u : 0u;
  ------------------
  |  Branch (1254:28): [True: 0, False: 209]
  ------------------
 1255|       |
 1256|       |  // Parse interface descriptor
 1257|    209|  const uint8_t *p_desc   = ((const uint8_t *)desc_cfg) + sizeof(tusb_desc_configuration_t);
 1258|    209|  const uint8_t *desc_end = ((const uint8_t *)desc_cfg) + tu_le16toh(desc_cfg->wTotalLength);
  ------------------
  |  |  272|    209|  #define tu_le16toh(u16) (u16)
  ------------------
 1259|       |
 1260|    209|  while (tu_desc_in_bounds(p_desc, desc_end)) {
  ------------------
  |  Branch (1260:10): [True: 209, False: 0]
  ------------------
 1261|       |    // Class will always start with Interface Association (if any) and then Interface descriptor
 1262|    209|    if (TUSB_DESC_INTERFACE_ASSOCIATION == tu_desc_type(p_desc)) {
  ------------------
  |  Branch (1262:9): [True: 0, False: 209]
  ------------------
 1263|      0|      p_desc = tu_desc_next(p_desc); // next to Interface
 1264|      0|      continue;
 1265|      0|    }
 1266|       |
 1267|    209|    TU_ASSERT(TUSB_DESC_INTERFACE == tu_desc_type(p_desc));
  ------------------
  |  |  131|    209|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    209|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|    209|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  127|    209|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|    209|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|    209|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   73|      0|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (73:41): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   96|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (96:40): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (124:10): [True: 0, False: 209]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|    209|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 209]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1268|    209|    const tusb_desc_interface_t *desc_itf = (const tusb_desc_interface_t *)p_desc;
 1269|       |
 1270|       |    // Find driver for this interface
 1271|    209|    const uint16_t remaining_len = (uint16_t)(desc_end - p_desc);
 1272|    209|    uint8_t        drv_id;
 1273|    418|    for (drv_id = 0; drv_id < TOTAL_DRIVER_COUNT; drv_id++) {
  ------------------
  |  |  389|    418|#define TOTAL_DRIVER_COUNT    ((uint8_t) (_app_driver_count + BUILTIN_DRIVER_COUNT))
  ------------------
  |  Branch (1273:22): [True: 209, False: 209]
  ------------------
 1274|    209|      const usbd_class_driver_t *driver = get_driver(drv_id);
 1275|    209|      TU_ASSERT(driver);
  ------------------
  |  |  131|    209|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    209|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|    209|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  127|    209|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|    209|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|    209|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   73|      0|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (73:41): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   96|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (96:40): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (124:10): [True: 0, False: 209]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|    209|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 209]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1276|    209|      const uint16_t drv_len = driver->open(rhport, desc_itf, remaining_len);
 1277|       |
 1278|    209|      if ((sizeof(tusb_desc_interface_t) <= drv_len) && (drv_len <= remaining_len)) {
  ------------------
  |  Branch (1278:11): [True: 0, False: 209]
  |  Branch (1278:57): [True: 0, False: 0]
  ------------------
 1279|       |        // Open successfully
 1280|      0|        TU_LOG_USBD("  %s opened\r\n", driver->name);
 1281|       |
 1282|       |        // bind found driver to all interfaces and endpoint within drv_len
 1283|      0|        TU_ASSERT(tu_bind_driver_to_ep_itf(drv_id, _usbd_dev.ep2drv, _usbd_dev.itf2drv, CFG_TUD_INTERFACE_MAX, p_desc,
  ------------------
  |  |  131|      0|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|      0|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|      0|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  127|      0|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|      0|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|      0|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   73|      0|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (73:41): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   96|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (96:40): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (124:10): [True: 0, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|      0|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1284|      0|                                           drv_len));
 1285|       |
 1286|      0|        p_desc += drv_len; // next Interface
 1287|      0|        break; // exit driver find loop
 1288|      0|      }
 1289|    209|    }
 1290|       |
 1291|       |    // Failed if there is no supported drivers
 1292|    209|    TU_ASSERT(drv_id < TOTAL_DRIVER_COUNT);
  ------------------
  |  |  131|    209|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    209|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|    209|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  127|    209|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|    209|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|    209|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   73|    209|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (73:41): [Folded, False: 209]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   96|    209|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (96:40): [Folded, False: 209]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (124:10): [True: 209, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|    209|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1293|    209|  }
 1294|       |
 1295|      0|  return true;
 1296|    209|}
usbd.c:process_get_descriptor:
 1299|  2.45k|static bool process_get_descriptor(uint8_t rhport, tusb_control_request_t const * p_request) {
 1300|  2.45k|  tusb_desc_type_t const desc_type = (tusb_desc_type_t) tu_u16_high(p_request->wValue);
 1301|  2.45k|  uint8_t const desc_index = tu_u16_low( p_request->wValue );
 1302|       |
 1303|  2.45k|  switch(desc_type) { //-V2520
 1304|    217|    case TUSB_DESC_DEVICE: {
  ------------------
  |  Branch (1304:5): [True: 217, False: 2.23k]
  ------------------
 1305|    217|      TU_LOG_USBD(" Device\r\n");
 1306|       |
 1307|    217|      void *desc_device = (void *)(uintptr_t)tud_descriptor_device_cb();
 1308|    217|      TU_ASSERT(desc_device);
  ------------------
  |  |  131|    217|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    217|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|    217|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  127|    217|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|    217|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|    217|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   73|      0|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (73:41): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   96|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (96:40): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (124:10): [True: 0, False: 217]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|    217|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 217]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1309|       |
 1310|       |      // Only response with exactly 1 Packet if: not addressed and host requested more data than device descriptor has.
 1311|       |      // This only happens with the very first get device descriptor and EP0 size = 8 or 16.
 1312|    217|      if ((CFG_TUD_ENDPOINT0_SIZE < sizeof(tusb_desc_device_t)) && !_usbd_dev.addressed &&
  ------------------
  |  |   90|    217|#define CFG_TUD_ENDPOINT0_SIZE    64
  ------------------
  |  Branch (1312:11): [Folded, False: 217]
  |  Branch (1312:68): [True: 0, False: 0]
  ------------------
 1313|      0|          p_request->wLength > sizeof(tusb_desc_device_t)) {
  ------------------
  |  Branch (1313:11): [True: 0, False: 0]
  ------------------
 1314|       |        // Hack here: we modify the request length to prevent usbd_control response with zlp
 1315|       |        // since we are responding with 1 packet & less data than wLength.
 1316|      0|        ((tusb_control_request_t *)(uintptr_t)p_request)->wLength = CFG_TUD_ENDPOINT0_SIZE;
  ------------------
  |  |   90|      0|#define CFG_TUD_ENDPOINT0_SIZE    64
  ------------------
 1317|      0|        return tud_control_xfer(rhport, p_request, desc_device, CFG_TUD_ENDPOINT0_SIZE);
  ------------------
  |  |   90|      0|#define CFG_TUD_ENDPOINT0_SIZE    64
  ------------------
 1318|    217|      } else {
 1319|    217|        return tud_control_xfer(rhport, p_request, desc_device, sizeof(tusb_desc_device_t));
 1320|    217|      }
 1321|    217|    }
 1322|       |    // break; // unreachable
 1323|       |
 1324|    202|    case TUSB_DESC_BOS: {
  ------------------
  |  Branch (1324:5): [True: 202, False: 2.25k]
  ------------------
 1325|    202|      TU_LOG_USBD(" BOS\r\n");
 1326|       |
 1327|       |      // requested by host if USB > 2.0 ( i.e 2.1 or 3.x )
 1328|    202|      uintptr_t desc_bos = (uintptr_t) tud_descriptor_bos_cb();
 1329|    202|      TU_VERIFY(desc_bos != 0);
  ------------------
  |  |  114|    202|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    202|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  114|    202|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  111|    202|#define TU_VERIFY_1ARGS(_cond)         TU_VERIFY_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  105|    202|  do {                                \
  |  |  |  |  |  |  |  |  |  |  106|    202|    if (!(_cond)) {                   \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:9): [True: 202, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  107|    202|      return _ret;                    \
  |  |  |  |  |  |  |  |  |  |  108|    202|    }                                 \
  |  |  |  |  |  |  |  |  |  |  109|    202|  } while (0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (109:12): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1330|       |
 1331|       |      // Use offsetof to avoid pointer to the odd/misaligned address
 1332|      0|      uint16_t const total_len = tu_le16toh( tu_unaligned_read16((const void*) (desc_bos + offsetof(tusb_desc_bos_t, wTotalLength))) );
  ------------------
  |  |  272|      0|  #define tu_le16toh(u16) (u16)
  ------------------
 1333|       |
 1334|      0|      return tud_control_xfer(rhport, p_request, (void*) desc_bos, total_len);
 1335|    202|    }
 1336|       |    // break; // unreachable
 1337|       |
 1338|    390|    case TUSB_DESC_CONFIGURATION:
  ------------------
  |  Branch (1338:5): [True: 390, False: 2.06k]
  ------------------
 1339|    588|    case TUSB_DESC_OTHER_SPEED_CONFIG: {
  ------------------
  |  Branch (1339:5): [True: 198, False: 2.25k]
  ------------------
 1340|    588|      uintptr_t desc_config;
 1341|       |
 1342|    588|      if ( desc_type == TUSB_DESC_CONFIGURATION ) {
  ------------------
  |  Branch (1342:12): [True: 390, False: 198]
  ------------------
 1343|    390|        TU_LOG_USBD(" Configuration[%u]\r\n", desc_index);
 1344|    390|        desc_config = (uintptr_t) tud_descriptor_configuration_cb(desc_index);
 1345|    390|        TU_ASSERT(desc_config != 0);
  ------------------
  |  |  131|    390|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    390|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|    390|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  127|    390|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|    390|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|    390|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   73|      0|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (73:41): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   96|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (96:40): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (124:10): [True: 0, False: 390]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|    390|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 390]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1346|    390|      }else {
 1347|       |        // Host only request this after getting Device Qualifier descriptor
 1348|    198|        TU_LOG_USBD(" Other Speed Configuration\r\n");
 1349|    198|        desc_config = (uintptr_t) tud_descriptor_other_speed_configuration_cb(desc_index);
 1350|    198|        TU_VERIFY(desc_config != 0);
  ------------------
  |  |  114|    198|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    198|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  114|    198|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  111|    198|#define TU_VERIFY_1ARGS(_cond)         TU_VERIFY_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  105|    198|  do {                                \
  |  |  |  |  |  |  |  |  |  |  106|    198|    if (!(_cond)) {                   \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:9): [True: 198, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  107|    198|      return _ret;                    \
  |  |  |  |  |  |  |  |  |  |  108|    198|    }                                 \
  |  |  |  |  |  |  |  |  |  |  109|    198|  } while (0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (109:12): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1351|    198|      }
 1352|       |
 1353|       |      // Use offsetof to avoid pointer to the odd/misaligned address
 1354|    390|      uint16_t const total_len = tu_le16toh( tu_unaligned_read16((const void*) (desc_config + offsetof(tusb_desc_configuration_t, wTotalLength))) );
  ------------------
  |  |  272|    390|  #define tu_le16toh(u16) (u16)
  ------------------
 1355|       |
 1356|    390|      return tud_control_xfer(rhport, p_request, (void*) desc_config, total_len);
 1357|    588|    }
 1358|       |    // break; // unreachable
 1359|       |
 1360|    982|    case TUSB_DESC_STRING: {
  ------------------
  |  Branch (1360:5): [True: 982, False: 1.47k]
  ------------------
 1361|    982|      TU_LOG_USBD(" String[%u]\r\n", desc_index);
 1362|       |
 1363|       |      // String Descriptor always uses the desc set from user
 1364|    982|      uint8_t const* desc_str = (uint8_t const*) tud_descriptor_string_cb(desc_index, p_request->wIndex);
 1365|    982|      TU_VERIFY(desc_str);
  ------------------
  |  |  114|    982|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    982|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  114|    982|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  111|    982|#define TU_VERIFY_1ARGS(_cond)         TU_VERIFY_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  105|    982|  do {                                \
  |  |  |  |  |  |  |  |  |  |  106|    982|    if (!(_cond)) {                   \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:9): [True: 210, False: 772]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  107|    210|      return _ret;                    \
  |  |  |  |  |  |  |  |  |  |  108|    210|    }                                 \
  |  |  |  |  |  |  |  |  |  |  109|    982|  } while (0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (109:12): [Folded, False: 772]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1366|       |
 1367|       |      // first byte of descriptor is its size
 1368|    772|      return tud_control_xfer(rhport, p_request, (void*) (uintptr_t) desc_str, tu_desc_len(desc_str));
 1369|    982|    }
 1370|       |    // break; // unreachable
 1371|       |
 1372|    209|    case TUSB_DESC_DEVICE_QUALIFIER: {
  ------------------
  |  Branch (1372:5): [True: 209, False: 2.24k]
  ------------------
 1373|    209|      TU_LOG_USBD(" Device Qualifier\r\n");
 1374|    209|      uint8_t const* desc_qualifier = tud_descriptor_device_qualifier_cb();
 1375|    209|      TU_VERIFY(desc_qualifier);
  ------------------
  |  |  114|    209|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    209|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  114|    209|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  111|    209|#define TU_VERIFY_1ARGS(_cond)         TU_VERIFY_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  105|    209|  do {                                \
  |  |  |  |  |  |  |  |  |  |  106|    209|    if (!(_cond)) {                   \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:9): [True: 209, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  107|    209|      return _ret;                    \
  |  |  |  |  |  |  |  |  |  |  108|    209|    }                                 \
  |  |  |  |  |  |  |  |  |  |  109|    209|  } while (0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (109:12): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1376|      0|      return tud_control_xfer(rhport, p_request, (void*) (uintptr_t) desc_qualifier, tu_desc_len(desc_qualifier));
 1377|    209|    }
 1378|       |    // break; // unreachable
 1379|       |
 1380|    258|    default: return false;
  ------------------
  |  Branch (1380:5): [True: 258, False: 2.19k]
  ------------------
 1381|  2.45k|  }
 1382|  2.45k|}
usbd.c:queue_event:
  430|  34.4k|TU_ATTR_ALWAYS_INLINE static inline bool queue_event(dcd_event_t const * event, bool in_isr) {
  431|  34.4k|  TU_ASSERT(osal_queue_send(_usbd_q, event, in_isr));
  ------------------
  |  |  131|  34.4k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|  34.4k|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|  34.4k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  127|  34.4k|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|  34.4k|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|  34.4k|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   73|      0|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (73:41): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   96|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (96:40): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (124:10): [True: 0, False: 34.4k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|  34.4k|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 34.4k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  432|  34.4k|  tud_event_hook_cb(event->rhport, event->event_id, in_isr);
  433|       |  return true;
  434|  34.4k|}

fuzz.cc:_ZL8tud_taskv:
   95|  41.7k|void tud_task (void) {
   96|       |  tud_task_ext(UINT32_MAX, false);
   97|  41.7k|}

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

tusb_rhport_init:
   84|  1.02k|bool tusb_rhport_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
   85|       |  //  backward compatible called with tusb_init(void)
   86|       |  #if defined(TUD_OPT_RHPORT) || defined(TUH_OPT_RHPORT)
   87|       |  if (rh_init == NULL) {
   88|       |    #if CFG_TUD_ENABLED && defined(TUD_OPT_RHPORT)
   89|       |    // init device stack CFG_TUSB_RHPORTx_MODE must be defined
   90|       |    const tusb_rhport_init_t dev_init = {
   91|       |      .role = TUSB_ROLE_DEVICE,
   92|       |      .speed = TUD_OPT_HIGH_SPEED ? TUSB_SPEED_HIGH : TUSB_SPEED_FULL
   93|       |    };
   94|       |    TU_ASSERT ( tud_rhport_init(TUD_OPT_RHPORT, &dev_init) );
   95|       |    _tusb_rhport_role[TUD_OPT_RHPORT] = TUSB_ROLE_DEVICE;
   96|       |    #endif
   97|       |
   98|       |    #if CFG_TUH_ENABLED && defined(TUH_OPT_RHPORT)
   99|       |    // init host stack CFG_TUSB_RHPORTx_MODE must be defined
  100|       |    const tusb_rhport_init_t host_init = {
  101|       |      .role = TUSB_ROLE_HOST,
  102|       |      .speed = TUH_OPT_HIGH_SPEED ? TUSB_SPEED_HIGH : TUSB_SPEED_FULL
  103|       |    };
  104|       |    TU_ASSERT( tuh_rhport_init(TUH_OPT_RHPORT, &host_init) );
  105|       |    _tusb_rhport_role[TUH_OPT_RHPORT] = TUSB_ROLE_HOST;
  106|       |    #endif
  107|       |
  108|       |    return true;
  109|       |  }
  110|       |  #endif
  111|       |
  112|       |  // new API with explicit rhport and role
  113|  1.02k|  TU_ASSERT(rhport < TUP_USBIP_CONTROLLER_NUM && rh_init->role != TUSB_ROLE_INVALID);
  ------------------
  |  |  131|  1.02k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|  1.02k|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|  1.02k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  127|  1.02k|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|  1.02k|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|  2.04k|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   73|      0|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (73:41): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   96|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (96:40): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (124:12): [True: 1.02k, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  Branch (124:12): [True: 1.02k, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|  1.02k|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 1.02k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  114|  1.02k|  _tusb_rhport_role[rhport] = rh_init->role;
  115|       |
  116|  1.02k|  #if CFG_TUD_ENABLED
  117|  1.02k|  if (rh_init->role == TUSB_ROLE_DEVICE) {
  ------------------
  |  Branch (117:7): [True: 1.02k, False: 0]
  ------------------
  118|  1.02k|    TU_ASSERT(tud_rhport_init(rhport, rh_init));
  ------------------
  |  |  131|  1.02k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|  1.02k|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|  1.02k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  127|  1.02k|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|  1.02k|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|  1.02k|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   73|      0|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (73:41): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   96|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (96:40): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (124:10): [True: 0, False: 1.02k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|  1.02k|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 1.02k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  119|  1.02k|  }
  120|  1.02k|  #endif
  121|       |
  122|       |  #if CFG_TUH_ENABLED
  123|       |  if (rh_init->role == TUSB_ROLE_HOST) {
  124|       |    TU_ASSERT(tuh_rhport_init(rhport, rh_init));
  125|       |  }
  126|       |  #endif
  127|       |
  128|  1.02k|  return true;
  129|  1.02k|}

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|  41.7k|void dcd_int_handler(uint8_t rhport) {
   56|  41.7k|  assert(_fuzz_data_provider.has_value());
  ------------------
  |  Branch (56:3): [True: 41.7k, False: 0]
  ------------------
   57|       |
   58|  41.7k|  if (!state.interrupts_enabled) {
  ------------------
  |  Branch (58:7): [True: 0, False: 41.7k]
  ------------------
   59|      0|    return;
   60|      0|  }
   61|       |
   62|       |  // Choose if we want to generate a signal based on the fuzzed data.
   63|  41.7k|  if (_fuzz_data_provider->ConsumeBool()) {
  ------------------
  |  Branch (63:7): [True: 10.2k, False: 31.4k]
  ------------------
   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|  10.2k|    static const dcd_eventid_t bus_signal_events[] = {
   69|  10.2k|        DCD_EVENT_UNPLUGGED, DCD_EVENT_SUSPEND, DCD_EVENT_RESUME};
   70|  10.2k|    uint8_t idx = _fuzz_data_provider->ConsumeIntegralInRange<uint8_t>(0, 2);
   71|  10.2k|    dcd_event_bus_signal(rhport, bus_signal_events[idx],
   72|  10.2k|                         _fuzz_data_provider->ConsumeBool());
   73|  10.2k|  }
   74|       |
   75|       |  // Optionally generate a BUS_RESET event with a valid speed value.
   76|  41.7k|  if (_fuzz_data_provider->ConsumeBool()) {
  ------------------
  |  Branch (76:7): [True: 9.59k, False: 32.1k]
  ------------------
   77|  9.59k|    tusb_speed_t speed = (tusb_speed_t)_fuzz_data_provider->ConsumeIntegralInRange<uint8_t>(
   78|  9.59k|        TUSB_SPEED_FULL, TUSB_SPEED_HIGH);
   79|  9.59k|    dcd_event_bus_reset(rhport, speed, _fuzz_data_provider->ConsumeBool());
   80|  9.59k|  }
   81|       |
   82|  41.7k|  if (_fuzz_data_provider->ConsumeBool()) {
  ------------------
  |  Branch (82:7): [True: 15.4k, False: 26.3k]
  ------------------
   83|  15.4k|    constexpr size_t kSetupFrameLength = 8;
   84|  15.4k|    std::vector<uint8_t> setup =
   85|  15.4k|        _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|  15.4k|    if (setup.size() != kSetupFrameLength) {
  ------------------
  |  Branch (89:9): [True: 426, False: 15.0k]
  ------------------
   90|    426|      setup.resize(kSetupFrameLength);
   91|    426|    }
   92|  15.4k|    dcd_event_setup_received(rhport, setup.data(),
   93|       |                             // Identify trigger as either an interrupt or a
   94|       |                             // syncrhonous call depending on fuzz data.
   95|  15.4k|                             _fuzz_data_provider->ConsumeBool());
   96|  15.4k|  }
   97|  41.7k|}
dcd_int_enable:
   99|  89.7k|void dcd_int_enable(uint8_t rhport) {
  100|  89.7k|  state.interrupts_enabled = true;
  101|  89.7k|  UNUSED(rhport);
  ------------------
  |  |   31|  89.7k|#define UNUSED(x) (void)(x)
  ------------------
  102|  89.7k|  return;
  103|  89.7k|}
dcd_int_disable:
  105|  89.7k|void dcd_int_disable(uint8_t rhport) {
  106|  89.7k|  state.interrupts_enabled = false;
  107|  89.7k|  UNUSED(rhport);
  ------------------
  |  |   31|  89.7k|#define UNUSED(x) (void)(x)
  ------------------
  108|  89.7k|  return;
  109|  89.7k|}
dcd_set_address:
  111|    218|void dcd_set_address(uint8_t rhport, uint8_t dev_addr) {
  112|    218|  UNUSED(rhport);
  ------------------
  |  |   31|    218|#define UNUSED(x) (void)(x)
  ------------------
  113|    218|  state.address = dev_addr;
  114|       |  // Respond with status.
  115|       |  dcd_edpt_xfer(rhport, tu_edpt_addr(0, TUSB_DIR_IN), NULL, 0, false);
  116|    218|  return;
  117|    218|}
dcd_edpt_xfer:
  171|  6.00k|                   uint16_t total_bytes, bool is_isr) {
  172|  6.00k|  UNUSED(rhport);
  ------------------
  |  |   31|  6.00k|#define UNUSED(x) (void)(x)
  ------------------
  173|  6.00k|  UNUSED(buffer);
  ------------------
  |  |   31|  6.00k|#define UNUSED(x) (void)(x)
  ------------------
  174|  6.00k|  UNUSED(total_bytes);
  ------------------
  |  |   31|  6.00k|#define UNUSED(x) (void)(x)
  ------------------
  175|  6.00k|  UNUSED(is_isr);
  ------------------
  |  |   31|  6.00k|#define UNUSED(x) (void)(x)
  ------------------
  176|       |
  177|  6.00k|  uint8_t const dir = tu_edpt_dir(ep_addr);
  178|       |
  179|  6.00k|  if (dir == TUSB_DIR_IN) {
  ------------------
  |  Branch (179:7): [True: 4.15k, False: 1.85k]
  ------------------
  180|  4.15k|    std::vector<uint8_t> temp =
  181|  4.15k|        _fuzz_data_provider->ConsumeBytes<uint8_t>(total_bytes);
  182|  4.15k|    std::copy(temp.begin(), temp.end(), buffer);
  183|  4.15k|  }
  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.00k|  volatile uint8_t *dont_optimise0 = buffer;
  188|  6.00k|  volatile uint16_t dont_optimise1 = total_bytes;
  189|  6.00k|  UNUSED(dont_optimise0);
  ------------------
  |  |   31|  6.00k|#define UNUSED(x) (void)(x)
  ------------------
  190|  6.00k|  UNUSED(dont_optimise1);
  ------------------
  |  |   31|  6.00k|#define UNUSED(x) (void)(x)
  ------------------
  191|       |
  192|       |
  193|  6.00k|  return _fuzz_data_provider->ConsumeBool();
  194|  6.00k|}
dcd_edpt_stall:
  202|  18.6k|void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr) {
  203|       |
  204|  18.6k|  UNUSED(rhport);
  ------------------
  |  |   31|  18.6k|#define UNUSED(x) (void)(x)
  ------------------
  205|  18.6k|  UNUSED(ep_addr);
  ------------------
  |  |   31|  18.6k|#define UNUSED(x) (void)(x)
  ------------------
  206|  18.6k|  return;
  207|  18.6k|}
dcd_edpt_clear_stall:
  212|    201|void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr) {
  213|       |
  214|    201|  UNUSED(rhport);
  ------------------
  |  |   31|    201|#define UNUSED(x) (void)(x)
  ------------------
  215|    201|  UNUSED(ep_addr);
  ------------------
  |  |   31|    201|#define UNUSED(x) (void)(x)
  ------------------
  216|    201|  return;
  217|    201|}

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

tud_descriptor_device_cb:
   46|    217|uint8_t const *tud_descriptor_device_cb(void) {
   47|    217|  tu_static tusb_desc_device_t const desc_device = {
  ------------------
  |  |   58|    217|  #define tu_static static __thread
  ------------------
   48|    217|      .bLength = sizeof(tusb_desc_device_t),
   49|    217|      .bDescriptorType = TUSB_DESC_DEVICE,
   50|    217|      .bcdUSB = USB_BCD,
  ------------------
  |  |   38|    217|#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|    217|      .bDeviceClass = TUSB_CLASS_MISC,
   56|    217|      .bDeviceSubClass = MISC_SUBCLASS_COMMON,
   57|    217|      .bDeviceProtocol = MISC_PROTOCOL_IAD,
   58|       |
   59|    217|      .bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
  ------------------
  |  |   90|    217|#define CFG_TUD_ENDPOINT0_SIZE    64
  ------------------
   60|       |
   61|    217|      .idVendor = USB_VID,
  ------------------
  |  |   37|    217|#define USB_VID 0xCafe
  ------------------
   62|    217|      .idProduct = USB_PID,
  ------------------
  |  |   35|    217|  (0x4000 | PID_MAP(MSC, 0) | PID_MAP(HID, 1) | PID_MAP(MIDI, 2) |          \
  |  |  ------------------
  |  |  |  |   33|    217|#define PID_MAP(itf, n) ((CFG_TUD_##itf) << (n))
  |  |  |  |  ------------------
  |  |  |  |  |  |   95|    217|#define CFG_TUD_MSC              1
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                 (0x4000 | PID_MAP(MSC, 0) | PID_MAP(HID, 1) | PID_MAP(MIDI, 2) |          \
  |  |  ------------------
  |  |  |  |   33|    217|#define PID_MAP(itf, n) ((CFG_TUD_##itf) << (n))
  |  |  |  |  ------------------
  |  |  |  |  |  |   96|    217|#define CFG_TUD_HID              0
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                 (0x4000 | PID_MAP(MSC, 0) | PID_MAP(HID, 1) | PID_MAP(MIDI, 2) |          \
  |  |  ------------------
  |  |  |  |   33|    217|#define PID_MAP(itf, n) ((CFG_TUD_##itf) << (n))
  |  |  |  |  ------------------
  |  |  |  |  |  |   97|    217|#define CFG_TUD_MIDI             0
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   36|    217|   PID_MAP(VENDOR, 3))
  |  |  ------------------
  |  |  |  |   33|    217|#define PID_MAP(itf, n) ((CFG_TUD_##itf) << (n))
  |  |  |  |  ------------------
  |  |  |  |  |  |   98|    217|#define CFG_TUD_VENDOR           0
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   63|    217|      .bcdDevice = 0x0100,
   64|       |
   65|    217|      .iManufacturer = 0x01,
   66|    217|      .iProduct = 0x02,
   67|    217|      .iSerialNumber = 0x03,
   68|       |
   69|    217|      .bNumConfigurations = 0x01};
   70|       |
   71|    217|  return (uint8_t const *)&desc_device;
   72|    217|}
tud_descriptor_configuration_cb:
  161|    599|uint8_t const *tud_descriptor_configuration_cb(uint8_t index) {
  162|    599|  (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|    599|  return desc_fs_configuration;
  170|    599|#endif
  171|    599|}
tud_descriptor_string_cb:
  192|    982|uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
  193|    982|  (void)langid;
  194|       |
  195|    982|  uint8_t chr_count;
  196|       |
  197|    982|  if (index == 0) {
  ------------------
  |  Branch (197:7): [True: 352, False: 630]
  ------------------
  198|    352|    memcpy(&_desc_str[1], string_desc_arr[0], 2);
  199|    352|    chr_count = 1;
  200|    630|  } 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|    630|    if (!(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])))
  ------------------
  |  Branch (204:9): [True: 210, False: 420]
  ------------------
  205|    210|      return NULL;
  206|       |
  207|    420|    const char *str = string_desc_arr[index];
  208|       |
  209|       |    // Cap at max char
  210|    420|    chr_count = (uint8_t)strlen(str);
  211|    420|    if (chr_count > 31)
  ------------------
  |  Branch (211:9): [True: 0, False: 420]
  ------------------
  212|      0|      chr_count = 31;
  213|       |
  214|       |    // Convert ASCII string into UTF-16
  215|  6.17k|    for (uint8_t i = 0; i < chr_count; i++) {
  ------------------
  |  Branch (215:25): [True: 5.75k, False: 420]
  ------------------
  216|  5.75k|      _desc_str[1 + i] = str[i];
  217|  5.75k|    }
  218|    420|  }
  219|       |
  220|       |  // first byte is length (including header), second byte is string type
  221|    772|  _desc_str[0] = (uint16_t)((TUSB_DESC_STRING << 8) | (2 * chr_count + 2));
  222|       |
  223|    772|  return _desc_str;
  224|    982|}

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

