DM USB: introduce helper functions: index_inc and index_valid

Introduce helper functions to make code shorter and cleaner.

Tracked-On: #3628
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
This commit is contained in:
Xiaoguang Wu
2019-09-09 18:18:56 +08:00
committed by wenlingz
parent d58a766556
commit 1352eca224
5 changed files with 41 additions and 43 deletions

View File

@@ -230,6 +230,21 @@ enum USB_ERRCODE {
#define USB_DROPPED_XFER_MAGIC 0xaaaaaaaa55555555
inline bool
index_valid(int head, int tail, int maxcnt, int idx) {
if (head <= tail)
return (idx >= head && idx < tail);
else
return (idx >= head && idx < maxcnt) ||
(idx >= 0 && idx < tail);
}
inline int
index_inc(int idx, int maxcnt)
{
return (idx + 1) % maxcnt;
}
extern int usb_log_level;
static inline int usb_get_log_level(void) { return usb_log_level; }
static inline void usb_set_log_level(int level) { usb_log_level = level; }