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.2k|void mscd_reset(uint8_t rhport) {
  367|  15.2k|  (void) rhport;
  368|  15.2k|  tu_memclr(&_mscd_itf, sizeof(mscd_interface_t));
  ------------------
  |  |  114|  15.2k|#define tu_memclr(buffer, size)  (void) memset((buffer), 0, (size))
  ------------------
  369|  15.2k|}
mscd_open:
  371|    213|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|    213|  TU_VERIFY(TUSB_CLASS_MSC    == itf_desc->bInterfaceClass &&
  ------------------
  |  |  114|    213|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    213|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  114|    213|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  112|    213|#define TU_VERIFY_2ARGS(_cond, _ret)   TU_VERIFY_DEFINE(_cond, _ret)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  105|    213|  do {                                \
  |  |  |  |  |  |  |  |  |  |  106|    852|    if (!(_cond)) {                   \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:11): [True: 213, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:11): [True: 213, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:11): [True: 213, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  107|      0|      return _ret;                    \
  |  |  |  |  |  |  |  |  |  |  108|      0|    }                                 \
  |  |  |  |  |  |  |  |  |  |  109|    213|  } while (0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (109:12): [Folded, False: 213]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  374|    213|            MSC_SUBCLASS_SCSI == itf_desc->bInterfaceSubClass &&
  375|    213|            MSC_PROTOCOL_BOT  == itf_desc->bInterfaceProtocol, 0);
  376|    213|  uint16_t const drv_len = sizeof(tusb_desc_interface_t) + 2*sizeof(tusb_desc_endpoint_t);
  377|    213|  TU_ASSERT(max_len >= drv_len, 0); // Max length must be at least 1 interface + 2 endpoints
  ------------------
  |  |  131|    213|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    213|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|    213|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  128|    213|#define TU_ASSERT_2ARGS(_cond, _ret)   TU_ASSERT_DEFINE(_cond, _ret)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|    213|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|    213|    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: 213]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|    213|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 213]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  378|       |
  379|    213|  mscd_interface_t * p_msc = &_mscd_itf;
  380|    213|  p_msc->itf_num = itf_desc->bInterfaceNumber;
  381|    213|  p_msc->rhport = rhport;
  382|       |
  383|       |  // Open endpoint pair
  384|    213|  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|    213|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    213|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|    213|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  128|    213|#define TU_ASSERT_2ARGS(_cond, _ret)   TU_ASSERT_DEFINE(_cond, _ret)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|    213|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|    213|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   73|    213|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (73:41): [Folded, False: 213]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   96|    213|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (96:40): [Folded, False: 213]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (124:10): [True: 213, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|    213|  } 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|  32.9k|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: 32.9k, False: 0]
  ------------------
usbd.c:tu_min16:
  206|  5.33k|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.43k, False: 905]
  ------------------
usbd.c:tu_memcpy_s:
  137|    491|TU_ATTR_ALWAYS_INLINE static inline int tu_memcpy_s(void *dest, size_t destsz, const void *src, size_t count) {
  138|    491|  if (dest == NULL) {
  ------------------
  |  Branch (138:7): [True: 0, False: 491]
  ------------------
  139|      0|    return -1;
  140|      0|  }
  141|       |
  142|    491|  if (count == 0u) {
  ------------------
  |  Branch (142:7): [True: 0, False: 491]
  ------------------
  143|      0|    return 0;
  144|      0|  }
  145|       |
  146|    491|  if (src == NULL) {
  ------------------
  |  Branch (146:7): [True: 0, False: 491]
  ------------------
  147|      0|    return -1;
  148|      0|  }
  149|       |
  150|    491|  if (count > destsz) {
  ------------------
  |  Branch (150:7): [True: 0, False: 491]
  ------------------
  151|      0|    return -1;
  152|      0|  }
  153|       |
  154|    491|  (void) memcpy(dest, src, count);
  155|    491|  return 0;
  156|    491|}
usbd.c:tu_u16_low:
  197|  5.47k|TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_u16_low (uint16_t ui16) { return TU_U16_LOW(ui16); }
  ------------------
  |  |   46|  5.47k|#define TU_U16_LOW(_u16)              ((uint8_t) ((uint16_t) (_u16) & 0x00ffu))
  ------------------
usbd.c:tu_desc_in_bounds:
  390|    213|TU_ATTR_ALWAYS_INLINE static inline bool tu_desc_in_bounds(const uint8_t *p_desc, const uint8_t *desc_end) {
  391|    213|  return p_desc < desc_end && tu_desc_next(p_desc) <= desc_end;
  ------------------
  |  Branch (391:10): [True: 213, False: 0]
  |  Branch (391:31): [True: 213, False: 0]
  ------------------
  392|    213|}
usbd.c:tu_desc_type:
  381|    426|TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_desc_type(void const* desc) {
  382|    426|  return ((uint8_t const*) desc)[DESC_OFFSET_TYPE];
  383|    426|}
usbd.c:tu_u16_high:
  196|  2.34k|TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_u16_high(uint16_t ui16) { return TU_U16_HIGH(ui16); }
  ------------------
  |  |   45|  2.34k|#define TU_U16_HIGH(_u16)             ((uint8_t) (((uint16_t) (_u16) >> 8) & 0x00ffu))
  ------------------
usbd.c:tu_unaligned_read16:
  271|    371|TU_ATTR_ALWAYS_INLINE static inline uint16_t tu_unaligned_read16(const void *mem) {
  272|    371|  tu_unaligned_uint16_t const *ua16 = (tu_unaligned_uint16_t const *) mem;
  273|    371|  return ua16->val;
  274|    371|}
usbd.c:tu_desc_len:
  376|    656|TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_desc_len(void const* desc) {
  377|    656|  return ((uint8_t const*) desc)[DESC_OFFSET_LEN];
  378|    656|}
usbd.c:tu_desc_next:
  370|    213|TU_ATTR_ALWAYS_INLINE static inline uint8_t const * tu_desc_next(void const* desc) {
  371|    213|  uint8_t const* desc8 = (uint8_t const*) desc;
  372|    213|  return desc8 + desc8[DESC_OFFSET_LEN];
  373|    213|}
msc_device.c:tu_desc_next:
  370|    213|TU_ATTR_ALWAYS_INLINE static inline uint8_t const * tu_desc_next(void const* desc) {
  371|    213|  uint8_t const* desc8 = (uint8_t const*) desc;
  372|    213|  return desc8 + desc8[DESC_OFFSET_LEN];
  373|    213|}

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|  75.0k|                                    const tu_hwfifo_access_t *access_mode) {
  464|  75.0k|  uint16_t count = tu_ff_overflow_count(f->depth, wr_idx, rd_idx);
  465|  75.0k|  if (count == 0) {
  ------------------
  |  Branch (465:7): [True: 42.1k, False: 32.9k]
  ------------------
  466|  42.1k|    return 0; // nothing to peek
  467|  42.1k|  }
  468|       |
  469|       |  // Check overflow and correct if required
  470|  32.9k|  if (count > f->depth) {
  ------------------
  |  Branch (470:7): [True: 0, False: 32.9k]
  ------------------
  471|      0|    rd_idx = correct_read_index(f, wr_idx);
  472|      0|    count  = f->depth;
  473|      0|  }
  474|       |
  475|  32.9k|  if (count < n) {
  ------------------
  |  Branch (475:7): [True: 0, False: 32.9k]
  ------------------
  476|      0|    n = count; // limit to available count
  477|      0|  }
  478|       |
  479|  32.9k|  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|  32.9k|  {
  487|  32.9k|    (void)access_mode;
  488|  32.9k|    ff_pull_n(f, p_buffer, n, rd_ptr);
  489|  32.9k|  }
  490|       |
  491|  32.9k|  return n;
  492|  75.0k|}
tu_fifo_read_n_access_mode:
  505|  75.0k|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|  75.0k|  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|  75.0k|  const uint16_t wr_idx = f->wr_idx;
  510|  75.0k|  n         = tu_fifo_peek_n_access_mode(f, buffer, n, wr_idx, f->rd_idx, access_mode);
  511|  75.0k|  f->rd_idx = advance_index(f->depth, f->rd_idx, n);
  512|       |
  513|  75.0k|  ff_unlock(f->mutex_rd);
  514|  75.0k|  return n;
  515|  75.0k|}
tu_fifo_write_n_access_mode:
  519|  32.9k|                                     const tu_hwfifo_access_t *access_mode) {
  520|  32.9k|  if (n == 0) {
  ------------------
  |  Branch (520:7): [True: 0, False: 32.9k]
  ------------------
  521|      0|    return 0;
  522|      0|  }
  523|       |
  524|  32.9k|  ff_lock(f->mutex_wr);
  525|       |
  526|  32.9k|  uint16_t wr_idx = f->wr_idx;
  527|  32.9k|  uint16_t rd_idx = f->rd_idx;
  528|       |
  529|  32.9k|  const uint8_t *buf8 = (const uint8_t *)data;
  530|       |
  531|  32.9k|  TU_LOG(TU_FIFO_DBG, "rd = %3u, wr = %3u, count = %3u, remain = %3u, n = %3u:  ", rd_idx, wr_idx,
  532|  32.9k|         tu_ff_overflow_count(f->depth, wr_idx, rd_idx), tu_ff_remaining_local(f->depth, wr_idx, rd_idx), n);
  533|       |
  534|  32.9k|  if (!f->overwritable) {
  ------------------
  |  Branch (534:7): [True: 32.9k, False: 0]
  ------------------
  535|       |    // limit up to full
  536|  32.9k|    const uint16_t remain = tu_ff_remaining_local(f->depth, wr_idx, rd_idx);
  537|  32.9k|    n                     = tu_min16(n, remain);
  538|  32.9k|  } 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|  32.9k|  if (n) {
  ------------------
  |  Branch (577:7): [True: 32.9k, False: 0]
  ------------------
  578|  32.9k|    const uint16_t wr_ptr = idx2ptr(f->depth, wr_idx);
  579|  32.9k|    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|  32.9k|    {
  587|  32.9k|      ff_push_n(f, buf8, n, wr_ptr);
  588|  32.9k|    }
  589|  32.9k|    f->wr_idx = advance_index(f->depth, wr_idx, n);
  590|       |
  591|  32.9k|    TU_LOG(TU_FIFO_DBG, "\tnew_wr = %u\r\n", f->wr_idx);
  592|  32.9k|  }
  593|       |
  594|  32.9k|  ff_unlock(f->mutex_wr);
  595|       |
  596|  32.9k|  return n;
  597|  32.9k|}
tusb_fifo.c:idx2ptr:
  434|  65.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|  98.8k|  while (idx >= depth) {
  ------------------
  |  Branch (436:10): [True: 32.9k, False: 65.8k]
  ------------------
  437|  32.9k|    idx -= depth;
  438|  32.9k|  }
  439|  65.8k|  return idx;
  440|  65.8k|}
tusb_fifo.c:ff_pull_n:
  398|  32.9k|static void ff_pull_n(const tu_fifo_t *f, void *app_buf, uint16_t n, uint16_t rd_ptr) {
  399|  32.9k|  uint16_t       lin_bytes  = f->depth - rd_ptr;
  400|  32.9k|  uint16_t       wrap_bytes = n - lin_bytes; // only used if wrapped
  401|  32.9k|  const uint8_t *ff_buf     = f->buffer + rd_ptr;
  402|       |
  403|       |  // single byte access
  404|  32.9k|  if (n <= lin_bytes) {
  ------------------
  |  Branch (404:7): [True: 32.9k, False: 0]
  ------------------
  405|       |    // Linear only
  406|  32.9k|    memcpy(app_buf, ff_buf, n);
  407|  32.9k|  } 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|  32.9k|}
tusb_fifo.c:advance_index:
  420|   108k|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|   108k|  uint16_t new_idx = (uint16_t)(idx + offset);
  425|   108k|  if ((idx > new_idx) || (new_idx >= 2 * depth)) {
  ------------------
  |  Branch (425:7): [True: 0, False: 108k]
  |  Branch (425:26): [True: 2.05k, False: 105k]
  ------------------
  426|  2.05k|    const uint16_t non_used_index_space = (uint16_t)(UINT16_MAX - (2 * depth - 1));
  427|  2.05k|    new_idx                             = (uint16_t)(new_idx + non_used_index_space);
  428|  2.05k|  }
  429|       |
  430|   108k|  return new_idx;
  431|   108k|}
tusb_fifo.c:ff_push_n:
  382|  32.9k|static void ff_push_n(const tu_fifo_t *f, const void *app_buf, uint16_t n, uint16_t wr_ptr) {
  383|  32.9k|  uint16_t lin_bytes  = f->depth - wr_ptr;
  384|  32.9k|  uint16_t wrap_bytes = n - lin_bytes;
  385|  32.9k|  uint8_t *ff_buf     = f->buffer + wr_ptr;
  386|       |
  387|  32.9k|  if (n <= lin_bytes) {
  ------------------
  |  Branch (387:7): [True: 32.9k, False: 0]
  ------------------
  388|       |    // Linear only case
  389|  32.9k|    memcpy(ff_buf, app_buf, n);
  390|  32.9k|  } 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|  32.9k|}

tusb_fifo.c:tu_ff_overflow_count:
  262|   108k|TU_ATTR_ALWAYS_INLINE static inline uint16_t tu_ff_overflow_count(uint16_t depth, uint16_t wr_idx, uint16_t rd_idx) {
  263|   108k|  const int32_t diff = (int32_t)wr_idx - (int32_t)rd_idx;
  264|   108k|  if (diff >= 0) {
  ------------------
  |  Branch (264:7): [True: 105k, False: 2.26k]
  ------------------
  265|   105k|    return (uint16_t)diff;
  266|   105k|  } else {
  267|  2.26k|    return (uint16_t)(2 * depth + diff);
  268|  2.26k|  }
  269|   108k|}
tusb_fifo.c:tu_ff_remaining_local:
  272|  32.9k|TU_ATTR_ALWAYS_INLINE static inline uint16_t tu_ff_remaining_local(uint16_t depth, uint16_t wr_idx, uint16_t rd_idx) {
  273|  32.9k|  const uint16_t ovf_count = tu_ff_overflow_count(depth, wr_idx, rd_idx);
  274|  32.9k|  return (depth > ovf_count) ? (depth - ovf_count) : 0;
  ------------------
  |  Branch (274:10): [True: 32.9k, False: 0]
  ------------------
  275|  32.9k|}
usbd.c:tu_fifo_read_n:
  211|  75.0k|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|  75.0k|}
usbd.c:tu_fifo_write_n:
  224|  32.9k|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|  32.9k|}

usbd.c:tu_edpt_number:
  580|  8.29k|TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_edpt_number(uint8_t addr) {
  581|  8.29k|  return (uint8_t) (addr & TUSB_EPNUM_MASK);
  582|  8.29k|}
usbd.c:tu_edpt_dir:
  575|  8.07k|TU_ATTR_ALWAYS_INLINE static inline tusb_dir_t tu_edpt_dir(uint8_t addr) {
  576|  8.07k|  return (addr & TUSB_DIR_IN_MASK) ? TUSB_DIR_IN : TUSB_DIR_OUT;
  ------------------
  |  Branch (576:10): [True: 3.95k, False: 4.11k]
  ------------------
  577|  8.07k|}
dcd_fuzz.cc:_ZL12tu_edpt_addrhh:
  584|    217|TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_edpt_addr(uint8_t num, uint8_t dir) {
  585|    217|  return (uint8_t) (num | (dir == (uint8_t)TUSB_DIR_IN ? (uint8_t)TUSB_DIR_IN_MASK : 0u));
  ------------------
  |  Branch (585:28): [True: 217, False: 0]
  ------------------
  586|    217|}
dcd_fuzz.cc:_ZL11tu_edpt_dirh:
  575|  5.65k|TU_ATTR_ALWAYS_INLINE static inline tusb_dir_t tu_edpt_dir(uint8_t addr) {
  576|  5.65k|  return (addr & TUSB_DIR_IN_MASK) ? TUSB_DIR_IN : TUSB_DIR_OUT;
  ------------------
  |  Branch (576:10): [True: 3.86k, False: 1.78k]
  ------------------
  577|  5.65k|}

dcd_fuzz.cc:_ZL20dcd_event_bus_signalh13dcd_eventid_tb:
  200|  10.0k|TU_ATTR_ALWAYS_INLINE static inline void dcd_event_bus_signal (uint8_t rhport, dcd_eventid_t eid, bool in_isr) {
  201|  10.0k|  dcd_event_t event;
  202|  10.0k|  event.rhport = rhport;
  203|  10.0k|  event.event_id = eid;
  204|  10.0k|  dcd_event_handler(&event, in_isr);
  205|  10.0k|}
dcd_fuzz.cc:_ZL19dcd_event_bus_reseth12tusb_speed_tb:
  208|  8.84k|TU_ATTR_ALWAYS_INLINE static inline  void dcd_event_bus_reset (uint8_t rhport, tusb_speed_t speed, bool in_isr) {
  209|  8.84k|  dcd_event_t event;
  210|  8.84k|  event.rhport = rhport;
  211|  8.84k|  event.event_id = DCD_EVENT_BUS_RESET;
  212|  8.84k|  event.bus_reset.speed = speed;
  213|  8.84k|  dcd_event_handler(&event, in_isr);
  214|  8.84k|}
dcd_fuzz.cc:_ZL24dcd_event_setup_receivedhPKhb:
  217|  14.7k|TU_ATTR_ALWAYS_INLINE static inline void dcd_event_setup_received(uint8_t rhport, uint8_t const * setup, bool in_isr) {
  218|  14.7k|  dcd_event_t event;
  219|  14.7k|  event.rhport = rhport;
  220|  14.7k|  event.event_id = DCD_EVENT_SETUP_RECEIVED;
  221|  14.7k|  (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|  14.7k|  event.setup_received.wValue  = tu_le16toh(event.setup_received.wValue);
  ------------------
  |  |  272|  14.7k|  #define tu_le16toh(u16) (u16)
  ------------------
  225|  14.7k|  event.setup_received.wIndex  = tu_le16toh(event.setup_received.wIndex);
  ------------------
  |  |  272|  14.7k|  #define tu_le16toh(u16) (u16)
  ------------------
  226|  14.7k|  event.setup_received.wLength = tu_le16toh(event.setup_received.wLength);
  ------------------
  |  |  272|  14.7k|  #define tu_le16toh(u16) (u16)
  ------------------
  227|  14.7k|  dcd_event_handler(&event, in_isr);
  228|  14.7k|}

tud_event_hook_cb:
   48|  32.9k|TU_ATTR_WEAK void tud_event_hook_cb(uint8_t rhport, uint32_t eventid, bool in_isr) {
   49|  32.9k|  (void) rhport; (void) eventid; (void) in_isr;
   50|  32.9k|}
tud_descriptor_bos_cb:
   56|    241|TU_ATTR_WEAK uint8_t const* tud_descriptor_bos_cb(void) {
   57|       |  return NULL;
   58|    241|}
tud_descriptor_device_qualifier_cb:
   60|    207|TU_ATTR_WEAK uint8_t const* tud_descriptor_device_qualifier_cb(void) {
   61|       |  return NULL;
   62|    207|}
tud_descriptor_other_speed_configuration_cb:
   64|    200|TU_ATTR_WEAK uint8_t const* tud_descriptor_other_speed_configuration_cb(uint8_t index) {
   65|    200|  (void) index;
   66|       |  return NULL;
   67|    200|}
tud_umount_cb:
   72|  6.41k|TU_ATTR_WEAK void tud_umount_cb(void) {
   73|  6.41k|}
tud_suspend_cb:
   75|  1.82k|TU_ATTR_WEAK void tud_suspend_cb(bool remote_wakeup_en) {
   76|  1.82k|  (void) remote_wakeup_en;
   77|  1.82k|}
tud_resume_cb:
   79|  1.08k|TU_ATTR_WEAK void tud_resume_cb(void) {
   80|  1.08k|}
tud_vendor_control_xfer_cb:
   82|  1.58k|TU_ATTR_WEAK bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const* request) {
   83|  1.58k|  (void) rhport; (void) stage; (void) request;
   84|       |  return false;
   85|  1.58k|}
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|  43.1k|bool tud_inited(void) {
  531|  43.1k|  return _usbd_rhport != RHPORT_INVALID;
  532|  43.1k|}
tud_rhport_init:
  538|  1.00k|bool tud_rhport_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
  539|  1.00k|  if (tud_inited()) {
  ------------------
  |  Branch (539:7): [True: 1.00k, False: 1]
  ------------------
  540|  1.00k|    return true; // skip if already initialized
  541|  1.00k|  }
  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|  42.1k|void tud_task_ext(uint32_t timeout_ms, bool in_isr) {
  687|  42.1k|  (void) in_isr; // not implemented yet
  688|       |
  689|       |  // Skip if stack is not initialized
  690|  42.1k|  if (!tud_inited()) {
  ------------------
  |  Branch (690:7): [True: 0, False: 42.1k]
  ------------------
  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|  75.0k|  for (unsigned epr = 0;; epr++) {
  696|  75.0k|#if CFG_TUD_TASK_EVENTS_PER_RUN > 0
  697|  75.0k|    if (epr >= CFG_TUD_TASK_EVENTS_PER_RUN) {
  ------------------
  |  |  599|  75.0k|  #define CFG_TUD_TASK_EVENTS_PER_RUN  16
  ------------------
  |  Branch (697:9): [True: 0, False: 75.0k]
  ------------------
  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|  75.0k|#endif
  702|  75.0k|    dcd_event_t event;
  703|  75.0k|    if (!osal_queue_receive(_usbd_q, &event, timeout_ms)) {
  ------------------
  |  Branch (703:9): [True: 42.1k, False: 32.9k]
  ------------------
  704|  42.1k|      return;
  705|  42.1k|    }
  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|  32.9k|    switch (event.event_id) {
  715|  8.84k|      case DCD_EVENT_BUS_RESET:
  ------------------
  |  Branch (715:7): [True: 8.84k, False: 24.1k]
  ------------------
  716|  8.84k|        TU_LOG_USBD(": %s Speed\r\n", tu_str_speed[event.bus_reset.speed]);
  717|  8.84k|        usbd_reset(event.rhport);
  718|  8.84k|        _usbd_dev.speed = event.bus_reset.speed;
  719|  8.84k|        break;
  720|       |
  721|  6.41k|      case DCD_EVENT_UNPLUGGED:
  ------------------
  |  Branch (721:7): [True: 6.41k, False: 26.5k]
  ------------------
  722|  6.41k|        TU_LOG_USBD("\r\n");
  723|  6.41k|        usbd_reset(event.rhport);
  724|  6.41k|        tud_umount_cb();
  725|  6.41k|        break;
  726|       |
  727|  14.7k|      case DCD_EVENT_SETUP_RECEIVED:
  ------------------
  |  Branch (727:7): [True: 14.7k, False: 18.1k]
  ------------------
  728|  14.7k|        if (_usbd_queued_setup == 0) {
  ------------------
  |  Branch (728:13): [True: 0, False: 14.7k]
  ------------------
  729|      0|          break;
  730|      0|        }
  731|  14.7k|        _usbd_queued_setup--;
  732|  14.7k|        TU_LOG_BUF(CFG_TUD_LOG_LEVEL, &event.setup_received, 8);
  733|  14.7k|        if (_usbd_queued_setup != 0) {
  ------------------
  |  Branch (733:13): [True: 0, False: 14.7k]
  ------------------
  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|  14.7k|        _usbd_dev.connected = 1;
  741|       |
  742|       |        // reset ep state
  743|  14.7k|        _usbd_dev.ep_status[0][TUSB_DIR_OUT] = 0;
  744|  14.7k|        _usbd_dev.ep_status[0][TUSB_DIR_IN] = 0;
  745|       |
  746|       |        // Process control request
  747|  14.7k|        if (!process_setup_received(event.rhport, &event.setup_received)) {
  ------------------
  |  Branch (747:13): [True: 8.95k, False: 5.82k]
  ------------------
  748|  8.95k|          TU_LOG_USBD("  Stall EP0\r\n");
  749|       |          // Failed -> stall both control endpoint IN and OUT
  750|  8.95k|          dcd_edpt_stall(event.rhport, TU_EP0_OUT);
  751|  8.95k|          dcd_edpt_stall(event.rhport, TU_EP0_IN);
  752|  8.95k|        }
  753|  14.7k|        break;
  754|       |
  755|      0|      case DCD_EVENT_XFER_COMPLETE: {
  ------------------
  |  Branch (755:7): [True: 0, False: 32.9k]
  ------------------
  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|  1.82k|      case DCD_EVENT_SUSPEND:
  ------------------
  |  Branch (778:7): [True: 1.82k, False: 31.1k]
  ------------------
  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|  1.82k|        if (_usbd_dev.connected) {
  ------------------
  |  Branch (782:13): [True: 1.82k, False: 0]
  ------------------
  783|  1.82k|          TU_LOG_USBD(": Remote Wakeup = %u\r\n", _usbd_dev.remote_wakeup_en);
  784|  1.82k|          tud_suspend_cb(_usbd_dev.remote_wakeup_en);
  785|  1.82k|        } else {
  786|      0|          TU_LOG_USBD(" Skipped\r\n");
  787|      0|        }
  788|  1.82k|        break;
  789|       |
  790|  1.08k|      case DCD_EVENT_RESUME:
  ------------------
  |  Branch (790:7): [True: 1.08k, False: 31.8k]
  ------------------
  791|  1.08k|        if (_usbd_dev.connected) {
  ------------------
  |  Branch (791:13): [True: 1.08k, False: 0]
  ------------------
  792|  1.08k|          TU_LOG_USBD("\r\n");
  793|  1.08k|          tud_resume_cb();
  794|  1.08k|        } else {
  795|      0|          TU_LOG_USBD(" Skipped\r\n");
  796|      0|        }
  797|  1.08k|        break;
  798|       |
  799|      0|      case USBD_EVENT_FUNC_CALL:
  ------------------
  |  Branch (799:7): [True: 0, False: 32.9k]
  ------------------
  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: 32.9k]
  ------------------
  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: 32.9k]
  ------------------
  814|      0|        TU_BREAKPOINT();
  ------------------
  |  |   96|      0|  #define TU_BREAKPOINT() do {} while (0)
  |  |  ------------------
  |  |  |  Branch (96:40): [Folded, False: 0]
  |  |  ------------------
  ------------------
  815|      0|        break;
  816|  32.9k|    }
  817|       |
  818|       |    // allow to exit tud_task() if there is no event in the next run
  819|  32.9k|    timeout_ms = 0;
  820|  32.9k|  }
  821|  42.1k|}
tud_control_status:
  867|  2.32k|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.32k|  (void) request;
  870|  2.32k|  return status_stage_xact(rhport, status_stage_ep(&_usbd_dev.ctrl_xfer.request));
  871|  2.32k|}
tud_control_xfer:
  874|  3.10k|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.10k|  (void) request;
  877|  3.10k|  usbd_control_xfer_t* const ctrl_xfer = &_usbd_dev.ctrl_xfer;
  878|  3.10k|  ctrl_xfer->buffer = (uint8_t*) buffer;
  879|  3.10k|  ctrl_xfer->data_len = tu_min16(len, ctrl_xfer->request.wLength);
  880|       |
  881|  3.10k|  if (ctrl_xfer->request.wLength > 0U) {
  ------------------
  |  Branch (881:7): [True: 2.23k, False: 873]
  ------------------
  882|  2.23k|    if (ctrl_xfer->data_len > 0U) {
  ------------------
  |  Branch (882:9): [True: 2.23k, False: 0]
  ------------------
  883|  2.23k|      TU_ASSERT(buffer);
  ------------------
  |  |  131|  2.23k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|  2.23k|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|  2.23k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  127|  2.23k|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|  2.23k|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|  2.23k|    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.23k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|  2.23k|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 2.23k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  884|  2.23k|    }
  885|  2.23k|    TU_ASSERT(data_stage_xact(rhport));
  ------------------
  |  |  131|  2.23k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|  2.23k|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|  2.23k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  127|  2.23k|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|  2.23k|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|  2.23k|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   73|  1.15k|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (73:41): [Folded, False: 1.15k]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   96|  1.15k|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (96:40): [Folded, False: 1.15k]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (124:10): [True: 1.15k, False: 1.07k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|  2.23k|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 1.07k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  886|  2.23k|  } else {
  887|       |    // wLength == 0: Status stage is always IN per USB 2.0 §9.3.1
  888|    873|    TU_ASSERT(status_stage_xact(rhport, TU_EP0_IN));
  ------------------
  |  |  131|    873|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    873|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|    873|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  127|    873|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|    873|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|    873|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   73|    429|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (73:41): [Folded, False: 429]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   96|    429|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (96:40): [Folded, False: 429]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (124:10): [True: 429, False: 444]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|    873|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 444]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  889|    873|  }
  890|       |
  891|  1.51k|  return true;
  892|  3.10k|}
dcd_event_handler:
 1387|  33.6k|TU_ATTR_FAST_FUNC void dcd_event_handler(dcd_event_t const* event, bool in_isr) {
 1388|  33.6k|  bool send = false;
 1389|  33.6k|  switch (event->event_id) {
 1390|  6.41k|    case DCD_EVENT_UNPLUGGED:
  ------------------
  |  Branch (1390:5): [True: 6.41k, False: 27.2k]
  ------------------
 1391|  6.41k|      _usbd_dev.connected = 0;
 1392|  6.41k|      _usbd_dev.addressed = 0;
 1393|  6.41k|      _usbd_dev.cfg_num = 0;
 1394|  6.41k|      _usbd_dev.suspended = 0;
 1395|  6.41k|      send = true;
 1396|  6.41k|      break;
 1397|       |
 1398|  2.19k|    case DCD_EVENT_SUSPEND:
  ------------------
  |  Branch (1398:5): [True: 2.19k, False: 31.4k]
  ------------------
 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.19k|      if (_usbd_dev.connected) {
  ------------------
  |  Branch (1403:11): [True: 1.82k, False: 367]
  ------------------
 1404|  1.82k|        _usbd_dev.suspended = 1;
 1405|  1.82k|        send = true;
 1406|  1.82k|      }
 1407|  2.19k|      break;
 1408|       |
 1409|  1.40k|    case DCD_EVENT_RESUME:
  ------------------
  |  Branch (1409:5): [True: 1.40k, False: 32.2k]
  ------------------
 1410|       |      // skip event if not connected (especially required for SAMD)
 1411|  1.40k|      if (_usbd_dev.connected) {
  ------------------
  |  Branch (1411:11): [True: 1.08k, False: 312]
  ------------------
 1412|  1.08k|        _usbd_dev.suspended = 0;
 1413|  1.08k|        send = true;
 1414|  1.08k|      }
 1415|  1.40k|      break;
 1416|       |
 1417|      0|    case DCD_EVENT_SOF:
  ------------------
  |  Branch (1417:5): [True: 0, False: 33.6k]
  ------------------
 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|  14.7k|    case DCD_EVENT_SETUP_RECEIVED:
  ------------------
  |  Branch (1441:5): [True: 14.7k, False: 18.8k]
  ------------------
 1442|  14.7k|      _usbd_queued_setup++;
 1443|  14.7k|      send = true;
 1444|  14.7k|      break;
 1445|       |
 1446|      0|    case DCD_EVENT_XFER_COMPLETE: {
  ------------------
  |  Branch (1446:5): [True: 0, False: 33.6k]
  ------------------
 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|  8.84k|    default:
  ------------------
  |  Branch (1472:5): [True: 8.84k, False: 24.7k]
  ------------------
 1473|  8.84k|      send = true;
 1474|  8.84k|      break;
 1475|  33.6k|  }
 1476|       |
 1477|  33.6k|  if (send) {
  ------------------
  |  Branch (1477:7): [True: 32.9k, False: 679]
  ------------------
 1478|  32.9k|    queue_event(event, in_isr);
 1479|  32.9k|  }
 1480|  33.6k|}
usbd_int_set:
 1486|   172k|void usbd_int_set(bool enabled) {
 1487|   172k|  if (enabled) {
  ------------------
  |  Branch (1487:7): [True: 86.4k, False: 86.4k]
  ------------------
 1488|  86.4k|    dcd_int_enable(_usbd_rhport);
 1489|  86.4k|  } else {
 1490|  86.4k|    dcd_int_disable(_usbd_rhport);
 1491|  86.4k|  }
 1492|   172k|}
usbd_open_edpt_pair:
 1503|    213|                         uint8_t *ep_in) {
 1504|    213|  for (int i = 0; i < ep_count; i++) {
  ------------------
  |  Branch (1504:19): [True: 213, False: 0]
  ------------------
 1505|    213|    const tusb_desc_endpoint_t *desc_ep = (const tusb_desc_endpoint_t *)p_desc;
 1506|       |
 1507|    213|    TU_ASSERT(TUSB_DESC_ENDPOINT == desc_ep->bDescriptorType && xfer_type == desc_ep->bmAttributes.xfer);
  ------------------
  |  |  131|    213|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    213|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|    213|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  127|    213|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|    213|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|    426|    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: 213, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  Branch (124:12): [True: 213, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|    213|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 213]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1508|    213|    TU_ASSERT(usbd_edpt_open(rhport, desc_ep));
  ------------------
  |  |  131|    213|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    213|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|    213|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  127|    213|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|    213|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|    213|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   73|    213|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (73:41): [Folded, False: 213]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   96|    213|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (96:40): [Folded, False: 213]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (124:10): [True: 213, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|    213|  } 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|    213|}
usbd_edpt_open:
 1538|    213|bool usbd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const* desc_ep) {
 1539|    213|  rhport = _usbd_rhport;
 1540|       |
 1541|    213|  TU_ASSERT(tu_edpt_number(desc_ep->bEndpointAddress) < CFG_TUD_ENDPPOINT_MAX);
  ------------------
  |  |  131|    213|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    213|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|    213|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  127|    213|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|    213|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|    213|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   73|    213|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (73:41): [Folded, False: 213]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   96|    213|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (96:40): [Folded, False: 213]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (124:10): [True: 213, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|    213|  } 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.43k|bool usbd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t* buffer, uint16_t total_bytes, bool is_isr) {
 1567|  5.43k|  rhport = _usbd_rhport;
 1568|       |
 1569|  5.43k|  uint8_t const epnum = tu_edpt_number(ep_addr);
 1570|  5.43k|  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.43k|  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.43k|  TU_ASSERT((_usbd_dev.ep_status[epnum][dir] & TU_EDPT_STATE_BUSY) == 0);
  ------------------
  |  |  131|  5.43k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|  5.43k|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|  5.43k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  127|  5.43k|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|  5.43k|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|  5.43k|    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.43k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|  5.43k|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 5.43k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 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.43k|  _usbd_dev.ep_status[epnum][dir] |= TU_EDPT_STATE_BUSY;
  ------------------
  |  |   50|  5.43k|#define TU_EDPT_STATE_BUSY    0x01u
  ------------------
 1588|       |
 1589|  5.43k|  if (dcd_edpt_xfer(rhport, ep_addr, buffer, total_bytes, is_isr)) {
  ------------------
  |  Branch (1589:7): [True: 2.69k, False: 2.74k]
  ------------------
 1590|  2.69k|    return true;
 1591|  2.74k|  } else {
 1592|       |    // DCD error, mark endpoint as ready to allow next transfer
 1593|  2.74k|    _usbd_dev.ep_status[epnum][dir] &= (uint8_t) ~(TU_EDPT_STATE_BUSY | TU_EDPT_STATE_CLAIMED);
  ------------------
  |  |   50|  2.74k|#define TU_EDPT_STATE_BUSY    0x01u
  ------------------
                  _usbd_dev.ep_status[epnum][dir] &= (uint8_t) ~(TU_EDPT_STATE_BUSY | TU_EDPT_STATE_CLAIMED);
  ------------------
  |  |   52|  2.74k|#define TU_EDPT_STATE_CLAIMED 0x04u
  ------------------
 1594|  2.74k|    TU_LOG_USBD("FAILED\r\n");
 1595|  2.74k|    TU_BREAKPOINT();
  ------------------
  |  |   96|  2.74k|  #define TU_BREAKPOINT() do {} while (0)
  |  |  ------------------
  |  |  |  Branch (96:40): [Folded, False: 2.74k]
  |  |  ------------------
  ------------------
 1596|       |    return false;
 1597|  2.74k|  }
 1598|  5.43k|}
usbd_edpt_stall:
 1649|    203|void usbd_edpt_stall(uint8_t rhport, uint8_t ep_addr) {
 1650|    203|  rhport = _usbd_rhport;
 1651|       |
 1652|    203|  uint8_t const epnum = tu_edpt_number(ep_addr);
 1653|    203|  uint8_t const dir = tu_edpt_dir(ep_addr);
 1654|       |
 1655|       |  // only stalled if currently cleared
 1656|    203|  TU_LOG_USBD("    Stall EP %02X\r\n", ep_addr);
 1657|    203|  dcd_edpt_stall(rhport, ep_addr);
 1658|    203|  _usbd_dev.ep_status[epnum][dir] |= (TU_EDPT_STATE_STALLED | TU_EDPT_STATE_BUSY);
  ------------------
  |  |   51|    203|#define TU_EDPT_STATE_STALLED 0x02u
  ------------------
                _usbd_dev.ep_status[epnum][dir] |= (TU_EDPT_STATE_STALLED | TU_EDPT_STATE_BUSY);
  ------------------
  |  |   50|    203|#define TU_EDPT_STATE_BUSY    0x01u
  ------------------
 1659|    203|}
usbd_edpt_clear_stall:
 1661|    219|void usbd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr) {
 1662|    219|  rhport = _usbd_rhport;
 1663|       |
 1664|    219|  uint8_t const epnum = tu_edpt_number(ep_addr);
 1665|    219|  uint8_t const dir = tu_edpt_dir(ep_addr);
 1666|       |
 1667|       |  // only clear if currently stalled
 1668|    219|  TU_LOG_USBD("    Clear Stall EP %02X\r\n", ep_addr);
 1669|    219|  dcd_edpt_clear_stall(rhport, ep_addr);
 1670|    219|  _usbd_dev.ep_status[epnum][dir] &= (uint8_t) ~(TU_EDPT_STATE_STALLED | TU_EDPT_STATE_BUSY);
  ------------------
  |  |   51|    219|#define TU_EDPT_STATE_STALLED 0x02u
  ------------------
                _usbd_dev.ep_status[epnum][dir] &= (uint8_t) ~(TU_EDPT_STATE_STALLED | TU_EDPT_STATE_BUSY);
  ------------------
  |  |   50|    219|#define TU_EDPT_STATE_BUSY    0x01u
  ------------------
 1671|    219|}
usbd_edpt_stalled:
 1673|    232|bool usbd_edpt_stalled(uint8_t rhport, uint8_t ep_addr) {
 1674|    232|  (void) rhport;
 1675|       |
 1676|    232|  uint8_t const epnum = tu_edpt_number(ep_addr);
 1677|    232|  uint8_t const dir = tu_edpt_dir(ep_addr);
 1678|       |
 1679|    232|  return (_usbd_dev.ep_status[epnum][dir] & TU_EDPT_STATE_STALLED) != 0;
  ------------------
  |  |   51|    232|#define TU_EDPT_STATE_STALLED 0x02u
  ------------------
 1680|    232|}
usbd.c:get_driver:
  393|  17.8k|TU_ATTR_ALWAYS_INLINE static inline usbd_class_driver_t const * get_driver(uint8_t drvid) {
  394|  17.8k|  usbd_class_driver_t const *driver = NULL;
  395|  17.8k|  if (drvid < _app_driver_count) {
  ------------------
  |  Branch (395:7): [True: 0, False: 17.8k]
  ------------------
  396|       |    // Application drivers
  397|      0|    driver = &_app_driver[drvid];
  398|  17.8k|  } else{
  399|  17.8k|    drvid -= _app_driver_count;
  400|  17.8k|    if (drvid < BUILTIN_DRIVER_COUNT) {
  ------------------
  |  Branch (400:9): [True: 15.4k, False: 2.39k]
  ------------------
  401|  15.4k|      driver = &_usbd_driver[drvid];
  402|  15.4k|    }
  403|  17.8k|  }
  404|       |
  405|  17.8k|  return driver;
  406|  17.8k|}
usbd.c:usbd_reset:
  660|  15.2k|static void usbd_reset(uint8_t rhport) {
  661|  15.2k|  configuration_reset(rhport);
  662|  15.2k|}
usbd.c:configuration_reset:
  648|  15.2k|static void configuration_reset(uint8_t rhport) {
  649|  30.5k|  for (uint8_t i = 0; i < TOTAL_DRIVER_COUNT; i++) {
  ------------------
  |  |  389|  30.5k|#define TOTAL_DRIVER_COUNT    ((uint8_t) (_app_driver_count + BUILTIN_DRIVER_COUNT))
  ------------------
  |  Branch (649:23): [True: 15.2k, False: 15.2k]
  ------------------
  650|  15.2k|    usbd_class_driver_t const* driver = get_driver(i);
  651|  15.2k|    TU_ASSERT(driver,);
  ------------------
  |  |  131|  15.2k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|  15.2k|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|  15.2k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  128|  15.2k|#define TU_ASSERT_2ARGS(_cond, _ret)   TU_ASSERT_DEFINE(_cond, _ret)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|  15.2k|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|  15.2k|    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.2k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|  15.2k|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 15.2k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  652|  15.2k|    driver->reset(rhport);
  653|  15.2k|  }
  654|       |
  655|  15.2k|  tu_varclr(&_usbd_dev);
  ------------------
  |  |  115|  15.2k|#define tu_varclr(_var)          tu_memclr(_var, sizeof(*(_var)))
  |  |  ------------------
  |  |  |  |  114|  15.2k|#define tu_memclr(buffer, size)  (void) memset((buffer), 0, (size))
  |  |  ------------------
  ------------------
  656|  15.2k|  (void)memset(_usbd_dev.itf2drv, TUSB_INDEX_INVALID_8, sizeof(_usbd_dev.itf2drv)); // invalid mapping
  657|  15.2k|  (void)memset(_usbd_dev.ep2drv, TUSB_INDEX_INVALID_8, sizeof(_usbd_dev.ep2drv));   // invalid mapping
  658|  15.2k|}
usbd.c:status_stage_xact:
  845|  3.20k|TU_ATTR_ALWAYS_INLINE static inline bool status_stage_xact(uint8_t rhport, uint8_t ep_status) {
  846|  3.20k|  return usbd_edpt_xfer(rhport, ep_status, NULL, 0, false);
  847|  3.20k|}
usbd.c:status_stage_ep:
  840|  2.32k|TU_ATTR_ALWAYS_INLINE static inline uint8_t status_stage_ep(const tusb_control_request_t* request) {
  841|  2.32k|  return (request->wLength != 0 && request->bmRequestType_bit.direction) ? TU_EP0_OUT : TU_EP0_IN;
  ------------------
  |  Branch (841:11): [True: 1.36k, False: 967]
  |  Branch (841:36): [True: 42, False: 1.31k]
  ------------------
  842|  2.32k|}
usbd.c:data_stage_xact:
  851|  2.23k|static bool data_stage_xact(uint8_t rhport) {
  852|  2.23k|  usbd_control_xfer_t* const ctrl_xfer = &_usbd_dev.ctrl_xfer;
  853|  2.23k|  const uint16_t xact_len = tu_min16(ctrl_xfer->data_len - ctrl_xfer->total_xferred, CFG_TUD_ENDPOINT0_BUFSIZE);
  ------------------
  |  |  590|  2.23k|  #define CFG_TUD_ENDPOINT0_BUFSIZE  CFG_TUD_ENDPOINT0_SIZE
  |  |  ------------------
  |  |  |  |   90|  2.23k|#define CFG_TUD_ENDPOINT0_SIZE    64
  |  |  ------------------
  ------------------
  854|  2.23k|  uint8_t ep_addr = TU_EP0_OUT;
  855|       |
  856|  2.23k|  if (ctrl_xfer->request.bmRequestType_bit.direction == TUSB_DIR_IN) {
  ------------------
  |  Branch (856:7): [True: 491, False: 1.74k]
  ------------------
  857|    491|    ep_addr = TU_EP0_IN;
  858|    491|    if (0u != xact_len && ctrl_xfer->buffer != _ctrl_epbuf.buf) {
  ------------------
  |  Branch (858:9): [True: 491, False: 0]
  |  Branch (858:27): [True: 491, False: 0]
  ------------------
  859|    491|      TU_VERIFY(0 == tu_memcpy_s(_ctrl_epbuf.buf, CFG_TUD_ENDPOINT0_BUFSIZE, ctrl_xfer->buffer, xact_len));
  ------------------
  |  |  114|    491|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    491|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  114|    491|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  111|    491|#define TU_VERIFY_1ARGS(_cond)         TU_VERIFY_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  105|    491|  do {                                \
  |  |  |  |  |  |  |  |  |  |  106|    491|    if (!(_cond)) {                   \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:9): [True: 0, False: 491]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  107|      0|      return _ret;                    \
  |  |  |  |  |  |  |  |  |  |  108|      0|    }                                 \
  |  |  |  |  |  |  |  |  |  |  109|    491|  } while (0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (109:12): [Folded, False: 491]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  860|    491|    }
  861|    491|  }
  862|       |
  863|  2.23k|  return usbd_edpt_xfer(rhport, ep_addr, xact_len ? _ctrl_epbuf.buf : NULL, xact_len, false);
  ------------------
  |  Branch (863:42): [True: 2.23k, False: 0]
  ------------------
  864|  2.23k|}
usbd.c:process_setup_received:
 1074|  14.7k|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|  14.7k|  usbd_control_xfer_t* const ctrl_xfer = &_usbd_dev.ctrl_xfer;
 1079|  14.7k|  ctrl_xfer->request = *p_request;
 1080|  14.7k|  ctrl_xfer->buffer = NULL;
 1081|  14.7k|  ctrl_xfer->total_xferred = 0;
 1082|  14.7k|  ctrl_xfer->data_len = 0;
 1083|  14.7k|  ctrl_xfer->complete_cb = NULL;
 1084|       |
 1085|  14.7k|  p_request = &ctrl_xfer->request; // re-direct request pointer to internal copy (modifiable for hacking)
 1086|  14.7k|  TU_ASSERT(p_request->bmRequestType_bit.type < TUSB_REQ_TYPE_INVALID);
  ------------------
  |  |  131|  14.7k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|  14.7k|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|  14.7k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  127|  14.7k|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|  14.7k|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|  14.7k|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   73|    970|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (73:41): [Folded, False: 970]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   96|    970|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (96:40): [Folded, False: 970]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (124:10): [True: 970, False: 13.8k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|  14.7k|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 13.8k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1087|       |
 1088|       |  // Vendor request
 1089|  13.8k|  if ( p_request->bmRequestType_bit.type == TUSB_REQ_TYPE_VENDOR ) {
  ------------------
  |  Branch (1089:8): [True: 1.58k, False: 12.2k]
  ------------------
 1090|  1.58k|    ctrl_xfer->complete_cb = tud_vendor_control_xfer_cb;
 1091|  1.58k|    return tud_vendor_control_xfer_cb(rhport, CONTROL_STAGE_SETUP, p_request);
 1092|  1.58k|  }
 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.2k|  switch (p_request->bmRequestType_bit.recipient) { //-V2520
 1104|       |    //------------- Device Requests e.g in enumeration -------------//
 1105|  8.07k|    case TUSB_REQ_RCPT_DEVICE:
  ------------------
  |  Branch (1105:5): [True: 8.07k, False: 4.14k]
  ------------------
 1106|  8.07k|      if ( TUSB_REQ_TYPE_CLASS == p_request->bmRequestType_bit.type ) {
  ------------------
  |  Branch (1106:12): [True: 425, False: 7.65k]
  ------------------
 1107|    425|        uint8_t const itf = tu_u16_low(p_request->wIndex);
 1108|    425|        TU_VERIFY(itf < TU_ARRAY_SIZE(_usbd_dev.itf2drv));
  ------------------
  |  |  114|    425|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    425|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  114|    425|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  111|    425|#define TU_VERIFY_1ARGS(_cond)         TU_VERIFY_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  105|    425|  do {                                \
  |  |  |  |  |  |  |  |  |  |  106|    425|    if (!(_cond)) {                   \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:9): [True: 220, False: 205]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  107|    220|      return _ret;                    \
  |  |  |  |  |  |  |  |  |  |  108|    220|    }                                 \
  |  |  |  |  |  |  |  |  |  |  109|    425|  } while (0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (109:12): [Folded, False: 205]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1109|       |
 1110|    205|        usbd_class_driver_t const * driver = get_driver(_usbd_dev.itf2drv[itf]);
 1111|    205|        TU_VERIFY(driver);
  ------------------
  |  |  114|    205|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    205|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  114|    205|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  111|    205|#define TU_VERIFY_1ARGS(_cond)         TU_VERIFY_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  105|    205|  do {                                \
  |  |  |  |  |  |  |  |  |  |  106|    205|    if (!(_cond)) {                   \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:9): [True: 205, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  107|    205|      return _ret;                    \
  |  |  |  |  |  |  |  |  |  |  108|    205|    }                                 \
  |  |  |  |  |  |  |  |  |  |  109|    205|  } 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|    205|      }
 1116|       |
 1117|  7.65k|      if (TUSB_REQ_TYPE_STANDARD != p_request->bmRequestType_bit.type) {
  ------------------
  |  Branch (1117:11): [True: 0, False: 7.65k]
  ------------------
 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|  7.65k|      return process_std_device_request(rhport, p_request);
 1124|       |
 1125|       |    //------------- Class/Interface Specific Request -------------//
 1126|    716|    case TUSB_REQ_RCPT_INTERFACE: {
  ------------------
  |  Branch (1126:5): [True: 716, False: 11.5k]
  ------------------
 1127|    716|      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|    716|      itf = tu_u16_low(p_request->wIndex);
 1146|    716|      TU_VERIFY(itf < TU_ARRAY_SIZE(_usbd_dev.itf2drv));
  ------------------
  |  |  114|    716|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    716|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  114|    716|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  111|    716|#define TU_VERIFY_1ARGS(_cond)         TU_VERIFY_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  105|    716|  do {                                \
  |  |  |  |  |  |  |  |  |  |  106|    716|    if (!(_cond)) {                   \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:9): [True: 296, False: 420]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  107|    296|      return _ret;                    \
  |  |  |  |  |  |  |  |  |  |  108|    296|    }                                 \
  |  |  |  |  |  |  |  |  |  |  109|    716|  } while (0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (109:12): [Folded, False: 420]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1147|       |
 1148|    420|      usbd_class_driver_t const * driver = get_driver(_usbd_dev.itf2drv[itf]);
 1149|    420|      TU_VERIFY(driver);
  ------------------
  |  |  114|    420|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    420|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  114|    420|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  111|    420|#define TU_VERIFY_1ARGS(_cond)         TU_VERIFY_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  105|    420|  do {                                \
  |  |  |  |  |  |  |  |  |  |  106|    420|    if (!(_cond)) {                   \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:9): [True: 420, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  107|    420|      return _ret;                    \
  |  |  |  |  |  |  |  |  |  |  108|    420|    }                                 \
  |  |  |  |  |  |  |  |  |  |  109|    420|  } 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.99k|    case TUSB_REQ_RCPT_ENDPOINT: {
  ------------------
  |  Branch (1179:5): [True: 1.99k, False: 10.2k]
  ------------------
 1180|  1.99k|      uint8_t const ep_addr = tu_u16_low(p_request->wIndex);
 1181|  1.99k|      uint8_t const ep_num  = tu_edpt_number(ep_addr);
 1182|  1.99k|      uint8_t const ep_dir  = tu_edpt_dir(ep_addr);
 1183|       |
 1184|  1.99k|      TU_ASSERT(ep_num < TU_ARRAY_SIZE(_usbd_dev.ep2drv) );
  ------------------
  |  |  131|  1.99k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|  1.99k|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|  1.99k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  127|  1.99k|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|  1.99k|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|  1.99k|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   73|    220|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (73:41): [Folded, False: 220]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   96|    220|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (96:40): [Folded, False: 220]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (124:10): [True: 220, False: 1.77k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|  1.99k|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 1.77k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1185|  1.77k|      usbd_class_driver_t const * driver = get_driver(_usbd_dev.ep2drv[ep_num][ep_dir]);
 1186|       |
 1187|  1.77k|      if (TUSB_REQ_TYPE_STANDARD != p_request->bmRequestType_bit.type) {
  ------------------
  |  Branch (1187:11): [True: 199, False: 1.57k]
  ------------------
 1188|       |        // Forward class request to its driver
 1189|    199|        TU_VERIFY(driver);
  ------------------
  |  |  114|    199|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    199|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  114|    199|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  111|    199|#define TU_VERIFY_1ARGS(_cond)         TU_VERIFY_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  105|    199|  do {                                \
  |  |  |  |  |  |  |  |  |  |  106|    199|    if (!(_cond)) {                   \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:9): [True: 199, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  107|    199|      return _ret;                    \
  |  |  |  |  |  |  |  |  |  |  108|    199|    }                                 \
  |  |  |  |  |  |  |  |  |  |  109|    199|  } while (0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (109:12): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1190|      0|        return invoke_class_control(rhport, driver, p_request);
 1191|  1.57k|      } else {
 1192|       |        // Handle STD request to endpoint
 1193|  1.57k|        switch (p_request->bRequest) { //-V2520
 1194|    232|          case TUSB_REQ_GET_STATUS: {
  ------------------
  |  Branch (1194:11): [True: 232, False: 1.33k]
  ------------------
 1195|    232|            uint16_t status = usbd_edpt_stalled(rhport, ep_addr) ? 0x0001u : 0x0000u;
  ------------------
  |  Branch (1195:31): [True: 0, False: 232]
  ------------------
 1196|    232|            tud_control_xfer(rhport, p_request, &status, 2);
 1197|    232|          }
 1198|    232|          break;
 1199|       |
 1200|    434|          case TUSB_REQ_CLEAR_FEATURE:
  ------------------
  |  Branch (1200:11): [True: 434, False: 1.13k]
  ------------------
 1201|    815|          case TUSB_REQ_SET_FEATURE: {
  ------------------
  |  Branch (1201:11): [True: 381, False: 1.19k]
  ------------------
 1202|    815|            if ( TUSB_REQ_FEATURE_EDPT_HALT == p_request->wValue ) {
  ------------------
  |  Branch (1202:18): [True: 422, False: 393]
  ------------------
 1203|    422|              if ( TUSB_REQ_CLEAR_FEATURE ==  p_request->bRequest ) {
  ------------------
  |  Branch (1203:20): [True: 219, False: 203]
  ------------------
 1204|    219|                usbd_edpt_clear_stall(rhport, ep_addr);
 1205|    219|              }else {
 1206|    203|                usbd_edpt_stall(rhport, ep_addr);
 1207|    203|              }
 1208|    422|            }
 1209|       |
 1210|    815|            if (driver != NULL) {
  ------------------
  |  Branch (1210:17): [True: 0, False: 815]
  ------------------
 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|    815|          }
 1225|    815|          break;
 1226|       |
 1227|       |          // Unknown/Unsupported request
 1228|    524|          default:
  ------------------
  |  Branch (1228:11): [True: 524, False: 1.04k]
  ------------------
 1229|    524|            TU_BREAKPOINT();
  ------------------
  |  |   96|    524|  #define TU_BREAKPOINT() do {} while (0)
  |  |  ------------------
  |  |  |  Branch (96:40): [Folded, False: 524]
  |  |  ------------------
  ------------------
 1230|    524|            return false;
 1231|  1.57k|        }
 1232|  1.57k|      }
 1233|  1.04k|      break;
 1234|  1.77k|    }
 1235|       |
 1236|       |    // Unknown recipient
 1237|  1.44k|    default:
  ------------------
  |  Branch (1237:5): [True: 1.44k, False: 10.7k]
  ------------------
 1238|  1.44k|      TU_BREAKPOINT();
  ------------------
  |  |   96|  1.44k|  #define TU_BREAKPOINT() do {} while (0)
  |  |  ------------------
  |  |  |  Branch (96:40): [Folded, False: 1.44k]
  |  |  ------------------
  ------------------
 1239|  1.44k|      return false;
 1240|  12.2k|  }
 1241|       |
 1242|  1.04k|  return true;
 1243|  12.2k|}
usbd.c:process_std_device_request:
  963|  7.65k|static bool process_std_device_request(uint8_t rhport, tusb_control_request_t const * p_request) {
  964|  7.65k|  switch (p_request->bRequest) { //-V2520
  965|    217|    case TUSB_REQ_SET_ADDRESS:
  ------------------
  |  Branch (965:5): [True: 217, False: 7.43k]
  ------------------
  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|    217|      dcd_set_address(rhport, (uint8_t) p_request->wValue);
  970|    217|      _usbd_dev.addressed = 1;
  971|    217|      return true;
  972|       |
  973|    388|    case TUSB_REQ_GET_CONFIGURATION: {
  ------------------
  |  Branch (973:5): [True: 388, False: 7.26k]
  ------------------
  974|    388|      uint8_t cfg_num = _usbd_dev.cfg_num;
  975|    388|      tud_control_xfer(rhport, p_request, &cfg_num, 1);
  976|    388|      return true;
  977|      0|    }
  978|       |
  979|  1.02k|    case TUSB_REQ_SET_CONFIGURATION: {
  ------------------
  |  Branch (979:5): [True: 1.02k, False: 6.62k]
  ------------------
  980|  1.02k|      uint8_t const cfg_num = (uint8_t) p_request->wValue;
  981|       |
  982|       |      // Only process if new configure is different
  983|  1.02k|      if (_usbd_dev.cfg_num != cfg_num) {
  ------------------
  |  Branch (983:11): [True: 213, False: 812]
  ------------------
  984|    213|        if (_usbd_dev.cfg_num != 0) {
  ------------------
  |  Branch (984:13): [True: 0, False: 213]
  ------------------
  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|    213|        _usbd_dev.cfg_num = cfg_num;
  999|       |
 1000|       |        // Handle the new configuration
 1001|    213|        if (cfg_num == 0) {
  ------------------
  |  Branch (1001:13): [True: 0, False: 213]
  ------------------
 1002|      0|          tud_umount_cb();
 1003|    213|        } else {
 1004|    213|          if (!process_set_config(rhport, cfg_num)) {
  ------------------
  |  Branch (1004:15): [True: 213, False: 0]
  ------------------
 1005|    213|            _usbd_dev.cfg_num = 0;
 1006|    213|            TU_ASSERT(false);
  ------------------
  |  |  131|    213|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    213|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|    213|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  127|    213|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|    213|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|    213|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   73|    213|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (73:41): [Folded, False: 213]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   96|    213|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (96:40): [Folded, False: 213]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (124:10): [True: 213, Folded]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|    213|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1007|    213|          }
 1008|      0|          tud_mount_cb();
 1009|      0|        }
 1010|    213|      }
 1011|       |
 1012|    812|      tud_control_status(rhport, p_request);
 1013|    812|      return true;
 1014|  1.02k|    }
 1015|       |
 1016|  2.34k|    case TUSB_REQ_GET_DESCRIPTOR:
  ------------------
  |  Branch (1016:5): [True: 2.34k, False: 5.30k]
  ------------------
 1017|  2.34k|      return process_get_descriptor(rhport, p_request);
 1018|       |
 1019|  1.03k|    case TUSB_REQ_SET_FEATURE:
  ------------------
  |  Branch (1019:5): [True: 1.03k, False: 6.61k]
  ------------------
 1020|  1.03k|      switch (p_request->wValue) { //-V2520
 1021|    810|        case TUSB_REQ_FEATURE_REMOTE_WAKEUP:
  ------------------
  |  Branch (1021:9): [True: 810, False: 229]
  ------------------
 1022|    810|          TU_LOG_USBD("    Enable Remote Wakeup\r\n");
 1023|       |          // Host may enable remote wake up before suspending especially HID device
 1024|    810|          _usbd_dev.remote_wakeup_en = 1;
 1025|    810|          tud_control_status(rhport, p_request);
 1026|    810|          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|    229|        default: return false;
  ------------------
  |  Branch (1043:9): [True: 229, False: 810]
  ------------------
 1044|  1.03k|      }
 1045|       |
 1046|  1.01k|    case TUSB_REQ_CLEAR_FEATURE:
  ------------------
  |  Branch (1046:5): [True: 1.01k, False: 6.63k]
  ------------------
 1047|       |      // Only support remote wakeup for device feature
 1048|  1.01k|      TU_VERIFY(TUSB_REQ_FEATURE_REMOTE_WAKEUP == p_request->wValue);
  ------------------
  |  |  114|  1.01k|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|  1.01k|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  114|  1.01k|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  111|  1.01k|#define TU_VERIFY_1ARGS(_cond)         TU_VERIFY_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  105|  1.01k|  do {                                \
  |  |  |  |  |  |  |  |  |  |  106|  1.01k|    if (!(_cond)) {                   \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:9): [True: 308, False: 705]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  107|    308|      return _ret;                    \
  |  |  |  |  |  |  |  |  |  |  108|    308|    }                                 \
  |  |  |  |  |  |  |  |  |  |  109|  1.01k|  } while (0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (109:12): [Folded, False: 705]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1049|    705|      TU_LOG_USBD("    Disable Remote Wakeup\r\n");
 1050|       |
 1051|       |      // Host may disable remote wake up after resuming
 1052|    705|      _usbd_dev.remote_wakeup_en = 0;
 1053|    705|      tud_control_status(rhport, p_request);
 1054|    705|      return true;
 1055|       |
 1056|  1.24k|    case TUSB_REQ_GET_STATUS: {
  ------------------
  |  Branch (1056:5): [True: 1.24k, False: 6.40k]
  ------------------
 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.24k|      uint16_t status = (uint16_t) _usbd_dev.dev_state_bm;
 1061|  1.24k|      tud_control_xfer(rhport, p_request, &status, 2);
 1062|  1.24k|      return true;
 1063|  1.01k|    }
 1064|       |
 1065|    374|    default:
  ------------------
  |  Branch (1065:5): [True: 374, False: 7.27k]
  ------------------
 1066|    374|      TU_BREAKPOINT();
  ------------------
  |  |   96|    374|  #define TU_BREAKPOINT() do {} while (0)
  |  |  ------------------
  |  |  |  Branch (96:40): [Folded, False: 374]
  |  |  ------------------
  ------------------
 1067|       |      return false;
 1068|  7.65k|  }
 1069|  7.65k|}
usbd.c:process_set_config:
 1247|    213|static bool process_set_config(uint8_t rhport, uint8_t cfg_num) {
 1248|       |  // index is cfg_num-1
 1249|    213|  const tusb_desc_configuration_t *desc_cfg =
 1250|    213|    (const tusb_desc_configuration_t *)tud_descriptor_configuration_cb(cfg_num - 1);
 1251|    213|  TU_ASSERT(desc_cfg != NULL && desc_cfg->bDescriptorType == TUSB_DESC_CONFIGURATION);
  ------------------
  |  |  131|    213|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    213|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|    213|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  127|    213|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|    213|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|    426|    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: 213, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  Branch (124:12): [True: 213, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|    213|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 213]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1252|       |
 1253|       |  // Parse configuration descriptor
 1254|    213|  _usbd_dev.self_powered = (desc_cfg->bmAttributes & TUSB_DESC_CONFIG_ATT_SELF_POWERED) ? 1u : 0u;
  ------------------
  |  Branch (1254:28): [True: 0, False: 213]
  ------------------
 1255|       |
 1256|       |  // Parse interface descriptor
 1257|    213|  const uint8_t *p_desc   = ((const uint8_t *)desc_cfg) + sizeof(tusb_desc_configuration_t);
 1258|    213|  const uint8_t *desc_end = ((const uint8_t *)desc_cfg) + tu_le16toh(desc_cfg->wTotalLength);
  ------------------
  |  |  272|    213|  #define tu_le16toh(u16) (u16)
  ------------------
 1259|       |
 1260|    213|  while (tu_desc_in_bounds(p_desc, desc_end)) {
  ------------------
  |  Branch (1260:10): [True: 213, False: 0]
  ------------------
 1261|       |    // Class will always start with Interface Association (if any) and then Interface descriptor
 1262|    213|    if (TUSB_DESC_INTERFACE_ASSOCIATION == tu_desc_type(p_desc)) {
  ------------------
  |  Branch (1262:9): [True: 0, False: 213]
  ------------------
 1263|      0|      p_desc = tu_desc_next(p_desc); // next to Interface
 1264|      0|      continue;
 1265|      0|    }
 1266|       |
 1267|    213|    TU_ASSERT(TUSB_DESC_INTERFACE == tu_desc_type(p_desc));
  ------------------
  |  |  131|    213|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    213|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|    213|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  127|    213|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|    213|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|    213|    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: 213]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|    213|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 213]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1268|    213|    const tusb_desc_interface_t *desc_itf = (const tusb_desc_interface_t *)p_desc;
 1269|       |
 1270|       |    // Find driver for this interface
 1271|    213|    const uint16_t remaining_len = (uint16_t)(desc_end - p_desc);
 1272|    213|    uint8_t        drv_id;
 1273|    426|    for (drv_id = 0; drv_id < TOTAL_DRIVER_COUNT; drv_id++) {
  ------------------
  |  |  389|    426|#define TOTAL_DRIVER_COUNT    ((uint8_t) (_app_driver_count + BUILTIN_DRIVER_COUNT))
  ------------------
  |  Branch (1273:22): [True: 213, False: 213]
  ------------------
 1274|    213|      const usbd_class_driver_t *driver = get_driver(drv_id);
 1275|    213|      TU_ASSERT(driver);
  ------------------
  |  |  131|    213|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    213|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|    213|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  127|    213|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|    213|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|    213|    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: 213]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|    213|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 213]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1276|    213|      const uint16_t drv_len = driver->open(rhport, desc_itf, remaining_len);
 1277|       |
 1278|    213|      if ((sizeof(tusb_desc_interface_t) <= drv_len) && (drv_len <= remaining_len)) {
  ------------------
  |  Branch (1278:11): [True: 0, False: 213]
  |  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|    213|    }
 1290|       |
 1291|       |    // Failed if there is no supported drivers
 1292|    213|    TU_ASSERT(drv_id < TOTAL_DRIVER_COUNT);
  ------------------
  |  |  131|    213|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    213|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|    213|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  127|    213|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|    213|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|    213|    if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   73|    213|  #define TU_MESS_FAILED() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (73:41): [Folded, False: 213]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |                   if ( !(_cond) ) { TU_MESS_FAILED(); TU_BREAKPOINT(); return _ret; } \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |   96|    213|  #define TU_BREAKPOINT() do {} while (0)
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  |  Branch (96:40): [Folded, False: 213]
  |  |  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (124:10): [True: 213, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|    213|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1293|    213|  }
 1294|       |
 1295|      0|  return true;
 1296|    213|}
usbd.c:process_get_descriptor:
 1299|  2.34k|static bool process_get_descriptor(uint8_t rhport, tusb_control_request_t const * p_request) {
 1300|  2.34k|  tusb_desc_type_t const desc_type = (tusb_desc_type_t) tu_u16_high(p_request->wValue);
 1301|  2.34k|  uint8_t const desc_index = tu_u16_low( p_request->wValue );
 1302|       |
 1303|  2.34k|  switch(desc_type) { //-V2520
 1304|    210|    case TUSB_DESC_DEVICE: {
  ------------------
  |  Branch (1304:5): [True: 210, False: 2.13k]
  ------------------
 1305|    210|      TU_LOG_USBD(" Device\r\n");
 1306|       |
 1307|    210|      void *desc_device = (void *)(uintptr_t)tud_descriptor_device_cb();
 1308|    210|      TU_ASSERT(desc_device);
  ------------------
  |  |  131|    210|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    210|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|    210|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  127|    210|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|    210|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|    210|    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: 210]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|    210|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 210]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 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|    210|      if ((CFG_TUD_ENDPOINT0_SIZE < sizeof(tusb_desc_device_t)) && !_usbd_dev.addressed &&
  ------------------
  |  |   90|    210|#define CFG_TUD_ENDPOINT0_SIZE    64
  ------------------
  |  Branch (1312:11): [Folded, False: 210]
  |  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|    210|      } else {
 1319|    210|        return tud_control_xfer(rhport, p_request, desc_device, sizeof(tusb_desc_device_t));
 1320|    210|      }
 1321|    210|    }
 1322|       |    // break; // unreachable
 1323|       |
 1324|    241|    case TUSB_DESC_BOS: {
  ------------------
  |  Branch (1324:5): [True: 241, False: 2.10k]
  ------------------
 1325|    241|      TU_LOG_USBD(" BOS\r\n");
 1326|       |
 1327|       |      // requested by host if USB > 2.0 ( i.e 2.1 or 3.x )
 1328|    241|      uintptr_t desc_bos = (uintptr_t) tud_descriptor_bos_cb();
 1329|    241|      TU_VERIFY(desc_bos != 0);
  ------------------
  |  |  114|    241|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    241|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  114|    241|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  111|    241|#define TU_VERIFY_1ARGS(_cond)         TU_VERIFY_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  105|    241|  do {                                \
  |  |  |  |  |  |  |  |  |  |  106|    241|    if (!(_cond)) {                   \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:9): [True: 241, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  107|    241|      return _ret;                    \
  |  |  |  |  |  |  |  |  |  |  108|    241|    }                                 \
  |  |  |  |  |  |  |  |  |  |  109|    241|  } 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|    241|    }
 1336|       |    // break; // unreachable
 1337|       |
 1338|    371|    case TUSB_DESC_CONFIGURATION:
  ------------------
  |  Branch (1338:5): [True: 371, False: 1.97k]
  ------------------
 1339|    571|    case TUSB_DESC_OTHER_SPEED_CONFIG: {
  ------------------
  |  Branch (1339:5): [True: 200, False: 2.14k]
  ------------------
 1340|    571|      uintptr_t desc_config;
 1341|       |
 1342|    571|      if ( desc_type == TUSB_DESC_CONFIGURATION ) {
  ------------------
  |  Branch (1342:12): [True: 371, False: 200]
  ------------------
 1343|    371|        TU_LOG_USBD(" Configuration[%u]\r\n", desc_index);
 1344|    371|        desc_config = (uintptr_t) tud_descriptor_configuration_cb(desc_index);
 1345|    371|        TU_ASSERT(desc_config != 0);
  ------------------
  |  |  131|    371|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    371|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|    371|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  127|    371|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|    371|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|    371|    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: 371]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|    371|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 371]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1346|    371|      }else {
 1347|       |        // Host only request this after getting Device Qualifier descriptor
 1348|    200|        TU_LOG_USBD(" Other Speed Configuration\r\n");
 1349|    200|        desc_config = (uintptr_t) tud_descriptor_other_speed_configuration_cb(desc_index);
 1350|    200|        TU_VERIFY(desc_config != 0);
  ------------------
  |  |  114|    200|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    200|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  114|    200|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  111|    200|#define TU_VERIFY_1ARGS(_cond)         TU_VERIFY_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  105|    200|  do {                                \
  |  |  |  |  |  |  |  |  |  |  106|    200|    if (!(_cond)) {                   \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:9): [True: 200, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  107|    200|      return _ret;                    \
  |  |  |  |  |  |  |  |  |  |  108|    200|    }                                 \
  |  |  |  |  |  |  |  |  |  |  109|    200|  } while (0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (109:12): [Folded, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1351|    200|      }
 1352|       |
 1353|       |      // Use offsetof to avoid pointer to the odd/misaligned address
 1354|    371|      uint16_t const total_len = tu_le16toh( tu_unaligned_read16((const void*) (desc_config + offsetof(tusb_desc_configuration_t, wTotalLength))) );
  ------------------
  |  |  272|    371|  #define tu_le16toh(u16) (u16)
  ------------------
 1355|       |
 1356|    371|      return tud_control_xfer(rhport, p_request, (void*) desc_config, total_len);
 1357|    571|    }
 1358|       |    // break; // unreachable
 1359|       |
 1360|    869|    case TUSB_DESC_STRING: {
  ------------------
  |  Branch (1360:5): [True: 869, False: 1.47k]
  ------------------
 1361|    869|      TU_LOG_USBD(" String[%u]\r\n", desc_index);
 1362|       |
 1363|       |      // String Descriptor always uses the desc set from user
 1364|    869|      uint8_t const* desc_str = (uint8_t const*) tud_descriptor_string_cb(desc_index, p_request->wIndex);
 1365|    869|      TU_VERIFY(desc_str);
  ------------------
  |  |  114|    869|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    869|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  114|    869|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  111|    869|#define TU_VERIFY_1ARGS(_cond)         TU_VERIFY_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  105|    869|  do {                                \
  |  |  |  |  |  |  |  |  |  |  106|    869|    if (!(_cond)) {                   \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:9): [True: 213, False: 656]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  107|    213|      return _ret;                    \
  |  |  |  |  |  |  |  |  |  |  108|    213|    }                                 \
  |  |  |  |  |  |  |  |  |  |  109|    869|  } while (0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (109:12): [Folded, False: 656]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1366|       |
 1367|       |      // first byte of descriptor is its size
 1368|    656|      return tud_control_xfer(rhport, p_request, (void*) (uintptr_t) desc_str, tu_desc_len(desc_str));
 1369|    869|    }
 1370|       |    // break; // unreachable
 1371|       |
 1372|    207|    case TUSB_DESC_DEVICE_QUALIFIER: {
  ------------------
  |  Branch (1372:5): [True: 207, False: 2.14k]
  ------------------
 1373|    207|      TU_LOG_USBD(" Device Qualifier\r\n");
 1374|    207|      uint8_t const* desc_qualifier = tud_descriptor_device_qualifier_cb();
 1375|    207|      TU_VERIFY(desc_qualifier);
  ------------------
  |  |  114|    207|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|    207|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  114|    207|#define TU_VERIFY(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  111|    207|#define TU_VERIFY_1ARGS(_cond)         TU_VERIFY_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  105|    207|  do {                                \
  |  |  |  |  |  |  |  |  |  |  106|    207|    if (!(_cond)) {                   \
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (106:9): [True: 207, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  107|    207|      return _ret;                    \
  |  |  |  |  |  |  |  |  |  |  108|    207|    }                                 \
  |  |  |  |  |  |  |  |  |  |  109|    207|  } 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|    207|    }
 1378|       |    // break; // unreachable
 1379|       |
 1380|    249|    default: return false;
  ------------------
  |  Branch (1380:5): [True: 249, False: 2.09k]
  ------------------
 1381|  2.34k|  }
 1382|  2.34k|}
usbd.c:queue_event:
  430|  32.9k|TU_ATTR_ALWAYS_INLINE static inline bool queue_event(dcd_event_t const * event, bool in_isr) {
  431|  32.9k|  TU_ASSERT(osal_queue_send(_usbd_q, event, in_isr));
  ------------------
  |  |  131|  32.9k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|  32.9k|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|  32.9k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  127|  32.9k|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|  32.9k|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|  32.9k|    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: 32.9k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|  32.9k|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 32.9k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  432|  32.9k|  tud_event_hook_cb(event->rhport, event->event_id, in_isr);
  433|       |  return true;
  434|  32.9k|}

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

usbd.c:osal_spin_init:
   69|      1|TU_ATTR_ALWAYS_INLINE static inline void osal_spin_init(osal_spinlock_t *ctx) {
   70|      1|  (void) ctx;
   71|      1|}
usbd.c:osal_queue_create:
  191|      1|TU_ATTR_ALWAYS_INLINE static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef) {
  192|      1|  tu_fifo_clear(&qdef->ff);
  193|      1|  return (osal_queue_t) qdef;
  194|      1|}
usbd.c:osal_queue_receive:
  201|  75.0k|TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_receive(osal_queue_t qhdl, void* data, uint32_t msec) {
  202|  75.0k|  (void) msec; // not used, always behave as msec = 0
  203|       |
  204|  75.0k|  qhdl->interrupt_set(false);
  205|  75.0k|  const bool success = (tu_fifo_read_n(&qhdl->ff, data, qhdl->item_size) > 0);
  206|  75.0k|  qhdl->interrupt_set(true);
  207|       |
  208|  75.0k|  return success;
  209|  75.0k|}
usbd.c:osal_queue_send:
  211|  32.9k|TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_send(osal_queue_t qhdl, void const* data, bool in_isr) {
  212|  32.9k|  if (!in_isr) {
  ------------------
  |  Branch (212:7): [True: 11.3k, False: 21.5k]
  ------------------
  213|  11.3k|    qhdl->interrupt_set(false);
  214|  11.3k|  }
  215|       |
  216|  32.9k|  const bool success = (tu_fifo_write_n(&qhdl->ff, data, qhdl->item_size) > 0);
  217|       |
  218|  32.9k|  if (!in_isr) {
  ------------------
  |  Branch (218:7): [True: 11.3k, False: 21.5k]
  ------------------
  219|  11.3k|    qhdl->interrupt_set(true);
  220|  11.3k|  }
  221|       |
  222|  32.9k|  return success;
  223|  32.9k|}

tusb_rhport_init:
   84|  1.00k|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.00k|  TU_ASSERT(rhport < TUP_USBIP_CONTROLLER_NUM && rh_init->role != TUSB_ROLE_INVALID);
  ------------------
  |  |  131|  1.00k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|  1.00k|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|  1.00k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  127|  1.00k|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|  1.00k|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|  2.01k|    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.00k, False: 0]
  |  |  |  |  |  |  |  |  |  |  |  Branch (124:12): [True: 1.00k, False: 0]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|  1.00k|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 1.00k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  114|  1.00k|  _tusb_rhport_role[rhport] = rh_init->role;
  115|       |
  116|  1.00k|  #if CFG_TUD_ENABLED
  117|  1.00k|  if (rh_init->role == TUSB_ROLE_DEVICE) {
  ------------------
  |  Branch (117:7): [True: 1.00k, False: 0]
  ------------------
  118|  1.00k|    TU_ASSERT(tud_rhport_init(rhport, rh_init));
  ------------------
  |  |  131|  1.00k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  131|  1.00k|#define TU_GET_3RD_ARG(arg1, arg2, arg3, ...)        arg3
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|  1.00k|#define TU_ASSERT(...)                 TU_GET_3RD_ARG(__VA_ARGS__, TU_ASSERT_2ARGS, TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  127|  1.00k|#define TU_ASSERT_1ARGS(_cond)         TU_ASSERT_DEFINE(_cond, false)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  123|  1.00k|  do {                                                                \
  |  |  |  |  |  |  |  |  |  |  124|  1.00k|    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.00k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  125|  1.00k|  } while(0)
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  Branch (125:11): [Folded, False: 1.00k]
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  119|  1.00k|  }
  120|  1.00k|  #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.00k|  return true;
  129|  1.00k|}

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

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

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

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

