summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorWini-Buh <[email protected]>2021-06-03 22:17:30 +0200
committerWini-Buh <[email protected]>2021-06-03 22:17:30 +0200
commit5a554508caba50bda2a82095a66a1896b960daaf (patch)
treec2a1aaafb98689d8827061a37cdbc7788a0eb4ad /src/common
parente26cf6b26ca0d7c54f71332896d4bed9c418844a (diff)
parentce30109b5bdb3ecd82f08c9dd48fe0f6f7f1713e (diff)
Merge remote-tracking branch 'upstream/master' into CCRX_Port
Diffstat (limited to 'src/common')
-rw-r--r--src/common/tusb_common.h64
-rw-r--r--src/common/tusb_fifo.c2
-rw-r--r--src/common/tusb_fifo.h26
3 files changed, 57 insertions, 35 deletions
diff --git a/src/common/tusb_common.h b/src/common/tusb_common.h
index 88e85c9e0..3350ed86c 100644
--- a/src/common/tusb_common.h
+++ b/src/common/tusb_common.h
@@ -24,10 +24,6 @@
* This file is part of the TinyUSB stack.
*/
-/** \ingroup Group_Common
- * \defgroup Group_CommonH common.h
- * @{ */
-
#ifndef _TUSB_COMMON_H_
#define _TUSB_COMMON_H_
@@ -72,10 +68,11 @@
#include "tusb_option.h"
#include "tusb_compiler.h"
#include "tusb_verify.h"
-#include "tusb_error.h" // TODO remove
-#include "tusb_timeout.h"
#include "tusb_types.h"
+#include "tusb_error.h" // TODO remove
+#include "tusb_timeout.h" // TODO remove
+
//------------- Mem -------------//
#define tu_memclr(buffer, size) memset((buffer), 0, (size))
#define tu_varclr(_var) tu_memclr(_var, sizeof(*(_var)))
@@ -287,8 +284,9 @@ TU_ATTR_ALWAYS_INLINE static inline void tu_unaligned_write16 (void* mem, ui
// CFG_TUSB_DEBUG for debugging
// 0 : no debug
-// 1 : print when there is error
-// 2 : print out log
+// 1 : print error
+// 2 : print warning
+// 3 : print info
#if CFG_TUSB_DEBUG
void tu_print_mem(void const *buf, uint32_t count, uint8_t indent);
@@ -306,25 +304,39 @@ void tu_print_var(uint8_t const* buf, uint32_t bufsize)
for(uint32_t i=0; i<bufsize; i++) tu_printf("%02X ", buf[i]);
}
-// Log with debug level 1
+// Log with Level
+#define TU_LOG(n, ...) TU_LOG##n(__VA_ARGS__)
+#define TU_LOG_MEM(n, ...) TU_LOG##n##_MEM(__VA_ARGS__)
+#define TU_LOG_VAR(n, ...) TU_LOG##n##_VAR(__VA_ARGS__)
+#define TU_LOG_INT(n, ...) TU_LOG##n##_INT(__VA_ARGS__)
+#define TU_LOG_HEX(n, ...) TU_LOG##n##_HEX(__VA_ARGS__)
+#define TU_LOG_LOCATION() tu_printf("%s: %d:\r\n", __PRETTY_FUNCTION__, __LINE__)
+#define TU_LOG_FAILED() tu_printf("%s: %d: Failed\r\n", __PRETTY_FUNCTION__, __LINE__)
+
+// Log Level 1: Error
#define TU_LOG1 tu_printf
#define TU_LOG1_MEM tu_print_mem
#define TU_LOG1_VAR(_x) tu_print_var((uint8_t const*)(_x), sizeof(*(_x)))
#define TU_LOG1_INT(_x) tu_printf(#_x " = %ld\n", (uint32_t) (_x) )
#define TU_LOG1_HEX(_x) tu_printf(#_x " = %lX\n", (uint32_t) (_x) )
-#define TU_LOG1_LOCATION() tu_printf("%s: %d:\r\n", __PRETTY_FUNCTION__, __LINE__)
-#define TU_LOG1_FAILED() tu_printf("%s: %d: Failed\r\n", __PRETTY_FUNCTION__, __LINE__)
-// Log with debug level 2
-#if CFG_TUSB_DEBUG > 1
+// Log Level 2: Warn
+#if CFG_TUSB_DEBUG >= 2
#define TU_LOG2 TU_LOG1
#define TU_LOG2_MEM TU_LOG1_MEM
#define TU_LOG2_VAR TU_LOG1_VAR
#define TU_LOG2_INT TU_LOG1_INT
#define TU_LOG2_HEX TU_LOG1_HEX
- #define TU_LOG2_LOCATION() TU_LOG1_LOCATION()
#endif
+// Log Level 3: Info
+#if CFG_TUSB_DEBUG >= 3
+ #define TU_LOG3 TU_LOG1
+ #define TU_LOG3_MEM TU_LOG1_MEM
+ #define TU_LOG3_VAR TU_LOG1_VAR
+ #define TU_LOG3_INT TU_LOG1_INT
+ #define TU_LOG3_HEX TU_LOG1_HEX
+#endif
typedef struct
{
@@ -350,14 +362,23 @@ static inline const char* tu_lookup_find(tu_lookup_table_t const* p_table, uint3
#endif // CFG_TUSB_DEBUG
+#ifndef TU_LOG
+#define TU_LOG(n, ...)
+#define TU_LOG_MEM(n, ...)
+#define TU_LOG_VAR(n, ...)
+#define TU_LOG_INT(n, ...)
+#define TU_LOG_HEX(n, ...)
+#define TU_LOG_LOCATION()
+#define TU_LOG_FAILED()
+#endif
+
+// TODO replace all TU_LOGn with TU_LOG(n)
#ifndef TU_LOG1
#define TU_LOG1(...)
#define TU_LOG1_MEM(...)
#define TU_LOG1_VAR(...)
#define TU_LOG1_INT(...)
#define TU_LOG1_HEX(...)
- #define TU_LOG1_LOCATION()
- #define TU_LOG1_FAILED()
#endif
#ifndef TU_LOG2
@@ -366,7 +387,14 @@ static inline const char* tu_lookup_find(tu_lookup_table_t const* p_table, uint3
#define TU_LOG2_VAR(...)
#define TU_LOG2_INT(...)
#define TU_LOG2_HEX(...)
- #define TU_LOG2_LOCATION()
+#endif
+
+#ifndef TU_LOG3
+ #define TU_LOG3(...)
+ #define TU_LOG3_MEM(...)
+ #define TU_LOG3_VAR(...)
+ #define TU_LOG3_INT(...)
+ #define TU_LOG3_HEX(...)
#endif
#ifdef __cplusplus
@@ -374,5 +402,3 @@ static inline const char* tu_lookup_find(tu_lookup_table_t const* p_table, uint3
#endif
#endif /* _TUSB_COMMON_H_ */
-
-/** @} */
diff --git a/src/common/tusb_fifo.c b/src/common/tusb_fifo.c
index 5f7b6a26d..1eb886aa1 100644
--- a/src/common/tusb_fifo.c
+++ b/src/common/tusb_fifo.c
@@ -25,8 +25,6 @@
* This file is part of the TinyUSB stack.
*/
-#include <string.h>
-
#include "osal/osal.h"
#include "tusb_fifo.h"
diff --git a/src/common/tusb_fifo.h b/src/common/tusb_fifo.h
index 8d73911f0..cf299269d 100644
--- a/src/common/tusb_fifo.h
+++ b/src/common/tusb_fifo.h
@@ -28,6 +28,10 @@
#ifndef _TUSB_FIFO_H_
#define _TUSB_FIFO_H_
+#ifdef __cplusplus
+extern "C" {
+#endif
+
// Due to the use of unmasked pointers, this FIFO does not suffer from loosing
// one item slice. Furthermore, write and read operations are completely
// decoupled as write and read functions do not modify a common state. Henceforth,
@@ -37,25 +41,17 @@
// read pointers can be updated from within a DMA ISR. Overflows are detectable
// within a certain number (see tu_fifo_overflow()).
+#include "common/tusb_common.h"
+
// mutex is only needed for RTOS
// for OS None, we don't get preempted
#define CFG_FIFO_MUTEX (CFG_TUSB_OS != OPT_OS_NONE)
-#include <stdint.h>
-#include <stdbool.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
#if CFG_FIFO_MUTEX
#include "osal/osal.h"
#define tu_fifo_mutex_t osal_mutex_t
#endif
-/** \struct tu_fifo_t
- * \brief Simple Circular FIFO
- */
typedef struct
{
uint8_t* buffer ; ///< buffer pointer
@@ -104,7 +100,8 @@ bool tu_fifo_clear(tu_fifo_t *f);
bool tu_fifo_config(tu_fifo_t *f, void* buffer, uint16_t depth, uint16_t item_size, bool overwritable);
#if CFG_FIFO_MUTEX
-static inline void tu_fifo_config_mutex(tu_fifo_t *f, tu_fifo_mutex_t write_mutex_hdl, tu_fifo_mutex_t read_mutex_hdl)
+TU_ATTR_ALWAYS_INLINE static inline
+void tu_fifo_config_mutex(tu_fifo_t *f, tu_fifo_mutex_t write_mutex_hdl, tu_fifo_mutex_t read_mutex_hdl)
{
f->mutex_wr = write_mutex_hdl;
f->mutex_rd = read_mutex_hdl;
@@ -129,15 +126,16 @@ uint16_t tu_fifo_remaining (tu_fifo_t* f);
bool tu_fifo_overflowed (tu_fifo_t* f);
void tu_fifo_correct_read_pointer (tu_fifo_t* f);
-static inline uint16_t tu_fifo_depth(tu_fifo_t* f)
+TU_ATTR_ALWAYS_INLINE static inline
+uint16_t tu_fifo_depth(tu_fifo_t* f)
{
return f->depth;
}
// Pointer modifications intended to be used in combinations with DMAs.
// USE WITH CARE - NO SAFTY CHECKS CONDUCTED HERE! NOT MUTEX PROTECTED!
-void tu_fifo_advance_write_pointer (tu_fifo_t *f, uint16_t n);
-void tu_fifo_advance_read_pointer (tu_fifo_t *f, uint16_t n);
+void tu_fifo_advance_write_pointer(tu_fifo_t *f, uint16_t n);
+void tu_fifo_advance_read_pointer (tu_fifo_t *f, uint16_t n);
// If you want to read/write from/to the FIFO by use of a DMA, you may need to conduct two copies
// to handle a possible wrapping part. These functions deliver a pointer to start