mirror of
https://github.com/hathach/tinyusb.git
synced 2025-04-16 05:42:56 +00:00
Merge pull request #2618 from HiFiPhile/fifo_const_split
tusb_fifo: skip constant address functions if not used
This commit is contained in:
commit
104a5daef4
@ -62,7 +62,9 @@ TU_ATTR_ALWAYS_INLINE static inline void _ff_unlock(osal_mutex_t mutex)
|
|||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
TU_FIFO_COPY_INC, ///< Copy from/to an increasing source/destination address - default mode
|
TU_FIFO_COPY_INC, ///< Copy from/to an increasing source/destination address - default mode
|
||||||
|
#ifdef TUP_MEM_CONST_ADDR
|
||||||
TU_FIFO_COPY_CST_FULL_WORDS, ///< Copy from/to a constant source/destination address - required for e.g. STM32 to write into USB hardware FIFO
|
TU_FIFO_COPY_CST_FULL_WORDS, ///< Copy from/to a constant source/destination address - required for e.g. STM32 to write into USB hardware FIFO
|
||||||
|
#endif
|
||||||
} tu_fifo_copy_mode_t;
|
} tu_fifo_copy_mode_t;
|
||||||
|
|
||||||
bool tu_fifo_config(tu_fifo_t *f, void* buffer, uint16_t depth, uint16_t item_size, bool overwritable)
|
bool tu_fifo_config(tu_fifo_t *f, void* buffer, uint16_t depth, uint16_t item_size, bool overwritable)
|
||||||
@ -92,6 +94,7 @@ bool tu_fifo_config(tu_fifo_t *f, void* buffer, uint16_t depth, uint16_t item_si
|
|||||||
// Pull & Push
|
// Pull & Push
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
|
|
||||||
|
#ifdef TUP_MEM_CONST_ADDR
|
||||||
// Intended to be used to read from hardware USB FIFO in e.g. STM32 where all data is read from a constant address
|
// Intended to be used to read from hardware USB FIFO in e.g. STM32 where all data is read from a constant address
|
||||||
// Code adapted from dcd_synopsys.c
|
// Code adapted from dcd_synopsys.c
|
||||||
// TODO generalize with configurable 1 byte or 4 byte each read
|
// TODO generalize with configurable 1 byte or 4 byte each read
|
||||||
@ -140,6 +143,7 @@ static void _ff_pull_const_addr(void * app_buf, const uint8_t * ff_buf, uint16_t
|
|||||||
*reg_tx = tmp32;
|
*reg_tx = tmp32;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// send one item to fifo WITHOUT updating write pointer
|
// send one item to fifo WITHOUT updating write pointer
|
||||||
static inline void _ff_push(tu_fifo_t* f, void const * app_buf, uint16_t rel)
|
static inline void _ff_push(tu_fifo_t* f, void const * app_buf, uint16_t rel)
|
||||||
@ -179,7 +183,7 @@ static void _ff_push_n(tu_fifo_t* f, void const * app_buf, uint16_t n, uint16_t
|
|||||||
memcpy(f->buffer, ((uint8_t const*) app_buf) + lin_bytes, wrap_bytes);
|
memcpy(f->buffer, ((uint8_t const*) app_buf) + lin_bytes, wrap_bytes);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
#ifdef TUP_MEM_CONST_ADDR
|
||||||
case TU_FIFO_COPY_CST_FULL_WORDS:
|
case TU_FIFO_COPY_CST_FULL_WORDS:
|
||||||
// Intended for hardware buffers from which it can be read word by word only
|
// Intended for hardware buffers from which it can be read word by word only
|
||||||
if(n <= lin_count)
|
if(n <= lin_count)
|
||||||
@ -224,6 +228,7 @@ static void _ff_push_n(tu_fifo_t* f, void const * app_buf, uint16_t n, uint16_t
|
|||||||
if (wrap_bytes > 0) _ff_push_const_addr(ff_buf, app_buf, wrap_bytes);
|
if (wrap_bytes > 0) _ff_push_const_addr(ff_buf, app_buf, wrap_bytes);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -265,7 +270,7 @@ static void _ff_pull_n(tu_fifo_t* f, void* app_buf, uint16_t n, uint16_t rd_ptr,
|
|||||||
memcpy((uint8_t*) app_buf + lin_bytes, f->buffer, wrap_bytes);
|
memcpy((uint8_t*) app_buf + lin_bytes, f->buffer, wrap_bytes);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
#ifdef TUP_MEM_CONST_ADDR
|
||||||
case TU_FIFO_COPY_CST_FULL_WORDS:
|
case TU_FIFO_COPY_CST_FULL_WORDS:
|
||||||
if ( n <= lin_count )
|
if ( n <= lin_count )
|
||||||
{
|
{
|
||||||
@ -310,6 +315,7 @@ static void _ff_pull_n(tu_fifo_t* f, void* app_buf, uint16_t n, uint16_t rd_ptr,
|
|||||||
// Read data wrapped part
|
// Read data wrapped part
|
||||||
if (wrap_bytes > 0) _ff_pull_const_addr(app_buf, ff_buf, wrap_bytes);
|
if (wrap_bytes > 0) _ff_pull_const_addr(app_buf, ff_buf, wrap_bytes);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: break;
|
default: break;
|
||||||
@ -727,10 +733,29 @@ uint16_t tu_fifo_read_n(tu_fifo_t* f, void * buffer, uint16_t n)
|
|||||||
return _tu_fifo_read_n(f, buffer, n, TU_FIFO_COPY_INC);
|
return _tu_fifo_read_n(f, buffer, n, TU_FIFO_COPY_INC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef TUP_MEM_CONST_ADDR
|
||||||
|
/******************************************************************************/
|
||||||
|
/*!
|
||||||
|
@brief This function will read n elements from the array index specified by
|
||||||
|
the read pointer and increment the read index.
|
||||||
|
This function checks for an overflow and corrects read pointer if required.
|
||||||
|
The dest address will not be incremented which is useful for writing to registers.
|
||||||
|
|
||||||
|
@param[in] f
|
||||||
|
Pointer to the FIFO buffer to manipulate
|
||||||
|
@param[in] buffer
|
||||||
|
The pointer to data location
|
||||||
|
@param[in] n
|
||||||
|
Number of element that buffer can afford
|
||||||
|
|
||||||
|
@returns number of items read from the FIFO
|
||||||
|
*/
|
||||||
|
/******************************************************************************/
|
||||||
uint16_t tu_fifo_read_n_const_addr_full_words(tu_fifo_t* f, void * buffer, uint16_t n)
|
uint16_t tu_fifo_read_n_const_addr_full_words(tu_fifo_t* f, void * buffer, uint16_t n)
|
||||||
{
|
{
|
||||||
return _tu_fifo_read_n(f, buffer, n, TU_FIFO_COPY_CST_FULL_WORDS);
|
return _tu_fifo_read_n(f, buffer, n, TU_FIFO_COPY_CST_FULL_WORDS);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
/*!
|
/*!
|
||||||
@ -839,6 +864,7 @@ uint16_t tu_fifo_write_n(tu_fifo_t* f, const void * data, uint16_t n)
|
|||||||
return _tu_fifo_write_n(f, data, n, TU_FIFO_COPY_INC);
|
return _tu_fifo_write_n(f, data, n, TU_FIFO_COPY_INC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef TUP_MEM_CONST_ADDR
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
/*!
|
/*!
|
||||||
@brief This function will write n elements into the array index specified by
|
@brief This function will write n elements into the array index specified by
|
||||||
@ -858,6 +884,7 @@ uint16_t tu_fifo_write_n_const_addr_full_words(tu_fifo_t* f, const void * data,
|
|||||||
{
|
{
|
||||||
return _tu_fifo_write_n(f, data, n, TU_FIFO_COPY_CST_FULL_WORDS);
|
return _tu_fifo_write_n(f, data, n, TU_FIFO_COPY_CST_FULL_WORDS);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
/*!
|
/*!
|
||||||
|
@ -156,11 +156,15 @@ void tu_fifo_config_mutex(tu_fifo_t *f, osal_mutex_t wr_mutex, osal_mutex_t rd_m
|
|||||||
|
|
||||||
bool tu_fifo_write (tu_fifo_t* f, void const * p_data);
|
bool tu_fifo_write (tu_fifo_t* f, void const * p_data);
|
||||||
uint16_t tu_fifo_write_n (tu_fifo_t* f, void const * p_data, uint16_t n);
|
uint16_t tu_fifo_write_n (tu_fifo_t* f, void const * p_data, uint16_t n);
|
||||||
|
#ifdef TUP_MEM_CONST_ADDR
|
||||||
uint16_t tu_fifo_write_n_const_addr_full_words (tu_fifo_t* f, const void * data, uint16_t n);
|
uint16_t tu_fifo_write_n_const_addr_full_words (tu_fifo_t* f, const void * data, uint16_t n);
|
||||||
|
#endif
|
||||||
|
|
||||||
bool tu_fifo_read (tu_fifo_t* f, void * p_buffer);
|
bool tu_fifo_read (tu_fifo_t* f, void * p_buffer);
|
||||||
uint16_t tu_fifo_read_n (tu_fifo_t* f, void * p_buffer, uint16_t n);
|
uint16_t tu_fifo_read_n (tu_fifo_t* f, void * p_buffer, uint16_t n);
|
||||||
|
#ifdef TUP_MEM_CONST_ADDR
|
||||||
uint16_t tu_fifo_read_n_const_addr_full_words (tu_fifo_t* f, void * buffer, uint16_t n);
|
uint16_t tu_fifo_read_n_const_addr_full_words (tu_fifo_t* f, void * buffer, uint16_t n);
|
||||||
|
#endif
|
||||||
|
|
||||||
bool tu_fifo_peek (tu_fifo_t* f, void * p_buffer);
|
bool tu_fifo_peek (tu_fifo_t* f, void * p_buffer);
|
||||||
uint16_t tu_fifo_peek_n (tu_fifo_t* f, void * p_buffer, uint16_t n);
|
uint16_t tu_fifo_peek_n (tu_fifo_t* f, void * p_buffer, uint16_t n);
|
||||||
|
@ -448,4 +448,8 @@
|
|||||||
#define TUP_DCD_EDPT_ISO_ALLOC
|
#define TUP_DCD_EDPT_ISO_ALLOC
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(TUP_USBIP_DWC2)
|
||||||
|
#define TUP_MEM_CONST_ADDR
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user